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 #include <rte_errno.h> 17 18 #include <rte_crypto.h> 19 #include <rte_cryptodev.h> 20 #include <rte_ethdev.h> 21 #include <rte_ip.h> 22 #include <rte_string_fns.h> 23 #include <rte_tcp.h> 24 #include <rte_udp.h> 25 26 #ifdef RTE_CRYPTO_SCHEDULER 27 #include <rte_cryptodev_scheduler.h> 28 #include <rte_cryptodev_scheduler_operations.h> 29 #endif 30 31 #include <rte_lcore.h> 32 33 #include "test.h" 34 #include "test_cryptodev.h" 35 36 #include "test_cryptodev_blockcipher.h" 37 #include "test_cryptodev_aes_test_vectors.h" 38 #include "test_cryptodev_des_test_vectors.h" 39 #include "test_cryptodev_hash_test_vectors.h" 40 #include "test_cryptodev_kasumi_test_vectors.h" 41 #include "test_cryptodev_kasumi_hash_test_vectors.h" 42 #include "test_cryptodev_snow3g_test_vectors.h" 43 #include "test_cryptodev_snow3g_hash_test_vectors.h" 44 #include "test_cryptodev_zuc_test_vectors.h" 45 #include "test_cryptodev_aead_test_vectors.h" 46 #include "test_cryptodev_hmac_test_vectors.h" 47 #include "test_cryptodev_mixed_test_vectors.h" 48 #include "test_cryptodev_sm4_test_vectors.h" 49 #ifdef RTE_LIB_SECURITY 50 #include "test_cryptodev_security_ipsec.h" 51 #include "test_cryptodev_security_ipsec_test_vectors.h" 52 #include "test_cryptodev_security_pdcp_test_vectors.h" 53 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h" 54 #include "test_cryptodev_security_pdcp_test_func.h" 55 #include "test_cryptodev_security_docsis_test_vectors.h" 56 #include "test_cryptodev_security_tls_record.h" 57 #include "test_security_proto.h" 58 59 #define SDAP_DISABLED 0 60 #define SDAP_ENABLED 1 61 #endif 62 63 #define VDEV_ARGS_SIZE 100 64 #define MAX_NB_SESSIONS 4 65 66 #define MAX_DRV_SERVICE_CTX_SIZE 256 67 68 #define MAX_RAW_DEQUEUE_COUNT 65535 69 70 #define IN_PLACE 0 71 #define OUT_OF_PLACE 1 72 73 static int gbl_driver_id; 74 75 static enum rte_security_session_action_type gbl_action_type = 76 RTE_SECURITY_ACTION_TYPE_NONE; 77 78 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST; 79 80 struct crypto_unittest_params { 81 struct rte_crypto_sym_xform cipher_xform; 82 struct rte_crypto_sym_xform auth_xform; 83 struct rte_crypto_sym_xform aead_xform; 84 #ifdef RTE_LIB_SECURITY 85 struct rte_security_docsis_xform docsis_xform; 86 #endif 87 88 union { 89 void *sess; 90 #ifdef RTE_LIB_SECURITY 91 void *sec_session; 92 #endif 93 }; 94 #ifdef RTE_LIB_SECURITY 95 enum rte_security_session_action_type type; 96 #endif 97 struct rte_crypto_op *op; 98 99 struct rte_mbuf *obuf, *ibuf; 100 101 uint8_t *digest; 102 }; 103 104 #define ALIGN_POW2_ROUNDUP(num, align) \ 105 (((num) + (align) - 1) & ~((align) - 1)) 106 107 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts) \ 108 for (j = 0; j < num_child_ts; index++, j++) \ 109 parent_ts.unit_test_suites[index] = child_ts[j] 110 111 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types) \ 112 for (j = 0; j < num_blk_types; index++, j++) \ 113 parent_ts.unit_test_suites[index] = \ 114 build_blockcipher_test_suite(blk_types[j]) 115 116 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types) \ 117 for (j = index; j < index + num_blk_types; j++) \ 118 free_blockcipher_test_suite(parent_ts.unit_test_suites[j]) 119 120 /* 121 * Forward declarations. 122 */ 123 static int 124 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 125 struct crypto_unittest_params *ut_params, uint8_t *cipher_key, 126 uint8_t *hmac_key); 127 128 static int 129 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess, 130 struct crypto_unittest_params *ut_params, 131 struct crypto_testsuite_params *ts_param, 132 const uint8_t *cipher, 133 const uint8_t *digest, 134 const uint8_t *iv); 135 136 static int 137 security_proto_supported(enum rte_security_session_action_type action, 138 enum rte_security_session_protocol proto); 139 140 static int 141 dev_configure_and_start(uint64_t ff_disable); 142 143 static int 144 check_cipher_capability(const struct crypto_testsuite_params *ts_params, 145 const enum rte_crypto_cipher_algorithm cipher_algo, 146 const uint16_t key_size, const uint16_t iv_size); 147 148 static int 149 check_auth_capability(const struct crypto_testsuite_params *ts_params, 150 const enum rte_crypto_auth_algorithm auth_algo, 151 const uint16_t key_size, const uint16_t iv_size, 152 const uint16_t tag_size); 153 154 static struct rte_mbuf * 155 setup_test_string(struct rte_mempool *mpool, 156 const char *string, size_t len, uint8_t blocksize) 157 { 158 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool); 159 size_t t_len = len - (blocksize ? (len % blocksize) : 0); 160 161 if (m) { 162 char *dst; 163 164 memset(m->buf_addr, 0, m->buf_len); 165 dst = rte_pktmbuf_append(m, t_len); 166 if (!dst) { 167 rte_pktmbuf_free(m); 168 return NULL; 169 } 170 if (string != NULL) 171 rte_memcpy(dst, string, t_len); 172 else 173 memset(dst, 0, t_len); 174 } 175 176 return m; 177 } 178 179 /* Get number of bytes in X bits (rounding up) */ 180 static uint32_t 181 ceil_byte_length(uint32_t num_bits) 182 { 183 if (num_bits % 8) 184 return ((num_bits >> 3) + 1); 185 else 186 return (num_bits >> 3); 187 } 188 189 static void 190 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused, 191 uint8_t is_op_success) 192 { 193 struct rte_crypto_op *op = user_data; 194 op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS : 195 RTE_CRYPTO_OP_STATUS_ERROR; 196 } 197 198 static struct crypto_testsuite_params testsuite_params = { NULL }; 199 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params; 200 static struct crypto_unittest_params unittest_params; 201 202 int 203 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id, 204 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth, 205 uint8_t len_in_bits, uint8_t cipher_iv_len) 206 { 207 struct rte_crypto_sym_op *sop = op->sym; 208 struct rte_crypto_op *ret_op = NULL; 209 struct rte_crypto_vec data_vec[UINT8_MAX], dest_data_vec[UINT8_MAX]; 210 struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv; 211 union rte_crypto_sym_ofs ofs; 212 struct rte_crypto_sym_vec vec; 213 struct rte_crypto_sgl sgl, dest_sgl; 214 uint32_t max_len; 215 union rte_cryptodev_session_ctx sess; 216 uint64_t auth_end_iova; 217 uint32_t count = 0; 218 struct rte_crypto_raw_dp_ctx *ctx; 219 uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0, 220 auth_len = 0; 221 int32_t n; 222 uint32_t n_success; 223 int ctx_service_size; 224 int32_t status = 0; 225 int enqueue_status, dequeue_status; 226 struct crypto_unittest_params *ut_params = &unittest_params; 227 int is_sgl = sop->m_src->nb_segs > 1; 228 int ret = TEST_SUCCESS, is_oop = 0; 229 230 ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id); 231 if (ctx_service_size < 0) 232 return TEST_SKIPPED; 233 234 ctx = malloc(ctx_service_size); 235 if (ctx == NULL) 236 return TEST_FAILED; 237 238 /* Both are enums, setting crypto_sess will suit any session type */ 239 sess.crypto_sess = op->sym->session; 240 241 ret = rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx, op->sess_type, sess, 0); 242 if (ret == -ENOTSUP) { 243 ret = TEST_SKIPPED; 244 goto exit; 245 } else if (ret) { 246 ret = TEST_FAILED; 247 goto exit; 248 } 249 250 cipher_iv.iova = 0; 251 cipher_iv.va = NULL; 252 aad_auth_iv.iova = 0; 253 aad_auth_iv.va = NULL; 254 digest.iova = 0; 255 digest.va = NULL; 256 sgl.vec = data_vec; 257 vec.num = 1; 258 vec.src_sgl = &sgl; 259 vec.iv = &cipher_iv; 260 vec.digest = &digest; 261 vec.aad = &aad_auth_iv; 262 vec.status = &status; 263 264 ofs.raw = 0; 265 266 if ((sop->m_dst != NULL) && (sop->m_dst != sop->m_src)) 267 is_oop = 1; 268 269 if (is_cipher && is_auth) { 270 cipher_offset = sop->cipher.data.offset; 271 cipher_len = sop->cipher.data.length; 272 auth_offset = sop->auth.data.offset; 273 auth_len = sop->auth.data.length; 274 max_len = RTE_MAX(cipher_offset + cipher_len, 275 auth_offset + auth_len); 276 if (len_in_bits) { 277 max_len = max_len >> 3; 278 cipher_offset = cipher_offset >> 3; 279 auth_offset = auth_offset >> 3; 280 cipher_len = cipher_len >> 3; 281 auth_len = auth_len >> 3; 282 } 283 ofs.ofs.cipher.head = cipher_offset; 284 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 285 ofs.ofs.auth.head = auth_offset; 286 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 287 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 288 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 289 aad_auth_iv.va = rte_crypto_op_ctod_offset( 290 op, void *, IV_OFFSET + cipher_iv_len); 291 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 292 cipher_iv_len); 293 digest.va = (void *)sop->auth.digest.data; 294 digest.iova = sop->auth.digest.phys_addr; 295 296 if (is_sgl) { 297 uint32_t remaining_off = auth_offset + auth_len; 298 struct rte_mbuf *sgl_buf = sop->m_src; 299 if (is_oop) 300 sgl_buf = sop->m_dst; 301 302 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf) 303 && sgl_buf->next != NULL) { 304 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 305 sgl_buf = sgl_buf->next; 306 } 307 308 auth_end_iova = (uint64_t)rte_pktmbuf_iova_offset( 309 sgl_buf, remaining_off); 310 } else { 311 auth_end_iova = rte_pktmbuf_iova(op->sym->m_src) + 312 auth_offset + auth_len; 313 } 314 /* Then check if digest-encrypted conditions are met */ 315 if ((auth_offset + auth_len < cipher_offset + cipher_len) && 316 (digest.iova == auth_end_iova) && is_sgl) 317 max_len = RTE_MAX(max_len, 318 auth_offset + auth_len + 319 ut_params->auth_xform.auth.digest_length); 320 321 } else if (is_cipher) { 322 cipher_offset = sop->cipher.data.offset; 323 cipher_len = sop->cipher.data.length; 324 max_len = cipher_len + cipher_offset; 325 if (len_in_bits) { 326 max_len = max_len >> 3; 327 cipher_offset = cipher_offset >> 3; 328 cipher_len = cipher_len >> 3; 329 } 330 ofs.ofs.cipher.head = cipher_offset; 331 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 332 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 333 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 334 335 } else if (is_auth) { 336 auth_offset = sop->auth.data.offset; 337 auth_len = sop->auth.data.length; 338 max_len = auth_len + auth_offset; 339 if (len_in_bits) { 340 max_len = max_len >> 3; 341 auth_offset = auth_offset >> 3; 342 auth_len = auth_len >> 3; 343 } 344 ofs.ofs.auth.head = auth_offset; 345 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 346 aad_auth_iv.va = rte_crypto_op_ctod_offset( 347 op, void *, IV_OFFSET + cipher_iv_len); 348 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 349 cipher_iv_len); 350 digest.va = (void *)sop->auth.digest.data; 351 digest.iova = sop->auth.digest.phys_addr; 352 353 } else { /* aead */ 354 cipher_offset = sop->aead.data.offset; 355 cipher_len = sop->aead.data.length; 356 max_len = cipher_len + cipher_offset; 357 if (len_in_bits) { 358 max_len = max_len >> 3; 359 cipher_offset = cipher_offset >> 3; 360 cipher_len = cipher_len >> 3; 361 } 362 ofs.ofs.cipher.head = cipher_offset; 363 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 364 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 365 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 366 aad_auth_iv.va = (void *)sop->aead.aad.data; 367 aad_auth_iv.iova = sop->aead.aad.phys_addr; 368 digest.va = (void *)sop->aead.digest.data; 369 digest.iova = sop->aead.digest.phys_addr; 370 } 371 372 n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len, 373 data_vec, RTE_DIM(data_vec)); 374 if (n < 0 || n > sop->m_src->nb_segs) { 375 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 376 goto exit; 377 } 378 379 sgl.num = n; 380 /* Out of place */ 381 if (is_oop) { 382 dest_sgl.vec = dest_data_vec; 383 vec.dest_sgl = &dest_sgl; 384 n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len, 385 dest_data_vec, RTE_DIM(dest_data_vec)); 386 if (n < 0 || n > sop->m_dst->nb_segs) { 387 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 388 goto exit; 389 } 390 dest_sgl.num = n; 391 } else 392 vec.dest_sgl = NULL; 393 394 if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op, 395 &enqueue_status) < 1) { 396 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 397 goto exit; 398 } 399 400 if (enqueue_status == 0) { 401 status = rte_cryptodev_raw_enqueue_done(ctx, 1); 402 if (status < 0) { 403 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 404 goto exit; 405 } 406 } else if (enqueue_status < 0) { 407 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 408 goto exit; 409 } 410 411 n = n_success = 0; 412 while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) { 413 n = rte_cryptodev_raw_dequeue_burst(ctx, 414 NULL, 1, post_process_raw_dp_op, 415 (void **)&ret_op, 0, &n_success, 416 &dequeue_status); 417 if (dequeue_status < 0) { 418 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 419 goto exit; 420 } 421 if (n == 0) 422 rte_pause(); 423 } 424 425 if (n == 1 && dequeue_status == 0) { 426 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) { 427 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 428 goto exit; 429 } 430 } 431 432 op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op || 433 ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR || 434 n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR : 435 RTE_CRYPTO_OP_STATUS_SUCCESS; 436 437 exit: 438 free(ctx); 439 return ret; 440 } 441 442 static void 443 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op) 444 { 445 int32_t n, st; 446 struct rte_crypto_sym_op *sop; 447 union rte_crypto_sym_ofs ofs; 448 struct rte_crypto_sgl sgl; 449 struct rte_crypto_sym_vec symvec; 450 struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr; 451 struct rte_crypto_vec vec[UINT8_MAX]; 452 453 sop = op->sym; 454 455 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset, 456 sop->aead.data.length, vec, RTE_DIM(vec)); 457 458 if (n < 0 || n != sop->m_src->nb_segs) { 459 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 460 return; 461 } 462 463 sgl.vec = vec; 464 sgl.num = n; 465 symvec.src_sgl = &sgl; 466 symvec.iv = &iv_ptr; 467 symvec.digest = &digest_ptr; 468 symvec.aad = &aad_ptr; 469 symvec.status = &st; 470 symvec.num = 1; 471 472 /* for CPU crypto the IOVA address is not required */ 473 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 474 digest_ptr.va = (void *)sop->aead.digest.data; 475 aad_ptr.va = (void *)sop->aead.aad.data; 476 477 ofs.raw = 0; 478 479 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 480 &symvec); 481 482 if (n != 1) 483 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 484 else 485 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 486 } 487 488 static void 489 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op) 490 { 491 int32_t n, st; 492 struct rte_crypto_sym_op *sop; 493 union rte_crypto_sym_ofs ofs; 494 struct rte_crypto_sgl sgl; 495 struct rte_crypto_sym_vec symvec; 496 struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr; 497 struct rte_crypto_vec vec[UINT8_MAX]; 498 499 sop = op->sym; 500 501 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset, 502 sop->auth.data.length, vec, RTE_DIM(vec)); 503 504 if (n < 0 || n != sop->m_src->nb_segs) { 505 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 506 return; 507 } 508 509 sgl.vec = vec; 510 sgl.num = n; 511 symvec.src_sgl = &sgl; 512 symvec.iv = &iv_ptr; 513 symvec.digest = &digest_ptr; 514 symvec.status = &st; 515 symvec.num = 1; 516 517 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 518 digest_ptr.va = (void *)sop->auth.digest.data; 519 520 ofs.raw = 0; 521 ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset; 522 ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) - 523 (sop->cipher.data.offset + sop->cipher.data.length); 524 525 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 526 &symvec); 527 528 if (n != 1) 529 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 530 else 531 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 532 } 533 534 static struct rte_crypto_op * 535 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op) 536 { 537 538 RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO); 539 540 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 541 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n"); 542 return NULL; 543 } 544 545 op = NULL; 546 547 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 548 rte_pause(); 549 550 if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 551 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status); 552 return NULL; 553 } 554 555 return op; 556 } 557 558 static int 559 testsuite_setup(void) 560 { 561 struct crypto_testsuite_params *ts_params = &testsuite_params; 562 struct rte_cryptodev_info info; 563 uint32_t i = 0, nb_devs, dev_id; 564 uint16_t qp_id; 565 566 memset(ts_params, 0, sizeof(*ts_params)); 567 568 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 569 if (ts_params->mbuf_pool == NULL) { 570 /* Not already created so create */ 571 ts_params->mbuf_pool = rte_pktmbuf_pool_create( 572 "CRYPTO_MBUFPOOL", 573 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE, 574 rte_socket_id()); 575 if (ts_params->mbuf_pool == NULL) { 576 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n"); 577 return TEST_FAILED; 578 } 579 } 580 581 ts_params->large_mbuf_pool = rte_mempool_lookup( 582 "CRYPTO_LARGE_MBUFPOOL"); 583 if (ts_params->large_mbuf_pool == NULL) { 584 /* Not already created so create */ 585 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create( 586 "CRYPTO_LARGE_MBUFPOOL", 587 1, 0, 0, UINT16_MAX, 588 rte_socket_id()); 589 if (ts_params->large_mbuf_pool == NULL) { 590 RTE_LOG(ERR, USER1, 591 "Can't create CRYPTO_LARGE_MBUFPOOL\n"); 592 return TEST_FAILED; 593 } 594 } 595 596 ts_params->op_mpool = rte_crypto_op_pool_create( 597 "MBUF_CRYPTO_SYM_OP_POOL", 598 RTE_CRYPTO_OP_TYPE_SYMMETRIC, 599 NUM_MBUFS, MBUF_CACHE_SIZE, 600 DEFAULT_NUM_XFORMS * 601 sizeof(struct rte_crypto_sym_xform) + 602 MAXIMUM_IV_LENGTH, 603 rte_socket_id()); 604 if (ts_params->op_mpool == NULL) { 605 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n"); 606 return TEST_FAILED; 607 } 608 609 nb_devs = rte_cryptodev_count(); 610 if (nb_devs < 1) { 611 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 612 return TEST_SKIPPED; 613 } 614 615 if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) { 616 RTE_LOG(WARNING, USER1, "No %s devices found?\n", 617 rte_cryptodev_driver_name_get(gbl_driver_id)); 618 return TEST_SKIPPED; 619 } 620 621 /* Create list of valid crypto devs */ 622 for (i = 0; i < nb_devs; i++) { 623 rte_cryptodev_info_get(i, &info); 624 if (info.driver_id == gbl_driver_id) 625 ts_params->valid_devs[ts_params->valid_dev_count++] = i; 626 } 627 628 if (ts_params->valid_dev_count < 1) 629 return TEST_FAILED; 630 631 /* Set up all the qps on the first of the valid devices found */ 632 633 dev_id = ts_params->valid_devs[0]; 634 635 rte_cryptodev_info_get(dev_id, &info); 636 637 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; 638 ts_params->conf.socket_id = SOCKET_ID_ANY; 639 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY; 640 641 unsigned int session_size = 642 rte_cryptodev_sym_get_private_session_size(dev_id); 643 644 #ifdef RTE_LIB_SECURITY 645 unsigned int security_session_size = rte_security_session_get_size( 646 rte_cryptodev_get_sec_ctx(dev_id)); 647 648 if (session_size < security_session_size) 649 session_size = security_session_size; 650 #endif 651 /* 652 * Create mempool with maximum number of sessions. 653 */ 654 if (info.sym.max_nb_sessions != 0 && 655 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 656 RTE_LOG(ERR, USER1, "Device does not support " 657 "at least %u sessions\n", 658 MAX_NB_SESSIONS); 659 return TEST_FAILED; 660 } 661 662 ts_params->session_mpool = rte_cryptodev_sym_session_pool_create( 663 "test_sess_mp", MAX_NB_SESSIONS, session_size, 0, 0, 664 SOCKET_ID_ANY); 665 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 666 "session mempool allocation failed"); 667 668 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, 669 &ts_params->conf), 670 "Failed to configure cryptodev %u with %u qps", 671 dev_id, ts_params->conf.nb_queue_pairs); 672 673 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 674 ts_params->qp_conf.mp_session = ts_params->session_mpool; 675 676 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 677 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 678 dev_id, qp_id, &ts_params->qp_conf, 679 rte_cryptodev_socket_id(dev_id)), 680 "Failed to setup queue pair %u on cryptodev %u", 681 qp_id, dev_id); 682 } 683 684 return TEST_SUCCESS; 685 } 686 687 static void 688 testsuite_teardown(void) 689 { 690 struct crypto_testsuite_params *ts_params = &testsuite_params; 691 int res; 692 693 if (ts_params->mbuf_pool != NULL) { 694 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 695 rte_mempool_avail_count(ts_params->mbuf_pool)); 696 } 697 698 if (ts_params->op_mpool != NULL) { 699 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", 700 rte_mempool_avail_count(ts_params->op_mpool)); 701 } 702 703 if (ts_params->session_mpool != NULL) { 704 rte_mempool_free(ts_params->session_mpool); 705 ts_params->session_mpool = NULL; 706 } 707 708 res = rte_cryptodev_close(ts_params->valid_devs[0]); 709 if (res) 710 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res); 711 } 712 713 static int 714 check_capabilities_supported(enum rte_crypto_sym_xform_type type, 715 const int *algs, uint16_t num_algs) 716 { 717 uint8_t dev_id = testsuite_params.valid_devs[0]; 718 bool some_alg_supported = FALSE; 719 uint16_t i; 720 721 for (i = 0; i < num_algs && !some_alg_supported; i++) { 722 struct rte_cryptodev_sym_capability_idx alg = { 723 type, {algs[i]} 724 }; 725 if (rte_cryptodev_sym_capability_get(dev_id, 726 &alg) != NULL) 727 some_alg_supported = TRUE; 728 } 729 if (!some_alg_supported) 730 return TEST_SKIPPED; 731 732 return 0; 733 } 734 735 int 736 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers, 737 uint16_t num_ciphers) 738 { 739 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER, 740 (const int *) ciphers, num_ciphers); 741 } 742 743 int 744 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths, 745 uint16_t num_auths) 746 { 747 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH, 748 (const int *) auths, num_auths); 749 } 750 751 int 752 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads, 753 uint16_t num_aeads) 754 { 755 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD, 756 (const int *) aeads, num_aeads); 757 } 758 759 static int 760 null_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 }; 768 const enum rte_crypto_auth_algorithm auths[] = { 769 RTE_CRYPTO_AUTH_NULL 770 }; 771 772 rte_cryptodev_info_get(dev_id, &dev_info); 773 774 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 775 RTE_LOG(INFO, USER1, "Feature flag requirements for NULL " 776 "testsuite not met\n"); 777 return TEST_SKIPPED; 778 } 779 780 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 781 && check_auth_capabilities_supported(auths, 782 RTE_DIM(auths)) != 0) { 783 RTE_LOG(INFO, USER1, "Capability requirements for NULL " 784 "testsuite not met\n"); 785 return TEST_SKIPPED; 786 } 787 788 return 0; 789 } 790 791 static int 792 crypto_gen_testsuite_setup(void) 793 { 794 struct crypto_testsuite_params *ts_params = &testsuite_params; 795 uint8_t dev_id = ts_params->valid_devs[0]; 796 struct rte_cryptodev_info dev_info; 797 798 rte_cryptodev_info_get(dev_id, &dev_info); 799 800 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 801 RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen " 802 "testsuite not met\n"); 803 return TEST_SKIPPED; 804 } 805 806 return 0; 807 } 808 809 #ifdef RTE_LIB_SECURITY 810 static int 811 sec_proto_testsuite_setup(enum rte_security_session_protocol protocol) 812 { 813 struct crypto_testsuite_params *ts_params = &testsuite_params; 814 struct crypto_unittest_params *ut_params = &unittest_params; 815 struct rte_cryptodev_info dev_info; 816 int ret = 0; 817 818 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 819 820 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) { 821 RTE_LOG(INFO, USER1, 822 "Feature flag requirements for security protocol testsuite not met\n"); 823 return TEST_SKIPPED; 824 } 825 826 /* Reconfigure to enable security */ 827 ret = dev_configure_and_start(0); 828 if (ret != TEST_SUCCESS) 829 return ret; 830 831 /* Set action type */ 832 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 833 834 if (security_proto_supported(RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, protocol) < 0) { 835 RTE_LOG(INFO, USER1, 836 "Capability requirements for security protocol test not met\n"); 837 ret = TEST_SKIPPED; 838 } 839 840 test_sec_alg_list_populate(); 841 test_sec_auth_only_alg_list_populate(); 842 843 /* 844 * Stop the device. Device would be started again by individual test 845 * case setup routine. 846 */ 847 rte_cryptodev_stop(ts_params->valid_devs[0]); 848 849 return ret; 850 } 851 852 static int 853 ipsec_proto_testsuite_setup(void) 854 { 855 return sec_proto_testsuite_setup(RTE_SECURITY_PROTOCOL_IPSEC); 856 } 857 858 static int 859 tls_record_proto_testsuite_setup(void) 860 { 861 test_sec_proto_pattern_generate(); 862 863 return sec_proto_testsuite_setup(RTE_SECURITY_PROTOCOL_TLS_RECORD); 864 } 865 866 static int 867 pdcp_proto_testsuite_setup(void) 868 { 869 struct crypto_testsuite_params *ts_params = &testsuite_params; 870 uint8_t dev_id = ts_params->valid_devs[0]; 871 struct rte_cryptodev_info dev_info; 872 const enum rte_crypto_cipher_algorithm ciphers[] = { 873 RTE_CRYPTO_CIPHER_NULL, 874 RTE_CRYPTO_CIPHER_AES_CTR, 875 RTE_CRYPTO_CIPHER_ZUC_EEA3, 876 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 877 }; 878 const enum rte_crypto_auth_algorithm auths[] = { 879 RTE_CRYPTO_AUTH_NULL, 880 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 881 RTE_CRYPTO_AUTH_AES_CMAC, 882 RTE_CRYPTO_AUTH_ZUC_EIA3 883 }; 884 885 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_auth_key)); 886 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_bearer)); 887 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_crypto_key)); 888 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_in)); 889 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_in_len)); 890 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_out)); 891 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_sn_size)); 892 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_hfn)); 893 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_hfn_threshold)); 894 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_packet_direction)); 895 896 rte_cryptodev_info_get(dev_id, &dev_info); 897 898 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 899 !(dev_info.feature_flags & 900 RTE_CRYPTODEV_FF_SECURITY)) { 901 RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto " 902 "testsuite not met\n"); 903 return TEST_SKIPPED; 904 } 905 906 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 907 && check_auth_capabilities_supported(auths, 908 RTE_DIM(auths)) != 0) { 909 RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto " 910 "testsuite not met\n"); 911 return TEST_SKIPPED; 912 } 913 914 return 0; 915 } 916 917 static int 918 docsis_proto_testsuite_setup(void) 919 { 920 struct crypto_testsuite_params *ts_params = &testsuite_params; 921 uint8_t dev_id = ts_params->valid_devs[0]; 922 struct rte_cryptodev_info dev_info; 923 const enum rte_crypto_cipher_algorithm ciphers[] = { 924 RTE_CRYPTO_CIPHER_AES_DOCSISBPI 925 }; 926 927 rte_cryptodev_info_get(dev_id, &dev_info); 928 929 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 930 !(dev_info.feature_flags & 931 RTE_CRYPTODEV_FF_SECURITY)) { 932 RTE_LOG(INFO, USER1, "Feature flag requirements for DOCSIS " 933 "Proto testsuite not met\n"); 934 return TEST_SKIPPED; 935 } 936 937 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { 938 RTE_LOG(INFO, USER1, "Capability requirements for DOCSIS Proto " 939 "testsuite not met\n"); 940 return TEST_SKIPPED; 941 } 942 943 return 0; 944 } 945 #endif 946 947 static int 948 aes_ccm_auth_testsuite_setup(void) 949 { 950 struct crypto_testsuite_params *ts_params = &testsuite_params; 951 uint8_t dev_id = ts_params->valid_devs[0]; 952 struct rte_cryptodev_info dev_info; 953 const enum rte_crypto_aead_algorithm aeads[] = { 954 RTE_CRYPTO_AEAD_AES_CCM 955 }; 956 957 rte_cryptodev_info_get(dev_id, &dev_info); 958 959 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 960 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 961 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 962 RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM " 963 "testsuite not met\n"); 964 return TEST_SKIPPED; 965 } 966 967 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 968 RTE_LOG(INFO, USER1, "Capability requirements for AES CCM " 969 "testsuite not met\n"); 970 return TEST_SKIPPED; 971 } 972 973 return 0; 974 } 975 976 static int 977 aes_gcm_auth_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_aead_algorithm aeads[] = { 983 RTE_CRYPTO_AEAD_AES_GCM 984 }; 985 986 rte_cryptodev_info_get(dev_id, &dev_info); 987 988 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 989 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM " 990 "testsuite not met\n"); 991 return TEST_SKIPPED; 992 } 993 994 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 995 RTE_LOG(INFO, USER1, "Capability requirements for AES GCM " 996 "testsuite not met\n"); 997 return TEST_SKIPPED; 998 } 999 1000 return 0; 1001 } 1002 1003 static int 1004 aes_gmac_auth_testsuite_setup(void) 1005 { 1006 struct crypto_testsuite_params *ts_params = &testsuite_params; 1007 uint8_t dev_id = ts_params->valid_devs[0]; 1008 struct rte_cryptodev_info dev_info; 1009 const enum rte_crypto_auth_algorithm auths[] = { 1010 RTE_CRYPTO_AUTH_AES_GMAC 1011 }; 1012 1013 rte_cryptodev_info_get(dev_id, &dev_info); 1014 1015 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1016 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1017 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1018 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC " 1019 "testsuite not met\n"); 1020 return TEST_SKIPPED; 1021 } 1022 1023 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1024 RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC " 1025 "testsuite not met\n"); 1026 return TEST_SKIPPED; 1027 } 1028 1029 return 0; 1030 } 1031 1032 static int 1033 chacha20_poly1305_testsuite_setup(void) 1034 { 1035 struct crypto_testsuite_params *ts_params = &testsuite_params; 1036 uint8_t dev_id = ts_params->valid_devs[0]; 1037 struct rte_cryptodev_info dev_info; 1038 const enum rte_crypto_aead_algorithm aeads[] = { 1039 RTE_CRYPTO_AEAD_CHACHA20_POLY1305 1040 }; 1041 1042 rte_cryptodev_info_get(dev_id, &dev_info); 1043 1044 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1045 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1046 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1047 RTE_LOG(INFO, USER1, "Feature flag requirements for " 1048 "Chacha20-Poly1305 testsuite not met\n"); 1049 return TEST_SKIPPED; 1050 } 1051 1052 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1053 RTE_LOG(INFO, USER1, "Capability requirements for " 1054 "Chacha20-Poly1305 testsuite not met\n"); 1055 return TEST_SKIPPED; 1056 } 1057 1058 return 0; 1059 } 1060 1061 static int 1062 snow3g_testsuite_setup(void) 1063 { 1064 struct crypto_testsuite_params *ts_params = &testsuite_params; 1065 uint8_t dev_id = ts_params->valid_devs[0]; 1066 struct rte_cryptodev_info dev_info; 1067 const enum rte_crypto_cipher_algorithm ciphers[] = { 1068 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1069 1070 }; 1071 const enum rte_crypto_auth_algorithm auths[] = { 1072 RTE_CRYPTO_AUTH_SNOW3G_UIA2 1073 }; 1074 1075 rte_cryptodev_info_get(dev_id, &dev_info); 1076 1077 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1078 RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G " 1079 "testsuite not met\n"); 1080 return TEST_SKIPPED; 1081 } 1082 1083 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1084 && check_auth_capabilities_supported(auths, 1085 RTE_DIM(auths)) != 0) { 1086 RTE_LOG(INFO, USER1, "Capability requirements for Snow3G " 1087 "testsuite not met\n"); 1088 return TEST_SKIPPED; 1089 } 1090 1091 return 0; 1092 } 1093 1094 static int 1095 zuc_testsuite_setup(void) 1096 { 1097 struct crypto_testsuite_params *ts_params = &testsuite_params; 1098 uint8_t dev_id = ts_params->valid_devs[0]; 1099 struct rte_cryptodev_info dev_info; 1100 const enum rte_crypto_cipher_algorithm ciphers[] = { 1101 RTE_CRYPTO_CIPHER_ZUC_EEA3 1102 }; 1103 const enum rte_crypto_auth_algorithm auths[] = { 1104 RTE_CRYPTO_AUTH_ZUC_EIA3 1105 }; 1106 1107 rte_cryptodev_info_get(dev_id, &dev_info); 1108 1109 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1110 RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC " 1111 "testsuite not met\n"); 1112 return TEST_SKIPPED; 1113 } 1114 1115 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1116 && check_auth_capabilities_supported(auths, 1117 RTE_DIM(auths)) != 0) { 1118 RTE_LOG(INFO, USER1, "Capability requirements for ZUC " 1119 "testsuite not met\n"); 1120 return TEST_SKIPPED; 1121 } 1122 1123 return 0; 1124 } 1125 1126 static int 1127 hmac_md5_auth_testsuite_setup(void) 1128 { 1129 struct crypto_testsuite_params *ts_params = &testsuite_params; 1130 uint8_t dev_id = ts_params->valid_devs[0]; 1131 struct rte_cryptodev_info dev_info; 1132 const enum rte_crypto_auth_algorithm auths[] = { 1133 RTE_CRYPTO_AUTH_MD5_HMAC 1134 }; 1135 1136 rte_cryptodev_info_get(dev_id, &dev_info); 1137 1138 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1139 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1140 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1141 RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 " 1142 "Auth testsuite not met\n"); 1143 return TEST_SKIPPED; 1144 } 1145 1146 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1147 RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 " 1148 "testsuite not met\n"); 1149 return TEST_SKIPPED; 1150 } 1151 1152 return 0; 1153 } 1154 1155 static int 1156 kasumi_testsuite_setup(void) 1157 { 1158 struct crypto_testsuite_params *ts_params = &testsuite_params; 1159 uint8_t dev_id = ts_params->valid_devs[0]; 1160 struct rte_cryptodev_info dev_info; 1161 const enum rte_crypto_cipher_algorithm ciphers[] = { 1162 RTE_CRYPTO_CIPHER_KASUMI_F8 1163 }; 1164 const enum rte_crypto_auth_algorithm auths[] = { 1165 RTE_CRYPTO_AUTH_KASUMI_F9 1166 }; 1167 1168 rte_cryptodev_info_get(dev_id, &dev_info); 1169 1170 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1171 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1172 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1173 RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi " 1174 "testsuite not met\n"); 1175 return TEST_SKIPPED; 1176 } 1177 1178 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1179 && check_auth_capabilities_supported(auths, 1180 RTE_DIM(auths)) != 0) { 1181 RTE_LOG(INFO, USER1, "Capability requirements for Kasumi " 1182 "testsuite not met\n"); 1183 return TEST_SKIPPED; 1184 } 1185 1186 return 0; 1187 } 1188 1189 static int 1190 negative_aes_gcm_testsuite_setup(void) 1191 { 1192 struct crypto_testsuite_params *ts_params = &testsuite_params; 1193 uint8_t dev_id = ts_params->valid_devs[0]; 1194 struct rte_cryptodev_info dev_info; 1195 const enum rte_crypto_aead_algorithm aeads[] = { 1196 RTE_CRYPTO_AEAD_AES_GCM 1197 }; 1198 1199 rte_cryptodev_info_get(dev_id, &dev_info); 1200 1201 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1202 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1203 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1204 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1205 "AES GCM testsuite not met\n"); 1206 return TEST_SKIPPED; 1207 } 1208 1209 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1210 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1211 "AES GCM testsuite not met\n"); 1212 return TEST_SKIPPED; 1213 } 1214 1215 return 0; 1216 } 1217 1218 static int 1219 negative_aes_gmac_testsuite_setup(void) 1220 { 1221 struct crypto_testsuite_params *ts_params = &testsuite_params; 1222 uint8_t dev_id = ts_params->valid_devs[0]; 1223 struct rte_cryptodev_info dev_info; 1224 const enum rte_crypto_auth_algorithm auths[] = { 1225 RTE_CRYPTO_AUTH_AES_GMAC 1226 }; 1227 1228 rte_cryptodev_info_get(dev_id, &dev_info); 1229 1230 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1231 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1232 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1233 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1234 "AES GMAC testsuite not met\n"); 1235 return TEST_SKIPPED; 1236 } 1237 1238 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1239 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1240 "AES GMAC testsuite not met\n"); 1241 return TEST_SKIPPED; 1242 } 1243 1244 return 0; 1245 } 1246 1247 static int 1248 mixed_cipher_hash_testsuite_setup(void) 1249 { 1250 struct crypto_testsuite_params *ts_params = &testsuite_params; 1251 uint8_t dev_id = ts_params->valid_devs[0]; 1252 struct rte_cryptodev_info dev_info; 1253 uint64_t feat_flags; 1254 const enum rte_crypto_cipher_algorithm ciphers[] = { 1255 RTE_CRYPTO_CIPHER_NULL, 1256 RTE_CRYPTO_CIPHER_AES_CTR, 1257 RTE_CRYPTO_CIPHER_ZUC_EEA3, 1258 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1259 }; 1260 const enum rte_crypto_auth_algorithm auths[] = { 1261 RTE_CRYPTO_AUTH_NULL, 1262 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 1263 RTE_CRYPTO_AUTH_AES_CMAC, 1264 RTE_CRYPTO_AUTH_ZUC_EIA3 1265 }; 1266 1267 rte_cryptodev_info_get(dev_id, &dev_info); 1268 feat_flags = dev_info.feature_flags; 1269 1270 if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1271 (global_api_test_type == CRYPTODEV_RAW_API_TEST)) { 1272 RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed " 1273 "Cipher Hash testsuite not met\n"); 1274 return TEST_SKIPPED; 1275 } 1276 1277 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1278 && check_auth_capabilities_supported(auths, 1279 RTE_DIM(auths)) != 0) { 1280 RTE_LOG(INFO, USER1, "Capability requirements for Mixed " 1281 "Cipher Hash testsuite not met\n"); 1282 return TEST_SKIPPED; 1283 } 1284 1285 return 0; 1286 } 1287 1288 static int 1289 esn_testsuite_setup(void) 1290 { 1291 struct crypto_testsuite_params *ts_params = &testsuite_params; 1292 uint8_t dev_id = ts_params->valid_devs[0]; 1293 struct rte_cryptodev_info dev_info; 1294 const enum rte_crypto_cipher_algorithm ciphers[] = { 1295 RTE_CRYPTO_CIPHER_AES_CBC 1296 }; 1297 const enum rte_crypto_auth_algorithm auths[] = { 1298 RTE_CRYPTO_AUTH_SHA1_HMAC 1299 }; 1300 1301 rte_cryptodev_info_get(dev_id, &dev_info); 1302 1303 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1304 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1305 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1306 RTE_LOG(INFO, USER1, "Feature flag requirements for ESN " 1307 "testsuite not met\n"); 1308 return TEST_SKIPPED; 1309 } 1310 1311 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1312 && check_auth_capabilities_supported(auths, 1313 RTE_DIM(auths)) != 0) { 1314 RTE_LOG(INFO, USER1, "Capability requirements for ESN " 1315 "testsuite not met\n"); 1316 return TEST_SKIPPED; 1317 } 1318 1319 return 0; 1320 } 1321 1322 static int 1323 multi_session_testsuite_setup(void) 1324 { 1325 struct crypto_testsuite_params *ts_params = &testsuite_params; 1326 uint8_t dev_id = ts_params->valid_devs[0]; 1327 struct rte_cryptodev_info dev_info; 1328 const enum rte_crypto_cipher_algorithm ciphers[] = { 1329 RTE_CRYPTO_CIPHER_AES_CBC 1330 }; 1331 const enum rte_crypto_auth_algorithm auths[] = { 1332 RTE_CRYPTO_AUTH_SHA512_HMAC 1333 }; 1334 1335 rte_cryptodev_info_get(dev_id, &dev_info); 1336 1337 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1338 RTE_LOG(INFO, USER1, "Feature flag requirements for Multi " 1339 "Session testsuite not met\n"); 1340 return TEST_SKIPPED; 1341 } 1342 1343 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1344 && check_auth_capabilities_supported(auths, 1345 RTE_DIM(auths)) != 0) { 1346 RTE_LOG(INFO, USER1, "Capability requirements for Multi " 1347 "Session testsuite not met\n"); 1348 return TEST_SKIPPED; 1349 } 1350 1351 return 0; 1352 } 1353 1354 static int 1355 negative_hmac_sha1_testsuite_setup(void) 1356 { 1357 struct crypto_testsuite_params *ts_params = &testsuite_params; 1358 uint8_t dev_id = ts_params->valid_devs[0]; 1359 struct rte_cryptodev_info dev_info; 1360 const enum rte_crypto_cipher_algorithm ciphers[] = { 1361 RTE_CRYPTO_CIPHER_AES_CBC 1362 }; 1363 const enum rte_crypto_auth_algorithm auths[] = { 1364 RTE_CRYPTO_AUTH_SHA1_HMAC 1365 }; 1366 1367 rte_cryptodev_info_get(dev_id, &dev_info); 1368 1369 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1370 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1371 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1372 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1373 "HMAC SHA1 testsuite not met\n"); 1374 return TEST_SKIPPED; 1375 } 1376 1377 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1378 && check_auth_capabilities_supported(auths, 1379 RTE_DIM(auths)) != 0) { 1380 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1381 "HMAC SHA1 testsuite not met\n"); 1382 return TEST_SKIPPED; 1383 } 1384 1385 return 0; 1386 } 1387 1388 static int 1389 dev_configure_and_start(uint64_t ff_disable) 1390 { 1391 struct crypto_testsuite_params *ts_params = &testsuite_params; 1392 struct crypto_unittest_params *ut_params = &unittest_params; 1393 1394 uint16_t qp_id; 1395 1396 /* Clear unit test parameters before running test */ 1397 memset(ut_params, 0, sizeof(*ut_params)); 1398 1399 /* Reconfigure device to default parameters */ 1400 ts_params->conf.socket_id = SOCKET_ID_ANY; 1401 ts_params->conf.ff_disable = ff_disable; 1402 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 1403 ts_params->qp_conf.mp_session = ts_params->session_mpool; 1404 1405 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1406 &ts_params->conf), 1407 "Failed to configure cryptodev %u", 1408 ts_params->valid_devs[0]); 1409 1410 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { 1411 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1412 ts_params->valid_devs[0], qp_id, 1413 &ts_params->qp_conf, 1414 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1415 "Failed to setup queue pair %u on cryptodev %u", 1416 qp_id, ts_params->valid_devs[0]); 1417 } 1418 1419 1420 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 1421 1422 /* Start the device */ 1423 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 1424 "Failed to start cryptodev %u", 1425 ts_params->valid_devs[0]); 1426 1427 return TEST_SUCCESS; 1428 } 1429 1430 int 1431 ut_setup(void) 1432 { 1433 /* Configure and start the device with security feature disabled */ 1434 return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY); 1435 } 1436 1437 static int 1438 ut_setup_security(void) 1439 { 1440 /* Configure and start the device with no features disabled */ 1441 return dev_configure_and_start(0); 1442 } 1443 1444 static int 1445 ut_setup_security_rx_inject(void) 1446 { 1447 struct rte_mempool *mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 1448 struct crypto_testsuite_params *ts_params = &testsuite_params; 1449 struct rte_eth_conf port_conf = { 1450 .rxmode = { 1451 .offloads = RTE_ETH_RX_OFFLOAD_CHECKSUM | 1452 RTE_ETH_RX_OFFLOAD_SECURITY, 1453 }, 1454 .txmode = { 1455 .offloads = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE, 1456 }, 1457 .lpbk_mode = 1, /* Enable loopback */ 1458 }; 1459 struct rte_cryptodev_info dev_info; 1460 struct rte_eth_rxconf rx_conf = { 1461 .rx_thresh = { 1462 .pthresh = 8, 1463 .hthresh = 8, 1464 .wthresh = 8, 1465 }, 1466 .rx_free_thresh = 32, 1467 }; 1468 uint16_t nb_ports; 1469 void *sec_ctx; 1470 int ret; 1471 1472 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 1473 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY_RX_INJECT) || 1474 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) { 1475 RTE_LOG(INFO, USER1, 1476 "Feature requirements for IPsec Rx inject test case not met\n"); 1477 return TEST_SKIPPED; 1478 } 1479 1480 sec_ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 1481 if (sec_ctx == NULL) 1482 return TEST_SKIPPED; 1483 1484 nb_ports = rte_eth_dev_count_avail(); 1485 if (nb_ports == 0) 1486 return TEST_SKIPPED; 1487 1488 ret = rte_eth_dev_configure(0 /* port_id */, 1489 1 /* nb_rx_queue */, 1490 0 /* nb_tx_queue */, 1491 &port_conf); 1492 if (ret) { 1493 printf("Could not configure ethdev port 0 [err=%d]\n", ret); 1494 return TEST_SKIPPED; 1495 } 1496 1497 /* Rx queue setup */ 1498 ret = rte_eth_rx_queue_setup(0 /* port_id */, 1499 0 /* rx_queue_id */, 1500 1024 /* nb_rx_desc */, 1501 SOCKET_ID_ANY, 1502 &rx_conf, 1503 mbuf_pool); 1504 if (ret) { 1505 printf("Could not setup eth port 0 queue 0\n"); 1506 return TEST_SKIPPED; 1507 } 1508 1509 ret = rte_security_rx_inject_configure(sec_ctx, 0, true); 1510 if (ret) { 1511 printf("Could not enable Rx inject offload"); 1512 return TEST_SKIPPED; 1513 } 1514 1515 ret = rte_eth_dev_start(0); 1516 if (ret) { 1517 printf("Could not start ethdev"); 1518 return TEST_SKIPPED; 1519 } 1520 1521 ret = rte_eth_promiscuous_enable(0); 1522 if (ret) { 1523 printf("Could not enable promiscuous mode"); 1524 return TEST_SKIPPED; 1525 } 1526 1527 /* Configure and start cryptodev with no features disabled */ 1528 return dev_configure_and_start(0); 1529 } 1530 1531 static inline void 1532 ext_mbuf_callback_fn_free(void *addr __rte_unused, void *opaque __rte_unused) 1533 { 1534 } 1535 1536 static inline void 1537 ext_mbuf_memzone_free(int nb_segs) 1538 { 1539 int i; 1540 1541 for (i = 0; i <= nb_segs; i++) { 1542 char mz_name[RTE_MEMZONE_NAMESIZE]; 1543 const struct rte_memzone *memzone; 1544 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "ext_buf_%d", i); 1545 memzone = rte_memzone_lookup(mz_name); 1546 if (memzone != NULL) { 1547 rte_memzone_free(memzone); 1548 memzone = NULL; 1549 } 1550 } 1551 } 1552 1553 static inline struct rte_mbuf * 1554 ext_mbuf_create(struct rte_mempool *mbuf_pool, int pkt_len, 1555 int nb_segs, const void *input_text) 1556 { 1557 struct rte_mbuf *m = NULL, *mbuf = NULL; 1558 size_t data_off = 0; 1559 uint8_t *dst; 1560 int i, size; 1561 int t_len; 1562 1563 if (pkt_len < 1) { 1564 printf("Packet size must be 1 or more (is %d)\n", pkt_len); 1565 return NULL; 1566 } 1567 1568 if (nb_segs < 1) { 1569 printf("Number of segments must be 1 or more (is %d)\n", 1570 nb_segs); 1571 return NULL; 1572 } 1573 1574 t_len = pkt_len >= nb_segs ? pkt_len / nb_segs : 1; 1575 size = pkt_len; 1576 1577 /* Create chained mbuf_src with external buffer */ 1578 for (i = 0; size > 0; i++) { 1579 struct rte_mbuf_ext_shared_info *ret_shinfo = NULL; 1580 uint16_t data_len = RTE_MIN(size, t_len); 1581 char mz_name[RTE_MEMZONE_NAMESIZE]; 1582 const struct rte_memzone *memzone; 1583 void *ext_buf_addr = NULL; 1584 rte_iova_t buf_iova; 1585 bool freed = false; 1586 uint16_t buf_len; 1587 1588 buf_len = RTE_ALIGN_CEIL(data_len + 1024 + 1589 sizeof(struct rte_mbuf_ext_shared_info), 8); 1590 1591 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "ext_buf_%d", i); 1592 memzone = rte_memzone_lookup(mz_name); 1593 if (memzone != NULL && memzone->len != buf_len) { 1594 rte_memzone_free(memzone); 1595 memzone = NULL; 1596 } 1597 if (memzone == NULL) { 1598 memzone = rte_memzone_reserve_aligned(mz_name, buf_len, SOCKET_ID_ANY, 1599 RTE_MEMZONE_IOVA_CONTIG, RTE_CACHE_LINE_SIZE); 1600 if (memzone == NULL) { 1601 printf("Can't allocate memory zone %s\n", mz_name); 1602 return NULL; 1603 } 1604 } 1605 1606 ext_buf_addr = memzone->addr; 1607 if (input_text) 1608 memcpy(ext_buf_addr, RTE_PTR_ADD(input_text, data_off), data_len); 1609 1610 /* Create buffer to hold rte_mbuf header */ 1611 m = rte_pktmbuf_alloc(mbuf_pool); 1612 if (i == 0) 1613 mbuf = m; 1614 1615 if (m == NULL) { 1616 printf("Cannot create segment for source mbuf"); 1617 goto fail; 1618 } 1619 1620 /* Save shared data (like callback function) in external buffer's end */ 1621 ret_shinfo = rte_pktmbuf_ext_shinfo_init_helper(ext_buf_addr, &buf_len, 1622 ext_mbuf_callback_fn_free, &freed); 1623 if (ret_shinfo == NULL) { 1624 printf("Shared mem initialization failed!\n"); 1625 goto fail; 1626 } 1627 1628 buf_iova = rte_mem_virt2iova(ext_buf_addr); 1629 1630 /* Attach external buffer to mbuf */ 1631 rte_pktmbuf_attach_extbuf(m, ext_buf_addr, buf_iova, buf_len, 1632 ret_shinfo); 1633 if (m->ol_flags != RTE_MBUF_F_EXTERNAL) { 1634 printf("External buffer is not attached to mbuf\n"); 1635 goto fail; 1636 } 1637 1638 if (input_text) { 1639 dst = (uint8_t *)rte_pktmbuf_append(m, data_len); 1640 if (dst == NULL) { 1641 printf("Cannot append %d bytes to the mbuf\n", data_len); 1642 goto fail; 1643 } 1644 } 1645 1646 if (mbuf != m) 1647 rte_pktmbuf_chain(mbuf, m); 1648 1649 size -= data_len; 1650 data_off += data_len; 1651 } 1652 1653 return mbuf; 1654 1655 fail: 1656 rte_pktmbuf_free(mbuf); 1657 ext_mbuf_memzone_free(nb_segs); 1658 return NULL; 1659 } 1660 1661 void 1662 ut_teardown(void) 1663 { 1664 struct crypto_testsuite_params *ts_params = &testsuite_params; 1665 struct crypto_unittest_params *ut_params = &unittest_params; 1666 1667 /* free crypto session structure */ 1668 #ifdef RTE_LIB_SECURITY 1669 if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) { 1670 if (ut_params->sec_session) { 1671 rte_security_session_destroy(rte_cryptodev_get_sec_ctx 1672 (ts_params->valid_devs[0]), 1673 ut_params->sec_session); 1674 ut_params->sec_session = NULL; 1675 } 1676 } else 1677 #endif 1678 { 1679 if (ut_params->sess) { 1680 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 1681 ut_params->sess); 1682 ut_params->sess = NULL; 1683 } 1684 } 1685 1686 /* free crypto operation structure */ 1687 rte_crypto_op_free(ut_params->op); 1688 1689 /* 1690 * free mbuf - both obuf and ibuf are usually the same, 1691 * so check if they point at the same address is necessary, 1692 * to avoid freeing the mbuf twice. 1693 */ 1694 if (ut_params->obuf) { 1695 rte_pktmbuf_free(ut_params->obuf); 1696 if (ut_params->ibuf == ut_params->obuf) 1697 ut_params->ibuf = 0; 1698 ut_params->obuf = 0; 1699 } 1700 if (ut_params->ibuf) { 1701 ext_mbuf_memzone_free(1); 1702 rte_pktmbuf_free(ut_params->ibuf); 1703 ut_params->ibuf = 0; 1704 } 1705 1706 if (ts_params->mbuf_pool != NULL) 1707 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 1708 rte_mempool_avail_count(ts_params->mbuf_pool)); 1709 1710 /* Stop the device */ 1711 rte_cryptodev_stop(ts_params->valid_devs[0]); 1712 } 1713 1714 static void 1715 ut_teardown_rx_inject(void) 1716 { 1717 struct crypto_testsuite_params *ts_params = &testsuite_params; 1718 void *sec_ctx; 1719 int ret; 1720 1721 if (rte_eth_dev_count_avail() != 0) { 1722 ret = rte_eth_dev_reset(0); 1723 if (ret) 1724 printf("Could not reset eth port 0"); 1725 1726 } 1727 1728 ut_teardown(); 1729 1730 sec_ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 1731 if (sec_ctx == NULL) 1732 return; 1733 1734 ret = rte_security_rx_inject_configure(sec_ctx, 0, false); 1735 if (ret) { 1736 printf("Could not disable Rx inject offload"); 1737 return; 1738 } 1739 } 1740 1741 static int 1742 test_device_configure_invalid_dev_id(void) 1743 { 1744 struct crypto_testsuite_params *ts_params = &testsuite_params; 1745 uint16_t dev_id, num_devs = 0; 1746 1747 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 1748 "Need at least %d devices for test", 1); 1749 1750 /* valid dev_id values */ 1751 dev_id = ts_params->valid_devs[0]; 1752 1753 /* Stop the device in case it's started so it can be configured */ 1754 rte_cryptodev_stop(dev_id); 1755 1756 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 1757 "Failed test for rte_cryptodev_configure: " 1758 "invalid dev_num %u", dev_id); 1759 1760 /* invalid dev_id values */ 1761 dev_id = num_devs; 1762 1763 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1764 "Failed test for rte_cryptodev_configure: " 1765 "invalid dev_num %u", dev_id); 1766 1767 dev_id = 0xff; 1768 1769 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1770 "Failed test for rte_cryptodev_configure:" 1771 "invalid dev_num %u", dev_id); 1772 1773 return TEST_SUCCESS; 1774 } 1775 1776 static int 1777 test_device_configure_invalid_queue_pair_ids(void) 1778 { 1779 struct crypto_testsuite_params *ts_params = &testsuite_params; 1780 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 1781 1782 /* Stop the device in case it's started so it can be configured */ 1783 rte_cryptodev_stop(ts_params->valid_devs[0]); 1784 1785 /* valid - max value queue pairs */ 1786 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1787 1788 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1789 &ts_params->conf), 1790 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1791 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 1792 1793 /* valid - one queue pairs */ 1794 ts_params->conf.nb_queue_pairs = 1; 1795 1796 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1797 &ts_params->conf), 1798 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1799 ts_params->valid_devs[0], 1800 ts_params->conf.nb_queue_pairs); 1801 1802 1803 /* invalid - zero queue pairs */ 1804 ts_params->conf.nb_queue_pairs = 0; 1805 1806 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1807 &ts_params->conf), 1808 "Failed test for rte_cryptodev_configure, dev_id %u," 1809 " invalid qps: %u", 1810 ts_params->valid_devs[0], 1811 ts_params->conf.nb_queue_pairs); 1812 1813 1814 /* invalid - max value supported by field queue pairs */ 1815 ts_params->conf.nb_queue_pairs = UINT16_MAX; 1816 1817 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1818 &ts_params->conf), 1819 "Failed test for rte_cryptodev_configure, dev_id %u," 1820 " invalid qps: %u", 1821 ts_params->valid_devs[0], 1822 ts_params->conf.nb_queue_pairs); 1823 1824 1825 /* invalid - max value + 1 queue pairs */ 1826 ts_params->conf.nb_queue_pairs = orig_nb_qps + 1; 1827 1828 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1829 &ts_params->conf), 1830 "Failed test for rte_cryptodev_configure, dev_id %u," 1831 " invalid qps: %u", 1832 ts_params->valid_devs[0], 1833 ts_params->conf.nb_queue_pairs); 1834 1835 /* revert to original testsuite value */ 1836 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1837 1838 return TEST_SUCCESS; 1839 } 1840 1841 static int 1842 test_queue_pair_descriptor_setup(void) 1843 { 1844 struct crypto_testsuite_params *ts_params = &testsuite_params; 1845 struct rte_cryptodev_qp_conf qp_conf = { 1846 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 1847 }; 1848 uint16_t qp_id; 1849 1850 /* Stop the device in case it's started so it can be configured */ 1851 rte_cryptodev_stop(ts_params->valid_devs[0]); 1852 1853 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1854 &ts_params->conf), 1855 "Failed to configure cryptodev %u", 1856 ts_params->valid_devs[0]); 1857 1858 /* 1859 * Test various ring sizes on this device. memzones can't be 1860 * freed so are re-used if ring is released and re-created. 1861 */ 1862 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/ 1863 qp_conf.mp_session = ts_params->session_mpool; 1864 1865 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1866 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1867 ts_params->valid_devs[0], qp_id, &qp_conf, 1868 rte_cryptodev_socket_id( 1869 ts_params->valid_devs[0])), 1870 "Failed test for " 1871 "rte_cryptodev_queue_pair_setup: num_inflights " 1872 "%u on qp %u on cryptodev %u", 1873 qp_conf.nb_descriptors, qp_id, 1874 ts_params->valid_devs[0]); 1875 } 1876 1877 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2); 1878 1879 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1880 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1881 ts_params->valid_devs[0], qp_id, &qp_conf, 1882 rte_cryptodev_socket_id( 1883 ts_params->valid_devs[0])), 1884 "Failed test for" 1885 " rte_cryptodev_queue_pair_setup: num_inflights" 1886 " %u on qp %u on cryptodev %u", 1887 qp_conf.nb_descriptors, qp_id, 1888 ts_params->valid_devs[0]); 1889 } 1890 1891 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */ 1892 1893 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1894 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1895 ts_params->valid_devs[0], qp_id, &qp_conf, 1896 rte_cryptodev_socket_id( 1897 ts_params->valid_devs[0])), 1898 "Failed test for " 1899 "rte_cryptodev_queue_pair_setup: num_inflights" 1900 " %u on qp %u on cryptodev %u", 1901 qp_conf.nb_descriptors, qp_id, 1902 ts_params->valid_devs[0]); 1903 } 1904 1905 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 1906 1907 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1908 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1909 ts_params->valid_devs[0], qp_id, &qp_conf, 1910 rte_cryptodev_socket_id( 1911 ts_params->valid_devs[0])), 1912 "Failed test for" 1913 " rte_cryptodev_queue_pair_setup:" 1914 "num_inflights %u on qp %u on cryptodev %u", 1915 qp_conf.nb_descriptors, qp_id, 1916 ts_params->valid_devs[0]); 1917 } 1918 1919 /* test invalid queue pair id */ 1920 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */ 1921 1922 qp_id = ts_params->conf.nb_queue_pairs; /*invalid */ 1923 1924 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1925 ts_params->valid_devs[0], 1926 qp_id, &qp_conf, 1927 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1928 "Failed test for rte_cryptodev_queue_pair_setup:" 1929 "invalid qp %u on cryptodev %u", 1930 qp_id, ts_params->valid_devs[0]); 1931 1932 qp_id = 0xffff; /*invalid*/ 1933 1934 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1935 ts_params->valid_devs[0], 1936 qp_id, &qp_conf, 1937 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1938 "Failed test for rte_cryptodev_queue_pair_setup:" 1939 "invalid qp %u on cryptodev %u", 1940 qp_id, ts_params->valid_devs[0]); 1941 1942 return TEST_SUCCESS; 1943 } 1944 1945 /* ***** Plaintext data for tests ***** */ 1946 1947 const char catch_22_quote_1[] = 1948 "There was only one catch and that was Catch-22, which " 1949 "specified that a concern for one's safety in the face of " 1950 "dangers that were real and immediate was the process of a " 1951 "rational mind. Orr was crazy and could be grounded. All he " 1952 "had to do was ask; and as soon as he did, he would no longer " 1953 "be crazy and would have to fly more missions. Orr would be " 1954 "crazy to fly more missions and sane if he didn't, but if he " 1955 "was sane he had to fly them. If he flew them he was crazy " 1956 "and didn't have to; but if he didn't want to he was sane and " 1957 "had to. Yossarian was moved very deeply by the absolute " 1958 "simplicity of this clause of Catch-22 and let out a " 1959 "respectful whistle. \"That's some catch, that Catch-22\", he " 1960 "observed. \"It's the best there is,\" Doc Daneeka agreed."; 1961 1962 const char catch_22_quote[] = 1963 "What a lousy earth! He wondered how many people were " 1964 "destitute that same night even in his own prosperous country, " 1965 "how many homes were shanties, how many husbands were drunk " 1966 "and wives socked, and how many children were bullied, abused, " 1967 "or abandoned. How many families hungered for food they could " 1968 "not afford to buy? How many hearts were broken? How many " 1969 "suicides would take place that same night, how many people " 1970 "would go insane? How many cockroaches and landlords would " 1971 "triumph? How many winners were losers, successes failures, " 1972 "and rich men poor men? How many wise guys were stupid? How " 1973 "many happy endings were unhappy endings? How many honest men " 1974 "were liars, brave men cowards, loyal men traitors, how many " 1975 "sainted men were corrupt, how many people in positions of " 1976 "trust had sold their souls to bodyguards, how many had never " 1977 "had souls? How many straight-and-narrow paths were crooked " 1978 "paths? How many best families were worst families and how " 1979 "many good people were bad people? When you added them all up " 1980 "and then subtracted, you might be left with only the children, " 1981 "and perhaps with Albert Einstein and an old violinist or " 1982 "sculptor somewhere."; 1983 1984 #define QUOTE_480_BYTES (480) 1985 #define QUOTE_512_BYTES (512) 1986 #define QUOTE_768_BYTES (768) 1987 #define QUOTE_1024_BYTES (1024) 1988 1989 1990 1991 /* ***** SHA1 Hash Tests ***** */ 1992 1993 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1) 1994 1995 static uint8_t hmac_sha1_key[] = { 1996 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 1997 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 1998 0xDE, 0xF4, 0xDE, 0xAD }; 1999 2000 /* ***** SHA224 Hash Tests ***** */ 2001 2002 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224) 2003 2004 2005 /* ***** AES-CBC Cipher Tests ***** */ 2006 2007 #define CIPHER_KEY_LENGTH_AES_CBC (16) 2008 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC) 2009 2010 static uint8_t aes_cbc_key[] = { 2011 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 2012 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A }; 2013 2014 static uint8_t aes_cbc_iv[] = { 2015 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 2016 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; 2017 2018 2019 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */ 2020 2021 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = { 2022 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, 2023 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, 2024 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, 2025 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, 2026 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E, 2027 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08, 2028 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0, 2029 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01, 2030 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57, 2031 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE, 2032 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9, 2033 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9, 2034 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D, 2035 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3, 2036 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46, 2037 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3, 2038 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80, 2039 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92, 2040 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5, 2041 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5, 2042 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2, 2043 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5, 2044 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2045 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76, 2046 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4, 2047 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62, 2048 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4, 2049 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4, 2050 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54, 2051 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61, 2052 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91, 2053 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A, 2054 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF, 2055 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F, 2056 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28, 2057 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E, 2058 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7, 2059 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76, 2060 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6, 2061 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03, 2062 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C, 2063 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2, 2064 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6, 2065 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96, 2066 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6, 2067 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA, 2068 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87, 2069 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55, 2070 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B, 2071 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98, 2072 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53, 2073 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A, 2074 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26, 2075 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36, 2076 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36, 2077 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D, 2078 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E, 2079 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E, 2080 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A, 2081 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6, 2082 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4, 2083 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7, 2084 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1, 2085 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C 2086 }; 2087 2088 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = { 2089 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60, 2090 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 2091 0x18, 0x8c, 0x1d, 0x32 2092 }; 2093 2094 2095 /* Multisession Vector context Test */ 2096 /*Begin Session 0 */ 2097 static uint8_t ms_aes_cbc_key0[] = { 2098 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2099 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2100 }; 2101 2102 static uint8_t ms_aes_cbc_iv0[] = { 2103 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2104 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2105 }; 2106 2107 static const uint8_t ms_aes_cbc_cipher0[] = { 2108 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38, 2109 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC, 2110 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB, 2111 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9, 2112 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D, 2113 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4, 2114 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34, 2115 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F, 2116 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99, 2117 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED, 2118 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D, 2119 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24, 2120 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71, 2121 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72, 2122 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E, 2123 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD, 2124 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18, 2125 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6, 2126 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29, 2127 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C, 2128 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96, 2129 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26, 2130 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55, 2131 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46, 2132 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B, 2133 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4, 2134 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7, 2135 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5, 2136 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0, 2137 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E, 2138 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D, 2139 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44, 2140 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76, 2141 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3, 2142 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83, 2143 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85, 2144 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45, 2145 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25, 2146 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A, 2147 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1, 2148 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA, 2149 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3, 2150 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4, 2151 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60, 2152 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A, 2153 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A, 2154 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9, 2155 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55, 2156 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13, 2157 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B, 2158 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1, 2159 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0, 2160 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3, 2161 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23, 2162 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B, 2163 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07, 2164 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB, 2165 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1, 2166 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F, 2167 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F, 2168 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84, 2169 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B, 2170 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17, 2171 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF 2172 }; 2173 2174 2175 static uint8_t ms_hmac_key0[] = { 2176 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2177 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2178 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2179 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2180 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2181 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2182 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2183 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2184 }; 2185 2186 static const uint8_t ms_hmac_digest0[] = { 2187 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51, 2188 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F, 2189 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C, 2190 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4, 2191 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56, 2192 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4, 2193 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23, 2194 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90 2195 }; 2196 2197 /* End Session 0 */ 2198 /* Begin session 1 */ 2199 2200 static uint8_t ms_aes_cbc_key1[] = { 2201 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2202 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2203 }; 2204 2205 static uint8_t ms_aes_cbc_iv1[] = { 2206 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2207 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2208 }; 2209 2210 static const uint8_t ms_aes_cbc_cipher1[] = { 2211 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71, 2212 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23, 2213 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09, 2214 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A, 2215 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C, 2216 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F, 2217 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9, 2218 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66, 2219 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43, 2220 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB, 2221 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23, 2222 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29, 2223 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26, 2224 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F, 2225 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68, 2226 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77, 2227 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8, 2228 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97, 2229 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3, 2230 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90, 2231 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5, 2232 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E, 2233 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45, 2234 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B, 2235 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5, 2236 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D, 2237 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E, 2238 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD, 2239 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE, 2240 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1, 2241 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F, 2242 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25, 2243 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1, 2244 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3, 2245 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE, 2246 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6, 2247 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52, 2248 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA, 2249 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63, 2250 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E, 2251 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA, 2252 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB, 2253 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71, 2254 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF, 2255 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A, 2256 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95, 2257 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73, 2258 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49, 2259 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB, 2260 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B, 2261 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC, 2262 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED, 2263 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02, 2264 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4, 2265 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF, 2266 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82, 2267 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D, 2268 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6, 2269 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9, 2270 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35, 2271 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0, 2272 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53, 2273 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5, 2274 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3 2275 2276 }; 2277 2278 static uint8_t ms_hmac_key1[] = { 2279 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2280 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2281 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2282 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2283 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2284 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2285 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2286 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2287 }; 2288 2289 static const uint8_t ms_hmac_digest1[] = { 2290 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69, 2291 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50, 2292 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20, 2293 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD, 2294 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9, 2295 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4, 2296 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA, 2297 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F 2298 }; 2299 /* End Session 1 */ 2300 /* Begin Session 2 */ 2301 static uint8_t ms_aes_cbc_key2[] = { 2302 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2303 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2304 }; 2305 2306 static uint8_t ms_aes_cbc_iv2[] = { 2307 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2308 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2309 }; 2310 2311 static const uint8_t ms_aes_cbc_cipher2[] = { 2312 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91, 2313 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97, 2314 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8, 2315 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5, 2316 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98, 2317 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69, 2318 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09, 2319 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF, 2320 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44, 2321 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B, 2322 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9, 2323 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34, 2324 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99, 2325 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF, 2326 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC, 2327 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26, 2328 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3, 2329 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF, 2330 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3, 2331 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3, 2332 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA, 2333 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13, 2334 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38, 2335 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71, 2336 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC, 2337 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1, 2338 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E, 2339 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22, 2340 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62, 2341 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72, 2342 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6, 2343 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6, 2344 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44, 2345 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24, 2346 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5, 2347 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E, 2348 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17, 2349 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9, 2350 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D, 2351 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D, 2352 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22, 2353 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9, 2354 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49, 2355 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E, 2356 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B, 2357 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2, 2358 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95, 2359 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07, 2360 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3, 2361 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A, 2362 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57, 2363 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84, 2364 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61, 2365 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF, 2366 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17, 2367 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A, 2368 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1, 2369 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53, 2370 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7, 2371 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2, 2372 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A, 2373 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8, 2374 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70, 2375 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92 2376 }; 2377 2378 static uint8_t ms_hmac_key2[] = { 2379 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2380 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2381 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2382 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2383 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2384 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2385 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2386 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2387 }; 2388 2389 static const uint8_t ms_hmac_digest2[] = { 2390 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF, 2391 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6, 2392 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77, 2393 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27, 2394 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82, 2395 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24, 2396 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E, 2397 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59 2398 }; 2399 2400 /* End Session 2 */ 2401 2402 2403 static int 2404 test_AES_CBC_HMAC_SHA1_encrypt_digest(void) 2405 { 2406 struct crypto_testsuite_params *ts_params = &testsuite_params; 2407 struct crypto_unittest_params *ut_params = &unittest_params; 2408 /* Verify the capabilities */ 2409 struct rte_cryptodev_sym_capability_idx cap_idx; 2410 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2411 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 2412 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2413 &cap_idx) == NULL) 2414 return TEST_SKIPPED; 2415 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2416 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 2417 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2418 &cap_idx) == NULL) 2419 return TEST_SKIPPED; 2420 2421 /* Generate test mbuf data and space for digest */ 2422 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2423 catch_22_quote, QUOTE_512_BYTES, 0); 2424 2425 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2426 DIGEST_BYTE_LENGTH_SHA1); 2427 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2428 2429 /* Setup Cipher Parameters */ 2430 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2431 ut_params->cipher_xform.next = &ut_params->auth_xform; 2432 2433 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2434 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 2435 ut_params->cipher_xform.cipher.key.data = aes_cbc_key; 2436 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2437 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2438 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2439 2440 /* Setup HMAC Parameters */ 2441 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2442 2443 ut_params->auth_xform.next = NULL; 2444 2445 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 2446 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 2447 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; 2448 ut_params->auth_xform.auth.key.data = hmac_sha1_key; 2449 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; 2450 2451 rte_errno = 0; 2452 ut_params->sess = rte_cryptodev_sym_session_create( 2453 ts_params->valid_devs[0], &ut_params->cipher_xform, 2454 ts_params->session_mpool); 2455 if (rte_errno == ENOTSUP) 2456 return TEST_SKIPPED; 2457 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2458 2459 /* Generate crypto op data structure */ 2460 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2461 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2462 TEST_ASSERT_NOT_NULL(ut_params->op, 2463 "Failed to allocate symmetric crypto operation struct"); 2464 2465 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2466 2467 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2468 2469 /* set crypto operation source mbuf */ 2470 sym_op->m_src = ut_params->ibuf; 2471 2472 /* Set crypto operation authentication parameters */ 2473 sym_op->auth.digest.data = ut_params->digest; 2474 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2475 ut_params->ibuf, QUOTE_512_BYTES); 2476 2477 sym_op->auth.data.offset = 0; 2478 sym_op->auth.data.length = QUOTE_512_BYTES; 2479 2480 /* Copy IV at the end of the crypto operation */ 2481 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2482 aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC); 2483 2484 /* Set crypto operation cipher parameters */ 2485 sym_op->cipher.data.offset = 0; 2486 sym_op->cipher.data.length = QUOTE_512_BYTES; 2487 2488 /* Process crypto operation */ 2489 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2490 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2491 ut_params->op); 2492 else 2493 TEST_ASSERT_NOT_NULL( 2494 process_crypto_request(ts_params->valid_devs[0], 2495 ut_params->op), 2496 "failed to process sym crypto op"); 2497 2498 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2499 "crypto op processing failed"); 2500 2501 /* Validate obuf */ 2502 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 2503 uint8_t *); 2504 2505 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, 2506 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 2507 QUOTE_512_BYTES, 2508 "ciphertext data not as expected"); 2509 2510 uint8_t *digest = ciphertext + QUOTE_512_BYTES; 2511 2512 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, 2513 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, 2514 gbl_driver_id == rte_cryptodev_driver_id_get( 2515 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ? 2516 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : 2517 DIGEST_BYTE_LENGTH_SHA1, 2518 "Generated digest data not as expected"); 2519 2520 return TEST_SUCCESS; 2521 } 2522 2523 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ 2524 2525 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) 2526 2527 static uint8_t hmac_sha512_key[] = { 2528 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 2529 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2530 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2531 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60, 2532 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1, 2533 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2534 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76, 2535 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 }; 2536 2537 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = { 2538 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8, 2539 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48, 2540 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8, 2541 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70, 2542 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8, 2543 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E, 2544 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D, 2545 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A }; 2546 2547 2548 2549 static int 2550 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2551 struct crypto_unittest_params *ut_params, 2552 uint8_t *cipher_key, 2553 uint8_t *hmac_key); 2554 2555 static int 2556 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess, 2557 struct crypto_unittest_params *ut_params, 2558 struct crypto_testsuite_params *ts_params, 2559 const uint8_t *cipher, 2560 const uint8_t *digest, 2561 const uint8_t *iv); 2562 2563 2564 static int 2565 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2566 struct crypto_unittest_params *ut_params, 2567 uint8_t *cipher_key, 2568 uint8_t *hmac_key) 2569 { 2570 2571 /* Setup Cipher Parameters */ 2572 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2573 ut_params->cipher_xform.next = NULL; 2574 2575 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2576 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 2577 ut_params->cipher_xform.cipher.key.data = cipher_key; 2578 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2579 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2580 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2581 2582 /* Setup HMAC Parameters */ 2583 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2584 ut_params->auth_xform.next = &ut_params->cipher_xform; 2585 2586 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 2587 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC; 2588 ut_params->auth_xform.auth.key.data = hmac_key; 2589 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512; 2590 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512; 2591 2592 return TEST_SUCCESS; 2593 } 2594 2595 2596 static int 2597 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess, 2598 struct crypto_unittest_params *ut_params, 2599 struct crypto_testsuite_params *ts_params, 2600 const uint8_t *cipher, 2601 const uint8_t *digest, 2602 const uint8_t *iv) 2603 { 2604 int ret; 2605 2606 /* Generate test mbuf data and digest */ 2607 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2608 (const char *) 2609 cipher, 2610 QUOTE_512_BYTES, 0); 2611 2612 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2613 DIGEST_BYTE_LENGTH_SHA512); 2614 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2615 2616 rte_memcpy(ut_params->digest, 2617 digest, 2618 DIGEST_BYTE_LENGTH_SHA512); 2619 2620 /* Generate Crypto op data structure */ 2621 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2622 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2623 TEST_ASSERT_NOT_NULL(ut_params->op, 2624 "Failed to allocate symmetric crypto operation struct"); 2625 2626 rte_crypto_op_attach_sym_session(ut_params->op, sess); 2627 2628 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2629 2630 /* set crypto operation source mbuf */ 2631 sym_op->m_src = ut_params->ibuf; 2632 2633 sym_op->auth.digest.data = ut_params->digest; 2634 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2635 ut_params->ibuf, QUOTE_512_BYTES); 2636 2637 sym_op->auth.data.offset = 0; 2638 sym_op->auth.data.length = QUOTE_512_BYTES; 2639 2640 /* Copy IV at the end of the crypto operation */ 2641 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2642 iv, CIPHER_IV_LENGTH_AES_CBC); 2643 2644 sym_op->cipher.data.offset = 0; 2645 sym_op->cipher.data.length = QUOTE_512_BYTES; 2646 2647 /* Process crypto operation */ 2648 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2649 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2650 ut_params->op); 2651 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 2652 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 0); 2653 if (ret != TEST_SUCCESS) 2654 return ret; 2655 } else 2656 TEST_ASSERT_NOT_NULL( 2657 process_crypto_request(ts_params->valid_devs[0], 2658 ut_params->op), 2659 "failed to process sym crypto op"); 2660 2661 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2662 "crypto op processing failed"); 2663 2664 ut_params->obuf = ut_params->op->sym->m_src; 2665 2666 /* Validate obuf */ 2667 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2668 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 2669 catch_22_quote, 2670 QUOTE_512_BYTES, 2671 "Plaintext data not as expected"); 2672 2673 /* Validate obuf */ 2674 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2675 "Digest verification failed"); 2676 2677 return TEST_SUCCESS; 2678 } 2679 2680 /* ***** SNOW 3G Tests ***** */ 2681 static int 2682 create_wireless_algo_hash_session(uint8_t dev_id, 2683 const uint8_t *key, const uint8_t key_len, 2684 const uint8_t iv_len, const uint8_t auth_len, 2685 enum rte_crypto_auth_operation op, 2686 enum rte_crypto_auth_algorithm algo) 2687 { 2688 uint8_t hash_key[key_len]; 2689 2690 struct crypto_testsuite_params *ts_params = &testsuite_params; 2691 struct crypto_unittest_params *ut_params = &unittest_params; 2692 2693 memcpy(hash_key, key, key_len); 2694 2695 debug_hexdump(stdout, "key:", key, key_len); 2696 2697 /* Setup Authentication Parameters */ 2698 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2699 ut_params->auth_xform.next = NULL; 2700 2701 ut_params->auth_xform.auth.op = op; 2702 ut_params->auth_xform.auth.algo = algo; 2703 ut_params->auth_xform.auth.key.length = key_len; 2704 ut_params->auth_xform.auth.key.data = hash_key; 2705 ut_params->auth_xform.auth.digest_length = auth_len; 2706 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 2707 ut_params->auth_xform.auth.iv.length = iv_len; 2708 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2709 &ut_params->auth_xform, ts_params->session_mpool); 2710 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2711 return TEST_SKIPPED; 2712 2713 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2714 return 0; 2715 } 2716 2717 static int 2718 create_wireless_algo_cipher_session(uint8_t dev_id, 2719 enum rte_crypto_cipher_operation op, 2720 enum rte_crypto_cipher_algorithm algo, 2721 const uint8_t *key, const uint8_t key_len, 2722 uint8_t iv_len) 2723 { 2724 uint8_t cipher_key[key_len]; 2725 struct crypto_testsuite_params *ts_params = &testsuite_params; 2726 struct crypto_unittest_params *ut_params = &unittest_params; 2727 2728 memcpy(cipher_key, key, key_len); 2729 2730 /* Setup Cipher Parameters */ 2731 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2732 ut_params->cipher_xform.next = NULL; 2733 2734 ut_params->cipher_xform.cipher.algo = algo; 2735 ut_params->cipher_xform.cipher.op = op; 2736 ut_params->cipher_xform.cipher.key.data = cipher_key; 2737 ut_params->cipher_xform.cipher.key.length = key_len; 2738 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2739 ut_params->cipher_xform.cipher.iv.length = iv_len; 2740 2741 debug_hexdump(stdout, "key:", key, key_len); 2742 2743 /* Create Crypto session */ 2744 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2745 &ut_params->cipher_xform, ts_params->session_mpool); 2746 2747 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2748 return TEST_SKIPPED; 2749 2750 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2751 return 0; 2752 } 2753 2754 static int 2755 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len, 2756 unsigned int cipher_len, 2757 unsigned int cipher_offset) 2758 { 2759 struct crypto_testsuite_params *ts_params = &testsuite_params; 2760 struct crypto_unittest_params *ut_params = &unittest_params; 2761 2762 /* Generate Crypto op data structure */ 2763 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2764 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2765 TEST_ASSERT_NOT_NULL(ut_params->op, 2766 "Failed to allocate pktmbuf offload"); 2767 2768 /* Set crypto operation data parameters */ 2769 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2770 2771 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2772 2773 /* set crypto operation source mbuf */ 2774 sym_op->m_src = ut_params->ibuf; 2775 2776 /* iv */ 2777 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2778 iv, iv_len); 2779 sym_op->cipher.data.length = cipher_len; 2780 sym_op->cipher.data.offset = cipher_offset; 2781 return 0; 2782 } 2783 2784 static int 2785 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len, 2786 unsigned int cipher_len, 2787 unsigned int cipher_offset) 2788 { 2789 struct crypto_testsuite_params *ts_params = &testsuite_params; 2790 struct crypto_unittest_params *ut_params = &unittest_params; 2791 2792 /* Generate Crypto op data structure */ 2793 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2794 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2795 TEST_ASSERT_NOT_NULL(ut_params->op, 2796 "Failed to allocate pktmbuf offload"); 2797 2798 /* Set crypto operation data parameters */ 2799 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2800 2801 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2802 2803 /* set crypto operation source mbuf */ 2804 sym_op->m_src = ut_params->ibuf; 2805 sym_op->m_dst = ut_params->obuf; 2806 2807 /* iv */ 2808 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2809 iv, iv_len); 2810 sym_op->cipher.data.length = cipher_len; 2811 sym_op->cipher.data.offset = cipher_offset; 2812 return 0; 2813 } 2814 2815 static int 2816 create_wireless_algo_cipher_auth_session(uint8_t dev_id, 2817 enum rte_crypto_cipher_operation cipher_op, 2818 enum rte_crypto_auth_operation auth_op, 2819 enum rte_crypto_auth_algorithm auth_algo, 2820 enum rte_crypto_cipher_algorithm cipher_algo, 2821 const uint8_t *a_key, uint8_t a_key_len, 2822 const uint8_t *c_key, uint8_t c_key_len, 2823 uint8_t auth_iv_len, uint8_t auth_len, 2824 uint8_t cipher_iv_len) 2825 2826 { 2827 struct crypto_testsuite_params *ts_params = &testsuite_params; 2828 struct crypto_unittest_params *ut_params = &unittest_params; 2829 2830 /* Setup Authentication Parameters */ 2831 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2832 ut_params->auth_xform.next = NULL; 2833 2834 ut_params->auth_xform.auth.op = auth_op; 2835 ut_params->auth_xform.auth.algo = auth_algo; 2836 ut_params->auth_xform.auth.key.length = a_key_len; 2837 ut_params->auth_xform.auth.key.data = a_key; 2838 ut_params->auth_xform.auth.digest_length = auth_len; 2839 /* Auth IV will be after cipher IV */ 2840 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2841 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2842 2843 /* Setup Cipher Parameters */ 2844 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2845 ut_params->cipher_xform.next = &ut_params->auth_xform; 2846 2847 ut_params->cipher_xform.cipher.algo = cipher_algo; 2848 ut_params->cipher_xform.cipher.op = cipher_op; 2849 ut_params->cipher_xform.cipher.key.data = c_key; 2850 ut_params->cipher_xform.cipher.key.length = c_key_len; 2851 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2852 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2853 2854 debug_hexdump(stdout, "Auth key:", a_key, c_key_len); 2855 debug_hexdump(stdout, "Cipher key:", c_key, c_key_len); 2856 2857 /* Create Crypto session*/ 2858 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2859 &ut_params->cipher_xform, ts_params->session_mpool); 2860 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2861 return TEST_SKIPPED; 2862 2863 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2864 return 0; 2865 } 2866 2867 static int 2868 create_wireless_cipher_auth_session(uint8_t dev_id, 2869 enum rte_crypto_cipher_operation cipher_op, 2870 enum rte_crypto_auth_operation auth_op, 2871 enum rte_crypto_auth_algorithm auth_algo, 2872 enum rte_crypto_cipher_algorithm cipher_algo, 2873 const struct wireless_test_data *tdata) 2874 { 2875 const uint8_t key_len = tdata->key.len; 2876 uint8_t cipher_auth_key[key_len]; 2877 2878 struct crypto_testsuite_params *ts_params = &testsuite_params; 2879 struct crypto_unittest_params *ut_params = &unittest_params; 2880 const uint8_t *key = tdata->key.data; 2881 const uint8_t auth_len = tdata->digest.len; 2882 uint8_t cipher_iv_len = tdata->cipher_iv.len; 2883 uint8_t auth_iv_len = tdata->auth_iv.len; 2884 2885 memcpy(cipher_auth_key, key, key_len); 2886 2887 /* Setup Authentication Parameters */ 2888 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2889 ut_params->auth_xform.next = NULL; 2890 2891 ut_params->auth_xform.auth.op = auth_op; 2892 ut_params->auth_xform.auth.algo = auth_algo; 2893 ut_params->auth_xform.auth.key.length = key_len; 2894 /* Hash key = cipher key */ 2895 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2896 ut_params->auth_xform.auth.digest_length = auth_len; 2897 /* Auth IV will be after cipher IV */ 2898 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2899 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2900 2901 /* Setup Cipher Parameters */ 2902 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2903 ut_params->cipher_xform.next = &ut_params->auth_xform; 2904 2905 ut_params->cipher_xform.cipher.algo = cipher_algo; 2906 ut_params->cipher_xform.cipher.op = cipher_op; 2907 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2908 ut_params->cipher_xform.cipher.key.length = key_len; 2909 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2910 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2911 2912 2913 debug_hexdump(stdout, "key:", key, key_len); 2914 2915 /* Create Crypto session*/ 2916 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2917 &ut_params->cipher_xform, ts_params->session_mpool); 2918 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2919 return TEST_SKIPPED; 2920 2921 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2922 return 0; 2923 } 2924 2925 static int 2926 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id, 2927 const struct wireless_test_data *tdata) 2928 { 2929 return create_wireless_cipher_auth_session(dev_id, 2930 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2931 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3, 2932 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata); 2933 } 2934 2935 static int 2936 create_wireless_algo_auth_cipher_session(uint8_t dev_id, 2937 enum rte_crypto_cipher_operation cipher_op, 2938 enum rte_crypto_auth_operation auth_op, 2939 enum rte_crypto_auth_algorithm auth_algo, 2940 enum rte_crypto_cipher_algorithm cipher_algo, 2941 const uint8_t *a_key, const uint8_t a_key_len, 2942 const uint8_t *c_key, const uint8_t c_key_len, 2943 uint8_t auth_iv_len, uint8_t auth_len, 2944 uint8_t cipher_iv_len) 2945 { 2946 struct crypto_testsuite_params *ts_params = &testsuite_params; 2947 struct crypto_unittest_params *ut_params = &unittest_params; 2948 2949 /* Setup Authentication Parameters */ 2950 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2951 ut_params->auth_xform.auth.op = auth_op; 2952 ut_params->auth_xform.next = &ut_params->cipher_xform; 2953 ut_params->auth_xform.auth.algo = auth_algo; 2954 ut_params->auth_xform.auth.key.length = a_key_len; 2955 ut_params->auth_xform.auth.key.data = a_key; 2956 ut_params->auth_xform.auth.digest_length = auth_len; 2957 /* Auth IV will be after cipher IV */ 2958 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2959 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2960 2961 /* Setup Cipher Parameters */ 2962 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2963 ut_params->cipher_xform.next = NULL; 2964 ut_params->cipher_xform.cipher.algo = cipher_algo; 2965 ut_params->cipher_xform.cipher.op = cipher_op; 2966 ut_params->cipher_xform.cipher.key.data = c_key; 2967 ut_params->cipher_xform.cipher.key.length = c_key_len; 2968 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2969 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2970 2971 debug_hexdump(stdout, "Auth key:", a_key, a_key_len); 2972 debug_hexdump(stdout, "Cipher key:", c_key, c_key_len); 2973 2974 /* Create Crypto session*/ 2975 if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 2976 ut_params->auth_xform.next = NULL; 2977 ut_params->cipher_xform.next = &ut_params->auth_xform; 2978 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2979 &ut_params->cipher_xform, ts_params->session_mpool); 2980 } else 2981 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2982 &ut_params->auth_xform, ts_params->session_mpool); 2983 2984 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2985 return TEST_SKIPPED; 2986 2987 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2988 2989 return 0; 2990 } 2991 2992 static int 2993 create_wireless_algo_hash_operation(const uint8_t *auth_tag, 2994 unsigned int auth_tag_len, 2995 const uint8_t *iv, unsigned int iv_len, 2996 unsigned int data_pad_len, 2997 enum rte_crypto_auth_operation op, 2998 unsigned int auth_len, unsigned int auth_offset) 2999 { 3000 struct crypto_testsuite_params *ts_params = &testsuite_params; 3001 3002 struct crypto_unittest_params *ut_params = &unittest_params; 3003 3004 /* Generate Crypto op data structure */ 3005 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3006 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3007 TEST_ASSERT_NOT_NULL(ut_params->op, 3008 "Failed to allocate pktmbuf offload"); 3009 3010 /* Set crypto operation data parameters */ 3011 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 3012 3013 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3014 3015 /* set crypto operation source mbuf */ 3016 sym_op->m_src = ut_params->ibuf; 3017 3018 /* iv */ 3019 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 3020 iv, iv_len); 3021 /* digest */ 3022 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 3023 ut_params->ibuf, auth_tag_len); 3024 3025 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 3026 "no room to append auth tag"); 3027 ut_params->digest = sym_op->auth.digest.data; 3028 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3029 ut_params->ibuf, data_pad_len); 3030 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 3031 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3032 else 3033 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3034 3035 debug_hexdump(stdout, "digest:", 3036 sym_op->auth.digest.data, 3037 auth_tag_len); 3038 3039 sym_op->auth.data.length = auth_len; 3040 sym_op->auth.data.offset = auth_offset; 3041 3042 return 0; 3043 } 3044 3045 static int 3046 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata, 3047 enum rte_crypto_auth_operation op) 3048 { 3049 struct crypto_testsuite_params *ts_params = &testsuite_params; 3050 struct crypto_unittest_params *ut_params = &unittest_params; 3051 3052 const uint8_t *auth_tag = tdata->digest.data; 3053 const unsigned int auth_tag_len = tdata->digest.len; 3054 unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len); 3055 unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3056 3057 const uint8_t *cipher_iv = tdata->cipher_iv.data; 3058 const uint8_t cipher_iv_len = tdata->cipher_iv.len; 3059 const uint8_t *auth_iv = tdata->auth_iv.data; 3060 const uint8_t auth_iv_len = tdata->auth_iv.len; 3061 const unsigned int cipher_len = tdata->validCipherLenInBits.len; 3062 const unsigned int auth_len = tdata->validAuthLenInBits.len; 3063 3064 /* Generate Crypto op data structure */ 3065 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3066 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3067 TEST_ASSERT_NOT_NULL(ut_params->op, 3068 "Failed to allocate pktmbuf offload"); 3069 /* Set crypto operation data parameters */ 3070 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 3071 3072 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3073 3074 /* set crypto operation source mbuf */ 3075 sym_op->m_src = ut_params->ibuf; 3076 3077 /* digest */ 3078 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 3079 ut_params->ibuf, auth_tag_len); 3080 3081 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 3082 "no room to append auth tag"); 3083 ut_params->digest = sym_op->auth.digest.data; 3084 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3085 ut_params->ibuf, data_pad_len); 3086 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 3087 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3088 else 3089 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3090 3091 debug_hexdump(stdout, "digest:", 3092 sym_op->auth.digest.data, 3093 auth_tag_len); 3094 3095 /* Copy cipher and auth IVs at the end of the crypto operation */ 3096 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 3097 IV_OFFSET); 3098 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 3099 iv_ptr += cipher_iv_len; 3100 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 3101 3102 sym_op->cipher.data.length = cipher_len; 3103 sym_op->cipher.data.offset = 0; 3104 sym_op->auth.data.length = auth_len; 3105 sym_op->auth.data.offset = 0; 3106 3107 return 0; 3108 } 3109 3110 static int 3111 create_zuc_cipher_hash_generate_operation( 3112 const struct wireless_test_data *tdata) 3113 { 3114 return create_wireless_cipher_hash_operation(tdata, 3115 RTE_CRYPTO_AUTH_OP_GENERATE); 3116 } 3117 3118 static int 3119 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag, 3120 const unsigned auth_tag_len, 3121 const uint8_t *auth_iv, uint8_t auth_iv_len, 3122 unsigned data_pad_len, 3123 enum rte_crypto_auth_operation op, 3124 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 3125 const unsigned cipher_len, const unsigned cipher_offset, 3126 const unsigned auth_len, const unsigned auth_offset) 3127 { 3128 struct crypto_testsuite_params *ts_params = &testsuite_params; 3129 struct crypto_unittest_params *ut_params = &unittest_params; 3130 3131 enum rte_crypto_cipher_algorithm cipher_algo = 3132 ut_params->cipher_xform.cipher.algo; 3133 enum rte_crypto_auth_algorithm auth_algo = 3134 ut_params->auth_xform.auth.algo; 3135 3136 /* Generate Crypto op data structure */ 3137 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3138 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3139 TEST_ASSERT_NOT_NULL(ut_params->op, 3140 "Failed to allocate pktmbuf offload"); 3141 /* Set crypto operation data parameters */ 3142 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 3143 3144 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3145 3146 /* set crypto operation source mbuf */ 3147 sym_op->m_src = ut_params->ibuf; 3148 3149 /* digest */ 3150 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 3151 ut_params->ibuf, auth_tag_len); 3152 3153 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 3154 "no room to append auth tag"); 3155 ut_params->digest = sym_op->auth.digest.data; 3156 3157 if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) { 3158 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3159 ut_params->ibuf, data_pad_len); 3160 } else { 3161 struct rte_mbuf *m = ut_params->ibuf; 3162 unsigned int offset = data_pad_len; 3163 3164 while (offset > m->data_len && m->next != NULL) { 3165 offset -= m->data_len; 3166 m = m->next; 3167 } 3168 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3169 m, offset); 3170 } 3171 3172 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 3173 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3174 else 3175 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3176 3177 debug_hexdump(stdout, "digest:", 3178 sym_op->auth.digest.data, 3179 auth_tag_len); 3180 3181 /* Copy cipher and auth IVs at the end of the crypto operation */ 3182 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 3183 IV_OFFSET); 3184 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 3185 iv_ptr += cipher_iv_len; 3186 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 3187 3188 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 3189 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 3190 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 3191 sym_op->cipher.data.length = cipher_len; 3192 sym_op->cipher.data.offset = cipher_offset; 3193 } else { 3194 sym_op->cipher.data.length = cipher_len >> 3; 3195 sym_op->cipher.data.offset = cipher_offset >> 3; 3196 } 3197 3198 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 3199 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 3200 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 3201 sym_op->auth.data.length = auth_len; 3202 sym_op->auth.data.offset = auth_offset; 3203 } else { 3204 sym_op->auth.data.length = auth_len >> 3; 3205 sym_op->auth.data.offset = auth_offset >> 3; 3206 } 3207 3208 return 0; 3209 } 3210 3211 static int 3212 create_wireless_algo_auth_cipher_operation( 3213 const uint8_t *auth_tag, unsigned int auth_tag_len, 3214 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 3215 const uint8_t *auth_iv, uint8_t auth_iv_len, 3216 unsigned int data_pad_len, 3217 unsigned int cipher_len, unsigned int cipher_offset, 3218 unsigned int auth_len, unsigned int auth_offset, 3219 uint8_t op_mode, uint8_t do_sgl, uint8_t verify) 3220 { 3221 struct crypto_testsuite_params *ts_params = &testsuite_params; 3222 struct crypto_unittest_params *ut_params = &unittest_params; 3223 3224 enum rte_crypto_cipher_algorithm cipher_algo = 3225 ut_params->cipher_xform.cipher.algo; 3226 enum rte_crypto_auth_algorithm auth_algo = 3227 ut_params->auth_xform.auth.algo; 3228 3229 /* Generate Crypto op data structure */ 3230 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3231 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3232 TEST_ASSERT_NOT_NULL(ut_params->op, 3233 "Failed to allocate pktmbuf offload"); 3234 3235 /* Set crypto operation data parameters */ 3236 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 3237 3238 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3239 3240 /* set crypto operation mbufs */ 3241 sym_op->m_src = ut_params->ibuf; 3242 if (op_mode == OUT_OF_PLACE) 3243 sym_op->m_dst = ut_params->obuf; 3244 3245 /* digest */ 3246 if (!do_sgl) { 3247 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset( 3248 (op_mode == IN_PLACE ? 3249 ut_params->ibuf : ut_params->obuf), 3250 uint8_t *, data_pad_len); 3251 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3252 (op_mode == IN_PLACE ? 3253 ut_params->ibuf : ut_params->obuf), 3254 data_pad_len); 3255 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3256 } else { 3257 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3); 3258 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ? 3259 sym_op->m_src : sym_op->m_dst); 3260 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) { 3261 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 3262 sgl_buf = sgl_buf->next; 3263 } 3264 3265 /* The last segment should be large enough to hold full digest */ 3266 if (sgl_buf->data_len < auth_tag_len) { 3267 rte_pktmbuf_free(sgl_buf->next); 3268 sgl_buf->next = NULL; 3269 TEST_ASSERT_NOT_NULL(rte_pktmbuf_append(sgl_buf, 3270 auth_tag_len - sgl_buf->data_len), 3271 "No room to append auth tag"); 3272 } 3273 3274 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf, 3275 uint8_t *, remaining_off); 3276 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf, 3277 remaining_off); 3278 memset(sym_op->auth.digest.data, 0, remaining_off); 3279 while (sgl_buf->next != NULL) { 3280 memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *), 3281 0, rte_pktmbuf_data_len(sgl_buf)); 3282 sgl_buf = sgl_buf->next; 3283 } 3284 } 3285 3286 /* Copy digest for the verification */ 3287 if (verify) 3288 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3289 3290 /* Copy cipher and auth IVs at the end of the crypto operation */ 3291 uint8_t *iv_ptr = rte_crypto_op_ctod_offset( 3292 ut_params->op, uint8_t *, IV_OFFSET); 3293 3294 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 3295 iv_ptr += cipher_iv_len; 3296 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 3297 3298 /* Only copy over the offset data needed from src to dst in OOP, 3299 * if the auth and cipher offsets are not aligned 3300 */ 3301 if (op_mode == OUT_OF_PLACE) { 3302 if (cipher_offset > auth_offset) 3303 rte_memcpy( 3304 rte_pktmbuf_mtod_offset( 3305 sym_op->m_dst, 3306 uint8_t *, auth_offset >> 3), 3307 rte_pktmbuf_mtod_offset( 3308 sym_op->m_src, 3309 uint8_t *, auth_offset >> 3), 3310 ((cipher_offset >> 3) - (auth_offset >> 3))); 3311 } 3312 3313 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 3314 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 3315 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 3316 sym_op->cipher.data.length = cipher_len; 3317 sym_op->cipher.data.offset = cipher_offset; 3318 } else { 3319 sym_op->cipher.data.length = cipher_len >> 3; 3320 sym_op->cipher.data.offset = cipher_offset >> 3; 3321 } 3322 3323 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 3324 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 3325 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 3326 sym_op->auth.data.length = auth_len; 3327 sym_op->auth.data.offset = auth_offset; 3328 } else { 3329 sym_op->auth.data.length = auth_len >> 3; 3330 sym_op->auth.data.offset = auth_offset >> 3; 3331 } 3332 3333 return 0; 3334 } 3335 3336 static int 3337 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) 3338 { 3339 struct crypto_testsuite_params *ts_params = &testsuite_params; 3340 struct crypto_unittest_params *ut_params = &unittest_params; 3341 3342 int retval; 3343 unsigned plaintext_pad_len; 3344 unsigned plaintext_len; 3345 uint8_t *plaintext; 3346 struct rte_cryptodev_info dev_info; 3347 3348 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3349 uint64_t feat_flags = dev_info.feature_flags; 3350 3351 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3352 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3353 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3354 return TEST_SKIPPED; 3355 } 3356 3357 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3358 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3359 printf("Device doesn't support RAW data-path APIs.\n"); 3360 return TEST_SKIPPED; 3361 } 3362 3363 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3364 return TEST_SKIPPED; 3365 3366 /* Verify the capabilities */ 3367 struct rte_cryptodev_sym_capability_idx cap_idx; 3368 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3369 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3370 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3371 &cap_idx) == NULL) 3372 return TEST_SKIPPED; 3373 3374 /* Create SNOW 3G session */ 3375 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3376 tdata->key.data, tdata->key.len, 3377 tdata->auth_iv.len, tdata->digest.len, 3378 RTE_CRYPTO_AUTH_OP_GENERATE, 3379 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3380 if (retval < 0) 3381 return retval; 3382 3383 /* alloc mbuf and set payload */ 3384 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3385 3386 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3387 rte_pktmbuf_tailroom(ut_params->ibuf)); 3388 3389 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3390 /* Append data which is padded to a multiple of */ 3391 /* the algorithms block size */ 3392 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3393 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3394 plaintext_pad_len); 3395 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3396 3397 /* Create SNOW 3G operation */ 3398 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3399 tdata->auth_iv.data, tdata->auth_iv.len, 3400 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3401 tdata->validAuthLenInBits.len, 3402 0); 3403 if (retval < 0) 3404 return retval; 3405 3406 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3407 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 3408 0); 3409 if (retval != TEST_SUCCESS) 3410 return retval; 3411 } else 3412 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3413 ut_params->op); 3414 ut_params->obuf = ut_params->op->sym->m_src; 3415 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3416 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 3417 uint8_t *, 3418 plaintext_pad_len); 3419 3420 /* Validate obuf */ 3421 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3422 ut_params->digest, 3423 tdata->digest.data, 3424 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 3425 "SNOW 3G Generated auth tag not as expected"); 3426 3427 return 0; 3428 } 3429 3430 static int 3431 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) 3432 { 3433 struct crypto_testsuite_params *ts_params = &testsuite_params; 3434 struct crypto_unittest_params *ut_params = &unittest_params; 3435 3436 int retval; 3437 unsigned plaintext_pad_len; 3438 unsigned plaintext_len; 3439 uint8_t *plaintext; 3440 struct rte_cryptodev_info dev_info; 3441 3442 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3443 uint64_t feat_flags = dev_info.feature_flags; 3444 3445 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3446 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3447 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3448 return TEST_SKIPPED; 3449 } 3450 3451 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3452 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3453 printf("Device doesn't support RAW data-path APIs.\n"); 3454 return TEST_SKIPPED; 3455 } 3456 3457 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3458 return TEST_SKIPPED; 3459 3460 /* Verify the capabilities */ 3461 struct rte_cryptodev_sym_capability_idx cap_idx; 3462 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3463 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3464 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3465 &cap_idx) == NULL) 3466 return TEST_SKIPPED; 3467 3468 /* Create SNOW 3G session */ 3469 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3470 tdata->key.data, tdata->key.len, 3471 tdata->auth_iv.len, tdata->digest.len, 3472 RTE_CRYPTO_AUTH_OP_VERIFY, 3473 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3474 if (retval < 0) 3475 return retval; 3476 /* alloc mbuf and set payload */ 3477 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3478 3479 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3480 rte_pktmbuf_tailroom(ut_params->ibuf)); 3481 3482 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3483 /* Append data which is padded to a multiple of */ 3484 /* the algorithms block size */ 3485 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3486 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3487 plaintext_pad_len); 3488 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3489 3490 /* Create SNOW 3G operation */ 3491 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3492 tdata->digest.len, 3493 tdata->auth_iv.data, tdata->auth_iv.len, 3494 plaintext_pad_len, 3495 RTE_CRYPTO_AUTH_OP_VERIFY, 3496 tdata->validAuthLenInBits.len, 3497 0); 3498 if (retval < 0) 3499 return retval; 3500 3501 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3502 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 3503 0); 3504 if (retval != TEST_SUCCESS) 3505 return retval; 3506 } else 3507 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3508 ut_params->op); 3509 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3510 ut_params->obuf = ut_params->op->sym->m_src; 3511 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 3512 uint8_t *, 3513 plaintext_pad_len); 3514 3515 /* Validate obuf */ 3516 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3517 return 0; 3518 else 3519 return -1; 3520 3521 return 0; 3522 } 3523 3524 static int 3525 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata) 3526 { 3527 struct crypto_testsuite_params *ts_params = &testsuite_params; 3528 struct crypto_unittest_params *ut_params = &unittest_params; 3529 3530 int retval; 3531 unsigned plaintext_pad_len; 3532 unsigned plaintext_len; 3533 uint8_t *plaintext; 3534 struct rte_cryptodev_info dev_info; 3535 3536 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3537 uint64_t feat_flags = dev_info.feature_flags; 3538 3539 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3540 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3541 printf("Device doesn't support RAW data-path APIs.\n"); 3542 return TEST_SKIPPED; 3543 } 3544 3545 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3546 return TEST_SKIPPED; 3547 3548 /* Verify the capabilities */ 3549 struct rte_cryptodev_sym_capability_idx cap_idx; 3550 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3551 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3552 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3553 &cap_idx) == NULL) 3554 return TEST_SKIPPED; 3555 3556 /* Create KASUMI session */ 3557 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3558 tdata->key.data, tdata->key.len, 3559 0, tdata->digest.len, 3560 RTE_CRYPTO_AUTH_OP_GENERATE, 3561 RTE_CRYPTO_AUTH_KASUMI_F9); 3562 if (retval < 0) 3563 return retval; 3564 3565 /* alloc mbuf and set payload */ 3566 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3567 3568 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3569 rte_pktmbuf_tailroom(ut_params->ibuf)); 3570 3571 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3572 /* Append data which is padded to a multiple of */ 3573 /* the algorithms block size */ 3574 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3575 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3576 plaintext_pad_len); 3577 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3578 3579 /* Create KASUMI operation */ 3580 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3581 NULL, 0, 3582 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3583 tdata->plaintext.len, 3584 0); 3585 if (retval < 0) 3586 return retval; 3587 3588 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3589 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 3590 ut_params->op); 3591 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3592 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 3593 0); 3594 if (retval != TEST_SUCCESS) 3595 return retval; 3596 } else 3597 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3598 ut_params->op); 3599 3600 ut_params->obuf = ut_params->op->sym->m_src; 3601 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3602 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 3603 uint8_t *, 3604 plaintext_pad_len); 3605 3606 /* Validate obuf */ 3607 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3608 ut_params->digest, 3609 tdata->digest.data, 3610 DIGEST_BYTE_LENGTH_KASUMI_F9, 3611 "KASUMI Generated auth tag not as expected"); 3612 3613 return 0; 3614 } 3615 3616 static int 3617 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata) 3618 { 3619 struct crypto_testsuite_params *ts_params = &testsuite_params; 3620 struct crypto_unittest_params *ut_params = &unittest_params; 3621 3622 int retval; 3623 unsigned plaintext_pad_len; 3624 unsigned plaintext_len; 3625 uint8_t *plaintext; 3626 struct rte_cryptodev_info dev_info; 3627 3628 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3629 uint64_t feat_flags = dev_info.feature_flags; 3630 3631 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3632 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3633 printf("Device doesn't support RAW data-path APIs.\n"); 3634 return TEST_SKIPPED; 3635 } 3636 3637 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3638 return TEST_SKIPPED; 3639 3640 /* Verify the capabilities */ 3641 struct rte_cryptodev_sym_capability_idx cap_idx; 3642 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3643 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3644 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3645 &cap_idx) == NULL) 3646 return TEST_SKIPPED; 3647 3648 /* Create KASUMI session */ 3649 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3650 tdata->key.data, tdata->key.len, 3651 0, tdata->digest.len, 3652 RTE_CRYPTO_AUTH_OP_VERIFY, 3653 RTE_CRYPTO_AUTH_KASUMI_F9); 3654 if (retval < 0) 3655 return retval; 3656 /* alloc mbuf and set payload */ 3657 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3658 3659 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3660 rte_pktmbuf_tailroom(ut_params->ibuf)); 3661 3662 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3663 /* Append data which is padded to a multiple */ 3664 /* of the algorithms block size */ 3665 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3666 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3667 plaintext_pad_len); 3668 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3669 3670 /* Create KASUMI operation */ 3671 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3672 tdata->digest.len, 3673 NULL, 0, 3674 plaintext_pad_len, 3675 RTE_CRYPTO_AUTH_OP_VERIFY, 3676 tdata->plaintext.len, 3677 0); 3678 if (retval < 0) 3679 return retval; 3680 3681 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3682 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 3683 0); 3684 if (retval != TEST_SUCCESS) 3685 return retval; 3686 } else 3687 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3688 ut_params->op); 3689 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3690 ut_params->obuf = ut_params->op->sym->m_src; 3691 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 3692 uint8_t *, 3693 plaintext_pad_len); 3694 3695 /* Validate obuf */ 3696 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3697 return 0; 3698 else 3699 return -1; 3700 3701 return 0; 3702 } 3703 3704 static int 3705 test_snow3g_hash_generate_test_case_1(void) 3706 { 3707 return test_snow3g_authentication(&snow3g_hash_test_case_1); 3708 } 3709 3710 static int 3711 test_snow3g_hash_generate_test_case_2(void) 3712 { 3713 return test_snow3g_authentication(&snow3g_hash_test_case_2); 3714 } 3715 3716 static int 3717 test_snow3g_hash_generate_test_case_3(void) 3718 { 3719 return test_snow3g_authentication(&snow3g_hash_test_case_3); 3720 } 3721 3722 static int 3723 test_snow3g_hash_generate_test_case_4(void) 3724 { 3725 return test_snow3g_authentication(&snow3g_hash_test_case_4); 3726 } 3727 3728 static int 3729 test_snow3g_hash_generate_test_case_5(void) 3730 { 3731 return test_snow3g_authentication(&snow3g_hash_test_case_5); 3732 } 3733 3734 static int 3735 test_snow3g_hash_generate_test_case_6(void) 3736 { 3737 return test_snow3g_authentication(&snow3g_hash_test_case_6); 3738 } 3739 3740 static int 3741 test_snow3g_hash_verify_test_case_1(void) 3742 { 3743 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1); 3744 3745 } 3746 3747 static int 3748 test_snow3g_hash_verify_test_case_2(void) 3749 { 3750 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2); 3751 } 3752 3753 static int 3754 test_snow3g_hash_verify_test_case_3(void) 3755 { 3756 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3); 3757 } 3758 3759 static int 3760 test_snow3g_hash_verify_test_case_4(void) 3761 { 3762 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4); 3763 } 3764 3765 static int 3766 test_snow3g_hash_verify_test_case_5(void) 3767 { 3768 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5); 3769 } 3770 3771 static int 3772 test_snow3g_hash_verify_test_case_6(void) 3773 { 3774 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6); 3775 } 3776 3777 static int 3778 test_kasumi_hash_generate_test_case_1(void) 3779 { 3780 return test_kasumi_authentication(&kasumi_hash_test_case_1); 3781 } 3782 3783 static int 3784 test_kasumi_hash_generate_test_case_2(void) 3785 { 3786 return test_kasumi_authentication(&kasumi_hash_test_case_2); 3787 } 3788 3789 static int 3790 test_kasumi_hash_generate_test_case_3(void) 3791 { 3792 return test_kasumi_authentication(&kasumi_hash_test_case_3); 3793 } 3794 3795 static int 3796 test_kasumi_hash_generate_test_case_4(void) 3797 { 3798 return test_kasumi_authentication(&kasumi_hash_test_case_4); 3799 } 3800 3801 static int 3802 test_kasumi_hash_generate_test_case_5(void) 3803 { 3804 return test_kasumi_authentication(&kasumi_hash_test_case_5); 3805 } 3806 3807 static int 3808 test_kasumi_hash_generate_test_case_6(void) 3809 { 3810 return test_kasumi_authentication(&kasumi_hash_test_case_6); 3811 } 3812 3813 static int 3814 test_kasumi_hash_verify_test_case_1(void) 3815 { 3816 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1); 3817 } 3818 3819 static int 3820 test_kasumi_hash_verify_test_case_2(void) 3821 { 3822 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2); 3823 } 3824 3825 static int 3826 test_kasumi_hash_verify_test_case_3(void) 3827 { 3828 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3); 3829 } 3830 3831 static int 3832 test_kasumi_hash_verify_test_case_4(void) 3833 { 3834 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4); 3835 } 3836 3837 static int 3838 test_kasumi_hash_verify_test_case_5(void) 3839 { 3840 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5); 3841 } 3842 3843 static int 3844 test_kasumi_encryption(const struct kasumi_test_data *tdata) 3845 { 3846 struct crypto_testsuite_params *ts_params = &testsuite_params; 3847 struct crypto_unittest_params *ut_params = &unittest_params; 3848 3849 int retval; 3850 uint8_t *plaintext, *ciphertext; 3851 unsigned plaintext_pad_len; 3852 unsigned plaintext_len; 3853 struct rte_cryptodev_info dev_info; 3854 3855 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3856 uint64_t feat_flags = dev_info.feature_flags; 3857 3858 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3859 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3860 printf("Device doesn't support RAW data-path APIs.\n"); 3861 return TEST_SKIPPED; 3862 } 3863 3864 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3865 return TEST_SKIPPED; 3866 3867 /* Verify the capabilities */ 3868 struct rte_cryptodev_sym_capability_idx cap_idx; 3869 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3870 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3871 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3872 &cap_idx) == NULL) 3873 return TEST_SKIPPED; 3874 3875 /* Create KASUMI session */ 3876 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3877 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3878 RTE_CRYPTO_CIPHER_KASUMI_F8, 3879 tdata->key.data, tdata->key.len, 3880 tdata->cipher_iv.len); 3881 if (retval < 0) 3882 return retval; 3883 3884 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3885 3886 /* Clear mbuf payload */ 3887 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3888 rte_pktmbuf_tailroom(ut_params->ibuf)); 3889 3890 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3891 /* Append data which is padded to a multiple */ 3892 /* of the algorithms block size */ 3893 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3894 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3895 plaintext_pad_len); 3896 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3897 3898 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3899 3900 /* Create KASUMI operation */ 3901 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3902 tdata->cipher_iv.len, 3903 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3904 tdata->validCipherOffsetInBits.len); 3905 if (retval < 0) 3906 return retval; 3907 3908 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3909 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 3910 tdata->cipher_iv.len); 3911 if (retval != TEST_SUCCESS) 3912 return retval; 3913 } else 3914 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3915 ut_params->op); 3916 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3917 3918 ut_params->obuf = ut_params->op->sym->m_dst; 3919 if (ut_params->obuf) 3920 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3921 else 3922 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3923 3924 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3925 3926 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3927 (tdata->validCipherOffsetInBits.len >> 3); 3928 /* Validate obuf */ 3929 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3930 ciphertext, 3931 reference_ciphertext, 3932 tdata->validCipherLenInBits.len, 3933 "KASUMI Ciphertext data not as expected"); 3934 return 0; 3935 } 3936 3937 static int 3938 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata) 3939 { 3940 struct crypto_testsuite_params *ts_params = &testsuite_params; 3941 struct crypto_unittest_params *ut_params = &unittest_params; 3942 3943 int retval; 3944 3945 unsigned int plaintext_pad_len; 3946 unsigned int plaintext_len; 3947 3948 uint8_t buffer[10000]; 3949 const uint8_t *ciphertext; 3950 3951 struct rte_cryptodev_info dev_info; 3952 3953 /* Verify the capabilities */ 3954 struct rte_cryptodev_sym_capability_idx cap_idx; 3955 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3956 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3957 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3958 &cap_idx) == NULL) 3959 return TEST_SKIPPED; 3960 3961 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3962 3963 uint64_t feat_flags = dev_info.feature_flags; 3964 3965 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 3966 printf("Device doesn't support in-place scatter-gather. " 3967 "Test Skipped.\n"); 3968 return TEST_SKIPPED; 3969 } 3970 3971 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3972 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3973 printf("Device doesn't support RAW data-path APIs.\n"); 3974 return TEST_SKIPPED; 3975 } 3976 3977 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3978 return TEST_SKIPPED; 3979 3980 /* Create KASUMI session */ 3981 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3982 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3983 RTE_CRYPTO_CIPHER_KASUMI_F8, 3984 tdata->key.data, tdata->key.len, 3985 tdata->cipher_iv.len); 3986 if (retval < 0) 3987 return retval; 3988 3989 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3990 3991 3992 /* Append data which is padded to a multiple */ 3993 /* of the algorithms block size */ 3994 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3995 3996 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3997 plaintext_pad_len, 10, 0); 3998 3999 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 4000 4001 /* Create KASUMI operation */ 4002 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4003 tdata->cipher_iv.len, 4004 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4005 tdata->validCipherOffsetInBits.len); 4006 if (retval < 0) 4007 return retval; 4008 4009 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4010 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4011 tdata->cipher_iv.len); 4012 if (retval != TEST_SUCCESS) 4013 return retval; 4014 } else 4015 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4016 ut_params->op); 4017 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4018 4019 ut_params->obuf = ut_params->op->sym->m_dst; 4020 4021 if (ut_params->obuf) 4022 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4023 plaintext_len, buffer); 4024 else 4025 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 4026 tdata->validCipherOffsetInBits.len >> 3, 4027 plaintext_len, buffer); 4028 4029 /* Validate obuf */ 4030 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4031 4032 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 4033 (tdata->validCipherOffsetInBits.len >> 3); 4034 /* Validate obuf */ 4035 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4036 ciphertext, 4037 reference_ciphertext, 4038 tdata->validCipherLenInBits.len, 4039 "KASUMI Ciphertext data not as expected"); 4040 return 0; 4041 } 4042 4043 static int 4044 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata) 4045 { 4046 struct crypto_testsuite_params *ts_params = &testsuite_params; 4047 struct crypto_unittest_params *ut_params = &unittest_params; 4048 4049 int retval; 4050 uint8_t *plaintext, *ciphertext; 4051 unsigned plaintext_pad_len; 4052 unsigned plaintext_len; 4053 4054 /* Verify the capabilities */ 4055 struct rte_cryptodev_sym_capability_idx cap_idx; 4056 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4057 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4058 /* Data-path service does not support OOP */ 4059 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4060 &cap_idx) == NULL) 4061 return TEST_SKIPPED; 4062 4063 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4064 return TEST_SKIPPED; 4065 4066 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4067 return TEST_SKIPPED; 4068 4069 /* Create KASUMI session */ 4070 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4071 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4072 RTE_CRYPTO_CIPHER_KASUMI_F8, 4073 tdata->key.data, tdata->key.len, 4074 tdata->cipher_iv.len); 4075 if (retval < 0) 4076 return retval; 4077 4078 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4079 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4080 4081 /* Clear mbuf payload */ 4082 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4083 rte_pktmbuf_tailroom(ut_params->ibuf)); 4084 4085 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4086 /* Append data which is padded to a multiple */ 4087 /* of the algorithms block size */ 4088 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 4089 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4090 plaintext_pad_len); 4091 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4092 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4093 4094 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4095 4096 /* Create KASUMI operation */ 4097 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4098 tdata->cipher_iv.len, 4099 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4100 tdata->validCipherOffsetInBits.len); 4101 if (retval < 0) 4102 return retval; 4103 4104 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4105 ut_params->op); 4106 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4107 4108 ut_params->obuf = ut_params->op->sym->m_dst; 4109 if (ut_params->obuf) 4110 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4111 else 4112 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 4113 4114 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4115 4116 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 4117 (tdata->validCipherOffsetInBits.len >> 3); 4118 /* Validate obuf */ 4119 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4120 ciphertext, 4121 reference_ciphertext, 4122 tdata->validCipherLenInBits.len, 4123 "KASUMI Ciphertext data not as expected"); 4124 return 0; 4125 } 4126 4127 static int 4128 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata) 4129 { 4130 struct crypto_testsuite_params *ts_params = &testsuite_params; 4131 struct crypto_unittest_params *ut_params = &unittest_params; 4132 4133 int retval; 4134 unsigned int plaintext_pad_len; 4135 unsigned int plaintext_len; 4136 4137 const uint8_t *ciphertext; 4138 uint8_t buffer[2048]; 4139 4140 struct rte_cryptodev_info dev_info; 4141 4142 /* Verify the capabilities */ 4143 struct rte_cryptodev_sym_capability_idx cap_idx; 4144 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4145 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4146 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4147 &cap_idx) == NULL) 4148 return TEST_SKIPPED; 4149 4150 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4151 return TEST_SKIPPED; 4152 4153 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4154 return TEST_SKIPPED; 4155 4156 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4157 4158 uint64_t feat_flags = dev_info.feature_flags; 4159 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 4160 printf("Device doesn't support out-of-place scatter-gather " 4161 "in both input and output mbufs. " 4162 "Test Skipped.\n"); 4163 return TEST_SKIPPED; 4164 } 4165 4166 /* Create KASUMI session */ 4167 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4168 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4169 RTE_CRYPTO_CIPHER_KASUMI_F8, 4170 tdata->key.data, tdata->key.len, 4171 tdata->cipher_iv.len); 4172 if (retval < 0) 4173 return retval; 4174 4175 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4176 /* Append data which is padded to a multiple */ 4177 /* of the algorithms block size */ 4178 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 4179 4180 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4181 plaintext_pad_len, 10, 0); 4182 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4183 plaintext_pad_len, 3, 0); 4184 4185 /* Append data which is padded to a multiple */ 4186 /* of the algorithms block size */ 4187 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 4188 4189 /* Create KASUMI operation */ 4190 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4191 tdata->cipher_iv.len, 4192 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4193 tdata->validCipherOffsetInBits.len); 4194 if (retval < 0) 4195 return retval; 4196 4197 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4198 ut_params->op); 4199 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4200 4201 ut_params->obuf = ut_params->op->sym->m_dst; 4202 if (ut_params->obuf) 4203 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4204 plaintext_pad_len, buffer); 4205 else 4206 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 4207 tdata->validCipherOffsetInBits.len >> 3, 4208 plaintext_pad_len, buffer); 4209 4210 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 4211 (tdata->validCipherOffsetInBits.len >> 3); 4212 /* Validate obuf */ 4213 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4214 ciphertext, 4215 reference_ciphertext, 4216 tdata->validCipherLenInBits.len, 4217 "KASUMI Ciphertext data not as expected"); 4218 return 0; 4219 } 4220 4221 4222 static int 4223 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata) 4224 { 4225 struct crypto_testsuite_params *ts_params = &testsuite_params; 4226 struct crypto_unittest_params *ut_params = &unittest_params; 4227 4228 int retval; 4229 uint8_t *ciphertext, *plaintext; 4230 unsigned ciphertext_pad_len; 4231 unsigned ciphertext_len; 4232 4233 /* Verify the capabilities */ 4234 struct rte_cryptodev_sym_capability_idx cap_idx; 4235 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4236 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4237 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4238 &cap_idx) == NULL) 4239 return TEST_SKIPPED; 4240 4241 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4242 return TEST_SKIPPED; 4243 4244 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4245 return TEST_SKIPPED; 4246 4247 /* Create KASUMI session */ 4248 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4249 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4250 RTE_CRYPTO_CIPHER_KASUMI_F8, 4251 tdata->key.data, tdata->key.len, 4252 tdata->cipher_iv.len); 4253 if (retval < 0) 4254 return retval; 4255 4256 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4257 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4258 4259 /* Clear mbuf payload */ 4260 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4261 rte_pktmbuf_tailroom(ut_params->ibuf)); 4262 4263 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4264 /* Append data which is padded to a multiple */ 4265 /* of the algorithms block size */ 4266 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4267 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4268 ciphertext_pad_len); 4269 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4270 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4271 4272 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4273 4274 /* Create KASUMI operation */ 4275 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4276 tdata->cipher_iv.len, 4277 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4278 tdata->validCipherOffsetInBits.len); 4279 if (retval < 0) 4280 return retval; 4281 4282 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4283 ut_params->op); 4284 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4285 4286 ut_params->obuf = ut_params->op->sym->m_dst; 4287 if (ut_params->obuf) 4288 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4289 else 4290 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4291 4292 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4293 4294 const uint8_t *reference_plaintext = tdata->plaintext.data + 4295 (tdata->validCipherOffsetInBits.len >> 3); 4296 /* Validate obuf */ 4297 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4298 plaintext, 4299 reference_plaintext, 4300 tdata->validCipherLenInBits.len, 4301 "KASUMI Plaintext data not as expected"); 4302 return 0; 4303 } 4304 4305 static int 4306 test_kasumi_decryption(const struct kasumi_test_data *tdata) 4307 { 4308 struct crypto_testsuite_params *ts_params = &testsuite_params; 4309 struct crypto_unittest_params *ut_params = &unittest_params; 4310 4311 int retval; 4312 uint8_t *ciphertext, *plaintext; 4313 unsigned ciphertext_pad_len; 4314 unsigned ciphertext_len; 4315 struct rte_cryptodev_info dev_info; 4316 4317 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4318 uint64_t feat_flags = dev_info.feature_flags; 4319 4320 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4321 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4322 printf("Device doesn't support RAW data-path APIs.\n"); 4323 return TEST_SKIPPED; 4324 } 4325 4326 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4327 return TEST_SKIPPED; 4328 4329 /* Verify the capabilities */ 4330 struct rte_cryptodev_sym_capability_idx cap_idx; 4331 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4332 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4333 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4334 &cap_idx) == NULL) 4335 return TEST_SKIPPED; 4336 4337 /* Create KASUMI session */ 4338 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4339 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4340 RTE_CRYPTO_CIPHER_KASUMI_F8, 4341 tdata->key.data, tdata->key.len, 4342 tdata->cipher_iv.len); 4343 if (retval < 0) 4344 return retval; 4345 4346 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4347 4348 /* Clear mbuf payload */ 4349 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4350 rte_pktmbuf_tailroom(ut_params->ibuf)); 4351 4352 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4353 /* Append data which is padded to a multiple */ 4354 /* of the algorithms block size */ 4355 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4356 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4357 ciphertext_pad_len); 4358 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4359 4360 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4361 4362 /* Create KASUMI operation */ 4363 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4364 tdata->cipher_iv.len, 4365 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4366 tdata->validCipherOffsetInBits.len); 4367 if (retval < 0) 4368 return retval; 4369 4370 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4371 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4372 0); 4373 if (retval != TEST_SUCCESS) 4374 return retval; 4375 } else 4376 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4377 ut_params->op); 4378 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4379 4380 ut_params->obuf = ut_params->op->sym->m_dst; 4381 if (ut_params->obuf) 4382 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4383 else 4384 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4385 4386 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4387 4388 const uint8_t *reference_plaintext = tdata->plaintext.data + 4389 (tdata->validCipherOffsetInBits.len >> 3); 4390 /* Validate obuf */ 4391 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4392 plaintext, 4393 reference_plaintext, 4394 tdata->validCipherLenInBits.len, 4395 "KASUMI Plaintext data not as expected"); 4396 return 0; 4397 } 4398 4399 static int 4400 test_snow3g_encryption(const struct snow3g_test_data *tdata) 4401 { 4402 struct crypto_testsuite_params *ts_params = &testsuite_params; 4403 struct crypto_unittest_params *ut_params = &unittest_params; 4404 4405 int retval; 4406 uint8_t *plaintext, *ciphertext; 4407 unsigned plaintext_pad_len; 4408 unsigned plaintext_len; 4409 struct rte_cryptodev_info dev_info; 4410 4411 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4412 uint64_t feat_flags = dev_info.feature_flags; 4413 4414 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4415 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4416 printf("Device doesn't support RAW data-path APIs.\n"); 4417 return TEST_SKIPPED; 4418 } 4419 4420 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4421 return TEST_SKIPPED; 4422 4423 /* Verify the capabilities */ 4424 struct rte_cryptodev_sym_capability_idx cap_idx; 4425 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4426 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4427 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4428 &cap_idx) == NULL) 4429 return TEST_SKIPPED; 4430 4431 /* Create SNOW 3G session */ 4432 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4433 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4434 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4435 tdata->key.data, tdata->key.len, 4436 tdata->cipher_iv.len); 4437 if (retval < 0) 4438 return retval; 4439 4440 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4441 4442 /* Clear mbuf payload */ 4443 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4444 rte_pktmbuf_tailroom(ut_params->ibuf)); 4445 4446 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4447 /* Append data which is padded to a multiple of */ 4448 /* the algorithms block size */ 4449 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4450 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4451 plaintext_pad_len); 4452 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4453 4454 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4455 4456 /* Create SNOW 3G operation */ 4457 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4458 tdata->cipher_iv.len, 4459 tdata->validCipherLenInBits.len, 4460 0); 4461 if (retval < 0) 4462 return retval; 4463 4464 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4465 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4466 tdata->cipher_iv.len); 4467 if (retval != TEST_SUCCESS) 4468 return retval; 4469 } else 4470 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4471 ut_params->op); 4472 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4473 4474 ut_params->obuf = ut_params->op->sym->m_dst; 4475 if (ut_params->obuf) 4476 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4477 else 4478 ciphertext = plaintext; 4479 4480 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4481 4482 /* Validate obuf */ 4483 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4484 ciphertext, 4485 tdata->ciphertext.data, 4486 tdata->validDataLenInBits.len, 4487 "SNOW 3G Ciphertext data not as expected"); 4488 return 0; 4489 } 4490 4491 4492 static int 4493 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) 4494 { 4495 struct crypto_testsuite_params *ts_params = &testsuite_params; 4496 struct crypto_unittest_params *ut_params = &unittest_params; 4497 uint8_t *plaintext, *ciphertext; 4498 4499 int retval; 4500 unsigned plaintext_pad_len; 4501 unsigned plaintext_len; 4502 struct rte_cryptodev_info dev_info; 4503 4504 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4505 uint64_t feat_flags = dev_info.feature_flags; 4506 4507 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4508 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4509 printf("Device does not support RAW data-path APIs.\n"); 4510 return -ENOTSUP; 4511 } 4512 4513 /* Verify the capabilities */ 4514 struct rte_cryptodev_sym_capability_idx cap_idx; 4515 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4516 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4517 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4518 &cap_idx) == NULL) 4519 return TEST_SKIPPED; 4520 4521 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4522 return TEST_SKIPPED; 4523 4524 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4525 return TEST_SKIPPED; 4526 4527 /* Create SNOW 3G session */ 4528 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4529 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4530 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4531 tdata->key.data, tdata->key.len, 4532 tdata->cipher_iv.len); 4533 if (retval < 0) 4534 return retval; 4535 4536 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4537 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4538 4539 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4540 "Failed to allocate input buffer in mempool"); 4541 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4542 "Failed to allocate output buffer in mempool"); 4543 4544 /* Clear mbuf payload */ 4545 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4546 rte_pktmbuf_tailroom(ut_params->ibuf)); 4547 4548 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4549 /* Append data which is padded to a multiple of */ 4550 /* the algorithms block size */ 4551 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4552 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4553 plaintext_pad_len); 4554 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4555 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4556 4557 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4558 4559 /* Create SNOW 3G operation */ 4560 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4561 tdata->cipher_iv.len, 4562 tdata->validCipherLenInBits.len, 4563 0); 4564 if (retval < 0) 4565 return retval; 4566 4567 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4568 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4569 tdata->cipher_iv.len); 4570 if (retval != TEST_SUCCESS) 4571 return retval; 4572 } else 4573 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4574 ut_params->op); 4575 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4576 4577 ut_params->obuf = ut_params->op->sym->m_dst; 4578 if (ut_params->obuf) 4579 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4580 else 4581 ciphertext = plaintext; 4582 4583 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4584 4585 /* Validate obuf */ 4586 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4587 ciphertext, 4588 tdata->ciphertext.data, 4589 tdata->validDataLenInBits.len, 4590 "SNOW 3G Ciphertext data not as expected"); 4591 return 0; 4592 } 4593 4594 static int 4595 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata, 4596 uint8_t sgl_in, uint8_t sgl_out) 4597 { 4598 struct crypto_testsuite_params *ts_params = &testsuite_params; 4599 struct crypto_unittest_params *ut_params = &unittest_params; 4600 4601 int retval; 4602 unsigned int plaintext_pad_len; 4603 unsigned int plaintext_len; 4604 uint8_t buffer[10000]; 4605 const uint8_t *ciphertext; 4606 4607 struct rte_cryptodev_info dev_info; 4608 4609 /* Verify the capabilities */ 4610 struct rte_cryptodev_sym_capability_idx cap_idx; 4611 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4612 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4613 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4614 &cap_idx) == NULL) 4615 return TEST_SKIPPED; 4616 4617 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4618 return TEST_SKIPPED; 4619 4620 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4621 return TEST_SKIPPED; 4622 4623 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4624 4625 uint64_t feat_flags = dev_info.feature_flags; 4626 4627 if (((sgl_in && sgl_out) && !(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 4628 || ((!sgl_in && sgl_out) && 4629 !(feat_flags & RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 4630 || ((sgl_in && !sgl_out) && 4631 !(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))) { 4632 printf("Device doesn't support out-of-place scatter gather type. " 4633 "Test Skipped.\n"); 4634 return TEST_SKIPPED; 4635 } 4636 4637 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4638 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4639 printf("Device does not support RAW data-path APIs.\n"); 4640 return -ENOTSUP; 4641 } 4642 4643 /* Create SNOW 3G session */ 4644 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4645 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4646 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4647 tdata->key.data, tdata->key.len, 4648 tdata->cipher_iv.len); 4649 if (retval < 0) 4650 return retval; 4651 4652 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4653 /* Append data which is padded to a multiple of */ 4654 /* the algorithms block size */ 4655 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4656 4657 if (sgl_in) 4658 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4659 plaintext_pad_len, 10, 0); 4660 else { 4661 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4662 rte_pktmbuf_append(ut_params->ibuf, plaintext_pad_len); 4663 } 4664 4665 if (sgl_out) 4666 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4667 plaintext_pad_len, 3, 0); 4668 else { 4669 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4670 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4671 } 4672 4673 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4674 "Failed to allocate input buffer in mempool"); 4675 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4676 "Failed to allocate output buffer in mempool"); 4677 4678 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 4679 4680 /* Create SNOW 3G operation */ 4681 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4682 tdata->cipher_iv.len, 4683 tdata->validCipherLenInBits.len, 4684 0); 4685 if (retval < 0) 4686 return retval; 4687 4688 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4689 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4690 tdata->cipher_iv.len); 4691 if (retval != TEST_SUCCESS) 4692 return retval; 4693 } else 4694 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4695 ut_params->op); 4696 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4697 4698 ut_params->obuf = ut_params->op->sym->m_dst; 4699 if (ut_params->obuf) 4700 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4701 plaintext_len, buffer); 4702 else 4703 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4704 plaintext_len, buffer); 4705 4706 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4707 4708 /* Validate obuf */ 4709 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4710 ciphertext, 4711 tdata->ciphertext.data, 4712 tdata->validDataLenInBits.len, 4713 "SNOW 3G Ciphertext data not as expected"); 4714 4715 return 0; 4716 } 4717 4718 /* Shift right a buffer by "offset" bits, "offset" < 8 */ 4719 static void 4720 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) 4721 { 4722 uint8_t curr_byte, prev_byte; 4723 uint32_t length_in_bytes = ceil_byte_length(length + offset); 4724 uint8_t lower_byte_mask = (1 << offset) - 1; 4725 unsigned i; 4726 4727 prev_byte = buffer[0]; 4728 buffer[0] >>= offset; 4729 4730 for (i = 1; i < length_in_bytes; i++) { 4731 curr_byte = buffer[i]; 4732 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | 4733 (curr_byte >> offset); 4734 prev_byte = curr_byte; 4735 } 4736 } 4737 4738 static int 4739 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) 4740 { 4741 struct crypto_testsuite_params *ts_params = &testsuite_params; 4742 struct crypto_unittest_params *ut_params = &unittest_params; 4743 uint8_t *plaintext, *ciphertext; 4744 int retval; 4745 uint32_t plaintext_len; 4746 uint32_t plaintext_pad_len; 4747 uint8_t extra_offset = 4; 4748 uint8_t *expected_ciphertext_shifted; 4749 struct rte_cryptodev_info dev_info; 4750 4751 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4752 uint64_t feat_flags = dev_info.feature_flags; 4753 4754 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4755 ((tdata->validDataLenInBits.len % 8) != 0)) { 4756 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4757 return TEST_SKIPPED; 4758 } 4759 4760 /* Verify the capabilities */ 4761 struct rte_cryptodev_sym_capability_idx cap_idx; 4762 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4763 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4764 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4765 &cap_idx) == NULL) 4766 return TEST_SKIPPED; 4767 4768 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4769 return TEST_SKIPPED; 4770 4771 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4772 return TEST_SKIPPED; 4773 4774 /* Create SNOW 3G session */ 4775 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4776 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4777 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4778 tdata->key.data, tdata->key.len, 4779 tdata->cipher_iv.len); 4780 if (retval < 0) 4781 return retval; 4782 4783 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4784 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4785 4786 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4787 "Failed to allocate input buffer in mempool"); 4788 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4789 "Failed to allocate output buffer in mempool"); 4790 4791 /* Clear mbuf payload */ 4792 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4793 rte_pktmbuf_tailroom(ut_params->ibuf)); 4794 4795 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset); 4796 /* 4797 * Append data which is padded to a 4798 * multiple of the algorithms block size 4799 */ 4800 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4801 4802 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, 4803 plaintext_pad_len); 4804 4805 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4806 4807 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); 4808 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); 4809 4810 #ifdef RTE_APP_TEST_DEBUG 4811 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); 4812 #endif 4813 /* Create SNOW 3G operation */ 4814 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4815 tdata->cipher_iv.len, 4816 tdata->validCipherLenInBits.len, 4817 extra_offset); 4818 if (retval < 0) 4819 return retval; 4820 4821 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4822 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4823 tdata->cipher_iv.len); 4824 if (retval != TEST_SUCCESS) 4825 return retval; 4826 } else 4827 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4828 ut_params->op); 4829 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4830 4831 ut_params->obuf = ut_params->op->sym->m_dst; 4832 if (ut_params->obuf) 4833 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4834 else 4835 ciphertext = plaintext; 4836 4837 #ifdef RTE_APP_TEST_DEBUG 4838 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4839 #endif 4840 4841 expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8); 4842 4843 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, 4844 "failed to reserve memory for ciphertext shifted\n"); 4845 4846 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, 4847 ceil_byte_length(tdata->ciphertext.len)); 4848 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, 4849 extra_offset); 4850 /* Validate obuf */ 4851 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4852 ciphertext, 4853 expected_ciphertext_shifted, 4854 tdata->validDataLenInBits.len, 4855 extra_offset, 4856 "SNOW 3G Ciphertext data not as expected"); 4857 return 0; 4858 } 4859 4860 static int test_snow3g_decryption(const struct snow3g_test_data *tdata) 4861 { 4862 struct crypto_testsuite_params *ts_params = &testsuite_params; 4863 struct crypto_unittest_params *ut_params = &unittest_params; 4864 4865 int retval; 4866 4867 uint8_t *plaintext, *ciphertext; 4868 unsigned ciphertext_pad_len; 4869 unsigned ciphertext_len; 4870 struct rte_cryptodev_info dev_info; 4871 4872 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4873 uint64_t feat_flags = dev_info.feature_flags; 4874 4875 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4876 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4877 printf("Device doesn't support RAW data-path APIs.\n"); 4878 return TEST_SKIPPED; 4879 } 4880 4881 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4882 return TEST_SKIPPED; 4883 4884 /* Verify the capabilities */ 4885 struct rte_cryptodev_sym_capability_idx cap_idx; 4886 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4887 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4888 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4889 &cap_idx) == NULL) 4890 return TEST_SKIPPED; 4891 4892 /* Create SNOW 3G session */ 4893 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4894 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4895 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4896 tdata->key.data, tdata->key.len, 4897 tdata->cipher_iv.len); 4898 if (retval < 0) 4899 return retval; 4900 4901 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4902 4903 /* Clear mbuf payload */ 4904 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4905 rte_pktmbuf_tailroom(ut_params->ibuf)); 4906 4907 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4908 /* Append data which is padded to a multiple of */ 4909 /* the algorithms block size */ 4910 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4911 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4912 ciphertext_pad_len); 4913 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4914 4915 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4916 4917 /* Create SNOW 3G operation */ 4918 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4919 tdata->cipher_iv.len, 4920 tdata->validCipherLenInBits.len, 4921 tdata->cipher.offset_bits); 4922 if (retval < 0) 4923 return retval; 4924 4925 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4926 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4927 tdata->cipher_iv.len); 4928 if (retval != TEST_SUCCESS) 4929 return retval; 4930 } else 4931 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4932 ut_params->op); 4933 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4934 ut_params->obuf = ut_params->op->sym->m_dst; 4935 if (ut_params->obuf) 4936 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4937 else 4938 plaintext = ciphertext; 4939 4940 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4941 4942 /* Validate obuf */ 4943 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4944 tdata->plaintext.data, 4945 tdata->validDataLenInBits.len, 4946 "SNOW 3G Plaintext data not as expected"); 4947 return 0; 4948 } 4949 4950 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) 4951 { 4952 struct crypto_testsuite_params *ts_params = &testsuite_params; 4953 struct crypto_unittest_params *ut_params = &unittest_params; 4954 4955 int retval; 4956 4957 uint8_t *plaintext, *ciphertext; 4958 unsigned ciphertext_pad_len; 4959 unsigned ciphertext_len; 4960 struct rte_cryptodev_info dev_info; 4961 4962 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4963 uint64_t feat_flags = dev_info.feature_flags; 4964 4965 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4966 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4967 printf("Device does not support RAW data-path APIs.\n"); 4968 return -ENOTSUP; 4969 } 4970 /* Verify the capabilities */ 4971 struct rte_cryptodev_sym_capability_idx cap_idx; 4972 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4973 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4974 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4975 &cap_idx) == NULL) 4976 return TEST_SKIPPED; 4977 4978 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4979 return TEST_SKIPPED; 4980 4981 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4982 return TEST_SKIPPED; 4983 4984 /* Create SNOW 3G session */ 4985 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4986 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4987 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4988 tdata->key.data, tdata->key.len, 4989 tdata->cipher_iv.len); 4990 if (retval < 0) 4991 return retval; 4992 4993 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4994 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4995 4996 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4997 "Failed to allocate input buffer"); 4998 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4999 "Failed to allocate output buffer"); 5000 5001 /* Clear mbuf payload */ 5002 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5003 rte_pktmbuf_tailroom(ut_params->ibuf)); 5004 5005 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5006 rte_pktmbuf_tailroom(ut_params->obuf)); 5007 5008 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5009 /* Append data which is padded to a multiple of */ 5010 /* the algorithms block size */ 5011 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5012 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5013 ciphertext_pad_len); 5014 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5015 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5016 5017 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 5018 5019 /* Create SNOW 3G operation */ 5020 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 5021 tdata->cipher_iv.len, 5022 tdata->validCipherLenInBits.len, 5023 0); 5024 if (retval < 0) 5025 return retval; 5026 5027 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5028 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 5029 tdata->cipher_iv.len); 5030 if (retval != TEST_SUCCESS) 5031 return retval; 5032 } else 5033 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5034 ut_params->op); 5035 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5036 ut_params->obuf = ut_params->op->sym->m_dst; 5037 if (ut_params->obuf) 5038 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 5039 else 5040 plaintext = ciphertext; 5041 5042 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 5043 5044 /* Validate obuf */ 5045 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 5046 tdata->plaintext.data, 5047 tdata->validDataLenInBits.len, 5048 "SNOW 3G Plaintext data not as expected"); 5049 return 0; 5050 } 5051 5052 static int 5053 test_zuc_cipher_auth(const struct wireless_test_data *tdata) 5054 { 5055 struct crypto_testsuite_params *ts_params = &testsuite_params; 5056 struct crypto_unittest_params *ut_params = &unittest_params; 5057 5058 int retval; 5059 5060 uint8_t *plaintext, *ciphertext; 5061 unsigned int plaintext_pad_len; 5062 unsigned int plaintext_len; 5063 5064 struct rte_cryptodev_info dev_info; 5065 5066 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5067 uint64_t feat_flags = dev_info.feature_flags; 5068 5069 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 5070 ((tdata->validAuthLenInBits.len % 8 != 0) || 5071 (tdata->validDataLenInBits.len % 8 != 0))) { 5072 printf("Device doesn't support NON-Byte Aligned Data.\n"); 5073 return TEST_SKIPPED; 5074 } 5075 5076 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5077 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5078 printf("Device doesn't support RAW data-path APIs.\n"); 5079 return TEST_SKIPPED; 5080 } 5081 5082 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5083 return TEST_SKIPPED; 5084 5085 /* Check if device supports ZUC EEA3 */ 5086 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 5087 tdata->key.len, tdata->cipher_iv.len) < 0) 5088 return TEST_SKIPPED; 5089 5090 /* Check if device supports ZUC EIA3 */ 5091 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 5092 tdata->key.len, tdata->auth_iv.len, 5093 tdata->digest.len) < 0) 5094 return TEST_SKIPPED; 5095 5096 /* Create ZUC session */ 5097 retval = create_zuc_cipher_auth_encrypt_generate_session( 5098 ts_params->valid_devs[0], 5099 tdata); 5100 if (retval != 0) 5101 return retval; 5102 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5103 5104 /* clear mbuf payload */ 5105 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5106 rte_pktmbuf_tailroom(ut_params->ibuf)); 5107 5108 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5109 /* Append data which is padded to a multiple of */ 5110 /* the algorithms block size */ 5111 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5112 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5113 plaintext_pad_len); 5114 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5115 5116 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5117 5118 /* Create ZUC operation */ 5119 retval = create_zuc_cipher_hash_generate_operation(tdata); 5120 if (retval < 0) 5121 return retval; 5122 5123 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5124 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5125 tdata->cipher_iv.len); 5126 if (retval != TEST_SUCCESS) 5127 return retval; 5128 } else 5129 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5130 ut_params->op); 5131 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5132 ut_params->obuf = ut_params->op->sym->m_src; 5133 if (ut_params->obuf) 5134 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 5135 else 5136 ciphertext = plaintext; 5137 5138 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 5139 /* Validate obuf */ 5140 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5141 ciphertext, 5142 tdata->ciphertext.data, 5143 tdata->validDataLenInBits.len, 5144 "ZUC Ciphertext data not as expected"); 5145 5146 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 5147 uint8_t *, 5148 plaintext_pad_len); 5149 5150 /* Validate obuf */ 5151 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5152 ut_params->digest, 5153 tdata->digest.data, 5154 tdata->digest.len, 5155 "ZUC Generated auth tag not as expected"); 5156 return 0; 5157 } 5158 5159 static int 5160 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) 5161 { 5162 struct crypto_testsuite_params *ts_params = &testsuite_params; 5163 struct crypto_unittest_params *ut_params = &unittest_params; 5164 5165 int retval; 5166 5167 uint8_t *plaintext, *ciphertext; 5168 unsigned plaintext_pad_len; 5169 unsigned plaintext_len; 5170 struct rte_cryptodev_info dev_info; 5171 5172 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5173 uint64_t feat_flags = dev_info.feature_flags; 5174 5175 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5176 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5177 printf("Device doesn't support RAW data-path APIs.\n"); 5178 return TEST_SKIPPED; 5179 } 5180 5181 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5182 return TEST_SKIPPED; 5183 5184 /* Verify the capabilities */ 5185 struct rte_cryptodev_sym_capability_idx cap_idx; 5186 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5187 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5188 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5189 &cap_idx) == NULL) 5190 return TEST_SKIPPED; 5191 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5192 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5193 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5194 &cap_idx) == NULL) 5195 return TEST_SKIPPED; 5196 5197 /* Create SNOW 3G session */ 5198 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0], 5199 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5200 RTE_CRYPTO_AUTH_OP_GENERATE, 5201 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5202 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5203 tdata->key.data, tdata->key.len, 5204 tdata->key.data, tdata->key.len, 5205 tdata->auth_iv.len, tdata->digest.len, 5206 tdata->cipher_iv.len); 5207 if (retval != 0) 5208 return retval; 5209 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5210 5211 /* clear mbuf payload */ 5212 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5213 rte_pktmbuf_tailroom(ut_params->ibuf)); 5214 5215 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5216 /* Append data which is padded to a multiple of */ 5217 /* the algorithms block size */ 5218 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5219 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5220 plaintext_pad_len); 5221 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5222 5223 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5224 5225 /* Create SNOW 3G operation */ 5226 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 5227 tdata->digest.len, tdata->auth_iv.data, 5228 tdata->auth_iv.len, 5229 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5230 tdata->cipher_iv.data, tdata->cipher_iv.len, 5231 tdata->validCipherLenInBits.len, 5232 0, 5233 tdata->validAuthLenInBits.len, 5234 0 5235 ); 5236 if (retval < 0) 5237 return retval; 5238 5239 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5240 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5241 tdata->cipher_iv.len); 5242 if (retval != TEST_SUCCESS) 5243 return retval; 5244 } else 5245 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5246 ut_params->op); 5247 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5248 ut_params->obuf = ut_params->op->sym->m_src; 5249 if (ut_params->obuf) 5250 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 5251 else 5252 ciphertext = plaintext; 5253 5254 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 5255 /* Validate obuf */ 5256 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5257 ciphertext, 5258 tdata->ciphertext.data, 5259 tdata->validDataLenInBits.len, 5260 "SNOW 3G Ciphertext data not as expected"); 5261 5262 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 5263 uint8_t *, 5264 plaintext_pad_len); 5265 5266 /* Validate obuf */ 5267 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5268 ut_params->digest, 5269 tdata->digest.data, 5270 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5271 "SNOW 3G Generated auth tag not as expected"); 5272 return 0; 5273 } 5274 5275 static int 5276 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata, 5277 uint8_t op_mode, uint8_t verify) 5278 { 5279 struct crypto_testsuite_params *ts_params = &testsuite_params; 5280 struct crypto_unittest_params *ut_params = &unittest_params; 5281 5282 int retval; 5283 5284 uint8_t *plaintext = NULL, *ciphertext = NULL; 5285 unsigned int plaintext_pad_len; 5286 unsigned int plaintext_len; 5287 unsigned int ciphertext_pad_len; 5288 unsigned int ciphertext_len; 5289 unsigned int digest_offset; 5290 5291 struct rte_cryptodev_info dev_info; 5292 5293 /* Verify the capabilities */ 5294 struct rte_cryptodev_sym_capability_idx cap_idx; 5295 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5296 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5297 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5298 &cap_idx) == NULL) 5299 return TEST_SKIPPED; 5300 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5301 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5302 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5303 &cap_idx) == NULL) 5304 return TEST_SKIPPED; 5305 5306 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5307 return TEST_SKIPPED; 5308 5309 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5310 5311 uint64_t feat_flags = dev_info.feature_flags; 5312 5313 if (op_mode == OUT_OF_PLACE) { 5314 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5315 printf("Device doesn't support digest encrypted.\n"); 5316 return TEST_SKIPPED; 5317 } 5318 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5319 return TEST_SKIPPED; 5320 } 5321 5322 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5323 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5324 printf("Device doesn't support RAW data-path APIs.\n"); 5325 return TEST_SKIPPED; 5326 } 5327 5328 /* Create SNOW 3G session */ 5329 retval = create_wireless_algo_auth_cipher_session( 5330 ts_params->valid_devs[0], 5331 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5332 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5333 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5334 : RTE_CRYPTO_AUTH_OP_GENERATE), 5335 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5336 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5337 tdata->key.data, tdata->key.len, 5338 tdata->key.data, tdata->key.len, 5339 tdata->auth_iv.len, tdata->digest.len, 5340 tdata->cipher_iv.len); 5341 if (retval != 0) 5342 return retval; 5343 5344 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5345 if (op_mode == OUT_OF_PLACE) 5346 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5347 5348 /* clear mbuf payload */ 5349 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5350 rte_pktmbuf_tailroom(ut_params->ibuf)); 5351 if (op_mode == OUT_OF_PLACE) 5352 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5353 rte_pktmbuf_tailroom(ut_params->obuf)); 5354 5355 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5356 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5357 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5358 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5359 5360 if (verify) { 5361 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5362 ciphertext_pad_len); 5363 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5364 if (op_mode == OUT_OF_PLACE) 5365 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5366 debug_hexdump(stdout, "ciphertext:", ciphertext, 5367 ciphertext_len); 5368 } else { 5369 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5370 plaintext_pad_len); 5371 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5372 if (op_mode == OUT_OF_PLACE) 5373 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5374 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5375 } 5376 5377 /* Create SNOW 3G operation */ 5378 retval = create_wireless_algo_auth_cipher_operation( 5379 tdata->digest.data, tdata->digest.len, 5380 tdata->cipher_iv.data, tdata->cipher_iv.len, 5381 tdata->auth_iv.data, tdata->auth_iv.len, 5382 (tdata->digest.offset_bytes == 0 ? 5383 (verify ? ciphertext_pad_len : plaintext_pad_len) 5384 : tdata->digest.offset_bytes), 5385 tdata->validCipherLenInBits.len, 5386 tdata->cipher.offset_bits, 5387 tdata->validAuthLenInBits.len, 5388 tdata->auth.offset_bits, 5389 op_mode, 0, verify); 5390 5391 if (retval < 0) 5392 return retval; 5393 5394 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5395 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5396 tdata->cipher_iv.len); 5397 if (retval != TEST_SUCCESS) 5398 return retval; 5399 } else 5400 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5401 ut_params->op); 5402 5403 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5404 5405 ut_params->obuf = (op_mode == IN_PLACE ? 5406 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5407 5408 if (verify) { 5409 if (ut_params->obuf) 5410 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5411 uint8_t *); 5412 else 5413 plaintext = ciphertext + 5414 (tdata->cipher.offset_bits >> 3); 5415 5416 debug_hexdump(stdout, "plaintext:", plaintext, 5417 (tdata->plaintext.len >> 3) - tdata->digest.len); 5418 debug_hexdump(stdout, "plaintext expected:", 5419 tdata->plaintext.data, 5420 (tdata->plaintext.len >> 3) - tdata->digest.len); 5421 } else { 5422 if (ut_params->obuf) 5423 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5424 uint8_t *); 5425 else 5426 ciphertext = plaintext; 5427 5428 debug_hexdump(stdout, "ciphertext:", ciphertext, 5429 ciphertext_len); 5430 debug_hexdump(stdout, "ciphertext expected:", 5431 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5432 5433 if (tdata->digest.offset_bytes == 0) 5434 digest_offset = plaintext_pad_len; 5435 else 5436 digest_offset = tdata->digest.offset_bytes; 5437 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 5438 uint8_t *, digest_offset); 5439 5440 debug_hexdump(stdout, "digest:", ut_params->digest, 5441 tdata->digest.len); 5442 debug_hexdump(stdout, "digest expected:", tdata->digest.data, 5443 tdata->digest.len); 5444 } 5445 5446 /* Validate obuf */ 5447 if (verify) { 5448 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5449 plaintext, 5450 tdata->plaintext.data, 5451 (tdata->plaintext.len - tdata->cipher.offset_bits - 5452 (tdata->digest.len << 3)), 5453 tdata->cipher.offset_bits, 5454 "SNOW 3G Plaintext data not as expected"); 5455 } else { 5456 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5457 ciphertext, 5458 tdata->ciphertext.data, 5459 (tdata->validDataLenInBits.len - 5460 tdata->cipher.offset_bits), 5461 tdata->cipher.offset_bits, 5462 "SNOW 3G Ciphertext data not as expected"); 5463 5464 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5465 ut_params->digest, 5466 tdata->digest.data, 5467 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5468 "SNOW 3G Generated auth tag not as expected"); 5469 } 5470 return 0; 5471 } 5472 5473 static int 5474 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata, 5475 uint8_t op_mode, uint8_t verify) 5476 { 5477 struct crypto_testsuite_params *ts_params = &testsuite_params; 5478 struct crypto_unittest_params *ut_params = &unittest_params; 5479 5480 int retval; 5481 5482 const uint8_t *plaintext = NULL; 5483 const uint8_t *ciphertext = NULL; 5484 const uint8_t *digest = NULL; 5485 unsigned int plaintext_pad_len; 5486 unsigned int plaintext_len; 5487 unsigned int ciphertext_pad_len; 5488 unsigned int ciphertext_len; 5489 uint8_t buffer[10000]; 5490 uint8_t digest_buffer[10000]; 5491 5492 struct rte_cryptodev_info dev_info; 5493 5494 /* Verify the capabilities */ 5495 struct rte_cryptodev_sym_capability_idx cap_idx; 5496 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5497 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5498 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5499 &cap_idx) == NULL) 5500 return TEST_SKIPPED; 5501 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5502 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5503 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5504 &cap_idx) == NULL) 5505 return TEST_SKIPPED; 5506 5507 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5508 return TEST_SKIPPED; 5509 5510 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5511 5512 uint64_t feat_flags = dev_info.feature_flags; 5513 5514 if (op_mode == IN_PLACE) { 5515 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5516 printf("Device doesn't support in-place scatter-gather " 5517 "in both input and output mbufs.\n"); 5518 return TEST_SKIPPED; 5519 } 5520 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5521 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5522 printf("Device doesn't support RAW data-path APIs.\n"); 5523 return TEST_SKIPPED; 5524 } 5525 } else { 5526 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5527 return TEST_SKIPPED; 5528 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5529 printf("Device doesn't support out-of-place scatter-gather " 5530 "in both input and output mbufs.\n"); 5531 return TEST_SKIPPED; 5532 } 5533 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5534 printf("Device doesn't support digest encrypted.\n"); 5535 return TEST_SKIPPED; 5536 } 5537 } 5538 5539 /* Create SNOW 3G session */ 5540 retval = create_wireless_algo_auth_cipher_session( 5541 ts_params->valid_devs[0], 5542 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5543 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5544 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5545 : RTE_CRYPTO_AUTH_OP_GENERATE), 5546 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5547 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5548 tdata->key.data, tdata->key.len, 5549 tdata->key.data, tdata->key.len, 5550 tdata->auth_iv.len, tdata->digest.len, 5551 tdata->cipher_iv.len); 5552 5553 if (retval != 0) 5554 return retval; 5555 5556 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5557 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5558 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5559 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5560 5561 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5562 plaintext_pad_len, 15, 0); 5563 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5564 "Failed to allocate input buffer in mempool"); 5565 5566 if (op_mode == OUT_OF_PLACE) { 5567 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5568 plaintext_pad_len, 15, 0); 5569 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5570 "Failed to allocate output buffer in mempool"); 5571 } 5572 5573 if (verify) { 5574 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5575 tdata->ciphertext.data); 5576 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5577 ciphertext_len, buffer); 5578 debug_hexdump(stdout, "ciphertext:", ciphertext, 5579 ciphertext_len); 5580 } else { 5581 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5582 tdata->plaintext.data); 5583 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5584 plaintext_len, buffer); 5585 debug_hexdump(stdout, "plaintext:", plaintext, 5586 plaintext_len); 5587 } 5588 memset(buffer, 0, sizeof(buffer)); 5589 5590 /* Create SNOW 3G operation */ 5591 retval = create_wireless_algo_auth_cipher_operation( 5592 tdata->digest.data, tdata->digest.len, 5593 tdata->cipher_iv.data, tdata->cipher_iv.len, 5594 tdata->auth_iv.data, tdata->auth_iv.len, 5595 (tdata->digest.offset_bytes == 0 ? 5596 (verify ? ciphertext_pad_len : plaintext_pad_len) 5597 : tdata->digest.offset_bytes), 5598 tdata->validCipherLenInBits.len, 5599 tdata->cipher.offset_bits, 5600 tdata->validAuthLenInBits.len, 5601 tdata->auth.offset_bits, 5602 op_mode, 1, verify); 5603 5604 if (retval < 0) 5605 return retval; 5606 5607 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5608 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5609 tdata->cipher_iv.len); 5610 if (retval != TEST_SUCCESS) 5611 return retval; 5612 } else 5613 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5614 ut_params->op); 5615 5616 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5617 5618 ut_params->obuf = (op_mode == IN_PLACE ? 5619 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5620 5621 if (verify) { 5622 if (ut_params->obuf) 5623 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5624 plaintext_len, buffer); 5625 else 5626 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5627 plaintext_len, buffer); 5628 5629 debug_hexdump(stdout, "plaintext:", plaintext, 5630 (tdata->plaintext.len >> 3) - tdata->digest.len); 5631 debug_hexdump(stdout, "plaintext expected:", 5632 tdata->plaintext.data, 5633 (tdata->plaintext.len >> 3) - tdata->digest.len); 5634 } else { 5635 if (ut_params->obuf) 5636 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5637 ciphertext_len, buffer); 5638 else 5639 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5640 ciphertext_len, buffer); 5641 5642 debug_hexdump(stdout, "ciphertext:", ciphertext, 5643 ciphertext_len); 5644 debug_hexdump(stdout, "ciphertext expected:", 5645 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5646 5647 if (ut_params->obuf) 5648 digest = rte_pktmbuf_read(ut_params->obuf, 5649 (tdata->digest.offset_bytes == 0 ? 5650 plaintext_pad_len : tdata->digest.offset_bytes), 5651 tdata->digest.len, digest_buffer); 5652 else 5653 digest = rte_pktmbuf_read(ut_params->ibuf, 5654 (tdata->digest.offset_bytes == 0 ? 5655 plaintext_pad_len : tdata->digest.offset_bytes), 5656 tdata->digest.len, digest_buffer); 5657 5658 debug_hexdump(stdout, "digest:", digest, 5659 tdata->digest.len); 5660 debug_hexdump(stdout, "digest expected:", 5661 tdata->digest.data, tdata->digest.len); 5662 } 5663 5664 /* Validate obuf */ 5665 if (verify) { 5666 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5667 plaintext, 5668 tdata->plaintext.data, 5669 (tdata->plaintext.len - tdata->cipher.offset_bits - 5670 (tdata->digest.len << 3)), 5671 tdata->cipher.offset_bits, 5672 "SNOW 3G Plaintext data not as expected"); 5673 } else { 5674 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5675 ciphertext, 5676 tdata->ciphertext.data, 5677 (tdata->validDataLenInBits.len - 5678 tdata->cipher.offset_bits), 5679 tdata->cipher.offset_bits, 5680 "SNOW 3G Ciphertext data not as expected"); 5681 5682 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5683 digest, 5684 tdata->digest.data, 5685 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5686 "SNOW 3G Generated auth tag not as expected"); 5687 } 5688 return 0; 5689 } 5690 5691 static int 5692 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata, 5693 uint8_t op_mode, uint8_t verify) 5694 { 5695 struct crypto_testsuite_params *ts_params = &testsuite_params; 5696 struct crypto_unittest_params *ut_params = &unittest_params; 5697 5698 int retval; 5699 5700 uint8_t *plaintext = NULL, *ciphertext = NULL; 5701 unsigned int plaintext_pad_len; 5702 unsigned int plaintext_len; 5703 unsigned int ciphertext_pad_len; 5704 unsigned int ciphertext_len; 5705 unsigned int digest_offset; 5706 5707 struct rte_cryptodev_info dev_info; 5708 5709 /* Verify the capabilities */ 5710 struct rte_cryptodev_sym_capability_idx cap_idx; 5711 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5712 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5713 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5714 &cap_idx) == NULL) 5715 return TEST_SKIPPED; 5716 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5717 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5718 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5719 &cap_idx) == NULL) 5720 return TEST_SKIPPED; 5721 5722 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5723 5724 uint64_t feat_flags = dev_info.feature_flags; 5725 5726 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5727 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5728 printf("Device doesn't support RAW data-path APIs.\n"); 5729 return TEST_SKIPPED; 5730 } 5731 5732 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5733 return TEST_SKIPPED; 5734 5735 if (op_mode == OUT_OF_PLACE) { 5736 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5737 return TEST_SKIPPED; 5738 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5739 printf("Device doesn't support digest encrypted.\n"); 5740 return TEST_SKIPPED; 5741 } 5742 } 5743 5744 /* Create KASUMI session */ 5745 retval = create_wireless_algo_auth_cipher_session( 5746 ts_params->valid_devs[0], 5747 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5748 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5749 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5750 : RTE_CRYPTO_AUTH_OP_GENERATE), 5751 RTE_CRYPTO_AUTH_KASUMI_F9, 5752 RTE_CRYPTO_CIPHER_KASUMI_F8, 5753 tdata->key.data, tdata->key.len, 5754 tdata->key.data, tdata->key.len, 5755 0, tdata->digest.len, 5756 tdata->cipher_iv.len); 5757 5758 if (retval != 0) 5759 return retval; 5760 5761 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5762 if (op_mode == OUT_OF_PLACE) 5763 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5764 5765 /* clear mbuf payload */ 5766 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5767 rte_pktmbuf_tailroom(ut_params->ibuf)); 5768 if (op_mode == OUT_OF_PLACE) 5769 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5770 rte_pktmbuf_tailroom(ut_params->obuf)); 5771 5772 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5773 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5774 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5775 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5776 5777 if (verify) { 5778 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5779 ciphertext_pad_len); 5780 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5781 if (op_mode == OUT_OF_PLACE) 5782 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5783 debug_hexdump(stdout, "ciphertext:", ciphertext, 5784 ciphertext_len); 5785 } else { 5786 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5787 plaintext_pad_len); 5788 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5789 if (op_mode == OUT_OF_PLACE) 5790 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5791 debug_hexdump(stdout, "plaintext:", plaintext, 5792 plaintext_len); 5793 } 5794 5795 /* Create KASUMI operation */ 5796 retval = create_wireless_algo_auth_cipher_operation( 5797 tdata->digest.data, tdata->digest.len, 5798 tdata->cipher_iv.data, tdata->cipher_iv.len, 5799 NULL, 0, 5800 (tdata->digest.offset_bytes == 0 ? 5801 (verify ? ciphertext_pad_len : plaintext_pad_len) 5802 : tdata->digest.offset_bytes), 5803 tdata->validCipherLenInBits.len, 5804 tdata->validCipherOffsetInBits.len, 5805 tdata->validAuthLenInBits.len, 5806 0, 5807 op_mode, 0, verify); 5808 5809 if (retval < 0) 5810 return retval; 5811 5812 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5813 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5814 tdata->cipher_iv.len); 5815 if (retval != TEST_SUCCESS) 5816 return retval; 5817 } else 5818 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5819 ut_params->op); 5820 5821 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5822 5823 ut_params->obuf = (op_mode == IN_PLACE ? 5824 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5825 5826 5827 if (verify) { 5828 if (ut_params->obuf) 5829 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5830 uint8_t *); 5831 else 5832 plaintext = ciphertext; 5833 5834 debug_hexdump(stdout, "plaintext:", plaintext, 5835 (tdata->plaintext.len >> 3) - tdata->digest.len); 5836 debug_hexdump(stdout, "plaintext expected:", 5837 tdata->plaintext.data, 5838 (tdata->plaintext.len >> 3) - tdata->digest.len); 5839 } else { 5840 if (ut_params->obuf) 5841 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5842 uint8_t *); 5843 else 5844 ciphertext = plaintext; 5845 5846 debug_hexdump(stdout, "ciphertext:", ciphertext, 5847 ciphertext_len); 5848 debug_hexdump(stdout, "ciphertext expected:", 5849 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5850 5851 if (tdata->digest.offset_bytes == 0) 5852 digest_offset = plaintext_pad_len; 5853 else 5854 digest_offset = tdata->digest.offset_bytes; 5855 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 5856 uint8_t *, digest_offset); 5857 5858 debug_hexdump(stdout, "digest:", ut_params->digest, 5859 tdata->digest.len); 5860 debug_hexdump(stdout, "digest expected:", 5861 tdata->digest.data, tdata->digest.len); 5862 } 5863 5864 /* Validate obuf */ 5865 if (verify) { 5866 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5867 plaintext, 5868 tdata->plaintext.data, 5869 tdata->plaintext.len >> 3, 5870 "KASUMI Plaintext data not as expected"); 5871 } else { 5872 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5873 ciphertext, 5874 tdata->ciphertext.data, 5875 tdata->ciphertext.len >> 3, 5876 "KASUMI Ciphertext data not as expected"); 5877 5878 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5879 ut_params->digest, 5880 tdata->digest.data, 5881 DIGEST_BYTE_LENGTH_KASUMI_F9, 5882 "KASUMI Generated auth tag not as expected"); 5883 } 5884 return 0; 5885 } 5886 5887 static int 5888 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata, 5889 uint8_t op_mode, uint8_t verify) 5890 { 5891 struct crypto_testsuite_params *ts_params = &testsuite_params; 5892 struct crypto_unittest_params *ut_params = &unittest_params; 5893 5894 int retval; 5895 5896 const uint8_t *plaintext = NULL; 5897 const uint8_t *ciphertext = NULL; 5898 const uint8_t *digest = NULL; 5899 unsigned int plaintext_pad_len; 5900 unsigned int plaintext_len; 5901 unsigned int ciphertext_pad_len; 5902 unsigned int ciphertext_len; 5903 uint8_t buffer[10000]; 5904 uint8_t digest_buffer[10000]; 5905 5906 struct rte_cryptodev_info dev_info; 5907 5908 /* Verify the capabilities */ 5909 struct rte_cryptodev_sym_capability_idx cap_idx; 5910 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5911 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5912 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5913 &cap_idx) == NULL) 5914 return TEST_SKIPPED; 5915 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5916 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5917 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5918 &cap_idx) == NULL) 5919 return TEST_SKIPPED; 5920 5921 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5922 return TEST_SKIPPED; 5923 5924 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5925 5926 uint64_t feat_flags = dev_info.feature_flags; 5927 5928 if (op_mode == IN_PLACE) { 5929 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5930 printf("Device doesn't support in-place scatter-gather " 5931 "in both input and output mbufs.\n"); 5932 return TEST_SKIPPED; 5933 } 5934 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5935 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5936 printf("Device doesn't support RAW data-path APIs.\n"); 5937 return TEST_SKIPPED; 5938 } 5939 } else { 5940 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5941 return TEST_SKIPPED; 5942 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5943 printf("Device doesn't support out-of-place scatter-gather " 5944 "in both input and output mbufs.\n"); 5945 return TEST_SKIPPED; 5946 } 5947 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5948 printf("Device doesn't support digest encrypted.\n"); 5949 return TEST_SKIPPED; 5950 } 5951 } 5952 5953 /* Create KASUMI session */ 5954 retval = create_wireless_algo_auth_cipher_session( 5955 ts_params->valid_devs[0], 5956 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5957 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5958 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5959 : RTE_CRYPTO_AUTH_OP_GENERATE), 5960 RTE_CRYPTO_AUTH_KASUMI_F9, 5961 RTE_CRYPTO_CIPHER_KASUMI_F8, 5962 tdata->key.data, tdata->key.len, 5963 tdata->key.data, tdata->key.len, 5964 0, tdata->digest.len, 5965 tdata->cipher_iv.len); 5966 5967 if (retval != 0) 5968 return retval; 5969 5970 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5971 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5972 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5973 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5974 5975 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5976 plaintext_pad_len, 15, 0); 5977 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5978 "Failed to allocate input buffer in mempool"); 5979 5980 if (op_mode == OUT_OF_PLACE) { 5981 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5982 plaintext_pad_len, 15, 0); 5983 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5984 "Failed to allocate output buffer in mempool"); 5985 } 5986 5987 if (verify) { 5988 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5989 tdata->ciphertext.data); 5990 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5991 ciphertext_len, buffer); 5992 debug_hexdump(stdout, "ciphertext:", ciphertext, 5993 ciphertext_len); 5994 } else { 5995 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5996 tdata->plaintext.data); 5997 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5998 plaintext_len, buffer); 5999 debug_hexdump(stdout, "plaintext:", plaintext, 6000 plaintext_len); 6001 } 6002 memset(buffer, 0, sizeof(buffer)); 6003 6004 /* Create KASUMI operation */ 6005 retval = create_wireless_algo_auth_cipher_operation( 6006 tdata->digest.data, tdata->digest.len, 6007 tdata->cipher_iv.data, tdata->cipher_iv.len, 6008 NULL, 0, 6009 (tdata->digest.offset_bytes == 0 ? 6010 (verify ? ciphertext_pad_len : plaintext_pad_len) 6011 : tdata->digest.offset_bytes), 6012 tdata->validCipherLenInBits.len, 6013 tdata->validCipherOffsetInBits.len, 6014 tdata->validAuthLenInBits.len, 6015 0, 6016 op_mode, 1, verify); 6017 6018 if (retval < 0) 6019 return retval; 6020 6021 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6022 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 6023 tdata->cipher_iv.len); 6024 if (retval != TEST_SUCCESS) 6025 return retval; 6026 } else 6027 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6028 ut_params->op); 6029 6030 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6031 6032 ut_params->obuf = (op_mode == IN_PLACE ? 6033 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6034 6035 if (verify) { 6036 if (ut_params->obuf) 6037 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 6038 plaintext_len, buffer); 6039 else 6040 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6041 plaintext_len, buffer); 6042 6043 debug_hexdump(stdout, "plaintext:", plaintext, 6044 (tdata->plaintext.len >> 3) - tdata->digest.len); 6045 debug_hexdump(stdout, "plaintext expected:", 6046 tdata->plaintext.data, 6047 (tdata->plaintext.len >> 3) - tdata->digest.len); 6048 } else { 6049 if (ut_params->obuf) 6050 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 6051 ciphertext_len, buffer); 6052 else 6053 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6054 ciphertext_len, buffer); 6055 6056 debug_hexdump(stdout, "ciphertext:", ciphertext, 6057 ciphertext_len); 6058 debug_hexdump(stdout, "ciphertext expected:", 6059 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6060 6061 if (ut_params->obuf) 6062 digest = rte_pktmbuf_read(ut_params->obuf, 6063 (tdata->digest.offset_bytes == 0 ? 6064 plaintext_pad_len : tdata->digest.offset_bytes), 6065 tdata->digest.len, digest_buffer); 6066 else 6067 digest = rte_pktmbuf_read(ut_params->ibuf, 6068 (tdata->digest.offset_bytes == 0 ? 6069 plaintext_pad_len : tdata->digest.offset_bytes), 6070 tdata->digest.len, digest_buffer); 6071 6072 debug_hexdump(stdout, "digest:", digest, 6073 tdata->digest.len); 6074 debug_hexdump(stdout, "digest expected:", 6075 tdata->digest.data, tdata->digest.len); 6076 } 6077 6078 /* Validate obuf */ 6079 if (verify) { 6080 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6081 plaintext, 6082 tdata->plaintext.data, 6083 tdata->plaintext.len >> 3, 6084 "KASUMI Plaintext data not as expected"); 6085 } else { 6086 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6087 ciphertext, 6088 tdata->ciphertext.data, 6089 tdata->validDataLenInBits.len, 6090 "KASUMI Ciphertext data not as expected"); 6091 6092 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6093 digest, 6094 tdata->digest.data, 6095 DIGEST_BYTE_LENGTH_KASUMI_F9, 6096 "KASUMI Generated auth tag not as expected"); 6097 } 6098 return 0; 6099 } 6100 6101 static int 6102 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata) 6103 { 6104 struct crypto_testsuite_params *ts_params = &testsuite_params; 6105 struct crypto_unittest_params *ut_params = &unittest_params; 6106 6107 int retval; 6108 6109 uint8_t *plaintext, *ciphertext; 6110 unsigned plaintext_pad_len; 6111 unsigned plaintext_len; 6112 struct rte_cryptodev_info dev_info; 6113 6114 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6115 uint64_t feat_flags = dev_info.feature_flags; 6116 6117 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6118 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6119 printf("Device doesn't support RAW data-path APIs.\n"); 6120 return TEST_SKIPPED; 6121 } 6122 6123 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6124 return TEST_SKIPPED; 6125 6126 /* Verify the capabilities */ 6127 struct rte_cryptodev_sym_capability_idx cap_idx; 6128 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 6129 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 6130 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 6131 &cap_idx) == NULL) 6132 return TEST_SKIPPED; 6133 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 6134 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 6135 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 6136 &cap_idx) == NULL) 6137 return TEST_SKIPPED; 6138 6139 /* Create KASUMI session */ 6140 retval = create_wireless_algo_cipher_auth_session( 6141 ts_params->valid_devs[0], 6142 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6143 RTE_CRYPTO_AUTH_OP_GENERATE, 6144 RTE_CRYPTO_AUTH_KASUMI_F9, 6145 RTE_CRYPTO_CIPHER_KASUMI_F8, 6146 tdata->key.data, tdata->key.len, 6147 tdata->key.data, tdata->key.len, 6148 0, tdata->digest.len, 6149 tdata->cipher_iv.len); 6150 if (retval != 0) 6151 return retval; 6152 6153 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6154 6155 /* clear mbuf payload */ 6156 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6157 rte_pktmbuf_tailroom(ut_params->ibuf)); 6158 6159 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6160 /* Append data which is padded to a multiple of */ 6161 /* the algorithms block size */ 6162 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6163 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6164 plaintext_pad_len); 6165 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6166 6167 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6168 6169 /* Create KASUMI operation */ 6170 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 6171 tdata->digest.len, NULL, 0, 6172 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 6173 tdata->cipher_iv.data, tdata->cipher_iv.len, 6174 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 6175 tdata->validCipherOffsetInBits.len, 6176 tdata->validAuthLenInBits.len, 6177 0 6178 ); 6179 if (retval < 0) 6180 return retval; 6181 6182 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6183 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 6184 tdata->cipher_iv.len); 6185 if (retval != TEST_SUCCESS) 6186 return retval; 6187 } else 6188 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6189 ut_params->op); 6190 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6191 6192 if (ut_params->op->sym->m_dst) 6193 ut_params->obuf = ut_params->op->sym->m_dst; 6194 else 6195 ut_params->obuf = ut_params->op->sym->m_src; 6196 6197 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 6198 tdata->validCipherOffsetInBits.len >> 3); 6199 6200 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 6201 uint8_t *, 6202 plaintext_pad_len); 6203 6204 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 6205 (tdata->validCipherOffsetInBits.len >> 3); 6206 /* Validate obuf */ 6207 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6208 ciphertext, 6209 reference_ciphertext, 6210 tdata->validCipherLenInBits.len, 6211 "KASUMI Ciphertext data not as expected"); 6212 6213 /* Validate obuf */ 6214 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6215 ut_params->digest, 6216 tdata->digest.data, 6217 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 6218 "KASUMI Generated auth tag not as expected"); 6219 return 0; 6220 } 6221 6222 static int 6223 check_cipher_capability(const struct crypto_testsuite_params *ts_params, 6224 const enum rte_crypto_cipher_algorithm cipher_algo, 6225 const uint16_t key_size, const uint16_t iv_size) 6226 { 6227 struct rte_cryptodev_sym_capability_idx cap_idx; 6228 const struct rte_cryptodev_symmetric_capability *cap; 6229 6230 /* Check if device supports the algorithm */ 6231 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 6232 cap_idx.algo.cipher = cipher_algo; 6233 6234 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 6235 &cap_idx); 6236 6237 if (cap == NULL) 6238 return -1; 6239 6240 /* Check if device supports key size and IV size */ 6241 if (rte_cryptodev_sym_capability_check_cipher(cap, key_size, 6242 iv_size) < 0) { 6243 return -1; 6244 } 6245 6246 return 0; 6247 } 6248 6249 static int 6250 check_auth_capability(const struct crypto_testsuite_params *ts_params, 6251 const enum rte_crypto_auth_algorithm auth_algo, 6252 const uint16_t key_size, const uint16_t iv_size, 6253 const uint16_t tag_size) 6254 { 6255 struct rte_cryptodev_sym_capability_idx cap_idx; 6256 const struct rte_cryptodev_symmetric_capability *cap; 6257 6258 /* Check if device supports the algorithm */ 6259 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 6260 cap_idx.algo.auth = auth_algo; 6261 6262 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 6263 &cap_idx); 6264 6265 if (cap == NULL) 6266 return -1; 6267 6268 /* Check if device supports key size and IV size */ 6269 if (rte_cryptodev_sym_capability_check_auth(cap, key_size, 6270 tag_size, iv_size) < 0) { 6271 return -1; 6272 } 6273 6274 return 0; 6275 } 6276 6277 static int 6278 test_zuc_cipher(const struct wireless_test_data *tdata, 6279 enum rte_crypto_cipher_operation direction) 6280 { 6281 struct crypto_testsuite_params *ts_params = &testsuite_params; 6282 struct crypto_unittest_params *ut_params = &unittest_params; 6283 6284 int retval; 6285 uint8_t *plaintext = NULL; 6286 uint8_t *ciphertext = NULL; 6287 unsigned int plaintext_pad_len, ciphertext_pad_len; 6288 unsigned int plaintext_len = 0; 6289 unsigned int ciphertext_len = 0; 6290 struct rte_cryptodev_info dev_info; 6291 6292 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6293 uint64_t feat_flags = dev_info.feature_flags; 6294 6295 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6296 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6297 printf("Device doesn't support RAW data-path APIs.\n"); 6298 return TEST_SKIPPED; 6299 } 6300 6301 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6302 return TEST_SKIPPED; 6303 6304 /* Check if device supports ZUC EEA3 */ 6305 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6306 tdata->key.len, tdata->cipher_iv.len) < 0) 6307 return TEST_SKIPPED; 6308 6309 /* Create ZUC session */ 6310 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 6311 direction, 6312 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6313 tdata->key.data, tdata->key.len, 6314 tdata->cipher_iv.len); 6315 if (retval != 0) 6316 return retval; 6317 6318 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6319 6320 /* Clear mbuf payload */ 6321 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6322 rte_pktmbuf_tailroom(ut_params->ibuf)); 6323 6324 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6325 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6326 /* Append data which is padded to a multiple */ 6327 /* of the algorithms block size */ 6328 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6329 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6330 plaintext_pad_len); 6331 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6332 6333 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6334 } else { 6335 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6336 /* Append data which is padded to a multiple */ 6337 /* of the algorithms block size */ 6338 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 6339 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6340 ciphertext_pad_len); 6341 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6342 6343 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 6344 } 6345 6346 /* Create ZUC operation */ 6347 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6348 tdata->cipher_iv.len, 6349 tdata->plaintext.len, 6350 tdata->validCipherOffsetInBits.len); 6351 if (retval < 0) 6352 return retval; 6353 6354 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6355 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 6356 tdata->cipher_iv.len); 6357 if (retval != TEST_SUCCESS) 6358 return retval; 6359 } else 6360 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6361 ut_params->op); 6362 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6363 6364 ut_params->obuf = ut_params->op->sym->m_dst; 6365 6366 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6367 if (ut_params->obuf) 6368 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 6369 else 6370 ciphertext = plaintext; 6371 6372 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6373 6374 /* Validate obuf */ 6375 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6376 ciphertext, 6377 tdata->ciphertext.data, 6378 tdata->validCipherLenInBits.len, 6379 "ZUC Ciphertext data not as expected"); 6380 } else { 6381 if (ut_params->obuf) 6382 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 6383 else 6384 plaintext = ciphertext; 6385 6386 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 6387 6388 const uint8_t *reference_plaintext = tdata->plaintext.data + 6389 (tdata->validCipherOffsetInBits.len >> 3); 6390 6391 /* Validate obuf */ 6392 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6393 plaintext, 6394 reference_plaintext, 6395 tdata->validCipherLenInBits.len, 6396 "ZUC Plaintext data not as expected"); 6397 } 6398 6399 return 0; 6400 } 6401 6402 static int 6403 test_zuc_cipher_sgl(const struct wireless_test_data *tdata, 6404 enum rte_crypto_cipher_operation direction) 6405 { 6406 struct crypto_testsuite_params *ts_params = &testsuite_params; 6407 struct crypto_unittest_params *ut_params = &unittest_params; 6408 6409 int retval; 6410 6411 unsigned int plaintext_pad_len, ciphertext_pad_len; 6412 unsigned int plaintext_len = 0; 6413 unsigned int ciphertext_len = 0; 6414 const uint8_t *ciphertext, *plaintext; 6415 uint8_t buffer[2048]; 6416 struct rte_cryptodev_info dev_info; 6417 6418 /* Check if device supports ZUC EEA3 */ 6419 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6420 tdata->key.len, tdata->cipher_iv.len) < 0) 6421 return TEST_SKIPPED; 6422 6423 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6424 return TEST_SKIPPED; 6425 6426 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6427 6428 uint64_t feat_flags = dev_info.feature_flags; 6429 6430 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6431 printf("Device doesn't support in-place scatter-gather. " 6432 "Test Skipped.\n"); 6433 return TEST_SKIPPED; 6434 } 6435 6436 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6437 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6438 printf("Device doesn't support RAW data-path APIs.\n"); 6439 return TEST_SKIPPED; 6440 } 6441 6442 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6443 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6444 6445 /* Append data which is padded to a multiple */ 6446 /* of the algorithms block size */ 6447 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6448 6449 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6450 plaintext_pad_len, 10, 0); 6451 6452 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6453 tdata->plaintext.data); 6454 } else { 6455 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6456 6457 /* Append data which is padded to a multiple */ 6458 /* of the algorithms block size */ 6459 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 6460 6461 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6462 ciphertext_pad_len, 10, 0); 6463 6464 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6465 tdata->ciphertext.data); 6466 6467 } 6468 6469 /* Create ZUC session */ 6470 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 6471 direction, 6472 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6473 tdata->key.data, tdata->key.len, 6474 tdata->cipher_iv.len); 6475 if (retval < 0) 6476 return retval; 6477 6478 /* Clear mbuf payload */ 6479 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) 6480 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 6481 else 6482 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, tdata->ciphertext.data); 6483 6484 /* Create ZUC operation */ 6485 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6486 tdata->cipher_iv.len, tdata->plaintext.len, 6487 tdata->validCipherOffsetInBits.len); 6488 if (retval < 0) 6489 return retval; 6490 6491 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6492 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 6493 tdata->cipher_iv.len); 6494 if (retval != TEST_SUCCESS) 6495 return retval; 6496 } else 6497 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6498 ut_params->op); 6499 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6500 6501 ut_params->obuf = ut_params->op->sym->m_dst; 6502 6503 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6504 if (ut_params->obuf) 6505 ciphertext = rte_pktmbuf_read(ut_params->obuf, 6506 0, plaintext_len, buffer); 6507 else 6508 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 6509 0, plaintext_len, buffer); 6510 6511 /* Validate obuf */ 6512 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6513 6514 /* Validate obuf */ 6515 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6516 ciphertext, 6517 tdata->ciphertext.data, 6518 tdata->validCipherLenInBits.len, 6519 "ZUC Ciphertext data not as expected"); 6520 } else { 6521 if (ut_params->obuf) 6522 plaintext = rte_pktmbuf_read(ut_params->obuf, 6523 0, ciphertext_len, buffer); 6524 else 6525 plaintext = rte_pktmbuf_read(ut_params->ibuf, 6526 0, ciphertext_len, buffer); 6527 6528 /* Validate obuf */ 6529 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 6530 6531 /* Validate obuf */ 6532 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6533 plaintext, 6534 tdata->plaintext.data, 6535 tdata->validCipherLenInBits.len, 6536 "ZUC Plaintext data not as expected"); 6537 } 6538 6539 return 0; 6540 } 6541 6542 static int 6543 test_zuc_authentication(const struct wireless_test_data *tdata, 6544 enum rte_crypto_auth_operation auth_op) 6545 { 6546 struct crypto_testsuite_params *ts_params = &testsuite_params; 6547 struct crypto_unittest_params *ut_params = &unittest_params; 6548 6549 int retval; 6550 unsigned plaintext_pad_len; 6551 unsigned plaintext_len; 6552 uint8_t *plaintext; 6553 6554 struct rte_cryptodev_info dev_info; 6555 6556 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6557 uint64_t feat_flags = dev_info.feature_flags; 6558 6559 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 6560 (tdata->validAuthLenInBits.len % 8 != 0)) { 6561 printf("Device doesn't support NON-Byte Aligned Data.\n"); 6562 return TEST_SKIPPED; 6563 } 6564 6565 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6566 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6567 printf("Device doesn't support RAW data-path APIs.\n"); 6568 return TEST_SKIPPED; 6569 } 6570 6571 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6572 return TEST_SKIPPED; 6573 6574 /* Check if device supports ZUC EIA3 */ 6575 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6576 tdata->key.len, tdata->auth_iv.len, 6577 tdata->digest.len) < 0) 6578 return TEST_SKIPPED; 6579 6580 /* Create ZUC session */ 6581 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 6582 tdata->key.data, tdata->key.len, 6583 tdata->auth_iv.len, tdata->digest.len, 6584 auth_op, RTE_CRYPTO_AUTH_ZUC_EIA3); 6585 if (retval != 0) 6586 return retval; 6587 6588 /* alloc mbuf and set payload */ 6589 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6590 6591 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6592 rte_pktmbuf_tailroom(ut_params->ibuf)); 6593 6594 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6595 /* Append data which is padded to a multiple of */ 6596 /* the algorithms block size */ 6597 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6598 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6599 plaintext_pad_len); 6600 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6601 6602 /* Create ZUC operation */ 6603 retval = create_wireless_algo_hash_operation(tdata->digest.data, 6604 tdata->digest.len, 6605 tdata->auth_iv.data, tdata->auth_iv.len, 6606 plaintext_pad_len, 6607 auth_op, tdata->validAuthLenInBits.len, 0); 6608 if (retval < 0) 6609 return retval; 6610 6611 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6612 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 6613 0); 6614 if (retval != TEST_SUCCESS) 6615 return retval; 6616 } else 6617 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6618 ut_params->op); 6619 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6620 ut_params->obuf = ut_params->op->sym->m_src; 6621 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 6622 uint8_t *, 6623 plaintext_pad_len); 6624 6625 if (auth_op != RTE_CRYPTO_AUTH_OP_VERIFY) { 6626 /* Validate obuf */ 6627 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6628 ut_params->digest, 6629 tdata->digest.data, 6630 tdata->digest.len, 6631 "ZUC Generated auth tag not as expected"); 6632 return 0; 6633 } 6634 6635 /* Validate obuf */ 6636 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 6637 return 0; 6638 else 6639 return -1; 6640 6641 return 0; 6642 } 6643 6644 static int 6645 test_zuc_auth_cipher(const struct wireless_test_data *tdata, 6646 uint8_t op_mode, uint8_t verify) 6647 { 6648 struct crypto_testsuite_params *ts_params = &testsuite_params; 6649 struct crypto_unittest_params *ut_params = &unittest_params; 6650 6651 int retval; 6652 6653 uint8_t *plaintext = NULL, *ciphertext = NULL; 6654 unsigned int plaintext_pad_len; 6655 unsigned int plaintext_len; 6656 unsigned int ciphertext_pad_len; 6657 unsigned int ciphertext_len; 6658 unsigned int digest_offset; 6659 6660 struct rte_cryptodev_info dev_info; 6661 6662 /* Check if device supports ZUC EEA3 */ 6663 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6664 tdata->key.len, tdata->cipher_iv.len) < 0) 6665 return TEST_SKIPPED; 6666 6667 /* Check if device supports ZUC EIA3 */ 6668 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6669 tdata->key.len, tdata->auth_iv.len, 6670 tdata->digest.len) < 0) 6671 return TEST_SKIPPED; 6672 6673 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6674 return TEST_SKIPPED; 6675 6676 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6677 6678 uint64_t feat_flags = dev_info.feature_flags; 6679 6680 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6681 printf("Device doesn't support digest encrypted.\n"); 6682 return TEST_SKIPPED; 6683 } 6684 if (op_mode == IN_PLACE) { 6685 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6686 printf("Device doesn't support in-place scatter-gather " 6687 "in both input and output mbufs.\n"); 6688 return TEST_SKIPPED; 6689 } 6690 6691 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6692 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6693 printf("Device doesn't support RAW data-path APIs.\n"); 6694 return TEST_SKIPPED; 6695 } 6696 } else { 6697 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6698 return TEST_SKIPPED; 6699 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6700 printf("Device doesn't support out-of-place scatter-gather " 6701 "in both input and output mbufs.\n"); 6702 return TEST_SKIPPED; 6703 } 6704 } 6705 6706 /* Create ZUC session */ 6707 retval = create_wireless_algo_auth_cipher_session( 6708 ts_params->valid_devs[0], 6709 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6710 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6711 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6712 : RTE_CRYPTO_AUTH_OP_GENERATE), 6713 RTE_CRYPTO_AUTH_ZUC_EIA3, 6714 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6715 tdata->key.data, tdata->key.len, 6716 tdata->key.data, tdata->key.len, 6717 tdata->auth_iv.len, tdata->digest.len, 6718 tdata->cipher_iv.len); 6719 6720 if (retval != 0) 6721 return retval; 6722 6723 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6724 if (op_mode == OUT_OF_PLACE) 6725 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6726 6727 /* clear mbuf payload */ 6728 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6729 rte_pktmbuf_tailroom(ut_params->ibuf)); 6730 if (op_mode == OUT_OF_PLACE) 6731 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 6732 rte_pktmbuf_tailroom(ut_params->obuf)); 6733 6734 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6735 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6736 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6737 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6738 6739 if (verify) { 6740 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6741 ciphertext_pad_len); 6742 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6743 debug_hexdump(stdout, "ciphertext:", ciphertext, 6744 ciphertext_len); 6745 } else { 6746 /* make sure enough space to cover partial digest verify case */ 6747 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6748 ciphertext_pad_len); 6749 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6750 debug_hexdump(stdout, "plaintext:", plaintext, 6751 plaintext_len); 6752 } 6753 6754 if (op_mode == OUT_OF_PLACE) 6755 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 6756 6757 /* Create ZUC operation */ 6758 retval = create_wireless_algo_auth_cipher_operation( 6759 tdata->digest.data, tdata->digest.len, 6760 tdata->cipher_iv.data, tdata->cipher_iv.len, 6761 tdata->auth_iv.data, tdata->auth_iv.len, 6762 (tdata->digest.offset_bytes == 0 ? 6763 (verify ? ciphertext_pad_len : plaintext_pad_len) 6764 : tdata->digest.offset_bytes), 6765 tdata->validCipherLenInBits.len, 6766 tdata->validCipherOffsetInBits.len, 6767 tdata->validAuthLenInBits.len, 6768 0, 6769 op_mode, 0, verify); 6770 6771 if (retval < 0) 6772 return retval; 6773 6774 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6775 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 6776 tdata->cipher_iv.len); 6777 if (retval != TEST_SUCCESS) 6778 return retval; 6779 } else 6780 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6781 ut_params->op); 6782 6783 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6784 6785 ut_params->obuf = (op_mode == IN_PLACE ? 6786 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6787 6788 6789 if (verify) { 6790 if (ut_params->obuf) 6791 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 6792 uint8_t *); 6793 else 6794 plaintext = ciphertext; 6795 6796 debug_hexdump(stdout, "plaintext:", plaintext, 6797 (tdata->plaintext.len >> 3) - tdata->digest.len); 6798 debug_hexdump(stdout, "plaintext expected:", 6799 tdata->plaintext.data, 6800 (tdata->plaintext.len >> 3) - tdata->digest.len); 6801 } else { 6802 if (ut_params->obuf) 6803 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 6804 uint8_t *); 6805 else 6806 ciphertext = plaintext; 6807 6808 debug_hexdump(stdout, "ciphertext:", ciphertext, 6809 ciphertext_len); 6810 debug_hexdump(stdout, "ciphertext expected:", 6811 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6812 6813 if (tdata->digest.offset_bytes == 0) 6814 digest_offset = plaintext_pad_len; 6815 else 6816 digest_offset = tdata->digest.offset_bytes; 6817 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 6818 uint8_t *, digest_offset); 6819 6820 debug_hexdump(stdout, "digest:", ut_params->digest, 6821 tdata->digest.len); 6822 debug_hexdump(stdout, "digest expected:", 6823 tdata->digest.data, tdata->digest.len); 6824 } 6825 6826 /* Validate obuf */ 6827 if (verify) { 6828 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6829 plaintext, 6830 tdata->plaintext.data, 6831 tdata->plaintext.len >> 3, 6832 "ZUC Plaintext data not as expected"); 6833 } else { 6834 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6835 ciphertext, 6836 tdata->ciphertext.data, 6837 tdata->ciphertext.len >> 3, 6838 "ZUC Ciphertext data not as expected"); 6839 6840 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6841 ut_params->digest, 6842 tdata->digest.data, 6843 tdata->digest.len, 6844 "ZUC Generated auth tag not as expected"); 6845 } 6846 return 0; 6847 } 6848 6849 static int 6850 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata, 6851 uint8_t op_mode, uint8_t verify) 6852 { 6853 struct crypto_testsuite_params *ts_params = &testsuite_params; 6854 struct crypto_unittest_params *ut_params = &unittest_params; 6855 6856 int retval; 6857 6858 const uint8_t *plaintext = NULL; 6859 const uint8_t *ciphertext = NULL; 6860 const uint8_t *digest = NULL; 6861 unsigned int plaintext_pad_len; 6862 unsigned int plaintext_len; 6863 unsigned int ciphertext_pad_len; 6864 unsigned int ciphertext_len; 6865 uint8_t buffer[10000]; 6866 uint8_t digest_buffer[10000]; 6867 6868 struct rte_cryptodev_info dev_info; 6869 6870 /* Check if device supports ZUC EEA3 */ 6871 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6872 tdata->key.len, tdata->cipher_iv.len) < 0) 6873 return TEST_SKIPPED; 6874 6875 /* Check if device supports ZUC EIA3 */ 6876 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6877 tdata->key.len, tdata->auth_iv.len, 6878 tdata->digest.len) < 0) 6879 return TEST_SKIPPED; 6880 6881 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6882 return TEST_SKIPPED; 6883 6884 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6885 6886 uint64_t feat_flags = dev_info.feature_flags; 6887 6888 if (op_mode == IN_PLACE) { 6889 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6890 printf("Device doesn't support in-place scatter-gather " 6891 "in both input and output mbufs.\n"); 6892 return TEST_SKIPPED; 6893 } 6894 6895 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6896 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6897 printf("Device doesn't support RAW data-path APIs.\n"); 6898 return TEST_SKIPPED; 6899 } 6900 } else { 6901 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6902 return TEST_SKIPPED; 6903 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6904 printf("Device doesn't support out-of-place scatter-gather " 6905 "in both input and output mbufs.\n"); 6906 return TEST_SKIPPED; 6907 } 6908 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6909 printf("Device doesn't support digest encrypted.\n"); 6910 return TEST_SKIPPED; 6911 } 6912 } 6913 6914 /* Create ZUC session */ 6915 retval = create_wireless_algo_auth_cipher_session( 6916 ts_params->valid_devs[0], 6917 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6918 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6919 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6920 : RTE_CRYPTO_AUTH_OP_GENERATE), 6921 RTE_CRYPTO_AUTH_ZUC_EIA3, 6922 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6923 tdata->key.data, tdata->key.len, 6924 tdata->key.data, tdata->key.len, 6925 tdata->auth_iv.len, tdata->digest.len, 6926 tdata->cipher_iv.len); 6927 6928 if (retval != 0) 6929 return retval; 6930 6931 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6932 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6933 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6934 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6935 6936 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6937 plaintext_pad_len, 15, 0); 6938 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6939 "Failed to allocate input buffer in mempool"); 6940 6941 if (op_mode == OUT_OF_PLACE) { 6942 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 6943 plaintext_pad_len, 15, 0); 6944 TEST_ASSERT_NOT_NULL(ut_params->obuf, 6945 "Failed to allocate output buffer in mempool"); 6946 } 6947 6948 if (verify) { 6949 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6950 tdata->ciphertext.data); 6951 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6952 ciphertext_len, buffer); 6953 debug_hexdump(stdout, "ciphertext:", ciphertext, 6954 ciphertext_len); 6955 } else { 6956 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6957 tdata->plaintext.data); 6958 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6959 plaintext_len, buffer); 6960 debug_hexdump(stdout, "plaintext:", plaintext, 6961 plaintext_len); 6962 } 6963 memset(buffer, 0, sizeof(buffer)); 6964 6965 /* Create ZUC operation */ 6966 retval = create_wireless_algo_auth_cipher_operation( 6967 tdata->digest.data, tdata->digest.len, 6968 tdata->cipher_iv.data, tdata->cipher_iv.len, 6969 tdata->auth_iv.data, tdata->auth_iv.len, 6970 (tdata->digest.offset_bytes == 0 ? 6971 (verify ? ciphertext_pad_len : plaintext_pad_len) 6972 : tdata->digest.offset_bytes), 6973 tdata->validCipherLenInBits.len, 6974 tdata->validCipherOffsetInBits.len, 6975 tdata->validAuthLenInBits.len, 6976 0, 6977 op_mode, 1, verify); 6978 6979 if (retval < 0) 6980 return retval; 6981 6982 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6983 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 6984 tdata->cipher_iv.len); 6985 if (retval != TEST_SUCCESS) 6986 return retval; 6987 } else 6988 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6989 ut_params->op); 6990 6991 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6992 6993 ut_params->obuf = (op_mode == IN_PLACE ? 6994 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6995 6996 if (verify) { 6997 if (ut_params->obuf) 6998 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 6999 plaintext_len, buffer); 7000 else 7001 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7002 plaintext_len, buffer); 7003 7004 debug_hexdump(stdout, "plaintext:", plaintext, 7005 (tdata->plaintext.len >> 3) - tdata->digest.len); 7006 debug_hexdump(stdout, "plaintext expected:", 7007 tdata->plaintext.data, 7008 (tdata->plaintext.len >> 3) - tdata->digest.len); 7009 } else { 7010 if (ut_params->obuf) 7011 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 7012 ciphertext_len, buffer); 7013 else 7014 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7015 ciphertext_len, buffer); 7016 7017 debug_hexdump(stdout, "ciphertext:", ciphertext, 7018 ciphertext_len); 7019 debug_hexdump(stdout, "ciphertext expected:", 7020 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 7021 7022 if (ut_params->obuf) 7023 digest = rte_pktmbuf_read(ut_params->obuf, 7024 (tdata->digest.offset_bytes == 0 ? 7025 plaintext_pad_len : tdata->digest.offset_bytes), 7026 tdata->digest.len, digest_buffer); 7027 else 7028 digest = rte_pktmbuf_read(ut_params->ibuf, 7029 (tdata->digest.offset_bytes == 0 ? 7030 plaintext_pad_len : tdata->digest.offset_bytes), 7031 tdata->digest.len, digest_buffer); 7032 7033 debug_hexdump(stdout, "digest:", digest, 7034 tdata->digest.len); 7035 debug_hexdump(stdout, "digest expected:", 7036 tdata->digest.data, tdata->digest.len); 7037 } 7038 7039 /* Validate obuf */ 7040 if (verify) { 7041 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7042 plaintext, 7043 tdata->plaintext.data, 7044 tdata->plaintext.len >> 3, 7045 "ZUC Plaintext data not as expected"); 7046 } else { 7047 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7048 ciphertext, 7049 tdata->ciphertext.data, 7050 tdata->validDataLenInBits.len, 7051 "ZUC Ciphertext data not as expected"); 7052 7053 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7054 digest, 7055 tdata->digest.data, 7056 tdata->digest.len, 7057 "ZUC Generated auth tag not as expected"); 7058 } 7059 return 0; 7060 } 7061 7062 static int 7063 test_kasumi_encryption_test_case_1(void) 7064 { 7065 return test_kasumi_encryption(&kasumi_test_case_1); 7066 } 7067 7068 static int 7069 test_kasumi_encryption_test_case_1_sgl(void) 7070 { 7071 return test_kasumi_encryption_sgl(&kasumi_test_case_1); 7072 } 7073 7074 static int 7075 test_kasumi_encryption_test_case_1_oop(void) 7076 { 7077 return test_kasumi_encryption_oop(&kasumi_test_case_1); 7078 } 7079 7080 static int 7081 test_kasumi_encryption_test_case_1_oop_sgl(void) 7082 { 7083 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1); 7084 } 7085 7086 static int 7087 test_kasumi_encryption_test_case_2(void) 7088 { 7089 return test_kasumi_encryption(&kasumi_test_case_2); 7090 } 7091 7092 static int 7093 test_kasumi_encryption_test_case_3(void) 7094 { 7095 return test_kasumi_encryption(&kasumi_test_case_3); 7096 } 7097 7098 static int 7099 test_kasumi_encryption_test_case_4(void) 7100 { 7101 return test_kasumi_encryption(&kasumi_test_case_4); 7102 } 7103 7104 static int 7105 test_kasumi_encryption_test_case_5(void) 7106 { 7107 return test_kasumi_encryption(&kasumi_test_case_5); 7108 } 7109 7110 static int 7111 test_kasumi_decryption_test_case_1(void) 7112 { 7113 return test_kasumi_decryption(&kasumi_test_case_1); 7114 } 7115 7116 static int 7117 test_kasumi_decryption_test_case_1_oop(void) 7118 { 7119 return test_kasumi_decryption_oop(&kasumi_test_case_1); 7120 } 7121 7122 static int 7123 test_kasumi_decryption_test_case_2(void) 7124 { 7125 return test_kasumi_decryption(&kasumi_test_case_2); 7126 } 7127 7128 static int 7129 test_kasumi_decryption_test_case_3(void) 7130 { 7131 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 7132 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7133 return TEST_SKIPPED; 7134 return test_kasumi_decryption(&kasumi_test_case_3); 7135 } 7136 7137 static int 7138 test_kasumi_decryption_test_case_4(void) 7139 { 7140 return test_kasumi_decryption(&kasumi_test_case_4); 7141 } 7142 7143 static int 7144 test_kasumi_decryption_test_case_5(void) 7145 { 7146 return test_kasumi_decryption(&kasumi_test_case_5); 7147 } 7148 static int 7149 test_snow3g_encryption_test_case_1(void) 7150 { 7151 return test_snow3g_encryption(&snow3g_test_case_1); 7152 } 7153 7154 static int 7155 test_snow3g_encryption_test_case_1_oop(void) 7156 { 7157 return test_snow3g_encryption_oop(&snow3g_test_case_1); 7158 } 7159 7160 static int 7161 test_snow3g_encryption_test_case_1_oop_sgl(void) 7162 { 7163 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 1, 1); 7164 } 7165 7166 static int 7167 test_snow3g_encryption_test_case_1_oop_lb_in_sgl_out(void) 7168 { 7169 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 0, 1); 7170 } 7171 7172 static int 7173 test_snow3g_encryption_test_case_1_oop_sgl_in_lb_out(void) 7174 { 7175 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 1, 0); 7176 } 7177 7178 static int 7179 test_snow3g_encryption_test_case_1_offset_oop(void) 7180 { 7181 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); 7182 } 7183 7184 static int 7185 test_snow3g_encryption_test_case_2(void) 7186 { 7187 return test_snow3g_encryption(&snow3g_test_case_2); 7188 } 7189 7190 static int 7191 test_snow3g_encryption_test_case_3(void) 7192 { 7193 return test_snow3g_encryption(&snow3g_test_case_3); 7194 } 7195 7196 static int 7197 test_snow3g_encryption_test_case_4(void) 7198 { 7199 return test_snow3g_encryption(&snow3g_test_case_4); 7200 } 7201 7202 static int 7203 test_snow3g_encryption_test_case_5(void) 7204 { 7205 return test_snow3g_encryption(&snow3g_test_case_5); 7206 } 7207 7208 static int 7209 test_snow3g_decryption_test_case_1(void) 7210 { 7211 return test_snow3g_decryption(&snow3g_test_case_1); 7212 } 7213 7214 static int 7215 test_snow3g_decryption_test_case_1_oop(void) 7216 { 7217 return test_snow3g_decryption_oop(&snow3g_test_case_1); 7218 } 7219 7220 static int 7221 test_snow3g_decryption_test_case_2(void) 7222 { 7223 return test_snow3g_decryption(&snow3g_test_case_2); 7224 } 7225 7226 static int 7227 test_snow3g_decryption_test_case_3(void) 7228 { 7229 return test_snow3g_decryption(&snow3g_test_case_3); 7230 } 7231 7232 static int 7233 test_snow3g_decryption_test_case_4(void) 7234 { 7235 return test_snow3g_decryption(&snow3g_test_case_4); 7236 } 7237 7238 static int 7239 test_snow3g_decryption_test_case_5(void) 7240 { 7241 return test_snow3g_decryption(&snow3g_test_case_5); 7242 } 7243 7244 /* 7245 * Function prepares snow3g_hash_test_data from snow3g_test_data. 7246 * Pattern digest from snow3g_test_data must be allocated as 7247 * 4 last bytes in plaintext. 7248 */ 7249 static void 7250 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern, 7251 struct snow3g_hash_test_data *output) 7252 { 7253 if ((pattern != NULL) && (output != NULL)) { 7254 output->key.len = pattern->key.len; 7255 7256 memcpy(output->key.data, 7257 pattern->key.data, pattern->key.len); 7258 7259 output->auth_iv.len = pattern->auth_iv.len; 7260 7261 memcpy(output->auth_iv.data, 7262 pattern->auth_iv.data, pattern->auth_iv.len); 7263 7264 output->plaintext.len = pattern->plaintext.len; 7265 7266 memcpy(output->plaintext.data, 7267 pattern->plaintext.data, pattern->plaintext.len >> 3); 7268 7269 output->digest.len = pattern->digest.len; 7270 7271 memcpy(output->digest.data, 7272 &pattern->plaintext.data[pattern->digest.offset_bytes], 7273 pattern->digest.len); 7274 7275 output->validAuthLenInBits.len = 7276 pattern->validAuthLenInBits.len; 7277 } 7278 } 7279 7280 /* 7281 * Test case verify computed cipher and digest from snow3g_test_case_7 data. 7282 */ 7283 static int 7284 test_snow3g_decryption_with_digest_test_case_1(void) 7285 { 7286 int ret; 7287 struct snow3g_hash_test_data snow3g_hash_data; 7288 struct rte_cryptodev_info dev_info; 7289 struct crypto_testsuite_params *ts_params = &testsuite_params; 7290 7291 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7292 uint64_t feat_flags = dev_info.feature_flags; 7293 7294 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7295 printf("Device doesn't support encrypted digest operations.\n"); 7296 return TEST_SKIPPED; 7297 } 7298 7299 /* 7300 * Function prepare data for hash verification test case. 7301 * Digest is allocated in 4 last bytes in plaintext, pattern. 7302 */ 7303 snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data); 7304 7305 ret = test_snow3g_decryption(&snow3g_test_case_7); 7306 if (ret != 0) 7307 return ret; 7308 7309 return test_snow3g_authentication_verify(&snow3g_hash_data); 7310 } 7311 7312 static int 7313 test_snow3g_cipher_auth_test_case_1(void) 7314 { 7315 return test_snow3g_cipher_auth(&snow3g_test_case_3); 7316 } 7317 7318 static int 7319 test_snow3g_auth_cipher_test_case_1(void) 7320 { 7321 return test_snow3g_auth_cipher( 7322 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0); 7323 } 7324 7325 static int 7326 test_snow3g_auth_cipher_test_case_2(void) 7327 { 7328 return test_snow3g_auth_cipher( 7329 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0); 7330 } 7331 7332 static int 7333 test_snow3g_auth_cipher_test_case_2_oop(void) 7334 { 7335 return test_snow3g_auth_cipher( 7336 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7337 } 7338 7339 static int 7340 test_snow3g_auth_cipher_part_digest_enc(void) 7341 { 7342 return test_snow3g_auth_cipher( 7343 &snow3g_auth_cipher_partial_digest_encryption, 7344 IN_PLACE, 0); 7345 } 7346 7347 static int 7348 test_snow3g_auth_cipher_part_digest_enc_oop(void) 7349 { 7350 return test_snow3g_auth_cipher( 7351 &snow3g_auth_cipher_partial_digest_encryption, 7352 OUT_OF_PLACE, 0); 7353 } 7354 7355 static int 7356 test_snow3g_auth_cipher_test_case_3_sgl(void) 7357 { 7358 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 7359 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7360 return TEST_SKIPPED; 7361 return test_snow3g_auth_cipher_sgl( 7362 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0); 7363 } 7364 7365 static int 7366 test_snow3g_auth_cipher_test_case_3_oop_sgl(void) 7367 { 7368 return test_snow3g_auth_cipher_sgl( 7369 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0); 7370 } 7371 7372 static int 7373 test_snow3g_auth_cipher_part_digest_enc_sgl(void) 7374 { 7375 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 7376 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7377 return TEST_SKIPPED; 7378 return test_snow3g_auth_cipher_sgl( 7379 &snow3g_auth_cipher_partial_digest_encryption, 7380 IN_PLACE, 0); 7381 } 7382 7383 static int 7384 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void) 7385 { 7386 return test_snow3g_auth_cipher_sgl( 7387 &snow3g_auth_cipher_partial_digest_encryption, 7388 OUT_OF_PLACE, 0); 7389 } 7390 7391 static int 7392 test_snow3g_auth_cipher_total_digest_enc_1(void) 7393 { 7394 return test_snow3g_auth_cipher( 7395 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 0); 7396 } 7397 7398 static int 7399 test_snow3g_auth_cipher_total_digest_enc_1_oop(void) 7400 { 7401 return test_snow3g_auth_cipher( 7402 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 0); 7403 } 7404 7405 static int 7406 test_snow3g_auth_cipher_total_digest_enc_1_sgl(void) 7407 { 7408 return test_snow3g_auth_cipher_sgl( 7409 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 0); 7410 } 7411 7412 static int 7413 test_snow3g_auth_cipher_total_digest_enc_1_oop_sgl(void) 7414 { 7415 return test_snow3g_auth_cipher_sgl( 7416 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 0); 7417 } 7418 7419 static int 7420 test_snow3g_auth_cipher_verify_test_case_1(void) 7421 { 7422 return test_snow3g_auth_cipher( 7423 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1); 7424 } 7425 7426 static int 7427 test_snow3g_auth_cipher_verify_test_case_2(void) 7428 { 7429 return test_snow3g_auth_cipher( 7430 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1); 7431 } 7432 7433 static int 7434 test_snow3g_auth_cipher_verify_test_case_2_oop(void) 7435 { 7436 return test_snow3g_auth_cipher( 7437 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7438 } 7439 7440 static int 7441 test_snow3g_auth_cipher_verify_part_digest_enc(void) 7442 { 7443 return test_snow3g_auth_cipher( 7444 &snow3g_auth_cipher_partial_digest_encryption, 7445 IN_PLACE, 1); 7446 } 7447 7448 static int 7449 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void) 7450 { 7451 return test_snow3g_auth_cipher( 7452 &snow3g_auth_cipher_partial_digest_encryption, 7453 OUT_OF_PLACE, 1); 7454 } 7455 7456 static int 7457 test_snow3g_auth_cipher_verify_test_case_3_sgl(void) 7458 { 7459 return test_snow3g_auth_cipher_sgl( 7460 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1); 7461 } 7462 7463 static int 7464 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void) 7465 { 7466 return test_snow3g_auth_cipher_sgl( 7467 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1); 7468 } 7469 7470 static int 7471 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void) 7472 { 7473 return test_snow3g_auth_cipher_sgl( 7474 &snow3g_auth_cipher_partial_digest_encryption, 7475 IN_PLACE, 1); 7476 } 7477 7478 static int 7479 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void) 7480 { 7481 return test_snow3g_auth_cipher_sgl( 7482 &snow3g_auth_cipher_partial_digest_encryption, 7483 OUT_OF_PLACE, 1); 7484 } 7485 7486 static int 7487 test_snow3g_auth_cipher_verify_total_digest_enc_1(void) 7488 { 7489 return test_snow3g_auth_cipher( 7490 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 1); 7491 } 7492 7493 static int 7494 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop(void) 7495 { 7496 return test_snow3g_auth_cipher( 7497 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 1); 7498 } 7499 7500 static int 7501 test_snow3g_auth_cipher_verify_total_digest_enc_1_sgl(void) 7502 { 7503 return test_snow3g_auth_cipher_sgl( 7504 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 1); 7505 } 7506 7507 static int 7508 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop_sgl(void) 7509 { 7510 return test_snow3g_auth_cipher_sgl( 7511 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 1); 7512 } 7513 7514 static int 7515 test_snow3g_auth_cipher_with_digest_test_case_1(void) 7516 { 7517 return test_snow3g_auth_cipher( 7518 &snow3g_test_case_7, IN_PLACE, 0); 7519 } 7520 7521 static int 7522 test_kasumi_auth_cipher_test_case_1(void) 7523 { 7524 return test_kasumi_auth_cipher( 7525 &kasumi_test_case_3, IN_PLACE, 0); 7526 } 7527 7528 static int 7529 test_kasumi_auth_cipher_test_case_2(void) 7530 { 7531 return test_kasumi_auth_cipher( 7532 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7533 } 7534 7535 static int 7536 test_kasumi_auth_cipher_test_case_2_oop(void) 7537 { 7538 return test_kasumi_auth_cipher( 7539 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7540 } 7541 7542 static int 7543 test_kasumi_auth_cipher_test_case_2_sgl(void) 7544 { 7545 return test_kasumi_auth_cipher_sgl( 7546 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7547 } 7548 7549 static int 7550 test_kasumi_auth_cipher_test_case_2_oop_sgl(void) 7551 { 7552 return test_kasumi_auth_cipher_sgl( 7553 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7554 } 7555 7556 static int 7557 test_kasumi_auth_cipher_verify_test_case_1(void) 7558 { 7559 return test_kasumi_auth_cipher( 7560 &kasumi_test_case_3, IN_PLACE, 1); 7561 } 7562 7563 static int 7564 test_kasumi_auth_cipher_verify_test_case_2(void) 7565 { 7566 return test_kasumi_auth_cipher( 7567 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7568 } 7569 7570 static int 7571 test_kasumi_auth_cipher_verify_test_case_2_oop(void) 7572 { 7573 return test_kasumi_auth_cipher( 7574 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7575 } 7576 7577 static int 7578 test_kasumi_auth_cipher_verify_test_case_2_sgl(void) 7579 { 7580 return test_kasumi_auth_cipher_sgl( 7581 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7582 } 7583 7584 static int 7585 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void) 7586 { 7587 return test_kasumi_auth_cipher_sgl( 7588 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7589 } 7590 7591 static int 7592 test_kasumi_cipher_auth_test_case_1(void) 7593 { 7594 return test_kasumi_cipher_auth(&kasumi_test_case_6); 7595 } 7596 7597 static int 7598 test_zuc_encryption_test_case_1(void) 7599 { 7600 return test_zuc_cipher(&zuc_test_case_cipher_193b, 7601 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7602 } 7603 7604 static int 7605 test_zuc_encryption_test_case_2(void) 7606 { 7607 return test_zuc_cipher(&zuc_test_case_cipher_800b, 7608 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7609 } 7610 7611 static int 7612 test_zuc_encryption_test_case_3(void) 7613 { 7614 return test_zuc_cipher(&zuc_test_case_cipher_1570b, 7615 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7616 } 7617 7618 static int 7619 test_zuc_encryption_test_case_4(void) 7620 { 7621 return test_zuc_cipher(&zuc_test_case_cipher_2798b, 7622 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7623 } 7624 7625 static int 7626 test_zuc_encryption_test_case_5(void) 7627 { 7628 return test_zuc_cipher(&zuc_test_case_cipher_4019b, 7629 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7630 } 7631 7632 static int 7633 test_zuc_encryption_test_case_6_sgl(void) 7634 { 7635 return test_zuc_cipher_sgl(&zuc_test_case_cipher_193b, 7636 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7637 } 7638 7639 static int 7640 test_zuc_decryption_test_case_1(void) 7641 { 7642 return test_zuc_cipher(&zuc_test_case_cipher_193b, 7643 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7644 } 7645 7646 static int 7647 test_zuc_decryption_test_case_2(void) 7648 { 7649 return test_zuc_cipher(&zuc_test_case_cipher_800b, 7650 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7651 } 7652 7653 static int 7654 test_zuc_decryption_test_case_3(void) 7655 { 7656 return test_zuc_cipher(&zuc_test_case_cipher_1570b, 7657 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7658 } 7659 7660 static int 7661 test_zuc_decryption_test_case_4(void) 7662 { 7663 return test_zuc_cipher(&zuc_test_case_cipher_2798b, 7664 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7665 } 7666 7667 static int 7668 test_zuc_decryption_test_case_5(void) 7669 { 7670 return test_zuc_cipher(&zuc_test_case_cipher_4019b, 7671 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7672 } 7673 7674 static int 7675 test_zuc_decryption_test_case_6_sgl(void) 7676 { 7677 return test_zuc_cipher_sgl(&zuc_test_case_cipher_193b, 7678 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7679 } 7680 7681 static int 7682 test_zuc_hash_generate_test_case_1(void) 7683 { 7684 return test_zuc_authentication(&zuc_test_case_auth_1b, 7685 RTE_CRYPTO_AUTH_OP_GENERATE); 7686 } 7687 7688 static int 7689 test_zuc_hash_generate_test_case_2(void) 7690 { 7691 return test_zuc_authentication(&zuc_test_case_auth_90b, 7692 RTE_CRYPTO_AUTH_OP_GENERATE); 7693 } 7694 7695 static int 7696 test_zuc_hash_generate_test_case_3(void) 7697 { 7698 return test_zuc_authentication(&zuc_test_case_auth_577b, 7699 RTE_CRYPTO_AUTH_OP_GENERATE); 7700 } 7701 7702 static int 7703 test_zuc_hash_generate_test_case_4(void) 7704 { 7705 return test_zuc_authentication(&zuc_test_case_auth_2079b, 7706 RTE_CRYPTO_AUTH_OP_GENERATE); 7707 } 7708 7709 static int 7710 test_zuc_hash_generate_test_case_5(void) 7711 { 7712 return test_zuc_authentication(&zuc_test_auth_5670b, 7713 RTE_CRYPTO_AUTH_OP_GENERATE); 7714 } 7715 7716 static int 7717 test_zuc_hash_generate_test_case_6(void) 7718 { 7719 return test_zuc_authentication(&zuc_test_case_auth_128b, 7720 RTE_CRYPTO_AUTH_OP_GENERATE); 7721 } 7722 7723 static int 7724 test_zuc_hash_generate_test_case_7(void) 7725 { 7726 return test_zuc_authentication(&zuc_test_case_auth_2080b, 7727 RTE_CRYPTO_AUTH_OP_GENERATE); 7728 } 7729 7730 static int 7731 test_zuc_hash_generate_test_case_8(void) 7732 { 7733 return test_zuc_authentication(&zuc_test_case_auth_584b, 7734 RTE_CRYPTO_AUTH_OP_GENERATE); 7735 } 7736 7737 static int 7738 test_zuc_hash_verify_test_case_1(void) 7739 { 7740 return test_zuc_authentication(&zuc_test_case_auth_1b, 7741 RTE_CRYPTO_AUTH_OP_VERIFY); 7742 } 7743 7744 static int 7745 test_zuc_hash_verify_test_case_2(void) 7746 { 7747 return test_zuc_authentication(&zuc_test_case_auth_90b, 7748 RTE_CRYPTO_AUTH_OP_VERIFY); 7749 } 7750 7751 static int 7752 test_zuc_hash_verify_test_case_3(void) 7753 { 7754 return test_zuc_authentication(&zuc_test_case_auth_577b, 7755 RTE_CRYPTO_AUTH_OP_VERIFY); 7756 } 7757 7758 static int 7759 test_zuc_hash_verify_test_case_4(void) 7760 { 7761 return test_zuc_authentication(&zuc_test_case_auth_2079b, 7762 RTE_CRYPTO_AUTH_OP_VERIFY); 7763 } 7764 7765 static int 7766 test_zuc_hash_verify_test_case_5(void) 7767 { 7768 return test_zuc_authentication(&zuc_test_auth_5670b, 7769 RTE_CRYPTO_AUTH_OP_VERIFY); 7770 } 7771 7772 static int 7773 test_zuc_hash_verify_test_case_6(void) 7774 { 7775 return test_zuc_authentication(&zuc_test_case_auth_128b, 7776 RTE_CRYPTO_AUTH_OP_VERIFY); 7777 } 7778 7779 static int 7780 test_zuc_hash_verify_test_case_7(void) 7781 { 7782 return test_zuc_authentication(&zuc_test_case_auth_2080b, 7783 RTE_CRYPTO_AUTH_OP_VERIFY); 7784 } 7785 7786 static int 7787 test_zuc_hash_verify_test_case_8(void) 7788 { 7789 return test_zuc_authentication(&zuc_test_case_auth_584b, 7790 RTE_CRYPTO_AUTH_OP_VERIFY); 7791 } 7792 7793 static int 7794 test_zuc_cipher_auth_test_case_1(void) 7795 { 7796 return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b); 7797 } 7798 7799 static int 7800 test_zuc_cipher_auth_test_case_2(void) 7801 { 7802 return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b); 7803 } 7804 7805 static int 7806 test_zuc_auth_cipher_test_case_1(void) 7807 { 7808 return test_zuc_auth_cipher( 7809 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7810 } 7811 7812 static int 7813 test_zuc_auth_cipher_test_case_1_oop(void) 7814 { 7815 return test_zuc_auth_cipher( 7816 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7817 } 7818 7819 static int 7820 test_zuc_auth_cipher_test_case_1_sgl(void) 7821 { 7822 return test_zuc_auth_cipher_sgl( 7823 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7824 } 7825 7826 static int 7827 test_zuc_auth_cipher_test_case_1_oop_sgl(void) 7828 { 7829 return test_zuc_auth_cipher_sgl( 7830 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7831 } 7832 7833 static int 7834 test_zuc_auth_cipher_test_case_2(void) 7835 { 7836 return test_zuc_auth_cipher( 7837 &zuc_auth_cipher_test_case_2, IN_PLACE, 0); 7838 } 7839 7840 static int 7841 test_zuc_auth_cipher_test_case_2_oop(void) 7842 { 7843 return test_zuc_auth_cipher( 7844 &zuc_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7845 } 7846 7847 static int 7848 test_zuc_auth_cipher_verify_test_case_1(void) 7849 { 7850 return test_zuc_auth_cipher( 7851 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7852 } 7853 7854 static int 7855 test_zuc_auth_cipher_verify_test_case_1_oop(void) 7856 { 7857 return test_zuc_auth_cipher( 7858 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7859 } 7860 7861 static int 7862 test_zuc_auth_cipher_verify_test_case_1_sgl(void) 7863 { 7864 return test_zuc_auth_cipher_sgl( 7865 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7866 } 7867 7868 static int 7869 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void) 7870 { 7871 return test_zuc_auth_cipher_sgl( 7872 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7873 } 7874 7875 static int 7876 test_zuc_auth_cipher_verify_test_case_2(void) 7877 { 7878 return test_zuc_auth_cipher( 7879 &zuc_auth_cipher_test_case_2, IN_PLACE, 1); 7880 } 7881 7882 static int 7883 test_zuc_auth_cipher_verify_test_case_2_oop(void) 7884 { 7885 return test_zuc_auth_cipher( 7886 &zuc_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7887 } 7888 7889 static int 7890 test_zuc256_encryption_test_case_1(void) 7891 { 7892 return test_zuc_cipher(&zuc256_test_case_cipher_1, 7893 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7894 } 7895 7896 static int 7897 test_zuc256_encryption_test_case_2(void) 7898 { 7899 return test_zuc_cipher(&zuc256_test_case_cipher_2, 7900 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7901 } 7902 7903 static int 7904 test_zuc256_decryption_test_case_1(void) 7905 { 7906 return test_zuc_cipher(&zuc256_test_case_cipher_1, 7907 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7908 } 7909 7910 static int 7911 test_zuc256_decryption_test_case_2(void) 7912 { 7913 return test_zuc_cipher(&zuc256_test_case_cipher_2, 7914 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7915 } 7916 7917 static int 7918 test_zuc256_hash_generate_4b_tag_test_case_1(void) 7919 { 7920 return test_zuc_authentication(&zuc256_test_case_auth_1, 7921 RTE_CRYPTO_AUTH_OP_GENERATE); 7922 } 7923 7924 static int 7925 test_zuc256_hash_generate_4b_tag_test_case_2(void) 7926 { 7927 return test_zuc_authentication(&zuc256_test_case_auth_2, 7928 RTE_CRYPTO_AUTH_OP_GENERATE); 7929 } 7930 7931 static int 7932 test_zuc256_hash_generate_4b_tag_test_case_3(void) 7933 { 7934 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b, 7935 RTE_CRYPTO_AUTH_OP_GENERATE); 7936 } 7937 7938 static int 7939 test_zuc256_hash_generate_8b_tag_test_case_1(void) 7940 { 7941 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b, 7942 RTE_CRYPTO_AUTH_OP_GENERATE); 7943 } 7944 7945 static int 7946 test_zuc256_hash_generate_16b_tag_test_case_1(void) 7947 { 7948 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b, 7949 RTE_CRYPTO_AUTH_OP_GENERATE); 7950 } 7951 7952 static int 7953 test_zuc256_hash_verify_4b_tag_test_case_1(void) 7954 { 7955 return test_zuc_authentication(&zuc256_test_case_auth_1, 7956 RTE_CRYPTO_AUTH_OP_VERIFY); 7957 } 7958 7959 static int 7960 test_zuc256_hash_verify_4b_tag_test_case_2(void) 7961 { 7962 return test_zuc_authentication(&zuc256_test_case_auth_2, 7963 RTE_CRYPTO_AUTH_OP_VERIFY); 7964 } 7965 7966 static int 7967 test_zuc256_hash_verify_4b_tag_test_case_3(void) 7968 { 7969 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b, 7970 RTE_CRYPTO_AUTH_OP_VERIFY); 7971 } 7972 7973 static int 7974 test_zuc256_hash_verify_8b_tag_test_case_1(void) 7975 { 7976 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b, 7977 RTE_CRYPTO_AUTH_OP_VERIFY); 7978 } 7979 7980 static int 7981 test_zuc256_hash_verify_16b_tag_test_case_1(void) 7982 { 7983 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b, 7984 RTE_CRYPTO_AUTH_OP_VERIFY); 7985 } 7986 7987 static int 7988 test_zuc256_cipher_auth_4b_tag_test_case_1(void) 7989 { 7990 return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_1); 7991 } 7992 7993 static int 7994 test_zuc256_cipher_auth_4b_tag_test_case_2(void) 7995 { 7996 return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_2); 7997 } 7998 7999 static int 8000 test_zuc256_cipher_auth_8b_tag_test_case_1(void) 8001 { 8002 return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_3); 8003 } 8004 8005 static int 8006 test_zuc256_cipher_auth_16b_tag_test_case_1(void) 8007 { 8008 return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_4); 8009 } 8010 8011 static int 8012 test_zuc256_auth_cipher_4b_tag_test_case_1(void) 8013 { 8014 return test_zuc_auth_cipher( 8015 &zuc256_auth_cipher_test_case_1, IN_PLACE, 0); 8016 } 8017 8018 static int 8019 test_zuc256_auth_cipher_4b_tag_test_case_2(void) 8020 { 8021 return test_zuc_auth_cipher( 8022 &zuc256_auth_cipher_test_case_2, IN_PLACE, 0); 8023 } 8024 8025 static int 8026 test_zuc256_auth_cipher_8b_tag_test_case_1(void) 8027 { 8028 return test_zuc_auth_cipher( 8029 &zuc256_auth_cipher_test_case_3, IN_PLACE, 0); 8030 } 8031 8032 static int 8033 test_zuc256_auth_cipher_16b_tag_test_case_1(void) 8034 { 8035 return test_zuc_auth_cipher( 8036 &zuc256_auth_cipher_test_case_4, IN_PLACE, 0); 8037 } 8038 8039 static int 8040 test_zuc256_auth_cipher_verify_4b_tag_test_case_1(void) 8041 { 8042 return test_zuc_auth_cipher( 8043 &zuc256_auth_cipher_test_case_1, IN_PLACE, 1); 8044 } 8045 8046 static int 8047 test_zuc256_auth_cipher_verify_4b_tag_test_case_2(void) 8048 { 8049 return test_zuc_auth_cipher( 8050 &zuc256_auth_cipher_test_case_2, IN_PLACE, 1); 8051 } 8052 8053 static int 8054 test_zuc256_auth_cipher_verify_8b_tag_test_case_1(void) 8055 { 8056 return test_zuc_auth_cipher( 8057 &zuc256_auth_cipher_test_case_3, IN_PLACE, 1); 8058 } 8059 8060 static int 8061 test_zuc256_auth_cipher_verify_16b_tag_test_case_1(void) 8062 { 8063 return test_zuc_auth_cipher( 8064 &zuc256_auth_cipher_test_case_4, IN_PLACE, 1); 8065 } 8066 8067 static int 8068 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata) 8069 { 8070 uint8_t dev_id = testsuite_params.valid_devs[0]; 8071 8072 struct rte_cryptodev_sym_capability_idx cap_idx; 8073 8074 /* Check if device supports particular cipher algorithm */ 8075 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8076 cap_idx.algo.cipher = tdata->cipher_algo; 8077 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 8078 return TEST_SKIPPED; 8079 8080 /* Check if device supports particular hash algorithm */ 8081 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8082 cap_idx.algo.auth = tdata->auth_algo; 8083 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 8084 return TEST_SKIPPED; 8085 8086 return 0; 8087 } 8088 8089 static int 8090 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata, 8091 uint8_t op_mode, uint8_t verify) 8092 { 8093 struct crypto_testsuite_params *ts_params = &testsuite_params; 8094 struct crypto_unittest_params *ut_params = &unittest_params; 8095 8096 int retval; 8097 8098 uint8_t *plaintext = NULL, *ciphertext = NULL; 8099 unsigned int plaintext_pad_len; 8100 unsigned int plaintext_len; 8101 unsigned int ciphertext_pad_len; 8102 unsigned int ciphertext_len; 8103 unsigned int digest_offset; 8104 8105 struct rte_cryptodev_info dev_info; 8106 struct rte_crypto_op *op; 8107 8108 /* Check if device supports particular algorithms separately */ 8109 if (test_mixed_check_if_unsupported(tdata)) 8110 return TEST_SKIPPED; 8111 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 8112 return TEST_SKIPPED; 8113 8114 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8115 return TEST_SKIPPED; 8116 8117 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8118 8119 uint64_t feat_flags = dev_info.feature_flags; 8120 8121 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 8122 printf("Device doesn't support digest encrypted.\n"); 8123 return TEST_SKIPPED; 8124 } 8125 8126 /* Create the session */ 8127 if (verify) 8128 retval = create_wireless_algo_cipher_auth_session( 8129 ts_params->valid_devs[0], 8130 RTE_CRYPTO_CIPHER_OP_DECRYPT, 8131 RTE_CRYPTO_AUTH_OP_VERIFY, 8132 tdata->auth_algo, 8133 tdata->cipher_algo, 8134 tdata->auth_key.data, tdata->auth_key.len, 8135 tdata->cipher_key.data, tdata->cipher_key.len, 8136 tdata->auth_iv.len, tdata->digest_enc.len, 8137 tdata->cipher_iv.len); 8138 else 8139 retval = create_wireless_algo_auth_cipher_session( 8140 ts_params->valid_devs[0], 8141 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8142 RTE_CRYPTO_AUTH_OP_GENERATE, 8143 tdata->auth_algo, 8144 tdata->cipher_algo, 8145 tdata->auth_key.data, tdata->auth_key.len, 8146 tdata->cipher_key.data, tdata->cipher_key.len, 8147 tdata->auth_iv.len, tdata->digest_enc.len, 8148 tdata->cipher_iv.len); 8149 if (retval != 0) 8150 return retval; 8151 8152 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8153 if (op_mode == OUT_OF_PLACE) 8154 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8155 8156 /* clear mbuf payload */ 8157 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8158 rte_pktmbuf_tailroom(ut_params->ibuf)); 8159 if (op_mode == OUT_OF_PLACE) { 8160 8161 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 8162 rte_pktmbuf_tailroom(ut_params->obuf)); 8163 } 8164 8165 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 8166 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 8167 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 8168 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 8169 8170 if (verify) { 8171 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8172 ciphertext_pad_len); 8173 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 8174 debug_hexdump(stdout, "ciphertext:", ciphertext, 8175 ciphertext_len); 8176 } else { 8177 /* make sure enough space to cover partial digest verify case */ 8178 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8179 ciphertext_pad_len); 8180 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 8181 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 8182 } 8183 8184 if (op_mode == OUT_OF_PLACE) 8185 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 8186 8187 /* Create the operation */ 8188 retval = create_wireless_algo_auth_cipher_operation( 8189 tdata->digest_enc.data, tdata->digest_enc.len, 8190 tdata->cipher_iv.data, tdata->cipher_iv.len, 8191 tdata->auth_iv.data, tdata->auth_iv.len, 8192 (tdata->digest_enc.offset == 0 ? 8193 plaintext_pad_len 8194 : tdata->digest_enc.offset), 8195 tdata->validCipherLen.len_bits, 8196 tdata->cipher.offset_bits, 8197 tdata->validAuthLen.len_bits, 8198 tdata->auth.offset_bits, 8199 op_mode, 0, verify); 8200 8201 if (retval < 0) 8202 return retval; 8203 8204 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 8205 8206 /* Check if the op failed because the device doesn't */ 8207 /* support this particular combination of algorithms */ 8208 if (op == NULL && ut_params->op->status == 8209 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 8210 printf("Device doesn't support this mixed combination. " 8211 "Test Skipped.\n"); 8212 return TEST_SKIPPED; 8213 } 8214 ut_params->op = op; 8215 8216 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 8217 8218 ut_params->obuf = (op_mode == IN_PLACE ? 8219 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 8220 8221 if (verify) { 8222 if (ut_params->obuf) 8223 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 8224 uint8_t *); 8225 else 8226 plaintext = ciphertext + 8227 (tdata->cipher.offset_bits >> 3); 8228 8229 debug_hexdump(stdout, "plaintext:", plaintext, 8230 tdata->plaintext.len_bits >> 3); 8231 debug_hexdump(stdout, "plaintext expected:", 8232 tdata->plaintext.data, 8233 tdata->plaintext.len_bits >> 3); 8234 } else { 8235 if (ut_params->obuf) 8236 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 8237 uint8_t *); 8238 else 8239 ciphertext = plaintext; 8240 8241 debug_hexdump(stdout, "ciphertext:", ciphertext, 8242 ciphertext_len); 8243 debug_hexdump(stdout, "ciphertext expected:", 8244 tdata->ciphertext.data, 8245 tdata->ciphertext.len_bits >> 3); 8246 8247 if (tdata->digest_enc.offset == 0) 8248 digest_offset = plaintext_pad_len; 8249 else 8250 digest_offset = tdata->digest_enc.offset; 8251 8252 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 8253 uint8_t *, digest_offset); 8254 8255 debug_hexdump(stdout, "digest:", ut_params->digest, 8256 tdata->digest_enc.len); 8257 debug_hexdump(stdout, "digest expected:", 8258 tdata->digest_enc.data, 8259 tdata->digest_enc.len); 8260 } 8261 8262 if (!verify) { 8263 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8264 ut_params->digest, 8265 tdata->digest_enc.data, 8266 tdata->digest_enc.len, 8267 "Generated auth tag not as expected"); 8268 } 8269 8270 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 8271 if (verify) { 8272 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 8273 plaintext, 8274 tdata->plaintext.data, 8275 tdata->plaintext.len_bits >> 3, 8276 "Plaintext data not as expected"); 8277 } else { 8278 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 8279 ciphertext, 8280 tdata->ciphertext.data, 8281 tdata->validDataLen.len_bits, 8282 "Ciphertext data not as expected"); 8283 } 8284 } 8285 8286 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8287 "crypto op processing failed"); 8288 8289 return 0; 8290 } 8291 8292 static int 8293 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata, 8294 uint8_t op_mode, uint8_t verify) 8295 { 8296 struct crypto_testsuite_params *ts_params = &testsuite_params; 8297 struct crypto_unittest_params *ut_params = &unittest_params; 8298 8299 int retval; 8300 8301 const uint8_t *plaintext = NULL; 8302 const uint8_t *ciphertext = NULL; 8303 const uint8_t *digest = NULL; 8304 unsigned int plaintext_pad_len; 8305 unsigned int plaintext_len; 8306 unsigned int ciphertext_pad_len; 8307 unsigned int ciphertext_len; 8308 uint8_t buffer[10000]; 8309 uint8_t digest_buffer[10000]; 8310 8311 struct rte_cryptodev_info dev_info; 8312 struct rte_crypto_op *op; 8313 8314 /* Check if device supports particular algorithms */ 8315 if (test_mixed_check_if_unsupported(tdata)) 8316 return TEST_SKIPPED; 8317 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 8318 return TEST_SKIPPED; 8319 8320 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8321 8322 uint64_t feat_flags = dev_info.feature_flags; 8323 8324 if (op_mode == IN_PLACE) { 8325 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 8326 printf("Device doesn't support in-place scatter-gather " 8327 "in both input and output mbufs.\n"); 8328 return TEST_SKIPPED; 8329 } 8330 } else { 8331 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 8332 printf("Device doesn't support out-of-place scatter-gather " 8333 "in both input and output mbufs.\n"); 8334 return TEST_SKIPPED; 8335 } 8336 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 8337 printf("Device doesn't support digest encrypted.\n"); 8338 return TEST_SKIPPED; 8339 } 8340 } 8341 8342 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8343 return TEST_SKIPPED; 8344 8345 /* Create the session */ 8346 if (verify) 8347 retval = create_wireless_algo_cipher_auth_session( 8348 ts_params->valid_devs[0], 8349 RTE_CRYPTO_CIPHER_OP_DECRYPT, 8350 RTE_CRYPTO_AUTH_OP_VERIFY, 8351 tdata->auth_algo, 8352 tdata->cipher_algo, 8353 tdata->auth_key.data, tdata->auth_key.len, 8354 tdata->cipher_key.data, tdata->cipher_key.len, 8355 tdata->auth_iv.len, tdata->digest_enc.len, 8356 tdata->cipher_iv.len); 8357 else 8358 retval = create_wireless_algo_auth_cipher_session( 8359 ts_params->valid_devs[0], 8360 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8361 RTE_CRYPTO_AUTH_OP_GENERATE, 8362 tdata->auth_algo, 8363 tdata->cipher_algo, 8364 tdata->auth_key.data, tdata->auth_key.len, 8365 tdata->cipher_key.data, tdata->cipher_key.len, 8366 tdata->auth_iv.len, tdata->digest_enc.len, 8367 tdata->cipher_iv.len); 8368 if (retval != 0) 8369 return retval; 8370 8371 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 8372 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 8373 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 8374 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 8375 8376 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 8377 ciphertext_pad_len, 15, 0); 8378 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 8379 "Failed to allocate input buffer in mempool"); 8380 8381 if (op_mode == OUT_OF_PLACE) { 8382 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 8383 plaintext_pad_len, 15, 0); 8384 TEST_ASSERT_NOT_NULL(ut_params->obuf, 8385 "Failed to allocate output buffer in mempool"); 8386 } 8387 8388 if (verify) { 8389 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 8390 tdata->ciphertext.data); 8391 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 8392 ciphertext_len, buffer); 8393 debug_hexdump(stdout, "ciphertext:", ciphertext, 8394 ciphertext_len); 8395 } else { 8396 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 8397 tdata->plaintext.data); 8398 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 8399 plaintext_len, buffer); 8400 debug_hexdump(stdout, "plaintext:", plaintext, 8401 plaintext_len); 8402 } 8403 memset(buffer, 0, sizeof(buffer)); 8404 8405 /* Create the operation */ 8406 retval = create_wireless_algo_auth_cipher_operation( 8407 tdata->digest_enc.data, tdata->digest_enc.len, 8408 tdata->cipher_iv.data, tdata->cipher_iv.len, 8409 tdata->auth_iv.data, tdata->auth_iv.len, 8410 (tdata->digest_enc.offset == 0 ? 8411 plaintext_pad_len 8412 : tdata->digest_enc.offset), 8413 tdata->validCipherLen.len_bits, 8414 tdata->cipher.offset_bits, 8415 tdata->validAuthLen.len_bits, 8416 tdata->auth.offset_bits, 8417 op_mode, 1, verify); 8418 8419 if (retval < 0) 8420 return retval; 8421 8422 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 8423 8424 /* Check if the op failed because the device doesn't */ 8425 /* support this particular combination of algorithms */ 8426 if (op == NULL && ut_params->op->status == 8427 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 8428 printf("Device doesn't support this mixed combination. " 8429 "Test Skipped.\n"); 8430 return TEST_SKIPPED; 8431 } 8432 ut_params->op = op; 8433 8434 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 8435 8436 ut_params->obuf = (op_mode == IN_PLACE ? 8437 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 8438 8439 if (verify) { 8440 if (ut_params->obuf) 8441 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 8442 plaintext_len, buffer); 8443 else 8444 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 8445 plaintext_len, buffer); 8446 8447 debug_hexdump(stdout, "plaintext:", plaintext, 8448 (tdata->plaintext.len_bits >> 3) - 8449 tdata->digest_enc.len); 8450 debug_hexdump(stdout, "plaintext expected:", 8451 tdata->plaintext.data, 8452 (tdata->plaintext.len_bits >> 3) - 8453 tdata->digest_enc.len); 8454 } else { 8455 if (ut_params->obuf) 8456 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 8457 ciphertext_len, buffer); 8458 else 8459 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 8460 ciphertext_len, buffer); 8461 8462 debug_hexdump(stdout, "ciphertext:", ciphertext, 8463 ciphertext_len); 8464 debug_hexdump(stdout, "ciphertext expected:", 8465 tdata->ciphertext.data, 8466 tdata->ciphertext.len_bits >> 3); 8467 8468 if (ut_params->obuf) 8469 digest = rte_pktmbuf_read(ut_params->obuf, 8470 (tdata->digest_enc.offset == 0 ? 8471 plaintext_pad_len : 8472 tdata->digest_enc.offset), 8473 tdata->digest_enc.len, digest_buffer); 8474 else 8475 digest = rte_pktmbuf_read(ut_params->ibuf, 8476 (tdata->digest_enc.offset == 0 ? 8477 plaintext_pad_len : 8478 tdata->digest_enc.offset), 8479 tdata->digest_enc.len, digest_buffer); 8480 8481 debug_hexdump(stdout, "digest:", digest, 8482 tdata->digest_enc.len); 8483 debug_hexdump(stdout, "digest expected:", 8484 tdata->digest_enc.data, tdata->digest_enc.len); 8485 } 8486 8487 if (!verify) { 8488 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8489 digest, 8490 tdata->digest_enc.data, 8491 tdata->digest_enc.len, 8492 "Generated auth tag not as expected"); 8493 } 8494 8495 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 8496 if (verify) { 8497 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 8498 plaintext, 8499 tdata->plaintext.data, 8500 tdata->plaintext.len_bits >> 3, 8501 "Plaintext data not as expected"); 8502 } else { 8503 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 8504 ciphertext, 8505 tdata->ciphertext.data, 8506 tdata->validDataLen.len_bits, 8507 "Ciphertext data not as expected"); 8508 } 8509 } 8510 8511 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8512 "crypto op processing failed"); 8513 8514 return 0; 8515 } 8516 8517 /** AUTH AES CMAC + CIPHER AES CTR */ 8518 8519 static int 8520 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 8521 { 8522 return test_mixed_auth_cipher( 8523 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8524 } 8525 8526 static int 8527 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 8528 { 8529 return test_mixed_auth_cipher( 8530 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8531 } 8532 8533 static int 8534 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 8535 { 8536 return test_mixed_auth_cipher_sgl( 8537 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8538 } 8539 8540 static int 8541 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 8542 { 8543 return test_mixed_auth_cipher_sgl( 8544 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8545 } 8546 8547 static int 8548 test_aes_cmac_aes_ctr_digest_enc_test_case_2(void) 8549 { 8550 return test_mixed_auth_cipher( 8551 &auth_aes_cmac_cipher_aes_ctr_test_case_2, IN_PLACE, 0); 8552 } 8553 8554 static int 8555 test_aes_cmac_aes_ctr_digest_enc_test_case_2_oop(void) 8556 { 8557 return test_mixed_auth_cipher( 8558 &auth_aes_cmac_cipher_aes_ctr_test_case_2, OUT_OF_PLACE, 0); 8559 } 8560 8561 static int 8562 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 8563 { 8564 return test_mixed_auth_cipher( 8565 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8566 } 8567 8568 static int 8569 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2(void) 8570 { 8571 return test_mixed_auth_cipher( 8572 &auth_aes_cmac_cipher_aes_ctr_test_case_2, IN_PLACE, 1); 8573 } 8574 8575 static int 8576 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 8577 { 8578 return test_mixed_auth_cipher( 8579 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8580 } 8581 8582 static int 8583 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 8584 { 8585 return test_mixed_auth_cipher_sgl( 8586 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8587 } 8588 8589 static int 8590 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 8591 { 8592 return test_mixed_auth_cipher_sgl( 8593 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8594 } 8595 8596 static int 8597 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2_oop(void) 8598 { 8599 return test_mixed_auth_cipher( 8600 &auth_aes_cmac_cipher_aes_ctr_test_case_2, OUT_OF_PLACE, 1); 8601 } 8602 8603 /** MIXED AUTH + CIPHER */ 8604 8605 static int 8606 test_auth_zuc_cipher_snow_test_case_1(void) 8607 { 8608 return test_mixed_auth_cipher( 8609 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 8610 } 8611 8612 static int 8613 test_verify_auth_zuc_cipher_snow_test_case_1(void) 8614 { 8615 return test_mixed_auth_cipher( 8616 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 8617 } 8618 8619 static int 8620 test_auth_zuc_cipher_snow_test_case_1_inplace(void) 8621 { 8622 return test_mixed_auth_cipher( 8623 &auth_zuc_cipher_snow_test_case_1, IN_PLACE, 0); 8624 } 8625 8626 static int 8627 test_verify_auth_zuc_cipher_snow_test_case_1_inplace(void) 8628 { 8629 return test_mixed_auth_cipher( 8630 &auth_zuc_cipher_snow_test_case_1, IN_PLACE, 1); 8631 } 8632 8633 8634 static int 8635 test_auth_aes_cmac_cipher_snow_test_case_1(void) 8636 { 8637 return test_mixed_auth_cipher( 8638 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 8639 } 8640 8641 static int 8642 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void) 8643 { 8644 return test_mixed_auth_cipher( 8645 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 8646 } 8647 8648 static int 8649 test_auth_aes_cmac_cipher_snow_test_case_1_inplace(void) 8650 { 8651 return test_mixed_auth_cipher( 8652 &auth_aes_cmac_cipher_snow_test_case_1, IN_PLACE, 0); 8653 } 8654 8655 static int 8656 test_verify_auth_aes_cmac_cipher_snow_test_case_1_inplace(void) 8657 { 8658 return test_mixed_auth_cipher( 8659 &auth_aes_cmac_cipher_snow_test_case_1, IN_PLACE, 1); 8660 } 8661 8662 static int 8663 test_auth_zuc_cipher_aes_ctr_test_case_1(void) 8664 { 8665 return test_mixed_auth_cipher( 8666 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8667 } 8668 8669 static int 8670 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void) 8671 { 8672 return test_mixed_auth_cipher( 8673 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8674 } 8675 8676 static int 8677 test_auth_zuc_cipher_aes_ctr_test_case_1_inplace(void) 8678 { 8679 return test_mixed_auth_cipher( 8680 &auth_zuc_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8681 } 8682 8683 static int 8684 test_verify_auth_zuc_cipher_aes_ctr_test_case_1_inplace(void) 8685 { 8686 return test_mixed_auth_cipher( 8687 &auth_zuc_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8688 } 8689 8690 static int 8691 test_auth_snow_cipher_aes_ctr_test_case_1(void) 8692 { 8693 return test_mixed_auth_cipher( 8694 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8695 } 8696 8697 static int 8698 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void) 8699 { 8700 return test_mixed_auth_cipher( 8701 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8702 } 8703 8704 static int 8705 test_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl(void) 8706 { 8707 return test_mixed_auth_cipher_sgl( 8708 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8709 } 8710 8711 static int 8712 test_auth_snow_cipher_aes_ctr_test_case_1_inplace(void) 8713 { 8714 return test_mixed_auth_cipher( 8715 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8716 } 8717 8718 static int 8719 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl(void) 8720 { 8721 return test_mixed_auth_cipher_sgl( 8722 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8723 } 8724 8725 static int 8726 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace(void) 8727 { 8728 return test_mixed_auth_cipher( 8729 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8730 } 8731 8732 static int 8733 test_auth_snow_cipher_zuc_test_case_1(void) 8734 { 8735 return test_mixed_auth_cipher( 8736 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 8737 } 8738 8739 static int 8740 test_verify_auth_snow_cipher_zuc_test_case_1(void) 8741 { 8742 return test_mixed_auth_cipher( 8743 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 8744 } 8745 8746 static int 8747 test_auth_snow_cipher_zuc_test_case_1_inplace(void) 8748 { 8749 return test_mixed_auth_cipher( 8750 &auth_snow_cipher_zuc_test_case_1, IN_PLACE, 0); 8751 } 8752 8753 static int 8754 test_verify_auth_snow_cipher_zuc_test_case_1_inplace(void) 8755 { 8756 return test_mixed_auth_cipher( 8757 &auth_snow_cipher_zuc_test_case_1, IN_PLACE, 1); 8758 } 8759 8760 static int 8761 test_auth_aes_cmac_cipher_zuc_test_case_1(void) 8762 { 8763 return test_mixed_auth_cipher( 8764 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 8765 } 8766 8767 static int 8768 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void) 8769 { 8770 return test_mixed_auth_cipher( 8771 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 8772 } 8773 static int 8774 test_auth_aes_cmac_cipher_zuc_test_case_1_inplace(void) 8775 { 8776 return test_mixed_auth_cipher( 8777 &auth_aes_cmac_cipher_zuc_test_case_1, IN_PLACE, 0); 8778 } 8779 8780 static int 8781 test_verify_auth_aes_cmac_cipher_zuc_test_case_1_inplace(void) 8782 { 8783 return test_mixed_auth_cipher( 8784 &auth_aes_cmac_cipher_zuc_test_case_1, IN_PLACE, 1); 8785 } 8786 8787 static int 8788 test_auth_null_cipher_snow_test_case_1(void) 8789 { 8790 return test_mixed_auth_cipher( 8791 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 8792 } 8793 8794 static int 8795 test_verify_auth_null_cipher_snow_test_case_1(void) 8796 { 8797 return test_mixed_auth_cipher( 8798 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 8799 } 8800 8801 static int 8802 test_auth_null_cipher_zuc_test_case_1(void) 8803 { 8804 return test_mixed_auth_cipher( 8805 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 8806 } 8807 8808 static int 8809 test_verify_auth_null_cipher_zuc_test_case_1(void) 8810 { 8811 return test_mixed_auth_cipher( 8812 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 8813 } 8814 8815 static int 8816 test_auth_snow_cipher_null_test_case_1(void) 8817 { 8818 return test_mixed_auth_cipher( 8819 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0); 8820 } 8821 8822 static int 8823 test_verify_auth_snow_cipher_null_test_case_1(void) 8824 { 8825 return test_mixed_auth_cipher( 8826 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1); 8827 } 8828 8829 static int 8830 test_auth_zuc_cipher_null_test_case_1(void) 8831 { 8832 return test_mixed_auth_cipher( 8833 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0); 8834 } 8835 8836 static int 8837 test_verify_auth_zuc_cipher_null_test_case_1(void) 8838 { 8839 return test_mixed_auth_cipher( 8840 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1); 8841 } 8842 8843 static int 8844 test_auth_null_cipher_aes_ctr_test_case_1(void) 8845 { 8846 return test_mixed_auth_cipher( 8847 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8848 } 8849 8850 static int 8851 test_verify_auth_null_cipher_aes_ctr_test_case_1(void) 8852 { 8853 return test_mixed_auth_cipher( 8854 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8855 } 8856 8857 static int 8858 test_auth_aes_cmac_cipher_null_test_case_1(void) 8859 { 8860 return test_mixed_auth_cipher( 8861 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0); 8862 } 8863 8864 static int 8865 test_verify_auth_aes_cmac_cipher_null_test_case_1(void) 8866 { 8867 return test_mixed_auth_cipher( 8868 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1); 8869 } 8870 8871 /* ***** AEAD algorithm Tests ***** */ 8872 8873 static int 8874 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo, 8875 enum rte_crypto_aead_operation op, 8876 const uint8_t *key, const uint8_t key_len, 8877 const uint16_t aad_len, const uint8_t auth_len, 8878 uint8_t iv_len) 8879 { 8880 uint8_t aead_key[key_len]; 8881 8882 struct crypto_testsuite_params *ts_params = &testsuite_params; 8883 struct crypto_unittest_params *ut_params = &unittest_params; 8884 8885 memcpy(aead_key, key, key_len); 8886 8887 /* Setup AEAD Parameters */ 8888 ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 8889 ut_params->aead_xform.next = NULL; 8890 ut_params->aead_xform.aead.algo = algo; 8891 ut_params->aead_xform.aead.op = op; 8892 ut_params->aead_xform.aead.key.data = aead_key; 8893 ut_params->aead_xform.aead.key.length = key_len; 8894 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 8895 ut_params->aead_xform.aead.iv.length = iv_len; 8896 ut_params->aead_xform.aead.digest_length = auth_len; 8897 ut_params->aead_xform.aead.aad_length = aad_len; 8898 8899 debug_hexdump(stdout, "key:", key, key_len); 8900 8901 /* Create Crypto session*/ 8902 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 8903 &ut_params->aead_xform, ts_params->session_mpool); 8904 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 8905 return TEST_SKIPPED; 8906 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 8907 return 0; 8908 } 8909 8910 static int 8911 create_aead_xform(struct rte_crypto_op *op, 8912 enum rte_crypto_aead_algorithm algo, 8913 enum rte_crypto_aead_operation aead_op, 8914 uint8_t *key, const uint8_t key_len, 8915 const uint8_t aad_len, const uint8_t auth_len, 8916 uint8_t iv_len) 8917 { 8918 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1), 8919 "failed to allocate space for crypto transform"); 8920 8921 struct rte_crypto_sym_op *sym_op = op->sym; 8922 8923 /* Setup AEAD Parameters */ 8924 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD; 8925 sym_op->xform->next = NULL; 8926 sym_op->xform->aead.algo = algo; 8927 sym_op->xform->aead.op = aead_op; 8928 sym_op->xform->aead.key.data = key; 8929 sym_op->xform->aead.key.length = key_len; 8930 sym_op->xform->aead.iv.offset = IV_OFFSET; 8931 sym_op->xform->aead.iv.length = iv_len; 8932 sym_op->xform->aead.digest_length = auth_len; 8933 sym_op->xform->aead.aad_length = aad_len; 8934 8935 debug_hexdump(stdout, "key:", key, key_len); 8936 8937 return 0; 8938 } 8939 8940 static int 8941 create_aead_operation(enum rte_crypto_aead_operation op, 8942 const struct aead_test_data *tdata) 8943 { 8944 struct crypto_testsuite_params *ts_params = &testsuite_params; 8945 struct crypto_unittest_params *ut_params = &unittest_params; 8946 8947 uint8_t *plaintext, *ciphertext; 8948 unsigned int aad_pad_len, plaintext_pad_len; 8949 8950 /* Generate Crypto op data structure */ 8951 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8952 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8953 TEST_ASSERT_NOT_NULL(ut_params->op, 8954 "Failed to allocate symmetric crypto operation struct"); 8955 8956 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 8957 8958 /* Append aad data */ 8959 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 8960 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16); 8961 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8962 aad_pad_len); 8963 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8964 "no room to append aad"); 8965 8966 sym_op->aead.aad.phys_addr = 8967 rte_pktmbuf_iova(ut_params->ibuf); 8968 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 8969 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len); 8970 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data + 18, 8971 tdata->aad.len); 8972 8973 /* Append IV at the end of the crypto operation*/ 8974 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8975 uint8_t *, IV_OFFSET); 8976 8977 /* Copy IV 1 byte after the IV pointer, according to the API */ 8978 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len); 8979 debug_hexdump(stdout, "iv:", iv_ptr + 1, 8980 tdata->iv.len); 8981 } else { 8982 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 8983 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8984 aad_pad_len); 8985 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8986 "no room to append aad"); 8987 8988 sym_op->aead.aad.phys_addr = 8989 rte_pktmbuf_iova(ut_params->ibuf); 8990 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len); 8991 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 8992 tdata->aad.len); 8993 8994 /* Append IV at the end of the crypto operation*/ 8995 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8996 uint8_t *, IV_OFFSET); 8997 8998 if (tdata->iv.len == 0) { 8999 rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH); 9000 debug_hexdump(stdout, "iv:", iv_ptr, 9001 AES_GCM_J0_LENGTH); 9002 } else { 9003 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 9004 debug_hexdump(stdout, "iv:", iv_ptr, 9005 tdata->iv.len); 9006 } 9007 } 9008 9009 /* Append plaintext/ciphertext */ 9010 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 9011 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 9012 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9013 plaintext_pad_len); 9014 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 9015 9016 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 9017 debug_hexdump(stdout, "plaintext:", plaintext, 9018 tdata->plaintext.len); 9019 9020 if (ut_params->obuf) { 9021 ciphertext = (uint8_t *)rte_pktmbuf_append( 9022 ut_params->obuf, 9023 plaintext_pad_len + aad_pad_len); 9024 TEST_ASSERT_NOT_NULL(ciphertext, 9025 "no room to append ciphertext"); 9026 9027 memset(ciphertext + aad_pad_len, 0, 9028 tdata->ciphertext.len); 9029 } 9030 } else { 9031 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); 9032 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9033 plaintext_pad_len); 9034 TEST_ASSERT_NOT_NULL(ciphertext, 9035 "no room to append ciphertext"); 9036 9037 memcpy(ciphertext, tdata->ciphertext.data, 9038 tdata->ciphertext.len); 9039 debug_hexdump(stdout, "ciphertext:", ciphertext, 9040 tdata->ciphertext.len); 9041 9042 if (ut_params->obuf) { 9043 plaintext = (uint8_t *)rte_pktmbuf_append( 9044 ut_params->obuf, 9045 plaintext_pad_len + aad_pad_len); 9046 TEST_ASSERT_NOT_NULL(plaintext, 9047 "no room to append plaintext"); 9048 9049 memset(plaintext + aad_pad_len, 0, 9050 tdata->plaintext.len); 9051 } 9052 } 9053 9054 /* Append digest data */ 9055 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 9056 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 9057 ut_params->obuf ? ut_params->obuf : 9058 ut_params->ibuf, 9059 tdata->auth_tag.len); 9060 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 9061 "no room to append digest"); 9062 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len); 9063 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 9064 ut_params->obuf ? ut_params->obuf : 9065 ut_params->ibuf, 9066 plaintext_pad_len + 9067 aad_pad_len); 9068 } else { 9069 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 9070 ut_params->ibuf, tdata->auth_tag.len); 9071 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 9072 "no room to append digest"); 9073 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 9074 ut_params->ibuf, 9075 plaintext_pad_len + aad_pad_len); 9076 9077 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 9078 tdata->auth_tag.len); 9079 debug_hexdump(stdout, "digest:", 9080 sym_op->aead.digest.data, 9081 tdata->auth_tag.len); 9082 } 9083 9084 sym_op->aead.data.length = tdata->plaintext.len; 9085 sym_op->aead.data.offset = aad_pad_len; 9086 9087 return 0; 9088 } 9089 9090 static int 9091 test_authenticated_encryption_helper(const struct aead_test_data *tdata, bool use_ext_mbuf) 9092 { 9093 struct crypto_testsuite_params *ts_params = &testsuite_params; 9094 struct crypto_unittest_params *ut_params = &unittest_params; 9095 9096 int retval; 9097 uint8_t *ciphertext, *auth_tag; 9098 uint16_t plaintext_pad_len; 9099 uint32_t i; 9100 struct rte_cryptodev_info dev_info; 9101 9102 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9103 uint64_t feat_flags = dev_info.feature_flags; 9104 9105 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9106 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9107 printf("Device doesn't support RAW data-path APIs.\n"); 9108 return TEST_SKIPPED; 9109 } 9110 9111 /* Verify the capabilities */ 9112 struct rte_cryptodev_sym_capability_idx cap_idx; 9113 const struct rte_cryptodev_symmetric_capability *capability; 9114 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9115 cap_idx.algo.aead = tdata->algo; 9116 capability = rte_cryptodev_sym_capability_get( 9117 ts_params->valid_devs[0], &cap_idx); 9118 if (capability == NULL) 9119 return TEST_SKIPPED; 9120 if (rte_cryptodev_sym_capability_check_aead( 9121 capability, tdata->key.len, tdata->auth_tag.len, 9122 tdata->aad.len, tdata->iv.len)) 9123 return TEST_SKIPPED; 9124 9125 /* Create AEAD session */ 9126 retval = create_aead_session(ts_params->valid_devs[0], 9127 tdata->algo, 9128 RTE_CRYPTO_AEAD_OP_ENCRYPT, 9129 tdata->key.data, tdata->key.len, 9130 tdata->aad.len, tdata->auth_tag.len, 9131 tdata->iv.len); 9132 if (retval != TEST_SUCCESS) 9133 return retval; 9134 9135 if (tdata->aad.len > MBUF_SIZE) { 9136 if (use_ext_mbuf) { 9137 ut_params->ibuf = ext_mbuf_create(ts_params->large_mbuf_pool, 9138 AEAD_TEXT_MAX_LENGTH, 9139 1 /* nb_segs */, 9140 NULL); 9141 } else { 9142 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 9143 } 9144 /* Populate full size of add data */ 9145 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 9146 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 9147 } else { 9148 if (use_ext_mbuf) { 9149 ut_params->ibuf = ext_mbuf_create(ts_params->mbuf_pool, 9150 AEAD_TEXT_MAX_LENGTH, 9151 1 /* nb_segs */, 9152 NULL); 9153 } else { 9154 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9155 } 9156 } 9157 9158 /* clear mbuf payload */ 9159 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9160 rte_pktmbuf_tailroom(ut_params->ibuf)); 9161 9162 /* Create AEAD operation */ 9163 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 9164 if (retval < 0) 9165 return retval; 9166 9167 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9168 9169 ut_params->op->sym->m_src = ut_params->ibuf; 9170 9171 /* Process crypto operation */ 9172 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9173 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 9174 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 9175 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 9176 0); 9177 if (retval != TEST_SUCCESS) 9178 return retval; 9179 } else 9180 TEST_ASSERT_NOT_NULL( 9181 process_crypto_request(ts_params->valid_devs[0], 9182 ut_params->op), "failed to process sym crypto op"); 9183 9184 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9185 "crypto op processing failed"); 9186 9187 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 9188 9189 if (ut_params->op->sym->m_dst) { 9190 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 9191 uint8_t *); 9192 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 9193 uint8_t *, plaintext_pad_len); 9194 } else { 9195 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 9196 uint8_t *, 9197 ut_params->op->sym->cipher.data.offset); 9198 auth_tag = ciphertext + plaintext_pad_len; 9199 } 9200 9201 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 9202 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 9203 9204 /* Validate obuf */ 9205 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9206 ciphertext, 9207 tdata->ciphertext.data, 9208 tdata->ciphertext.len, 9209 "Ciphertext data not as expected"); 9210 9211 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9212 auth_tag, 9213 tdata->auth_tag.data, 9214 tdata->auth_tag.len, 9215 "Generated auth tag not as expected"); 9216 9217 return 0; 9218 9219 } 9220 9221 static int 9222 test_authenticated_encryption(const struct aead_test_data *tdata) 9223 { 9224 return test_authenticated_encryption_helper(tdata, false); 9225 } 9226 9227 #ifdef RTE_LIB_SECURITY 9228 static int 9229 security_proto_supported(enum rte_security_session_action_type action, 9230 enum rte_security_session_protocol proto) 9231 { 9232 struct crypto_testsuite_params *ts_params = &testsuite_params; 9233 9234 const struct rte_security_capability *capabilities; 9235 const struct rte_security_capability *capability; 9236 uint16_t i = 0; 9237 9238 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 9239 9240 9241 capabilities = rte_security_capabilities_get(ctx); 9242 9243 if (capabilities == NULL) 9244 return -ENOTSUP; 9245 9246 while ((capability = &capabilities[i++])->action != 9247 RTE_SECURITY_ACTION_TYPE_NONE) { 9248 if (capability->action == action && 9249 capability->protocol == proto) 9250 return 0; 9251 } 9252 9253 return -ENOTSUP; 9254 } 9255 9256 /* Basic algorithm run function for async inplace mode. 9257 * Creates a session from input parameters and runs one operation 9258 * on input_vec. Checks the output of the crypto operation against 9259 * output_vec. 9260 */ 9261 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc, 9262 enum rte_crypto_auth_operation opa, 9263 const uint8_t *input_vec, unsigned int input_vec_len, 9264 const uint8_t *output_vec, 9265 unsigned int output_vec_len, 9266 enum rte_crypto_cipher_algorithm cipher_alg, 9267 const uint8_t *cipher_key, uint32_t cipher_key_len, 9268 enum rte_crypto_auth_algorithm auth_alg, 9269 const uint8_t *auth_key, uint32_t auth_key_len, 9270 uint8_t bearer, enum rte_security_pdcp_domain domain, 9271 uint8_t packet_direction, uint8_t sn_size, 9272 uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap) 9273 { 9274 struct crypto_testsuite_params *ts_params = &testsuite_params; 9275 struct crypto_unittest_params *ut_params = &unittest_params; 9276 uint8_t *plaintext; 9277 int ret = TEST_SUCCESS; 9278 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 9279 struct rte_cryptodev_info dev_info; 9280 uint64_t feat_flags; 9281 9282 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9283 feat_flags = dev_info.feature_flags; 9284 9285 /* Verify the capabilities */ 9286 struct rte_security_capability_idx sec_cap_idx; 9287 9288 sec_cap_idx.action = ut_params->type; 9289 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 9290 sec_cap_idx.pdcp.domain = domain; 9291 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 9292 return TEST_SKIPPED; 9293 9294 /* Generate test mbuf data */ 9295 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9296 9297 /* clear mbuf payload */ 9298 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9299 rte_pktmbuf_tailroom(ut_params->ibuf)); 9300 9301 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9302 input_vec_len); 9303 memcpy(plaintext, input_vec, input_vec_len); 9304 9305 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9306 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9307 printf("Device does not support RAW data-path APIs.\n"); 9308 return TEST_SKIPPED; 9309 } 9310 /* Out of place support */ 9311 if (oop) { 9312 /* 9313 * For out-op-place we need to alloc another mbuf 9314 */ 9315 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9316 rte_pktmbuf_append(ut_params->obuf, output_vec_len); 9317 } 9318 9319 /* Setup Cipher Parameters */ 9320 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9321 ut_params->cipher_xform.cipher.algo = cipher_alg; 9322 ut_params->cipher_xform.cipher.op = opc; 9323 ut_params->cipher_xform.cipher.key.data = cipher_key; 9324 ut_params->cipher_xform.cipher.key.length = cipher_key_len; 9325 ut_params->cipher_xform.cipher.iv.length = 9326 packet_direction ? 4 : 0; 9327 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 9328 9329 /* Setup HMAC Parameters if ICV header is required */ 9330 if (auth_alg != 0) { 9331 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9332 ut_params->auth_xform.next = NULL; 9333 ut_params->auth_xform.auth.algo = auth_alg; 9334 ut_params->auth_xform.auth.op = opa; 9335 ut_params->auth_xform.auth.key.data = auth_key; 9336 ut_params->auth_xform.auth.key.length = auth_key_len; 9337 9338 ut_params->cipher_xform.next = &ut_params->auth_xform; 9339 } else { 9340 ut_params->cipher_xform.next = NULL; 9341 } 9342 9343 struct rte_security_session_conf sess_conf = { 9344 .action_type = ut_params->type, 9345 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 9346 {.pdcp = { 9347 .bearer = bearer, 9348 .domain = domain, 9349 .pkt_dir = packet_direction, 9350 .sn_size = sn_size, 9351 .hfn = packet_direction ? 0 : hfn, 9352 /** 9353 * hfn can be set as pdcp_test_hfn[i] 9354 * if hfn_ovrd is not set. Here, PDCP 9355 * packet direction is just used to 9356 * run half of the cases with session 9357 * HFN and other half with per packet 9358 * HFN. 9359 */ 9360 .hfn_threshold = hfn_threshold, 9361 .hfn_ovrd = packet_direction ? 1 : 0, 9362 .sdap_enabled = sdap, 9363 } }, 9364 .crypto_xform = &ut_params->cipher_xform 9365 }; 9366 9367 /* Create security session */ 9368 ut_params->sec_session = rte_security_session_create(ctx, 9369 &sess_conf, ts_params->session_mpool); 9370 9371 if (!ut_params->sec_session) { 9372 printf("TestCase %s()-%d line %d failed %s: ", 9373 __func__, i, __LINE__, "Failed to allocate session"); 9374 ret = TEST_FAILED; 9375 goto on_err; 9376 } 9377 9378 /* Generate crypto op data structure */ 9379 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9380 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9381 if (!ut_params->op) { 9382 printf("TestCase %s()-%d line %d failed %s: ", 9383 __func__, i, __LINE__, 9384 "Failed to allocate symmetric crypto operation struct"); 9385 ret = TEST_FAILED; 9386 goto on_err; 9387 } 9388 9389 uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op, 9390 uint32_t *, IV_OFFSET); 9391 *per_pkt_hfn = packet_direction ? hfn : 0; 9392 9393 rte_security_attach_session(ut_params->op, ut_params->sec_session); 9394 9395 /* set crypto operation source mbuf */ 9396 ut_params->op->sym->m_src = ut_params->ibuf; 9397 if (oop) 9398 ut_params->op->sym->m_dst = ut_params->obuf; 9399 9400 /* Process crypto operation */ 9401 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 9402 /* filling lengths */ 9403 ut_params->op->sym->cipher.data.length = ut_params->op->sym->m_src->pkt_len; 9404 ut_params->op->sym->auth.data.length = ut_params->op->sym->m_src->pkt_len; 9405 9406 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 0); 9407 if (ret != TEST_SUCCESS) 9408 return ret; 9409 } else { 9410 ut_params->op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 9411 } 9412 if (ut_params->op == NULL) { 9413 printf("TestCase %s()-%d line %d failed %s: ", 9414 __func__, i, __LINE__, 9415 "failed to process sym crypto op"); 9416 ret = TEST_FAILED; 9417 goto on_err; 9418 } 9419 9420 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 9421 printf("TestCase %s()-%d line %d failed %s: ", 9422 __func__, i, __LINE__, "crypto op processing failed"); 9423 ret = TEST_FAILED; 9424 goto on_err; 9425 } 9426 9427 /* Validate obuf */ 9428 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 9429 uint8_t *); 9430 if (oop) { 9431 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 9432 uint8_t *); 9433 } 9434 9435 if (memcmp(ciphertext, output_vec, output_vec_len)) { 9436 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 9437 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len); 9438 rte_hexdump(stdout, "reference", output_vec, output_vec_len); 9439 ret = TEST_FAILED; 9440 goto on_err; 9441 } 9442 9443 on_err: 9444 rte_crypto_op_free(ut_params->op); 9445 ut_params->op = NULL; 9446 9447 if (ut_params->sec_session) 9448 rte_security_session_destroy(ctx, ut_params->sec_session); 9449 ut_params->sec_session = NULL; 9450 9451 rte_pktmbuf_free(ut_params->ibuf); 9452 ut_params->ibuf = NULL; 9453 if (oop) { 9454 rte_pktmbuf_free(ut_params->obuf); 9455 ut_params->obuf = NULL; 9456 } 9457 9458 return ret; 9459 } 9460 9461 static int 9462 test_pdcp_proto_SGL(int i, int oop, 9463 enum rte_crypto_cipher_operation opc, 9464 enum rte_crypto_auth_operation opa, 9465 uint8_t *input_vec, 9466 unsigned int input_vec_len, 9467 uint8_t *output_vec, 9468 unsigned int output_vec_len, 9469 uint32_t fragsz, 9470 uint32_t fragsz_oop) 9471 { 9472 struct crypto_testsuite_params *ts_params = &testsuite_params; 9473 struct crypto_unittest_params *ut_params = &unittest_params; 9474 uint8_t *plaintext; 9475 struct rte_mbuf *buf, *buf_oop = NULL; 9476 int ret = TEST_SUCCESS; 9477 int to_trn = 0; 9478 int to_trn_tbl[16]; 9479 int segs = 1; 9480 unsigned int trn_data = 0; 9481 struct rte_cryptodev_info dev_info; 9482 uint64_t feat_flags; 9483 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 9484 struct rte_mbuf *temp_mbuf; 9485 9486 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9487 feat_flags = dev_info.feature_flags; 9488 9489 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9490 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9491 printf("Device does not support RAW data-path APIs.\n"); 9492 return -ENOTSUP; 9493 } 9494 /* Verify the capabilities */ 9495 struct rte_security_capability_idx sec_cap_idx; 9496 9497 sec_cap_idx.action = ut_params->type; 9498 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 9499 sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain; 9500 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 9501 return TEST_SKIPPED; 9502 9503 if (fragsz > input_vec_len) 9504 fragsz = input_vec_len; 9505 9506 uint16_t plaintext_len = fragsz; 9507 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 9508 9509 if (fragsz_oop > output_vec_len) 9510 frag_size_oop = output_vec_len; 9511 9512 int ecx = 0; 9513 if (input_vec_len % fragsz != 0) { 9514 if (input_vec_len / fragsz + 1 > 16) 9515 return 1; 9516 } else if (input_vec_len / fragsz > 16) 9517 return 1; 9518 9519 /* Out of place support */ 9520 if (oop) { 9521 /* 9522 * For out-op-place we need to alloc another mbuf 9523 */ 9524 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9525 rte_pktmbuf_append(ut_params->obuf, frag_size_oop); 9526 buf_oop = ut_params->obuf; 9527 } 9528 9529 /* Generate test mbuf data */ 9530 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9531 9532 /* clear mbuf payload */ 9533 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9534 rte_pktmbuf_tailroom(ut_params->ibuf)); 9535 9536 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9537 plaintext_len); 9538 memcpy(plaintext, input_vec, plaintext_len); 9539 trn_data += plaintext_len; 9540 9541 buf = ut_params->ibuf; 9542 9543 /* 9544 * Loop until no more fragments 9545 */ 9546 9547 while (trn_data < input_vec_len) { 9548 ++segs; 9549 to_trn = (input_vec_len - trn_data < fragsz) ? 9550 (input_vec_len - trn_data) : fragsz; 9551 9552 to_trn_tbl[ecx++] = to_trn; 9553 9554 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9555 buf = buf->next; 9556 9557 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 9558 rte_pktmbuf_tailroom(buf)); 9559 9560 /* OOP */ 9561 if (oop && !fragsz_oop) { 9562 buf_oop->next = 9563 rte_pktmbuf_alloc(ts_params->mbuf_pool); 9564 buf_oop = buf_oop->next; 9565 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 9566 0, rte_pktmbuf_tailroom(buf_oop)); 9567 rte_pktmbuf_append(buf_oop, to_trn); 9568 } 9569 9570 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 9571 to_trn); 9572 9573 memcpy(plaintext, input_vec + trn_data, to_trn); 9574 trn_data += to_trn; 9575 } 9576 9577 ut_params->ibuf->nb_segs = segs; 9578 9579 segs = 1; 9580 if (fragsz_oop && oop) { 9581 to_trn = 0; 9582 ecx = 0; 9583 9584 trn_data = frag_size_oop; 9585 while (trn_data < output_vec_len) { 9586 ++segs; 9587 to_trn = 9588 (output_vec_len - trn_data < 9589 frag_size_oop) ? 9590 (output_vec_len - trn_data) : 9591 frag_size_oop; 9592 9593 to_trn_tbl[ecx++] = to_trn; 9594 9595 buf_oop->next = 9596 rte_pktmbuf_alloc(ts_params->mbuf_pool); 9597 buf_oop = buf_oop->next; 9598 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 9599 0, rte_pktmbuf_tailroom(buf_oop)); 9600 rte_pktmbuf_append(buf_oop, to_trn); 9601 9602 trn_data += to_trn; 9603 } 9604 ut_params->obuf->nb_segs = segs; 9605 } 9606 9607 /* Setup Cipher Parameters */ 9608 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9609 ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg; 9610 ut_params->cipher_xform.cipher.op = opc; 9611 ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i]; 9612 ut_params->cipher_xform.cipher.key.length = 9613 pdcp_test_params[i].cipher_key_len; 9614 ut_params->cipher_xform.cipher.iv.length = 0; 9615 9616 /* Setup HMAC Parameters if ICV header is required */ 9617 if (pdcp_test_params[i].auth_alg != 0) { 9618 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9619 ut_params->auth_xform.next = NULL; 9620 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg; 9621 ut_params->auth_xform.auth.op = opa; 9622 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i]; 9623 ut_params->auth_xform.auth.key.length = 9624 pdcp_test_params[i].auth_key_len; 9625 9626 ut_params->cipher_xform.next = &ut_params->auth_xform; 9627 } else { 9628 ut_params->cipher_xform.next = NULL; 9629 } 9630 9631 struct rte_security_session_conf sess_conf = { 9632 .action_type = ut_params->type, 9633 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 9634 {.pdcp = { 9635 .bearer = pdcp_test_bearer[i], 9636 .domain = pdcp_test_params[i].domain, 9637 .pkt_dir = pdcp_test_packet_direction[i], 9638 .sn_size = pdcp_test_data_sn_size[i], 9639 .hfn = pdcp_test_hfn[i], 9640 .hfn_threshold = pdcp_test_hfn_threshold[i], 9641 .hfn_ovrd = 0, 9642 } }, 9643 .crypto_xform = &ut_params->cipher_xform 9644 }; 9645 9646 /* Create security session */ 9647 ut_params->sec_session = rte_security_session_create(ctx, 9648 &sess_conf, ts_params->session_mpool); 9649 9650 if (!ut_params->sec_session) { 9651 printf("TestCase %s()-%d line %d failed %s: ", 9652 __func__, i, __LINE__, "Failed to allocate session"); 9653 ret = TEST_FAILED; 9654 goto on_err; 9655 } 9656 9657 /* Generate crypto op data structure */ 9658 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9659 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9660 if (!ut_params->op) { 9661 printf("TestCase %s()-%d line %d failed %s: ", 9662 __func__, i, __LINE__, 9663 "Failed to allocate symmetric crypto operation struct"); 9664 ret = TEST_FAILED; 9665 goto on_err; 9666 } 9667 9668 rte_security_attach_session(ut_params->op, ut_params->sec_session); 9669 9670 /* set crypto operation source mbuf */ 9671 ut_params->op->sym->m_src = ut_params->ibuf; 9672 if (oop) 9673 ut_params->op->sym->m_dst = ut_params->obuf; 9674 9675 /* Process crypto operation */ 9676 temp_mbuf = ut_params->op->sym->m_src; 9677 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 9678 /* filling lengths */ 9679 while (temp_mbuf) { 9680 ut_params->op->sym->cipher.data.length 9681 += temp_mbuf->pkt_len; 9682 ut_params->op->sym->auth.data.length 9683 += temp_mbuf->pkt_len; 9684 temp_mbuf = temp_mbuf->next; 9685 } 9686 9687 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 0); 9688 if (ret != TEST_SUCCESS) 9689 return ret; 9690 } else { 9691 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 9692 ut_params->op); 9693 } 9694 if (ut_params->op == NULL) { 9695 printf("TestCase %s()-%d line %d failed %s: ", 9696 __func__, i, __LINE__, 9697 "failed to process sym crypto op"); 9698 ret = TEST_FAILED; 9699 goto on_err; 9700 } 9701 9702 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 9703 printf("TestCase %s()-%d line %d failed %s: ", 9704 __func__, i, __LINE__, "crypto op processing failed"); 9705 ret = TEST_FAILED; 9706 goto on_err; 9707 } 9708 9709 /* Validate obuf */ 9710 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 9711 uint8_t *); 9712 if (oop) { 9713 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 9714 uint8_t *); 9715 } 9716 if (fragsz_oop) 9717 fragsz = frag_size_oop; 9718 if (memcmp(ciphertext, output_vec, fragsz)) { 9719 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 9720 rte_hexdump(stdout, "encrypted", ciphertext, fragsz); 9721 rte_hexdump(stdout, "reference", output_vec, fragsz); 9722 ret = TEST_FAILED; 9723 goto on_err; 9724 } 9725 9726 buf = ut_params->op->sym->m_src->next; 9727 if (oop) 9728 buf = ut_params->op->sym->m_dst->next; 9729 9730 unsigned int off = fragsz; 9731 9732 ecx = 0; 9733 while (buf) { 9734 ciphertext = rte_pktmbuf_mtod(buf, 9735 uint8_t *); 9736 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) { 9737 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 9738 rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]); 9739 rte_hexdump(stdout, "reference", output_vec + off, 9740 to_trn_tbl[ecx]); 9741 ret = TEST_FAILED; 9742 goto on_err; 9743 } 9744 off += to_trn_tbl[ecx++]; 9745 buf = buf->next; 9746 } 9747 on_err: 9748 rte_crypto_op_free(ut_params->op); 9749 ut_params->op = NULL; 9750 9751 if (ut_params->sec_session) 9752 rte_security_session_destroy(ctx, ut_params->sec_session); 9753 ut_params->sec_session = NULL; 9754 9755 rte_pktmbuf_free(ut_params->ibuf); 9756 ut_params->ibuf = NULL; 9757 if (oop) { 9758 rte_pktmbuf_free(ut_params->obuf); 9759 ut_params->obuf = NULL; 9760 } 9761 9762 return ret; 9763 } 9764 9765 int 9766 test_pdcp_proto_cplane_encap(int i) 9767 { 9768 return test_pdcp_proto( 9769 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 9770 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9771 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9772 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9773 pdcp_test_params[i].cipher_key_len, 9774 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9775 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9776 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9777 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9778 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9779 } 9780 9781 int 9782 test_pdcp_proto_uplane_encap(int i) 9783 { 9784 return test_pdcp_proto( 9785 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 9786 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9787 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 9788 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9789 pdcp_test_params[i].cipher_key_len, 9790 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9791 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9792 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9793 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9794 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9795 } 9796 9797 int 9798 test_pdcp_proto_uplane_encap_with_int(int i) 9799 { 9800 return test_pdcp_proto( 9801 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 9802 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9803 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9804 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9805 pdcp_test_params[i].cipher_key_len, 9806 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9807 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9808 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9809 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9810 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9811 } 9812 9813 int 9814 test_pdcp_proto_cplane_decap(int i) 9815 { 9816 return test_pdcp_proto( 9817 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 9818 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9819 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9820 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9821 pdcp_test_params[i].cipher_key_len, 9822 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9823 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9824 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9825 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9826 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9827 } 9828 9829 int 9830 test_pdcp_proto_uplane_decap(int i) 9831 { 9832 return test_pdcp_proto( 9833 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 9834 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 9835 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9836 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9837 pdcp_test_params[i].cipher_key_len, 9838 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9839 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9840 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9841 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9842 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9843 } 9844 9845 int 9846 test_pdcp_proto_uplane_decap_with_int(int i) 9847 { 9848 return test_pdcp_proto( 9849 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 9850 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9851 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9852 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9853 pdcp_test_params[i].cipher_key_len, 9854 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9855 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9856 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9857 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9858 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9859 } 9860 9861 static int 9862 test_PDCP_PROTO_SGL_in_place_32B(void) 9863 { 9864 /* i can be used for running any PDCP case 9865 * In this case it is uplane 12-bit AES-SNOW DL encap 9866 */ 9867 int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK; 9868 return test_pdcp_proto_SGL(i, IN_PLACE, 9869 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9870 RTE_CRYPTO_AUTH_OP_GENERATE, 9871 pdcp_test_data_in[i], 9872 pdcp_test_data_in_len[i], 9873 pdcp_test_data_out[i], 9874 pdcp_test_data_in_len[i]+4, 9875 32, 0); 9876 } 9877 static int 9878 test_PDCP_PROTO_SGL_oop_32B_128B(void) 9879 { 9880 /* i can be used for running any PDCP case 9881 * In this case it is uplane 18-bit NULL-NULL DL encap 9882 */ 9883 int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK; 9884 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9885 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9886 RTE_CRYPTO_AUTH_OP_GENERATE, 9887 pdcp_test_data_in[i], 9888 pdcp_test_data_in_len[i], 9889 pdcp_test_data_out[i], 9890 pdcp_test_data_in_len[i]+4, 9891 32, 128); 9892 } 9893 static int 9894 test_PDCP_PROTO_SGL_oop_32B_40B(void) 9895 { 9896 /* i can be used for running any PDCP case 9897 * In this case it is uplane 18-bit AES DL encap 9898 */ 9899 int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET 9900 + DOWNLINK; 9901 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9902 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9903 RTE_CRYPTO_AUTH_OP_GENERATE, 9904 pdcp_test_data_in[i], 9905 pdcp_test_data_in_len[i], 9906 pdcp_test_data_out[i], 9907 pdcp_test_data_in_len[i], 9908 32, 40); 9909 } 9910 static int 9911 test_PDCP_PROTO_SGL_oop_128B_32B(void) 9912 { 9913 /* i can be used for running any PDCP case 9914 * In this case it is cplane 12-bit AES-ZUC DL encap 9915 */ 9916 int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK; 9917 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9918 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9919 RTE_CRYPTO_AUTH_OP_GENERATE, 9920 pdcp_test_data_in[i], 9921 pdcp_test_data_in_len[i], 9922 pdcp_test_data_out[i], 9923 pdcp_test_data_in_len[i]+4, 9924 128, 32); 9925 } 9926 9927 static int 9928 test_PDCP_SDAP_PROTO_encap_all(void) 9929 { 9930 int i = 0, size = 0; 9931 int err, all_err = TEST_SUCCESS; 9932 const struct pdcp_sdap_test *cur_test; 9933 9934 size = RTE_DIM(list_pdcp_sdap_tests); 9935 9936 for (i = 0; i < size; i++) { 9937 cur_test = &list_pdcp_sdap_tests[i]; 9938 err = test_pdcp_proto( 9939 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9940 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9941 cur_test->in_len, cur_test->data_out, 9942 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9943 cur_test->param.cipher_alg, cur_test->cipher_key, 9944 cur_test->param.cipher_key_len, 9945 cur_test->param.auth_alg, 9946 cur_test->auth_key, cur_test->param.auth_key_len, 9947 cur_test->bearer, cur_test->param.domain, 9948 cur_test->packet_direction, cur_test->sn_size, 9949 cur_test->hfn, 9950 cur_test->hfn_threshold, SDAP_ENABLED); 9951 if (err) { 9952 printf("\t%d) %s: Encapsulation failed\n", 9953 cur_test->test_idx, 9954 cur_test->param.name); 9955 err = TEST_FAILED; 9956 } else { 9957 printf("\t%d) %s: Encap PASS\n", cur_test->test_idx, 9958 cur_test->param.name); 9959 err = TEST_SUCCESS; 9960 } 9961 all_err += err; 9962 } 9963 9964 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9965 9966 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9967 } 9968 9969 static int 9970 test_PDCP_PROTO_short_mac(void) 9971 { 9972 int i = 0, size = 0; 9973 int err, all_err = TEST_SUCCESS; 9974 const struct pdcp_short_mac_test *cur_test; 9975 9976 size = RTE_DIM(list_pdcp_smac_tests); 9977 9978 for (i = 0; i < size; i++) { 9979 cur_test = &list_pdcp_smac_tests[i]; 9980 err = test_pdcp_proto( 9981 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9982 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9983 cur_test->in_len, cur_test->data_out, 9984 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9985 RTE_CRYPTO_CIPHER_NULL, NULL, 9986 0, cur_test->param.auth_alg, 9987 cur_test->auth_key, cur_test->param.auth_key_len, 9988 0, cur_test->param.domain, 0, 0, 9989 0, 0, 0); 9990 if (err) { 9991 printf("\t%d) %s: Short MAC test failed\n", 9992 cur_test->test_idx, 9993 cur_test->param.name); 9994 err = TEST_FAILED; 9995 } else { 9996 printf("\t%d) %s: Short MAC test PASS\n", 9997 cur_test->test_idx, 9998 cur_test->param.name); 9999 rte_hexdump(stdout, "MAC I", 10000 cur_test->data_out + cur_test->in_len + 2, 10001 2); 10002 err = TEST_SUCCESS; 10003 } 10004 all_err += err; 10005 } 10006 10007 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 10008 10009 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 10010 10011 } 10012 10013 static int 10014 test_PDCP_SDAP_PROTO_decap_all(void) 10015 { 10016 int i = 0, size = 0; 10017 int err, all_err = TEST_SUCCESS; 10018 const struct pdcp_sdap_test *cur_test; 10019 10020 size = RTE_DIM(list_pdcp_sdap_tests); 10021 10022 for (i = 0; i < size; i++) { 10023 cur_test = &list_pdcp_sdap_tests[i]; 10024 err = test_pdcp_proto( 10025 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, 10026 RTE_CRYPTO_AUTH_OP_VERIFY, 10027 cur_test->data_out, 10028 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 10029 cur_test->data_in, cur_test->in_len, 10030 cur_test->param.cipher_alg, 10031 cur_test->cipher_key, cur_test->param.cipher_key_len, 10032 cur_test->param.auth_alg, cur_test->auth_key, 10033 cur_test->param.auth_key_len, cur_test->bearer, 10034 cur_test->param.domain, cur_test->packet_direction, 10035 cur_test->sn_size, cur_test->hfn, 10036 cur_test->hfn_threshold, SDAP_ENABLED); 10037 if (err) { 10038 printf("\t%d) %s: Decapsulation failed\n", 10039 cur_test->test_idx, 10040 cur_test->param.name); 10041 err = TEST_FAILED; 10042 } else { 10043 printf("\t%d) %s: Decap PASS\n", cur_test->test_idx, 10044 cur_test->param.name); 10045 err = TEST_SUCCESS; 10046 } 10047 all_err += err; 10048 } 10049 10050 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 10051 10052 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 10053 } 10054 10055 static int 10056 test_ipsec_proto_crypto_op_enq(struct crypto_testsuite_params *ts_params, 10057 struct crypto_unittest_params *ut_params, 10058 struct rte_security_ipsec_xform *ipsec_xform, 10059 const struct ipsec_test_data *td, 10060 const struct ipsec_test_flags *flags, 10061 int pkt_num) 10062 { 10063 uint8_t dev_id = ts_params->valid_devs[0]; 10064 enum rte_security_ipsec_sa_direction dir; 10065 int ret; 10066 10067 dir = ipsec_xform->direction; 10068 10069 /* Generate crypto op data structure */ 10070 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10071 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10072 if (!ut_params->op) { 10073 printf("Could not allocate crypto op"); 10074 return TEST_FAILED; 10075 } 10076 10077 /* Attach session to operation */ 10078 rte_security_attach_session(ut_params->op, ut_params->sec_session); 10079 10080 /* Set crypto operation mbufs */ 10081 ut_params->op->sym->m_src = ut_params->ibuf; 10082 ut_params->op->sym->m_dst = NULL; 10083 10084 /* Copy IV in crypto operation when IV generation is disabled */ 10085 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS && 10086 ipsec_xform->options.iv_gen_disable == 1) { 10087 uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op, 10088 uint8_t *, 10089 IV_OFFSET); 10090 int len; 10091 10092 if (td->aead) 10093 len = td->xform.aead.aead.iv.length; 10094 else if (td->aes_gmac) 10095 len = td->xform.chain.auth.auth.iv.length; 10096 else 10097 len = td->xform.chain.cipher.cipher.iv.length; 10098 10099 memcpy(iv, td->iv.data, len); 10100 } 10101 10102 /* Process crypto operation */ 10103 process_crypto_request(dev_id, ut_params->op); 10104 10105 ret = test_ipsec_status_check(td, ut_params->op, flags, dir, pkt_num); 10106 10107 rte_crypto_op_free(ut_params->op); 10108 ut_params->op = NULL; 10109 10110 return ret; 10111 } 10112 10113 static int 10114 test_ipsec_proto_mbuf_enq(struct crypto_testsuite_params *ts_params, 10115 struct crypto_unittest_params *ut_params, 10116 void *ctx) 10117 { 10118 uint64_t timeout, userdata; 10119 struct rte_ether_hdr *hdr; 10120 struct rte_mbuf *m; 10121 void **sec_sess; 10122 int ret; 10123 10124 RTE_SET_USED(ts_params); 10125 10126 hdr = (void *)rte_pktmbuf_prepend(ut_params->ibuf, sizeof(struct rte_ether_hdr)); 10127 hdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4); 10128 10129 ut_params->ibuf->l2_len = sizeof(struct rte_ether_hdr); 10130 ut_params->ibuf->port = 0; 10131 10132 sec_sess = &ut_params->sec_session; 10133 ret = rte_security_inb_pkt_rx_inject(ctx, &ut_params->ibuf, sec_sess, 1); 10134 10135 if (ret != 1) 10136 return TEST_FAILED; 10137 10138 ut_params->ibuf = NULL; 10139 10140 /* Add a timeout for 1 s */ 10141 timeout = rte_get_tsc_cycles() + rte_get_tsc_hz(); 10142 10143 do { 10144 /* Get packet from port 0, queue 0 */ 10145 ret = rte_eth_rx_burst(0, 0, &m, 1); 10146 } while ((ret == 0) && (rte_get_tsc_cycles() < timeout)); 10147 10148 if (ret == 0) { 10149 printf("Could not receive packets from ethdev\n"); 10150 return TEST_FAILED; 10151 } 10152 10153 if (m == NULL) { 10154 printf("Received mbuf is NULL\n"); 10155 return TEST_FAILED; 10156 } 10157 10158 ut_params->ibuf = m; 10159 10160 if (!(m->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD)) { 10161 printf("Received packet is not Rx security processed\n"); 10162 return TEST_FAILED; 10163 } 10164 10165 if (m->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED) { 10166 printf("Received packet has failed Rx security processing\n"); 10167 return TEST_FAILED; 10168 } 10169 10170 /* 10171 * 'ut_params' is set as userdata. Verify that the field is returned 10172 * correctly. 10173 */ 10174 userdata = *(uint64_t *)rte_security_dynfield(m); 10175 if (userdata != (uint64_t)ut_params) { 10176 printf("Userdata retrieved not matching expected\n"); 10177 return TEST_FAILED; 10178 } 10179 10180 /* Trim L2 header */ 10181 rte_pktmbuf_adj(m, sizeof(struct rte_ether_hdr)); 10182 10183 return TEST_SUCCESS; 10184 } 10185 10186 static int 10187 test_ipsec_proto_process(const struct ipsec_test_data td[], 10188 struct ipsec_test_data res_d[], 10189 int nb_td, 10190 bool silent, 10191 const struct ipsec_test_flags *flags) 10192 { 10193 uint16_t v6_src[8] = {0x2607, 0xf8b0, 0x400c, 0x0c03, 0x0000, 0x0000, 10194 0x0000, 0x001a}; 10195 uint16_t v6_dst[8] = {0x2001, 0x0470, 0xe5bf, 0xdead, 0x4957, 0x2174, 10196 0xe82c, 0x4887}; 10197 const struct rte_ipv4_hdr *ipv4 = 10198 (const struct rte_ipv4_hdr *)td[0].output_text.data; 10199 int nb_segs = flags->nb_segs_in_mbuf ? flags->nb_segs_in_mbuf : 1; 10200 struct crypto_testsuite_params *ts_params = &testsuite_params; 10201 struct crypto_unittest_params *ut_params = &unittest_params; 10202 struct rte_security_capability_idx sec_cap_idx; 10203 const struct rte_security_capability *sec_cap; 10204 struct rte_security_ipsec_xform ipsec_xform; 10205 uint8_t dev_id = ts_params->valid_devs[0]; 10206 enum rte_security_ipsec_sa_direction dir; 10207 struct ipsec_test_data *res_d_tmp = NULL; 10208 uint8_t input_text[IPSEC_TEXT_MAX_LEN]; 10209 int salt_len, i, ret = TEST_SUCCESS; 10210 void *ctx; 10211 uint32_t src, dst; 10212 uint32_t verify; 10213 10214 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 10215 gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 10216 10217 /* Use first test data to create session */ 10218 10219 /* Copy IPsec xform */ 10220 memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform)); 10221 10222 dir = ipsec_xform.direction; 10223 verify = flags->tunnel_hdr_verify; 10224 10225 memcpy(&src, &ipv4->src_addr, sizeof(ipv4->src_addr)); 10226 memcpy(&dst, &ipv4->dst_addr, sizeof(ipv4->dst_addr)); 10227 10228 if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) { 10229 if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR) 10230 src += 1; 10231 else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR) 10232 dst += 1; 10233 } 10234 10235 if (td->ipsec_xform.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) { 10236 if (td->ipsec_xform.tunnel.type == 10237 RTE_SECURITY_IPSEC_TUNNEL_IPV4) { 10238 memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, 10239 sizeof(src)); 10240 memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, 10241 sizeof(dst)); 10242 10243 if (flags->df == TEST_IPSEC_SET_DF_0_INNER_1) 10244 ipsec_xform.tunnel.ipv4.df = 0; 10245 10246 if (flags->df == TEST_IPSEC_SET_DF_1_INNER_0) 10247 ipsec_xform.tunnel.ipv4.df = 1; 10248 10249 if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1) 10250 ipsec_xform.tunnel.ipv4.dscp = 0; 10251 10252 if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0) 10253 ipsec_xform.tunnel.ipv4.dscp = 10254 TEST_IPSEC_DSCP_VAL; 10255 10256 } else { 10257 if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1) 10258 ipsec_xform.tunnel.ipv6.dscp = 0; 10259 10260 if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0) 10261 ipsec_xform.tunnel.ipv6.dscp = 10262 TEST_IPSEC_DSCP_VAL; 10263 10264 memcpy(&ipsec_xform.tunnel.ipv6.src_addr, &v6_src, 10265 sizeof(v6_src)); 10266 memcpy(&ipsec_xform.tunnel.ipv6.dst_addr, &v6_dst, 10267 sizeof(v6_dst)); 10268 } 10269 } 10270 10271 ctx = rte_cryptodev_get_sec_ctx(dev_id); 10272 10273 sec_cap_idx.action = ut_params->type; 10274 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC; 10275 sec_cap_idx.ipsec.proto = ipsec_xform.proto; 10276 sec_cap_idx.ipsec.mode = ipsec_xform.mode; 10277 sec_cap_idx.ipsec.direction = ipsec_xform.direction; 10278 10279 if (flags->udp_encap) 10280 ipsec_xform.options.udp_encap = 1; 10281 10282 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 10283 if (sec_cap == NULL) 10284 return TEST_SKIPPED; 10285 10286 /* Copy cipher session parameters */ 10287 if (td[0].aead) { 10288 memcpy(&ut_params->aead_xform, &td[0].xform.aead, 10289 sizeof(ut_params->aead_xform)); 10290 ut_params->aead_xform.aead.key.data = td[0].key.data; 10291 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 10292 10293 /* Verify crypto capabilities */ 10294 if (test_sec_crypto_caps_aead_verify(sec_cap, &ut_params->aead_xform) != 0) { 10295 if (!silent) 10296 RTE_LOG(INFO, USER1, 10297 "Crypto capabilities not supported\n"); 10298 return TEST_SKIPPED; 10299 } 10300 } else if (td[0].auth_only) { 10301 memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth, 10302 sizeof(ut_params->auth_xform)); 10303 ut_params->auth_xform.auth.key.data = td[0].auth_key.data; 10304 10305 if (test_sec_crypto_caps_auth_verify(sec_cap, &ut_params->auth_xform) != 0) { 10306 if (!silent) 10307 RTE_LOG(INFO, USER1, 10308 "Auth crypto capabilities not supported\n"); 10309 return TEST_SKIPPED; 10310 } 10311 } else { 10312 memcpy(&ut_params->cipher_xform, &td[0].xform.chain.cipher, 10313 sizeof(ut_params->cipher_xform)); 10314 memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth, 10315 sizeof(ut_params->auth_xform)); 10316 ut_params->cipher_xform.cipher.key.data = td[0].key.data; 10317 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 10318 ut_params->auth_xform.auth.key.data = td[0].auth_key.data; 10319 10320 /* Verify crypto capabilities */ 10321 10322 if (test_sec_crypto_caps_cipher_verify(sec_cap, &ut_params->cipher_xform) != 0) { 10323 if (!silent) 10324 RTE_LOG(INFO, USER1, 10325 "Cipher crypto capabilities not supported\n"); 10326 return TEST_SKIPPED; 10327 } 10328 10329 if (test_sec_crypto_caps_auth_verify(sec_cap, &ut_params->auth_xform) != 0) { 10330 if (!silent) 10331 RTE_LOG(INFO, USER1, 10332 "Auth crypto capabilities not supported\n"); 10333 return TEST_SKIPPED; 10334 } 10335 } 10336 10337 if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0) 10338 return TEST_SKIPPED; 10339 10340 struct rte_security_session_conf sess_conf = { 10341 .action_type = ut_params->type, 10342 .protocol = RTE_SECURITY_PROTOCOL_IPSEC, 10343 }; 10344 10345 if (td[0].aead || td[0].aes_gmac) { 10346 salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len); 10347 memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len); 10348 } 10349 10350 if (td[0].aead) { 10351 sess_conf.ipsec = ipsec_xform; 10352 sess_conf.crypto_xform = &ut_params->aead_xform; 10353 } else if (td[0].auth_only) { 10354 sess_conf.ipsec = ipsec_xform; 10355 sess_conf.crypto_xform = &ut_params->auth_xform; 10356 } else { 10357 sess_conf.ipsec = ipsec_xform; 10358 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) { 10359 sess_conf.crypto_xform = &ut_params->cipher_xform; 10360 ut_params->cipher_xform.next = &ut_params->auth_xform; 10361 } else { 10362 sess_conf.crypto_xform = &ut_params->auth_xform; 10363 ut_params->auth_xform.next = &ut_params->cipher_xform; 10364 } 10365 } 10366 10367 if (dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS && flags->rx_inject) 10368 sess_conf.userdata = ut_params; 10369 10370 /* Create security session */ 10371 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 10372 ts_params->session_mpool); 10373 10374 if (ut_params->sec_session == NULL) 10375 return TEST_SKIPPED; 10376 10377 for (i = 0; i < nb_td; i++) { 10378 if (flags->antireplay && 10379 (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)) { 10380 sess_conf.ipsec.esn.value = td[i].ipsec_xform.esn.value; 10381 ret = rte_security_session_update(ctx, 10382 ut_params->sec_session, &sess_conf); 10383 if (ret) { 10384 printf("Could not update sequence number in " 10385 "session\n"); 10386 return TEST_SKIPPED; 10387 } 10388 } 10389 10390 /* Copy test data before modification */ 10391 memcpy(input_text, td[i].input_text.data, td[i].input_text.len); 10392 if (test_ipsec_pkt_update(input_text, flags)) { 10393 ret = TEST_FAILED; 10394 goto mbuf_free; 10395 } 10396 10397 /* Setup source mbuf payload */ 10398 if (flags->use_ext_mbuf) { 10399 ut_params->ibuf = ext_mbuf_create(ts_params->mbuf_pool, 10400 td[i].input_text.len, nb_segs, input_text); 10401 } else { 10402 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 10403 td[i].input_text.len, nb_segs, 0); 10404 pktmbuf_write(ut_params->ibuf, 0, td[i].input_text.len, input_text); 10405 } 10406 10407 if (dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS && flags->rx_inject) 10408 ret = test_ipsec_proto_mbuf_enq(ts_params, ut_params, 10409 ctx); 10410 else 10411 ret = test_ipsec_proto_crypto_op_enq(ts_params, 10412 ut_params, 10413 &ipsec_xform, 10414 &td[i], flags, 10415 i + 1); 10416 10417 if (ret != TEST_SUCCESS) 10418 goto mbuf_free; 10419 10420 if (res_d != NULL) 10421 res_d_tmp = &res_d[i]; 10422 10423 ret = test_ipsec_post_process(ut_params->ibuf, &td[i], 10424 res_d_tmp, silent, flags); 10425 if (ret != TEST_SUCCESS) 10426 goto mbuf_free; 10427 10428 ret = test_ipsec_stats_verify(ctx, ut_params->sec_session, 10429 flags, dir); 10430 if (ret != TEST_SUCCESS) 10431 goto mbuf_free; 10432 10433 rte_pktmbuf_free(ut_params->ibuf); 10434 ut_params->ibuf = NULL; 10435 } 10436 10437 mbuf_free: 10438 if (flags->use_ext_mbuf) 10439 ext_mbuf_memzone_free(nb_segs); 10440 10441 rte_pktmbuf_free(ut_params->ibuf); 10442 ut_params->ibuf = NULL; 10443 10444 if (ut_params->sec_session) 10445 rte_security_session_destroy(ctx, ut_params->sec_session); 10446 ut_params->sec_session = NULL; 10447 10448 return ret; 10449 } 10450 10451 static int 10452 test_ipsec_proto_known_vec(const void *test_data) 10453 { 10454 struct ipsec_test_data td_outb; 10455 struct ipsec_test_flags flags; 10456 10457 memset(&flags, 0, sizeof(flags)); 10458 10459 memcpy(&td_outb, test_data, sizeof(td_outb)); 10460 10461 if (td_outb.aes_gmac || td_outb.aead || 10462 ((td_outb.ipsec_xform.proto != RTE_SECURITY_IPSEC_SA_PROTO_AH) && 10463 (td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL))) { 10464 /* Disable IV gen to be able to test with known vectors */ 10465 td_outb.ipsec_xform.options.iv_gen_disable = 1; 10466 } 10467 10468 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 10469 } 10470 10471 static int 10472 test_ipsec_proto_known_vec_ext_mbuf(const void *test_data) 10473 { 10474 struct ipsec_test_data td_outb; 10475 struct ipsec_test_flags flags; 10476 10477 memset(&flags, 0, sizeof(flags)); 10478 flags.use_ext_mbuf = true; 10479 10480 memcpy(&td_outb, test_data, sizeof(td_outb)); 10481 10482 if (td_outb.aes_gmac || td_outb.aead || 10483 ((td_outb.ipsec_xform.proto != RTE_SECURITY_IPSEC_SA_PROTO_AH) && 10484 (td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL))) { 10485 /* Disable IV gen to be able to test with known vectors */ 10486 td_outb.ipsec_xform.options.iv_gen_disable = 1; 10487 } 10488 10489 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 10490 } 10491 10492 static int 10493 test_ipsec_proto_known_vec_inb(const void *test_data) 10494 { 10495 const struct ipsec_test_data *td = test_data; 10496 struct ipsec_test_flags flags; 10497 struct ipsec_test_data td_inb; 10498 10499 memset(&flags, 0, sizeof(flags)); 10500 10501 if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) 10502 test_ipsec_td_in_from_out(td, &td_inb); 10503 else 10504 memcpy(&td_inb, td, sizeof(td_inb)); 10505 10506 return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags); 10507 } 10508 10509 static int 10510 test_ipsec_proto_known_vec_fragmented(const void *test_data) 10511 { 10512 struct ipsec_test_data td_outb; 10513 struct ipsec_test_flags flags; 10514 10515 memset(&flags, 0, sizeof(flags)); 10516 flags.fragment = true; 10517 10518 memcpy(&td_outb, test_data, sizeof(td_outb)); 10519 10520 /* Disable IV gen to be able to test with known vectors */ 10521 td_outb.ipsec_xform.options.iv_gen_disable = 1; 10522 10523 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 10524 } 10525 10526 static int 10527 test_ipsec_proto_known_vec_inb_rx_inject(const void *test_data) 10528 { 10529 const struct ipsec_test_data *td = test_data; 10530 struct ipsec_test_flags flags; 10531 struct ipsec_test_data td_inb; 10532 10533 memset(&flags, 0, sizeof(flags)); 10534 flags.rx_inject = true; 10535 10536 if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) 10537 test_ipsec_td_in_from_out(td, &td_inb); 10538 else 10539 memcpy(&td_inb, td, sizeof(td_inb)); 10540 10541 return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags); 10542 } 10543 10544 static int 10545 test_ipsec_proto_all(const struct ipsec_test_flags *flags) 10546 { 10547 struct ipsec_test_data td_outb[TEST_SEC_PKTS_MAX]; 10548 struct ipsec_test_data td_inb[TEST_SEC_PKTS_MAX]; 10549 unsigned int i, nb_pkts = 1, pass_cnt = 0; 10550 int ret; 10551 10552 if (flags->iv_gen || 10553 flags->sa_expiry_pkts_soft || 10554 flags->sa_expiry_pkts_hard) 10555 nb_pkts = TEST_SEC_PKTS_MAX; 10556 10557 for (i = 0; i < RTE_DIM(sec_alg_list); i++) { 10558 test_ipsec_td_prepare(sec_alg_list[i].param1, 10559 sec_alg_list[i].param2, 10560 flags, 10561 td_outb, 10562 nb_pkts); 10563 10564 if (!td_outb->aead) { 10565 enum rte_crypto_cipher_algorithm cipher_alg; 10566 enum rte_crypto_auth_algorithm auth_alg; 10567 10568 cipher_alg = td_outb->xform.chain.cipher.cipher.algo; 10569 auth_alg = td_outb->xform.chain.auth.auth.algo; 10570 10571 if (td_outb->aes_gmac && cipher_alg != RTE_CRYPTO_CIPHER_NULL) 10572 continue; 10573 10574 /* ICV is not applicable for NULL auth */ 10575 if (flags->icv_corrupt && 10576 auth_alg == RTE_CRYPTO_AUTH_NULL) 10577 continue; 10578 10579 /* IV is not applicable for NULL cipher */ 10580 if (flags->iv_gen && 10581 cipher_alg == RTE_CRYPTO_CIPHER_NULL) 10582 continue; 10583 } 10584 10585 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 10586 flags); 10587 if (ret == TEST_SKIPPED) 10588 continue; 10589 10590 if (ret == TEST_FAILED) 10591 return TEST_FAILED; 10592 10593 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags); 10594 10595 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 10596 flags); 10597 if (ret == TEST_SKIPPED) 10598 continue; 10599 10600 if (ret == TEST_FAILED) 10601 return TEST_FAILED; 10602 10603 if (flags->display_alg) 10604 test_sec_alg_display(sec_alg_list[i].param1, sec_alg_list[i].param2); 10605 10606 pass_cnt++; 10607 } 10608 10609 if (pass_cnt > 0) 10610 return TEST_SUCCESS; 10611 else 10612 return TEST_SKIPPED; 10613 } 10614 10615 static int 10616 test_ipsec_ah_proto_all(const struct ipsec_test_flags *flags) 10617 { 10618 struct ipsec_test_data td_outb[TEST_SEC_PKTS_MAX]; 10619 struct ipsec_test_data td_inb[TEST_SEC_PKTS_MAX]; 10620 unsigned int i, nb_pkts = 1, pass_cnt = 0; 10621 int ret; 10622 10623 for (i = 0; i < RTE_DIM(sec_auth_only_alg_list); i++) { 10624 test_ipsec_td_prepare(sec_auth_only_alg_list[i].param1, 10625 sec_auth_only_alg_list[i].param2, 10626 flags, 10627 td_outb, 10628 nb_pkts); 10629 10630 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 10631 flags); 10632 if (ret == TEST_SKIPPED) 10633 continue; 10634 10635 if (ret == TEST_FAILED) 10636 return TEST_FAILED; 10637 10638 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags); 10639 10640 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 10641 flags); 10642 if (ret == TEST_SKIPPED) 10643 continue; 10644 10645 if (ret == TEST_FAILED) 10646 return TEST_FAILED; 10647 10648 if (flags->display_alg) 10649 test_sec_alg_display(sec_auth_only_alg_list[i].param1, 10650 sec_auth_only_alg_list[i].param2); 10651 10652 pass_cnt++; 10653 } 10654 10655 if (pass_cnt > 0) 10656 return TEST_SUCCESS; 10657 else 10658 return TEST_SKIPPED; 10659 } 10660 10661 static int 10662 test_ipsec_proto_display_list(void) 10663 { 10664 struct ipsec_test_flags flags; 10665 10666 memset(&flags, 0, sizeof(flags)); 10667 10668 flags.display_alg = true; 10669 10670 return test_ipsec_proto_all(&flags); 10671 } 10672 10673 static int 10674 test_ipsec_proto_ah_tunnel_ipv4(void) 10675 { 10676 struct ipsec_test_flags flags; 10677 10678 memset(&flags, 0, sizeof(flags)); 10679 10680 flags.ah = true; 10681 flags.display_alg = true; 10682 10683 return test_ipsec_ah_proto_all(&flags); 10684 } 10685 10686 static int 10687 test_ipsec_proto_ah_transport_ipv4(void) 10688 { 10689 struct ipsec_test_flags flags; 10690 10691 memset(&flags, 0, sizeof(flags)); 10692 10693 flags.ah = true; 10694 flags.transport = true; 10695 10696 return test_ipsec_ah_proto_all(&flags); 10697 } 10698 10699 static int 10700 test_ipsec_proto_iv_gen(void) 10701 { 10702 struct ipsec_test_flags flags; 10703 10704 memset(&flags, 0, sizeof(flags)); 10705 10706 flags.iv_gen = true; 10707 10708 return test_ipsec_proto_all(&flags); 10709 } 10710 10711 static int 10712 test_ipsec_proto_sa_exp_pkts_soft(void) 10713 { 10714 struct ipsec_test_flags flags; 10715 10716 memset(&flags, 0, sizeof(flags)); 10717 10718 flags.sa_expiry_pkts_soft = true; 10719 10720 return test_ipsec_proto_all(&flags); 10721 } 10722 10723 static int 10724 test_ipsec_proto_sa_exp_pkts_hard(void) 10725 { 10726 struct ipsec_test_flags flags; 10727 10728 memset(&flags, 0, sizeof(flags)); 10729 10730 flags.sa_expiry_pkts_hard = true; 10731 10732 return test_ipsec_proto_all(&flags); 10733 } 10734 10735 static int 10736 test_ipsec_proto_err_icv_corrupt(void) 10737 { 10738 struct ipsec_test_flags flags; 10739 10740 memset(&flags, 0, sizeof(flags)); 10741 10742 flags.icv_corrupt = true; 10743 10744 return test_ipsec_proto_all(&flags); 10745 } 10746 10747 static int 10748 test_ipsec_proto_udp_encap_custom_ports(void) 10749 { 10750 struct ipsec_test_flags flags; 10751 10752 if (gbl_driver_id == rte_cryptodev_driver_id_get( 10753 RTE_STR(CRYPTODEV_NAME_CN10K_PMD))) 10754 return TEST_SKIPPED; 10755 10756 memset(&flags, 0, sizeof(flags)); 10757 10758 flags.udp_encap = true; 10759 flags.udp_encap_custom_ports = true; 10760 10761 return test_ipsec_proto_all(&flags); 10762 } 10763 10764 static int 10765 test_ipsec_proto_udp_encap(void) 10766 { 10767 struct ipsec_test_flags flags; 10768 10769 memset(&flags, 0, sizeof(flags)); 10770 10771 flags.udp_encap = true; 10772 10773 return test_ipsec_proto_all(&flags); 10774 } 10775 10776 static int 10777 test_ipsec_proto_tunnel_src_dst_addr_verify(void) 10778 { 10779 struct ipsec_test_flags flags; 10780 10781 memset(&flags, 0, sizeof(flags)); 10782 10783 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR; 10784 10785 return test_ipsec_proto_all(&flags); 10786 } 10787 10788 static int 10789 test_ipsec_proto_tunnel_dst_addr_verify(void) 10790 { 10791 struct ipsec_test_flags flags; 10792 10793 memset(&flags, 0, sizeof(flags)); 10794 10795 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR; 10796 10797 return test_ipsec_proto_all(&flags); 10798 } 10799 10800 static int 10801 test_ipsec_proto_udp_ports_verify(void) 10802 { 10803 struct ipsec_test_flags flags; 10804 10805 memset(&flags, 0, sizeof(flags)); 10806 10807 flags.udp_encap = true; 10808 flags.udp_ports_verify = true; 10809 10810 return test_ipsec_proto_all(&flags); 10811 } 10812 10813 static int 10814 test_ipsec_proto_inner_ip_csum(void) 10815 { 10816 struct ipsec_test_flags flags; 10817 10818 memset(&flags, 0, sizeof(flags)); 10819 10820 flags.ip_csum = true; 10821 10822 return test_ipsec_proto_all(&flags); 10823 } 10824 10825 static int 10826 test_ipsec_proto_inner_l4_csum(void) 10827 { 10828 struct ipsec_test_flags flags; 10829 10830 memset(&flags, 0, sizeof(flags)); 10831 10832 flags.l4_csum = true; 10833 10834 return test_ipsec_proto_all(&flags); 10835 } 10836 10837 static int 10838 test_ipsec_proto_tunnel_v4_in_v4(void) 10839 { 10840 struct ipsec_test_flags flags; 10841 10842 memset(&flags, 0, sizeof(flags)); 10843 10844 flags.ipv6 = false; 10845 flags.tunnel_ipv6 = false; 10846 10847 return test_ipsec_proto_all(&flags); 10848 } 10849 10850 static int 10851 test_ipsec_proto_tunnel_v6_in_v6(void) 10852 { 10853 struct ipsec_test_flags flags; 10854 10855 memset(&flags, 0, sizeof(flags)); 10856 10857 flags.ipv6 = true; 10858 flags.tunnel_ipv6 = true; 10859 10860 return test_ipsec_proto_all(&flags); 10861 } 10862 10863 static int 10864 test_ipsec_proto_tunnel_v4_in_v6(void) 10865 { 10866 struct ipsec_test_flags flags; 10867 10868 memset(&flags, 0, sizeof(flags)); 10869 10870 flags.ipv6 = false; 10871 flags.tunnel_ipv6 = true; 10872 10873 return test_ipsec_proto_all(&flags); 10874 } 10875 10876 static int 10877 test_ipsec_proto_tunnel_v6_in_v4(void) 10878 { 10879 struct ipsec_test_flags flags; 10880 10881 memset(&flags, 0, sizeof(flags)); 10882 10883 flags.ipv6 = true; 10884 flags.tunnel_ipv6 = false; 10885 10886 return test_ipsec_proto_all(&flags); 10887 } 10888 10889 static int 10890 test_ipsec_proto_transport_v4(void) 10891 { 10892 struct ipsec_test_flags flags; 10893 10894 memset(&flags, 0, sizeof(flags)); 10895 10896 flags.ipv6 = false; 10897 flags.transport = true; 10898 10899 return test_ipsec_proto_all(&flags); 10900 } 10901 10902 static int 10903 test_ipsec_proto_transport_l4_csum(void) 10904 { 10905 struct ipsec_test_flags flags = { 10906 .l4_csum = true, 10907 .transport = true, 10908 }; 10909 10910 return test_ipsec_proto_all(&flags); 10911 } 10912 10913 static int 10914 test_ipsec_proto_stats(void) 10915 { 10916 struct ipsec_test_flags flags; 10917 10918 memset(&flags, 0, sizeof(flags)); 10919 10920 flags.stats_success = true; 10921 10922 return test_ipsec_proto_all(&flags); 10923 } 10924 10925 static int 10926 test_ipsec_proto_pkt_fragment(void) 10927 { 10928 struct ipsec_test_flags flags; 10929 10930 memset(&flags, 0, sizeof(flags)); 10931 10932 flags.fragment = true; 10933 10934 return test_ipsec_proto_all(&flags); 10935 10936 } 10937 10938 static int 10939 test_ipsec_proto_copy_df_inner_0(void) 10940 { 10941 struct ipsec_test_flags flags; 10942 10943 memset(&flags, 0, sizeof(flags)); 10944 10945 flags.df = TEST_IPSEC_COPY_DF_INNER_0; 10946 10947 return test_ipsec_proto_all(&flags); 10948 } 10949 10950 static int 10951 test_ipsec_proto_copy_df_inner_1(void) 10952 { 10953 struct ipsec_test_flags flags; 10954 10955 memset(&flags, 0, sizeof(flags)); 10956 10957 flags.df = TEST_IPSEC_COPY_DF_INNER_1; 10958 10959 return test_ipsec_proto_all(&flags); 10960 } 10961 10962 static int 10963 test_ipsec_proto_set_df_0_inner_1(void) 10964 { 10965 struct ipsec_test_flags flags; 10966 10967 memset(&flags, 0, sizeof(flags)); 10968 10969 flags.df = TEST_IPSEC_SET_DF_0_INNER_1; 10970 10971 return test_ipsec_proto_all(&flags); 10972 } 10973 10974 static int 10975 test_ipsec_proto_set_df_1_inner_0(void) 10976 { 10977 struct ipsec_test_flags flags; 10978 10979 memset(&flags, 0, sizeof(flags)); 10980 10981 flags.df = TEST_IPSEC_SET_DF_1_INNER_0; 10982 10983 return test_ipsec_proto_all(&flags); 10984 } 10985 10986 static int 10987 test_ipsec_proto_ipv4_copy_dscp_inner_0(void) 10988 { 10989 struct ipsec_test_flags flags; 10990 10991 memset(&flags, 0, sizeof(flags)); 10992 10993 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0; 10994 10995 return test_ipsec_proto_all(&flags); 10996 } 10997 10998 static int 10999 test_ipsec_proto_ipv4_copy_dscp_inner_1(void) 11000 { 11001 struct ipsec_test_flags flags; 11002 11003 memset(&flags, 0, sizeof(flags)); 11004 11005 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1; 11006 11007 return test_ipsec_proto_all(&flags); 11008 } 11009 11010 static int 11011 test_ipsec_proto_ipv4_set_dscp_0_inner_1(void) 11012 { 11013 struct ipsec_test_flags flags; 11014 11015 if (gbl_driver_id == rte_cryptodev_driver_id_get( 11016 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 11017 return TEST_SKIPPED; 11018 11019 memset(&flags, 0, sizeof(flags)); 11020 11021 flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1; 11022 11023 return test_ipsec_proto_all(&flags); 11024 } 11025 11026 static int 11027 test_ipsec_proto_ipv4_set_dscp_1_inner_0(void) 11028 { 11029 struct ipsec_test_flags flags; 11030 11031 if (gbl_driver_id == rte_cryptodev_driver_id_get( 11032 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 11033 return TEST_SKIPPED; 11034 11035 memset(&flags, 0, sizeof(flags)); 11036 11037 flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0; 11038 11039 return test_ipsec_proto_all(&flags); 11040 } 11041 11042 static int 11043 test_ipsec_proto_ipv6_copy_dscp_inner_0(void) 11044 { 11045 struct ipsec_test_flags flags; 11046 11047 memset(&flags, 0, sizeof(flags)); 11048 11049 flags.ipv6 = true; 11050 flags.tunnel_ipv6 = true; 11051 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0; 11052 11053 return test_ipsec_proto_all(&flags); 11054 } 11055 11056 static int 11057 test_ipsec_proto_ipv6_copy_dscp_inner_1(void) 11058 { 11059 struct ipsec_test_flags flags; 11060 11061 memset(&flags, 0, sizeof(flags)); 11062 11063 flags.ipv6 = true; 11064 flags.tunnel_ipv6 = true; 11065 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1; 11066 11067 return test_ipsec_proto_all(&flags); 11068 } 11069 11070 static int 11071 test_ipsec_proto_ipv6_set_dscp_0_inner_1(void) 11072 { 11073 struct ipsec_test_flags flags; 11074 11075 if (gbl_driver_id == rte_cryptodev_driver_id_get( 11076 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 11077 return TEST_SKIPPED; 11078 11079 memset(&flags, 0, sizeof(flags)); 11080 11081 flags.ipv6 = true; 11082 flags.tunnel_ipv6 = true; 11083 flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1; 11084 11085 return test_ipsec_proto_all(&flags); 11086 } 11087 11088 static int 11089 test_ipsec_proto_ipv6_set_dscp_1_inner_0(void) 11090 { 11091 struct ipsec_test_flags flags; 11092 11093 if (gbl_driver_id == rte_cryptodev_driver_id_get( 11094 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 11095 return TEST_SKIPPED; 11096 11097 memset(&flags, 0, sizeof(flags)); 11098 11099 flags.ipv6 = true; 11100 flags.tunnel_ipv6 = true; 11101 flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0; 11102 11103 return test_ipsec_proto_all(&flags); 11104 } 11105 11106 static int 11107 test_ipsec_proto_sgl(void) 11108 { 11109 struct crypto_testsuite_params *ts_params = &testsuite_params; 11110 struct rte_cryptodev_info dev_info; 11111 11112 struct ipsec_test_flags flags = { 11113 .nb_segs_in_mbuf = 5 11114 }; 11115 11116 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11117 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 11118 printf("Device doesn't support in-place scatter-gather. " 11119 "Test Skipped.\n"); 11120 return TEST_SKIPPED; 11121 } 11122 11123 return test_ipsec_proto_all(&flags); 11124 } 11125 11126 static int 11127 test_ipsec_proto_sgl_ext_mbuf(void) 11128 { 11129 struct crypto_testsuite_params *ts_params = &testsuite_params; 11130 struct rte_cryptodev_info dev_info; 11131 11132 struct ipsec_test_flags flags = { 11133 .nb_segs_in_mbuf = 5, 11134 .use_ext_mbuf = 1 11135 }; 11136 11137 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11138 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 11139 printf("Device doesn't support in-place scatter-gather. " 11140 "Test Skipped.\n"); 11141 return TEST_SKIPPED; 11142 } 11143 11144 return test_ipsec_proto_all(&flags); 11145 } 11146 11147 static int 11148 test_ipsec_pkt_replay(const void *test_data, const uint64_t esn[], 11149 bool replayed_pkt[], uint32_t nb_pkts, bool esn_en, 11150 uint64_t winsz) 11151 { 11152 struct ipsec_test_data td_outb[TEST_SEC_PKTS_MAX]; 11153 struct ipsec_test_data td_inb[TEST_SEC_PKTS_MAX]; 11154 struct ipsec_test_flags flags; 11155 uint32_t i = 0, ret = 0; 11156 11157 if (nb_pkts == 0) 11158 return TEST_FAILED; 11159 11160 memset(&flags, 0, sizeof(flags)); 11161 flags.antireplay = true; 11162 11163 for (i = 0; i < nb_pkts; i++) { 11164 memcpy(&td_outb[i], test_data, sizeof(td_outb[i])); 11165 td_outb[i].ipsec_xform.options.iv_gen_disable = 1; 11166 td_outb[i].ipsec_xform.replay_win_sz = winsz; 11167 td_outb[i].ipsec_xform.options.esn = esn_en; 11168 } 11169 11170 for (i = 0; i < nb_pkts; i++) 11171 td_outb[i].ipsec_xform.esn.value = esn[i]; 11172 11173 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 11174 &flags); 11175 if (ret != TEST_SUCCESS) 11176 return ret; 11177 11178 test_ipsec_td_update(td_inb, td_outb, nb_pkts, &flags); 11179 11180 for (i = 0; i < nb_pkts; i++) { 11181 td_inb[i].ipsec_xform.options.esn = esn_en; 11182 /* Set antireplay flag for packets to be dropped */ 11183 td_inb[i].ar_packet = replayed_pkt[i]; 11184 } 11185 11186 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 11187 &flags); 11188 11189 return ret; 11190 } 11191 11192 static int 11193 test_ipsec_proto_pkt_antireplay(const void *test_data, uint64_t winsz) 11194 { 11195 11196 uint32_t nb_pkts = 5; 11197 bool replayed_pkt[5]; 11198 uint64_t esn[5]; 11199 11200 /* 1. Advance the TOP of the window to WS * 2 */ 11201 esn[0] = winsz * 2; 11202 /* 2. Test sequence number within the new window(WS + 1) */ 11203 esn[1] = winsz + 1; 11204 /* 3. Test sequence number less than the window BOTTOM */ 11205 esn[2] = winsz; 11206 /* 4. Test sequence number in the middle of the window */ 11207 esn[3] = winsz + (winsz / 2); 11208 /* 5. Test replay of the packet in the middle of the window */ 11209 esn[4] = winsz + (winsz / 2); 11210 11211 replayed_pkt[0] = false; 11212 replayed_pkt[1] = false; 11213 replayed_pkt[2] = true; 11214 replayed_pkt[3] = false; 11215 replayed_pkt[4] = true; 11216 11217 return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts, 11218 false, winsz); 11219 } 11220 11221 static int 11222 test_ipsec_proto_pkt_antireplay1024(const void *test_data) 11223 { 11224 return test_ipsec_proto_pkt_antireplay(test_data, 1024); 11225 } 11226 11227 static int 11228 test_ipsec_proto_pkt_antireplay2048(const void *test_data) 11229 { 11230 return test_ipsec_proto_pkt_antireplay(test_data, 2048); 11231 } 11232 11233 static int 11234 test_ipsec_proto_pkt_antireplay4096(const void *test_data) 11235 { 11236 return test_ipsec_proto_pkt_antireplay(test_data, 4096); 11237 } 11238 11239 static int 11240 test_ipsec_proto_pkt_esn_antireplay(const void *test_data, uint64_t winsz) 11241 { 11242 11243 uint32_t nb_pkts = 7; 11244 bool replayed_pkt[7]; 11245 uint64_t esn[7]; 11246 11247 /* Set the initial sequence number */ 11248 esn[0] = (uint64_t)(0xFFFFFFFF - winsz); 11249 /* 1. Advance the TOP of the window to (1<<32 + WS/2) */ 11250 esn[1] = (uint64_t)((1ULL << 32) + (winsz / 2)); 11251 /* 2. Test sequence number within new window (1<<32 + WS/2 + 1) */ 11252 esn[2] = (uint64_t)((1ULL << 32) - (winsz / 2) + 1); 11253 /* 3. Test with sequence number within window (1<<32 - 1) */ 11254 esn[3] = (uint64_t)((1ULL << 32) - 1); 11255 /* 4. Test with sequence number within window (1<<32 - 1) */ 11256 esn[4] = (uint64_t)(1ULL << 32); 11257 /* 5. Test with duplicate sequence number within 11258 * new window (1<<32 - 1) 11259 */ 11260 esn[5] = (uint64_t)((1ULL << 32) - 1); 11261 /* 6. Test with duplicate sequence number within new window (1<<32) */ 11262 esn[6] = (uint64_t)(1ULL << 32); 11263 11264 replayed_pkt[0] = false; 11265 replayed_pkt[1] = false; 11266 replayed_pkt[2] = false; 11267 replayed_pkt[3] = false; 11268 replayed_pkt[4] = false; 11269 replayed_pkt[5] = true; 11270 replayed_pkt[6] = true; 11271 11272 return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts, 11273 true, winsz); 11274 } 11275 11276 static int 11277 test_ipsec_proto_pkt_esn_antireplay1024(const void *test_data) 11278 { 11279 return test_ipsec_proto_pkt_esn_antireplay(test_data, 1024); 11280 } 11281 11282 static int 11283 test_ipsec_proto_pkt_esn_antireplay2048(const void *test_data) 11284 { 11285 return test_ipsec_proto_pkt_esn_antireplay(test_data, 2048); 11286 } 11287 11288 static int 11289 test_ipsec_proto_pkt_esn_antireplay4096(const void *test_data) 11290 { 11291 return test_ipsec_proto_pkt_esn_antireplay(test_data, 4096); 11292 } 11293 11294 static int 11295 test_PDCP_PROTO_all(void) 11296 { 11297 struct crypto_testsuite_params *ts_params = &testsuite_params; 11298 struct crypto_unittest_params *ut_params = &unittest_params; 11299 struct rte_cryptodev_info dev_info; 11300 int status; 11301 11302 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11303 uint64_t feat_flags = dev_info.feature_flags; 11304 11305 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 11306 return TEST_SKIPPED; 11307 11308 /* Set action type */ 11309 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 11310 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 11311 gbl_action_type; 11312 11313 if (security_proto_supported(ut_params->type, 11314 RTE_SECURITY_PROTOCOL_PDCP) < 0) 11315 return TEST_SKIPPED; 11316 11317 status = test_PDCP_PROTO_cplane_encap_all(); 11318 status += test_PDCP_PROTO_cplane_decap_all(); 11319 status += test_PDCP_PROTO_uplane_encap_all(); 11320 status += test_PDCP_PROTO_uplane_decap_all(); 11321 status += test_PDCP_PROTO_SGL_in_place_32B(); 11322 status += test_PDCP_PROTO_SGL_oop_32B_128B(); 11323 status += test_PDCP_PROTO_SGL_oop_32B_40B(); 11324 status += test_PDCP_PROTO_SGL_oop_128B_32B(); 11325 status += test_PDCP_SDAP_PROTO_encap_all(); 11326 status += test_PDCP_SDAP_PROTO_decap_all(); 11327 status += test_PDCP_PROTO_short_mac(); 11328 11329 if (status) 11330 return TEST_FAILED; 11331 else 11332 return TEST_SUCCESS; 11333 } 11334 11335 static int 11336 test_ipsec_proto_ipv4_ttl_decrement(void) 11337 { 11338 struct ipsec_test_flags flags = { 11339 .dec_ttl_or_hop_limit = true 11340 }; 11341 11342 return test_ipsec_proto_all(&flags); 11343 } 11344 11345 static int 11346 test_ipsec_proto_ipv6_hop_limit_decrement(void) 11347 { 11348 struct ipsec_test_flags flags = { 11349 .ipv6 = true, 11350 .dec_ttl_or_hop_limit = true 11351 }; 11352 11353 return test_ipsec_proto_all(&flags); 11354 } 11355 11356 static int 11357 test_docsis_proto_uplink(const void *data) 11358 { 11359 const struct docsis_test_data *d_td = data; 11360 struct crypto_testsuite_params *ts_params = &testsuite_params; 11361 struct crypto_unittest_params *ut_params = &unittest_params; 11362 uint8_t *plaintext = NULL; 11363 uint8_t *ciphertext = NULL; 11364 uint8_t *iv_ptr; 11365 int32_t cipher_len, crc_len; 11366 uint32_t crc_data_len; 11367 int ret = TEST_SUCCESS; 11368 11369 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 11370 11371 /* Verify the capabilities */ 11372 struct rte_security_capability_idx sec_cap_idx; 11373 const struct rte_security_capability *sec_cap; 11374 const struct rte_cryptodev_capabilities *crypto_cap; 11375 const struct rte_cryptodev_symmetric_capability *sym_cap; 11376 int j = 0; 11377 11378 /* Set action type */ 11379 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 11380 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 11381 gbl_action_type; 11382 11383 if (security_proto_supported(ut_params->type, 11384 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 11385 return TEST_SKIPPED; 11386 11387 sec_cap_idx.action = ut_params->type; 11388 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 11389 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK; 11390 11391 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 11392 if (sec_cap == NULL) 11393 return TEST_SKIPPED; 11394 11395 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 11396 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 11397 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 11398 crypto_cap->sym.xform_type == 11399 RTE_CRYPTO_SYM_XFORM_CIPHER && 11400 crypto_cap->sym.cipher.algo == 11401 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 11402 sym_cap = &crypto_cap->sym; 11403 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 11404 d_td->key.len, 11405 d_td->iv.len) == 0) 11406 break; 11407 } 11408 } 11409 11410 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 11411 return TEST_SKIPPED; 11412 11413 /* Setup source mbuf payload */ 11414 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11415 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11416 rte_pktmbuf_tailroom(ut_params->ibuf)); 11417 11418 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11419 d_td->ciphertext.len); 11420 11421 memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len); 11422 11423 /* Setup cipher session parameters */ 11424 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11425 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 11426 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 11427 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 11428 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 11429 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 11430 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 11431 ut_params->cipher_xform.next = NULL; 11432 11433 /* Setup DOCSIS session parameters */ 11434 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK; 11435 11436 struct rte_security_session_conf sess_conf = { 11437 .action_type = ut_params->type, 11438 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 11439 .docsis = ut_params->docsis_xform, 11440 .crypto_xform = &ut_params->cipher_xform, 11441 }; 11442 11443 /* Create security session */ 11444 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 11445 ts_params->session_mpool); 11446 11447 if (!ut_params->sec_session) { 11448 printf("Test function %s line %u: failed to allocate session\n", 11449 __func__, __LINE__); 11450 ret = TEST_FAILED; 11451 goto on_err; 11452 } 11453 11454 /* Generate crypto op data structure */ 11455 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11456 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11457 if (!ut_params->op) { 11458 printf("Test function %s line %u: failed to allocate symmetric " 11459 "crypto operation\n", __func__, __LINE__); 11460 ret = TEST_FAILED; 11461 goto on_err; 11462 } 11463 11464 /* Setup CRC operation parameters */ 11465 crc_len = d_td->ciphertext.no_crc == false ? 11466 (d_td->ciphertext.len - 11467 d_td->ciphertext.crc_offset - 11468 RTE_ETHER_CRC_LEN) : 11469 0; 11470 crc_len = crc_len > 0 ? crc_len : 0; 11471 crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN; 11472 ut_params->op->sym->auth.data.length = crc_len; 11473 ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset; 11474 11475 /* Setup cipher operation parameters */ 11476 cipher_len = d_td->ciphertext.no_cipher == false ? 11477 (d_td->ciphertext.len - 11478 d_td->ciphertext.cipher_offset) : 11479 0; 11480 cipher_len = cipher_len > 0 ? cipher_len : 0; 11481 ut_params->op->sym->cipher.data.length = cipher_len; 11482 ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset; 11483 11484 /* Setup cipher IV */ 11485 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 11486 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 11487 11488 /* Attach session to operation */ 11489 rte_security_attach_session(ut_params->op, ut_params->sec_session); 11490 11491 /* Set crypto operation mbufs */ 11492 ut_params->op->sym->m_src = ut_params->ibuf; 11493 ut_params->op->sym->m_dst = NULL; 11494 11495 /* Process crypto operation */ 11496 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 11497 NULL) { 11498 printf("Test function %s line %u: failed to process security " 11499 "crypto op\n", __func__, __LINE__); 11500 ret = TEST_FAILED; 11501 goto on_err; 11502 } 11503 11504 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 11505 printf("Test function %s line %u: failed to process crypto op\n", 11506 __func__, __LINE__); 11507 ret = TEST_FAILED; 11508 goto on_err; 11509 } 11510 11511 /* Validate plaintext */ 11512 plaintext = ciphertext; 11513 11514 if (memcmp(plaintext, d_td->plaintext.data, 11515 d_td->plaintext.len - crc_data_len)) { 11516 printf("Test function %s line %u: plaintext not as expected\n", 11517 __func__, __LINE__); 11518 rte_hexdump(stdout, "expected", d_td->plaintext.data, 11519 d_td->plaintext.len); 11520 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len); 11521 ret = TEST_FAILED; 11522 goto on_err; 11523 } 11524 11525 on_err: 11526 rte_crypto_op_free(ut_params->op); 11527 ut_params->op = NULL; 11528 11529 if (ut_params->sec_session) 11530 rte_security_session_destroy(ctx, ut_params->sec_session); 11531 ut_params->sec_session = NULL; 11532 11533 rte_pktmbuf_free(ut_params->ibuf); 11534 ut_params->ibuf = NULL; 11535 11536 return ret; 11537 } 11538 11539 static int 11540 test_docsis_proto_downlink(const void *data) 11541 { 11542 const struct docsis_test_data *d_td = data; 11543 struct crypto_testsuite_params *ts_params = &testsuite_params; 11544 struct crypto_unittest_params *ut_params = &unittest_params; 11545 uint8_t *plaintext = NULL; 11546 uint8_t *ciphertext = NULL; 11547 uint8_t *iv_ptr; 11548 int32_t cipher_len, crc_len; 11549 int ret = TEST_SUCCESS; 11550 11551 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 11552 11553 /* Verify the capabilities */ 11554 struct rte_security_capability_idx sec_cap_idx; 11555 const struct rte_security_capability *sec_cap; 11556 const struct rte_cryptodev_capabilities *crypto_cap; 11557 const struct rte_cryptodev_symmetric_capability *sym_cap; 11558 int j = 0; 11559 11560 /* Set action type */ 11561 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 11562 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 11563 gbl_action_type; 11564 11565 if (security_proto_supported(ut_params->type, 11566 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 11567 return TEST_SKIPPED; 11568 11569 sec_cap_idx.action = ut_params->type; 11570 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 11571 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 11572 11573 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 11574 if (sec_cap == NULL) 11575 return TEST_SKIPPED; 11576 11577 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 11578 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 11579 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 11580 crypto_cap->sym.xform_type == 11581 RTE_CRYPTO_SYM_XFORM_CIPHER && 11582 crypto_cap->sym.cipher.algo == 11583 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 11584 sym_cap = &crypto_cap->sym; 11585 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 11586 d_td->key.len, 11587 d_td->iv.len) == 0) 11588 break; 11589 } 11590 } 11591 11592 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 11593 return TEST_SKIPPED; 11594 11595 /* Setup source mbuf payload */ 11596 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11597 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11598 rte_pktmbuf_tailroom(ut_params->ibuf)); 11599 11600 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11601 d_td->plaintext.len); 11602 11603 memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len); 11604 11605 /* Setup cipher session parameters */ 11606 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11607 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 11608 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 11609 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 11610 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 11611 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 11612 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 11613 ut_params->cipher_xform.next = NULL; 11614 11615 /* Setup DOCSIS session parameters */ 11616 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 11617 11618 struct rte_security_session_conf sess_conf = { 11619 .action_type = ut_params->type, 11620 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 11621 .docsis = ut_params->docsis_xform, 11622 .crypto_xform = &ut_params->cipher_xform, 11623 }; 11624 11625 /* Create security session */ 11626 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 11627 ts_params->session_mpool); 11628 11629 if (!ut_params->sec_session) { 11630 printf("Test function %s line %u: failed to allocate session\n", 11631 __func__, __LINE__); 11632 ret = TEST_FAILED; 11633 goto on_err; 11634 } 11635 11636 /* Generate crypto op data structure */ 11637 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11638 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11639 if (!ut_params->op) { 11640 printf("Test function %s line %u: failed to allocate symmetric " 11641 "crypto operation\n", __func__, __LINE__); 11642 ret = TEST_FAILED; 11643 goto on_err; 11644 } 11645 11646 /* Setup CRC operation parameters */ 11647 crc_len = d_td->plaintext.no_crc == false ? 11648 (d_td->plaintext.len - 11649 d_td->plaintext.crc_offset - 11650 RTE_ETHER_CRC_LEN) : 11651 0; 11652 crc_len = crc_len > 0 ? crc_len : 0; 11653 ut_params->op->sym->auth.data.length = crc_len; 11654 ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset; 11655 11656 /* Setup cipher operation parameters */ 11657 cipher_len = d_td->plaintext.no_cipher == false ? 11658 (d_td->plaintext.len - 11659 d_td->plaintext.cipher_offset) : 11660 0; 11661 cipher_len = cipher_len > 0 ? cipher_len : 0; 11662 ut_params->op->sym->cipher.data.length = cipher_len; 11663 ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset; 11664 11665 /* Setup cipher IV */ 11666 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 11667 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 11668 11669 /* Attach session to operation */ 11670 rte_security_attach_session(ut_params->op, ut_params->sec_session); 11671 11672 /* Set crypto operation mbufs */ 11673 ut_params->op->sym->m_src = ut_params->ibuf; 11674 ut_params->op->sym->m_dst = NULL; 11675 11676 /* Process crypto operation */ 11677 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 11678 NULL) { 11679 printf("Test function %s line %u: failed to process crypto op\n", 11680 __func__, __LINE__); 11681 ret = TEST_FAILED; 11682 goto on_err; 11683 } 11684 11685 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 11686 printf("Test function %s line %u: crypto op processing failed\n", 11687 __func__, __LINE__); 11688 ret = TEST_FAILED; 11689 goto on_err; 11690 } 11691 11692 /* Validate ciphertext */ 11693 ciphertext = plaintext; 11694 11695 if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) { 11696 printf("Test function %s line %u: plaintext not as expected\n", 11697 __func__, __LINE__); 11698 rte_hexdump(stdout, "expected", d_td->ciphertext.data, 11699 d_td->ciphertext.len); 11700 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len); 11701 ret = TEST_FAILED; 11702 goto on_err; 11703 } 11704 11705 on_err: 11706 rte_crypto_op_free(ut_params->op); 11707 ut_params->op = NULL; 11708 11709 if (ut_params->sec_session) 11710 rte_security_session_destroy(ctx, ut_params->sec_session); 11711 ut_params->sec_session = NULL; 11712 11713 rte_pktmbuf_free(ut_params->ibuf); 11714 ut_params->ibuf = NULL; 11715 11716 return ret; 11717 } 11718 11719 static void 11720 test_tls_record_imp_nonce_update(const struct tls_record_test_data *td, 11721 struct rte_security_tls_record_xform *tls_record_xform) 11722 { 11723 unsigned int imp_nonce_len; 11724 uint8_t *imp_nonce; 11725 11726 switch (tls_record_xform->ver) { 11727 case RTE_SECURITY_VERSION_TLS_1_2: 11728 imp_nonce_len = RTE_SECURITY_TLS_1_2_IMP_NONCE_LEN; 11729 imp_nonce = tls_record_xform->tls_1_2.imp_nonce; 11730 break; 11731 case RTE_SECURITY_VERSION_DTLS_1_2: 11732 imp_nonce_len = RTE_SECURITY_DTLS_1_2_IMP_NONCE_LEN; 11733 imp_nonce = tls_record_xform->dtls_1_2.imp_nonce; 11734 break; 11735 case RTE_SECURITY_VERSION_TLS_1_3: 11736 imp_nonce_len = RTE_SECURITY_TLS_1_3_IMP_NONCE_LEN; 11737 imp_nonce = tls_record_xform->tls_1_3.imp_nonce; 11738 break; 11739 default: 11740 return; 11741 } 11742 11743 imp_nonce_len = RTE_MIN(imp_nonce_len, td[0].imp_nonce.len); 11744 memcpy(imp_nonce, td[0].imp_nonce.data, imp_nonce_len); 11745 } 11746 11747 static int 11748 test_tls_record_proto_process(const struct tls_record_test_data td[], 11749 struct tls_record_test_data res_d[], int nb_td, bool silent, 11750 const struct tls_record_test_flags *flags) 11751 { 11752 int nb_segs = flags->nb_segs_in_mbuf ? flags->nb_segs_in_mbuf : 1; 11753 struct crypto_testsuite_params *ts_params = &testsuite_params; 11754 struct crypto_unittest_params *ut_params = &unittest_params; 11755 struct rte_security_tls_record_xform tls_record_xform; 11756 struct rte_security_capability_idx sec_cap_idx; 11757 const struct rte_security_capability *sec_cap; 11758 struct tls_record_test_data *res_d_tmp = NULL; 11759 enum rte_security_tls_sess_type sess_type; 11760 uint8_t dev_id = ts_params->valid_devs[0]; 11761 struct rte_security_ctx *ctx; 11762 int i, ret = TEST_SUCCESS; 11763 11764 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 11765 gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 11766 11767 /* Use first test data to create session */ 11768 11769 /* Copy TLS record xform */ 11770 memcpy(&tls_record_xform, &td[0].tls_record_xform, sizeof(tls_record_xform)); 11771 11772 sess_type = tls_record_xform.type; 11773 11774 ctx = rte_cryptodev_get_sec_ctx(dev_id); 11775 11776 sec_cap_idx.action = ut_params->type; 11777 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_TLS_RECORD; 11778 sec_cap_idx.tls_record.type = tls_record_xform.type; 11779 sec_cap_idx.tls_record.ver = tls_record_xform.ver; 11780 11781 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 11782 if (sec_cap == NULL) 11783 return TEST_SKIPPED; 11784 11785 /* Copy cipher session parameters */ 11786 if (td[0].aead) { 11787 memcpy(&ut_params->aead_xform, &td[0].xform.aead, sizeof(ut_params->aead_xform)); 11788 ut_params->aead_xform.aead.key.data = td[0].key.data; 11789 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 11790 11791 /* Verify crypto capabilities */ 11792 if (test_sec_crypto_caps_aead_verify(sec_cap, &ut_params->aead_xform) != 0) { 11793 if (!silent) 11794 RTE_LOG(INFO, USER1, "Crypto capabilities not supported\n"); 11795 return TEST_SKIPPED; 11796 } 11797 } else { 11798 memcpy(&ut_params->cipher_xform, &td[0].xform.chain.cipher, 11799 sizeof(ut_params->cipher_xform)); 11800 memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth, 11801 sizeof(ut_params->auth_xform)); 11802 ut_params->cipher_xform.cipher.key.data = td[0].key.data; 11803 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 11804 ut_params->auth_xform.auth.key.data = td[0].auth_key.data; 11805 11806 /* Verify crypto capabilities */ 11807 11808 if (test_sec_crypto_caps_cipher_verify(sec_cap, &ut_params->cipher_xform) != 0) { 11809 if (!silent) 11810 RTE_LOG(INFO, USER1, "Cipher crypto capabilities not supported\n"); 11811 return TEST_SKIPPED; 11812 } 11813 11814 if (test_sec_crypto_caps_auth_verify(sec_cap, &ut_params->auth_xform) != 0) { 11815 if (!silent) 11816 RTE_LOG(INFO, USER1, "Auth crypto capabilities not supported\n"); 11817 return TEST_SKIPPED; 11818 } 11819 } 11820 11821 if (test_tls_record_sec_caps_verify(&tls_record_xform, sec_cap, silent) != 0) 11822 return TEST_SKIPPED; 11823 11824 struct rte_security_session_conf sess_conf = { 11825 .action_type = ut_params->type, 11826 .protocol = RTE_SECURITY_PROTOCOL_TLS_RECORD, 11827 }; 11828 11829 if (td[0].aead) 11830 test_tls_record_imp_nonce_update(&td[0], &tls_record_xform); 11831 11832 sess_conf.tls_record = tls_record_xform; 11833 11834 if (td[0].aead) { 11835 sess_conf.crypto_xform = &ut_params->aead_xform; 11836 } else { 11837 if (sess_type == RTE_SECURITY_TLS_SESS_TYPE_READ) { 11838 sess_conf.crypto_xform = &ut_params->cipher_xform; 11839 ut_params->cipher_xform.next = &ut_params->auth_xform; 11840 } else { 11841 sess_conf.crypto_xform = &ut_params->auth_xform; 11842 ut_params->auth_xform.next = &ut_params->cipher_xform; 11843 } 11844 } 11845 11846 /* Create security session */ 11847 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 11848 ts_params->session_mpool); 11849 if (ut_params->sec_session == NULL) 11850 return TEST_SKIPPED; 11851 11852 for (i = 0; i < nb_td; i++) { 11853 /* Setup source mbuf payload */ 11854 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, td[i].input_text.len, 11855 nb_segs, 0); 11856 pktmbuf_write(ut_params->ibuf, 0, td[i].input_text.len, td[i].input_text.data); 11857 11858 /* Generate crypto op data structure */ 11859 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11860 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11861 if (ut_params->op == NULL) { 11862 printf("Could not allocate crypto op"); 11863 ret = TEST_FAILED; 11864 goto crypto_op_free; 11865 } 11866 11867 /* Attach session to operation */ 11868 rte_security_attach_session(ut_params->op, ut_params->sec_session); 11869 11870 /* Set crypto operation mbufs */ 11871 ut_params->op->sym->m_src = ut_params->ibuf; 11872 ut_params->op->sym->m_dst = NULL; 11873 ut_params->op->param1.tls_record.content_type = td[i].app_type; 11874 11875 /* Copy IV in crypto operation when IV generation is disabled */ 11876 if (sess_type == RTE_SECURITY_TLS_SESS_TYPE_WRITE && 11877 tls_record_xform.options.iv_gen_disable == 1) { 11878 uint8_t *iv; 11879 int len; 11880 11881 iv = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET); 11882 if (td[i].aead) 11883 len = td[i].xform.aead.aead.iv.length - 4; 11884 else 11885 len = td[i].xform.chain.cipher.cipher.iv.length; 11886 memcpy(iv, td[i].iv.data, len); 11887 } 11888 11889 /* Process crypto operation */ 11890 process_crypto_request(dev_id, ut_params->op); 11891 11892 ret = test_tls_record_status_check(ut_params->op); 11893 if (ret != TEST_SUCCESS) 11894 goto crypto_op_free; 11895 11896 if (res_d != NULL) 11897 res_d_tmp = &res_d[i]; 11898 11899 ret = test_tls_record_post_process(ut_params->ibuf, &td[i], res_d_tmp, silent); 11900 if (ret != TEST_SUCCESS) 11901 goto crypto_op_free; 11902 11903 11904 rte_crypto_op_free(ut_params->op); 11905 ut_params->op = NULL; 11906 11907 rte_pktmbuf_free(ut_params->ibuf); 11908 ut_params->ibuf = NULL; 11909 } 11910 11911 crypto_op_free: 11912 rte_crypto_op_free(ut_params->op); 11913 ut_params->op = NULL; 11914 11915 rte_pktmbuf_free(ut_params->ibuf); 11916 ut_params->ibuf = NULL; 11917 11918 if (ut_params->sec_session) 11919 rte_security_session_destroy(ctx, ut_params->sec_session); 11920 ut_params->sec_session = NULL; 11921 11922 RTE_SET_USED(flags); 11923 11924 return ret; 11925 } 11926 11927 static int 11928 test_tls_record_proto_known_vec(const void *test_data) 11929 { 11930 struct tls_record_test_data td_write; 11931 struct tls_record_test_flags flags; 11932 11933 memset(&flags, 0, sizeof(flags)); 11934 11935 memcpy(&td_write, test_data, sizeof(td_write)); 11936 11937 /* Disable IV gen to be able to test with known vectors */ 11938 td_write.tls_record_xform.options.iv_gen_disable = 1; 11939 11940 return test_tls_record_proto_process(&td_write, NULL, 1, false, &flags); 11941 } 11942 11943 static int 11944 test_tls_record_proto_known_vec_read(const void *test_data) 11945 { 11946 const struct tls_record_test_data *td = test_data; 11947 struct tls_record_test_flags flags; 11948 struct tls_record_test_data td_inb; 11949 11950 memset(&flags, 0, sizeof(flags)); 11951 11952 if (td->tls_record_xform.type == RTE_SECURITY_TLS_SESS_TYPE_WRITE) 11953 test_tls_record_td_read_from_write(td, &td_inb); 11954 else 11955 memcpy(&td_inb, td, sizeof(td_inb)); 11956 11957 return test_tls_record_proto_process(&td_inb, NULL, 1, false, &flags); 11958 } 11959 11960 static int 11961 test_tls_record_proto_all(const struct tls_record_test_flags *flags) 11962 { 11963 unsigned int i, nb_pkts = 1, pass_cnt = 0, payload_len, max_payload_len; 11964 struct tls_record_test_data td_outb[TEST_SEC_PKTS_MAX]; 11965 struct tls_record_test_data td_inb[TEST_SEC_PKTS_MAX]; 11966 int ret; 11967 11968 switch (flags->tls_version) { 11969 case RTE_SECURITY_VERSION_TLS_1_2: 11970 max_payload_len = TLS_1_2_RECORD_PLAINTEXT_MAX_LEN; 11971 break; 11972 case RTE_SECURITY_VERSION_TLS_1_3: 11973 max_payload_len = TLS_1_3_RECORD_PLAINTEXT_MAX_LEN; 11974 break; 11975 case RTE_SECURITY_VERSION_DTLS_1_2: 11976 max_payload_len = DTLS_1_2_RECORD_PLAINTEXT_MAX_LEN; 11977 break; 11978 default: 11979 max_payload_len = 0; 11980 } 11981 11982 for (i = 0; i < RTE_DIM(sec_alg_list); i++) { 11983 payload_len = TLS_RECORD_PLAINTEXT_MIN_LEN; 11984 again: 11985 test_tls_record_td_prepare(sec_alg_list[i].param1, sec_alg_list[i].param2, flags, 11986 td_outb, nb_pkts, payload_len); 11987 11988 ret = test_tls_record_proto_process(td_outb, td_inb, nb_pkts, true, flags); 11989 if (ret == TEST_SKIPPED) 11990 continue; 11991 11992 if (ret == TEST_FAILED) 11993 return TEST_FAILED; 11994 11995 test_tls_record_td_update(td_inb, td_outb, nb_pkts, flags); 11996 11997 ret = test_tls_record_proto_process(td_inb, NULL, nb_pkts, true, flags); 11998 if (ret == TEST_SKIPPED) 11999 continue; 12000 12001 if (ret == TEST_FAILED) 12002 return TEST_FAILED; 12003 12004 if (flags->data_walkthrough && (++payload_len <= max_payload_len)) 12005 goto again; 12006 12007 if (flags->display_alg) 12008 test_sec_alg_display(sec_alg_list[i].param1, sec_alg_list[i].param2); 12009 12010 pass_cnt++; 12011 } 12012 12013 if (pass_cnt > 0) 12014 return TEST_SUCCESS; 12015 else 12016 return TEST_SKIPPED; 12017 } 12018 12019 static int 12020 test_tls_1_2_record_proto_data_walkthrough(void) 12021 { 12022 struct tls_record_test_flags flags; 12023 12024 memset(&flags, 0, sizeof(flags)); 12025 12026 flags.data_walkthrough = true; 12027 flags.tls_version = RTE_SECURITY_VERSION_TLS_1_2; 12028 12029 return test_tls_record_proto_all(&flags); 12030 } 12031 12032 static int 12033 test_tls_1_2_record_proto_display_list(void) 12034 { 12035 struct tls_record_test_flags flags; 12036 12037 memset(&flags, 0, sizeof(flags)); 12038 12039 flags.display_alg = true; 12040 flags.tls_version = RTE_SECURITY_VERSION_TLS_1_2; 12041 12042 return test_tls_record_proto_all(&flags); 12043 } 12044 12045 static int 12046 test_tls_1_2_record_proto_sgl(void) 12047 { 12048 struct tls_record_test_flags flags = { 12049 .nb_segs_in_mbuf = 5, 12050 .tls_version = RTE_SECURITY_VERSION_TLS_1_2 12051 }; 12052 struct crypto_testsuite_params *ts_params = &testsuite_params; 12053 struct rte_cryptodev_info dev_info; 12054 12055 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12056 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 12057 printf("Device doesn't support in-place scatter-gather. Test Skipped.\n"); 12058 return TEST_SKIPPED; 12059 } 12060 12061 return test_tls_record_proto_all(&flags); 12062 } 12063 12064 static int 12065 test_dtls_1_2_record_proto_data_walkthrough(void) 12066 { 12067 struct tls_record_test_flags flags; 12068 12069 memset(&flags, 0, sizeof(flags)); 12070 12071 flags.data_walkthrough = true; 12072 flags.tls_version = RTE_SECURITY_VERSION_DTLS_1_2; 12073 12074 return test_tls_record_proto_all(&flags); 12075 } 12076 12077 static int 12078 test_dtls_1_2_record_proto_display_list(void) 12079 { 12080 struct tls_record_test_flags flags; 12081 12082 memset(&flags, 0, sizeof(flags)); 12083 12084 flags.display_alg = true; 12085 flags.tls_version = RTE_SECURITY_VERSION_DTLS_1_2; 12086 12087 return test_tls_record_proto_all(&flags); 12088 } 12089 12090 static int 12091 test_dtls_1_2_record_proto_sgl(void) 12092 { 12093 struct tls_record_test_flags flags = { 12094 .nb_segs_in_mbuf = 5, 12095 .tls_version = RTE_SECURITY_VERSION_DTLS_1_2 12096 }; 12097 struct crypto_testsuite_params *ts_params = &testsuite_params; 12098 struct rte_cryptodev_info dev_info; 12099 12100 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12101 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 12102 printf("Device doesn't support in-place scatter-gather. Test Skipped.\n"); 12103 return TEST_SKIPPED; 12104 } 12105 12106 return test_tls_record_proto_all(&flags); 12107 } 12108 12109 #endif 12110 12111 static int 12112 test_AES_GCM_authenticated_encryption_test_case_1(void) 12113 { 12114 return test_authenticated_encryption(&gcm_test_case_1); 12115 } 12116 12117 static int 12118 test_AES_GCM_authenticated_encryption_test_case_2(void) 12119 { 12120 return test_authenticated_encryption(&gcm_test_case_2); 12121 } 12122 12123 static int 12124 test_AES_GCM_authenticated_encryption_test_case_3(void) 12125 { 12126 return test_authenticated_encryption(&gcm_test_case_3); 12127 } 12128 12129 static int 12130 test_AES_GCM_authenticated_encryption_test_case_3_ext_mbuf(void) 12131 { 12132 return test_authenticated_encryption_helper(&gcm_test_case_3, true); 12133 } 12134 12135 static int 12136 test_AES_GCM_authenticated_encryption_test_case_4(void) 12137 { 12138 return test_authenticated_encryption(&gcm_test_case_4); 12139 } 12140 12141 static int 12142 test_AES_GCM_authenticated_encryption_test_case_5(void) 12143 { 12144 return test_authenticated_encryption(&gcm_test_case_5); 12145 } 12146 12147 static int 12148 test_AES_GCM_authenticated_encryption_test_case_6(void) 12149 { 12150 return test_authenticated_encryption(&gcm_test_case_6); 12151 } 12152 12153 static int 12154 test_AES_GCM_authenticated_encryption_test_case_7(void) 12155 { 12156 return test_authenticated_encryption(&gcm_test_case_7); 12157 } 12158 12159 static int 12160 test_AES_GCM_authenticated_encryption_test_case_8(void) 12161 { 12162 return test_authenticated_encryption(&gcm_test_case_8); 12163 } 12164 12165 static int 12166 test_AES_GCM_J0_authenticated_encryption_test_case_1(void) 12167 { 12168 return test_authenticated_encryption(&gcm_J0_test_case_1); 12169 } 12170 12171 static int 12172 test_AES_GCM_auth_encryption_test_case_192_1(void) 12173 { 12174 return test_authenticated_encryption(&gcm_test_case_192_1); 12175 } 12176 12177 static int 12178 test_AES_GCM_auth_encryption_test_case_192_2(void) 12179 { 12180 return test_authenticated_encryption(&gcm_test_case_192_2); 12181 } 12182 12183 static int 12184 test_AES_GCM_auth_encryption_test_case_192_3(void) 12185 { 12186 return test_authenticated_encryption(&gcm_test_case_192_3); 12187 } 12188 12189 static int 12190 test_AES_GCM_auth_encryption_test_case_192_4(void) 12191 { 12192 return test_authenticated_encryption(&gcm_test_case_192_4); 12193 } 12194 12195 static int 12196 test_AES_GCM_auth_encryption_test_case_192_5(void) 12197 { 12198 return test_authenticated_encryption(&gcm_test_case_192_5); 12199 } 12200 12201 static int 12202 test_AES_GCM_auth_encryption_test_case_192_6(void) 12203 { 12204 return test_authenticated_encryption(&gcm_test_case_192_6); 12205 } 12206 12207 static int 12208 test_AES_GCM_auth_encryption_test_case_192_7(void) 12209 { 12210 return test_authenticated_encryption(&gcm_test_case_192_7); 12211 } 12212 12213 static int 12214 test_AES_GCM_auth_encryption_test_case_256_1(void) 12215 { 12216 return test_authenticated_encryption(&gcm_test_case_256_1); 12217 } 12218 12219 static int 12220 test_AES_GCM_auth_encryption_test_case_256_2(void) 12221 { 12222 return test_authenticated_encryption(&gcm_test_case_256_2); 12223 } 12224 12225 static int 12226 test_AES_GCM_auth_encryption_test_case_256_3(void) 12227 { 12228 return test_authenticated_encryption(&gcm_test_case_256_3); 12229 } 12230 12231 static int 12232 test_AES_GCM_auth_encryption_test_case_256_4(void) 12233 { 12234 return test_authenticated_encryption(&gcm_test_case_256_4); 12235 } 12236 12237 static int 12238 test_AES_GCM_auth_encryption_test_case_256_5(void) 12239 { 12240 return test_authenticated_encryption(&gcm_test_case_256_5); 12241 } 12242 12243 static int 12244 test_AES_GCM_auth_encryption_test_case_256_6(void) 12245 { 12246 return test_authenticated_encryption(&gcm_test_case_256_6); 12247 } 12248 12249 static int 12250 test_AES_GCM_auth_encryption_test_case_256_7(void) 12251 { 12252 return test_authenticated_encryption(&gcm_test_case_256_7); 12253 } 12254 12255 static int 12256 test_AES_GCM_auth_encryption_test_case_aad_1(void) 12257 { 12258 return test_authenticated_encryption(&gcm_test_case_aad_1); 12259 } 12260 12261 static int 12262 test_AES_GCM_auth_encryption_test_case_aad_2(void) 12263 { 12264 return test_authenticated_encryption(&gcm_test_case_aad_2); 12265 } 12266 12267 static int 12268 test_AES_GCM_auth_encryption_fail_iv_corrupt(void) 12269 { 12270 struct aead_test_data tdata; 12271 int res; 12272 12273 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12274 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12275 tdata.iv.data[0] += 1; 12276 res = test_authenticated_encryption(&tdata); 12277 if (res == TEST_SKIPPED) 12278 return res; 12279 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 12280 return TEST_SUCCESS; 12281 } 12282 12283 static int 12284 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void) 12285 { 12286 struct aead_test_data tdata; 12287 int res; 12288 12289 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12290 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12291 tdata.plaintext.data[0] += 1; 12292 res = test_authenticated_encryption(&tdata); 12293 if (res == TEST_SKIPPED) 12294 return res; 12295 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 12296 return TEST_SUCCESS; 12297 } 12298 12299 static int 12300 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void) 12301 { 12302 struct aead_test_data tdata; 12303 int res; 12304 12305 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12306 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12307 tdata.ciphertext.data[0] += 1; 12308 res = test_authenticated_encryption(&tdata); 12309 if (res == TEST_SKIPPED) 12310 return res; 12311 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 12312 return TEST_SUCCESS; 12313 } 12314 12315 static int 12316 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void) 12317 { 12318 struct aead_test_data tdata; 12319 int res; 12320 12321 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12322 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12323 tdata.aad.len += 1; 12324 res = test_authenticated_encryption(&tdata); 12325 if (res == TEST_SKIPPED) 12326 return res; 12327 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 12328 return TEST_SUCCESS; 12329 } 12330 12331 static int 12332 test_AES_GCM_auth_encryption_fail_aad_corrupt(void) 12333 { 12334 struct aead_test_data tdata; 12335 uint8_t aad[gcm_test_case_7.aad.len]; 12336 int res; 12337 12338 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12339 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12340 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 12341 aad[0] += 1; 12342 tdata.aad.data = aad; 12343 res = test_authenticated_encryption(&tdata); 12344 if (res == TEST_SKIPPED) 12345 return res; 12346 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 12347 return TEST_SUCCESS; 12348 } 12349 12350 static int 12351 test_AES_GCM_auth_encryption_fail_tag_corrupt(void) 12352 { 12353 struct aead_test_data tdata; 12354 int res; 12355 12356 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12357 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12358 tdata.auth_tag.data[0] += 1; 12359 res = test_authenticated_encryption(&tdata); 12360 if (res == TEST_SKIPPED) 12361 return res; 12362 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 12363 return TEST_SUCCESS; 12364 } 12365 12366 static int 12367 test_authenticated_decryption_helper(const struct aead_test_data *tdata, bool use_ext_mbuf) 12368 { 12369 struct crypto_testsuite_params *ts_params = &testsuite_params; 12370 struct crypto_unittest_params *ut_params = &unittest_params; 12371 12372 int retval; 12373 uint8_t *plaintext; 12374 uint32_t i; 12375 struct rte_cryptodev_info dev_info; 12376 12377 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12378 uint64_t feat_flags = dev_info.feature_flags; 12379 12380 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12381 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12382 printf("Device doesn't support RAW data-path APIs.\n"); 12383 return TEST_SKIPPED; 12384 } 12385 12386 /* Verify the capabilities */ 12387 struct rte_cryptodev_sym_capability_idx cap_idx; 12388 const struct rte_cryptodev_symmetric_capability *capability; 12389 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12390 cap_idx.algo.aead = tdata->algo; 12391 capability = rte_cryptodev_sym_capability_get( 12392 ts_params->valid_devs[0], &cap_idx); 12393 if (capability == NULL) 12394 return TEST_SKIPPED; 12395 if (rte_cryptodev_sym_capability_check_aead( 12396 capability, tdata->key.len, tdata->auth_tag.len, 12397 tdata->aad.len, tdata->iv.len)) 12398 return TEST_SKIPPED; 12399 12400 /* Create AEAD session */ 12401 retval = create_aead_session(ts_params->valid_devs[0], 12402 tdata->algo, 12403 RTE_CRYPTO_AEAD_OP_DECRYPT, 12404 tdata->key.data, tdata->key.len, 12405 tdata->aad.len, tdata->auth_tag.len, 12406 tdata->iv.len); 12407 if (retval != TEST_SUCCESS) 12408 return retval; 12409 12410 /* alloc mbuf and set payload */ 12411 if (tdata->aad.len > MBUF_SIZE) { 12412 if (use_ext_mbuf) { 12413 ut_params->ibuf = ext_mbuf_create(ts_params->large_mbuf_pool, 12414 AEAD_TEXT_MAX_LENGTH, 12415 1 /* nb_segs */, 12416 NULL); 12417 } else { 12418 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 12419 } 12420 /* Populate full size of add data */ 12421 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 12422 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 12423 } else { 12424 if (use_ext_mbuf) { 12425 ut_params->ibuf = ext_mbuf_create(ts_params->mbuf_pool, 12426 AEAD_TEXT_MAX_LENGTH, 12427 1 /* nb_segs */, 12428 NULL); 12429 } else { 12430 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12431 } 12432 } 12433 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12434 rte_pktmbuf_tailroom(ut_params->ibuf)); 12435 12436 /* Create AEAD operation */ 12437 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 12438 if (retval < 0) 12439 return retval; 12440 12441 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12442 12443 ut_params->op->sym->m_src = ut_params->ibuf; 12444 12445 /* Process crypto operation */ 12446 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12447 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 12448 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 12449 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 12450 0); 12451 if (retval != TEST_SUCCESS) 12452 return retval; 12453 } else 12454 TEST_ASSERT_NOT_NULL( 12455 process_crypto_request(ts_params->valid_devs[0], 12456 ut_params->op), "failed to process sym crypto op"); 12457 12458 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12459 "crypto op processing failed"); 12460 12461 if (ut_params->op->sym->m_dst) 12462 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 12463 uint8_t *); 12464 else 12465 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 12466 uint8_t *, 12467 ut_params->op->sym->cipher.data.offset); 12468 12469 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 12470 12471 /* Validate obuf */ 12472 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12473 plaintext, 12474 tdata->plaintext.data, 12475 tdata->plaintext.len, 12476 "Plaintext data not as expected"); 12477 12478 TEST_ASSERT_EQUAL(ut_params->op->status, 12479 RTE_CRYPTO_OP_STATUS_SUCCESS, 12480 "Authentication failed"); 12481 12482 return 0; 12483 } 12484 12485 static int 12486 test_authenticated_decryption(const struct aead_test_data *tdata) 12487 { 12488 return test_authenticated_decryption_helper(tdata, false); 12489 } 12490 12491 static int 12492 test_AES_GCM_authenticated_decryption_test_case_1(void) 12493 { 12494 return test_authenticated_decryption(&gcm_test_case_1); 12495 } 12496 12497 static int 12498 test_AES_GCM_authenticated_decryption_test_case_2(void) 12499 { 12500 return test_authenticated_decryption(&gcm_test_case_2); 12501 } 12502 12503 static int 12504 test_AES_GCM_authenticated_decryption_test_case_3(void) 12505 { 12506 return test_authenticated_decryption(&gcm_test_case_3); 12507 } 12508 12509 static int 12510 test_AES_GCM_authenticated_decryption_test_case_3_ext_mbuf(void) 12511 { 12512 return test_authenticated_decryption_helper(&gcm_test_case_3, true); 12513 } 12514 12515 static int 12516 test_AES_GCM_authenticated_decryption_test_case_4(void) 12517 { 12518 return test_authenticated_decryption(&gcm_test_case_4); 12519 } 12520 12521 static int 12522 test_AES_GCM_authenticated_decryption_test_case_5(void) 12523 { 12524 return test_authenticated_decryption(&gcm_test_case_5); 12525 } 12526 12527 static int 12528 test_AES_GCM_authenticated_decryption_test_case_6(void) 12529 { 12530 return test_authenticated_decryption(&gcm_test_case_6); 12531 } 12532 12533 static int 12534 test_AES_GCM_authenticated_decryption_test_case_7(void) 12535 { 12536 return test_authenticated_decryption(&gcm_test_case_7); 12537 } 12538 12539 static int 12540 test_AES_GCM_authenticated_decryption_test_case_8(void) 12541 { 12542 return test_authenticated_decryption(&gcm_test_case_8); 12543 } 12544 12545 static int 12546 test_AES_GCM_J0_authenticated_decryption_test_case_1(void) 12547 { 12548 return test_authenticated_decryption(&gcm_J0_test_case_1); 12549 } 12550 12551 static int 12552 test_AES_GCM_auth_decryption_test_case_192_1(void) 12553 { 12554 return test_authenticated_decryption(&gcm_test_case_192_1); 12555 } 12556 12557 static int 12558 test_AES_GCM_auth_decryption_test_case_192_2(void) 12559 { 12560 return test_authenticated_decryption(&gcm_test_case_192_2); 12561 } 12562 12563 static int 12564 test_AES_GCM_auth_decryption_test_case_192_3(void) 12565 { 12566 return test_authenticated_decryption(&gcm_test_case_192_3); 12567 } 12568 12569 static int 12570 test_AES_GCM_auth_decryption_test_case_192_4(void) 12571 { 12572 return test_authenticated_decryption(&gcm_test_case_192_4); 12573 } 12574 12575 static int 12576 test_AES_GCM_auth_decryption_test_case_192_5(void) 12577 { 12578 return test_authenticated_decryption(&gcm_test_case_192_5); 12579 } 12580 12581 static int 12582 test_AES_GCM_auth_decryption_test_case_192_6(void) 12583 { 12584 return test_authenticated_decryption(&gcm_test_case_192_6); 12585 } 12586 12587 static int 12588 test_AES_GCM_auth_decryption_test_case_192_7(void) 12589 { 12590 return test_authenticated_decryption(&gcm_test_case_192_7); 12591 } 12592 12593 static int 12594 test_AES_GCM_auth_decryption_test_case_256_1(void) 12595 { 12596 return test_authenticated_decryption(&gcm_test_case_256_1); 12597 } 12598 12599 static int 12600 test_AES_GCM_auth_decryption_test_case_256_2(void) 12601 { 12602 return test_authenticated_decryption(&gcm_test_case_256_2); 12603 } 12604 12605 static int 12606 test_AES_GCM_auth_decryption_test_case_256_3(void) 12607 { 12608 return test_authenticated_decryption(&gcm_test_case_256_3); 12609 } 12610 12611 static int 12612 test_AES_GCM_auth_decryption_test_case_256_4(void) 12613 { 12614 return test_authenticated_decryption(&gcm_test_case_256_4); 12615 } 12616 12617 static int 12618 test_AES_GCM_auth_decryption_test_case_256_5(void) 12619 { 12620 return test_authenticated_decryption(&gcm_test_case_256_5); 12621 } 12622 12623 static int 12624 test_AES_GCM_auth_decryption_test_case_256_6(void) 12625 { 12626 return test_authenticated_decryption(&gcm_test_case_256_6); 12627 } 12628 12629 static int 12630 test_AES_GCM_auth_decryption_test_case_256_7(void) 12631 { 12632 return test_authenticated_decryption(&gcm_test_case_256_7); 12633 } 12634 12635 static int 12636 test_AES_GCM_auth_decryption_test_case_256_8(void) 12637 { 12638 return test_authenticated_decryption(&gcm_test_case_256_8); 12639 } 12640 12641 static int 12642 test_AES_GCM_auth_encryption_test_case_256_8(void) 12643 { 12644 return test_authenticated_encryption(&gcm_test_case_256_8); 12645 } 12646 12647 static int 12648 test_AES_GCM_auth_decryption_test_case_aad_1(void) 12649 { 12650 return test_authenticated_decryption(&gcm_test_case_aad_1); 12651 } 12652 12653 static int 12654 test_AES_GCM_auth_decryption_test_case_aad_2(void) 12655 { 12656 return test_authenticated_decryption(&gcm_test_case_aad_2); 12657 } 12658 12659 static int 12660 test_AES_GCM_auth_decryption_fail_iv_corrupt(void) 12661 { 12662 struct aead_test_data tdata; 12663 int res; 12664 12665 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12666 tdata.iv.data[0] += 1; 12667 res = test_authenticated_decryption(&tdata); 12668 if (res == TEST_SKIPPED) 12669 return res; 12670 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12671 return TEST_SUCCESS; 12672 } 12673 12674 static int 12675 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void) 12676 { 12677 struct aead_test_data tdata; 12678 int res; 12679 12680 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12681 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12682 tdata.plaintext.data[0] += 1; 12683 res = test_authenticated_decryption(&tdata); 12684 if (res == TEST_SKIPPED) 12685 return res; 12686 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12687 return TEST_SUCCESS; 12688 } 12689 12690 static int 12691 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void) 12692 { 12693 struct aead_test_data tdata; 12694 int res; 12695 12696 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12697 tdata.ciphertext.data[0] += 1; 12698 res = test_authenticated_decryption(&tdata); 12699 if (res == TEST_SKIPPED) 12700 return res; 12701 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12702 return TEST_SUCCESS; 12703 } 12704 12705 static int 12706 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void) 12707 { 12708 struct aead_test_data tdata; 12709 int res; 12710 12711 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12712 tdata.aad.len += 1; 12713 res = test_authenticated_decryption(&tdata); 12714 if (res == TEST_SKIPPED) 12715 return res; 12716 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12717 return TEST_SUCCESS; 12718 } 12719 12720 static int 12721 test_AES_GCM_auth_decryption_fail_aad_corrupt(void) 12722 { 12723 struct aead_test_data tdata; 12724 uint8_t aad[gcm_test_case_7.aad.len]; 12725 int res; 12726 12727 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12728 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 12729 aad[0] += 1; 12730 tdata.aad.data = aad; 12731 res = test_authenticated_decryption(&tdata); 12732 if (res == TEST_SKIPPED) 12733 return res; 12734 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12735 return TEST_SUCCESS; 12736 } 12737 12738 static int 12739 test_AES_GCM_auth_decryption_fail_tag_corrupt(void) 12740 { 12741 struct aead_test_data tdata; 12742 int res; 12743 12744 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12745 tdata.auth_tag.data[0] += 1; 12746 res = test_authenticated_decryption(&tdata); 12747 if (res == TEST_SKIPPED) 12748 return res; 12749 TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed"); 12750 return TEST_SUCCESS; 12751 } 12752 12753 static int 12754 test_authenticated_encryption_oop(const struct aead_test_data *tdata) 12755 { 12756 struct crypto_testsuite_params *ts_params = &testsuite_params; 12757 struct crypto_unittest_params *ut_params = &unittest_params; 12758 12759 int retval; 12760 uint8_t *ciphertext, *auth_tag; 12761 uint16_t plaintext_pad_len; 12762 struct rte_cryptodev_info dev_info; 12763 12764 /* Verify the capabilities */ 12765 struct rte_cryptodev_sym_capability_idx cap_idx; 12766 const struct rte_cryptodev_symmetric_capability *capability; 12767 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12768 cap_idx.algo.aead = tdata->algo; 12769 capability = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], &cap_idx); 12770 if (capability == NULL) 12771 return TEST_SKIPPED; 12772 if (rte_cryptodev_sym_capability_check_aead( 12773 capability, tdata->key.len, tdata->auth_tag.len, 12774 tdata->aad.len, tdata->iv.len)) 12775 return TEST_SKIPPED; 12776 12777 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12778 uint64_t feat_flags = dev_info.feature_flags; 12779 12780 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12781 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) 12782 return TEST_SKIPPED; 12783 12784 /* not supported with CPU crypto */ 12785 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12786 return TEST_SKIPPED; 12787 12788 /* Create AEAD session */ 12789 retval = create_aead_session(ts_params->valid_devs[0], 12790 tdata->algo, 12791 RTE_CRYPTO_AEAD_OP_ENCRYPT, 12792 tdata->key.data, tdata->key.len, 12793 tdata->aad.len, tdata->auth_tag.len, 12794 tdata->iv.len); 12795 if (retval < 0) 12796 return retval; 12797 12798 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12799 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12800 12801 /* clear mbuf payload */ 12802 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12803 rte_pktmbuf_tailroom(ut_params->ibuf)); 12804 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 12805 rte_pktmbuf_tailroom(ut_params->obuf)); 12806 12807 /* Create AEAD operation */ 12808 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 12809 if (retval < 0) 12810 return retval; 12811 12812 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12813 12814 ut_params->op->sym->m_src = ut_params->ibuf; 12815 ut_params->op->sym->m_dst = ut_params->obuf; 12816 12817 /* Process crypto operation */ 12818 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 12819 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 12820 0); 12821 if (retval != TEST_SUCCESS) 12822 return retval; 12823 } else 12824 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 12825 ut_params->op), "failed to process sym crypto op"); 12826 12827 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12828 "crypto op processing failed"); 12829 12830 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12831 12832 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 12833 ut_params->op->sym->cipher.data.offset); 12834 auth_tag = ciphertext + plaintext_pad_len; 12835 12836 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 12837 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 12838 12839 /* Validate obuf */ 12840 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12841 ciphertext, 12842 tdata->ciphertext.data, 12843 tdata->ciphertext.len, 12844 "Ciphertext data not as expected"); 12845 12846 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12847 auth_tag, 12848 tdata->auth_tag.data, 12849 tdata->auth_tag.len, 12850 "Generated auth tag not as expected"); 12851 12852 return 0; 12853 12854 } 12855 12856 static int 12857 test_AES_GCM_authenticated_encryption_oop_test_case_1(void) 12858 { 12859 return test_authenticated_encryption_oop(&gcm_test_case_5); 12860 } 12861 12862 static int 12863 test_authenticated_decryption_oop(const struct aead_test_data *tdata) 12864 { 12865 struct crypto_testsuite_params *ts_params = &testsuite_params; 12866 struct crypto_unittest_params *ut_params = &unittest_params; 12867 12868 int retval; 12869 uint8_t *plaintext; 12870 struct rte_cryptodev_info dev_info; 12871 12872 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12873 uint64_t feat_flags = dev_info.feature_flags; 12874 12875 /* Verify the capabilities */ 12876 struct rte_cryptodev_sym_capability_idx cap_idx; 12877 const struct rte_cryptodev_symmetric_capability *capability; 12878 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12879 cap_idx.algo.aead = tdata->algo; 12880 capability = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], &cap_idx); 12881 12882 if (capability == NULL) 12883 return TEST_SKIPPED; 12884 12885 if (rte_cryptodev_sym_capability_check_aead(capability, tdata->key.len, 12886 tdata->auth_tag.len, tdata->aad.len, tdata->iv.len)) 12887 return TEST_SKIPPED; 12888 12889 /* not supported with CPU crypto and raw data-path APIs*/ 12890 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO || 12891 global_api_test_type == CRYPTODEV_RAW_API_TEST) 12892 return TEST_SKIPPED; 12893 12894 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12895 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12896 printf("Device does not support RAW data-path APIs.\n"); 12897 return TEST_SKIPPED; 12898 } 12899 12900 /* Create AEAD session */ 12901 retval = create_aead_session(ts_params->valid_devs[0], 12902 tdata->algo, 12903 RTE_CRYPTO_AEAD_OP_DECRYPT, 12904 tdata->key.data, tdata->key.len, 12905 tdata->aad.len, tdata->auth_tag.len, 12906 tdata->iv.len); 12907 if (retval < 0) 12908 return retval; 12909 12910 /* alloc mbuf and set payload */ 12911 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12912 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12913 12914 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12915 rte_pktmbuf_tailroom(ut_params->ibuf)); 12916 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 12917 rte_pktmbuf_tailroom(ut_params->obuf)); 12918 12919 /* Create AEAD operation */ 12920 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 12921 if (retval < 0) 12922 return retval; 12923 12924 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12925 12926 ut_params->op->sym->m_src = ut_params->ibuf; 12927 ut_params->op->sym->m_dst = ut_params->obuf; 12928 12929 /* Process crypto operation */ 12930 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 12931 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 12932 0); 12933 if (retval != TEST_SUCCESS) 12934 return retval; 12935 } else 12936 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 12937 ut_params->op), "failed to process sym crypto op"); 12938 12939 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12940 "crypto op processing failed"); 12941 12942 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 12943 ut_params->op->sym->cipher.data.offset); 12944 12945 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 12946 12947 /* Validate obuf */ 12948 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12949 plaintext, 12950 tdata->plaintext.data, 12951 tdata->plaintext.len, 12952 "Plaintext data not as expected"); 12953 12954 TEST_ASSERT_EQUAL(ut_params->op->status, 12955 RTE_CRYPTO_OP_STATUS_SUCCESS, 12956 "Authentication failed"); 12957 return 0; 12958 } 12959 12960 static int 12961 test_AES_GCM_authenticated_decryption_oop_test_case_1(void) 12962 { 12963 return test_authenticated_decryption_oop(&gcm_test_case_5); 12964 } 12965 12966 static int 12967 test_authenticated_encryption_sessionless( 12968 const struct aead_test_data *tdata) 12969 { 12970 struct crypto_testsuite_params *ts_params = &testsuite_params; 12971 struct crypto_unittest_params *ut_params = &unittest_params; 12972 12973 int retval; 12974 uint8_t *ciphertext, *auth_tag; 12975 uint16_t plaintext_pad_len; 12976 uint8_t key[tdata->key.len + 1]; 12977 struct rte_cryptodev_info dev_info; 12978 12979 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12980 uint64_t feat_flags = dev_info.feature_flags; 12981 12982 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 12983 printf("Device doesn't support Sessionless ops.\n"); 12984 return TEST_SKIPPED; 12985 } 12986 12987 /* not supported with CPU crypto */ 12988 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12989 return TEST_SKIPPED; 12990 12991 /* Verify the capabilities */ 12992 struct rte_cryptodev_sym_capability_idx cap_idx; 12993 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12994 cap_idx.algo.aead = tdata->algo; 12995 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12996 &cap_idx) == NULL) 12997 return TEST_SKIPPED; 12998 12999 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13000 13001 /* clear mbuf payload */ 13002 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13003 rte_pktmbuf_tailroom(ut_params->ibuf)); 13004 13005 /* Create AEAD operation */ 13006 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 13007 if (retval < 0) 13008 return retval; 13009 13010 /* Create GCM xform */ 13011 memcpy(key, tdata->key.data, tdata->key.len); 13012 retval = create_aead_xform(ut_params->op, 13013 tdata->algo, 13014 RTE_CRYPTO_AEAD_OP_ENCRYPT, 13015 key, tdata->key.len, 13016 tdata->aad.len, tdata->auth_tag.len, 13017 tdata->iv.len); 13018 if (retval < 0) 13019 return retval; 13020 13021 ut_params->op->sym->m_src = ut_params->ibuf; 13022 13023 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 13024 RTE_CRYPTO_OP_SESSIONLESS, 13025 "crypto op session type not sessionless"); 13026 13027 /* Process crypto operation */ 13028 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 13029 ut_params->op), "failed to process sym crypto op"); 13030 13031 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 13032 13033 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13034 "crypto op status not success"); 13035 13036 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 13037 13038 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 13039 ut_params->op->sym->cipher.data.offset); 13040 auth_tag = ciphertext + plaintext_pad_len; 13041 13042 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 13043 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 13044 13045 /* Validate obuf */ 13046 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13047 ciphertext, 13048 tdata->ciphertext.data, 13049 tdata->ciphertext.len, 13050 "Ciphertext data not as expected"); 13051 13052 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13053 auth_tag, 13054 tdata->auth_tag.data, 13055 tdata->auth_tag.len, 13056 "Generated auth tag not as expected"); 13057 13058 return 0; 13059 13060 } 13061 13062 static int 13063 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void) 13064 { 13065 return test_authenticated_encryption_sessionless( 13066 &gcm_test_case_5); 13067 } 13068 13069 static int 13070 test_authenticated_decryption_sessionless( 13071 const struct aead_test_data *tdata) 13072 { 13073 struct crypto_testsuite_params *ts_params = &testsuite_params; 13074 struct crypto_unittest_params *ut_params = &unittest_params; 13075 13076 int retval; 13077 uint8_t *plaintext; 13078 uint8_t key[tdata->key.len + 1]; 13079 struct rte_cryptodev_info dev_info; 13080 13081 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13082 uint64_t feat_flags = dev_info.feature_flags; 13083 13084 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 13085 printf("Device doesn't support Sessionless ops.\n"); 13086 return TEST_SKIPPED; 13087 } 13088 13089 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13090 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13091 printf("Device doesn't support RAW data-path APIs.\n"); 13092 return TEST_SKIPPED; 13093 } 13094 13095 /* not supported with CPU crypto */ 13096 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13097 return TEST_SKIPPED; 13098 13099 /* Verify the capabilities */ 13100 struct rte_cryptodev_sym_capability_idx cap_idx; 13101 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 13102 cap_idx.algo.aead = tdata->algo; 13103 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13104 &cap_idx) == NULL) 13105 return TEST_SKIPPED; 13106 13107 /* alloc mbuf and set payload */ 13108 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13109 13110 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13111 rte_pktmbuf_tailroom(ut_params->ibuf)); 13112 13113 /* Create AEAD operation */ 13114 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 13115 if (retval < 0) 13116 return retval; 13117 13118 /* Create AEAD xform */ 13119 memcpy(key, tdata->key.data, tdata->key.len); 13120 retval = create_aead_xform(ut_params->op, 13121 tdata->algo, 13122 RTE_CRYPTO_AEAD_OP_DECRYPT, 13123 key, tdata->key.len, 13124 tdata->aad.len, tdata->auth_tag.len, 13125 tdata->iv.len); 13126 if (retval < 0) 13127 return retval; 13128 13129 ut_params->op->sym->m_src = ut_params->ibuf; 13130 13131 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 13132 RTE_CRYPTO_OP_SESSIONLESS, 13133 "crypto op session type not sessionless"); 13134 13135 /* Process crypto operation */ 13136 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 13137 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 13138 0); 13139 if (retval != TEST_SUCCESS) 13140 return retval; 13141 } else 13142 TEST_ASSERT_NOT_NULL(process_crypto_request( 13143 ts_params->valid_devs[0], ut_params->op), 13144 "failed to process sym crypto op"); 13145 13146 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 13147 13148 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13149 "crypto op status not success"); 13150 13151 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 13152 ut_params->op->sym->cipher.data.offset); 13153 13154 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 13155 13156 /* Validate obuf */ 13157 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13158 plaintext, 13159 tdata->plaintext.data, 13160 tdata->plaintext.len, 13161 "Plaintext data not as expected"); 13162 13163 TEST_ASSERT_EQUAL(ut_params->op->status, 13164 RTE_CRYPTO_OP_STATUS_SUCCESS, 13165 "Authentication failed"); 13166 return 0; 13167 } 13168 13169 static int 13170 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void) 13171 { 13172 return test_authenticated_decryption_sessionless( 13173 &gcm_test_case_5); 13174 } 13175 13176 static int 13177 test_AES_CCM_authenticated_encryption_test_case_128_1(void) 13178 { 13179 return test_authenticated_encryption(&ccm_test_case_128_1); 13180 } 13181 13182 static int 13183 test_AES_CCM_authenticated_encryption_test_case_128_2(void) 13184 { 13185 return test_authenticated_encryption(&ccm_test_case_128_2); 13186 } 13187 13188 static int 13189 test_AES_CCM_authenticated_encryption_test_case_128_3(void) 13190 { 13191 return test_authenticated_encryption(&ccm_test_case_128_3); 13192 } 13193 13194 static int 13195 test_AES_CCM_authenticated_decryption_test_case_128_1(void) 13196 { 13197 return test_authenticated_decryption(&ccm_test_case_128_1); 13198 } 13199 13200 static int 13201 test_AES_CCM_authenticated_decryption_test_case_128_2(void) 13202 { 13203 return test_authenticated_decryption(&ccm_test_case_128_2); 13204 } 13205 13206 static int 13207 test_AES_CCM_authenticated_decryption_test_case_128_3(void) 13208 { 13209 return test_authenticated_decryption(&ccm_test_case_128_3); 13210 } 13211 13212 static int 13213 test_AES_CCM_authenticated_encryption_test_case_192_1(void) 13214 { 13215 return test_authenticated_encryption(&ccm_test_case_192_1); 13216 } 13217 13218 static int 13219 test_AES_CCM_authenticated_encryption_test_case_192_2(void) 13220 { 13221 return test_authenticated_encryption(&ccm_test_case_192_2); 13222 } 13223 13224 static int 13225 test_AES_CCM_authenticated_encryption_test_case_192_3(void) 13226 { 13227 return test_authenticated_encryption(&ccm_test_case_192_3); 13228 } 13229 13230 static int 13231 test_AES_CCM_authenticated_decryption_test_case_192_1(void) 13232 { 13233 return test_authenticated_decryption(&ccm_test_case_192_1); 13234 } 13235 13236 static int 13237 test_AES_CCM_authenticated_decryption_test_case_192_2(void) 13238 { 13239 return test_authenticated_decryption(&ccm_test_case_192_2); 13240 } 13241 13242 static int 13243 test_AES_CCM_authenticated_decryption_test_case_192_3(void) 13244 { 13245 return test_authenticated_decryption(&ccm_test_case_192_3); 13246 } 13247 13248 static int 13249 test_AES_CCM_authenticated_encryption_test_case_256_1(void) 13250 { 13251 return test_authenticated_encryption(&ccm_test_case_256_1); 13252 } 13253 13254 static int 13255 test_AES_CCM_authenticated_encryption_test_case_256_2(void) 13256 { 13257 return test_authenticated_encryption(&ccm_test_case_256_2); 13258 } 13259 13260 static int 13261 test_AES_CCM_authenticated_encryption_test_case_256_3(void) 13262 { 13263 return test_authenticated_encryption(&ccm_test_case_256_3); 13264 } 13265 13266 static int 13267 test_AES_CCM_authenticated_decryption_test_case_256_1(void) 13268 { 13269 return test_authenticated_decryption(&ccm_test_case_256_1); 13270 } 13271 13272 static int 13273 test_AES_CCM_authenticated_decryption_test_case_256_2(void) 13274 { 13275 return test_authenticated_decryption(&ccm_test_case_256_2); 13276 } 13277 13278 static int 13279 test_AES_CCM_authenticated_decryption_test_case_256_3(void) 13280 { 13281 return test_authenticated_decryption(&ccm_test_case_256_3); 13282 } 13283 13284 static int 13285 test_stats(void) 13286 { 13287 struct crypto_testsuite_params *ts_params = &testsuite_params; 13288 struct rte_cryptodev_stats stats; 13289 13290 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13291 return TEST_SKIPPED; 13292 13293 /* Verify the capabilities */ 13294 struct rte_cryptodev_sym_capability_idx cap_idx; 13295 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13296 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 13297 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13298 &cap_idx) == NULL) 13299 return TEST_SKIPPED; 13300 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13301 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 13302 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13303 &cap_idx) == NULL) 13304 return TEST_SKIPPED; 13305 13306 if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 13307 == -ENOTSUP) 13308 return TEST_SKIPPED; 13309 13310 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 13311 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 13312 &stats) == -ENODEV), 13313 "rte_cryptodev_stats_get invalid dev failed"); 13314 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 13315 "rte_cryptodev_stats_get invalid Param failed"); 13316 13317 /* Test expected values */ 13318 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 13319 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 13320 &stats), 13321 "rte_cryptodev_stats_get failed"); 13322 TEST_ASSERT((stats.enqueued_count == 1), 13323 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 13324 TEST_ASSERT((stats.dequeued_count == 1), 13325 "rte_cryptodev_stats_get returned unexpected dequeued stat"); 13326 TEST_ASSERT((stats.enqueue_err_count == 0), 13327 "rte_cryptodev_stats_get returned unexpected enqueued error count stat"); 13328 TEST_ASSERT((stats.dequeue_err_count == 0), 13329 "rte_cryptodev_stats_get returned unexpected dequeued error count stat"); 13330 13331 /* invalid device but should ignore and not reset device stats*/ 13332 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 13333 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 13334 &stats), 13335 "rte_cryptodev_stats_get failed"); 13336 TEST_ASSERT((stats.enqueued_count == 1), 13337 "rte_cryptodev_stats_get returned unexpected enqueued stat after invalid reset"); 13338 13339 /* check that a valid reset clears stats */ 13340 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 13341 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 13342 &stats), 13343 "rte_cryptodev_stats_get failed"); 13344 TEST_ASSERT((stats.enqueued_count == 0), 13345 "rte_cryptodev_stats_get returned unexpected enqueued stat after valid reset"); 13346 TEST_ASSERT((stats.dequeued_count == 0), 13347 "rte_cryptodev_stats_get returned unexpected dequeued stat after valid reset"); 13348 13349 return TEST_SUCCESS; 13350 } 13351 13352 static int 13353 test_device_reconfigure(void) 13354 { 13355 struct crypto_testsuite_params *ts_params = &testsuite_params; 13356 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 13357 struct rte_cryptodev_qp_conf qp_conf = { 13358 .nb_descriptors = MAX_NUM_OPS_INFLIGHT, 13359 .mp_session = ts_params->session_mpool 13360 }; 13361 uint16_t qp_id, dev_id, num_devs = 0; 13362 13363 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 13364 "Need at least %d devices for test", 1); 13365 13366 dev_id = ts_params->valid_devs[0]; 13367 13368 /* Stop the device in case it's started so it can be configured */ 13369 rte_cryptodev_stop(dev_id); 13370 13371 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 13372 "Failed test for rte_cryptodev_configure: " 13373 "dev_num %u", dev_id); 13374 13375 /* Reconfigure with same configure params */ 13376 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 13377 "Failed test for rte_cryptodev_configure: " 13378 "dev_num %u", dev_id); 13379 13380 /* Reconfigure with just one queue pair */ 13381 ts_params->conf.nb_queue_pairs = 1; 13382 13383 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 13384 &ts_params->conf), 13385 "Failed to configure cryptodev: dev_id %u, qp_id %u", 13386 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 13387 13388 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 13389 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 13390 ts_params->valid_devs[0], qp_id, &qp_conf, 13391 rte_cryptodev_socket_id( 13392 ts_params->valid_devs[0])), 13393 "Failed test for " 13394 "rte_cryptodev_queue_pair_setup: num_inflights " 13395 "%u on qp %u on cryptodev %u", 13396 qp_conf.nb_descriptors, qp_id, 13397 ts_params->valid_devs[0]); 13398 } 13399 13400 /* Reconfigure with max number of queue pairs */ 13401 ts_params->conf.nb_queue_pairs = orig_nb_qps; 13402 13403 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 13404 &ts_params->conf), 13405 "Failed to configure cryptodev: dev_id %u, qp_id %u", 13406 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 13407 13408 qp_conf.mp_session = ts_params->session_mpool; 13409 13410 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 13411 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 13412 ts_params->valid_devs[0], qp_id, &qp_conf, 13413 rte_cryptodev_socket_id( 13414 ts_params->valid_devs[0])), 13415 "Failed test for " 13416 "rte_cryptodev_queue_pair_setup: num_inflights " 13417 "%u on qp %u on cryptodev %u", 13418 qp_conf.nb_descriptors, qp_id, 13419 ts_params->valid_devs[0]); 13420 } 13421 13422 /* Start the device */ 13423 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 13424 "Failed to start cryptodev %u", 13425 ts_params->valid_devs[0]); 13426 13427 /* Test expected values */ 13428 return test_AES_CBC_HMAC_SHA1_encrypt_digest(); 13429 } 13430 13431 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 13432 struct crypto_unittest_params *ut_params, 13433 enum rte_crypto_auth_operation op, 13434 const struct HMAC_MD5_vector *test_case) 13435 { 13436 uint8_t key[64]; 13437 13438 memcpy(key, test_case->key.data, test_case->key.len); 13439 13440 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13441 ut_params->auth_xform.next = NULL; 13442 ut_params->auth_xform.auth.op = op; 13443 13444 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 13445 13446 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 13447 ut_params->auth_xform.auth.key.length = test_case->key.len; 13448 ut_params->auth_xform.auth.key.data = key; 13449 13450 ut_params->sess = rte_cryptodev_sym_session_create( 13451 ts_params->valid_devs[0], &ut_params->auth_xform, 13452 ts_params->session_mpool); 13453 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 13454 return TEST_SKIPPED; 13455 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13456 13457 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13458 13459 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13460 rte_pktmbuf_tailroom(ut_params->ibuf)); 13461 13462 return 0; 13463 } 13464 13465 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 13466 const struct HMAC_MD5_vector *test_case, 13467 uint8_t **plaintext) 13468 { 13469 uint16_t plaintext_pad_len; 13470 13471 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 13472 13473 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 13474 16); 13475 13476 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13477 plaintext_pad_len); 13478 memcpy(*plaintext, test_case->plaintext.data, 13479 test_case->plaintext.len); 13480 13481 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 13482 ut_params->ibuf, MD5_DIGEST_LEN); 13483 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13484 "no room to append digest"); 13485 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 13486 ut_params->ibuf, plaintext_pad_len); 13487 13488 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 13489 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 13490 test_case->auth_tag.len); 13491 } 13492 13493 sym_op->auth.data.offset = 0; 13494 sym_op->auth.data.length = test_case->plaintext.len; 13495 13496 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13497 ut_params->op->sym->m_src = ut_params->ibuf; 13498 13499 return 0; 13500 } 13501 13502 static int 13503 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 13504 { 13505 uint16_t plaintext_pad_len; 13506 uint8_t *plaintext, *auth_tag; 13507 int ret; 13508 13509 struct crypto_testsuite_params *ts_params = &testsuite_params; 13510 struct crypto_unittest_params *ut_params = &unittest_params; 13511 struct rte_cryptodev_info dev_info; 13512 13513 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13514 uint64_t feat_flags = dev_info.feature_flags; 13515 13516 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13517 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13518 printf("Device doesn't support RAW data-path APIs.\n"); 13519 return TEST_SKIPPED; 13520 } 13521 13522 /* Verify the capabilities */ 13523 struct rte_cryptodev_sym_capability_idx cap_idx; 13524 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13525 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 13526 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13527 &cap_idx) == NULL) 13528 return TEST_SKIPPED; 13529 13530 if (MD5_HMAC_create_session(ts_params, ut_params, 13531 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 13532 return TEST_FAILED; 13533 13534 /* Generate Crypto op data structure */ 13535 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13536 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13537 TEST_ASSERT_NOT_NULL(ut_params->op, 13538 "Failed to allocate symmetric crypto operation struct"); 13539 13540 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 13541 16); 13542 13543 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 13544 return TEST_FAILED; 13545 13546 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13547 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13548 ut_params->op); 13549 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 13550 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 0); 13551 if (ret != TEST_SUCCESS) 13552 return ret; 13553 } else 13554 TEST_ASSERT_NOT_NULL( 13555 process_crypto_request(ts_params->valid_devs[0], 13556 ut_params->op), 13557 "failed to process sym crypto op"); 13558 13559 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13560 "crypto op processing failed"); 13561 13562 if (ut_params->op->sym->m_dst) { 13563 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 13564 uint8_t *, plaintext_pad_len); 13565 } else { 13566 auth_tag = plaintext + plaintext_pad_len; 13567 } 13568 13569 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13570 auth_tag, 13571 test_case->auth_tag.data, 13572 test_case->auth_tag.len, 13573 "HMAC_MD5 generated tag not as expected"); 13574 13575 return TEST_SUCCESS; 13576 } 13577 13578 static int 13579 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 13580 { 13581 uint8_t *plaintext; 13582 int ret; 13583 13584 struct crypto_testsuite_params *ts_params = &testsuite_params; 13585 struct crypto_unittest_params *ut_params = &unittest_params; 13586 struct rte_cryptodev_info dev_info; 13587 13588 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13589 uint64_t feat_flags = dev_info.feature_flags; 13590 13591 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13592 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13593 printf("Device doesn't support RAW data-path APIs.\n"); 13594 return TEST_SKIPPED; 13595 } 13596 13597 /* Verify the capabilities */ 13598 struct rte_cryptodev_sym_capability_idx cap_idx; 13599 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13600 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 13601 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13602 &cap_idx) == NULL) 13603 return TEST_SKIPPED; 13604 13605 if (MD5_HMAC_create_session(ts_params, ut_params, 13606 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 13607 return TEST_FAILED; 13608 } 13609 13610 /* Generate Crypto op data structure */ 13611 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13612 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13613 TEST_ASSERT_NOT_NULL(ut_params->op, 13614 "Failed to allocate symmetric crypto operation struct"); 13615 13616 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 13617 return TEST_FAILED; 13618 13619 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13620 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13621 ut_params->op); 13622 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 13623 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 0); 13624 if (ret != TEST_SUCCESS) 13625 return ret; 13626 } else 13627 TEST_ASSERT_NOT_NULL( 13628 process_crypto_request(ts_params->valid_devs[0], 13629 ut_params->op), 13630 "failed to process sym crypto op"); 13631 13632 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13633 "HMAC_MD5 crypto op processing failed"); 13634 13635 return TEST_SUCCESS; 13636 } 13637 13638 static int 13639 test_MD5_HMAC_generate_case_1(void) 13640 { 13641 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 13642 } 13643 13644 static int 13645 test_MD5_HMAC_verify_case_1(void) 13646 { 13647 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 13648 } 13649 13650 static int 13651 test_MD5_HMAC_generate_case_2(void) 13652 { 13653 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 13654 } 13655 13656 static int 13657 test_MD5_HMAC_verify_case_2(void) 13658 { 13659 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 13660 } 13661 13662 static int 13663 test_multi_session(void) 13664 { 13665 struct crypto_testsuite_params *ts_params = &testsuite_params; 13666 struct crypto_unittest_params *ut_params = &unittest_params; 13667 struct rte_cryptodev_info dev_info; 13668 int i, nb_sess, ret = TEST_SUCCESS; 13669 void **sessions; 13670 13671 /* Verify the capabilities */ 13672 struct rte_cryptodev_sym_capability_idx cap_idx; 13673 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13674 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 13675 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13676 &cap_idx) == NULL) 13677 return TEST_SKIPPED; 13678 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13679 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 13680 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13681 &cap_idx) == NULL) 13682 return TEST_SKIPPED; 13683 13684 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 13685 aes_cbc_key, hmac_sha512_key); 13686 13687 13688 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13689 13690 sessions = rte_malloc(NULL, 13691 sizeof(void *) * 13692 (MAX_NB_SESSIONS + 1), 0); 13693 13694 /* Create multiple crypto sessions*/ 13695 for (i = 0; i < MAX_NB_SESSIONS; i++) { 13696 sessions[i] = rte_cryptodev_sym_session_create( 13697 ts_params->valid_devs[0], &ut_params->auth_xform, 13698 ts_params->session_mpool); 13699 if (sessions[i] == NULL && rte_errno == ENOTSUP) { 13700 nb_sess = i; 13701 ret = TEST_SKIPPED; 13702 break; 13703 } 13704 13705 TEST_ASSERT_NOT_NULL(sessions[i], 13706 "Session creation failed at session number %u", 13707 i); 13708 13709 /* Attempt to send a request on each session */ 13710 ret = test_AES_CBC_HMAC_SHA512_decrypt_perform( 13711 sessions[i], 13712 ut_params, 13713 ts_params, 13714 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 13715 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 13716 aes_cbc_iv); 13717 13718 /* free crypto operation structure */ 13719 rte_crypto_op_free(ut_params->op); 13720 13721 /* 13722 * free mbuf - both obuf and ibuf are usually the same, 13723 * so check if they point at the same address is necessary, 13724 * to avoid freeing the mbuf twice. 13725 */ 13726 if (ut_params->obuf) { 13727 rte_pktmbuf_free(ut_params->obuf); 13728 if (ut_params->ibuf == ut_params->obuf) 13729 ut_params->ibuf = 0; 13730 ut_params->obuf = 0; 13731 } 13732 if (ut_params->ibuf) { 13733 rte_pktmbuf_free(ut_params->ibuf); 13734 ut_params->ibuf = 0; 13735 } 13736 13737 if (ret != TEST_SUCCESS) { 13738 i++; 13739 break; 13740 } 13741 } 13742 13743 nb_sess = i; 13744 13745 for (i = 0; i < nb_sess; i++) { 13746 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 13747 sessions[i]); 13748 } 13749 13750 rte_free(sessions); 13751 13752 if (ret != TEST_SKIPPED) 13753 TEST_ASSERT_SUCCESS(ret, "Failed to perform decrypt on request number %u.", i - 1); 13754 13755 return ret; 13756 } 13757 13758 struct multi_session_params { 13759 struct crypto_unittest_params ut_params; 13760 uint8_t *cipher_key; 13761 uint8_t *hmac_key; 13762 const uint8_t *cipher; 13763 const uint8_t *digest; 13764 uint8_t *iv; 13765 }; 13766 13767 #define MB_SESSION_NUMBER 3 13768 13769 static int 13770 test_multi_session_random_usage(void) 13771 { 13772 struct crypto_testsuite_params *ts_params = &testsuite_params; 13773 struct rte_cryptodev_info dev_info; 13774 int index = 0, ret = TEST_SUCCESS; 13775 uint32_t nb_sess, i, j; 13776 void **sessions; 13777 struct multi_session_params ut_paramz[] = { 13778 13779 { 13780 .cipher_key = ms_aes_cbc_key0, 13781 .hmac_key = ms_hmac_key0, 13782 .cipher = ms_aes_cbc_cipher0, 13783 .digest = ms_hmac_digest0, 13784 .iv = ms_aes_cbc_iv0 13785 }, 13786 { 13787 .cipher_key = ms_aes_cbc_key1, 13788 .hmac_key = ms_hmac_key1, 13789 .cipher = ms_aes_cbc_cipher1, 13790 .digest = ms_hmac_digest1, 13791 .iv = ms_aes_cbc_iv1 13792 }, 13793 { 13794 .cipher_key = ms_aes_cbc_key2, 13795 .hmac_key = ms_hmac_key2, 13796 .cipher = ms_aes_cbc_cipher2, 13797 .digest = ms_hmac_digest2, 13798 .iv = ms_aes_cbc_iv2 13799 }, 13800 13801 }; 13802 13803 /* Verify the capabilities */ 13804 struct rte_cryptodev_sym_capability_idx cap_idx; 13805 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13806 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 13807 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13808 &cap_idx) == NULL) 13809 return TEST_SKIPPED; 13810 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13811 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 13812 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13813 &cap_idx) == NULL) 13814 return TEST_SKIPPED; 13815 13816 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13817 13818 sessions = rte_malloc(NULL, (sizeof(void *) 13819 * MAX_NB_SESSIONS) + 1, 0); 13820 13821 for (i = 0; i < MB_SESSION_NUMBER; i++) { 13822 13823 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params, 13824 sizeof(struct crypto_unittest_params)); 13825 13826 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 13827 &ut_paramz[i].ut_params, 13828 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 13829 13830 /* Create multiple crypto sessions*/ 13831 sessions[i] = rte_cryptodev_sym_session_create( 13832 ts_params->valid_devs[0], 13833 &ut_paramz[i].ut_params.auth_xform, 13834 ts_params->session_mpool); 13835 if (sessions[i] == NULL && rte_errno == ENOTSUP) { 13836 nb_sess = i; 13837 ret = TEST_SKIPPED; 13838 goto session_clear; 13839 } 13840 13841 TEST_ASSERT_NOT_NULL(sessions[i], 13842 "Session creation failed at session number %u", 13843 i); 13844 } 13845 13846 nb_sess = i; 13847 13848 srand(time(NULL)); 13849 for (i = 0; i < 40000; i++) { 13850 13851 j = rand() % MB_SESSION_NUMBER; 13852 13853 ret = test_AES_CBC_HMAC_SHA512_decrypt_perform( 13854 sessions[j], 13855 &ut_paramz[j].ut_params, 13856 ts_params, ut_paramz[j].cipher, 13857 ut_paramz[j].digest, 13858 ut_paramz[j].iv); 13859 13860 rte_crypto_op_free(ut_paramz[j].ut_params.op); 13861 13862 /* 13863 * free mbuf - both obuf and ibuf are usually the same, 13864 * so check if they point at the same address is necessary, 13865 * to avoid freeing the mbuf twice. 13866 */ 13867 if (ut_paramz[j].ut_params.obuf) { 13868 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 13869 if (ut_paramz[j].ut_params.ibuf 13870 == ut_paramz[j].ut_params.obuf) 13871 ut_paramz[j].ut_params.ibuf = 0; 13872 ut_paramz[j].ut_params.obuf = 0; 13873 } 13874 if (ut_paramz[j].ut_params.ibuf) { 13875 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 13876 ut_paramz[j].ut_params.ibuf = 0; 13877 } 13878 13879 if (ret != TEST_SKIPPED) { 13880 index = i; 13881 break; 13882 } 13883 } 13884 13885 session_clear: 13886 for (i = 0; i < nb_sess; i++) { 13887 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 13888 sessions[i]); 13889 } 13890 13891 rte_free(sessions); 13892 13893 if (ret != TEST_SKIPPED) 13894 TEST_ASSERT_SUCCESS(ret, "Failed to perform decrypt on request number %u.", index); 13895 13896 return TEST_SUCCESS; 13897 } 13898 13899 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab, 13900 0xab, 0xab, 0xab, 0xab, 13901 0xab, 0xab, 0xab, 0xab, 13902 0xab, 0xab, 0xab, 0xab}; 13903 13904 static int 13905 test_null_invalid_operation(void) 13906 { 13907 struct crypto_testsuite_params *ts_params = &testsuite_params; 13908 struct crypto_unittest_params *ut_params = &unittest_params; 13909 13910 /* This test is for NULL PMD only */ 13911 if (gbl_driver_id != rte_cryptodev_driver_id_get( 13912 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 13913 return TEST_SKIPPED; 13914 13915 /* Setup Cipher Parameters */ 13916 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13917 ut_params->cipher_xform.next = NULL; 13918 13919 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 13920 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 13921 13922 /* Create Crypto session*/ 13923 ut_params->sess = rte_cryptodev_sym_session_create( 13924 ts_params->valid_devs[0], &ut_params->cipher_xform, 13925 ts_params->session_mpool); 13926 TEST_ASSERT(ut_params->sess == NULL, 13927 "Session creation succeeded unexpectedly"); 13928 13929 /* Setup HMAC Parameters */ 13930 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13931 ut_params->auth_xform.next = NULL; 13932 13933 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 13934 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 13935 13936 /* Create Crypto session*/ 13937 ut_params->sess = rte_cryptodev_sym_session_create( 13938 ts_params->valid_devs[0], &ut_params->auth_xform, 13939 ts_params->session_mpool); 13940 TEST_ASSERT(ut_params->sess == NULL, 13941 "Session creation succeeded unexpectedly"); 13942 13943 return TEST_SUCCESS; 13944 } 13945 13946 13947 #define NULL_BURST_LENGTH (32) 13948 13949 static int 13950 test_null_burst_operation(void) 13951 { 13952 struct crypto_testsuite_params *ts_params = &testsuite_params; 13953 struct crypto_unittest_params *ut_params = &unittest_params; 13954 13955 unsigned i, burst_len = NULL_BURST_LENGTH; 13956 13957 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 13958 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 13959 13960 /* This test is for NULL PMD only */ 13961 if (gbl_driver_id != rte_cryptodev_driver_id_get( 13962 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 13963 return TEST_SKIPPED; 13964 13965 /* Setup Cipher Parameters */ 13966 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13967 ut_params->cipher_xform.next = &ut_params->auth_xform; 13968 13969 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 13970 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 13971 13972 /* Setup HMAC Parameters */ 13973 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13974 ut_params->auth_xform.next = NULL; 13975 13976 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 13977 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 13978 13979 /* Create Crypto session*/ 13980 ut_params->sess = rte_cryptodev_sym_session_create( 13981 ts_params->valid_devs[0], 13982 &ut_params->auth_xform, 13983 ts_params->session_mpool); 13984 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 13985 return TEST_SKIPPED; 13986 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13987 13988 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 13989 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 13990 burst_len, "failed to generate burst of crypto ops"); 13991 13992 /* Generate an operation for each mbuf in burst */ 13993 for (i = 0; i < burst_len; i++) { 13994 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13995 13996 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 13997 13998 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 13999 sizeof(unsigned)); 14000 *data = i; 14001 14002 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 14003 14004 burst[i]->sym->m_src = m; 14005 } 14006 14007 /* Process crypto operation */ 14008 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 14009 0, burst, burst_len), 14010 burst_len, 14011 "Error enqueuing burst"); 14012 14013 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 14014 0, burst_dequeued, burst_len), 14015 burst_len, 14016 "Error dequeuing burst"); 14017 14018 14019 for (i = 0; i < burst_len; i++) { 14020 TEST_ASSERT_EQUAL( 14021 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 14022 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 14023 uint32_t *), 14024 "data not as expected"); 14025 14026 rte_pktmbuf_free(burst[i]->sym->m_src); 14027 rte_crypto_op_free(burst[i]); 14028 } 14029 14030 return TEST_SUCCESS; 14031 } 14032 14033 static uint16_t 14034 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 14035 uint16_t nb_ops, void *user_param) 14036 { 14037 RTE_SET_USED(dev_id); 14038 RTE_SET_USED(qp_id); 14039 RTE_SET_USED(ops); 14040 RTE_SET_USED(user_param); 14041 14042 printf("crypto enqueue callback called\n"); 14043 return nb_ops; 14044 } 14045 14046 static uint16_t 14047 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 14048 uint16_t nb_ops, void *user_param) 14049 { 14050 RTE_SET_USED(dev_id); 14051 RTE_SET_USED(qp_id); 14052 RTE_SET_USED(ops); 14053 RTE_SET_USED(user_param); 14054 14055 printf("crypto dequeue callback called\n"); 14056 return nb_ops; 14057 } 14058 14059 /* 14060 * Thread using enqueue/dequeue callback with RCU. 14061 */ 14062 static int 14063 test_enqdeq_callback_thread(void *arg) 14064 { 14065 RTE_SET_USED(arg); 14066 /* DP thread calls rte_cryptodev_enqueue_burst()/ 14067 * rte_cryptodev_dequeue_burst() and invokes callback. 14068 */ 14069 test_null_burst_operation(); 14070 return 0; 14071 } 14072 14073 static int 14074 test_enq_callback_setup(void) 14075 { 14076 struct crypto_testsuite_params *ts_params = &testsuite_params; 14077 struct rte_cryptodev_info dev_info; 14078 struct rte_cryptodev_qp_conf qp_conf = { 14079 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 14080 }; 14081 14082 struct rte_cryptodev_cb *cb; 14083 uint16_t qp_id = 0; 14084 14085 /* Stop the device in case it's started so it can be configured */ 14086 rte_cryptodev_stop(ts_params->valid_devs[0]); 14087 14088 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14089 14090 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 14091 &ts_params->conf), 14092 "Failed to configure cryptodev %u", 14093 ts_params->valid_devs[0]); 14094 14095 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 14096 qp_conf.mp_session = ts_params->session_mpool; 14097 14098 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 14099 ts_params->valid_devs[0], qp_id, &qp_conf, 14100 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 14101 "Failed test for " 14102 "rte_cryptodev_queue_pair_setup: num_inflights " 14103 "%u on qp %u on cryptodev %u", 14104 qp_conf.nb_descriptors, qp_id, 14105 ts_params->valid_devs[0]); 14106 14107 /* Test with invalid crypto device */ 14108 cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS, 14109 qp_id, test_enq_callback, NULL); 14110 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 14111 "cryptodev %u did not fail", 14112 qp_id, RTE_CRYPTO_MAX_DEVS); 14113 14114 /* Test with invalid queue pair */ 14115 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 14116 dev_info.max_nb_queue_pairs + 1, 14117 test_enq_callback, NULL); 14118 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 14119 "cryptodev %u did not fail", 14120 dev_info.max_nb_queue_pairs + 1, 14121 ts_params->valid_devs[0]); 14122 14123 /* Test with NULL callback */ 14124 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 14125 qp_id, NULL, NULL); 14126 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 14127 "cryptodev %u did not fail", 14128 qp_id, ts_params->valid_devs[0]); 14129 14130 /* Test with valid configuration */ 14131 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 14132 qp_id, test_enq_callback, NULL); 14133 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 14134 "qp %u on cryptodev %u", 14135 qp_id, ts_params->valid_devs[0]); 14136 14137 rte_cryptodev_start(ts_params->valid_devs[0]); 14138 14139 /* Launch a thread */ 14140 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 14141 rte_get_next_lcore(-1, 1, 0)); 14142 14143 /* Wait until reader exited. */ 14144 rte_eal_mp_wait_lcore(); 14145 14146 /* Test with invalid crypto device */ 14147 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 14148 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 14149 "Expected call to fail as crypto device is invalid"); 14150 14151 /* Test with invalid queue pair */ 14152 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 14153 ts_params->valid_devs[0], 14154 dev_info.max_nb_queue_pairs + 1, cb), 14155 "Expected call to fail as queue pair is invalid"); 14156 14157 /* Test with NULL callback */ 14158 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 14159 ts_params->valid_devs[0], qp_id, NULL), 14160 "Expected call to fail as callback is NULL"); 14161 14162 /* Test with valid configuration */ 14163 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback( 14164 ts_params->valid_devs[0], qp_id, cb), 14165 "Failed test to remove callback on " 14166 "qp %u on cryptodev %u", 14167 qp_id, ts_params->valid_devs[0]); 14168 14169 return TEST_SUCCESS; 14170 } 14171 14172 static int 14173 test_deq_callback_setup(void) 14174 { 14175 struct crypto_testsuite_params *ts_params = &testsuite_params; 14176 struct rte_cryptodev_info dev_info; 14177 struct rte_cryptodev_qp_conf qp_conf = { 14178 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 14179 }; 14180 14181 struct rte_cryptodev_cb *cb; 14182 uint16_t qp_id = 0; 14183 14184 /* Stop the device in case it's started so it can be configured */ 14185 rte_cryptodev_stop(ts_params->valid_devs[0]); 14186 14187 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14188 14189 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 14190 &ts_params->conf), 14191 "Failed to configure cryptodev %u", 14192 ts_params->valid_devs[0]); 14193 14194 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 14195 qp_conf.mp_session = ts_params->session_mpool; 14196 14197 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 14198 ts_params->valid_devs[0], qp_id, &qp_conf, 14199 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 14200 "Failed test for " 14201 "rte_cryptodev_queue_pair_setup: num_inflights " 14202 "%u on qp %u on cryptodev %u", 14203 qp_conf.nb_descriptors, qp_id, 14204 ts_params->valid_devs[0]); 14205 14206 /* Test with invalid crypto device */ 14207 cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS, 14208 qp_id, test_deq_callback, NULL); 14209 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 14210 "cryptodev %u did not fail", 14211 qp_id, RTE_CRYPTO_MAX_DEVS); 14212 14213 /* Test with invalid queue pair */ 14214 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 14215 dev_info.max_nb_queue_pairs + 1, 14216 test_deq_callback, NULL); 14217 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 14218 "cryptodev %u did not fail", 14219 dev_info.max_nb_queue_pairs + 1, 14220 ts_params->valid_devs[0]); 14221 14222 /* Test with NULL callback */ 14223 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 14224 qp_id, NULL, NULL); 14225 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 14226 "cryptodev %u did not fail", 14227 qp_id, ts_params->valid_devs[0]); 14228 14229 /* Test with valid configuration */ 14230 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 14231 qp_id, test_deq_callback, NULL); 14232 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 14233 "qp %u on cryptodev %u", 14234 qp_id, ts_params->valid_devs[0]); 14235 14236 rte_cryptodev_start(ts_params->valid_devs[0]); 14237 14238 /* Launch a thread */ 14239 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 14240 rte_get_next_lcore(-1, 1, 0)); 14241 14242 /* Wait until reader exited. */ 14243 rte_eal_mp_wait_lcore(); 14244 14245 /* Test with invalid crypto device */ 14246 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 14247 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 14248 "Expected call to fail as crypto device is invalid"); 14249 14250 /* Test with invalid queue pair */ 14251 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 14252 ts_params->valid_devs[0], 14253 dev_info.max_nb_queue_pairs + 1, cb), 14254 "Expected call to fail as queue pair is invalid"); 14255 14256 /* Test with NULL callback */ 14257 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 14258 ts_params->valid_devs[0], qp_id, NULL), 14259 "Expected call to fail as callback is NULL"); 14260 14261 /* Test with valid configuration */ 14262 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback( 14263 ts_params->valid_devs[0], qp_id, cb), 14264 "Failed test to remove callback on " 14265 "qp %u on cryptodev %u", 14266 qp_id, ts_params->valid_devs[0]); 14267 14268 return TEST_SUCCESS; 14269 } 14270 14271 static void 14272 generate_gmac_large_plaintext(uint8_t *data) 14273 { 14274 uint16_t i; 14275 14276 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 14277 memcpy(&data[i], &data[0], 32); 14278 } 14279 14280 static int 14281 create_gmac_operation(enum rte_crypto_auth_operation op, 14282 const struct gmac_test_data *tdata) 14283 { 14284 struct crypto_testsuite_params *ts_params = &testsuite_params; 14285 struct crypto_unittest_params *ut_params = &unittest_params; 14286 struct rte_crypto_sym_op *sym_op; 14287 14288 uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 14289 14290 /* Generate Crypto op data structure */ 14291 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 14292 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 14293 TEST_ASSERT_NOT_NULL(ut_params->op, 14294 "Failed to allocate symmetric crypto operation struct"); 14295 14296 sym_op = ut_params->op->sym; 14297 14298 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 14299 ut_params->ibuf, tdata->gmac_tag.len); 14300 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 14301 "no room to append digest"); 14302 14303 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 14304 ut_params->ibuf, plaintext_pad_len); 14305 14306 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 14307 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 14308 tdata->gmac_tag.len); 14309 debug_hexdump(stdout, "digest:", 14310 sym_op->auth.digest.data, 14311 tdata->gmac_tag.len); 14312 } 14313 14314 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 14315 uint8_t *, IV_OFFSET); 14316 14317 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 14318 14319 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 14320 14321 sym_op->cipher.data.length = 0; 14322 sym_op->cipher.data.offset = 0; 14323 14324 sym_op->auth.data.offset = 0; 14325 sym_op->auth.data.length = tdata->plaintext.len; 14326 14327 return 0; 14328 } 14329 14330 static int 14331 create_gmac_operation_sgl(enum rte_crypto_auth_operation op, 14332 const struct gmac_test_data *tdata, 14333 void *digest_mem, uint64_t digest_phys) 14334 { 14335 struct crypto_testsuite_params *ts_params = &testsuite_params; 14336 struct crypto_unittest_params *ut_params = &unittest_params; 14337 struct rte_crypto_sym_op *sym_op; 14338 14339 /* Generate Crypto op data structure */ 14340 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 14341 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 14342 TEST_ASSERT_NOT_NULL(ut_params->op, 14343 "Failed to allocate symmetric crypto operation struct"); 14344 14345 sym_op = ut_params->op->sym; 14346 14347 sym_op->auth.digest.data = digest_mem; 14348 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 14349 "no room to append digest"); 14350 14351 sym_op->auth.digest.phys_addr = digest_phys; 14352 14353 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 14354 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 14355 tdata->gmac_tag.len); 14356 debug_hexdump(stdout, "digest:", 14357 sym_op->auth.digest.data, 14358 tdata->gmac_tag.len); 14359 } 14360 14361 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 14362 uint8_t *, IV_OFFSET); 14363 14364 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 14365 14366 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 14367 14368 sym_op->cipher.data.length = 0; 14369 sym_op->cipher.data.offset = 0; 14370 14371 sym_op->auth.data.offset = 0; 14372 sym_op->auth.data.length = tdata->plaintext.len; 14373 14374 return 0; 14375 } 14376 14377 static int create_gmac_session(uint8_t dev_id, 14378 const struct gmac_test_data *tdata, 14379 enum rte_crypto_auth_operation auth_op) 14380 { 14381 uint8_t auth_key[tdata->key.len]; 14382 14383 struct crypto_testsuite_params *ts_params = &testsuite_params; 14384 struct crypto_unittest_params *ut_params = &unittest_params; 14385 14386 memcpy(auth_key, tdata->key.data, tdata->key.len); 14387 14388 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14389 ut_params->auth_xform.next = NULL; 14390 14391 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 14392 ut_params->auth_xform.auth.op = auth_op; 14393 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 14394 ut_params->auth_xform.auth.key.length = tdata->key.len; 14395 ut_params->auth_xform.auth.key.data = auth_key; 14396 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 14397 ut_params->auth_xform.auth.iv.length = tdata->iv.len; 14398 14399 14400 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 14401 &ut_params->auth_xform, ts_params->session_mpool); 14402 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 14403 return TEST_SKIPPED; 14404 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 14405 14406 return 0; 14407 } 14408 14409 static int 14410 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 14411 { 14412 struct crypto_testsuite_params *ts_params = &testsuite_params; 14413 struct crypto_unittest_params *ut_params = &unittest_params; 14414 struct rte_cryptodev_info dev_info; 14415 14416 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14417 uint64_t feat_flags = dev_info.feature_flags; 14418 14419 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14420 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14421 printf("Device doesn't support RAW data-path APIs.\n"); 14422 return TEST_SKIPPED; 14423 } 14424 14425 int retval; 14426 14427 uint8_t *auth_tag, *plaintext; 14428 uint16_t plaintext_pad_len; 14429 14430 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 14431 "No GMAC length in the source data"); 14432 14433 /* Verify the capabilities */ 14434 struct rte_cryptodev_sym_capability_idx cap_idx; 14435 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14436 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 14437 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14438 &cap_idx) == NULL) 14439 return TEST_SKIPPED; 14440 14441 retval = create_gmac_session(ts_params->valid_devs[0], 14442 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 14443 14444 if (retval == TEST_SKIPPED) 14445 return TEST_SKIPPED; 14446 if (retval < 0) 14447 return retval; 14448 14449 if (tdata->plaintext.len > MBUF_SIZE) 14450 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 14451 else 14452 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14453 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14454 "Failed to allocate input buffer in mempool"); 14455 14456 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14457 rte_pktmbuf_tailroom(ut_params->ibuf)); 14458 14459 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 14460 /* 14461 * Runtime generate the large plain text instead of use hard code 14462 * plain text vector. It is done to avoid create huge source file 14463 * with the test vector. 14464 */ 14465 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 14466 generate_gmac_large_plaintext(tdata->plaintext.data); 14467 14468 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14469 plaintext_pad_len); 14470 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14471 14472 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 14473 debug_hexdump(stdout, "plaintext:", plaintext, 14474 tdata->plaintext.len); 14475 14476 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 14477 tdata); 14478 14479 if (retval < 0) 14480 return retval; 14481 14482 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14483 14484 ut_params->op->sym->m_src = ut_params->ibuf; 14485 14486 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14487 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14488 ut_params->op); 14489 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 14490 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 14491 0); 14492 if (retval != TEST_SUCCESS) 14493 return retval; 14494 } else 14495 TEST_ASSERT_NOT_NULL( 14496 process_crypto_request(ts_params->valid_devs[0], 14497 ut_params->op), "failed to process sym crypto op"); 14498 14499 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14500 "crypto op processing failed"); 14501 14502 if (ut_params->op->sym->m_dst) { 14503 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 14504 uint8_t *, plaintext_pad_len); 14505 } else { 14506 auth_tag = plaintext + plaintext_pad_len; 14507 } 14508 14509 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 14510 14511 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14512 auth_tag, 14513 tdata->gmac_tag.data, 14514 tdata->gmac_tag.len, 14515 "GMAC Generated auth tag not as expected"); 14516 14517 return 0; 14518 } 14519 14520 static int 14521 test_AES_GMAC_authentication_test_case_1(void) 14522 { 14523 return test_AES_GMAC_authentication(&gmac_test_case_1); 14524 } 14525 14526 static int 14527 test_AES_GMAC_authentication_test_case_2(void) 14528 { 14529 return test_AES_GMAC_authentication(&gmac_test_case_2); 14530 } 14531 14532 static int 14533 test_AES_GMAC_authentication_test_case_3(void) 14534 { 14535 return test_AES_GMAC_authentication(&gmac_test_case_3); 14536 } 14537 14538 static int 14539 test_AES_GMAC_authentication_test_case_4(void) 14540 { 14541 return test_AES_GMAC_authentication(&gmac_test_case_4); 14542 } 14543 14544 static int 14545 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 14546 { 14547 struct crypto_testsuite_params *ts_params = &testsuite_params; 14548 struct crypto_unittest_params *ut_params = &unittest_params; 14549 int retval; 14550 uint32_t plaintext_pad_len; 14551 uint8_t *plaintext; 14552 struct rte_cryptodev_info dev_info; 14553 14554 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14555 uint64_t feat_flags = dev_info.feature_flags; 14556 14557 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14558 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14559 printf("Device doesn't support RAW data-path APIs.\n"); 14560 return TEST_SKIPPED; 14561 } 14562 14563 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 14564 "No GMAC length in the source data"); 14565 14566 /* Verify the capabilities */ 14567 struct rte_cryptodev_sym_capability_idx cap_idx; 14568 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14569 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 14570 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14571 &cap_idx) == NULL) 14572 return TEST_SKIPPED; 14573 14574 retval = create_gmac_session(ts_params->valid_devs[0], 14575 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 14576 14577 if (retval == TEST_SKIPPED) 14578 return TEST_SKIPPED; 14579 if (retval < 0) 14580 return retval; 14581 14582 if (tdata->plaintext.len > MBUF_SIZE) 14583 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 14584 else 14585 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14586 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14587 "Failed to allocate input buffer in mempool"); 14588 14589 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14590 rte_pktmbuf_tailroom(ut_params->ibuf)); 14591 14592 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 14593 14594 /* 14595 * Runtime generate the large plain text instead of use hard code 14596 * plain text vector. It is done to avoid create huge source file 14597 * with the test vector. 14598 */ 14599 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 14600 generate_gmac_large_plaintext(tdata->plaintext.data); 14601 14602 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14603 plaintext_pad_len); 14604 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14605 14606 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 14607 debug_hexdump(stdout, "plaintext:", plaintext, 14608 tdata->plaintext.len); 14609 14610 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 14611 tdata); 14612 14613 if (retval < 0) 14614 return retval; 14615 14616 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14617 14618 ut_params->op->sym->m_src = ut_params->ibuf; 14619 14620 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14621 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14622 ut_params->op); 14623 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 14624 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 14625 0); 14626 if (retval != TEST_SUCCESS) 14627 return retval; 14628 } else 14629 TEST_ASSERT_NOT_NULL( 14630 process_crypto_request(ts_params->valid_devs[0], 14631 ut_params->op), "failed to process sym crypto op"); 14632 14633 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14634 "crypto op processing failed"); 14635 14636 return 0; 14637 14638 } 14639 14640 static int 14641 test_AES_GMAC_authentication_verify_test_case_1(void) 14642 { 14643 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 14644 } 14645 14646 static int 14647 test_AES_GMAC_authentication_verify_test_case_2(void) 14648 { 14649 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 14650 } 14651 14652 static int 14653 test_AES_GMAC_authentication_verify_test_case_3(void) 14654 { 14655 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 14656 } 14657 14658 static int 14659 test_AES_GMAC_authentication_verify_test_case_4(void) 14660 { 14661 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 14662 } 14663 14664 static int 14665 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata, 14666 uint32_t fragsz) 14667 { 14668 struct crypto_testsuite_params *ts_params = &testsuite_params; 14669 struct crypto_unittest_params *ut_params = &unittest_params; 14670 struct rte_cryptodev_info dev_info; 14671 uint64_t feature_flags; 14672 unsigned int trn_data = 0; 14673 void *digest_mem = NULL; 14674 uint32_t segs = 1; 14675 unsigned int to_trn = 0; 14676 struct rte_mbuf *buf = NULL; 14677 uint8_t *auth_tag, *plaintext; 14678 int retval; 14679 14680 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 14681 "No GMAC length in the source data"); 14682 14683 /* Verify the capabilities */ 14684 struct rte_cryptodev_sym_capability_idx cap_idx; 14685 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14686 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 14687 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14688 &cap_idx) == NULL) 14689 return TEST_SKIPPED; 14690 14691 /* Check for any input SGL support */ 14692 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14693 feature_flags = dev_info.feature_flags; 14694 14695 if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) || 14696 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) || 14697 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))) 14698 return TEST_SKIPPED; 14699 14700 if (fragsz > tdata->plaintext.len) 14701 fragsz = tdata->plaintext.len; 14702 14703 uint16_t plaintext_len = fragsz; 14704 14705 retval = create_gmac_session(ts_params->valid_devs[0], 14706 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 14707 14708 if (retval == TEST_SKIPPED) 14709 return TEST_SKIPPED; 14710 if (retval < 0) 14711 return retval; 14712 14713 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14714 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14715 "Failed to allocate input buffer in mempool"); 14716 14717 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14718 rte_pktmbuf_tailroom(ut_params->ibuf)); 14719 14720 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14721 plaintext_len); 14722 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14723 14724 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 14725 14726 trn_data += plaintext_len; 14727 14728 buf = ut_params->ibuf; 14729 14730 /* 14731 * Loop until no more fragments 14732 */ 14733 14734 while (trn_data < tdata->plaintext.len) { 14735 ++segs; 14736 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 14737 (tdata->plaintext.len - trn_data) : fragsz; 14738 14739 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14740 buf = buf->next; 14741 14742 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 14743 rte_pktmbuf_tailroom(buf)); 14744 14745 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 14746 to_trn); 14747 14748 memcpy(plaintext, tdata->plaintext.data + trn_data, 14749 to_trn); 14750 trn_data += to_trn; 14751 if (trn_data == tdata->plaintext.len) 14752 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 14753 tdata->gmac_tag.len); 14754 } 14755 ut_params->ibuf->nb_segs = segs; 14756 14757 /* 14758 * Place digest at the end of the last buffer 14759 */ 14760 uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn; 14761 14762 if (!digest_mem) { 14763 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14764 + tdata->gmac_tag.len); 14765 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 14766 tdata->plaintext.len); 14767 } 14768 14769 retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE, 14770 tdata, digest_mem, digest_phys); 14771 14772 if (retval < 0) 14773 return retval; 14774 14775 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14776 14777 ut_params->op->sym->m_src = ut_params->ibuf; 14778 14779 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14780 return TEST_SKIPPED; 14781 14782 TEST_ASSERT_NOT_NULL( 14783 process_crypto_request(ts_params->valid_devs[0], 14784 ut_params->op), "failed to process sym crypto op"); 14785 14786 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14787 "crypto op processing failed"); 14788 14789 auth_tag = digest_mem; 14790 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 14791 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14792 auth_tag, 14793 tdata->gmac_tag.data, 14794 tdata->gmac_tag.len, 14795 "GMAC Generated auth tag not as expected"); 14796 14797 return 0; 14798 } 14799 14800 /* Segment size not multiple of block size (16B) */ 14801 static int 14802 test_AES_GMAC_authentication_SGL_40B(void) 14803 { 14804 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40); 14805 } 14806 14807 static int 14808 test_AES_GMAC_authentication_SGL_80B(void) 14809 { 14810 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80); 14811 } 14812 14813 static int 14814 test_AES_GMAC_authentication_SGL_2048B(void) 14815 { 14816 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048); 14817 } 14818 14819 /* Segment size not multiple of block size (16B) */ 14820 static int 14821 test_AES_GMAC_authentication_SGL_2047B(void) 14822 { 14823 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047); 14824 } 14825 14826 struct test_crypto_vector { 14827 enum rte_crypto_cipher_algorithm crypto_algo; 14828 unsigned int cipher_offset; 14829 unsigned int cipher_len; 14830 14831 struct { 14832 uint8_t data[64]; 14833 unsigned int len; 14834 } cipher_key; 14835 14836 struct { 14837 uint8_t data[64]; 14838 unsigned int len; 14839 } iv; 14840 14841 struct { 14842 const uint8_t *data; 14843 unsigned int len; 14844 } plaintext; 14845 14846 struct { 14847 const uint8_t *data; 14848 unsigned int len; 14849 } ciphertext; 14850 14851 enum rte_crypto_auth_algorithm auth_algo; 14852 unsigned int auth_offset; 14853 14854 struct { 14855 uint8_t data[128]; 14856 unsigned int len; 14857 } auth_key; 14858 14859 struct { 14860 const uint8_t *data; 14861 unsigned int len; 14862 } aad; 14863 14864 struct { 14865 uint8_t data[128]; 14866 unsigned int len; 14867 } digest; 14868 }; 14869 14870 static const struct test_crypto_vector 14871 hmac_sha1_test_crypto_vector = { 14872 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 14873 .plaintext = { 14874 .data = plaintext_hash, 14875 .len = 512 14876 }, 14877 .auth_key = { 14878 .data = { 14879 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 14880 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 14881 0xDE, 0xF4, 0xDE, 0xAD 14882 }, 14883 .len = 20 14884 }, 14885 .digest = { 14886 .data = { 14887 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 14888 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 14889 0x3F, 0x91, 0x64, 0x59 14890 }, 14891 .len = 20 14892 } 14893 }; 14894 14895 static const struct test_crypto_vector 14896 aes128_gmac_test_vector = { 14897 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 14898 .plaintext = { 14899 .data = plaintext_hash, 14900 .len = 512 14901 }, 14902 .iv = { 14903 .data = { 14904 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 14905 0x08, 0x09, 0x0A, 0x0B 14906 }, 14907 .len = 12 14908 }, 14909 .auth_key = { 14910 .data = { 14911 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 14912 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 14913 }, 14914 .len = 16 14915 }, 14916 .digest = { 14917 .data = { 14918 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 14919 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 14920 }, 14921 .len = 16 14922 } 14923 }; 14924 14925 static const struct test_crypto_vector 14926 aes128cbc_hmac_sha1_test_vector = { 14927 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 14928 .cipher_offset = 0, 14929 .cipher_len = 512, 14930 .cipher_key = { 14931 .data = { 14932 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 14933 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 14934 }, 14935 .len = 16 14936 }, 14937 .iv = { 14938 .data = { 14939 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 14940 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 14941 }, 14942 .len = 16 14943 }, 14944 .plaintext = { 14945 .data = plaintext_hash, 14946 .len = 512 14947 }, 14948 .ciphertext = { 14949 .data = ciphertext512_aes128cbc, 14950 .len = 512 14951 }, 14952 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 14953 .auth_offset = 0, 14954 .auth_key = { 14955 .data = { 14956 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 14957 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 14958 0xDE, 0xF4, 0xDE, 0xAD 14959 }, 14960 .len = 20 14961 }, 14962 .digest = { 14963 .data = { 14964 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 14965 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 14966 0x18, 0x8C, 0x1D, 0x32 14967 }, 14968 .len = 20 14969 } 14970 }; 14971 14972 static const struct test_crypto_vector 14973 aes128cbc_hmac_sha1_aad_test_vector = { 14974 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 14975 .cipher_offset = 8, 14976 .cipher_len = 496, 14977 .cipher_key = { 14978 .data = { 14979 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 14980 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 14981 }, 14982 .len = 16 14983 }, 14984 .iv = { 14985 .data = { 14986 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 14987 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 14988 }, 14989 .len = 16 14990 }, 14991 .plaintext = { 14992 .data = plaintext_hash, 14993 .len = 512 14994 }, 14995 .ciphertext = { 14996 .data = ciphertext512_aes128cbc_aad, 14997 .len = 512 14998 }, 14999 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 15000 .auth_offset = 0, 15001 .auth_key = { 15002 .data = { 15003 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 15004 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 15005 0xDE, 0xF4, 0xDE, 0xAD 15006 }, 15007 .len = 20 15008 }, 15009 .digest = { 15010 .data = { 15011 0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F, 15012 0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B, 15013 0x62, 0x0F, 0xFB, 0x10 15014 }, 15015 .len = 20 15016 } 15017 }; 15018 15019 static void 15020 data_corruption(uint8_t *data) 15021 { 15022 data[0] += 1; 15023 } 15024 15025 static void 15026 tag_corruption(uint8_t *data, unsigned int tag_offset) 15027 { 15028 data[tag_offset] += 1; 15029 } 15030 15031 static int 15032 create_auth_session(struct crypto_unittest_params *ut_params, 15033 uint8_t dev_id, 15034 const struct test_crypto_vector *reference, 15035 enum rte_crypto_auth_operation auth_op) 15036 { 15037 struct crypto_testsuite_params *ts_params = &testsuite_params; 15038 uint8_t auth_key[reference->auth_key.len + 1]; 15039 15040 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 15041 15042 /* Setup Authentication Parameters */ 15043 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15044 ut_params->auth_xform.auth.op = auth_op; 15045 ut_params->auth_xform.next = NULL; 15046 ut_params->auth_xform.auth.algo = reference->auth_algo; 15047 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 15048 ut_params->auth_xform.auth.key.data = auth_key; 15049 ut_params->auth_xform.auth.digest_length = reference->digest.len; 15050 15051 /* Create Crypto session*/ 15052 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 15053 &ut_params->auth_xform, 15054 ts_params->session_mpool); 15055 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 15056 return TEST_SKIPPED; 15057 15058 return 0; 15059 } 15060 15061 static int 15062 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 15063 uint8_t dev_id, 15064 const struct test_crypto_vector *reference, 15065 enum rte_crypto_auth_operation auth_op, 15066 enum rte_crypto_cipher_operation cipher_op) 15067 { 15068 struct crypto_testsuite_params *ts_params = &testsuite_params; 15069 uint8_t cipher_key[reference->cipher_key.len + 1]; 15070 uint8_t auth_key[reference->auth_key.len + 1]; 15071 15072 memcpy(cipher_key, reference->cipher_key.data, 15073 reference->cipher_key.len); 15074 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 15075 15076 /* Setup Authentication Parameters */ 15077 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15078 ut_params->auth_xform.auth.op = auth_op; 15079 ut_params->auth_xform.auth.algo = reference->auth_algo; 15080 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 15081 ut_params->auth_xform.auth.key.data = auth_key; 15082 ut_params->auth_xform.auth.digest_length = reference->digest.len; 15083 15084 if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) { 15085 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 15086 ut_params->auth_xform.auth.iv.length = reference->iv.len; 15087 } else { 15088 ut_params->auth_xform.next = &ut_params->cipher_xform; 15089 15090 /* Setup Cipher Parameters */ 15091 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15092 ut_params->cipher_xform.next = NULL; 15093 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 15094 ut_params->cipher_xform.cipher.op = cipher_op; 15095 ut_params->cipher_xform.cipher.key.data = cipher_key; 15096 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 15097 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 15098 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 15099 } 15100 15101 /* Create Crypto session*/ 15102 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 15103 &ut_params->auth_xform, 15104 ts_params->session_mpool); 15105 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 15106 return TEST_SKIPPED; 15107 15108 return 0; 15109 } 15110 15111 static int 15112 create_auth_operation(struct crypto_testsuite_params *ts_params, 15113 struct crypto_unittest_params *ut_params, 15114 const struct test_crypto_vector *reference, 15115 unsigned int auth_generate) 15116 { 15117 /* Generate Crypto op data structure */ 15118 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 15119 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 15120 TEST_ASSERT_NOT_NULL(ut_params->op, 15121 "Failed to allocate pktmbuf offload"); 15122 15123 /* Set crypto operation data parameters */ 15124 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 15125 15126 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 15127 15128 /* set crypto operation source mbuf */ 15129 sym_op->m_src = ut_params->ibuf; 15130 15131 /* digest */ 15132 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 15133 ut_params->ibuf, reference->digest.len); 15134 15135 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 15136 "no room to append auth tag"); 15137 15138 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 15139 ut_params->ibuf, reference->plaintext.len); 15140 15141 if (auth_generate) 15142 memset(sym_op->auth.digest.data, 0, reference->digest.len); 15143 else 15144 memcpy(sym_op->auth.digest.data, 15145 reference->digest.data, 15146 reference->digest.len); 15147 15148 debug_hexdump(stdout, "digest:", 15149 sym_op->auth.digest.data, 15150 reference->digest.len); 15151 15152 sym_op->auth.data.length = reference->plaintext.len; 15153 sym_op->auth.data.offset = 0; 15154 15155 return 0; 15156 } 15157 15158 static int 15159 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 15160 struct crypto_unittest_params *ut_params, 15161 const struct test_crypto_vector *reference, 15162 unsigned int auth_generate) 15163 { 15164 /* Generate Crypto op data structure */ 15165 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 15166 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 15167 TEST_ASSERT_NOT_NULL(ut_params->op, 15168 "Failed to allocate pktmbuf offload"); 15169 15170 /* Set crypto operation data parameters */ 15171 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 15172 15173 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 15174 15175 /* set crypto operation source mbuf */ 15176 sym_op->m_src = ut_params->ibuf; 15177 15178 /* digest */ 15179 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 15180 ut_params->ibuf, reference->digest.len); 15181 15182 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 15183 "no room to append auth tag"); 15184 15185 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 15186 ut_params->ibuf, reference->ciphertext.len); 15187 15188 if (auth_generate) 15189 memset(sym_op->auth.digest.data, 0, reference->digest.len); 15190 else 15191 memcpy(sym_op->auth.digest.data, 15192 reference->digest.data, 15193 reference->digest.len); 15194 15195 debug_hexdump(stdout, "digest:", 15196 sym_op->auth.digest.data, 15197 reference->digest.len); 15198 15199 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 15200 reference->iv.data, reference->iv.len); 15201 15202 sym_op->cipher.data.length = 0; 15203 sym_op->cipher.data.offset = 0; 15204 15205 sym_op->auth.data.length = reference->plaintext.len; 15206 sym_op->auth.data.offset = 0; 15207 15208 return 0; 15209 } 15210 15211 static int 15212 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 15213 struct crypto_unittest_params *ut_params, 15214 const struct test_crypto_vector *reference, 15215 unsigned int auth_generate) 15216 { 15217 /* Generate Crypto op data structure */ 15218 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 15219 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 15220 TEST_ASSERT_NOT_NULL(ut_params->op, 15221 "Failed to allocate pktmbuf offload"); 15222 15223 /* Set crypto operation data parameters */ 15224 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 15225 15226 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 15227 15228 /* set crypto operation source mbuf */ 15229 sym_op->m_src = ut_params->ibuf; 15230 15231 /* digest */ 15232 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 15233 ut_params->ibuf, reference->digest.len); 15234 15235 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 15236 "no room to append auth tag"); 15237 15238 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 15239 ut_params->ibuf, reference->ciphertext.len); 15240 15241 if (auth_generate) 15242 memset(sym_op->auth.digest.data, 0, reference->digest.len); 15243 else 15244 memcpy(sym_op->auth.digest.data, 15245 reference->digest.data, 15246 reference->digest.len); 15247 15248 debug_hexdump(stdout, "digest:", 15249 sym_op->auth.digest.data, 15250 reference->digest.len); 15251 15252 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 15253 reference->iv.data, reference->iv.len); 15254 15255 sym_op->cipher.data.length = reference->cipher_len; 15256 sym_op->cipher.data.offset = reference->cipher_offset; 15257 15258 sym_op->auth.data.length = reference->plaintext.len; 15259 sym_op->auth.data.offset = reference->auth_offset; 15260 15261 return 0; 15262 } 15263 15264 static int 15265 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 15266 struct crypto_unittest_params *ut_params, 15267 const struct test_crypto_vector *reference) 15268 { 15269 return create_auth_operation(ts_params, ut_params, reference, 0); 15270 } 15271 15272 static int 15273 create_auth_verify_GMAC_operation( 15274 struct crypto_testsuite_params *ts_params, 15275 struct crypto_unittest_params *ut_params, 15276 const struct test_crypto_vector *reference) 15277 { 15278 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 15279 } 15280 15281 static int 15282 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params, 15283 struct crypto_unittest_params *ut_params, 15284 const struct test_crypto_vector *reference) 15285 { 15286 return create_cipher_auth_operation(ts_params, ut_params, reference, 0); 15287 } 15288 15289 static int 15290 test_authentication_verify_fail_when_data_corruption( 15291 struct crypto_testsuite_params *ts_params, 15292 struct crypto_unittest_params *ut_params, 15293 const struct test_crypto_vector *reference, 15294 unsigned int data_corrupted) 15295 { 15296 int retval; 15297 15298 uint8_t *plaintext; 15299 struct rte_cryptodev_info dev_info; 15300 15301 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15302 uint64_t feat_flags = dev_info.feature_flags; 15303 15304 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15305 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15306 printf("Device doesn't support RAW data-path APIs.\n"); 15307 return TEST_SKIPPED; 15308 } 15309 15310 /* Verify the capabilities */ 15311 struct rte_cryptodev_sym_capability_idx cap_idx; 15312 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15313 cap_idx.algo.auth = reference->auth_algo; 15314 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15315 &cap_idx) == NULL) 15316 return TEST_SKIPPED; 15317 15318 15319 /* Create session */ 15320 retval = create_auth_session(ut_params, 15321 ts_params->valid_devs[0], 15322 reference, 15323 RTE_CRYPTO_AUTH_OP_VERIFY); 15324 15325 if (retval == TEST_SKIPPED) 15326 return TEST_SKIPPED; 15327 if (retval < 0) 15328 return retval; 15329 15330 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15331 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 15332 "Failed to allocate input buffer in mempool"); 15333 15334 /* clear mbuf payload */ 15335 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15336 rte_pktmbuf_tailroom(ut_params->ibuf)); 15337 15338 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15339 reference->plaintext.len); 15340 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 15341 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 15342 15343 debug_hexdump(stdout, "plaintext:", plaintext, 15344 reference->plaintext.len); 15345 15346 /* Create operation */ 15347 retval = create_auth_verify_operation(ts_params, ut_params, reference); 15348 15349 if (retval < 0) 15350 return retval; 15351 15352 if (data_corrupted) 15353 data_corruption(plaintext); 15354 else 15355 tag_corruption(plaintext, reference->plaintext.len); 15356 15357 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 15358 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 15359 ut_params->op); 15360 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 15361 RTE_CRYPTO_OP_STATUS_SUCCESS, 15362 "authentication not failed"); 15363 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15364 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 15365 0); 15366 if (retval != TEST_SUCCESS) 15367 return retval; 15368 } else { 15369 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 15370 ut_params->op); 15371 } 15372 if (ut_params->op == NULL) 15373 return 0; 15374 else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) 15375 return 0; 15376 15377 return -1; 15378 } 15379 15380 static int 15381 test_authentication_verify_GMAC_fail_when_corruption( 15382 struct crypto_testsuite_params *ts_params, 15383 struct crypto_unittest_params *ut_params, 15384 const struct test_crypto_vector *reference, 15385 unsigned int data_corrupted) 15386 { 15387 int retval; 15388 uint8_t *plaintext; 15389 struct rte_cryptodev_info dev_info; 15390 15391 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15392 uint64_t feat_flags = dev_info.feature_flags; 15393 15394 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15395 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15396 printf("Device doesn't support RAW data-path APIs.\n"); 15397 return TEST_SKIPPED; 15398 } 15399 15400 /* Verify the capabilities */ 15401 struct rte_cryptodev_sym_capability_idx cap_idx; 15402 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15403 cap_idx.algo.auth = reference->auth_algo; 15404 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15405 &cap_idx) == NULL) 15406 return TEST_SKIPPED; 15407 15408 /* Create session */ 15409 retval = create_auth_cipher_session(ut_params, 15410 ts_params->valid_devs[0], 15411 reference, 15412 RTE_CRYPTO_AUTH_OP_VERIFY, 15413 RTE_CRYPTO_CIPHER_OP_DECRYPT); 15414 if (retval == TEST_SKIPPED) 15415 return TEST_SKIPPED; 15416 if (retval < 0) 15417 return retval; 15418 15419 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15420 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 15421 "Failed to allocate input buffer in mempool"); 15422 15423 /* clear mbuf payload */ 15424 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15425 rte_pktmbuf_tailroom(ut_params->ibuf)); 15426 15427 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15428 reference->plaintext.len); 15429 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 15430 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 15431 15432 debug_hexdump(stdout, "plaintext:", plaintext, 15433 reference->plaintext.len); 15434 15435 /* Create operation */ 15436 retval = create_auth_verify_GMAC_operation(ts_params, 15437 ut_params, 15438 reference); 15439 15440 if (retval < 0) 15441 return retval; 15442 15443 if (data_corrupted) 15444 data_corruption(plaintext); 15445 else 15446 tag_corruption(plaintext, reference->aad.len); 15447 15448 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 15449 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 15450 ut_params->op); 15451 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 15452 RTE_CRYPTO_OP_STATUS_SUCCESS, 15453 "authentication not failed"); 15454 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15455 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 15456 0); 15457 if (retval != TEST_SUCCESS) 15458 return retval; 15459 } else { 15460 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 15461 ut_params->op); 15462 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 15463 } 15464 15465 return 0; 15466 } 15467 15468 static int 15469 test_authenticated_decryption_fail_when_corruption( 15470 struct crypto_testsuite_params *ts_params, 15471 struct crypto_unittest_params *ut_params, 15472 const struct test_crypto_vector *reference, 15473 unsigned int data_corrupted) 15474 { 15475 int retval; 15476 15477 uint8_t *ciphertext; 15478 struct rte_cryptodev_info dev_info; 15479 15480 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15481 uint64_t feat_flags = dev_info.feature_flags; 15482 15483 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15484 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15485 printf("Device doesn't support RAW data-path APIs.\n"); 15486 return TEST_SKIPPED; 15487 } 15488 15489 /* Verify the capabilities */ 15490 struct rte_cryptodev_sym_capability_idx cap_idx; 15491 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15492 cap_idx.algo.auth = reference->auth_algo; 15493 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15494 &cap_idx) == NULL) 15495 return TEST_SKIPPED; 15496 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15497 cap_idx.algo.cipher = reference->crypto_algo; 15498 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15499 &cap_idx) == NULL) 15500 return TEST_SKIPPED; 15501 15502 /* Create session */ 15503 retval = create_auth_cipher_session(ut_params, 15504 ts_params->valid_devs[0], 15505 reference, 15506 RTE_CRYPTO_AUTH_OP_VERIFY, 15507 RTE_CRYPTO_CIPHER_OP_DECRYPT); 15508 if (retval == TEST_SKIPPED) 15509 return TEST_SKIPPED; 15510 if (retval < 0) 15511 return retval; 15512 15513 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15514 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 15515 "Failed to allocate input buffer in mempool"); 15516 15517 /* clear mbuf payload */ 15518 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15519 rte_pktmbuf_tailroom(ut_params->ibuf)); 15520 15521 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15522 reference->ciphertext.len); 15523 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 15524 memcpy(ciphertext, reference->ciphertext.data, 15525 reference->ciphertext.len); 15526 15527 /* Create operation */ 15528 retval = create_cipher_auth_verify_operation(ts_params, 15529 ut_params, 15530 reference); 15531 15532 if (retval < 0) 15533 return retval; 15534 15535 if (data_corrupted) 15536 data_corruption(ciphertext); 15537 else 15538 tag_corruption(ciphertext, reference->ciphertext.len); 15539 15540 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 15541 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 15542 ut_params->op); 15543 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 15544 RTE_CRYPTO_OP_STATUS_SUCCESS, 15545 "authentication not failed"); 15546 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15547 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 15548 0); 15549 if (retval != TEST_SUCCESS) 15550 return retval; 15551 } else { 15552 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 15553 ut_params->op); 15554 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 15555 } 15556 15557 return 0; 15558 } 15559 15560 static int 15561 test_authenticated_encrypt_with_esn( 15562 struct crypto_testsuite_params *ts_params, 15563 struct crypto_unittest_params *ut_params, 15564 const struct test_crypto_vector *reference) 15565 { 15566 int retval; 15567 15568 uint8_t *authciphertext, *plaintext, *auth_tag; 15569 uint16_t plaintext_pad_len; 15570 uint8_t cipher_key[reference->cipher_key.len + 1]; 15571 uint8_t auth_key[reference->auth_key.len + 1]; 15572 struct rte_cryptodev_info dev_info; 15573 15574 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15575 uint64_t feat_flags = dev_info.feature_flags; 15576 15577 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15578 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15579 printf("Device doesn't support RAW data-path APIs.\n"); 15580 return TEST_SKIPPED; 15581 } 15582 15583 /* Verify the capabilities */ 15584 struct rte_cryptodev_sym_capability_idx cap_idx; 15585 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15586 cap_idx.algo.auth = reference->auth_algo; 15587 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15588 &cap_idx) == NULL) 15589 return TEST_SKIPPED; 15590 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15591 cap_idx.algo.cipher = reference->crypto_algo; 15592 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15593 &cap_idx) == NULL) 15594 return TEST_SKIPPED; 15595 15596 /* Create session */ 15597 memcpy(cipher_key, reference->cipher_key.data, 15598 reference->cipher_key.len); 15599 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 15600 15601 /* Setup Cipher Parameters */ 15602 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15603 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 15604 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 15605 ut_params->cipher_xform.cipher.key.data = cipher_key; 15606 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 15607 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 15608 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 15609 15610 ut_params->cipher_xform.next = &ut_params->auth_xform; 15611 15612 /* Setup Authentication Parameters */ 15613 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15614 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 15615 ut_params->auth_xform.auth.algo = reference->auth_algo; 15616 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 15617 ut_params->auth_xform.auth.key.data = auth_key; 15618 ut_params->auth_xform.auth.digest_length = reference->digest.len; 15619 ut_params->auth_xform.next = NULL; 15620 15621 /* Create Crypto session*/ 15622 ut_params->sess = rte_cryptodev_sym_session_create( 15623 ts_params->valid_devs[0], &ut_params->cipher_xform, 15624 ts_params->session_mpool); 15625 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 15626 return TEST_SKIPPED; 15627 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 15628 15629 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15630 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 15631 "Failed to allocate input buffer in mempool"); 15632 15633 /* clear mbuf payload */ 15634 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15635 rte_pktmbuf_tailroom(ut_params->ibuf)); 15636 15637 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15638 reference->plaintext.len); 15639 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 15640 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 15641 15642 /* Create operation */ 15643 retval = create_cipher_auth_operation(ts_params, 15644 ut_params, 15645 reference, 0); 15646 15647 if (retval < 0) 15648 return retval; 15649 15650 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 15651 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 15652 ut_params->op); 15653 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15654 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 15655 0); 15656 if (retval != TEST_SUCCESS) 15657 return retval; 15658 } else 15659 ut_params->op = process_crypto_request( 15660 ts_params->valid_devs[0], ut_params->op); 15661 15662 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 15663 15664 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 15665 "crypto op processing failed"); 15666 15667 plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16); 15668 15669 authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 15670 ut_params->op->sym->auth.data.offset); 15671 auth_tag = authciphertext + plaintext_pad_len; 15672 debug_hexdump(stdout, "ciphertext:", authciphertext, 15673 reference->ciphertext.len); 15674 debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len); 15675 15676 /* Validate obuf */ 15677 TEST_ASSERT_BUFFERS_ARE_EQUAL( 15678 authciphertext, 15679 reference->ciphertext.data, 15680 reference->ciphertext.len, 15681 "Ciphertext data not as expected"); 15682 15683 TEST_ASSERT_BUFFERS_ARE_EQUAL( 15684 auth_tag, 15685 reference->digest.data, 15686 reference->digest.len, 15687 "Generated digest not as expected"); 15688 15689 return TEST_SUCCESS; 15690 15691 } 15692 15693 static int 15694 test_authenticated_decrypt_with_esn( 15695 struct crypto_testsuite_params *ts_params, 15696 struct crypto_unittest_params *ut_params, 15697 const struct test_crypto_vector *reference) 15698 { 15699 int retval; 15700 15701 uint8_t *ciphertext; 15702 uint8_t cipher_key[reference->cipher_key.len + 1]; 15703 uint8_t auth_key[reference->auth_key.len + 1]; 15704 struct rte_cryptodev_info dev_info; 15705 15706 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15707 uint64_t feat_flags = dev_info.feature_flags; 15708 15709 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15710 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15711 printf("Device doesn't support RAW data-path APIs.\n"); 15712 return TEST_SKIPPED; 15713 } 15714 15715 /* Verify the capabilities */ 15716 struct rte_cryptodev_sym_capability_idx cap_idx; 15717 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15718 cap_idx.algo.auth = reference->auth_algo; 15719 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15720 &cap_idx) == NULL) 15721 return TEST_SKIPPED; 15722 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15723 cap_idx.algo.cipher = reference->crypto_algo; 15724 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15725 &cap_idx) == NULL) 15726 return TEST_SKIPPED; 15727 15728 /* Create session */ 15729 memcpy(cipher_key, reference->cipher_key.data, 15730 reference->cipher_key.len); 15731 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 15732 15733 /* Setup Authentication Parameters */ 15734 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15735 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 15736 ut_params->auth_xform.auth.algo = reference->auth_algo; 15737 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 15738 ut_params->auth_xform.auth.key.data = auth_key; 15739 ut_params->auth_xform.auth.digest_length = reference->digest.len; 15740 ut_params->auth_xform.next = &ut_params->cipher_xform; 15741 15742 /* Setup Cipher Parameters */ 15743 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15744 ut_params->cipher_xform.next = NULL; 15745 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 15746 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 15747 ut_params->cipher_xform.cipher.key.data = cipher_key; 15748 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 15749 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 15750 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 15751 15752 /* Create Crypto session*/ 15753 ut_params->sess = rte_cryptodev_sym_session_create( 15754 ts_params->valid_devs[0], &ut_params->auth_xform, 15755 ts_params->session_mpool); 15756 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 15757 return TEST_SKIPPED; 15758 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 15759 15760 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15761 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 15762 "Failed to allocate input buffer in mempool"); 15763 15764 /* clear mbuf payload */ 15765 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15766 rte_pktmbuf_tailroom(ut_params->ibuf)); 15767 15768 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15769 reference->ciphertext.len); 15770 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 15771 memcpy(ciphertext, reference->ciphertext.data, 15772 reference->ciphertext.len); 15773 15774 /* Create operation */ 15775 retval = create_cipher_auth_verify_operation(ts_params, 15776 ut_params, 15777 reference); 15778 15779 if (retval < 0) 15780 return retval; 15781 15782 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 15783 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 15784 ut_params->op); 15785 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15786 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 15787 0); 15788 if (retval != TEST_SUCCESS) 15789 return retval; 15790 } else 15791 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 15792 ut_params->op); 15793 15794 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 15795 TEST_ASSERT_EQUAL(ut_params->op->status, 15796 RTE_CRYPTO_OP_STATUS_SUCCESS, 15797 "crypto op processing passed"); 15798 15799 ut_params->obuf = ut_params->op->sym->m_src; 15800 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 15801 15802 return 0; 15803 } 15804 15805 static int 15806 create_aead_operation_SGL(enum rte_crypto_aead_operation op, 15807 const struct aead_test_data *tdata, 15808 void *digest_mem, uint64_t digest_phys) 15809 { 15810 struct crypto_testsuite_params *ts_params = &testsuite_params; 15811 struct crypto_unittest_params *ut_params = &unittest_params; 15812 15813 const unsigned int auth_tag_len = tdata->auth_tag.len; 15814 const unsigned int iv_len = tdata->iv.len; 15815 unsigned int aad_len = tdata->aad.len; 15816 unsigned int aad_len_pad = 0; 15817 15818 /* Generate Crypto op data structure */ 15819 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 15820 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 15821 TEST_ASSERT_NOT_NULL(ut_params->op, 15822 "Failed to allocate symmetric crypto operation struct"); 15823 15824 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 15825 15826 sym_op->aead.digest.data = digest_mem; 15827 15828 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 15829 "no room to append digest"); 15830 15831 sym_op->aead.digest.phys_addr = digest_phys; 15832 15833 if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) { 15834 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 15835 auth_tag_len); 15836 debug_hexdump(stdout, "digest:", 15837 sym_op->aead.digest.data, 15838 auth_tag_len); 15839 } 15840 15841 /* Append aad data */ 15842 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 15843 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 15844 uint8_t *, IV_OFFSET); 15845 15846 /* Copy IV 1 byte after the IV pointer, according to the API */ 15847 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len); 15848 15849 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16); 15850 15851 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 15852 ut_params->ibuf, aad_len); 15853 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 15854 "no room to prepend aad"); 15855 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 15856 ut_params->ibuf); 15857 15858 memset(sym_op->aead.aad.data, 0, aad_len); 15859 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 15860 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 15861 15862 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 15863 debug_hexdump(stdout, "aad:", 15864 sym_op->aead.aad.data, aad_len); 15865 } else { 15866 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 15867 uint8_t *, IV_OFFSET); 15868 15869 rte_memcpy(iv_ptr, tdata->iv.data, iv_len); 15870 15871 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16); 15872 15873 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 15874 ut_params->ibuf, aad_len_pad); 15875 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 15876 "no room to prepend aad"); 15877 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 15878 ut_params->ibuf); 15879 15880 memset(sym_op->aead.aad.data, 0, aad_len); 15881 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 15882 15883 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 15884 debug_hexdump(stdout, "aad:", 15885 sym_op->aead.aad.data, aad_len); 15886 } 15887 15888 sym_op->aead.data.length = tdata->plaintext.len; 15889 sym_op->aead.data.offset = aad_len_pad; 15890 15891 return 0; 15892 } 15893 15894 #define SGL_MAX_NO 16 15895 15896 static int 15897 test_authenticated_encryption_SGL(const struct aead_test_data *tdata, 15898 const int oop, uint32_t fragsz, uint32_t fragsz_oop) 15899 { 15900 struct crypto_testsuite_params *ts_params = &testsuite_params; 15901 struct crypto_unittest_params *ut_params = &unittest_params; 15902 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL; 15903 int retval; 15904 int to_trn = 0; 15905 int to_trn_tbl[SGL_MAX_NO]; 15906 int segs = 1; 15907 unsigned int trn_data = 0; 15908 uint8_t *plaintext, *ciphertext, *auth_tag; 15909 struct rte_cryptodev_info dev_info; 15910 15911 /* Verify the capabilities */ 15912 struct rte_cryptodev_sym_capability_idx cap_idx; 15913 const struct rte_cryptodev_symmetric_capability *capability; 15914 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 15915 cap_idx.algo.aead = tdata->algo; 15916 capability = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], &cap_idx); 15917 if (capability == NULL) 15918 return TEST_SKIPPED; 15919 if (rte_cryptodev_sym_capability_check_aead(capability, tdata->key.len, 15920 tdata->auth_tag.len, tdata->aad.len, tdata->iv.len)) 15921 return TEST_SKIPPED; 15922 15923 /* 15924 * SGL not supported on AESNI_MB PMD CPU crypto, 15925 * OOP not supported on AESNI_GCM CPU crypto 15926 */ 15927 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO && 15928 (gbl_driver_id == rte_cryptodev_driver_id_get( 15929 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) || oop)) 15930 return TEST_SKIPPED; 15931 15932 /* Detailed check for the particular SGL support flag */ 15933 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15934 if (!oop) { 15935 unsigned int sgl_in = fragsz < tdata->plaintext.len; 15936 if (sgl_in && (!(dev_info.feature_flags & 15937 RTE_CRYPTODEV_FF_IN_PLACE_SGL))) 15938 return TEST_SKIPPED; 15939 15940 uint64_t feat_flags = dev_info.feature_flags; 15941 15942 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15943 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15944 printf("Device doesn't support RAW data-path APIs.\n"); 15945 return TEST_SKIPPED; 15946 } 15947 } else { 15948 unsigned int sgl_in = fragsz < tdata->plaintext.len; 15949 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) < 15950 tdata->plaintext.len; 15951 /* Raw data path API does not support OOP */ 15952 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 15953 return TEST_SKIPPED; 15954 if (sgl_in && !sgl_out) { 15955 if (!(dev_info.feature_flags & 15956 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) 15957 return TEST_SKIPPED; 15958 } else if (!sgl_in && sgl_out) { 15959 if (!(dev_info.feature_flags & 15960 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 15961 return TEST_SKIPPED; 15962 } else if (sgl_in && sgl_out) { 15963 if (!(dev_info.feature_flags & 15964 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 15965 return TEST_SKIPPED; 15966 } 15967 } 15968 15969 if (fragsz > tdata->plaintext.len) 15970 fragsz = tdata->plaintext.len; 15971 15972 uint16_t plaintext_len = fragsz; 15973 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 15974 15975 if (fragsz_oop > tdata->plaintext.len) 15976 frag_size_oop = tdata->plaintext.len; 15977 15978 int ecx = 0; 15979 void *digest_mem = NULL; 15980 15981 uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 15982 15983 if (tdata->plaintext.len % fragsz != 0) { 15984 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO) 15985 return 1; 15986 } else { 15987 if (tdata->plaintext.len / fragsz > SGL_MAX_NO) 15988 return 1; 15989 } 15990 15991 /* 15992 * For out-op-place we need to alloc another mbuf 15993 */ 15994 if (oop) { 15995 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15996 rte_pktmbuf_append(ut_params->obuf, 15997 frag_size_oop + prepend_len); 15998 buf_oop = ut_params->obuf; 15999 } 16000 16001 /* Create AEAD session */ 16002 retval = create_aead_session(ts_params->valid_devs[0], 16003 tdata->algo, 16004 RTE_CRYPTO_AEAD_OP_ENCRYPT, 16005 tdata->key.data, tdata->key.len, 16006 tdata->aad.len, tdata->auth_tag.len, 16007 tdata->iv.len); 16008 if (retval < 0) 16009 return retval; 16010 16011 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 16012 16013 /* clear mbuf payload */ 16014 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 16015 rte_pktmbuf_tailroom(ut_params->ibuf)); 16016 16017 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 16018 plaintext_len); 16019 16020 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 16021 16022 trn_data += plaintext_len; 16023 16024 buf = ut_params->ibuf; 16025 16026 /* 16027 * Loop until no more fragments 16028 */ 16029 16030 while (trn_data < tdata->plaintext.len) { 16031 ++segs; 16032 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 16033 (tdata->plaintext.len - trn_data) : fragsz; 16034 16035 to_trn_tbl[ecx++] = to_trn; 16036 16037 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 16038 buf = buf->next; 16039 16040 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 16041 rte_pktmbuf_tailroom(buf)); 16042 16043 /* OOP */ 16044 if (oop && !fragsz_oop) { 16045 buf_last_oop = buf_oop->next = 16046 rte_pktmbuf_alloc(ts_params->mbuf_pool); 16047 buf_oop = buf_oop->next; 16048 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 16049 0, rte_pktmbuf_tailroom(buf_oop)); 16050 rte_pktmbuf_append(buf_oop, to_trn); 16051 } 16052 16053 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 16054 to_trn); 16055 16056 memcpy(plaintext, tdata->plaintext.data + trn_data, 16057 to_trn); 16058 trn_data += to_trn; 16059 if (trn_data == tdata->plaintext.len) { 16060 if (oop) { 16061 if (!fragsz_oop) 16062 digest_mem = rte_pktmbuf_append(buf_oop, 16063 tdata->auth_tag.len); 16064 } else 16065 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 16066 tdata->auth_tag.len); 16067 } 16068 } 16069 16070 uint64_t digest_phys = 0; 16071 16072 ut_params->ibuf->nb_segs = segs; 16073 16074 segs = 1; 16075 if (fragsz_oop && oop) { 16076 to_trn = 0; 16077 ecx = 0; 16078 16079 if (frag_size_oop == tdata->plaintext.len) { 16080 digest_mem = rte_pktmbuf_append(ut_params->obuf, 16081 tdata->auth_tag.len); 16082 16083 digest_phys = rte_pktmbuf_iova_offset( 16084 ut_params->obuf, 16085 tdata->plaintext.len + prepend_len); 16086 } 16087 16088 trn_data = frag_size_oop; 16089 while (trn_data < tdata->plaintext.len) { 16090 ++segs; 16091 to_trn = 16092 (tdata->plaintext.len - trn_data < 16093 frag_size_oop) ? 16094 (tdata->plaintext.len - trn_data) : 16095 frag_size_oop; 16096 16097 to_trn_tbl[ecx++] = to_trn; 16098 16099 buf_last_oop = buf_oop->next = 16100 rte_pktmbuf_alloc(ts_params->mbuf_pool); 16101 buf_oop = buf_oop->next; 16102 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 16103 0, rte_pktmbuf_tailroom(buf_oop)); 16104 rte_pktmbuf_append(buf_oop, to_trn); 16105 16106 trn_data += to_trn; 16107 16108 if (trn_data == tdata->plaintext.len) { 16109 digest_mem = rte_pktmbuf_append(buf_oop, 16110 tdata->auth_tag.len); 16111 } 16112 } 16113 16114 ut_params->obuf->nb_segs = segs; 16115 } 16116 16117 /* 16118 * Place digest at the end of the last buffer 16119 */ 16120 if (!digest_phys) 16121 digest_phys = rte_pktmbuf_iova(buf) + to_trn; 16122 if (oop && buf_last_oop) 16123 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn; 16124 16125 if (!digest_mem && !oop) { 16126 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 16127 + tdata->auth_tag.len); 16128 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 16129 tdata->plaintext.len); 16130 } 16131 16132 /* Create AEAD operation */ 16133 retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT, 16134 tdata, digest_mem, digest_phys); 16135 16136 if (retval < 0) 16137 return retval; 16138 16139 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 16140 16141 ut_params->op->sym->m_src = ut_params->ibuf; 16142 if (oop) 16143 ut_params->op->sym->m_dst = ut_params->obuf; 16144 16145 /* Process crypto operation */ 16146 if (oop == IN_PLACE && 16147 gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 16148 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 16149 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 16150 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 16151 0); 16152 if (retval != TEST_SUCCESS) 16153 return retval; 16154 } else 16155 TEST_ASSERT_NOT_NULL( 16156 process_crypto_request(ts_params->valid_devs[0], 16157 ut_params->op), "failed to process sym crypto op"); 16158 16159 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 16160 "crypto op processing failed"); 16161 16162 16163 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 16164 uint8_t *, prepend_len); 16165 if (oop) { 16166 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 16167 uint8_t *, prepend_len); 16168 } 16169 16170 if (fragsz_oop) 16171 fragsz = fragsz_oop; 16172 16173 TEST_ASSERT_BUFFERS_ARE_EQUAL( 16174 ciphertext, 16175 tdata->ciphertext.data, 16176 fragsz, 16177 "Ciphertext data not as expected"); 16178 16179 buf = ut_params->op->sym->m_src->next; 16180 if (oop) 16181 buf = ut_params->op->sym->m_dst->next; 16182 16183 unsigned int off = fragsz; 16184 16185 ecx = 0; 16186 while (buf) { 16187 ciphertext = rte_pktmbuf_mtod(buf, 16188 uint8_t *); 16189 16190 TEST_ASSERT_BUFFERS_ARE_EQUAL( 16191 ciphertext, 16192 tdata->ciphertext.data + off, 16193 to_trn_tbl[ecx], 16194 "Ciphertext data not as expected"); 16195 16196 off += to_trn_tbl[ecx++]; 16197 buf = buf->next; 16198 } 16199 16200 auth_tag = digest_mem; 16201 TEST_ASSERT_BUFFERS_ARE_EQUAL( 16202 auth_tag, 16203 tdata->auth_tag.data, 16204 tdata->auth_tag.len, 16205 "Generated auth tag not as expected"); 16206 16207 return 0; 16208 } 16209 16210 static int 16211 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) 16212 { 16213 return test_authenticated_encryption_SGL( 16214 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400); 16215 } 16216 16217 static int 16218 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void) 16219 { 16220 return test_authenticated_encryption_SGL( 16221 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000); 16222 } 16223 16224 static int 16225 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void) 16226 { 16227 return test_authenticated_encryption_SGL( 16228 &gcm_test_case_8, OUT_OF_PLACE, 400, 16229 gcm_test_case_8.plaintext.len); 16230 } 16231 16232 static int 16233 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void) 16234 { 16235 /* This test is not for OPENSSL PMD */ 16236 if (gbl_driver_id == rte_cryptodev_driver_id_get( 16237 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) 16238 return TEST_SKIPPED; 16239 16240 return test_authenticated_encryption_SGL( 16241 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0); 16242 } 16243 16244 static int 16245 test_authentication_verify_fail_when_data_corrupted( 16246 struct crypto_testsuite_params *ts_params, 16247 struct crypto_unittest_params *ut_params, 16248 const struct test_crypto_vector *reference) 16249 { 16250 return test_authentication_verify_fail_when_data_corruption( 16251 ts_params, ut_params, reference, 1); 16252 } 16253 16254 static int 16255 test_authentication_verify_fail_when_tag_corrupted( 16256 struct crypto_testsuite_params *ts_params, 16257 struct crypto_unittest_params *ut_params, 16258 const struct test_crypto_vector *reference) 16259 { 16260 return test_authentication_verify_fail_when_data_corruption( 16261 ts_params, ut_params, reference, 0); 16262 } 16263 16264 static int 16265 test_authentication_verify_GMAC_fail_when_data_corrupted( 16266 struct crypto_testsuite_params *ts_params, 16267 struct crypto_unittest_params *ut_params, 16268 const struct test_crypto_vector *reference) 16269 { 16270 return test_authentication_verify_GMAC_fail_when_corruption( 16271 ts_params, ut_params, reference, 1); 16272 } 16273 16274 static int 16275 test_authentication_verify_GMAC_fail_when_tag_corrupted( 16276 struct crypto_testsuite_params *ts_params, 16277 struct crypto_unittest_params *ut_params, 16278 const struct test_crypto_vector *reference) 16279 { 16280 return test_authentication_verify_GMAC_fail_when_corruption( 16281 ts_params, ut_params, reference, 0); 16282 } 16283 16284 static int 16285 test_authenticated_decryption_fail_when_data_corrupted( 16286 struct crypto_testsuite_params *ts_params, 16287 struct crypto_unittest_params *ut_params, 16288 const struct test_crypto_vector *reference) 16289 { 16290 return test_authenticated_decryption_fail_when_corruption( 16291 ts_params, ut_params, reference, 1); 16292 } 16293 16294 static int 16295 test_authenticated_decryption_fail_when_tag_corrupted( 16296 struct crypto_testsuite_params *ts_params, 16297 struct crypto_unittest_params *ut_params, 16298 const struct test_crypto_vector *reference) 16299 { 16300 return test_authenticated_decryption_fail_when_corruption( 16301 ts_params, ut_params, reference, 0); 16302 } 16303 16304 static int 16305 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 16306 { 16307 return test_authentication_verify_fail_when_data_corrupted( 16308 &testsuite_params, &unittest_params, 16309 &hmac_sha1_test_crypto_vector); 16310 } 16311 16312 static int 16313 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 16314 { 16315 return test_authentication_verify_fail_when_tag_corrupted( 16316 &testsuite_params, &unittest_params, 16317 &hmac_sha1_test_crypto_vector); 16318 } 16319 16320 static int 16321 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 16322 { 16323 return test_authentication_verify_GMAC_fail_when_data_corrupted( 16324 &testsuite_params, &unittest_params, 16325 &aes128_gmac_test_vector); 16326 } 16327 16328 static int 16329 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 16330 { 16331 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 16332 &testsuite_params, &unittest_params, 16333 &aes128_gmac_test_vector); 16334 } 16335 16336 static int 16337 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 16338 { 16339 return test_authenticated_decryption_fail_when_data_corrupted( 16340 &testsuite_params, 16341 &unittest_params, 16342 &aes128cbc_hmac_sha1_test_vector); 16343 } 16344 16345 static int 16346 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 16347 { 16348 return test_authenticated_decryption_fail_when_tag_corrupted( 16349 &testsuite_params, 16350 &unittest_params, 16351 &aes128cbc_hmac_sha1_test_vector); 16352 } 16353 16354 static int 16355 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void) 16356 { 16357 return test_authenticated_encrypt_with_esn( 16358 &testsuite_params, 16359 &unittest_params, 16360 &aes128cbc_hmac_sha1_aad_test_vector); 16361 } 16362 16363 static int 16364 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void) 16365 { 16366 return test_authenticated_decrypt_with_esn( 16367 &testsuite_params, 16368 &unittest_params, 16369 &aes128cbc_hmac_sha1_aad_test_vector); 16370 } 16371 16372 static int 16373 test_chacha20_poly1305_encrypt_test_case_rfc8439(void) 16374 { 16375 return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439); 16376 } 16377 16378 static int 16379 test_chacha20_poly1305_decrypt_test_case_rfc8439(void) 16380 { 16381 return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439); 16382 } 16383 16384 static int 16385 test_chacha20_poly1305_encrypt_SGL_out_of_place(void) 16386 { 16387 return test_authenticated_encryption_SGL( 16388 &chacha20_poly1305_case_2, OUT_OF_PLACE, 32, 16389 chacha20_poly1305_case_2.plaintext.len); 16390 } 16391 16392 #ifdef RTE_CRYPTO_SCHEDULER 16393 16394 /* global AESNI worker IDs for the scheduler test */ 16395 uint8_t aesni_ids[2]; 16396 16397 static int 16398 scheduler_testsuite_setup(void) 16399 { 16400 uint32_t i = 0; 16401 int32_t nb_devs, ret; 16402 char vdev_args[VDEV_ARGS_SIZE] = {""}; 16403 char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core," 16404 "ordering=enable,name=cryptodev_test_scheduler,corelist="}; 16405 uint16_t worker_core_count = 0; 16406 uint16_t socket_id = 0; 16407 16408 if (gbl_driver_id == rte_cryptodev_driver_id_get( 16409 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) { 16410 16411 /* Identify the Worker Cores 16412 * Use 2 worker cores for the device args 16413 */ 16414 RTE_LCORE_FOREACH_WORKER(i) { 16415 if (worker_core_count > 1) 16416 break; 16417 snprintf(vdev_args, sizeof(vdev_args), 16418 "%s%d", temp_str, i); 16419 strcpy(temp_str, vdev_args); 16420 strlcat(temp_str, ";", sizeof(temp_str)); 16421 worker_core_count++; 16422 socket_id = rte_lcore_to_socket_id(i); 16423 } 16424 if (worker_core_count != 2) { 16425 RTE_LOG(ERR, USER1, 16426 "Cryptodev scheduler test require at least " 16427 "two worker cores to run. " 16428 "Please use the correct coremask.\n"); 16429 return TEST_FAILED; 16430 } 16431 strcpy(temp_str, vdev_args); 16432 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", 16433 temp_str, socket_id); 16434 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args); 16435 nb_devs = rte_cryptodev_device_count_by_driver( 16436 rte_cryptodev_driver_id_get( 16437 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))); 16438 if (nb_devs < 1) { 16439 ret = rte_vdev_init( 16440 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD), 16441 vdev_args); 16442 TEST_ASSERT(ret == 0, 16443 "Failed to create instance %u of pmd : %s", 16444 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 16445 } 16446 } 16447 return testsuite_setup(); 16448 } 16449 16450 static int 16451 test_scheduler_attach_worker_op(void) 16452 { 16453 struct crypto_testsuite_params *ts_params = &testsuite_params; 16454 uint8_t sched_id = ts_params->valid_devs[0]; 16455 uint32_t i, nb_devs_attached = 0; 16456 int ret; 16457 char vdev_name[32]; 16458 unsigned int count = rte_cryptodev_count(); 16459 16460 /* create 2 AESNI_MB vdevs on top of existing devices */ 16461 for (i = count; i < count + 2; i++) { 16462 snprintf(vdev_name, sizeof(vdev_name), "%s_%u", 16463 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), 16464 i); 16465 ret = rte_vdev_init(vdev_name, NULL); 16466 16467 TEST_ASSERT(ret == 0, 16468 "Failed to create instance %u of" 16469 " pmd : %s", 16470 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 16471 16472 if (ret < 0) { 16473 RTE_LOG(ERR, USER1, 16474 "Failed to create 2 AESNI MB PMDs.\n"); 16475 return TEST_SKIPPED; 16476 } 16477 } 16478 16479 /* attach 2 AESNI_MB cdevs */ 16480 for (i = count; i < count + 2; i++) { 16481 struct rte_cryptodev_info info; 16482 unsigned int session_size; 16483 16484 rte_cryptodev_info_get(i, &info); 16485 if (info.driver_id != rte_cryptodev_driver_id_get( 16486 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) 16487 continue; 16488 16489 session_size = rte_cryptodev_sym_get_private_session_size(i); 16490 /* 16491 * Create the session mempool again, since now there are new devices 16492 * to use the mempool. 16493 */ 16494 if (ts_params->session_mpool) { 16495 rte_mempool_free(ts_params->session_mpool); 16496 ts_params->session_mpool = NULL; 16497 } 16498 16499 if (info.sym.max_nb_sessions != 0 && 16500 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 16501 RTE_LOG(ERR, USER1, 16502 "Device does not support " 16503 "at least %u sessions\n", 16504 MAX_NB_SESSIONS); 16505 return TEST_FAILED; 16506 } 16507 /* 16508 * Create mempool with maximum number of sessions, 16509 * to include the session headers 16510 */ 16511 if (ts_params->session_mpool == NULL) { 16512 ts_params->session_mpool = 16513 rte_cryptodev_sym_session_pool_create( 16514 "test_sess_mp", 16515 MAX_NB_SESSIONS, session_size, 16516 0, 0, SOCKET_ID_ANY); 16517 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 16518 "session mempool allocation failed"); 16519 } 16520 16521 ts_params->qp_conf.mp_session = ts_params->session_mpool; 16522 16523 ret = rte_cryptodev_scheduler_worker_attach(sched_id, 16524 (uint8_t)i); 16525 16526 TEST_ASSERT(ret == 0, 16527 "Failed to attach device %u of pmd : %s", i, 16528 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 16529 16530 aesni_ids[nb_devs_attached] = (uint8_t)i; 16531 16532 nb_devs_attached++; 16533 } 16534 16535 return 0; 16536 } 16537 16538 static int 16539 test_scheduler_detach_worker_op(void) 16540 { 16541 struct crypto_testsuite_params *ts_params = &testsuite_params; 16542 uint8_t sched_id = ts_params->valid_devs[0]; 16543 uint32_t i; 16544 int ret; 16545 16546 for (i = 0; i < 2; i++) { 16547 ret = rte_cryptodev_scheduler_worker_detach(sched_id, 16548 aesni_ids[i]); 16549 TEST_ASSERT(ret == 0, 16550 "Failed to detach device %u", aesni_ids[i]); 16551 } 16552 16553 return 0; 16554 } 16555 16556 static int 16557 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode) 16558 { 16559 struct crypto_testsuite_params *ts_params = &testsuite_params; 16560 uint8_t sched_id = ts_params->valid_devs[0]; 16561 /* set mode */ 16562 return rte_cryptodev_scheduler_mode_set(sched_id, 16563 scheduler_mode); 16564 } 16565 16566 static int 16567 test_scheduler_mode_roundrobin_op(void) 16568 { 16569 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) == 16570 0, "Failed to set roundrobin mode"); 16571 return 0; 16572 16573 } 16574 16575 static int 16576 test_scheduler_mode_multicore_op(void) 16577 { 16578 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) == 16579 0, "Failed to set multicore mode"); 16580 16581 return 0; 16582 } 16583 16584 static int 16585 test_scheduler_mode_failover_op(void) 16586 { 16587 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) == 16588 0, "Failed to set failover mode"); 16589 16590 return 0; 16591 } 16592 16593 static int 16594 test_scheduler_mode_pkt_size_distr_op(void) 16595 { 16596 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) == 16597 0, "Failed to set pktsize mode"); 16598 16599 return 0; 16600 } 16601 16602 static int 16603 scheduler_multicore_testsuite_setup(void) 16604 { 16605 if (test_scheduler_attach_worker_op() < 0) 16606 return TEST_SKIPPED; 16607 if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0) 16608 return TEST_SKIPPED; 16609 return 0; 16610 } 16611 16612 static int 16613 scheduler_roundrobin_testsuite_setup(void) 16614 { 16615 if (test_scheduler_attach_worker_op() < 0) 16616 return TEST_SKIPPED; 16617 if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0) 16618 return TEST_SKIPPED; 16619 return 0; 16620 } 16621 16622 static int 16623 scheduler_failover_testsuite_setup(void) 16624 { 16625 if (test_scheduler_attach_worker_op() < 0) 16626 return TEST_SKIPPED; 16627 if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0) 16628 return TEST_SKIPPED; 16629 return 0; 16630 } 16631 16632 static int 16633 scheduler_pkt_size_distr_testsuite_setup(void) 16634 { 16635 if (test_scheduler_attach_worker_op() < 0) 16636 return TEST_SKIPPED; 16637 if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0) 16638 return TEST_SKIPPED; 16639 return 0; 16640 } 16641 16642 static void 16643 scheduler_mode_testsuite_teardown(void) 16644 { 16645 test_scheduler_detach_worker_op(); 16646 } 16647 16648 #endif /* RTE_CRYPTO_SCHEDULER */ 16649 16650 static struct unit_test_suite end_testsuite = { 16651 .suite_name = NULL, 16652 .setup = NULL, 16653 .teardown = NULL, 16654 .unit_test_suites = NULL 16655 }; 16656 16657 #ifdef RTE_LIB_SECURITY 16658 static struct unit_test_suite ipsec_proto_testsuite = { 16659 .suite_name = "IPsec Proto Unit Test Suite", 16660 .setup = ipsec_proto_testsuite_setup, 16661 .unit_test_cases = { 16662 TEST_CASE_NAMED_WITH_DATA( 16663 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 16664 ut_setup_security, ut_teardown, 16665 test_ipsec_proto_known_vec, &pkt_aes_128_gcm), 16666 TEST_CASE_NAMED_WITH_DATA( 16667 "Outbound known vector ext_mbuf mode (ESP tunnel mode IPv4 AES-GCM 128)", 16668 ut_setup_security, ut_teardown, 16669 test_ipsec_proto_known_vec_ext_mbuf, &pkt_aes_128_gcm), 16670 TEST_CASE_NAMED_WITH_DATA( 16671 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 16672 ut_setup_security, ut_teardown, 16673 test_ipsec_proto_known_vec, &pkt_aes_192_gcm), 16674 TEST_CASE_NAMED_WITH_DATA( 16675 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 16676 ut_setup_security, ut_teardown, 16677 test_ipsec_proto_known_vec, &pkt_aes_256_gcm), 16678 TEST_CASE_NAMED_WITH_DATA( 16679 "Outbound known vector (ESP tunnel mode IPv4 AES-CCM 256)", 16680 ut_setup_security, ut_teardown, 16681 test_ipsec_proto_known_vec, &pkt_aes_256_ccm), 16682 TEST_CASE_NAMED_WITH_DATA( 16683 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC MD5 [12B ICV])", 16684 ut_setup_security, ut_teardown, 16685 test_ipsec_proto_known_vec, 16686 &pkt_aes_128_cbc_md5), 16687 TEST_CASE_NAMED_WITH_DATA( 16688 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])", 16689 ut_setup_security, ut_teardown, 16690 test_ipsec_proto_known_vec, 16691 &pkt_aes_128_cbc_hmac_sha256), 16692 TEST_CASE_NAMED_WITH_DATA( 16693 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])", 16694 ut_setup_security, ut_teardown, 16695 test_ipsec_proto_known_vec, 16696 &pkt_aes_128_cbc_hmac_sha384), 16697 TEST_CASE_NAMED_WITH_DATA( 16698 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])", 16699 ut_setup_security, ut_teardown, 16700 test_ipsec_proto_known_vec, 16701 &pkt_aes_128_cbc_hmac_sha512), 16702 TEST_CASE_NAMED_WITH_DATA( 16703 "Outbound known vector (ESP tunnel mode IPv6 AES-GCM 128)", 16704 ut_setup_security, ut_teardown, 16705 test_ipsec_proto_known_vec, &pkt_aes_256_gcm_v6), 16706 TEST_CASE_NAMED_WITH_DATA( 16707 "Outbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])", 16708 ut_setup_security, ut_teardown, 16709 test_ipsec_proto_known_vec, 16710 &pkt_aes_128_cbc_hmac_sha256_v6), 16711 TEST_CASE_NAMED_WITH_DATA( 16712 "Outbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])", 16713 ut_setup_security, ut_teardown, 16714 test_ipsec_proto_known_vec, 16715 &pkt_null_aes_xcbc), 16716 TEST_CASE_NAMED_WITH_DATA( 16717 "Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA256 [16B ICV])", 16718 ut_setup_security, ut_teardown, 16719 test_ipsec_proto_known_vec, 16720 &pkt_des_cbc_hmac_sha256), 16721 TEST_CASE_NAMED_WITH_DATA( 16722 "Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA384 [24B ICV])", 16723 ut_setup_security, ut_teardown, 16724 test_ipsec_proto_known_vec, 16725 &pkt_des_cbc_hmac_sha384), 16726 TEST_CASE_NAMED_WITH_DATA( 16727 "Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA512 [32B ICV])", 16728 ut_setup_security, ut_teardown, 16729 test_ipsec_proto_known_vec, 16730 &pkt_des_cbc_hmac_sha512), 16731 TEST_CASE_NAMED_WITH_DATA( 16732 "Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA256 [16B ICV])", 16733 ut_setup_security, ut_teardown, 16734 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha256), 16735 TEST_CASE_NAMED_WITH_DATA( 16736 "Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA384 [24B ICV])", 16737 ut_setup_security, ut_teardown, 16738 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha384), 16739 TEST_CASE_NAMED_WITH_DATA( 16740 "Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA512 [32B ICV])", 16741 ut_setup_security, ut_teardown, 16742 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha512), 16743 TEST_CASE_NAMED_WITH_DATA( 16744 "Outbound known vector (ESP tunnel mode IPv6 DES-CBC HMAC-SHA256 [16B ICV])", 16745 ut_setup_security, ut_teardown, 16746 test_ipsec_proto_known_vec, 16747 &pkt_des_cbc_hmac_sha256_v6), 16748 TEST_CASE_NAMED_WITH_DATA( 16749 "Outbound known vector (ESP tunnel mode IPv6 3DES-CBC HMAC-SHA256 [16B ICV])", 16750 ut_setup_security, ut_teardown, 16751 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha256_v6), 16752 TEST_CASE_NAMED_WITH_DATA( 16753 "Outbound known vector (AH tunnel mode IPv4 HMAC-SHA256)", 16754 ut_setup_security, ut_teardown, 16755 test_ipsec_proto_known_vec, 16756 &pkt_ah_tunnel_sha256), 16757 TEST_CASE_NAMED_WITH_DATA( 16758 "Outbound known vector (AH transport mode IPv4 HMAC-SHA256)", 16759 ut_setup_security, ut_teardown, 16760 test_ipsec_proto_known_vec, 16761 &pkt_ah_transport_sha256), 16762 TEST_CASE_NAMED_WITH_DATA( 16763 "Outbound known vector (AH transport mode IPv4 AES-GMAC 128)", 16764 ut_setup_security, ut_teardown, 16765 test_ipsec_proto_known_vec, 16766 &pkt_ah_ipv4_aes_gmac_128), 16767 TEST_CASE_NAMED_WITH_DATA( 16768 "Outbound fragmented packet", 16769 ut_setup_security, ut_teardown, 16770 test_ipsec_proto_known_vec_fragmented, 16771 &pkt_aes_128_gcm_frag), 16772 TEST_CASE_NAMED_WITH_DATA( 16773 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 16774 ut_setup_security, ut_teardown, 16775 test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm), 16776 TEST_CASE_NAMED_WITH_DATA( 16777 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 16778 ut_setup_security, ut_teardown, 16779 test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm), 16780 TEST_CASE_NAMED_WITH_DATA( 16781 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 16782 ut_setup_security, ut_teardown, 16783 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm), 16784 TEST_CASE_NAMED_WITH_DATA( 16785 "Inbound known vector (ESP tunnel mode IPv4 AES-CCM 256)", 16786 ut_setup_security, ut_teardown, 16787 test_ipsec_proto_known_vec_inb, &pkt_aes_256_ccm), 16788 TEST_CASE_NAMED_WITH_DATA( 16789 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)", 16790 ut_setup_security, ut_teardown, 16791 test_ipsec_proto_known_vec_inb, &pkt_aes_128_cbc_null), 16792 TEST_CASE_NAMED_WITH_DATA( 16793 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC MD5 [12B ICV])", 16794 ut_setup_security, ut_teardown, 16795 test_ipsec_proto_known_vec_inb, 16796 &pkt_aes_128_cbc_md5), 16797 TEST_CASE_NAMED_WITH_DATA( 16798 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])", 16799 ut_setup_security, ut_teardown, 16800 test_ipsec_proto_known_vec_inb, 16801 &pkt_aes_128_cbc_hmac_sha256), 16802 TEST_CASE_NAMED_WITH_DATA( 16803 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])", 16804 ut_setup_security, ut_teardown, 16805 test_ipsec_proto_known_vec_inb, 16806 &pkt_aes_128_cbc_hmac_sha384), 16807 TEST_CASE_NAMED_WITH_DATA( 16808 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])", 16809 ut_setup_security, ut_teardown, 16810 test_ipsec_proto_known_vec_inb, 16811 &pkt_aes_128_cbc_hmac_sha512), 16812 TEST_CASE_NAMED_WITH_DATA( 16813 "Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)", 16814 ut_setup_security, ut_teardown, 16815 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm_v6), 16816 TEST_CASE_NAMED_WITH_DATA( 16817 "Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])", 16818 ut_setup_security, ut_teardown, 16819 test_ipsec_proto_known_vec_inb, 16820 &pkt_aes_128_cbc_hmac_sha256_v6), 16821 TEST_CASE_NAMED_WITH_DATA( 16822 "Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])", 16823 ut_setup_security, ut_teardown, 16824 test_ipsec_proto_known_vec_inb, 16825 &pkt_null_aes_xcbc), 16826 TEST_CASE_NAMED_WITH_DATA( 16827 "Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA256 [16B ICV])", 16828 ut_setup_security, ut_teardown, 16829 test_ipsec_proto_known_vec_inb, 16830 &pkt_des_cbc_hmac_sha256), 16831 TEST_CASE_NAMED_WITH_DATA( 16832 "Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA384 [24B ICV])", 16833 ut_setup_security, ut_teardown, 16834 test_ipsec_proto_known_vec_inb, 16835 &pkt_des_cbc_hmac_sha384), 16836 TEST_CASE_NAMED_WITH_DATA( 16837 "Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA512 [32B ICV])", 16838 ut_setup_security, ut_teardown, 16839 test_ipsec_proto_known_vec_inb, 16840 &pkt_des_cbc_hmac_sha512), 16841 TEST_CASE_NAMED_WITH_DATA( 16842 "Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA256 [16B ICV])", 16843 ut_setup_security, ut_teardown, 16844 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha256), 16845 TEST_CASE_NAMED_WITH_DATA( 16846 "Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA384 [24B ICV])", 16847 ut_setup_security, ut_teardown, 16848 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha384), 16849 TEST_CASE_NAMED_WITH_DATA( 16850 "Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA512 [32B ICV])", 16851 ut_setup_security, ut_teardown, 16852 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha512), 16853 TEST_CASE_NAMED_WITH_DATA( 16854 "Inbound known vector (ESP tunnel mode IPv6 DES-CBC HMAC-SHA256 [16B ICV])", 16855 ut_setup_security, ut_teardown, 16856 test_ipsec_proto_known_vec_inb, 16857 &pkt_des_cbc_hmac_sha256_v6), 16858 TEST_CASE_NAMED_WITH_DATA( 16859 "Inbound known vector (ESP tunnel mode IPv6 3DES-CBC HMAC-SHA256 [16B ICV])", 16860 ut_setup_security, ut_teardown, 16861 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha256_v6), 16862 TEST_CASE_NAMED_WITH_DATA( 16863 "Inbound known vector (AH tunnel mode IPv4 HMAC-SHA256)", 16864 ut_setup_security, ut_teardown, 16865 test_ipsec_proto_known_vec_inb, 16866 &pkt_ah_tunnel_sha256), 16867 TEST_CASE_NAMED_WITH_DATA( 16868 "Inbound known vector (AH transport mode IPv4 HMAC-SHA256)", 16869 ut_setup_security, ut_teardown, 16870 test_ipsec_proto_known_vec_inb, 16871 &pkt_ah_transport_sha256), 16872 TEST_CASE_NAMED_WITH_DATA( 16873 "Inbound known vector (AH transport mode IPv4 AES-GMAC 128)", 16874 ut_setup_security, ut_teardown, 16875 test_ipsec_proto_known_vec_inb, 16876 &pkt_ah_ipv4_aes_gmac_128), 16877 TEST_CASE_NAMED_ST( 16878 "Combined test alg list", 16879 ut_setup_security, ut_teardown, 16880 test_ipsec_proto_display_list), 16881 TEST_CASE_NAMED_ST( 16882 "Combined test alg list (AH)", 16883 ut_setup_security, ut_teardown, 16884 test_ipsec_proto_ah_tunnel_ipv4), 16885 TEST_CASE_NAMED_ST( 16886 "IV generation", 16887 ut_setup_security, ut_teardown, 16888 test_ipsec_proto_iv_gen), 16889 TEST_CASE_NAMED_ST( 16890 "UDP encapsulation", 16891 ut_setup_security, ut_teardown, 16892 test_ipsec_proto_udp_encap), 16893 TEST_CASE_NAMED_ST( 16894 "UDP encapsulation with custom ports", 16895 ut_setup_security, ut_teardown, 16896 test_ipsec_proto_udp_encap_custom_ports), 16897 TEST_CASE_NAMED_ST( 16898 "UDP encapsulation ports verification test", 16899 ut_setup_security, ut_teardown, 16900 test_ipsec_proto_udp_ports_verify), 16901 TEST_CASE_NAMED_ST( 16902 "SA expiry packets soft", 16903 ut_setup_security, ut_teardown, 16904 test_ipsec_proto_sa_exp_pkts_soft), 16905 TEST_CASE_NAMED_ST( 16906 "SA expiry packets hard", 16907 ut_setup_security, ut_teardown, 16908 test_ipsec_proto_sa_exp_pkts_hard), 16909 TEST_CASE_NAMED_ST( 16910 "Negative test: ICV corruption", 16911 ut_setup_security, ut_teardown, 16912 test_ipsec_proto_err_icv_corrupt), 16913 TEST_CASE_NAMED_ST( 16914 "Tunnel dst addr verification", 16915 ut_setup_security, ut_teardown, 16916 test_ipsec_proto_tunnel_dst_addr_verify), 16917 TEST_CASE_NAMED_ST( 16918 "Tunnel src and dst addr verification", 16919 ut_setup_security, ut_teardown, 16920 test_ipsec_proto_tunnel_src_dst_addr_verify), 16921 TEST_CASE_NAMED_ST( 16922 "Inner IP checksum", 16923 ut_setup_security, ut_teardown, 16924 test_ipsec_proto_inner_ip_csum), 16925 TEST_CASE_NAMED_ST( 16926 "Inner L4 checksum", 16927 ut_setup_security, ut_teardown, 16928 test_ipsec_proto_inner_l4_csum), 16929 TEST_CASE_NAMED_ST( 16930 "Tunnel IPv4 in IPv4", 16931 ut_setup_security, ut_teardown, 16932 test_ipsec_proto_tunnel_v4_in_v4), 16933 TEST_CASE_NAMED_ST( 16934 "Tunnel IPv6 in IPv6", 16935 ut_setup_security, ut_teardown, 16936 test_ipsec_proto_tunnel_v6_in_v6), 16937 TEST_CASE_NAMED_ST( 16938 "Tunnel IPv4 in IPv6", 16939 ut_setup_security, ut_teardown, 16940 test_ipsec_proto_tunnel_v4_in_v6), 16941 TEST_CASE_NAMED_ST( 16942 "Tunnel IPv6 in IPv4", 16943 ut_setup_security, ut_teardown, 16944 test_ipsec_proto_tunnel_v6_in_v4), 16945 TEST_CASE_NAMED_ST( 16946 "Transport IPv4", 16947 ut_setup_security, ut_teardown, 16948 test_ipsec_proto_transport_v4), 16949 TEST_CASE_NAMED_ST( 16950 "AH transport IPv4", 16951 ut_setup_security, ut_teardown, 16952 test_ipsec_proto_ah_transport_ipv4), 16953 TEST_CASE_NAMED_ST( 16954 "Transport l4 checksum", 16955 ut_setup_security, ut_teardown, 16956 test_ipsec_proto_transport_l4_csum), 16957 TEST_CASE_NAMED_ST( 16958 "Statistics: success", 16959 ut_setup_security, ut_teardown, 16960 test_ipsec_proto_stats), 16961 TEST_CASE_NAMED_ST( 16962 "Fragmented packet", 16963 ut_setup_security, ut_teardown, 16964 test_ipsec_proto_pkt_fragment), 16965 TEST_CASE_NAMED_ST( 16966 "Tunnel header copy DF (inner 0)", 16967 ut_setup_security, ut_teardown, 16968 test_ipsec_proto_copy_df_inner_0), 16969 TEST_CASE_NAMED_ST( 16970 "Tunnel header copy DF (inner 1)", 16971 ut_setup_security, ut_teardown, 16972 test_ipsec_proto_copy_df_inner_1), 16973 TEST_CASE_NAMED_ST( 16974 "Tunnel header set DF 0 (inner 1)", 16975 ut_setup_security, ut_teardown, 16976 test_ipsec_proto_set_df_0_inner_1), 16977 TEST_CASE_NAMED_ST( 16978 "Tunnel header set DF 1 (inner 0)", 16979 ut_setup_security, ut_teardown, 16980 test_ipsec_proto_set_df_1_inner_0), 16981 TEST_CASE_NAMED_ST( 16982 "Tunnel header IPv4 copy DSCP (inner 0)", 16983 ut_setup_security, ut_teardown, 16984 test_ipsec_proto_ipv4_copy_dscp_inner_0), 16985 TEST_CASE_NAMED_ST( 16986 "Tunnel header IPv4 copy DSCP (inner 1)", 16987 ut_setup_security, ut_teardown, 16988 test_ipsec_proto_ipv4_copy_dscp_inner_1), 16989 TEST_CASE_NAMED_ST( 16990 "Tunnel header IPv4 set DSCP 0 (inner 1)", 16991 ut_setup_security, ut_teardown, 16992 test_ipsec_proto_ipv4_set_dscp_0_inner_1), 16993 TEST_CASE_NAMED_ST( 16994 "Tunnel header IPv4 set DSCP 1 (inner 0)", 16995 ut_setup_security, ut_teardown, 16996 test_ipsec_proto_ipv4_set_dscp_1_inner_0), 16997 TEST_CASE_NAMED_ST( 16998 "Tunnel header IPv6 copy DSCP (inner 0)", 16999 ut_setup_security, ut_teardown, 17000 test_ipsec_proto_ipv6_copy_dscp_inner_0), 17001 TEST_CASE_NAMED_ST( 17002 "Tunnel header IPv6 copy DSCP (inner 1)", 17003 ut_setup_security, ut_teardown, 17004 test_ipsec_proto_ipv6_copy_dscp_inner_1), 17005 TEST_CASE_NAMED_ST( 17006 "Tunnel header IPv6 set DSCP 0 (inner 1)", 17007 ut_setup_security, ut_teardown, 17008 test_ipsec_proto_ipv6_set_dscp_0_inner_1), 17009 TEST_CASE_NAMED_ST( 17010 "Tunnel header IPv6 set DSCP 1 (inner 0)", 17011 ut_setup_security, ut_teardown, 17012 test_ipsec_proto_ipv6_set_dscp_1_inner_0), 17013 TEST_CASE_NAMED_WITH_DATA( 17014 "Antireplay with window size 1024", 17015 ut_setup_security, ut_teardown, 17016 test_ipsec_proto_pkt_antireplay1024, &pkt_aes_128_gcm), 17017 TEST_CASE_NAMED_WITH_DATA( 17018 "Antireplay with window size 2048", 17019 ut_setup_security, ut_teardown, 17020 test_ipsec_proto_pkt_antireplay2048, &pkt_aes_128_gcm), 17021 TEST_CASE_NAMED_WITH_DATA( 17022 "Antireplay with window size 4096", 17023 ut_setup_security, ut_teardown, 17024 test_ipsec_proto_pkt_antireplay4096, &pkt_aes_128_gcm), 17025 TEST_CASE_NAMED_WITH_DATA( 17026 "ESN and Antireplay with window size 1024", 17027 ut_setup_security, ut_teardown, 17028 test_ipsec_proto_pkt_esn_antireplay1024, 17029 &pkt_aes_128_gcm), 17030 TEST_CASE_NAMED_WITH_DATA( 17031 "ESN and Antireplay with window size 2048", 17032 ut_setup_security, ut_teardown, 17033 test_ipsec_proto_pkt_esn_antireplay2048, 17034 &pkt_aes_128_gcm), 17035 TEST_CASE_NAMED_WITH_DATA( 17036 "ESN and Antireplay with window size 4096", 17037 ut_setup_security, ut_teardown, 17038 test_ipsec_proto_pkt_esn_antireplay4096, 17039 &pkt_aes_128_gcm), 17040 TEST_CASE_NAMED_ST( 17041 "Tunnel header IPv4 decrement inner TTL", 17042 ut_setup_security, ut_teardown, 17043 test_ipsec_proto_ipv4_ttl_decrement), 17044 TEST_CASE_NAMED_ST( 17045 "Tunnel header IPv6 decrement inner hop limit", 17046 ut_setup_security, ut_teardown, 17047 test_ipsec_proto_ipv6_hop_limit_decrement), 17048 TEST_CASE_NAMED_ST( 17049 "Multi-segmented mode", 17050 ut_setup_security, ut_teardown, 17051 test_ipsec_proto_sgl), 17052 TEST_CASE_NAMED_ST( 17053 "Multi-segmented external mbuf mode", 17054 ut_setup_security, ut_teardown, 17055 test_ipsec_proto_sgl_ext_mbuf), 17056 TEST_CASE_NAMED_WITH_DATA( 17057 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128) Rx inject", 17058 ut_setup_security_rx_inject, ut_teardown_rx_inject, 17059 test_ipsec_proto_known_vec_inb_rx_inject, &pkt_aes_128_gcm), 17060 TEST_CASES_END() /**< NULL terminate unit test array */ 17061 } 17062 }; 17063 17064 static struct unit_test_suite pdcp_proto_testsuite = { 17065 .suite_name = "PDCP Proto Unit Test Suite", 17066 .setup = pdcp_proto_testsuite_setup, 17067 .unit_test_cases = { 17068 TEST_CASE_ST(ut_setup_security, ut_teardown, 17069 test_PDCP_PROTO_all), 17070 TEST_CASES_END() /**< NULL terminate unit test array */ 17071 } 17072 }; 17073 17074 static struct unit_test_suite tls12_record_proto_testsuite = { 17075 .suite_name = "TLS 1.2 Record Protocol Unit Test Suite", 17076 .setup = tls_record_proto_testsuite_setup, 17077 .unit_test_cases = { 17078 TEST_CASE_NAMED_WITH_DATA( 17079 "Write record known vector AES-GCM-128 (vector 1)", 17080 ut_setup_security, ut_teardown, 17081 test_tls_record_proto_known_vec, &tls_test_data_aes_128_gcm_v1), 17082 TEST_CASE_NAMED_WITH_DATA( 17083 "Write record known vector AES-GCM-128 (vector 2)", 17084 ut_setup_security, ut_teardown, 17085 test_tls_record_proto_known_vec, &tls_test_data_aes_128_gcm_v2), 17086 TEST_CASE_NAMED_WITH_DATA( 17087 "Write record known vector AES-GCM-256", 17088 ut_setup_security, ut_teardown, 17089 test_tls_record_proto_known_vec, &tls_test_data_aes_256_gcm), 17090 TEST_CASE_NAMED_WITH_DATA( 17091 "Write record known vector AES-CBC-128-SHA1", 17092 ut_setup_security, ut_teardown, 17093 test_tls_record_proto_known_vec, &tls_test_data_aes_128_cbc_sha1_hmac), 17094 TEST_CASE_NAMED_WITH_DATA( 17095 "Write record known vector AES-128-CBC-SHA256", 17096 ut_setup_security, ut_teardown, 17097 test_tls_record_proto_known_vec, &tls_test_data_aes_128_cbc_sha256_hmac), 17098 TEST_CASE_NAMED_WITH_DATA( 17099 "Write record known vector AES-256-CBC-SHA1", 17100 ut_setup_security, ut_teardown, 17101 test_tls_record_proto_known_vec, &tls_test_data_aes_256_cbc_sha1_hmac), 17102 TEST_CASE_NAMED_WITH_DATA( 17103 "Write record known vector AES-256-CBC-SHA256", 17104 ut_setup_security, ut_teardown, 17105 test_tls_record_proto_known_vec, &tls_test_data_aes_256_cbc_sha256_hmac), 17106 TEST_CASE_NAMED_WITH_DATA( 17107 "Write record known vector 3DES-CBC-SHA1-HMAC", 17108 ut_setup_security, ut_teardown, 17109 test_tls_record_proto_known_vec, &tls_test_data_3des_cbc_sha1_hmac), 17110 TEST_CASE_NAMED_WITH_DATA( 17111 "Write record known vector NULL-SHA1-HMAC", 17112 ut_setup_security, ut_teardown, 17113 test_tls_record_proto_known_vec, &tls_test_data_null_cipher_sha1_hmac), 17114 TEST_CASE_NAMED_WITH_DATA( 17115 "Write record known vector CHACHA20-POLY1305", 17116 ut_setup_security, ut_teardown, 17117 test_tls_record_proto_known_vec, &tls_test_data_chacha20_poly1305), 17118 17119 TEST_CASE_NAMED_WITH_DATA( 17120 "Read record known vector AES-GCM-128 (vector 1)", 17121 ut_setup_security, ut_teardown, 17122 test_tls_record_proto_known_vec_read, &tls_test_data_aes_128_gcm_v1), 17123 TEST_CASE_NAMED_WITH_DATA( 17124 "Read record known vector AES-GCM-128 (vector 2)", 17125 ut_setup_security, ut_teardown, 17126 test_tls_record_proto_known_vec_read, &tls_test_data_aes_128_gcm_v2), 17127 TEST_CASE_NAMED_WITH_DATA( 17128 "Read record known vector AES-GCM-256", 17129 ut_setup_security, ut_teardown, 17130 test_tls_record_proto_known_vec_read, &tls_test_data_aes_256_gcm), 17131 TEST_CASE_NAMED_WITH_DATA( 17132 "Read record known vector AES-128-CBC-SHA1", 17133 ut_setup_security, ut_teardown, 17134 test_tls_record_proto_known_vec_read, &tls_test_data_aes_128_cbc_sha1_hmac), 17135 TEST_CASE_NAMED_WITH_DATA( 17136 "Read record known vector AES-128-CBC-SHA256", 17137 ut_setup_security, ut_teardown, 17138 test_tls_record_proto_known_vec_read, 17139 &tls_test_data_aes_128_cbc_sha256_hmac), 17140 TEST_CASE_NAMED_WITH_DATA( 17141 "Read record known vector AES-256-CBC-SHA1", 17142 ut_setup_security, ut_teardown, 17143 test_tls_record_proto_known_vec_read, &tls_test_data_aes_256_cbc_sha1_hmac), 17144 TEST_CASE_NAMED_WITH_DATA( 17145 "Read record known vector AES-256-CBC-SHA256", 17146 ut_setup_security, ut_teardown, 17147 test_tls_record_proto_known_vec_read, 17148 &tls_test_data_aes_256_cbc_sha256_hmac), 17149 TEST_CASE_NAMED_WITH_DATA( 17150 "Read record known vector 3DES-CBC-SHA1-HMAC", 17151 ut_setup_security, ut_teardown, 17152 test_tls_record_proto_known_vec_read, &tls_test_data_3des_cbc_sha1_hmac), 17153 TEST_CASE_NAMED_WITH_DATA( 17154 "Read record known vector NULL-SHA1-HMAC", 17155 ut_setup_security, ut_teardown, 17156 test_tls_record_proto_known_vec_read, &tls_test_data_null_cipher_sha1_hmac), 17157 TEST_CASE_NAMED_WITH_DATA( 17158 "Read record known vector CHACHA20-POLY1305", 17159 ut_setup_security, ut_teardown, 17160 test_tls_record_proto_known_vec_read, &tls_test_data_chacha20_poly1305), 17161 17162 TEST_CASE_NAMED_ST( 17163 "Combined test alg list", 17164 ut_setup_security, ut_teardown, 17165 test_tls_1_2_record_proto_display_list), 17166 TEST_CASE_NAMED_ST( 17167 "Data walkthrough combined test alg list", 17168 ut_setup_security, ut_teardown, 17169 test_tls_1_2_record_proto_data_walkthrough), 17170 TEST_CASE_NAMED_ST( 17171 "Multi-segmented mode", 17172 ut_setup_security, ut_teardown, 17173 test_tls_1_2_record_proto_sgl), 17174 TEST_CASES_END() /**< NULL terminate unit test array */ 17175 } 17176 }; 17177 17178 static struct unit_test_suite dtls12_record_proto_testsuite = { 17179 .suite_name = "DTLS 1.2 Record Protocol Unit Test Suite", 17180 .setup = tls_record_proto_testsuite_setup, 17181 .unit_test_cases = { 17182 TEST_CASE_NAMED_WITH_DATA( 17183 "Write record known vector AES-GCM-128", 17184 ut_setup_security, ut_teardown, 17185 test_tls_record_proto_known_vec, &dtls_test_data_aes_128_gcm), 17186 TEST_CASE_NAMED_WITH_DATA( 17187 "Write record known vector AES-GCM-256", 17188 ut_setup_security, ut_teardown, 17189 test_tls_record_proto_known_vec, &dtls_test_data_aes_256_gcm), 17190 TEST_CASE_NAMED_WITH_DATA( 17191 "Write record known vector AES-128-CBC-SHA1", 17192 ut_setup_security, ut_teardown, 17193 test_tls_record_proto_known_vec, 17194 &dtls_test_data_aes_128_cbc_sha1_hmac), 17195 TEST_CASE_NAMED_WITH_DATA( 17196 "Write record known vector AES-128-CBC-SHA256", 17197 ut_setup_security, ut_teardown, 17198 test_tls_record_proto_known_vec, 17199 &dtls_test_data_aes_128_cbc_sha256_hmac), 17200 TEST_CASE_NAMED_WITH_DATA( 17201 "Write record known vector AES-256-CBC-SHA1", 17202 ut_setup_security, ut_teardown, 17203 test_tls_record_proto_known_vec, 17204 &dtls_test_data_aes_256_cbc_sha1_hmac), 17205 TEST_CASE_NAMED_WITH_DATA( 17206 "Write record known vector AES-256-CBC-SHA256", 17207 ut_setup_security, ut_teardown, 17208 test_tls_record_proto_known_vec, 17209 &dtls_test_data_aes_256_cbc_sha256_hmac), 17210 TEST_CASE_NAMED_WITH_DATA( 17211 "Write record known vector 3DES-CBC-SHA1-HMAC", 17212 ut_setup_security, ut_teardown, 17213 test_tls_record_proto_known_vec, 17214 &dtls_test_data_3des_cbc_sha1_hmac), 17215 TEST_CASE_NAMED_WITH_DATA( 17216 "Write record known vector NULL-SHA1-HMAC", 17217 ut_setup_security, ut_teardown, 17218 test_tls_record_proto_known_vec, 17219 &dtls_test_data_null_cipher_sha1_hmac), 17220 TEST_CASE_NAMED_WITH_DATA( 17221 "Write record known vector CHACHA20-POLY1305", 17222 ut_setup_security, ut_teardown, 17223 test_tls_record_proto_known_vec, &dtls_test_data_chacha20_poly1305), 17224 TEST_CASE_NAMED_WITH_DATA( 17225 "Read record known vector AES-GCM-128", 17226 ut_setup_security, ut_teardown, 17227 test_tls_record_proto_known_vec_read, &dtls_test_data_aes_128_gcm), 17228 TEST_CASE_NAMED_WITH_DATA( 17229 "Read record known vector AES-GCM-256", 17230 ut_setup_security, ut_teardown, 17231 test_tls_record_proto_known_vec_read, &dtls_test_data_aes_256_gcm), 17232 TEST_CASE_NAMED_WITH_DATA( 17233 "Read record known vector AES-128-CBC-SHA1", 17234 ut_setup_security, ut_teardown, 17235 test_tls_record_proto_known_vec_read, 17236 &dtls_test_data_aes_128_cbc_sha1_hmac), 17237 TEST_CASE_NAMED_WITH_DATA( 17238 "Read record known vector AES-128-CBC-SHA256", 17239 ut_setup_security, ut_teardown, 17240 test_tls_record_proto_known_vec_read, 17241 &dtls_test_data_aes_128_cbc_sha256_hmac), 17242 TEST_CASE_NAMED_WITH_DATA( 17243 "Read record known vector AES-256-CBC-SHA1", 17244 ut_setup_security, ut_teardown, 17245 test_tls_record_proto_known_vec_read, 17246 &dtls_test_data_aes_256_cbc_sha1_hmac), 17247 TEST_CASE_NAMED_WITH_DATA( 17248 "Read record known vector AES-256-CBC-SHA256", 17249 ut_setup_security, ut_teardown, 17250 test_tls_record_proto_known_vec_read, 17251 &dtls_test_data_aes_256_cbc_sha256_hmac), 17252 TEST_CASE_NAMED_WITH_DATA( 17253 "Read record known vector 3DES-CBC-SHA1-HMAC", 17254 ut_setup_security, ut_teardown, 17255 test_tls_record_proto_known_vec_read, 17256 &dtls_test_data_3des_cbc_sha1_hmac), 17257 TEST_CASE_NAMED_WITH_DATA( 17258 "Read record known vector NULL-SHA1-HMAC", 17259 ut_setup_security, ut_teardown, 17260 test_tls_record_proto_known_vec_read, 17261 &dtls_test_data_null_cipher_sha1_hmac), 17262 TEST_CASE_NAMED_WITH_DATA( 17263 "Read record known vector CHACHA20-POLY1305", 17264 ut_setup_security, ut_teardown, 17265 test_tls_record_proto_known_vec_read, &dtls_test_data_chacha20_poly1305), 17266 17267 TEST_CASE_NAMED_ST( 17268 "Combined test alg list", 17269 ut_setup_security, ut_teardown, 17270 test_dtls_1_2_record_proto_display_list), 17271 TEST_CASE_NAMED_ST( 17272 "Data walkthrough combined test alg list", 17273 ut_setup_security, ut_teardown, 17274 test_dtls_1_2_record_proto_data_walkthrough), 17275 TEST_CASE_NAMED_ST( 17276 "Multi-segmented mode", 17277 ut_setup_security, ut_teardown, 17278 test_dtls_1_2_record_proto_sgl), 17279 TEST_CASES_END() /**< NULL terminate unit test array */ 17280 } 17281 }; 17282 17283 #define ADD_UPLINK_TESTCASE(data) \ 17284 TEST_CASE_NAMED_WITH_DATA(data.test_descr_uplink, ut_setup_security, \ 17285 ut_teardown, test_docsis_proto_uplink, (const void *) &data), \ 17286 17287 #define ADD_DOWNLINK_TESTCASE(data) \ 17288 TEST_CASE_NAMED_WITH_DATA(data.test_descr_downlink, ut_setup_security, \ 17289 ut_teardown, test_docsis_proto_downlink, (const void *) &data), \ 17290 17291 static struct unit_test_suite docsis_proto_testsuite = { 17292 .suite_name = "DOCSIS Proto Unit Test Suite", 17293 .setup = docsis_proto_testsuite_setup, 17294 .unit_test_cases = { 17295 /* Uplink */ 17296 ADD_UPLINK_TESTCASE(docsis_test_case_1) 17297 ADD_UPLINK_TESTCASE(docsis_test_case_2) 17298 ADD_UPLINK_TESTCASE(docsis_test_case_3) 17299 ADD_UPLINK_TESTCASE(docsis_test_case_4) 17300 ADD_UPLINK_TESTCASE(docsis_test_case_5) 17301 ADD_UPLINK_TESTCASE(docsis_test_case_6) 17302 ADD_UPLINK_TESTCASE(docsis_test_case_7) 17303 ADD_UPLINK_TESTCASE(docsis_test_case_8) 17304 ADD_UPLINK_TESTCASE(docsis_test_case_9) 17305 ADD_UPLINK_TESTCASE(docsis_test_case_10) 17306 ADD_UPLINK_TESTCASE(docsis_test_case_11) 17307 ADD_UPLINK_TESTCASE(docsis_test_case_12) 17308 ADD_UPLINK_TESTCASE(docsis_test_case_13) 17309 ADD_UPLINK_TESTCASE(docsis_test_case_14) 17310 ADD_UPLINK_TESTCASE(docsis_test_case_15) 17311 ADD_UPLINK_TESTCASE(docsis_test_case_16) 17312 ADD_UPLINK_TESTCASE(docsis_test_case_17) 17313 ADD_UPLINK_TESTCASE(docsis_test_case_18) 17314 ADD_UPLINK_TESTCASE(docsis_test_case_19) 17315 ADD_UPLINK_TESTCASE(docsis_test_case_20) 17316 ADD_UPLINK_TESTCASE(docsis_test_case_21) 17317 ADD_UPLINK_TESTCASE(docsis_test_case_22) 17318 ADD_UPLINK_TESTCASE(docsis_test_case_23) 17319 ADD_UPLINK_TESTCASE(docsis_test_case_24) 17320 ADD_UPLINK_TESTCASE(docsis_test_case_25) 17321 ADD_UPLINK_TESTCASE(docsis_test_case_26) 17322 /* Downlink */ 17323 ADD_DOWNLINK_TESTCASE(docsis_test_case_1) 17324 ADD_DOWNLINK_TESTCASE(docsis_test_case_2) 17325 ADD_DOWNLINK_TESTCASE(docsis_test_case_3) 17326 ADD_DOWNLINK_TESTCASE(docsis_test_case_4) 17327 ADD_DOWNLINK_TESTCASE(docsis_test_case_5) 17328 ADD_DOWNLINK_TESTCASE(docsis_test_case_6) 17329 ADD_DOWNLINK_TESTCASE(docsis_test_case_7) 17330 ADD_DOWNLINK_TESTCASE(docsis_test_case_8) 17331 ADD_DOWNLINK_TESTCASE(docsis_test_case_9) 17332 ADD_DOWNLINK_TESTCASE(docsis_test_case_10) 17333 ADD_DOWNLINK_TESTCASE(docsis_test_case_11) 17334 ADD_DOWNLINK_TESTCASE(docsis_test_case_12) 17335 ADD_DOWNLINK_TESTCASE(docsis_test_case_13) 17336 ADD_DOWNLINK_TESTCASE(docsis_test_case_14) 17337 ADD_DOWNLINK_TESTCASE(docsis_test_case_15) 17338 ADD_DOWNLINK_TESTCASE(docsis_test_case_16) 17339 ADD_DOWNLINK_TESTCASE(docsis_test_case_17) 17340 ADD_DOWNLINK_TESTCASE(docsis_test_case_18) 17341 ADD_DOWNLINK_TESTCASE(docsis_test_case_19) 17342 ADD_DOWNLINK_TESTCASE(docsis_test_case_20) 17343 ADD_DOWNLINK_TESTCASE(docsis_test_case_21) 17344 ADD_DOWNLINK_TESTCASE(docsis_test_case_22) 17345 ADD_DOWNLINK_TESTCASE(docsis_test_case_23) 17346 ADD_DOWNLINK_TESTCASE(docsis_test_case_24) 17347 ADD_DOWNLINK_TESTCASE(docsis_test_case_25) 17348 ADD_DOWNLINK_TESTCASE(docsis_test_case_26) 17349 TEST_CASES_END() /**< NULL terminate unit test array */ 17350 } 17351 }; 17352 #endif 17353 17354 static struct unit_test_suite cryptodev_gen_testsuite = { 17355 .suite_name = "Crypto General Unit Test Suite", 17356 .setup = crypto_gen_testsuite_setup, 17357 .unit_test_cases = { 17358 TEST_CASE_ST(ut_setup, ut_teardown, 17359 test_device_reconfigure), 17360 TEST_CASE_ST(ut_setup, ut_teardown, 17361 test_device_configure_invalid_dev_id), 17362 TEST_CASE_ST(ut_setup, ut_teardown, 17363 test_queue_pair_descriptor_setup), 17364 TEST_CASE_ST(ut_setup, ut_teardown, 17365 test_device_configure_invalid_queue_pair_ids), 17366 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 17367 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup), 17368 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup), 17369 TEST_CASES_END() /**< NULL terminate unit test array */ 17370 } 17371 }; 17372 17373 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = { 17374 .suite_name = "Negative HMAC SHA1 Unit Test Suite", 17375 .setup = negative_hmac_sha1_testsuite_setup, 17376 .unit_test_cases = { 17377 /** Negative tests */ 17378 TEST_CASE_ST(ut_setup, ut_teardown, 17379 authentication_verify_HMAC_SHA1_fail_data_corrupt), 17380 TEST_CASE_ST(ut_setup, ut_teardown, 17381 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 17382 TEST_CASE_ST(ut_setup, ut_teardown, 17383 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 17384 TEST_CASE_ST(ut_setup, ut_teardown, 17385 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 17386 17387 TEST_CASES_END() /**< NULL terminate unit test array */ 17388 } 17389 }; 17390 17391 static struct unit_test_suite cryptodev_multi_session_testsuite = { 17392 .suite_name = "Multi Session Unit Test Suite", 17393 .setup = multi_session_testsuite_setup, 17394 .unit_test_cases = { 17395 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 17396 TEST_CASE_ST(ut_setup, ut_teardown, 17397 test_multi_session_random_usage), 17398 17399 TEST_CASES_END() /**< NULL terminate unit test array */ 17400 } 17401 }; 17402 17403 static struct unit_test_suite cryptodev_null_testsuite = { 17404 .suite_name = "NULL Test Suite", 17405 .setup = null_testsuite_setup, 17406 .unit_test_cases = { 17407 TEST_CASE_ST(ut_setup, ut_teardown, 17408 test_null_invalid_operation), 17409 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation), 17410 TEST_CASES_END() 17411 } 17412 }; 17413 17414 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite = { 17415 .suite_name = "AES CCM Authenticated Test Suite", 17416 .setup = aes_ccm_auth_testsuite_setup, 17417 .unit_test_cases = { 17418 /** AES CCM Authenticated Encryption 128 bits key*/ 17419 TEST_CASE_ST(ut_setup, ut_teardown, 17420 test_AES_CCM_authenticated_encryption_test_case_128_1), 17421 TEST_CASE_ST(ut_setup, ut_teardown, 17422 test_AES_CCM_authenticated_encryption_test_case_128_2), 17423 TEST_CASE_ST(ut_setup, ut_teardown, 17424 test_AES_CCM_authenticated_encryption_test_case_128_3), 17425 17426 /** AES CCM Authenticated Decryption 128 bits key*/ 17427 TEST_CASE_ST(ut_setup, ut_teardown, 17428 test_AES_CCM_authenticated_decryption_test_case_128_1), 17429 TEST_CASE_ST(ut_setup, ut_teardown, 17430 test_AES_CCM_authenticated_decryption_test_case_128_2), 17431 TEST_CASE_ST(ut_setup, ut_teardown, 17432 test_AES_CCM_authenticated_decryption_test_case_128_3), 17433 17434 /** AES CCM Authenticated Encryption 192 bits key */ 17435 TEST_CASE_ST(ut_setup, ut_teardown, 17436 test_AES_CCM_authenticated_encryption_test_case_192_1), 17437 TEST_CASE_ST(ut_setup, ut_teardown, 17438 test_AES_CCM_authenticated_encryption_test_case_192_2), 17439 TEST_CASE_ST(ut_setup, ut_teardown, 17440 test_AES_CCM_authenticated_encryption_test_case_192_3), 17441 17442 /** AES CCM Authenticated Decryption 192 bits key*/ 17443 TEST_CASE_ST(ut_setup, ut_teardown, 17444 test_AES_CCM_authenticated_decryption_test_case_192_1), 17445 TEST_CASE_ST(ut_setup, ut_teardown, 17446 test_AES_CCM_authenticated_decryption_test_case_192_2), 17447 TEST_CASE_ST(ut_setup, ut_teardown, 17448 test_AES_CCM_authenticated_decryption_test_case_192_3), 17449 17450 /** AES CCM Authenticated Encryption 256 bits key */ 17451 TEST_CASE_ST(ut_setup, ut_teardown, 17452 test_AES_CCM_authenticated_encryption_test_case_256_1), 17453 TEST_CASE_ST(ut_setup, ut_teardown, 17454 test_AES_CCM_authenticated_encryption_test_case_256_2), 17455 TEST_CASE_ST(ut_setup, ut_teardown, 17456 test_AES_CCM_authenticated_encryption_test_case_256_3), 17457 17458 /** AES CCM Authenticated Decryption 256 bits key*/ 17459 TEST_CASE_ST(ut_setup, ut_teardown, 17460 test_AES_CCM_authenticated_decryption_test_case_256_1), 17461 TEST_CASE_ST(ut_setup, ut_teardown, 17462 test_AES_CCM_authenticated_decryption_test_case_256_2), 17463 TEST_CASE_ST(ut_setup, ut_teardown, 17464 test_AES_CCM_authenticated_decryption_test_case_256_3), 17465 TEST_CASES_END() 17466 } 17467 }; 17468 17469 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite = { 17470 .suite_name = "AES GCM Authenticated Test Suite", 17471 .setup = aes_gcm_auth_testsuite_setup, 17472 .unit_test_cases = { 17473 /** AES GCM Authenticated Encryption */ 17474 TEST_CASE_ST(ut_setup, ut_teardown, 17475 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 17476 TEST_CASE_ST(ut_setup, ut_teardown, 17477 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 17478 TEST_CASE_ST(ut_setup, ut_teardown, 17479 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 17480 TEST_CASE_ST(ut_setup, ut_teardown, 17481 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 17482 TEST_CASE_ST(ut_setup, ut_teardown, 17483 test_AES_GCM_authenticated_encryption_test_case_1), 17484 TEST_CASE_ST(ut_setup, ut_teardown, 17485 test_AES_GCM_authenticated_encryption_test_case_2), 17486 TEST_CASE_ST(ut_setup, ut_teardown, 17487 test_AES_GCM_authenticated_encryption_test_case_3), 17488 TEST_CASE_ST(ut_setup, ut_teardown, 17489 test_AES_GCM_authenticated_encryption_test_case_4), 17490 TEST_CASE_ST(ut_setup, ut_teardown, 17491 test_AES_GCM_authenticated_encryption_test_case_5), 17492 TEST_CASE_ST(ut_setup, ut_teardown, 17493 test_AES_GCM_authenticated_encryption_test_case_6), 17494 TEST_CASE_ST(ut_setup, ut_teardown, 17495 test_AES_GCM_authenticated_encryption_test_case_7), 17496 TEST_CASE_ST(ut_setup, ut_teardown, 17497 test_AES_GCM_authenticated_encryption_test_case_8), 17498 TEST_CASE_ST(ut_setup, ut_teardown, 17499 test_AES_GCM_J0_authenticated_encryption_test_case_1), 17500 17501 /** AES GCM Authenticated Decryption */ 17502 TEST_CASE_ST(ut_setup, ut_teardown, 17503 test_AES_GCM_authenticated_decryption_test_case_1), 17504 TEST_CASE_ST(ut_setup, ut_teardown, 17505 test_AES_GCM_authenticated_decryption_test_case_2), 17506 TEST_CASE_ST(ut_setup, ut_teardown, 17507 test_AES_GCM_authenticated_decryption_test_case_3), 17508 TEST_CASE_ST(ut_setup, ut_teardown, 17509 test_AES_GCM_authenticated_decryption_test_case_4), 17510 TEST_CASE_ST(ut_setup, ut_teardown, 17511 test_AES_GCM_authenticated_decryption_test_case_5), 17512 TEST_CASE_ST(ut_setup, ut_teardown, 17513 test_AES_GCM_authenticated_decryption_test_case_6), 17514 TEST_CASE_ST(ut_setup, ut_teardown, 17515 test_AES_GCM_authenticated_decryption_test_case_7), 17516 TEST_CASE_ST(ut_setup, ut_teardown, 17517 test_AES_GCM_authenticated_decryption_test_case_8), 17518 TEST_CASE_ST(ut_setup, ut_teardown, 17519 test_AES_GCM_J0_authenticated_decryption_test_case_1), 17520 17521 /** AES GCM Authenticated Encryption 192 bits key */ 17522 TEST_CASE_ST(ut_setup, ut_teardown, 17523 test_AES_GCM_auth_encryption_test_case_192_1), 17524 TEST_CASE_ST(ut_setup, ut_teardown, 17525 test_AES_GCM_auth_encryption_test_case_192_2), 17526 TEST_CASE_ST(ut_setup, ut_teardown, 17527 test_AES_GCM_auth_encryption_test_case_192_3), 17528 TEST_CASE_ST(ut_setup, ut_teardown, 17529 test_AES_GCM_auth_encryption_test_case_192_4), 17530 TEST_CASE_ST(ut_setup, ut_teardown, 17531 test_AES_GCM_auth_encryption_test_case_192_5), 17532 TEST_CASE_ST(ut_setup, ut_teardown, 17533 test_AES_GCM_auth_encryption_test_case_192_6), 17534 TEST_CASE_ST(ut_setup, ut_teardown, 17535 test_AES_GCM_auth_encryption_test_case_192_7), 17536 17537 /** AES GCM Authenticated Decryption 192 bits key */ 17538 TEST_CASE_ST(ut_setup, ut_teardown, 17539 test_AES_GCM_auth_decryption_test_case_192_1), 17540 TEST_CASE_ST(ut_setup, ut_teardown, 17541 test_AES_GCM_auth_decryption_test_case_192_2), 17542 TEST_CASE_ST(ut_setup, ut_teardown, 17543 test_AES_GCM_auth_decryption_test_case_192_3), 17544 TEST_CASE_ST(ut_setup, ut_teardown, 17545 test_AES_GCM_auth_decryption_test_case_192_4), 17546 TEST_CASE_ST(ut_setup, ut_teardown, 17547 test_AES_GCM_auth_decryption_test_case_192_5), 17548 TEST_CASE_ST(ut_setup, ut_teardown, 17549 test_AES_GCM_auth_decryption_test_case_192_6), 17550 TEST_CASE_ST(ut_setup, ut_teardown, 17551 test_AES_GCM_auth_decryption_test_case_192_7), 17552 17553 /** AES GCM Authenticated Encryption 256 bits key */ 17554 TEST_CASE_ST(ut_setup, ut_teardown, 17555 test_AES_GCM_auth_encryption_test_case_256_1), 17556 TEST_CASE_ST(ut_setup, ut_teardown, 17557 test_AES_GCM_auth_encryption_test_case_256_2), 17558 TEST_CASE_ST(ut_setup, ut_teardown, 17559 test_AES_GCM_auth_encryption_test_case_256_3), 17560 TEST_CASE_ST(ut_setup, ut_teardown, 17561 test_AES_GCM_auth_encryption_test_case_256_4), 17562 TEST_CASE_ST(ut_setup, ut_teardown, 17563 test_AES_GCM_auth_encryption_test_case_256_5), 17564 TEST_CASE_ST(ut_setup, ut_teardown, 17565 test_AES_GCM_auth_encryption_test_case_256_6), 17566 TEST_CASE_ST(ut_setup, ut_teardown, 17567 test_AES_GCM_auth_encryption_test_case_256_7), 17568 TEST_CASE_ST(ut_setup, ut_teardown, 17569 test_AES_GCM_auth_encryption_test_case_256_8), 17570 17571 /** AES GCM Authenticated Decryption 256 bits key */ 17572 TEST_CASE_ST(ut_setup, ut_teardown, 17573 test_AES_GCM_auth_decryption_test_case_256_1), 17574 TEST_CASE_ST(ut_setup, ut_teardown, 17575 test_AES_GCM_auth_decryption_test_case_256_2), 17576 TEST_CASE_ST(ut_setup, ut_teardown, 17577 test_AES_GCM_auth_decryption_test_case_256_3), 17578 TEST_CASE_ST(ut_setup, ut_teardown, 17579 test_AES_GCM_auth_decryption_test_case_256_4), 17580 TEST_CASE_ST(ut_setup, ut_teardown, 17581 test_AES_GCM_auth_decryption_test_case_256_5), 17582 TEST_CASE_ST(ut_setup, ut_teardown, 17583 test_AES_GCM_auth_decryption_test_case_256_6), 17584 TEST_CASE_ST(ut_setup, ut_teardown, 17585 test_AES_GCM_auth_decryption_test_case_256_7), 17586 TEST_CASE_ST(ut_setup, ut_teardown, 17587 test_AES_GCM_auth_decryption_test_case_256_8), 17588 17589 /** AES GCM Authenticated Encryption big aad size */ 17590 TEST_CASE_ST(ut_setup, ut_teardown, 17591 test_AES_GCM_auth_encryption_test_case_aad_1), 17592 TEST_CASE_ST(ut_setup, ut_teardown, 17593 test_AES_GCM_auth_encryption_test_case_aad_2), 17594 17595 /** AES GCM Authenticated Decryption big aad size */ 17596 TEST_CASE_ST(ut_setup, ut_teardown, 17597 test_AES_GCM_auth_decryption_test_case_aad_1), 17598 TEST_CASE_ST(ut_setup, ut_teardown, 17599 test_AES_GCM_auth_decryption_test_case_aad_2), 17600 17601 /** Out of place tests */ 17602 TEST_CASE_ST(ut_setup, ut_teardown, 17603 test_AES_GCM_authenticated_encryption_oop_test_case_1), 17604 TEST_CASE_ST(ut_setup, ut_teardown, 17605 test_AES_GCM_authenticated_decryption_oop_test_case_1), 17606 17607 /** Session-less tests */ 17608 TEST_CASE_ST(ut_setup, ut_teardown, 17609 test_AES_GCM_authenticated_encryption_sessionless_test_case_1), 17610 TEST_CASE_ST(ut_setup, ut_teardown, 17611 test_AES_GCM_authenticated_decryption_sessionless_test_case_1), 17612 17613 /** AES GCM external mbuf tests */ 17614 TEST_CASE_ST(ut_setup, ut_teardown, 17615 test_AES_GCM_authenticated_encryption_test_case_3_ext_mbuf), 17616 TEST_CASE_ST(ut_setup, ut_teardown, 17617 test_AES_GCM_authenticated_decryption_test_case_3_ext_mbuf), 17618 17619 TEST_CASES_END() 17620 } 17621 }; 17622 17623 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite = { 17624 .suite_name = "AES GMAC Authentication Test Suite", 17625 .setup = aes_gmac_auth_testsuite_setup, 17626 .unit_test_cases = { 17627 TEST_CASE_ST(ut_setup, ut_teardown, 17628 test_AES_GMAC_authentication_test_case_1), 17629 TEST_CASE_ST(ut_setup, ut_teardown, 17630 test_AES_GMAC_authentication_verify_test_case_1), 17631 TEST_CASE_ST(ut_setup, ut_teardown, 17632 test_AES_GMAC_authentication_test_case_2), 17633 TEST_CASE_ST(ut_setup, ut_teardown, 17634 test_AES_GMAC_authentication_verify_test_case_2), 17635 TEST_CASE_ST(ut_setup, ut_teardown, 17636 test_AES_GMAC_authentication_test_case_3), 17637 TEST_CASE_ST(ut_setup, ut_teardown, 17638 test_AES_GMAC_authentication_verify_test_case_3), 17639 TEST_CASE_ST(ut_setup, ut_teardown, 17640 test_AES_GMAC_authentication_test_case_4), 17641 TEST_CASE_ST(ut_setup, ut_teardown, 17642 test_AES_GMAC_authentication_verify_test_case_4), 17643 TEST_CASE_ST(ut_setup, ut_teardown, 17644 test_AES_GMAC_authentication_SGL_40B), 17645 TEST_CASE_ST(ut_setup, ut_teardown, 17646 test_AES_GMAC_authentication_SGL_80B), 17647 TEST_CASE_ST(ut_setup, ut_teardown, 17648 test_AES_GMAC_authentication_SGL_2048B), 17649 TEST_CASE_ST(ut_setup, ut_teardown, 17650 test_AES_GMAC_authentication_SGL_2047B), 17651 17652 TEST_CASES_END() 17653 } 17654 }; 17655 17656 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite = { 17657 .suite_name = "Chacha20-Poly1305 Test Suite", 17658 .setup = chacha20_poly1305_testsuite_setup, 17659 .unit_test_cases = { 17660 TEST_CASE_ST(ut_setup, ut_teardown, 17661 test_chacha20_poly1305_encrypt_test_case_rfc8439), 17662 TEST_CASE_ST(ut_setup, ut_teardown, 17663 test_chacha20_poly1305_decrypt_test_case_rfc8439), 17664 TEST_CASE_ST(ut_setup, ut_teardown, 17665 test_chacha20_poly1305_encrypt_SGL_out_of_place), 17666 TEST_CASES_END() 17667 } 17668 }; 17669 17670 static struct unit_test_suite cryptodev_snow3g_testsuite = { 17671 .suite_name = "SNOW 3G Test Suite", 17672 .setup = snow3g_testsuite_setup, 17673 .unit_test_cases = { 17674 /** SNOW 3G encrypt only (UEA2) */ 17675 TEST_CASE_ST(ut_setup, ut_teardown, 17676 test_snow3g_encryption_test_case_1), 17677 TEST_CASE_ST(ut_setup, ut_teardown, 17678 test_snow3g_encryption_test_case_2), 17679 TEST_CASE_ST(ut_setup, ut_teardown, 17680 test_snow3g_encryption_test_case_3), 17681 TEST_CASE_ST(ut_setup, ut_teardown, 17682 test_snow3g_encryption_test_case_4), 17683 TEST_CASE_ST(ut_setup, ut_teardown, 17684 test_snow3g_encryption_test_case_5), 17685 17686 TEST_CASE_ST(ut_setup, ut_teardown, 17687 test_snow3g_encryption_test_case_1_oop), 17688 TEST_CASE_ST(ut_setup, ut_teardown, 17689 test_snow3g_encryption_test_case_1_oop_sgl), 17690 TEST_CASE_ST(ut_setup, ut_teardown, 17691 test_snow3g_encryption_test_case_1_oop_lb_in_sgl_out), 17692 TEST_CASE_ST(ut_setup, ut_teardown, 17693 test_snow3g_encryption_test_case_1_oop_sgl_in_lb_out), 17694 TEST_CASE_ST(ut_setup, ut_teardown, 17695 test_snow3g_encryption_test_case_1_offset_oop), 17696 TEST_CASE_ST(ut_setup, ut_teardown, 17697 test_snow3g_decryption_test_case_1_oop), 17698 17699 /** SNOW 3G generate auth, then encrypt (UEA2) */ 17700 TEST_CASE_ST(ut_setup, ut_teardown, 17701 test_snow3g_auth_cipher_test_case_1), 17702 TEST_CASE_ST(ut_setup, ut_teardown, 17703 test_snow3g_auth_cipher_test_case_2), 17704 TEST_CASE_ST(ut_setup, ut_teardown, 17705 test_snow3g_auth_cipher_test_case_2_oop), 17706 TEST_CASE_ST(ut_setup, ut_teardown, 17707 test_snow3g_auth_cipher_part_digest_enc), 17708 TEST_CASE_ST(ut_setup, ut_teardown, 17709 test_snow3g_auth_cipher_part_digest_enc_oop), 17710 TEST_CASE_ST(ut_setup, ut_teardown, 17711 test_snow3g_auth_cipher_test_case_3_sgl), 17712 TEST_CASE_ST(ut_setup, ut_teardown, 17713 test_snow3g_auth_cipher_test_case_3_oop_sgl), 17714 TEST_CASE_ST(ut_setup, ut_teardown, 17715 test_snow3g_auth_cipher_part_digest_enc_sgl), 17716 TEST_CASE_ST(ut_setup, ut_teardown, 17717 test_snow3g_auth_cipher_part_digest_enc_oop_sgl), 17718 TEST_CASE_ST(ut_setup, ut_teardown, 17719 test_snow3g_auth_cipher_total_digest_enc_1), 17720 TEST_CASE_ST(ut_setup, ut_teardown, 17721 test_snow3g_auth_cipher_total_digest_enc_1_oop), 17722 TEST_CASE_ST(ut_setup, ut_teardown, 17723 test_snow3g_auth_cipher_total_digest_enc_1_sgl), 17724 TEST_CASE_ST(ut_setup, ut_teardown, 17725 test_snow3g_auth_cipher_total_digest_enc_1_oop_sgl), 17726 17727 /** SNOW 3G decrypt (UEA2), then verify auth */ 17728 TEST_CASE_ST(ut_setup, ut_teardown, 17729 test_snow3g_auth_cipher_verify_test_case_1), 17730 TEST_CASE_ST(ut_setup, ut_teardown, 17731 test_snow3g_auth_cipher_verify_test_case_2), 17732 TEST_CASE_ST(ut_setup, ut_teardown, 17733 test_snow3g_auth_cipher_verify_test_case_2_oop), 17734 TEST_CASE_ST(ut_setup, ut_teardown, 17735 test_snow3g_auth_cipher_verify_part_digest_enc), 17736 TEST_CASE_ST(ut_setup, ut_teardown, 17737 test_snow3g_auth_cipher_verify_part_digest_enc_oop), 17738 TEST_CASE_ST(ut_setup, ut_teardown, 17739 test_snow3g_auth_cipher_verify_test_case_3_sgl), 17740 TEST_CASE_ST(ut_setup, ut_teardown, 17741 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl), 17742 TEST_CASE_ST(ut_setup, ut_teardown, 17743 test_snow3g_auth_cipher_verify_part_digest_enc_sgl), 17744 TEST_CASE_ST(ut_setup, ut_teardown, 17745 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl), 17746 TEST_CASE_ST(ut_setup, ut_teardown, 17747 test_snow3g_auth_cipher_verify_total_digest_enc_1), 17748 TEST_CASE_ST(ut_setup, ut_teardown, 17749 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop), 17750 TEST_CASE_ST(ut_setup, ut_teardown, 17751 test_snow3g_auth_cipher_verify_total_digest_enc_1_sgl), 17752 TEST_CASE_ST(ut_setup, ut_teardown, 17753 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop_sgl), 17754 17755 /** SNOW 3G decrypt only (UEA2) */ 17756 TEST_CASE_ST(ut_setup, ut_teardown, 17757 test_snow3g_decryption_test_case_1), 17758 TEST_CASE_ST(ut_setup, ut_teardown, 17759 test_snow3g_decryption_test_case_2), 17760 TEST_CASE_ST(ut_setup, ut_teardown, 17761 test_snow3g_decryption_test_case_3), 17762 TEST_CASE_ST(ut_setup, ut_teardown, 17763 test_snow3g_decryption_test_case_4), 17764 TEST_CASE_ST(ut_setup, ut_teardown, 17765 test_snow3g_decryption_test_case_5), 17766 TEST_CASE_ST(ut_setup, ut_teardown, 17767 test_snow3g_decryption_with_digest_test_case_1), 17768 TEST_CASE_ST(ut_setup, ut_teardown, 17769 test_snow3g_hash_generate_test_case_1), 17770 TEST_CASE_ST(ut_setup, ut_teardown, 17771 test_snow3g_hash_generate_test_case_2), 17772 TEST_CASE_ST(ut_setup, ut_teardown, 17773 test_snow3g_hash_generate_test_case_3), 17774 17775 /* Tests with buffers which length is not byte-aligned */ 17776 TEST_CASE_ST(ut_setup, ut_teardown, 17777 test_snow3g_hash_generate_test_case_4), 17778 TEST_CASE_ST(ut_setup, ut_teardown, 17779 test_snow3g_hash_generate_test_case_5), 17780 TEST_CASE_ST(ut_setup, ut_teardown, 17781 test_snow3g_hash_generate_test_case_6), 17782 TEST_CASE_ST(ut_setup, ut_teardown, 17783 test_snow3g_hash_verify_test_case_1), 17784 TEST_CASE_ST(ut_setup, ut_teardown, 17785 test_snow3g_hash_verify_test_case_2), 17786 TEST_CASE_ST(ut_setup, ut_teardown, 17787 test_snow3g_hash_verify_test_case_3), 17788 17789 /* Tests with buffers which length is not byte-aligned */ 17790 TEST_CASE_ST(ut_setup, ut_teardown, 17791 test_snow3g_hash_verify_test_case_4), 17792 TEST_CASE_ST(ut_setup, ut_teardown, 17793 test_snow3g_hash_verify_test_case_5), 17794 TEST_CASE_ST(ut_setup, ut_teardown, 17795 test_snow3g_hash_verify_test_case_6), 17796 TEST_CASE_ST(ut_setup, ut_teardown, 17797 test_snow3g_cipher_auth_test_case_1), 17798 TEST_CASE_ST(ut_setup, ut_teardown, 17799 test_snow3g_auth_cipher_with_digest_test_case_1), 17800 TEST_CASES_END() 17801 } 17802 }; 17803 17804 static struct unit_test_suite cryptodev_zuc_testsuite = { 17805 .suite_name = "ZUC Test Suite", 17806 .setup = zuc_testsuite_setup, 17807 .unit_test_cases = { 17808 /** ZUC encrypt only (EEA3) */ 17809 TEST_CASE_ST(ut_setup, ut_teardown, 17810 test_zuc_encryption_test_case_1), 17811 TEST_CASE_ST(ut_setup, ut_teardown, 17812 test_zuc_encryption_test_case_2), 17813 TEST_CASE_ST(ut_setup, ut_teardown, 17814 test_zuc_encryption_test_case_3), 17815 TEST_CASE_ST(ut_setup, ut_teardown, 17816 test_zuc_encryption_test_case_4), 17817 TEST_CASE_ST(ut_setup, ut_teardown, 17818 test_zuc_encryption_test_case_5), 17819 TEST_CASE_ST(ut_setup, ut_teardown, 17820 test_zuc_encryption_test_case_6_sgl), 17821 17822 /** ZUC decrypt only (EEA3) */ 17823 TEST_CASE_ST(ut_setup, ut_teardown, 17824 test_zuc_decryption_test_case_1), 17825 TEST_CASE_ST(ut_setup, ut_teardown, 17826 test_zuc_decryption_test_case_2), 17827 TEST_CASE_ST(ut_setup, ut_teardown, 17828 test_zuc_decryption_test_case_3), 17829 TEST_CASE_ST(ut_setup, ut_teardown, 17830 test_zuc_decryption_test_case_4), 17831 TEST_CASE_ST(ut_setup, ut_teardown, 17832 test_zuc_decryption_test_case_5), 17833 TEST_CASE_ST(ut_setup, ut_teardown, 17834 test_zuc_decryption_test_case_6_sgl), 17835 17836 /** ZUC authenticate (EIA3) */ 17837 TEST_CASE_ST(ut_setup, ut_teardown, 17838 test_zuc_hash_generate_test_case_1), 17839 TEST_CASE_ST(ut_setup, ut_teardown, 17840 test_zuc_hash_generate_test_case_2), 17841 TEST_CASE_ST(ut_setup, ut_teardown, 17842 test_zuc_hash_generate_test_case_3), 17843 TEST_CASE_ST(ut_setup, ut_teardown, 17844 test_zuc_hash_generate_test_case_4), 17845 TEST_CASE_ST(ut_setup, ut_teardown, 17846 test_zuc_hash_generate_test_case_5), 17847 TEST_CASE_ST(ut_setup, ut_teardown, 17848 test_zuc_hash_generate_test_case_6), 17849 TEST_CASE_ST(ut_setup, ut_teardown, 17850 test_zuc_hash_generate_test_case_7), 17851 TEST_CASE_ST(ut_setup, ut_teardown, 17852 test_zuc_hash_generate_test_case_8), 17853 17854 /** ZUC verify (EIA3) */ 17855 TEST_CASE_ST(ut_setup, ut_teardown, 17856 test_zuc_hash_verify_test_case_1), 17857 TEST_CASE_ST(ut_setup, ut_teardown, 17858 test_zuc_hash_verify_test_case_2), 17859 TEST_CASE_ST(ut_setup, ut_teardown, 17860 test_zuc_hash_verify_test_case_3), 17861 TEST_CASE_ST(ut_setup, ut_teardown, 17862 test_zuc_hash_verify_test_case_4), 17863 TEST_CASE_ST(ut_setup, ut_teardown, 17864 test_zuc_hash_verify_test_case_5), 17865 TEST_CASE_ST(ut_setup, ut_teardown, 17866 test_zuc_hash_verify_test_case_6), 17867 TEST_CASE_ST(ut_setup, ut_teardown, 17868 test_zuc_hash_verify_test_case_7), 17869 TEST_CASE_ST(ut_setup, ut_teardown, 17870 test_zuc_hash_verify_test_case_8), 17871 17872 /** ZUC alg-chain (EEA3/EIA3) */ 17873 TEST_CASE_ST(ut_setup, ut_teardown, 17874 test_zuc_cipher_auth_test_case_1), 17875 TEST_CASE_ST(ut_setup, ut_teardown, 17876 test_zuc_cipher_auth_test_case_2), 17877 17878 /** ZUC generate auth, then encrypt (EEA3) */ 17879 TEST_CASE_ST(ut_setup, ut_teardown, 17880 test_zuc_auth_cipher_test_case_1), 17881 TEST_CASE_ST(ut_setup, ut_teardown, 17882 test_zuc_auth_cipher_test_case_1_oop), 17883 TEST_CASE_ST(ut_setup, ut_teardown, 17884 test_zuc_auth_cipher_test_case_1_sgl), 17885 TEST_CASE_ST(ut_setup, ut_teardown, 17886 test_zuc_auth_cipher_test_case_1_oop_sgl), 17887 TEST_CASE_ST(ut_setup, ut_teardown, 17888 test_zuc_auth_cipher_test_case_2), 17889 TEST_CASE_ST(ut_setup, ut_teardown, 17890 test_zuc_auth_cipher_test_case_2_oop), 17891 17892 /** ZUC decrypt (EEA3), then verify auth */ 17893 TEST_CASE_ST(ut_setup, ut_teardown, 17894 test_zuc_auth_cipher_verify_test_case_1), 17895 TEST_CASE_ST(ut_setup, ut_teardown, 17896 test_zuc_auth_cipher_verify_test_case_1_oop), 17897 TEST_CASE_ST(ut_setup, ut_teardown, 17898 test_zuc_auth_cipher_verify_test_case_1_sgl), 17899 TEST_CASE_ST(ut_setup, ut_teardown, 17900 test_zuc_auth_cipher_verify_test_case_1_oop_sgl), 17901 TEST_CASE_ST(ut_setup, ut_teardown, 17902 test_zuc_auth_cipher_verify_test_case_2), 17903 TEST_CASE_ST(ut_setup, ut_teardown, 17904 test_zuc_auth_cipher_verify_test_case_2_oop), 17905 17906 /** ZUC-256 encrypt only **/ 17907 TEST_CASE_ST(ut_setup, ut_teardown, 17908 test_zuc256_encryption_test_case_1), 17909 TEST_CASE_ST(ut_setup, ut_teardown, 17910 test_zuc256_encryption_test_case_2), 17911 17912 /** ZUC-256 decrypt only **/ 17913 TEST_CASE_ST(ut_setup, ut_teardown, 17914 test_zuc256_decryption_test_case_1), 17915 TEST_CASE_ST(ut_setup, ut_teardown, 17916 test_zuc256_decryption_test_case_2), 17917 17918 /** ZUC-256 authentication only **/ 17919 TEST_CASE_ST(ut_setup, ut_teardown, 17920 test_zuc256_hash_generate_4b_tag_test_case_1), 17921 TEST_CASE_ST(ut_setup, ut_teardown, 17922 test_zuc256_hash_generate_4b_tag_test_case_2), 17923 TEST_CASE_ST(ut_setup, ut_teardown, 17924 test_zuc256_hash_generate_4b_tag_test_case_3), 17925 TEST_CASE_ST(ut_setup, ut_teardown, 17926 test_zuc256_hash_generate_8b_tag_test_case_1), 17927 TEST_CASE_ST(ut_setup, ut_teardown, 17928 test_zuc256_hash_generate_16b_tag_test_case_1), 17929 17930 /** ZUC-256 authentication verify only **/ 17931 TEST_CASE_ST(ut_setup, ut_teardown, 17932 test_zuc256_hash_verify_4b_tag_test_case_1), 17933 TEST_CASE_ST(ut_setup, ut_teardown, 17934 test_zuc256_hash_verify_4b_tag_test_case_2), 17935 TEST_CASE_ST(ut_setup, ut_teardown, 17936 test_zuc256_hash_verify_4b_tag_test_case_3), 17937 TEST_CASE_ST(ut_setup, ut_teardown, 17938 test_zuc256_hash_verify_8b_tag_test_case_1), 17939 TEST_CASE_ST(ut_setup, ut_teardown, 17940 test_zuc256_hash_verify_16b_tag_test_case_1), 17941 17942 /** ZUC-256 encrypt and authenticate **/ 17943 TEST_CASE_ST(ut_setup, ut_teardown, 17944 test_zuc256_cipher_auth_4b_tag_test_case_1), 17945 TEST_CASE_ST(ut_setup, ut_teardown, 17946 test_zuc256_cipher_auth_4b_tag_test_case_2), 17947 TEST_CASE_ST(ut_setup, ut_teardown, 17948 test_zuc256_cipher_auth_8b_tag_test_case_1), 17949 TEST_CASE_ST(ut_setup, ut_teardown, 17950 test_zuc256_cipher_auth_16b_tag_test_case_1), 17951 17952 /** ZUC-256 generate auth, then encrypt */ 17953 TEST_CASE_ST(ut_setup, ut_teardown, 17954 test_zuc256_auth_cipher_4b_tag_test_case_1), 17955 TEST_CASE_ST(ut_setup, ut_teardown, 17956 test_zuc256_auth_cipher_4b_tag_test_case_2), 17957 TEST_CASE_ST(ut_setup, ut_teardown, 17958 test_zuc256_auth_cipher_8b_tag_test_case_1), 17959 TEST_CASE_ST(ut_setup, ut_teardown, 17960 test_zuc256_auth_cipher_16b_tag_test_case_1), 17961 17962 /** ZUC-256 decrypt, then verify auth */ 17963 TEST_CASE_ST(ut_setup, ut_teardown, 17964 test_zuc256_auth_cipher_verify_4b_tag_test_case_1), 17965 TEST_CASE_ST(ut_setup, ut_teardown, 17966 test_zuc256_auth_cipher_verify_4b_tag_test_case_2), 17967 TEST_CASE_ST(ut_setup, ut_teardown, 17968 test_zuc256_auth_cipher_verify_8b_tag_test_case_1), 17969 TEST_CASE_ST(ut_setup, ut_teardown, 17970 test_zuc256_auth_cipher_verify_16b_tag_test_case_1), 17971 17972 TEST_CASES_END() 17973 } 17974 }; 17975 17976 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite = { 17977 .suite_name = "HMAC_MD5 Authentication Test Suite", 17978 .setup = hmac_md5_auth_testsuite_setup, 17979 .unit_test_cases = { 17980 TEST_CASE_ST(ut_setup, ut_teardown, 17981 test_MD5_HMAC_generate_case_1), 17982 TEST_CASE_ST(ut_setup, ut_teardown, 17983 test_MD5_HMAC_verify_case_1), 17984 TEST_CASE_ST(ut_setup, ut_teardown, 17985 test_MD5_HMAC_generate_case_2), 17986 TEST_CASE_ST(ut_setup, ut_teardown, 17987 test_MD5_HMAC_verify_case_2), 17988 TEST_CASES_END() 17989 } 17990 }; 17991 17992 static struct unit_test_suite cryptodev_kasumi_testsuite = { 17993 .suite_name = "Kasumi Test Suite", 17994 .setup = kasumi_testsuite_setup, 17995 .unit_test_cases = { 17996 /** KASUMI hash only (UIA1) */ 17997 TEST_CASE_ST(ut_setup, ut_teardown, 17998 test_kasumi_hash_generate_test_case_1), 17999 TEST_CASE_ST(ut_setup, ut_teardown, 18000 test_kasumi_hash_generate_test_case_2), 18001 TEST_CASE_ST(ut_setup, ut_teardown, 18002 test_kasumi_hash_generate_test_case_3), 18003 TEST_CASE_ST(ut_setup, ut_teardown, 18004 test_kasumi_hash_generate_test_case_4), 18005 TEST_CASE_ST(ut_setup, ut_teardown, 18006 test_kasumi_hash_generate_test_case_5), 18007 TEST_CASE_ST(ut_setup, ut_teardown, 18008 test_kasumi_hash_generate_test_case_6), 18009 18010 TEST_CASE_ST(ut_setup, ut_teardown, 18011 test_kasumi_hash_verify_test_case_1), 18012 TEST_CASE_ST(ut_setup, ut_teardown, 18013 test_kasumi_hash_verify_test_case_2), 18014 TEST_CASE_ST(ut_setup, ut_teardown, 18015 test_kasumi_hash_verify_test_case_3), 18016 TEST_CASE_ST(ut_setup, ut_teardown, 18017 test_kasumi_hash_verify_test_case_4), 18018 TEST_CASE_ST(ut_setup, ut_teardown, 18019 test_kasumi_hash_verify_test_case_5), 18020 18021 /** KASUMI encrypt only (UEA1) */ 18022 TEST_CASE_ST(ut_setup, ut_teardown, 18023 test_kasumi_encryption_test_case_1), 18024 TEST_CASE_ST(ut_setup, ut_teardown, 18025 test_kasumi_encryption_test_case_1_sgl), 18026 TEST_CASE_ST(ut_setup, ut_teardown, 18027 test_kasumi_encryption_test_case_1_oop), 18028 TEST_CASE_ST(ut_setup, ut_teardown, 18029 test_kasumi_encryption_test_case_1_oop_sgl), 18030 TEST_CASE_ST(ut_setup, ut_teardown, 18031 test_kasumi_encryption_test_case_2), 18032 TEST_CASE_ST(ut_setup, ut_teardown, 18033 test_kasumi_encryption_test_case_3), 18034 TEST_CASE_ST(ut_setup, ut_teardown, 18035 test_kasumi_encryption_test_case_4), 18036 TEST_CASE_ST(ut_setup, ut_teardown, 18037 test_kasumi_encryption_test_case_5), 18038 18039 /** KASUMI decrypt only (UEA1) */ 18040 TEST_CASE_ST(ut_setup, ut_teardown, 18041 test_kasumi_decryption_test_case_1), 18042 TEST_CASE_ST(ut_setup, ut_teardown, 18043 test_kasumi_decryption_test_case_2), 18044 TEST_CASE_ST(ut_setup, ut_teardown, 18045 test_kasumi_decryption_test_case_3), 18046 TEST_CASE_ST(ut_setup, ut_teardown, 18047 test_kasumi_decryption_test_case_4), 18048 TEST_CASE_ST(ut_setup, ut_teardown, 18049 test_kasumi_decryption_test_case_5), 18050 TEST_CASE_ST(ut_setup, ut_teardown, 18051 test_kasumi_decryption_test_case_1_oop), 18052 TEST_CASE_ST(ut_setup, ut_teardown, 18053 test_kasumi_cipher_auth_test_case_1), 18054 18055 /** KASUMI generate auth, then encrypt (F8) */ 18056 TEST_CASE_ST(ut_setup, ut_teardown, 18057 test_kasumi_auth_cipher_test_case_1), 18058 TEST_CASE_ST(ut_setup, ut_teardown, 18059 test_kasumi_auth_cipher_test_case_2), 18060 TEST_CASE_ST(ut_setup, ut_teardown, 18061 test_kasumi_auth_cipher_test_case_2_oop), 18062 TEST_CASE_ST(ut_setup, ut_teardown, 18063 test_kasumi_auth_cipher_test_case_2_sgl), 18064 TEST_CASE_ST(ut_setup, ut_teardown, 18065 test_kasumi_auth_cipher_test_case_2_oop_sgl), 18066 18067 /** KASUMI decrypt (F8), then verify auth */ 18068 TEST_CASE_ST(ut_setup, ut_teardown, 18069 test_kasumi_auth_cipher_verify_test_case_1), 18070 TEST_CASE_ST(ut_setup, ut_teardown, 18071 test_kasumi_auth_cipher_verify_test_case_2), 18072 TEST_CASE_ST(ut_setup, ut_teardown, 18073 test_kasumi_auth_cipher_verify_test_case_2_oop), 18074 TEST_CASE_ST(ut_setup, ut_teardown, 18075 test_kasumi_auth_cipher_verify_test_case_2_sgl), 18076 TEST_CASE_ST(ut_setup, ut_teardown, 18077 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl), 18078 18079 TEST_CASES_END() 18080 } 18081 }; 18082 18083 static struct unit_test_suite cryptodev_esn_testsuite = { 18084 .suite_name = "ESN Test Suite", 18085 .setup = esn_testsuite_setup, 18086 .unit_test_cases = { 18087 TEST_CASE_ST(ut_setup, ut_teardown, 18088 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 18089 TEST_CASE_ST(ut_setup, ut_teardown, 18090 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 18091 TEST_CASES_END() 18092 } 18093 }; 18094 18095 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite = { 18096 .suite_name = "Negative AES GCM Test Suite", 18097 .setup = negative_aes_gcm_testsuite_setup, 18098 .unit_test_cases = { 18099 TEST_CASE_ST(ut_setup, ut_teardown, 18100 test_AES_GCM_auth_encryption_fail_iv_corrupt), 18101 TEST_CASE_ST(ut_setup, ut_teardown, 18102 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 18103 TEST_CASE_ST(ut_setup, ut_teardown, 18104 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 18105 TEST_CASE_ST(ut_setup, ut_teardown, 18106 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 18107 TEST_CASE_ST(ut_setup, ut_teardown, 18108 test_AES_GCM_auth_encryption_fail_aad_corrupt), 18109 TEST_CASE_ST(ut_setup, ut_teardown, 18110 test_AES_GCM_auth_encryption_fail_tag_corrupt), 18111 TEST_CASE_ST(ut_setup, ut_teardown, 18112 test_AES_GCM_auth_decryption_fail_iv_corrupt), 18113 TEST_CASE_ST(ut_setup, ut_teardown, 18114 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 18115 TEST_CASE_ST(ut_setup, ut_teardown, 18116 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 18117 TEST_CASE_ST(ut_setup, ut_teardown, 18118 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 18119 TEST_CASE_ST(ut_setup, ut_teardown, 18120 test_AES_GCM_auth_decryption_fail_aad_corrupt), 18121 TEST_CASE_ST(ut_setup, ut_teardown, 18122 test_AES_GCM_auth_decryption_fail_tag_corrupt), 18123 18124 TEST_CASES_END() 18125 } 18126 }; 18127 18128 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite = { 18129 .suite_name = "Negative AES GMAC Test Suite", 18130 .setup = negative_aes_gmac_testsuite_setup, 18131 .unit_test_cases = { 18132 TEST_CASE_ST(ut_setup, ut_teardown, 18133 authentication_verify_AES128_GMAC_fail_data_corrupt), 18134 TEST_CASE_ST(ut_setup, ut_teardown, 18135 authentication_verify_AES128_GMAC_fail_tag_corrupt), 18136 18137 TEST_CASES_END() 18138 } 18139 }; 18140 18141 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite = { 18142 .suite_name = "Mixed CIPHER + HASH algorithms Test Suite", 18143 .setup = mixed_cipher_hash_testsuite_setup, 18144 .unit_test_cases = { 18145 /** AUTH AES CMAC + CIPHER AES CTR */ 18146 TEST_CASE_ST(ut_setup, ut_teardown, 18147 test_aes_cmac_aes_ctr_digest_enc_test_case_1), 18148 TEST_CASE_ST(ut_setup, ut_teardown, 18149 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 18150 TEST_CASE_ST(ut_setup, ut_teardown, 18151 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 18152 TEST_CASE_ST(ut_setup, ut_teardown, 18153 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 18154 TEST_CASE_ST(ut_setup, ut_teardown, 18155 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1), 18156 TEST_CASE_ST(ut_setup, ut_teardown, 18157 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 18158 TEST_CASE_ST(ut_setup, ut_teardown, 18159 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 18160 TEST_CASE_ST(ut_setup, ut_teardown, 18161 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 18162 TEST_CASE_ST(ut_setup, ut_teardown, 18163 test_aes_cmac_aes_ctr_digest_enc_test_case_2), 18164 TEST_CASE_ST(ut_setup, ut_teardown, 18165 test_aes_cmac_aes_ctr_digest_enc_test_case_2_oop), 18166 TEST_CASE_ST(ut_setup, ut_teardown, 18167 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2), 18168 TEST_CASE_ST(ut_setup, ut_teardown, 18169 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2_oop), 18170 18171 /** AUTH ZUC + CIPHER SNOW3G */ 18172 TEST_CASE_ST(ut_setup, ut_teardown, 18173 test_auth_zuc_cipher_snow_test_case_1), 18174 TEST_CASE_ST(ut_setup, ut_teardown, 18175 test_verify_auth_zuc_cipher_snow_test_case_1), 18176 TEST_CASE_ST(ut_setup, ut_teardown, 18177 test_auth_zuc_cipher_snow_test_case_1_inplace), 18178 TEST_CASE_ST(ut_setup, ut_teardown, 18179 test_verify_auth_zuc_cipher_snow_test_case_1_inplace), 18180 /** AUTH AES CMAC + CIPHER SNOW3G */ 18181 TEST_CASE_ST(ut_setup, ut_teardown, 18182 test_auth_aes_cmac_cipher_snow_test_case_1), 18183 TEST_CASE_ST(ut_setup, ut_teardown, 18184 test_verify_auth_aes_cmac_cipher_snow_test_case_1), 18185 TEST_CASE_ST(ut_setup, ut_teardown, 18186 test_auth_aes_cmac_cipher_snow_test_case_1_inplace), 18187 TEST_CASE_ST(ut_setup, ut_teardown, 18188 test_verify_auth_aes_cmac_cipher_snow_test_case_1_inplace), 18189 /** AUTH ZUC + CIPHER AES CTR */ 18190 TEST_CASE_ST(ut_setup, ut_teardown, 18191 test_auth_zuc_cipher_aes_ctr_test_case_1), 18192 TEST_CASE_ST(ut_setup, ut_teardown, 18193 test_verify_auth_zuc_cipher_aes_ctr_test_case_1), 18194 TEST_CASE_ST(ut_setup, ut_teardown, 18195 test_auth_zuc_cipher_aes_ctr_test_case_1_inplace), 18196 TEST_CASE_ST(ut_setup, ut_teardown, 18197 test_verify_auth_zuc_cipher_aes_ctr_test_case_1_inplace), 18198 /** AUTH SNOW3G + CIPHER AES CTR */ 18199 TEST_CASE_ST(ut_setup, ut_teardown, 18200 test_auth_snow_cipher_aes_ctr_test_case_1), 18201 TEST_CASE_ST(ut_setup, ut_teardown, 18202 test_verify_auth_snow_cipher_aes_ctr_test_case_1), 18203 TEST_CASE_ST(ut_setup, ut_teardown, 18204 test_auth_snow_cipher_aes_ctr_test_case_1_inplace), 18205 TEST_CASE_ST(ut_setup, ut_teardown, 18206 test_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl), 18207 TEST_CASE_ST(ut_setup, ut_teardown, 18208 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace), 18209 TEST_CASE_ST(ut_setup, ut_teardown, 18210 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl), 18211 /** AUTH SNOW3G + CIPHER ZUC */ 18212 TEST_CASE_ST(ut_setup, ut_teardown, 18213 test_auth_snow_cipher_zuc_test_case_1), 18214 TEST_CASE_ST(ut_setup, ut_teardown, 18215 test_verify_auth_snow_cipher_zuc_test_case_1), 18216 TEST_CASE_ST(ut_setup, ut_teardown, 18217 test_auth_snow_cipher_zuc_test_case_1_inplace), 18218 TEST_CASE_ST(ut_setup, ut_teardown, 18219 test_verify_auth_snow_cipher_zuc_test_case_1_inplace), 18220 /** AUTH AES CMAC + CIPHER ZUC */ 18221 TEST_CASE_ST(ut_setup, ut_teardown, 18222 test_auth_aes_cmac_cipher_zuc_test_case_1), 18223 TEST_CASE_ST(ut_setup, ut_teardown, 18224 test_verify_auth_aes_cmac_cipher_zuc_test_case_1), 18225 TEST_CASE_ST(ut_setup, ut_teardown, 18226 test_auth_aes_cmac_cipher_zuc_test_case_1_inplace), 18227 TEST_CASE_ST(ut_setup, ut_teardown, 18228 test_verify_auth_aes_cmac_cipher_zuc_test_case_1_inplace), 18229 18230 /** AUTH NULL + CIPHER SNOW3G */ 18231 TEST_CASE_ST(ut_setup, ut_teardown, 18232 test_auth_null_cipher_snow_test_case_1), 18233 TEST_CASE_ST(ut_setup, ut_teardown, 18234 test_verify_auth_null_cipher_snow_test_case_1), 18235 /** AUTH NULL + CIPHER ZUC */ 18236 TEST_CASE_ST(ut_setup, ut_teardown, 18237 test_auth_null_cipher_zuc_test_case_1), 18238 TEST_CASE_ST(ut_setup, ut_teardown, 18239 test_verify_auth_null_cipher_zuc_test_case_1), 18240 /** AUTH SNOW3G + CIPHER NULL */ 18241 TEST_CASE_ST(ut_setup, ut_teardown, 18242 test_auth_snow_cipher_null_test_case_1), 18243 TEST_CASE_ST(ut_setup, ut_teardown, 18244 test_verify_auth_snow_cipher_null_test_case_1), 18245 /** AUTH ZUC + CIPHER NULL */ 18246 TEST_CASE_ST(ut_setup, ut_teardown, 18247 test_auth_zuc_cipher_null_test_case_1), 18248 TEST_CASE_ST(ut_setup, ut_teardown, 18249 test_verify_auth_zuc_cipher_null_test_case_1), 18250 /** AUTH NULL + CIPHER AES CTR */ 18251 TEST_CASE_ST(ut_setup, ut_teardown, 18252 test_auth_null_cipher_aes_ctr_test_case_1), 18253 TEST_CASE_ST(ut_setup, ut_teardown, 18254 test_verify_auth_null_cipher_aes_ctr_test_case_1), 18255 /** AUTH AES CMAC + CIPHER NULL */ 18256 TEST_CASE_ST(ut_setup, ut_teardown, 18257 test_auth_aes_cmac_cipher_null_test_case_1), 18258 TEST_CASE_ST(ut_setup, ut_teardown, 18259 test_verify_auth_aes_cmac_cipher_null_test_case_1), 18260 TEST_CASES_END() 18261 } 18262 }; 18263 18264 static int 18265 run_cryptodev_testsuite(const char *pmd_name) 18266 { 18267 uint8_t ret, j, i = 0, blk_start_idx = 0; 18268 const enum blockcipher_test_type blk_suites[] = { 18269 BLKCIPHER_AES_CHAIN_TYPE, 18270 BLKCIPHER_AES_CIPHERONLY_TYPE, 18271 BLKCIPHER_AES_DOCSIS_TYPE, 18272 BLKCIPHER_3DES_CHAIN_TYPE, 18273 BLKCIPHER_3DES_CIPHERONLY_TYPE, 18274 BLKCIPHER_DES_CIPHERONLY_TYPE, 18275 BLKCIPHER_DES_DOCSIS_TYPE, 18276 BLKCIPHER_SM4_CHAIN_TYPE, 18277 BLKCIPHER_SM4_CIPHERONLY_TYPE, 18278 BLKCIPHER_AUTHONLY_TYPE}; 18279 struct unit_test_suite *static_suites[] = { 18280 &cryptodev_multi_session_testsuite, 18281 &cryptodev_null_testsuite, 18282 &cryptodev_aes_ccm_auth_testsuite, 18283 &cryptodev_aes_gcm_auth_testsuite, 18284 &cryptodev_aes_gmac_auth_testsuite, 18285 &cryptodev_snow3g_testsuite, 18286 &cryptodev_chacha20_poly1305_testsuite, 18287 &cryptodev_zuc_testsuite, 18288 &cryptodev_hmac_md5_auth_testsuite, 18289 &cryptodev_kasumi_testsuite, 18290 &cryptodev_esn_testsuite, 18291 &cryptodev_negative_aes_gcm_testsuite, 18292 &cryptodev_negative_aes_gmac_testsuite, 18293 &cryptodev_mixed_cipher_hash_testsuite, 18294 &cryptodev_negative_hmac_sha1_testsuite, 18295 &cryptodev_gen_testsuite, 18296 #ifdef RTE_LIB_SECURITY 18297 &ipsec_proto_testsuite, 18298 &pdcp_proto_testsuite, 18299 &docsis_proto_testsuite, 18300 &tls12_record_proto_testsuite, 18301 &dtls12_record_proto_testsuite, 18302 #endif 18303 &end_testsuite 18304 }; 18305 static struct unit_test_suite ts = { 18306 .suite_name = "Cryptodev Unit Test Suite", 18307 .setup = testsuite_setup, 18308 .teardown = testsuite_teardown, 18309 .unit_test_cases = {TEST_CASES_END()} 18310 }; 18311 18312 gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name); 18313 18314 if (gbl_driver_id == -1) { 18315 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name); 18316 return TEST_SKIPPED; 18317 } 18318 18319 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 18320 (RTE_DIM(blk_suites) + RTE_DIM(static_suites))); 18321 18322 ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites)); 18323 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 18324 ret = unit_test_suite_runner(&ts); 18325 18326 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites)); 18327 free(ts.unit_test_suites); 18328 return ret; 18329 } 18330 18331 static int 18332 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name) 18333 { 18334 struct rte_cryptodev_info dev_info; 18335 uint8_t i, nb_devs; 18336 int driver_id; 18337 18338 driver_id = rte_cryptodev_driver_id_get(pmd_name); 18339 if (driver_id == -1) { 18340 RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name); 18341 return TEST_SKIPPED; 18342 } 18343 18344 nb_devs = rte_cryptodev_count(); 18345 if (nb_devs < 1) { 18346 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 18347 return TEST_SKIPPED; 18348 } 18349 18350 for (i = 0; i < nb_devs; i++) { 18351 rte_cryptodev_info_get(i, &dev_info); 18352 if (dev_info.driver_id == driver_id) { 18353 if (!(dev_info.feature_flags & flag)) { 18354 RTE_LOG(INFO, USER1, "%s not supported\n", 18355 flag_name); 18356 return TEST_SKIPPED; 18357 } 18358 return 0; /* found */ 18359 } 18360 } 18361 18362 RTE_LOG(INFO, USER1, "%s not supported\n", flag_name); 18363 return TEST_SKIPPED; 18364 } 18365 18366 static int 18367 test_cryptodev_qat(void) 18368 { 18369 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 18370 } 18371 18372 static int 18373 test_cryptodev_uadk(void) 18374 { 18375 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_UADK_PMD)); 18376 } 18377 18378 static int 18379 test_cryptodev_virtio(void) 18380 { 18381 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)); 18382 } 18383 18384 static int 18385 test_cryptodev_aesni_mb(void) 18386 { 18387 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 18388 } 18389 18390 static int 18391 test_cryptodev_cpu_aesni_mb(void) 18392 { 18393 int32_t rc; 18394 enum rte_security_session_action_type at = gbl_action_type; 18395 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 18396 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 18397 gbl_action_type = at; 18398 return rc; 18399 } 18400 18401 static int 18402 test_cryptodev_chacha_poly_mb(void) 18403 { 18404 int32_t rc; 18405 enum rte_security_session_action_type at = gbl_action_type; 18406 rc = run_cryptodev_testsuite( 18407 RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD)); 18408 gbl_action_type = at; 18409 return rc; 18410 } 18411 18412 static int 18413 test_cryptodev_openssl(void) 18414 { 18415 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 18416 } 18417 18418 static int 18419 test_cryptodev_aesni_gcm(void) 18420 { 18421 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 18422 } 18423 18424 static int 18425 test_cryptodev_cpu_aesni_gcm(void) 18426 { 18427 int32_t rc; 18428 enum rte_security_session_action_type at = gbl_action_type; 18429 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 18430 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 18431 gbl_action_type = at; 18432 return rc; 18433 } 18434 18435 static int 18436 test_cryptodev_mlx5(void) 18437 { 18438 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD)); 18439 } 18440 18441 static int 18442 test_cryptodev_null(void) 18443 { 18444 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 18445 } 18446 18447 static int 18448 test_cryptodev_sw_snow3g(void) 18449 { 18450 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 18451 } 18452 18453 static int 18454 test_cryptodev_sw_kasumi(void) 18455 { 18456 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 18457 } 18458 18459 static int 18460 test_cryptodev_sw_zuc(void) 18461 { 18462 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 18463 } 18464 18465 static int 18466 test_cryptodev_armv8(void) 18467 { 18468 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 18469 } 18470 18471 static int 18472 test_cryptodev_mrvl(void) 18473 { 18474 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 18475 } 18476 18477 #ifdef RTE_CRYPTO_SCHEDULER 18478 18479 static int 18480 test_cryptodev_scheduler(void) 18481 { 18482 uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0; 18483 const enum blockcipher_test_type blk_suites[] = { 18484 BLKCIPHER_AES_CHAIN_TYPE, 18485 BLKCIPHER_AES_CIPHERONLY_TYPE, 18486 BLKCIPHER_AUTHONLY_TYPE 18487 }; 18488 static struct unit_test_suite scheduler_multicore = { 18489 .suite_name = "Scheduler Multicore Unit Test Suite", 18490 .setup = scheduler_multicore_testsuite_setup, 18491 .teardown = scheduler_mode_testsuite_teardown, 18492 .unit_test_cases = {TEST_CASES_END()} 18493 }; 18494 static struct unit_test_suite scheduler_round_robin = { 18495 .suite_name = "Scheduler Round Robin Unit Test Suite", 18496 .setup = scheduler_roundrobin_testsuite_setup, 18497 .teardown = scheduler_mode_testsuite_teardown, 18498 .unit_test_cases = {TEST_CASES_END()} 18499 }; 18500 static struct unit_test_suite scheduler_failover = { 18501 .suite_name = "Scheduler Failover Unit Test Suite", 18502 .setup = scheduler_failover_testsuite_setup, 18503 .teardown = scheduler_mode_testsuite_teardown, 18504 .unit_test_cases = {TEST_CASES_END()} 18505 }; 18506 static struct unit_test_suite scheduler_pkt_size_distr = { 18507 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite", 18508 .setup = scheduler_pkt_size_distr_testsuite_setup, 18509 .teardown = scheduler_mode_testsuite_teardown, 18510 .unit_test_cases = {TEST_CASES_END()} 18511 }; 18512 struct unit_test_suite *sched_mode_suites[] = { 18513 &scheduler_multicore, 18514 &scheduler_round_robin, 18515 &scheduler_failover, 18516 &scheduler_pkt_size_distr 18517 }; 18518 static struct unit_test_suite scheduler_config = { 18519 .suite_name = "Crypto Device Scheduler Config Unit Test Suite", 18520 .unit_test_cases = { 18521 TEST_CASE(test_scheduler_attach_worker_op), 18522 TEST_CASE(test_scheduler_mode_multicore_op), 18523 TEST_CASE(test_scheduler_mode_roundrobin_op), 18524 TEST_CASE(test_scheduler_mode_failover_op), 18525 TEST_CASE(test_scheduler_mode_pkt_size_distr_op), 18526 TEST_CASE(test_scheduler_detach_worker_op), 18527 18528 TEST_CASES_END() /**< NULL terminate array */ 18529 } 18530 }; 18531 struct unit_test_suite *static_suites[] = { 18532 &scheduler_config, 18533 &end_testsuite 18534 }; 18535 struct unit_test_suite *sched_mode_static_suites[] = { 18536 #ifdef RTE_LIB_SECURITY 18537 &docsis_proto_testsuite, 18538 #endif 18539 &end_testsuite 18540 }; 18541 static struct unit_test_suite ts = { 18542 .suite_name = "Scheduler Unit Test Suite", 18543 .setup = scheduler_testsuite_setup, 18544 .teardown = testsuite_teardown, 18545 .unit_test_cases = {TEST_CASES_END()} 18546 }; 18547 18548 gbl_driver_id = rte_cryptodev_driver_id_get( 18549 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 18550 18551 if (gbl_driver_id == -1) { 18552 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n"); 18553 return TEST_SKIPPED; 18554 } 18555 18556 if (rte_cryptodev_driver_id_get( 18557 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) { 18558 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 18559 return TEST_SKIPPED; 18560 } 18561 18562 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 18563 uint8_t blk_i = 0; 18564 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof 18565 (struct unit_test_suite *) * 18566 (RTE_DIM(blk_suites) + 18567 RTE_DIM(sched_mode_static_suites) + 1)); 18568 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]), 18569 blk_suites, RTE_DIM(blk_suites)); 18570 ADD_STATIC_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]), 18571 sched_mode_static_suites, 18572 RTE_DIM(sched_mode_static_suites)); 18573 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite; 18574 } 18575 18576 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 18577 (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites))); 18578 ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites, 18579 RTE_DIM(sched_mode_suites)); 18580 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 18581 ret = unit_test_suite_runner(&ts); 18582 18583 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 18584 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, 18585 (*sched_mode_suites[sched_i]), 18586 RTE_DIM(blk_suites)); 18587 free(sched_mode_suites[sched_i]->unit_test_suites); 18588 } 18589 free(ts.unit_test_suites); 18590 return ret; 18591 } 18592 18593 REGISTER_DRIVER_TEST(cryptodev_scheduler_autotest, test_cryptodev_scheduler); 18594 18595 #endif 18596 18597 static int 18598 test_cryptodev_dpaa2_sec(void) 18599 { 18600 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 18601 } 18602 18603 static int 18604 test_cryptodev_dpaa_sec(void) 18605 { 18606 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 18607 } 18608 18609 static int 18610 test_cryptodev_ccp(void) 18611 { 18612 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 18613 } 18614 18615 static int 18616 test_cryptodev_octeontx(void) 18617 { 18618 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)); 18619 } 18620 18621 static int 18622 test_cryptodev_caam_jr(void) 18623 { 18624 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)); 18625 } 18626 18627 static int 18628 test_cryptodev_nitrox(void) 18629 { 18630 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD)); 18631 } 18632 18633 static int 18634 test_cryptodev_bcmfs(void) 18635 { 18636 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD)); 18637 } 18638 18639 static int 18640 run_cryptodev_raw_testsuite(const char *pmd_name) 18641 { 18642 int ret; 18643 18644 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, "RAW API"); 18645 if (ret) 18646 return ret; 18647 18648 global_api_test_type = CRYPTODEV_RAW_API_TEST; 18649 ret = run_cryptodev_testsuite(pmd_name); 18650 global_api_test_type = CRYPTODEV_API_TEST; 18651 18652 return ret; 18653 } 18654 18655 static int 18656 test_cryptodev_qat_raw_api(void) 18657 { 18658 return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 18659 } 18660 18661 static int 18662 test_cryptodev_cn9k(void) 18663 { 18664 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD)); 18665 } 18666 18667 static int 18668 test_cryptodev_cn10k(void) 18669 { 18670 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD)); 18671 } 18672 18673 static int 18674 test_cryptodev_cn10k_raw_api(void) 18675 { 18676 return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD)); 18677 } 18678 18679 static int 18680 test_cryptodev_dpaa2_sec_raw_api(void) 18681 { 18682 return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 18683 } 18684 18685 static int 18686 test_cryptodev_dpaa_sec_raw_api(void) 18687 { 18688 return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 18689 } 18690 18691 REGISTER_DRIVER_TEST(cryptodev_cn10k_raw_api_autotest, 18692 test_cryptodev_cn10k_raw_api); 18693 REGISTER_DRIVER_TEST(cryptodev_dpaa2_sec_raw_api_autotest, 18694 test_cryptodev_dpaa2_sec_raw_api); 18695 REGISTER_DRIVER_TEST(cryptodev_dpaa_sec_raw_api_autotest, 18696 test_cryptodev_dpaa_sec_raw_api); 18697 REGISTER_DRIVER_TEST(cryptodev_qat_raw_api_autotest, 18698 test_cryptodev_qat_raw_api); 18699 REGISTER_DRIVER_TEST(cryptodev_qat_autotest, test_cryptodev_qat); 18700 REGISTER_DRIVER_TEST(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 18701 REGISTER_DRIVER_TEST(cryptodev_cpu_aesni_mb_autotest, 18702 test_cryptodev_cpu_aesni_mb); 18703 REGISTER_DRIVER_TEST(cryptodev_chacha_poly_mb_autotest, 18704 test_cryptodev_chacha_poly_mb); 18705 REGISTER_DRIVER_TEST(cryptodev_openssl_autotest, test_cryptodev_openssl); 18706 REGISTER_DRIVER_TEST(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 18707 REGISTER_DRIVER_TEST(cryptodev_cpu_aesni_gcm_autotest, 18708 test_cryptodev_cpu_aesni_gcm); 18709 REGISTER_DRIVER_TEST(cryptodev_mlx5_autotest, test_cryptodev_mlx5); 18710 REGISTER_DRIVER_TEST(cryptodev_null_autotest, test_cryptodev_null); 18711 REGISTER_DRIVER_TEST(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 18712 REGISTER_DRIVER_TEST(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 18713 REGISTER_DRIVER_TEST(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 18714 REGISTER_DRIVER_TEST(cryptodev_sw_armv8_autotest, test_cryptodev_armv8); 18715 REGISTER_DRIVER_TEST(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl); 18716 REGISTER_DRIVER_TEST(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec); 18717 REGISTER_DRIVER_TEST(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec); 18718 REGISTER_DRIVER_TEST(cryptodev_ccp_autotest, test_cryptodev_ccp); 18719 REGISTER_DRIVER_TEST(cryptodev_uadk_autotest, test_cryptodev_uadk); 18720 REGISTER_DRIVER_TEST(cryptodev_virtio_autotest, test_cryptodev_virtio); 18721 REGISTER_DRIVER_TEST(cryptodev_octeontx_autotest, test_cryptodev_octeontx); 18722 REGISTER_DRIVER_TEST(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr); 18723 REGISTER_DRIVER_TEST(cryptodev_nitrox_autotest, test_cryptodev_nitrox); 18724 REGISTER_DRIVER_TEST(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs); 18725 REGISTER_DRIVER_TEST(cryptodev_cn9k_autotest, test_cryptodev_cn9k); 18726 REGISTER_DRIVER_TEST(cryptodev_cn10k_autotest, test_cryptodev_cn10k); 18727