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_tls.h> 25 #include <rte_udp.h> 26 27 #ifdef RTE_CRYPTO_SCHEDULER 28 #include <rte_cryptodev_scheduler.h> 29 #include <rte_cryptodev_scheduler_operations.h> 30 #endif 31 32 #include <rte_lcore.h> 33 34 #include "test.h" 35 #include "test_cryptodev.h" 36 37 #include "test_cryptodev_blockcipher.h" 38 #include "test_cryptodev_aes_test_vectors.h" 39 #include "test_cryptodev_des_test_vectors.h" 40 #include "test_cryptodev_hash_test_vectors.h" 41 #include "test_cryptodev_kasumi_test_vectors.h" 42 #include "test_cryptodev_kasumi_hash_test_vectors.h" 43 #include "test_cryptodev_snow3g_test_vectors.h" 44 #include "test_cryptodev_snow3g_hash_test_vectors.h" 45 #include "test_cryptodev_zuc_test_vectors.h" 46 #include "test_cryptodev_aead_test_vectors.h" 47 #include "test_cryptodev_hmac_test_vectors.h" 48 #include "test_cryptodev_mixed_test_vectors.h" 49 #include "test_cryptodev_sm4_test_vectors.h" 50 #ifdef RTE_LIB_SECURITY 51 #include "test_cryptodev_security_ipsec.h" 52 #include "test_cryptodev_security_ipsec_test_vectors.h" 53 #include "test_cryptodev_security_pdcp_test_vectors.h" 54 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h" 55 #include "test_cryptodev_security_pdcp_test_func.h" 56 #include "test_cryptodev_security_docsis_test_vectors.h" 57 #include "test_cryptodev_security_tls_record.h" 58 #include "test_security_proto.h" 59 60 #define SDAP_DISABLED 0 61 #define SDAP_ENABLED 1 62 #endif 63 64 #define VDEV_ARGS_SIZE 100 65 #define MAX_NB_SESSIONS 4 66 67 #define MAX_DRV_SERVICE_CTX_SIZE 256 68 69 #define MAX_RAW_DEQUEUE_COUNT 65535 70 71 #define IN_PLACE 0 72 #define OUT_OF_PLACE 1 73 74 static int gbl_driver_id; 75 76 static enum rte_security_session_action_type gbl_action_type = 77 RTE_SECURITY_ACTION_TYPE_NONE; 78 79 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST; 80 81 struct crypto_unittest_params { 82 struct rte_crypto_sym_xform cipher_xform; 83 struct rte_crypto_sym_xform auth_xform; 84 struct rte_crypto_sym_xform aead_xform; 85 #ifdef RTE_LIB_SECURITY 86 struct rte_security_docsis_xform docsis_xform; 87 #endif 88 89 union { 90 void *sess; 91 #ifdef RTE_LIB_SECURITY 92 void *sec_session; 93 #endif 94 }; 95 #ifdef RTE_LIB_SECURITY 96 enum rte_security_session_action_type type; 97 #endif 98 struct rte_crypto_op *op; 99 100 struct rte_mbuf *obuf, *ibuf; 101 102 uint8_t *digest; 103 }; 104 105 #define ALIGN_POW2_ROUNDUP(num, align) \ 106 (((num) + (align) - 1) & ~((align) - 1)) 107 108 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts) \ 109 for (j = 0; j < num_child_ts; index++, j++) \ 110 parent_ts.unit_test_suites[index] = child_ts[j] 111 112 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types) \ 113 for (j = 0; j < num_blk_types; index++, j++) \ 114 parent_ts.unit_test_suites[index] = \ 115 build_blockcipher_test_suite(blk_types[j]) 116 117 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types) \ 118 for (j = index; j < index + num_blk_types; j++) \ 119 free_blockcipher_test_suite(parent_ts.unit_test_suites[j]) 120 121 /* 122 * Forward declarations. 123 */ 124 static int 125 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 126 struct crypto_unittest_params *ut_params, uint8_t *cipher_key, 127 uint8_t *hmac_key); 128 129 static int 130 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess, 131 struct crypto_unittest_params *ut_params, 132 struct crypto_testsuite_params *ts_param, 133 const uint8_t *cipher, 134 const uint8_t *digest, 135 const uint8_t *iv); 136 137 static int 138 security_proto_supported(enum rte_security_session_action_type action, 139 enum rte_security_session_protocol proto); 140 141 static int 142 dev_configure_and_start(uint64_t ff_disable); 143 144 static int 145 check_cipher_capability(const struct crypto_testsuite_params *ts_params, 146 const enum rte_crypto_cipher_algorithm cipher_algo, 147 const uint16_t key_size, const uint16_t iv_size); 148 149 static int 150 check_auth_capability(const struct crypto_testsuite_params *ts_params, 151 const enum rte_crypto_auth_algorithm auth_algo, 152 const uint16_t key_size, const uint16_t iv_size, 153 const uint16_t tag_size); 154 155 static struct rte_mbuf * 156 setup_test_string(struct rte_mempool *mpool, 157 const char *string, size_t len, uint8_t blocksize) 158 { 159 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool); 160 size_t t_len = len - (blocksize ? (len % blocksize) : 0); 161 162 if (m) { 163 char *dst; 164 165 memset(m->buf_addr, 0, m->buf_len); 166 dst = rte_pktmbuf_append(m, t_len); 167 if (!dst) { 168 rte_pktmbuf_free(m); 169 return NULL; 170 } 171 if (string != NULL) 172 rte_memcpy(dst, string, t_len); 173 else 174 memset(dst, 0, t_len); 175 } 176 177 return m; 178 } 179 180 /* Get number of bytes in X bits (rounding up) */ 181 static uint32_t 182 ceil_byte_length(uint32_t num_bits) 183 { 184 if (num_bits % 8) 185 return ((num_bits >> 3) + 1); 186 else 187 return (num_bits >> 3); 188 } 189 190 static void 191 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused, 192 uint8_t is_op_success) 193 { 194 struct rte_crypto_op *op = user_data; 195 op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS : 196 RTE_CRYPTO_OP_STATUS_ERROR; 197 } 198 199 static struct crypto_testsuite_params testsuite_params = { NULL }; 200 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params; 201 static struct crypto_unittest_params unittest_params; 202 203 int 204 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id, 205 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth, 206 uint8_t len_in_bits, uint8_t cipher_iv_len) 207 { 208 struct rte_crypto_sym_op *sop = op->sym; 209 struct rte_crypto_op *ret_op = NULL; 210 struct rte_crypto_vec data_vec[UINT8_MAX], dest_data_vec[UINT8_MAX]; 211 struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv; 212 union rte_crypto_sym_ofs ofs; 213 struct rte_crypto_sym_vec vec; 214 struct rte_crypto_sgl sgl, dest_sgl; 215 uint32_t max_len; 216 union rte_cryptodev_session_ctx sess; 217 uint64_t auth_end_iova; 218 uint32_t count = 0; 219 struct rte_crypto_raw_dp_ctx *ctx; 220 uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0, 221 auth_len = 0; 222 int32_t n; 223 uint32_t n_success; 224 int ctx_service_size; 225 int32_t status = 0; 226 int enqueue_status, dequeue_status; 227 struct crypto_unittest_params *ut_params = &unittest_params; 228 int is_sgl = sop->m_src->nb_segs > 1; 229 int ret = TEST_SUCCESS, is_oop = 0; 230 231 ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id); 232 if (ctx_service_size < 0) 233 return TEST_SKIPPED; 234 235 ctx = malloc(ctx_service_size); 236 if (ctx == NULL) 237 return TEST_FAILED; 238 239 /* Both are enums, setting crypto_sess will suit any session type */ 240 sess.crypto_sess = op->sym->session; 241 242 ret = rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx, op->sess_type, sess, 0); 243 if (ret == -ENOTSUP) { 244 ret = TEST_SKIPPED; 245 goto exit; 246 } else if (ret) { 247 ret = TEST_FAILED; 248 goto exit; 249 } 250 251 cipher_iv.iova = 0; 252 cipher_iv.va = NULL; 253 aad_auth_iv.iova = 0; 254 aad_auth_iv.va = NULL; 255 digest.iova = 0; 256 digest.va = NULL; 257 sgl.vec = data_vec; 258 vec.num = 1; 259 vec.src_sgl = &sgl; 260 vec.iv = &cipher_iv; 261 vec.digest = &digest; 262 vec.aad = &aad_auth_iv; 263 vec.status = &status; 264 265 ofs.raw = 0; 266 267 if ((sop->m_dst != NULL) && (sop->m_dst != sop->m_src)) 268 is_oop = 1; 269 270 if (is_cipher && is_auth) { 271 cipher_offset = sop->cipher.data.offset; 272 cipher_len = sop->cipher.data.length; 273 auth_offset = sop->auth.data.offset; 274 auth_len = sop->auth.data.length; 275 max_len = RTE_MAX(cipher_offset + cipher_len, 276 auth_offset + auth_len); 277 if (len_in_bits) { 278 max_len = max_len >> 3; 279 cipher_offset = cipher_offset >> 3; 280 auth_offset = auth_offset >> 3; 281 cipher_len = cipher_len >> 3; 282 auth_len = auth_len >> 3; 283 } 284 ofs.ofs.cipher.head = cipher_offset; 285 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 286 ofs.ofs.auth.head = auth_offset; 287 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 288 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 289 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 290 aad_auth_iv.va = rte_crypto_op_ctod_offset( 291 op, void *, IV_OFFSET + cipher_iv_len); 292 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 293 cipher_iv_len); 294 digest.va = (void *)sop->auth.digest.data; 295 digest.iova = sop->auth.digest.phys_addr; 296 297 if (is_sgl) { 298 uint32_t remaining_off = auth_offset + auth_len; 299 struct rte_mbuf *sgl_buf = sop->m_src; 300 if (is_oop) 301 sgl_buf = sop->m_dst; 302 303 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf) 304 && sgl_buf->next != NULL) { 305 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 306 sgl_buf = sgl_buf->next; 307 } 308 309 auth_end_iova = (uint64_t)rte_pktmbuf_iova_offset( 310 sgl_buf, remaining_off); 311 } else { 312 auth_end_iova = rte_pktmbuf_iova(op->sym->m_src) + 313 auth_offset + auth_len; 314 } 315 /* Then check if digest-encrypted conditions are met */ 316 if ((auth_offset + auth_len < cipher_offset + cipher_len) && 317 (digest.iova == auth_end_iova) && is_sgl) 318 max_len = RTE_MAX(max_len, 319 auth_offset + auth_len + 320 ut_params->auth_xform.auth.digest_length); 321 322 } else if (is_cipher) { 323 cipher_offset = sop->cipher.data.offset; 324 cipher_len = sop->cipher.data.length; 325 max_len = cipher_len + cipher_offset; 326 if (len_in_bits) { 327 max_len = max_len >> 3; 328 cipher_offset = cipher_offset >> 3; 329 cipher_len = cipher_len >> 3; 330 } 331 ofs.ofs.cipher.head = cipher_offset; 332 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 333 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 334 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 335 336 } else if (is_auth) { 337 auth_offset = sop->auth.data.offset; 338 auth_len = sop->auth.data.length; 339 max_len = auth_len + auth_offset; 340 if (len_in_bits) { 341 max_len = max_len >> 3; 342 auth_offset = auth_offset >> 3; 343 auth_len = auth_len >> 3; 344 } 345 ofs.ofs.auth.head = auth_offset; 346 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 347 aad_auth_iv.va = rte_crypto_op_ctod_offset( 348 op, void *, IV_OFFSET + cipher_iv_len); 349 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 350 cipher_iv_len); 351 digest.va = (void *)sop->auth.digest.data; 352 digest.iova = sop->auth.digest.phys_addr; 353 354 } else { /* aead */ 355 cipher_offset = sop->aead.data.offset; 356 cipher_len = sop->aead.data.length; 357 max_len = cipher_len + cipher_offset; 358 if (len_in_bits) { 359 max_len = max_len >> 3; 360 cipher_offset = cipher_offset >> 3; 361 cipher_len = cipher_len >> 3; 362 } 363 ofs.ofs.cipher.head = cipher_offset; 364 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 365 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 366 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 367 aad_auth_iv.va = (void *)sop->aead.aad.data; 368 aad_auth_iv.iova = sop->aead.aad.phys_addr; 369 digest.va = (void *)sop->aead.digest.data; 370 digest.iova = sop->aead.digest.phys_addr; 371 } 372 373 n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len, 374 data_vec, RTE_DIM(data_vec)); 375 if (n < 0 || n > sop->m_src->nb_segs) { 376 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 377 goto exit; 378 } 379 380 sgl.num = n; 381 /* Out of place */ 382 if (is_oop) { 383 dest_sgl.vec = dest_data_vec; 384 vec.dest_sgl = &dest_sgl; 385 n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len, 386 dest_data_vec, RTE_DIM(dest_data_vec)); 387 if (n < 0 || n > sop->m_dst->nb_segs) { 388 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 389 goto exit; 390 } 391 dest_sgl.num = n; 392 } else 393 vec.dest_sgl = NULL; 394 395 if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op, 396 &enqueue_status) < 1) { 397 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 398 goto exit; 399 } 400 401 if (enqueue_status == 0) { 402 status = rte_cryptodev_raw_enqueue_done(ctx, 1); 403 if (status < 0) { 404 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 405 goto exit; 406 } 407 } else if (enqueue_status < 0) { 408 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 409 goto exit; 410 } 411 412 n = n_success = 0; 413 while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) { 414 n = rte_cryptodev_raw_dequeue_burst(ctx, 415 NULL, 1, post_process_raw_dp_op, 416 (void **)&ret_op, 0, &n_success, 417 &dequeue_status); 418 if (dequeue_status < 0) { 419 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 420 goto exit; 421 } 422 if (n == 0) 423 rte_pause(); 424 } 425 426 if (n == 1 && dequeue_status == 0) { 427 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) { 428 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 429 goto exit; 430 } 431 } 432 433 op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op || 434 ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR || 435 n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR : 436 RTE_CRYPTO_OP_STATUS_SUCCESS; 437 438 exit: 439 free(ctx); 440 return ret; 441 } 442 443 static void 444 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op) 445 { 446 int32_t n, st; 447 struct rte_crypto_sym_op *sop; 448 union rte_crypto_sym_ofs ofs; 449 struct rte_crypto_sgl sgl; 450 struct rte_crypto_sym_vec symvec; 451 struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr; 452 struct rte_crypto_vec vec[UINT8_MAX]; 453 454 sop = op->sym; 455 456 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset, 457 sop->aead.data.length, vec, RTE_DIM(vec)); 458 459 if (n < 0 || n != sop->m_src->nb_segs) { 460 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 461 return; 462 } 463 464 sgl.vec = vec; 465 sgl.num = n; 466 symvec.src_sgl = &sgl; 467 symvec.iv = &iv_ptr; 468 symvec.digest = &digest_ptr; 469 symvec.aad = &aad_ptr; 470 symvec.status = &st; 471 symvec.num = 1; 472 473 /* for CPU crypto the IOVA address is not required */ 474 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 475 digest_ptr.va = (void *)sop->aead.digest.data; 476 aad_ptr.va = (void *)sop->aead.aad.data; 477 478 ofs.raw = 0; 479 480 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 481 &symvec); 482 483 if (n != 1) 484 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 485 else 486 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 487 } 488 489 static void 490 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op) 491 { 492 int32_t n, st; 493 struct rte_crypto_sym_op *sop; 494 union rte_crypto_sym_ofs ofs; 495 struct rte_crypto_sgl sgl; 496 struct rte_crypto_sym_vec symvec; 497 struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr; 498 struct rte_crypto_vec vec[UINT8_MAX]; 499 500 sop = op->sym; 501 502 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset, 503 sop->auth.data.length, vec, RTE_DIM(vec)); 504 505 if (n < 0 || n != sop->m_src->nb_segs) { 506 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 507 return; 508 } 509 510 sgl.vec = vec; 511 sgl.num = n; 512 symvec.src_sgl = &sgl; 513 symvec.iv = &iv_ptr; 514 symvec.digest = &digest_ptr; 515 symvec.status = &st; 516 symvec.num = 1; 517 518 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 519 digest_ptr.va = (void *)sop->auth.digest.data; 520 521 ofs.raw = 0; 522 ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset; 523 ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) - 524 (sop->cipher.data.offset + sop->cipher.data.length); 525 526 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 527 &symvec); 528 529 if (n != 1) 530 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 531 else 532 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 533 } 534 535 static struct rte_crypto_op * 536 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op) 537 { 538 539 RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO); 540 541 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 542 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n"); 543 return NULL; 544 } 545 546 op = NULL; 547 548 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 549 rte_pause(); 550 551 if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 552 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status); 553 return NULL; 554 } 555 556 return op; 557 } 558 559 static int 560 testsuite_setup(void) 561 { 562 struct crypto_testsuite_params *ts_params = &testsuite_params; 563 struct rte_cryptodev_info info; 564 uint32_t i = 0, nb_devs, dev_id; 565 uint16_t qp_id; 566 567 memset(ts_params, 0, sizeof(*ts_params)); 568 569 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 570 if (ts_params->mbuf_pool == NULL) { 571 /* Not already created so create */ 572 ts_params->mbuf_pool = rte_pktmbuf_pool_create( 573 "CRYPTO_MBUFPOOL", 574 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE, 575 rte_socket_id()); 576 if (ts_params->mbuf_pool == NULL) { 577 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n"); 578 return TEST_FAILED; 579 } 580 } 581 582 ts_params->large_mbuf_pool = rte_mempool_lookup( 583 "CRYPTO_LARGE_MBUFPOOL"); 584 if (ts_params->large_mbuf_pool == NULL) { 585 /* Not already created so create */ 586 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create( 587 "CRYPTO_LARGE_MBUFPOOL", 588 1, 0, 0, UINT16_MAX, 589 rte_socket_id()); 590 if (ts_params->large_mbuf_pool == NULL) { 591 RTE_LOG(ERR, USER1, 592 "Can't create CRYPTO_LARGE_MBUFPOOL\n"); 593 return TEST_FAILED; 594 } 595 } 596 597 ts_params->op_mpool = rte_crypto_op_pool_create( 598 "MBUF_CRYPTO_SYM_OP_POOL", 599 RTE_CRYPTO_OP_TYPE_SYMMETRIC, 600 NUM_MBUFS, MBUF_CACHE_SIZE, 601 DEFAULT_NUM_XFORMS * 602 sizeof(struct rte_crypto_sym_xform) + 603 MAXIMUM_IV_LENGTH, 604 rte_socket_id()); 605 if (ts_params->op_mpool == NULL) { 606 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n"); 607 return TEST_FAILED; 608 } 609 610 nb_devs = rte_cryptodev_count(); 611 if (nb_devs < 1) { 612 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 613 return TEST_SKIPPED; 614 } 615 616 if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) { 617 RTE_LOG(WARNING, USER1, "No %s devices found?\n", 618 rte_cryptodev_driver_name_get(gbl_driver_id)); 619 return TEST_SKIPPED; 620 } 621 622 /* Create list of valid crypto devs */ 623 for (i = 0; i < nb_devs; i++) { 624 rte_cryptodev_info_get(i, &info); 625 if (info.driver_id == gbl_driver_id) 626 ts_params->valid_devs[ts_params->valid_dev_count++] = i; 627 } 628 629 if (ts_params->valid_dev_count < 1) 630 return TEST_FAILED; 631 632 /* Set up all the qps on the first of the valid devices found */ 633 634 dev_id = ts_params->valid_devs[0]; 635 636 rte_cryptodev_info_get(dev_id, &info); 637 638 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; 639 ts_params->conf.socket_id = SOCKET_ID_ANY; 640 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY; 641 642 unsigned int session_size = 643 rte_cryptodev_sym_get_private_session_size(dev_id); 644 645 #ifdef RTE_LIB_SECURITY 646 unsigned int security_session_size = rte_security_session_get_size( 647 rte_cryptodev_get_sec_ctx(dev_id)); 648 649 if (session_size < security_session_size) 650 session_size = security_session_size; 651 #endif 652 /* 653 * Create mempool with maximum number of sessions. 654 */ 655 if (info.sym.max_nb_sessions != 0 && 656 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 657 RTE_LOG(ERR, USER1, "Device does not support " 658 "at least %u sessions\n", 659 MAX_NB_SESSIONS); 660 return TEST_FAILED; 661 } 662 663 ts_params->session_mpool = rte_cryptodev_sym_session_pool_create( 664 "test_sess_mp", MAX_NB_SESSIONS, session_size, 0, 0, 665 SOCKET_ID_ANY); 666 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 667 "session mempool allocation failed"); 668 669 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, 670 &ts_params->conf), 671 "Failed to configure cryptodev %u with %u qps", 672 dev_id, ts_params->conf.nb_queue_pairs); 673 674 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 675 ts_params->qp_conf.mp_session = ts_params->session_mpool; 676 677 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 678 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 679 dev_id, qp_id, &ts_params->qp_conf, 680 rte_cryptodev_socket_id(dev_id)), 681 "Failed to setup queue pair %u on cryptodev %u", 682 qp_id, dev_id); 683 } 684 685 return TEST_SUCCESS; 686 } 687 688 static void 689 testsuite_teardown(void) 690 { 691 struct crypto_testsuite_params *ts_params = &testsuite_params; 692 int res; 693 694 if (ts_params->mbuf_pool != NULL) { 695 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 696 rte_mempool_avail_count(ts_params->mbuf_pool)); 697 } 698 699 if (ts_params->op_mpool != NULL) { 700 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", 701 rte_mempool_avail_count(ts_params->op_mpool)); 702 } 703 704 if (ts_params->session_mpool != NULL) { 705 rte_mempool_free(ts_params->session_mpool); 706 ts_params->session_mpool = NULL; 707 } 708 709 res = rte_cryptodev_close(ts_params->valid_devs[0]); 710 if (res) 711 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res); 712 } 713 714 static int 715 check_capabilities_supported(enum rte_crypto_sym_xform_type type, 716 const int *algs, uint16_t num_algs) 717 { 718 uint8_t dev_id = testsuite_params.valid_devs[0]; 719 bool some_alg_supported = FALSE; 720 uint16_t i; 721 722 for (i = 0; i < num_algs && !some_alg_supported; i++) { 723 struct rte_cryptodev_sym_capability_idx alg = { 724 type, {algs[i]} 725 }; 726 if (rte_cryptodev_sym_capability_get(dev_id, 727 &alg) != NULL) 728 some_alg_supported = TRUE; 729 } 730 if (!some_alg_supported) 731 return TEST_SKIPPED; 732 733 return 0; 734 } 735 736 int 737 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers, 738 uint16_t num_ciphers) 739 { 740 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER, 741 (const int *) ciphers, num_ciphers); 742 } 743 744 int 745 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths, 746 uint16_t num_auths) 747 { 748 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH, 749 (const int *) auths, num_auths); 750 } 751 752 int 753 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads, 754 uint16_t num_aeads) 755 { 756 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD, 757 (const int *) aeads, num_aeads); 758 } 759 760 static int 761 null_testsuite_setup(void) 762 { 763 struct crypto_testsuite_params *ts_params = &testsuite_params; 764 uint8_t dev_id = ts_params->valid_devs[0]; 765 struct rte_cryptodev_info dev_info; 766 const enum rte_crypto_cipher_algorithm ciphers[] = { 767 RTE_CRYPTO_CIPHER_NULL 768 }; 769 const enum rte_crypto_auth_algorithm auths[] = { 770 RTE_CRYPTO_AUTH_NULL 771 }; 772 773 rte_cryptodev_info_get(dev_id, &dev_info); 774 775 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 776 RTE_LOG(INFO, USER1, "Feature flag requirements for NULL " 777 "testsuite not met\n"); 778 return TEST_SKIPPED; 779 } 780 781 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 782 && check_auth_capabilities_supported(auths, 783 RTE_DIM(auths)) != 0) { 784 RTE_LOG(INFO, USER1, "Capability requirements for NULL " 785 "testsuite not met\n"); 786 return TEST_SKIPPED; 787 } 788 789 return 0; 790 } 791 792 static int 793 crypto_gen_testsuite_setup(void) 794 { 795 struct crypto_testsuite_params *ts_params = &testsuite_params; 796 uint8_t dev_id = ts_params->valid_devs[0]; 797 struct rte_cryptodev_info dev_info; 798 799 rte_cryptodev_info_get(dev_id, &dev_info); 800 801 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 802 RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen " 803 "testsuite not met\n"); 804 return TEST_SKIPPED; 805 } 806 807 return 0; 808 } 809 810 #ifdef RTE_LIB_SECURITY 811 static int 812 sec_proto_testsuite_setup(enum rte_security_session_protocol protocol) 813 { 814 struct crypto_testsuite_params *ts_params = &testsuite_params; 815 struct crypto_unittest_params *ut_params = &unittest_params; 816 struct rte_cryptodev_info dev_info; 817 int ret = 0; 818 819 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 820 821 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) { 822 RTE_LOG(INFO, USER1, 823 "Feature flag requirements for security protocol testsuite not met\n"); 824 return TEST_SKIPPED; 825 } 826 827 /* Reconfigure to enable security */ 828 ret = dev_configure_and_start(0); 829 if (ret != TEST_SUCCESS) 830 return ret; 831 832 /* Set action type */ 833 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 834 835 if (security_proto_supported(RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, protocol) < 0) { 836 RTE_LOG(INFO, USER1, 837 "Capability requirements for security protocol test not met\n"); 838 ret = TEST_SKIPPED; 839 } 840 841 test_sec_alg_list_populate(); 842 test_sec_auth_only_alg_list_populate(); 843 844 /* 845 * Stop the device. Device would be started again by individual test 846 * case setup routine. 847 */ 848 rte_cryptodev_stop(ts_params->valid_devs[0]); 849 850 return ret; 851 } 852 853 static int 854 ipsec_proto_testsuite_setup(void) 855 { 856 return sec_proto_testsuite_setup(RTE_SECURITY_PROTOCOL_IPSEC); 857 } 858 859 static int 860 tls_record_proto_testsuite_setup(void) 861 { 862 test_sec_proto_pattern_generate(); 863 864 return sec_proto_testsuite_setup(RTE_SECURITY_PROTOCOL_TLS_RECORD); 865 } 866 867 static int 868 pdcp_proto_testsuite_setup(void) 869 { 870 struct crypto_testsuite_params *ts_params = &testsuite_params; 871 uint8_t dev_id = ts_params->valid_devs[0]; 872 struct rte_cryptodev_info dev_info; 873 const enum rte_crypto_cipher_algorithm ciphers[] = { 874 RTE_CRYPTO_CIPHER_NULL, 875 RTE_CRYPTO_CIPHER_AES_CTR, 876 RTE_CRYPTO_CIPHER_ZUC_EEA3, 877 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 878 }; 879 const enum rte_crypto_auth_algorithm auths[] = { 880 RTE_CRYPTO_AUTH_NULL, 881 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 882 RTE_CRYPTO_AUTH_AES_CMAC, 883 RTE_CRYPTO_AUTH_ZUC_EIA3 884 }; 885 886 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_auth_key)); 887 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_bearer)); 888 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_crypto_key)); 889 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_in)); 890 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_in_len)); 891 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_out)); 892 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_sn_size)); 893 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_hfn)); 894 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_hfn_threshold)); 895 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_packet_direction)); 896 897 rte_cryptodev_info_get(dev_id, &dev_info); 898 899 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 900 !(dev_info.feature_flags & 901 RTE_CRYPTODEV_FF_SECURITY)) { 902 RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto " 903 "testsuite not met\n"); 904 return TEST_SKIPPED; 905 } 906 907 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 908 && check_auth_capabilities_supported(auths, 909 RTE_DIM(auths)) != 0) { 910 RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto " 911 "testsuite not met\n"); 912 return TEST_SKIPPED; 913 } 914 915 return 0; 916 } 917 918 static int 919 docsis_proto_testsuite_setup(void) 920 { 921 struct crypto_testsuite_params *ts_params = &testsuite_params; 922 uint8_t dev_id = ts_params->valid_devs[0]; 923 struct rte_cryptodev_info dev_info; 924 const enum rte_crypto_cipher_algorithm ciphers[] = { 925 RTE_CRYPTO_CIPHER_AES_DOCSISBPI 926 }; 927 928 rte_cryptodev_info_get(dev_id, &dev_info); 929 930 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 931 !(dev_info.feature_flags & 932 RTE_CRYPTODEV_FF_SECURITY)) { 933 RTE_LOG(INFO, USER1, "Feature flag requirements for DOCSIS " 934 "Proto testsuite not met\n"); 935 return TEST_SKIPPED; 936 } 937 938 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { 939 RTE_LOG(INFO, USER1, "Capability requirements for DOCSIS Proto " 940 "testsuite not met\n"); 941 return TEST_SKIPPED; 942 } 943 944 return 0; 945 } 946 #endif 947 948 static int 949 aes_ccm_auth_testsuite_setup(void) 950 { 951 struct crypto_testsuite_params *ts_params = &testsuite_params; 952 uint8_t dev_id = ts_params->valid_devs[0]; 953 struct rte_cryptodev_info dev_info; 954 const enum rte_crypto_aead_algorithm aeads[] = { 955 RTE_CRYPTO_AEAD_AES_CCM 956 }; 957 958 rte_cryptodev_info_get(dev_id, &dev_info); 959 960 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 961 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 962 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 963 RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM " 964 "testsuite not met\n"); 965 return TEST_SKIPPED; 966 } 967 968 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 969 RTE_LOG(INFO, USER1, "Capability requirements for AES CCM " 970 "testsuite not met\n"); 971 return TEST_SKIPPED; 972 } 973 974 return 0; 975 } 976 977 static int 978 aes_gcm_auth_testsuite_setup(void) 979 { 980 struct crypto_testsuite_params *ts_params = &testsuite_params; 981 uint8_t dev_id = ts_params->valid_devs[0]; 982 struct rte_cryptodev_info dev_info; 983 const enum rte_crypto_aead_algorithm aeads[] = { 984 RTE_CRYPTO_AEAD_AES_GCM 985 }; 986 987 rte_cryptodev_info_get(dev_id, &dev_info); 988 989 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 990 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM " 991 "testsuite not met\n"); 992 return TEST_SKIPPED; 993 } 994 995 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 996 RTE_LOG(INFO, USER1, "Capability requirements for AES GCM " 997 "testsuite not met\n"); 998 return TEST_SKIPPED; 999 } 1000 1001 return 0; 1002 } 1003 1004 static int 1005 aes_gmac_auth_testsuite_setup(void) 1006 { 1007 struct crypto_testsuite_params *ts_params = &testsuite_params; 1008 uint8_t dev_id = ts_params->valid_devs[0]; 1009 struct rte_cryptodev_info dev_info; 1010 const enum rte_crypto_auth_algorithm auths[] = { 1011 RTE_CRYPTO_AUTH_AES_GMAC 1012 }; 1013 1014 rte_cryptodev_info_get(dev_id, &dev_info); 1015 1016 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1017 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1018 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1019 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC " 1020 "testsuite not met\n"); 1021 return TEST_SKIPPED; 1022 } 1023 1024 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1025 RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC " 1026 "testsuite not met\n"); 1027 return TEST_SKIPPED; 1028 } 1029 1030 return 0; 1031 } 1032 1033 static int 1034 chacha20_poly1305_testsuite_setup(void) 1035 { 1036 struct crypto_testsuite_params *ts_params = &testsuite_params; 1037 uint8_t dev_id = ts_params->valid_devs[0]; 1038 struct rte_cryptodev_info dev_info; 1039 const enum rte_crypto_aead_algorithm aeads[] = { 1040 RTE_CRYPTO_AEAD_CHACHA20_POLY1305 1041 }; 1042 1043 rte_cryptodev_info_get(dev_id, &dev_info); 1044 1045 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1046 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1047 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1048 RTE_LOG(INFO, USER1, "Feature flag requirements for " 1049 "Chacha20-Poly1305 testsuite not met\n"); 1050 return TEST_SKIPPED; 1051 } 1052 1053 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1054 RTE_LOG(INFO, USER1, "Capability requirements for " 1055 "Chacha20-Poly1305 testsuite not met\n"); 1056 return TEST_SKIPPED; 1057 } 1058 1059 return 0; 1060 } 1061 1062 static int 1063 snow3g_testsuite_setup(void) 1064 { 1065 struct crypto_testsuite_params *ts_params = &testsuite_params; 1066 uint8_t dev_id = ts_params->valid_devs[0]; 1067 struct rte_cryptodev_info dev_info; 1068 const enum rte_crypto_cipher_algorithm ciphers[] = { 1069 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1070 1071 }; 1072 const enum rte_crypto_auth_algorithm auths[] = { 1073 RTE_CRYPTO_AUTH_SNOW3G_UIA2 1074 }; 1075 1076 rte_cryptodev_info_get(dev_id, &dev_info); 1077 1078 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1079 RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G " 1080 "testsuite not met\n"); 1081 return TEST_SKIPPED; 1082 } 1083 1084 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1085 && check_auth_capabilities_supported(auths, 1086 RTE_DIM(auths)) != 0) { 1087 RTE_LOG(INFO, USER1, "Capability requirements for Snow3G " 1088 "testsuite not met\n"); 1089 return TEST_SKIPPED; 1090 } 1091 1092 return 0; 1093 } 1094 1095 static int 1096 zuc_testsuite_setup(void) 1097 { 1098 struct crypto_testsuite_params *ts_params = &testsuite_params; 1099 uint8_t dev_id = ts_params->valid_devs[0]; 1100 struct rte_cryptodev_info dev_info; 1101 const enum rte_crypto_cipher_algorithm ciphers[] = { 1102 RTE_CRYPTO_CIPHER_ZUC_EEA3 1103 }; 1104 const enum rte_crypto_auth_algorithm auths[] = { 1105 RTE_CRYPTO_AUTH_ZUC_EIA3 1106 }; 1107 1108 rte_cryptodev_info_get(dev_id, &dev_info); 1109 1110 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1111 RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC " 1112 "testsuite not met\n"); 1113 return TEST_SKIPPED; 1114 } 1115 1116 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1117 && check_auth_capabilities_supported(auths, 1118 RTE_DIM(auths)) != 0) { 1119 RTE_LOG(INFO, USER1, "Capability requirements for ZUC " 1120 "testsuite not met\n"); 1121 return TEST_SKIPPED; 1122 } 1123 1124 return 0; 1125 } 1126 1127 static int 1128 hmac_md5_auth_testsuite_setup(void) 1129 { 1130 struct crypto_testsuite_params *ts_params = &testsuite_params; 1131 uint8_t dev_id = ts_params->valid_devs[0]; 1132 struct rte_cryptodev_info dev_info; 1133 const enum rte_crypto_auth_algorithm auths[] = { 1134 RTE_CRYPTO_AUTH_MD5_HMAC 1135 }; 1136 1137 rte_cryptodev_info_get(dev_id, &dev_info); 1138 1139 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1140 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1141 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1142 RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 " 1143 "Auth testsuite not met\n"); 1144 return TEST_SKIPPED; 1145 } 1146 1147 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1148 RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 " 1149 "testsuite not met\n"); 1150 return TEST_SKIPPED; 1151 } 1152 1153 return 0; 1154 } 1155 1156 static int 1157 kasumi_testsuite_setup(void) 1158 { 1159 struct crypto_testsuite_params *ts_params = &testsuite_params; 1160 uint8_t dev_id = ts_params->valid_devs[0]; 1161 struct rte_cryptodev_info dev_info; 1162 const enum rte_crypto_cipher_algorithm ciphers[] = { 1163 RTE_CRYPTO_CIPHER_KASUMI_F8 1164 }; 1165 const enum rte_crypto_auth_algorithm auths[] = { 1166 RTE_CRYPTO_AUTH_KASUMI_F9 1167 }; 1168 1169 rte_cryptodev_info_get(dev_id, &dev_info); 1170 1171 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1172 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1173 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1174 RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi " 1175 "testsuite not met\n"); 1176 return TEST_SKIPPED; 1177 } 1178 1179 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1180 && check_auth_capabilities_supported(auths, 1181 RTE_DIM(auths)) != 0) { 1182 RTE_LOG(INFO, USER1, "Capability requirements for Kasumi " 1183 "testsuite not met\n"); 1184 return TEST_SKIPPED; 1185 } 1186 1187 return 0; 1188 } 1189 1190 static int 1191 negative_aes_gcm_testsuite_setup(void) 1192 { 1193 struct crypto_testsuite_params *ts_params = &testsuite_params; 1194 uint8_t dev_id = ts_params->valid_devs[0]; 1195 struct rte_cryptodev_info dev_info; 1196 const enum rte_crypto_aead_algorithm aeads[] = { 1197 RTE_CRYPTO_AEAD_AES_GCM 1198 }; 1199 1200 rte_cryptodev_info_get(dev_id, &dev_info); 1201 1202 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1203 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1204 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1205 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1206 "AES GCM testsuite not met\n"); 1207 return TEST_SKIPPED; 1208 } 1209 1210 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1211 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1212 "AES GCM testsuite not met\n"); 1213 return TEST_SKIPPED; 1214 } 1215 1216 return 0; 1217 } 1218 1219 static int 1220 negative_aes_gmac_testsuite_setup(void) 1221 { 1222 struct crypto_testsuite_params *ts_params = &testsuite_params; 1223 uint8_t dev_id = ts_params->valid_devs[0]; 1224 struct rte_cryptodev_info dev_info; 1225 const enum rte_crypto_auth_algorithm auths[] = { 1226 RTE_CRYPTO_AUTH_AES_GMAC 1227 }; 1228 1229 rte_cryptodev_info_get(dev_id, &dev_info); 1230 1231 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1232 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1233 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1234 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1235 "AES GMAC testsuite not met\n"); 1236 return TEST_SKIPPED; 1237 } 1238 1239 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1240 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1241 "AES GMAC testsuite not met\n"); 1242 return TEST_SKIPPED; 1243 } 1244 1245 return 0; 1246 } 1247 1248 static int 1249 mixed_cipher_hash_testsuite_setup(void) 1250 { 1251 struct crypto_testsuite_params *ts_params = &testsuite_params; 1252 uint8_t dev_id = ts_params->valid_devs[0]; 1253 struct rte_cryptodev_info dev_info; 1254 uint64_t feat_flags; 1255 const enum rte_crypto_cipher_algorithm ciphers[] = { 1256 RTE_CRYPTO_CIPHER_NULL, 1257 RTE_CRYPTO_CIPHER_AES_CTR, 1258 RTE_CRYPTO_CIPHER_ZUC_EEA3, 1259 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1260 }; 1261 const enum rte_crypto_auth_algorithm auths[] = { 1262 RTE_CRYPTO_AUTH_NULL, 1263 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 1264 RTE_CRYPTO_AUTH_AES_CMAC, 1265 RTE_CRYPTO_AUTH_ZUC_EIA3 1266 }; 1267 1268 rte_cryptodev_info_get(dev_id, &dev_info); 1269 feat_flags = dev_info.feature_flags; 1270 1271 if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1272 (global_api_test_type == CRYPTODEV_RAW_API_TEST)) { 1273 RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed " 1274 "Cipher Hash testsuite not met\n"); 1275 return TEST_SKIPPED; 1276 } 1277 1278 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1279 && check_auth_capabilities_supported(auths, 1280 RTE_DIM(auths)) != 0) { 1281 RTE_LOG(INFO, USER1, "Capability requirements for Mixed " 1282 "Cipher Hash testsuite not met\n"); 1283 return TEST_SKIPPED; 1284 } 1285 1286 return 0; 1287 } 1288 1289 static int 1290 esn_testsuite_setup(void) 1291 { 1292 struct crypto_testsuite_params *ts_params = &testsuite_params; 1293 uint8_t dev_id = ts_params->valid_devs[0]; 1294 struct rte_cryptodev_info dev_info; 1295 const enum rte_crypto_cipher_algorithm ciphers[] = { 1296 RTE_CRYPTO_CIPHER_AES_CBC 1297 }; 1298 const enum rte_crypto_auth_algorithm auths[] = { 1299 RTE_CRYPTO_AUTH_SHA1_HMAC 1300 }; 1301 1302 rte_cryptodev_info_get(dev_id, &dev_info); 1303 1304 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1305 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1306 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1307 RTE_LOG(INFO, USER1, "Feature flag requirements for ESN " 1308 "testsuite not met\n"); 1309 return TEST_SKIPPED; 1310 } 1311 1312 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1313 && check_auth_capabilities_supported(auths, 1314 RTE_DIM(auths)) != 0) { 1315 RTE_LOG(INFO, USER1, "Capability requirements for ESN " 1316 "testsuite not met\n"); 1317 return TEST_SKIPPED; 1318 } 1319 1320 return 0; 1321 } 1322 1323 static int 1324 multi_session_testsuite_setup(void) 1325 { 1326 struct crypto_testsuite_params *ts_params = &testsuite_params; 1327 uint8_t dev_id = ts_params->valid_devs[0]; 1328 struct rte_cryptodev_info dev_info; 1329 const enum rte_crypto_cipher_algorithm ciphers[] = { 1330 RTE_CRYPTO_CIPHER_AES_CBC 1331 }; 1332 const enum rte_crypto_auth_algorithm auths[] = { 1333 RTE_CRYPTO_AUTH_SHA512_HMAC 1334 }; 1335 1336 rte_cryptodev_info_get(dev_id, &dev_info); 1337 1338 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1339 RTE_LOG(INFO, USER1, "Feature flag requirements for Multi " 1340 "Session testsuite not met\n"); 1341 return TEST_SKIPPED; 1342 } 1343 1344 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1345 && check_auth_capabilities_supported(auths, 1346 RTE_DIM(auths)) != 0) { 1347 RTE_LOG(INFO, USER1, "Capability requirements for Multi " 1348 "Session testsuite not met\n"); 1349 return TEST_SKIPPED; 1350 } 1351 1352 return 0; 1353 } 1354 1355 static int 1356 negative_hmac_sha1_testsuite_setup(void) 1357 { 1358 struct crypto_testsuite_params *ts_params = &testsuite_params; 1359 uint8_t dev_id = ts_params->valid_devs[0]; 1360 struct rte_cryptodev_info dev_info; 1361 const enum rte_crypto_cipher_algorithm ciphers[] = { 1362 RTE_CRYPTO_CIPHER_AES_CBC 1363 }; 1364 const enum rte_crypto_auth_algorithm auths[] = { 1365 RTE_CRYPTO_AUTH_SHA1_HMAC 1366 }; 1367 1368 rte_cryptodev_info_get(dev_id, &dev_info); 1369 1370 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1371 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1372 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1373 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1374 "HMAC SHA1 testsuite not met\n"); 1375 return TEST_SKIPPED; 1376 } 1377 1378 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1379 && check_auth_capabilities_supported(auths, 1380 RTE_DIM(auths)) != 0) { 1381 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1382 "HMAC SHA1 testsuite not met\n"); 1383 return TEST_SKIPPED; 1384 } 1385 1386 return 0; 1387 } 1388 1389 static int 1390 dev_configure_and_start(uint64_t ff_disable) 1391 { 1392 struct crypto_testsuite_params *ts_params = &testsuite_params; 1393 struct crypto_unittest_params *ut_params = &unittest_params; 1394 1395 uint16_t qp_id; 1396 1397 /* Clear unit test parameters before running test */ 1398 memset(ut_params, 0, sizeof(*ut_params)); 1399 1400 /* Reconfigure device to default parameters */ 1401 ts_params->conf.socket_id = SOCKET_ID_ANY; 1402 ts_params->conf.ff_disable = ff_disable; 1403 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 1404 ts_params->qp_conf.mp_session = ts_params->session_mpool; 1405 1406 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1407 &ts_params->conf), 1408 "Failed to configure cryptodev %u", 1409 ts_params->valid_devs[0]); 1410 1411 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { 1412 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1413 ts_params->valid_devs[0], qp_id, 1414 &ts_params->qp_conf, 1415 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1416 "Failed to setup queue pair %u on cryptodev %u", 1417 qp_id, ts_params->valid_devs[0]); 1418 } 1419 1420 1421 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 1422 1423 /* Start the device */ 1424 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 1425 "Failed to start cryptodev %u", 1426 ts_params->valid_devs[0]); 1427 1428 return TEST_SUCCESS; 1429 } 1430 1431 int 1432 ut_setup(void) 1433 { 1434 /* Configure and start the device with security feature disabled */ 1435 return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY); 1436 } 1437 1438 static int 1439 ut_setup_security(void) 1440 { 1441 /* Configure and start the device with no features disabled */ 1442 return dev_configure_and_start(0); 1443 } 1444 1445 static int 1446 ut_setup_security_rx_inject(void) 1447 { 1448 struct rte_mempool *mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 1449 struct crypto_testsuite_params *ts_params = &testsuite_params; 1450 struct rte_eth_conf port_conf = { 1451 .rxmode = { 1452 .offloads = RTE_ETH_RX_OFFLOAD_CHECKSUM | 1453 RTE_ETH_RX_OFFLOAD_SECURITY, 1454 }, 1455 .txmode = { 1456 .offloads = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE, 1457 }, 1458 .lpbk_mode = 1, /* Enable loopback */ 1459 }; 1460 struct rte_cryptodev_info dev_info; 1461 struct rte_eth_rxconf rx_conf = { 1462 .rx_thresh = { 1463 .pthresh = 8, 1464 .hthresh = 8, 1465 .wthresh = 8, 1466 }, 1467 .rx_free_thresh = 32, 1468 }; 1469 uint16_t nb_ports; 1470 void *sec_ctx; 1471 int ret; 1472 1473 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 1474 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY_RX_INJECT) || 1475 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) { 1476 RTE_LOG(INFO, USER1, 1477 "Feature requirements for IPsec Rx inject test case not met\n"); 1478 return TEST_SKIPPED; 1479 } 1480 1481 sec_ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 1482 if (sec_ctx == NULL) 1483 return TEST_SKIPPED; 1484 1485 nb_ports = rte_eth_dev_count_avail(); 1486 if (nb_ports == 0) 1487 return TEST_SKIPPED; 1488 1489 ret = rte_eth_dev_configure(0 /* port_id */, 1490 1 /* nb_rx_queue */, 1491 0 /* nb_tx_queue */, 1492 &port_conf); 1493 if (ret) { 1494 printf("Could not configure ethdev port 0 [err=%d]\n", ret); 1495 return TEST_SKIPPED; 1496 } 1497 1498 /* Rx queue setup */ 1499 ret = rte_eth_rx_queue_setup(0 /* port_id */, 1500 0 /* rx_queue_id */, 1501 1024 /* nb_rx_desc */, 1502 SOCKET_ID_ANY, 1503 &rx_conf, 1504 mbuf_pool); 1505 if (ret) { 1506 printf("Could not setup eth port 0 queue 0\n"); 1507 return TEST_SKIPPED; 1508 } 1509 1510 ret = rte_security_rx_inject_configure(sec_ctx, 0, true); 1511 if (ret) { 1512 printf("Could not enable Rx inject offload"); 1513 return TEST_SKIPPED; 1514 } 1515 1516 ret = rte_eth_dev_start(0); 1517 if (ret) { 1518 printf("Could not start ethdev"); 1519 return TEST_SKIPPED; 1520 } 1521 1522 ret = rte_eth_promiscuous_enable(0); 1523 if (ret) { 1524 printf("Could not enable promiscuous mode"); 1525 return TEST_SKIPPED; 1526 } 1527 1528 /* Configure and start cryptodev with no features disabled */ 1529 return dev_configure_and_start(0); 1530 } 1531 1532 static inline void 1533 ext_mbuf_callback_fn_free(void *addr __rte_unused, void *opaque __rte_unused) 1534 { 1535 } 1536 1537 static inline void 1538 ext_mbuf_memzone_free(int nb_segs) 1539 { 1540 int i; 1541 1542 for (i = 0; i <= nb_segs; i++) { 1543 char mz_name[RTE_MEMZONE_NAMESIZE]; 1544 const struct rte_memzone *memzone; 1545 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "ext_buf_%d", i); 1546 memzone = rte_memzone_lookup(mz_name); 1547 if (memzone != NULL) { 1548 rte_memzone_free(memzone); 1549 memzone = NULL; 1550 } 1551 } 1552 } 1553 1554 static inline struct rte_mbuf * 1555 ext_mbuf_create(struct rte_mempool *mbuf_pool, int pkt_len, 1556 int nb_segs, const void *input_text) 1557 { 1558 struct rte_mbuf *m = NULL, *mbuf = NULL; 1559 size_t data_off = 0; 1560 uint8_t *dst; 1561 int i, size; 1562 int t_len; 1563 1564 if (pkt_len < 1) { 1565 printf("Packet size must be 1 or more (is %d)\n", pkt_len); 1566 return NULL; 1567 } 1568 1569 if (nb_segs < 1) { 1570 printf("Number of segments must be 1 or more (is %d)\n", 1571 nb_segs); 1572 return NULL; 1573 } 1574 1575 t_len = pkt_len >= nb_segs ? pkt_len / nb_segs : 1; 1576 size = pkt_len; 1577 1578 /* Create chained mbuf_src with external buffer */ 1579 for (i = 0; size > 0; i++) { 1580 struct rte_mbuf_ext_shared_info *ret_shinfo = NULL; 1581 uint16_t data_len = RTE_MIN(size, t_len); 1582 char mz_name[RTE_MEMZONE_NAMESIZE]; 1583 const struct rte_memzone *memzone; 1584 void *ext_buf_addr = NULL; 1585 rte_iova_t buf_iova; 1586 bool freed = false; 1587 uint16_t buf_len; 1588 1589 buf_len = RTE_ALIGN_CEIL(data_len + 1024 + 1590 sizeof(struct rte_mbuf_ext_shared_info), 8); 1591 1592 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "ext_buf_%d", i); 1593 memzone = rte_memzone_lookup(mz_name); 1594 if (memzone != NULL && memzone->len != buf_len) { 1595 rte_memzone_free(memzone); 1596 memzone = NULL; 1597 } 1598 if (memzone == NULL) { 1599 memzone = rte_memzone_reserve_aligned(mz_name, buf_len, SOCKET_ID_ANY, 1600 RTE_MEMZONE_IOVA_CONTIG, RTE_CACHE_LINE_SIZE); 1601 if (memzone == NULL) { 1602 printf("Can't allocate memory zone %s\n", mz_name); 1603 return NULL; 1604 } 1605 } 1606 1607 ext_buf_addr = memzone->addr; 1608 if (input_text) 1609 memcpy(ext_buf_addr, RTE_PTR_ADD(input_text, data_off), data_len); 1610 1611 /* Create buffer to hold rte_mbuf header */ 1612 m = rte_pktmbuf_alloc(mbuf_pool); 1613 if (i == 0) 1614 mbuf = m; 1615 1616 if (m == NULL) { 1617 printf("Cannot create segment for source mbuf"); 1618 goto fail; 1619 } 1620 1621 /* Save shared data (like callback function) in external buffer's end */ 1622 ret_shinfo = rte_pktmbuf_ext_shinfo_init_helper(ext_buf_addr, &buf_len, 1623 ext_mbuf_callback_fn_free, &freed); 1624 if (ret_shinfo == NULL) { 1625 printf("Shared mem initialization failed!\n"); 1626 goto fail; 1627 } 1628 1629 buf_iova = rte_mem_virt2iova(ext_buf_addr); 1630 1631 /* Attach external buffer to mbuf */ 1632 rte_pktmbuf_attach_extbuf(m, ext_buf_addr, buf_iova, buf_len, 1633 ret_shinfo); 1634 if (m->ol_flags != RTE_MBUF_F_EXTERNAL) { 1635 printf("External buffer is not attached to mbuf\n"); 1636 goto fail; 1637 } 1638 1639 if (input_text) { 1640 dst = (uint8_t *)rte_pktmbuf_append(m, data_len); 1641 if (dst == NULL) { 1642 printf("Cannot append %d bytes to the mbuf\n", data_len); 1643 goto fail; 1644 } 1645 } 1646 1647 if (mbuf != m) 1648 rte_pktmbuf_chain(mbuf, m); 1649 1650 size -= data_len; 1651 data_off += data_len; 1652 } 1653 1654 return mbuf; 1655 1656 fail: 1657 rte_pktmbuf_free(mbuf); 1658 ext_mbuf_memzone_free(nb_segs); 1659 return NULL; 1660 } 1661 1662 void 1663 ut_teardown(void) 1664 { 1665 struct crypto_testsuite_params *ts_params = &testsuite_params; 1666 struct crypto_unittest_params *ut_params = &unittest_params; 1667 1668 /* free crypto session structure */ 1669 #ifdef RTE_LIB_SECURITY 1670 if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) { 1671 if (ut_params->sec_session) { 1672 rte_security_session_destroy(rte_cryptodev_get_sec_ctx 1673 (ts_params->valid_devs[0]), 1674 ut_params->sec_session); 1675 ut_params->sec_session = NULL; 1676 } 1677 } else 1678 #endif 1679 { 1680 if (ut_params->sess) { 1681 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 1682 ut_params->sess); 1683 ut_params->sess = NULL; 1684 } 1685 } 1686 1687 /* free crypto operation structure */ 1688 rte_crypto_op_free(ut_params->op); 1689 1690 /* 1691 * free mbuf - both obuf and ibuf are usually the same, 1692 * so check if they point at the same address is necessary, 1693 * to avoid freeing the mbuf twice. 1694 */ 1695 if (ut_params->obuf) { 1696 rte_pktmbuf_free(ut_params->obuf); 1697 if (ut_params->ibuf == ut_params->obuf) 1698 ut_params->ibuf = 0; 1699 ut_params->obuf = 0; 1700 } 1701 if (ut_params->ibuf) { 1702 ext_mbuf_memzone_free(1); 1703 rte_pktmbuf_free(ut_params->ibuf); 1704 ut_params->ibuf = 0; 1705 } 1706 1707 if (ts_params->mbuf_pool != NULL) 1708 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 1709 rte_mempool_avail_count(ts_params->mbuf_pool)); 1710 1711 /* Stop the device */ 1712 rte_cryptodev_stop(ts_params->valid_devs[0]); 1713 } 1714 1715 static void 1716 ut_teardown_rx_inject(void) 1717 { 1718 struct crypto_testsuite_params *ts_params = &testsuite_params; 1719 void *sec_ctx; 1720 int ret; 1721 1722 if (rte_eth_dev_count_avail() != 0) { 1723 ret = rte_eth_dev_reset(0); 1724 if (ret) 1725 printf("Could not reset eth port 0"); 1726 1727 } 1728 1729 ut_teardown(); 1730 1731 sec_ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 1732 if (sec_ctx == NULL) 1733 return; 1734 1735 ret = rte_security_rx_inject_configure(sec_ctx, 0, false); 1736 if (ret) { 1737 printf("Could not disable Rx inject offload"); 1738 return; 1739 } 1740 } 1741 1742 static int 1743 test_device_configure_invalid_dev_id(void) 1744 { 1745 struct crypto_testsuite_params *ts_params = &testsuite_params; 1746 uint16_t dev_id, num_devs = 0; 1747 1748 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 1749 "Need at least %d devices for test", 1); 1750 1751 /* valid dev_id values */ 1752 dev_id = ts_params->valid_devs[0]; 1753 1754 /* Stop the device in case it's started so it can be configured */ 1755 rte_cryptodev_stop(dev_id); 1756 1757 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 1758 "Failed test for rte_cryptodev_configure: " 1759 "invalid dev_num %u", dev_id); 1760 1761 /* invalid dev_id values */ 1762 dev_id = num_devs; 1763 1764 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1765 "Failed test for rte_cryptodev_configure: " 1766 "invalid dev_num %u", dev_id); 1767 1768 dev_id = 0xff; 1769 1770 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1771 "Failed test for rte_cryptodev_configure:" 1772 "invalid dev_num %u", dev_id); 1773 1774 return TEST_SUCCESS; 1775 } 1776 1777 static int 1778 test_device_configure_invalid_queue_pair_ids(void) 1779 { 1780 struct crypto_testsuite_params *ts_params = &testsuite_params; 1781 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 1782 1783 /* Stop the device in case it's started so it can be configured */ 1784 rte_cryptodev_stop(ts_params->valid_devs[0]); 1785 1786 /* valid - max value queue pairs */ 1787 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1788 1789 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1790 &ts_params->conf), 1791 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1792 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 1793 1794 /* valid - one queue pairs */ 1795 ts_params->conf.nb_queue_pairs = 1; 1796 1797 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1798 &ts_params->conf), 1799 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1800 ts_params->valid_devs[0], 1801 ts_params->conf.nb_queue_pairs); 1802 1803 1804 /* invalid - zero queue pairs */ 1805 ts_params->conf.nb_queue_pairs = 0; 1806 1807 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1808 &ts_params->conf), 1809 "Failed test for rte_cryptodev_configure, dev_id %u," 1810 " invalid qps: %u", 1811 ts_params->valid_devs[0], 1812 ts_params->conf.nb_queue_pairs); 1813 1814 1815 /* invalid - max value supported by field queue pairs */ 1816 ts_params->conf.nb_queue_pairs = UINT16_MAX; 1817 1818 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1819 &ts_params->conf), 1820 "Failed test for rte_cryptodev_configure, dev_id %u," 1821 " invalid qps: %u", 1822 ts_params->valid_devs[0], 1823 ts_params->conf.nb_queue_pairs); 1824 1825 1826 /* invalid - max value + 1 queue pairs */ 1827 ts_params->conf.nb_queue_pairs = orig_nb_qps + 1; 1828 1829 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1830 &ts_params->conf), 1831 "Failed test for rte_cryptodev_configure, dev_id %u," 1832 " invalid qps: %u", 1833 ts_params->valid_devs[0], 1834 ts_params->conf.nb_queue_pairs); 1835 1836 /* revert to original testsuite value */ 1837 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1838 1839 return TEST_SUCCESS; 1840 } 1841 1842 static int 1843 test_queue_pair_descriptor_setup(void) 1844 { 1845 struct crypto_testsuite_params *ts_params = &testsuite_params; 1846 struct rte_cryptodev_qp_conf qp_conf = { 1847 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 1848 }; 1849 uint16_t qp_id; 1850 1851 /* Stop the device in case it's started so it can be configured */ 1852 rte_cryptodev_stop(ts_params->valid_devs[0]); 1853 1854 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1855 &ts_params->conf), 1856 "Failed to configure cryptodev %u", 1857 ts_params->valid_devs[0]); 1858 1859 /* 1860 * Test various ring sizes on this device. memzones can't be 1861 * freed so are re-used if ring is released and re-created. 1862 */ 1863 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/ 1864 qp_conf.mp_session = ts_params->session_mpool; 1865 1866 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1867 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1868 ts_params->valid_devs[0], qp_id, &qp_conf, 1869 rte_cryptodev_socket_id( 1870 ts_params->valid_devs[0])), 1871 "Failed test for " 1872 "rte_cryptodev_queue_pair_setup: num_inflights " 1873 "%u on qp %u on cryptodev %u", 1874 qp_conf.nb_descriptors, qp_id, 1875 ts_params->valid_devs[0]); 1876 } 1877 1878 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2); 1879 1880 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1881 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1882 ts_params->valid_devs[0], qp_id, &qp_conf, 1883 rte_cryptodev_socket_id( 1884 ts_params->valid_devs[0])), 1885 "Failed test for" 1886 " rte_cryptodev_queue_pair_setup: num_inflights" 1887 " %u on qp %u on cryptodev %u", 1888 qp_conf.nb_descriptors, qp_id, 1889 ts_params->valid_devs[0]); 1890 } 1891 1892 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */ 1893 1894 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1895 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1896 ts_params->valid_devs[0], qp_id, &qp_conf, 1897 rte_cryptodev_socket_id( 1898 ts_params->valid_devs[0])), 1899 "Failed test for " 1900 "rte_cryptodev_queue_pair_setup: num_inflights" 1901 " %u on qp %u on cryptodev %u", 1902 qp_conf.nb_descriptors, qp_id, 1903 ts_params->valid_devs[0]); 1904 } 1905 1906 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 1907 1908 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1909 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1910 ts_params->valid_devs[0], qp_id, &qp_conf, 1911 rte_cryptodev_socket_id( 1912 ts_params->valid_devs[0])), 1913 "Failed test for" 1914 " rte_cryptodev_queue_pair_setup:" 1915 "num_inflights %u on qp %u on cryptodev %u", 1916 qp_conf.nb_descriptors, qp_id, 1917 ts_params->valid_devs[0]); 1918 } 1919 1920 /* test invalid queue pair id */ 1921 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */ 1922 1923 qp_id = ts_params->conf.nb_queue_pairs; /*invalid */ 1924 1925 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1926 ts_params->valid_devs[0], 1927 qp_id, &qp_conf, 1928 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1929 "Failed test for rte_cryptodev_queue_pair_setup:" 1930 "invalid qp %u on cryptodev %u", 1931 qp_id, ts_params->valid_devs[0]); 1932 1933 qp_id = 0xffff; /*invalid*/ 1934 1935 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1936 ts_params->valid_devs[0], 1937 qp_id, &qp_conf, 1938 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1939 "Failed test for rte_cryptodev_queue_pair_setup:" 1940 "invalid qp %u on cryptodev %u", 1941 qp_id, ts_params->valid_devs[0]); 1942 1943 return TEST_SUCCESS; 1944 } 1945 1946 /* ***** Plaintext data for tests ***** */ 1947 1948 const char catch_22_quote_1[] = 1949 "There was only one catch and that was Catch-22, which " 1950 "specified that a concern for one's safety in the face of " 1951 "dangers that were real and immediate was the process of a " 1952 "rational mind. Orr was crazy and could be grounded. All he " 1953 "had to do was ask; and as soon as he did, he would no longer " 1954 "be crazy and would have to fly more missions. Orr would be " 1955 "crazy to fly more missions and sane if he didn't, but if he " 1956 "was sane he had to fly them. If he flew them he was crazy " 1957 "and didn't have to; but if he didn't want to he was sane and " 1958 "had to. Yossarian was moved very deeply by the absolute " 1959 "simplicity of this clause of Catch-22 and let out a " 1960 "respectful whistle. \"That's some catch, that Catch-22\", he " 1961 "observed. \"It's the best there is,\" Doc Daneeka agreed."; 1962 1963 const char catch_22_quote[] = 1964 "What a lousy earth! He wondered how many people were " 1965 "destitute that same night even in his own prosperous country, " 1966 "how many homes were shanties, how many husbands were drunk " 1967 "and wives socked, and how many children were bullied, abused, " 1968 "or abandoned. How many families hungered for food they could " 1969 "not afford to buy? How many hearts were broken? How many " 1970 "suicides would take place that same night, how many people " 1971 "would go insane? How many cockroaches and landlords would " 1972 "triumph? How many winners were losers, successes failures, " 1973 "and rich men poor men? How many wise guys were stupid? How " 1974 "many happy endings were unhappy endings? How many honest men " 1975 "were liars, brave men cowards, loyal men traitors, how many " 1976 "sainted men were corrupt, how many people in positions of " 1977 "trust had sold their souls to bodyguards, how many had never " 1978 "had souls? How many straight-and-narrow paths were crooked " 1979 "paths? How many best families were worst families and how " 1980 "many good people were bad people? When you added them all up " 1981 "and then subtracted, you might be left with only the children, " 1982 "and perhaps with Albert Einstein and an old violinist or " 1983 "sculptor somewhere."; 1984 1985 #define QUOTE_480_BYTES (480) 1986 #define QUOTE_512_BYTES (512) 1987 #define QUOTE_768_BYTES (768) 1988 #define QUOTE_1024_BYTES (1024) 1989 1990 1991 1992 /* ***** SHA1 Hash Tests ***** */ 1993 1994 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1) 1995 1996 static uint8_t hmac_sha1_key[] = { 1997 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 1998 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 1999 0xDE, 0xF4, 0xDE, 0xAD }; 2000 2001 /* ***** SHA224 Hash Tests ***** */ 2002 2003 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224) 2004 2005 2006 /* ***** AES-CBC Cipher Tests ***** */ 2007 2008 #define CIPHER_KEY_LENGTH_AES_CBC (16) 2009 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC) 2010 2011 static uint8_t aes_cbc_key[] = { 2012 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 2013 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A }; 2014 2015 static uint8_t aes_cbc_iv[] = { 2016 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 2017 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; 2018 2019 2020 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */ 2021 2022 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = { 2023 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, 2024 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, 2025 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, 2026 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, 2027 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E, 2028 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08, 2029 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0, 2030 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01, 2031 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57, 2032 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE, 2033 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9, 2034 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9, 2035 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D, 2036 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3, 2037 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46, 2038 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3, 2039 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80, 2040 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92, 2041 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5, 2042 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5, 2043 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2, 2044 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5, 2045 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2046 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76, 2047 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4, 2048 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62, 2049 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4, 2050 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4, 2051 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54, 2052 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61, 2053 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91, 2054 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A, 2055 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF, 2056 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F, 2057 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28, 2058 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E, 2059 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7, 2060 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76, 2061 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6, 2062 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03, 2063 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C, 2064 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2, 2065 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6, 2066 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96, 2067 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6, 2068 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA, 2069 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87, 2070 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55, 2071 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B, 2072 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98, 2073 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53, 2074 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A, 2075 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26, 2076 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36, 2077 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36, 2078 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D, 2079 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E, 2080 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E, 2081 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A, 2082 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6, 2083 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4, 2084 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7, 2085 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1, 2086 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C 2087 }; 2088 2089 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = { 2090 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60, 2091 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 2092 0x18, 0x8c, 0x1d, 0x32 2093 }; 2094 2095 2096 /* Multisession Vector context Test */ 2097 /*Begin Session 0 */ 2098 static uint8_t ms_aes_cbc_key0[] = { 2099 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2100 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2101 }; 2102 2103 static uint8_t ms_aes_cbc_iv0[] = { 2104 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2105 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2106 }; 2107 2108 static const uint8_t ms_aes_cbc_cipher0[] = { 2109 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38, 2110 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC, 2111 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB, 2112 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9, 2113 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D, 2114 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4, 2115 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34, 2116 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F, 2117 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99, 2118 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED, 2119 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D, 2120 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24, 2121 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71, 2122 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72, 2123 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E, 2124 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD, 2125 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18, 2126 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6, 2127 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29, 2128 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C, 2129 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96, 2130 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26, 2131 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55, 2132 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46, 2133 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B, 2134 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4, 2135 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7, 2136 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5, 2137 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0, 2138 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E, 2139 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D, 2140 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44, 2141 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76, 2142 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3, 2143 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83, 2144 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85, 2145 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45, 2146 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25, 2147 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A, 2148 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1, 2149 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA, 2150 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3, 2151 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4, 2152 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60, 2153 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A, 2154 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A, 2155 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9, 2156 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55, 2157 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13, 2158 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B, 2159 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1, 2160 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0, 2161 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3, 2162 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23, 2163 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B, 2164 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07, 2165 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB, 2166 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1, 2167 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F, 2168 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F, 2169 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84, 2170 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B, 2171 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17, 2172 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF 2173 }; 2174 2175 2176 static uint8_t ms_hmac_key0[] = { 2177 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2178 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2179 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2180 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2181 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2182 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2183 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2184 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2185 }; 2186 2187 static const uint8_t ms_hmac_digest0[] = { 2188 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51, 2189 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F, 2190 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C, 2191 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4, 2192 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56, 2193 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4, 2194 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23, 2195 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90 2196 }; 2197 2198 /* End Session 0 */ 2199 /* Begin session 1 */ 2200 2201 static uint8_t ms_aes_cbc_key1[] = { 2202 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2203 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2204 }; 2205 2206 static uint8_t ms_aes_cbc_iv1[] = { 2207 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2208 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2209 }; 2210 2211 static const uint8_t ms_aes_cbc_cipher1[] = { 2212 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71, 2213 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23, 2214 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09, 2215 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A, 2216 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C, 2217 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F, 2218 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9, 2219 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66, 2220 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43, 2221 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB, 2222 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23, 2223 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29, 2224 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26, 2225 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F, 2226 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68, 2227 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77, 2228 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8, 2229 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97, 2230 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3, 2231 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90, 2232 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5, 2233 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E, 2234 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45, 2235 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B, 2236 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5, 2237 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D, 2238 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E, 2239 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD, 2240 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE, 2241 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1, 2242 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F, 2243 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25, 2244 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1, 2245 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3, 2246 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE, 2247 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6, 2248 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52, 2249 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA, 2250 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63, 2251 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E, 2252 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA, 2253 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB, 2254 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71, 2255 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF, 2256 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A, 2257 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95, 2258 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73, 2259 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49, 2260 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB, 2261 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B, 2262 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC, 2263 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED, 2264 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02, 2265 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4, 2266 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF, 2267 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82, 2268 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D, 2269 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6, 2270 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9, 2271 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35, 2272 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0, 2273 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53, 2274 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5, 2275 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3 2276 2277 }; 2278 2279 static uint8_t ms_hmac_key1[] = { 2280 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2281 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2282 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2283 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2284 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2285 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2286 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2287 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2288 }; 2289 2290 static const uint8_t ms_hmac_digest1[] = { 2291 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69, 2292 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50, 2293 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20, 2294 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD, 2295 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9, 2296 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4, 2297 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA, 2298 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F 2299 }; 2300 /* End Session 1 */ 2301 /* Begin Session 2 */ 2302 static uint8_t ms_aes_cbc_key2[] = { 2303 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2304 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2305 }; 2306 2307 static uint8_t ms_aes_cbc_iv2[] = { 2308 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2309 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2310 }; 2311 2312 static const uint8_t ms_aes_cbc_cipher2[] = { 2313 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91, 2314 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97, 2315 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8, 2316 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5, 2317 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98, 2318 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69, 2319 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09, 2320 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF, 2321 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44, 2322 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B, 2323 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9, 2324 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34, 2325 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99, 2326 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF, 2327 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC, 2328 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26, 2329 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3, 2330 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF, 2331 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3, 2332 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3, 2333 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA, 2334 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13, 2335 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38, 2336 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71, 2337 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC, 2338 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1, 2339 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E, 2340 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22, 2341 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62, 2342 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72, 2343 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6, 2344 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6, 2345 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44, 2346 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24, 2347 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5, 2348 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E, 2349 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17, 2350 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9, 2351 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D, 2352 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D, 2353 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22, 2354 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9, 2355 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49, 2356 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E, 2357 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B, 2358 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2, 2359 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95, 2360 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07, 2361 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3, 2362 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A, 2363 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57, 2364 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84, 2365 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61, 2366 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF, 2367 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17, 2368 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A, 2369 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1, 2370 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53, 2371 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7, 2372 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2, 2373 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A, 2374 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8, 2375 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70, 2376 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92 2377 }; 2378 2379 static uint8_t ms_hmac_key2[] = { 2380 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2381 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2382 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2383 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2384 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2385 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2386 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2387 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2388 }; 2389 2390 static const uint8_t ms_hmac_digest2[] = { 2391 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF, 2392 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6, 2393 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77, 2394 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27, 2395 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82, 2396 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24, 2397 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E, 2398 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59 2399 }; 2400 2401 /* End Session 2 */ 2402 2403 2404 static int 2405 test_AES_CBC_HMAC_SHA1_encrypt_digest(void) 2406 { 2407 struct crypto_testsuite_params *ts_params = &testsuite_params; 2408 struct crypto_unittest_params *ut_params = &unittest_params; 2409 /* Verify the capabilities */ 2410 struct rte_cryptodev_sym_capability_idx cap_idx; 2411 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2412 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 2413 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2414 &cap_idx) == NULL) 2415 return TEST_SKIPPED; 2416 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2417 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 2418 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2419 &cap_idx) == NULL) 2420 return TEST_SKIPPED; 2421 2422 /* Generate test mbuf data and space for digest */ 2423 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2424 catch_22_quote, QUOTE_512_BYTES, 0); 2425 2426 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2427 DIGEST_BYTE_LENGTH_SHA1); 2428 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2429 2430 /* Setup Cipher Parameters */ 2431 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2432 ut_params->cipher_xform.next = &ut_params->auth_xform; 2433 2434 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2435 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 2436 ut_params->cipher_xform.cipher.key.data = aes_cbc_key; 2437 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2438 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2439 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2440 2441 /* Setup HMAC Parameters */ 2442 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2443 2444 ut_params->auth_xform.next = NULL; 2445 2446 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 2447 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 2448 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; 2449 ut_params->auth_xform.auth.key.data = hmac_sha1_key; 2450 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; 2451 2452 rte_errno = 0; 2453 ut_params->sess = rte_cryptodev_sym_session_create( 2454 ts_params->valid_devs[0], &ut_params->cipher_xform, 2455 ts_params->session_mpool); 2456 if (rte_errno == ENOTSUP) 2457 return TEST_SKIPPED; 2458 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2459 2460 /* Generate crypto op data structure */ 2461 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2462 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2463 TEST_ASSERT_NOT_NULL(ut_params->op, 2464 "Failed to allocate symmetric crypto operation struct"); 2465 2466 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2467 2468 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2469 2470 /* set crypto operation source mbuf */ 2471 sym_op->m_src = ut_params->ibuf; 2472 2473 /* Set crypto operation authentication parameters */ 2474 sym_op->auth.digest.data = ut_params->digest; 2475 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2476 ut_params->ibuf, QUOTE_512_BYTES); 2477 2478 sym_op->auth.data.offset = 0; 2479 sym_op->auth.data.length = QUOTE_512_BYTES; 2480 2481 /* Copy IV at the end of the crypto operation */ 2482 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2483 aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC); 2484 2485 /* Set crypto operation cipher parameters */ 2486 sym_op->cipher.data.offset = 0; 2487 sym_op->cipher.data.length = QUOTE_512_BYTES; 2488 2489 /* Process crypto operation */ 2490 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2491 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2492 ut_params->op); 2493 else 2494 TEST_ASSERT_NOT_NULL( 2495 process_crypto_request(ts_params->valid_devs[0], 2496 ut_params->op), 2497 "failed to process sym crypto op"); 2498 2499 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2500 "crypto op processing failed"); 2501 2502 /* Validate obuf */ 2503 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 2504 uint8_t *); 2505 2506 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, 2507 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 2508 QUOTE_512_BYTES, 2509 "ciphertext data not as expected"); 2510 2511 uint8_t *digest = ciphertext + QUOTE_512_BYTES; 2512 2513 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, 2514 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, 2515 gbl_driver_id == rte_cryptodev_driver_id_get( 2516 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ? 2517 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : 2518 DIGEST_BYTE_LENGTH_SHA1, 2519 "Generated digest data not as expected"); 2520 2521 return TEST_SUCCESS; 2522 } 2523 2524 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ 2525 2526 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) 2527 2528 static uint8_t hmac_sha512_key[] = { 2529 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 2530 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2531 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2532 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60, 2533 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1, 2534 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2535 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76, 2536 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 }; 2537 2538 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = { 2539 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8, 2540 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48, 2541 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8, 2542 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70, 2543 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8, 2544 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E, 2545 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D, 2546 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A }; 2547 2548 2549 2550 static int 2551 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2552 struct crypto_unittest_params *ut_params, 2553 uint8_t *cipher_key, 2554 uint8_t *hmac_key); 2555 2556 static int 2557 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess, 2558 struct crypto_unittest_params *ut_params, 2559 struct crypto_testsuite_params *ts_params, 2560 const uint8_t *cipher, 2561 const uint8_t *digest, 2562 const uint8_t *iv); 2563 2564 2565 static int 2566 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2567 struct crypto_unittest_params *ut_params, 2568 uint8_t *cipher_key, 2569 uint8_t *hmac_key) 2570 { 2571 2572 /* Setup Cipher Parameters */ 2573 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2574 ut_params->cipher_xform.next = NULL; 2575 2576 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2577 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 2578 ut_params->cipher_xform.cipher.key.data = cipher_key; 2579 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2580 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2581 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2582 2583 /* Setup HMAC Parameters */ 2584 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2585 ut_params->auth_xform.next = &ut_params->cipher_xform; 2586 2587 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 2588 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC; 2589 ut_params->auth_xform.auth.key.data = hmac_key; 2590 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512; 2591 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512; 2592 2593 return TEST_SUCCESS; 2594 } 2595 2596 2597 static int 2598 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess, 2599 struct crypto_unittest_params *ut_params, 2600 struct crypto_testsuite_params *ts_params, 2601 const uint8_t *cipher, 2602 const uint8_t *digest, 2603 const uint8_t *iv) 2604 { 2605 int ret; 2606 2607 /* Generate test mbuf data and digest */ 2608 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2609 (const char *) 2610 cipher, 2611 QUOTE_512_BYTES, 0); 2612 2613 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2614 DIGEST_BYTE_LENGTH_SHA512); 2615 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2616 2617 rte_memcpy(ut_params->digest, 2618 digest, 2619 DIGEST_BYTE_LENGTH_SHA512); 2620 2621 /* Generate Crypto op data structure */ 2622 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2623 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2624 TEST_ASSERT_NOT_NULL(ut_params->op, 2625 "Failed to allocate symmetric crypto operation struct"); 2626 2627 rte_crypto_op_attach_sym_session(ut_params->op, sess); 2628 2629 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2630 2631 /* set crypto operation source mbuf */ 2632 sym_op->m_src = ut_params->ibuf; 2633 2634 sym_op->auth.digest.data = ut_params->digest; 2635 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2636 ut_params->ibuf, QUOTE_512_BYTES); 2637 2638 sym_op->auth.data.offset = 0; 2639 sym_op->auth.data.length = QUOTE_512_BYTES; 2640 2641 /* Copy IV at the end of the crypto operation */ 2642 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2643 iv, CIPHER_IV_LENGTH_AES_CBC); 2644 2645 sym_op->cipher.data.offset = 0; 2646 sym_op->cipher.data.length = QUOTE_512_BYTES; 2647 2648 /* Process crypto operation */ 2649 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2650 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2651 ut_params->op); 2652 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 2653 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 0); 2654 if (ret != TEST_SUCCESS) 2655 return ret; 2656 } else 2657 TEST_ASSERT_NOT_NULL( 2658 process_crypto_request(ts_params->valid_devs[0], 2659 ut_params->op), 2660 "failed to process sym crypto op"); 2661 2662 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2663 "crypto op processing failed"); 2664 2665 ut_params->obuf = ut_params->op->sym->m_src; 2666 2667 /* Validate obuf */ 2668 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2669 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 2670 catch_22_quote, 2671 QUOTE_512_BYTES, 2672 "Plaintext data not as expected"); 2673 2674 /* Validate obuf */ 2675 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2676 "Digest verification failed"); 2677 2678 return TEST_SUCCESS; 2679 } 2680 2681 /* ***** SNOW 3G Tests ***** */ 2682 static int 2683 create_wireless_algo_hash_session(uint8_t dev_id, 2684 const uint8_t *key, const uint8_t key_len, 2685 const uint8_t iv_len, const uint8_t auth_len, 2686 enum rte_crypto_auth_operation op, 2687 enum rte_crypto_auth_algorithm algo) 2688 { 2689 uint8_t hash_key[key_len]; 2690 2691 struct crypto_testsuite_params *ts_params = &testsuite_params; 2692 struct crypto_unittest_params *ut_params = &unittest_params; 2693 2694 memcpy(hash_key, key, key_len); 2695 2696 debug_hexdump(stdout, "key:", key, key_len); 2697 2698 /* Setup Authentication Parameters */ 2699 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2700 ut_params->auth_xform.next = NULL; 2701 2702 ut_params->auth_xform.auth.op = op; 2703 ut_params->auth_xform.auth.algo = algo; 2704 ut_params->auth_xform.auth.key.length = key_len; 2705 ut_params->auth_xform.auth.key.data = hash_key; 2706 ut_params->auth_xform.auth.digest_length = auth_len; 2707 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 2708 ut_params->auth_xform.auth.iv.length = iv_len; 2709 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2710 &ut_params->auth_xform, ts_params->session_mpool); 2711 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2712 return TEST_SKIPPED; 2713 2714 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2715 return 0; 2716 } 2717 2718 static int 2719 create_wireless_algo_cipher_session(uint8_t dev_id, 2720 enum rte_crypto_cipher_operation op, 2721 enum rte_crypto_cipher_algorithm algo, 2722 const uint8_t *key, const uint8_t key_len, 2723 uint8_t iv_len) 2724 { 2725 uint8_t cipher_key[key_len]; 2726 struct crypto_testsuite_params *ts_params = &testsuite_params; 2727 struct crypto_unittest_params *ut_params = &unittest_params; 2728 2729 memcpy(cipher_key, key, key_len); 2730 2731 /* Setup Cipher Parameters */ 2732 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2733 ut_params->cipher_xform.next = NULL; 2734 2735 ut_params->cipher_xform.cipher.algo = algo; 2736 ut_params->cipher_xform.cipher.op = op; 2737 ut_params->cipher_xform.cipher.key.data = cipher_key; 2738 ut_params->cipher_xform.cipher.key.length = key_len; 2739 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2740 ut_params->cipher_xform.cipher.iv.length = iv_len; 2741 2742 debug_hexdump(stdout, "key:", key, key_len); 2743 2744 /* Create Crypto session */ 2745 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2746 &ut_params->cipher_xform, ts_params->session_mpool); 2747 2748 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2749 return TEST_SKIPPED; 2750 2751 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2752 return 0; 2753 } 2754 2755 static int 2756 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len, 2757 unsigned int cipher_len, 2758 unsigned int cipher_offset) 2759 { 2760 struct crypto_testsuite_params *ts_params = &testsuite_params; 2761 struct crypto_unittest_params *ut_params = &unittest_params; 2762 2763 /* Generate Crypto op data structure */ 2764 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2765 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2766 TEST_ASSERT_NOT_NULL(ut_params->op, 2767 "Failed to allocate pktmbuf offload"); 2768 2769 /* Set crypto operation data parameters */ 2770 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2771 2772 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2773 2774 /* set crypto operation source mbuf */ 2775 sym_op->m_src = ut_params->ibuf; 2776 2777 /* iv */ 2778 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2779 iv, iv_len); 2780 sym_op->cipher.data.length = cipher_len; 2781 sym_op->cipher.data.offset = cipher_offset; 2782 return 0; 2783 } 2784 2785 static int 2786 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len, 2787 unsigned int cipher_len, 2788 unsigned int cipher_offset) 2789 { 2790 struct crypto_testsuite_params *ts_params = &testsuite_params; 2791 struct crypto_unittest_params *ut_params = &unittest_params; 2792 2793 /* Generate Crypto op data structure */ 2794 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2795 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2796 TEST_ASSERT_NOT_NULL(ut_params->op, 2797 "Failed to allocate pktmbuf offload"); 2798 2799 /* Set crypto operation data parameters */ 2800 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2801 2802 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2803 2804 /* set crypto operation source mbuf */ 2805 sym_op->m_src = ut_params->ibuf; 2806 sym_op->m_dst = ut_params->obuf; 2807 2808 /* iv */ 2809 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2810 iv, iv_len); 2811 sym_op->cipher.data.length = cipher_len; 2812 sym_op->cipher.data.offset = cipher_offset; 2813 return 0; 2814 } 2815 2816 static int 2817 create_wireless_algo_cipher_auth_session(uint8_t dev_id, 2818 enum rte_crypto_cipher_operation cipher_op, 2819 enum rte_crypto_auth_operation auth_op, 2820 enum rte_crypto_auth_algorithm auth_algo, 2821 enum rte_crypto_cipher_algorithm cipher_algo, 2822 const uint8_t *a_key, uint8_t a_key_len, 2823 const uint8_t *c_key, uint8_t c_key_len, 2824 uint8_t auth_iv_len, uint8_t auth_len, 2825 uint8_t cipher_iv_len) 2826 2827 { 2828 struct crypto_testsuite_params *ts_params = &testsuite_params; 2829 struct crypto_unittest_params *ut_params = &unittest_params; 2830 2831 /* Setup Authentication Parameters */ 2832 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2833 ut_params->auth_xform.next = NULL; 2834 2835 ut_params->auth_xform.auth.op = auth_op; 2836 ut_params->auth_xform.auth.algo = auth_algo; 2837 ut_params->auth_xform.auth.key.length = a_key_len; 2838 ut_params->auth_xform.auth.key.data = a_key; 2839 ut_params->auth_xform.auth.digest_length = auth_len; 2840 /* Auth IV will be after cipher IV */ 2841 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2842 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2843 2844 /* Setup Cipher Parameters */ 2845 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2846 ut_params->cipher_xform.next = &ut_params->auth_xform; 2847 2848 ut_params->cipher_xform.cipher.algo = cipher_algo; 2849 ut_params->cipher_xform.cipher.op = cipher_op; 2850 ut_params->cipher_xform.cipher.key.data = c_key; 2851 ut_params->cipher_xform.cipher.key.length = c_key_len; 2852 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2853 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2854 2855 debug_hexdump(stdout, "Auth key:", a_key, c_key_len); 2856 debug_hexdump(stdout, "Cipher key:", c_key, c_key_len); 2857 2858 /* Create Crypto session*/ 2859 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2860 &ut_params->cipher_xform, ts_params->session_mpool); 2861 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2862 return TEST_SKIPPED; 2863 2864 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2865 return 0; 2866 } 2867 2868 static int 2869 create_wireless_cipher_auth_session(uint8_t dev_id, 2870 enum rte_crypto_cipher_operation cipher_op, 2871 enum rte_crypto_auth_operation auth_op, 2872 enum rte_crypto_auth_algorithm auth_algo, 2873 enum rte_crypto_cipher_algorithm cipher_algo, 2874 const struct wireless_test_data *tdata) 2875 { 2876 const uint8_t key_len = tdata->key.len; 2877 uint8_t cipher_auth_key[key_len]; 2878 2879 struct crypto_testsuite_params *ts_params = &testsuite_params; 2880 struct crypto_unittest_params *ut_params = &unittest_params; 2881 const uint8_t *key = tdata->key.data; 2882 const uint8_t auth_len = tdata->digest.len; 2883 uint8_t cipher_iv_len = tdata->cipher_iv.len; 2884 uint8_t auth_iv_len = tdata->auth_iv.len; 2885 2886 memcpy(cipher_auth_key, key, key_len); 2887 2888 /* Setup Authentication Parameters */ 2889 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2890 ut_params->auth_xform.next = NULL; 2891 2892 ut_params->auth_xform.auth.op = auth_op; 2893 ut_params->auth_xform.auth.algo = auth_algo; 2894 ut_params->auth_xform.auth.key.length = key_len; 2895 /* Hash key = cipher key */ 2896 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2897 ut_params->auth_xform.auth.digest_length = auth_len; 2898 /* Auth IV will be after cipher IV */ 2899 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2900 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2901 2902 /* Setup Cipher Parameters */ 2903 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2904 ut_params->cipher_xform.next = &ut_params->auth_xform; 2905 2906 ut_params->cipher_xform.cipher.algo = cipher_algo; 2907 ut_params->cipher_xform.cipher.op = cipher_op; 2908 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2909 ut_params->cipher_xform.cipher.key.length = key_len; 2910 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2911 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2912 2913 2914 debug_hexdump(stdout, "key:", key, key_len); 2915 2916 /* Create Crypto session*/ 2917 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2918 &ut_params->cipher_xform, ts_params->session_mpool); 2919 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2920 return TEST_SKIPPED; 2921 2922 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2923 return 0; 2924 } 2925 2926 static int 2927 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id, 2928 const struct wireless_test_data *tdata) 2929 { 2930 return create_wireless_cipher_auth_session(dev_id, 2931 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2932 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3, 2933 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata); 2934 } 2935 2936 static int 2937 create_wireless_algo_auth_cipher_session(uint8_t dev_id, 2938 enum rte_crypto_cipher_operation cipher_op, 2939 enum rte_crypto_auth_operation auth_op, 2940 enum rte_crypto_auth_algorithm auth_algo, 2941 enum rte_crypto_cipher_algorithm cipher_algo, 2942 const uint8_t *a_key, const uint8_t a_key_len, 2943 const uint8_t *c_key, const uint8_t c_key_len, 2944 uint8_t auth_iv_len, uint8_t auth_len, 2945 uint8_t cipher_iv_len) 2946 { 2947 struct crypto_testsuite_params *ts_params = &testsuite_params; 2948 struct crypto_unittest_params *ut_params = &unittest_params; 2949 2950 /* Setup Authentication Parameters */ 2951 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2952 ut_params->auth_xform.auth.op = auth_op; 2953 ut_params->auth_xform.next = &ut_params->cipher_xform; 2954 ut_params->auth_xform.auth.algo = auth_algo; 2955 ut_params->auth_xform.auth.key.length = a_key_len; 2956 ut_params->auth_xform.auth.key.data = a_key; 2957 ut_params->auth_xform.auth.digest_length = auth_len; 2958 /* Auth IV will be after cipher IV */ 2959 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2960 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2961 2962 /* Setup Cipher Parameters */ 2963 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2964 ut_params->cipher_xform.next = NULL; 2965 ut_params->cipher_xform.cipher.algo = cipher_algo; 2966 ut_params->cipher_xform.cipher.op = cipher_op; 2967 ut_params->cipher_xform.cipher.key.data = c_key; 2968 ut_params->cipher_xform.cipher.key.length = c_key_len; 2969 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2970 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2971 2972 debug_hexdump(stdout, "Auth key:", a_key, a_key_len); 2973 debug_hexdump(stdout, "Cipher key:", c_key, c_key_len); 2974 2975 /* Create Crypto session*/ 2976 if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 2977 ut_params->auth_xform.next = NULL; 2978 ut_params->cipher_xform.next = &ut_params->auth_xform; 2979 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2980 &ut_params->cipher_xform, ts_params->session_mpool); 2981 } else 2982 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2983 &ut_params->auth_xform, ts_params->session_mpool); 2984 2985 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2986 return TEST_SKIPPED; 2987 2988 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2989 2990 return 0; 2991 } 2992 2993 static int 2994 create_wireless_algo_hash_operation(const uint8_t *auth_tag, 2995 unsigned int auth_tag_len, 2996 const uint8_t *iv, unsigned int iv_len, 2997 unsigned int data_pad_len, 2998 enum rte_crypto_auth_operation op, 2999 unsigned int auth_len, unsigned int auth_offset) 3000 { 3001 struct crypto_testsuite_params *ts_params = &testsuite_params; 3002 3003 struct crypto_unittest_params *ut_params = &unittest_params; 3004 3005 /* Generate Crypto op data structure */ 3006 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3007 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3008 TEST_ASSERT_NOT_NULL(ut_params->op, 3009 "Failed to allocate pktmbuf offload"); 3010 3011 /* Set crypto operation data parameters */ 3012 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 3013 3014 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3015 3016 /* set crypto operation source mbuf */ 3017 sym_op->m_src = ut_params->ibuf; 3018 3019 /* iv */ 3020 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 3021 iv, iv_len); 3022 /* digest */ 3023 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 3024 ut_params->ibuf, auth_tag_len); 3025 3026 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 3027 "no room to append auth tag"); 3028 ut_params->digest = sym_op->auth.digest.data; 3029 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3030 ut_params->ibuf, data_pad_len); 3031 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 3032 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3033 else 3034 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3035 3036 debug_hexdump(stdout, "digest:", 3037 sym_op->auth.digest.data, 3038 auth_tag_len); 3039 3040 sym_op->auth.data.length = auth_len; 3041 sym_op->auth.data.offset = auth_offset; 3042 3043 return 0; 3044 } 3045 3046 static int 3047 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata, 3048 enum rte_crypto_auth_operation op) 3049 { 3050 struct crypto_testsuite_params *ts_params = &testsuite_params; 3051 struct crypto_unittest_params *ut_params = &unittest_params; 3052 3053 const uint8_t *auth_tag = tdata->digest.data; 3054 const unsigned int auth_tag_len = tdata->digest.len; 3055 unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len); 3056 unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3057 3058 const uint8_t *cipher_iv = tdata->cipher_iv.data; 3059 const uint8_t cipher_iv_len = tdata->cipher_iv.len; 3060 const uint8_t *auth_iv = tdata->auth_iv.data; 3061 const uint8_t auth_iv_len = tdata->auth_iv.len; 3062 const unsigned int cipher_len = tdata->validCipherLenInBits.len; 3063 const unsigned int auth_len = tdata->validAuthLenInBits.len; 3064 3065 /* Generate Crypto op data structure */ 3066 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3067 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3068 TEST_ASSERT_NOT_NULL(ut_params->op, 3069 "Failed to allocate pktmbuf offload"); 3070 /* Set crypto operation data parameters */ 3071 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 3072 3073 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3074 3075 /* set crypto operation source mbuf */ 3076 sym_op->m_src = ut_params->ibuf; 3077 3078 /* digest */ 3079 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 3080 ut_params->ibuf, auth_tag_len); 3081 3082 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 3083 "no room to append auth tag"); 3084 ut_params->digest = sym_op->auth.digest.data; 3085 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3086 ut_params->ibuf, data_pad_len); 3087 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 3088 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3089 else 3090 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3091 3092 debug_hexdump(stdout, "digest:", 3093 sym_op->auth.digest.data, 3094 auth_tag_len); 3095 3096 /* Copy cipher and auth IVs at the end of the crypto operation */ 3097 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 3098 IV_OFFSET); 3099 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 3100 iv_ptr += cipher_iv_len; 3101 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 3102 3103 sym_op->cipher.data.length = cipher_len; 3104 sym_op->cipher.data.offset = 0; 3105 sym_op->auth.data.length = auth_len; 3106 sym_op->auth.data.offset = 0; 3107 3108 return 0; 3109 } 3110 3111 static int 3112 create_zuc_cipher_hash_generate_operation( 3113 const struct wireless_test_data *tdata) 3114 { 3115 return create_wireless_cipher_hash_operation(tdata, 3116 RTE_CRYPTO_AUTH_OP_GENERATE); 3117 } 3118 3119 static int 3120 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag, 3121 const unsigned auth_tag_len, 3122 const uint8_t *auth_iv, uint8_t auth_iv_len, 3123 unsigned data_pad_len, 3124 enum rte_crypto_auth_operation op, 3125 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 3126 const unsigned cipher_len, const unsigned cipher_offset, 3127 const unsigned auth_len, const unsigned auth_offset) 3128 { 3129 struct crypto_testsuite_params *ts_params = &testsuite_params; 3130 struct crypto_unittest_params *ut_params = &unittest_params; 3131 3132 enum rte_crypto_cipher_algorithm cipher_algo = 3133 ut_params->cipher_xform.cipher.algo; 3134 enum rte_crypto_auth_algorithm auth_algo = 3135 ut_params->auth_xform.auth.algo; 3136 3137 /* Generate Crypto op data structure */ 3138 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3139 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3140 TEST_ASSERT_NOT_NULL(ut_params->op, 3141 "Failed to allocate pktmbuf offload"); 3142 /* Set crypto operation data parameters */ 3143 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 3144 3145 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3146 3147 /* set crypto operation source mbuf */ 3148 sym_op->m_src = ut_params->ibuf; 3149 3150 /* digest */ 3151 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 3152 ut_params->ibuf, auth_tag_len); 3153 3154 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 3155 "no room to append auth tag"); 3156 ut_params->digest = sym_op->auth.digest.data; 3157 3158 if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) { 3159 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3160 ut_params->ibuf, data_pad_len); 3161 } else { 3162 struct rte_mbuf *m = ut_params->ibuf; 3163 unsigned int offset = data_pad_len; 3164 3165 while (offset > m->data_len && m->next != NULL) { 3166 offset -= m->data_len; 3167 m = m->next; 3168 } 3169 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3170 m, offset); 3171 } 3172 3173 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 3174 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3175 else 3176 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3177 3178 debug_hexdump(stdout, "digest:", 3179 sym_op->auth.digest.data, 3180 auth_tag_len); 3181 3182 /* Copy cipher and auth IVs at the end of the crypto operation */ 3183 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 3184 IV_OFFSET); 3185 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 3186 iv_ptr += cipher_iv_len; 3187 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 3188 3189 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 3190 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 3191 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 3192 sym_op->cipher.data.length = cipher_len; 3193 sym_op->cipher.data.offset = cipher_offset; 3194 } else { 3195 sym_op->cipher.data.length = cipher_len >> 3; 3196 sym_op->cipher.data.offset = cipher_offset >> 3; 3197 } 3198 3199 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 3200 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 3201 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 3202 sym_op->auth.data.length = auth_len; 3203 sym_op->auth.data.offset = auth_offset; 3204 } else { 3205 sym_op->auth.data.length = auth_len >> 3; 3206 sym_op->auth.data.offset = auth_offset >> 3; 3207 } 3208 3209 return 0; 3210 } 3211 3212 static int 3213 create_wireless_algo_auth_cipher_operation( 3214 const uint8_t *auth_tag, unsigned int auth_tag_len, 3215 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 3216 const uint8_t *auth_iv, uint8_t auth_iv_len, 3217 unsigned int data_pad_len, 3218 unsigned int cipher_len, unsigned int cipher_offset, 3219 unsigned int auth_len, unsigned int auth_offset, 3220 uint8_t op_mode, uint8_t do_sgl, uint8_t verify) 3221 { 3222 struct crypto_testsuite_params *ts_params = &testsuite_params; 3223 struct crypto_unittest_params *ut_params = &unittest_params; 3224 3225 enum rte_crypto_cipher_algorithm cipher_algo = 3226 ut_params->cipher_xform.cipher.algo; 3227 enum rte_crypto_auth_algorithm auth_algo = 3228 ut_params->auth_xform.auth.algo; 3229 3230 /* Generate Crypto op data structure */ 3231 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3232 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3233 TEST_ASSERT_NOT_NULL(ut_params->op, 3234 "Failed to allocate pktmbuf offload"); 3235 3236 /* Set crypto operation data parameters */ 3237 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 3238 3239 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3240 3241 /* set crypto operation mbufs */ 3242 sym_op->m_src = ut_params->ibuf; 3243 if (op_mode == OUT_OF_PLACE) 3244 sym_op->m_dst = ut_params->obuf; 3245 3246 /* digest */ 3247 if (!do_sgl) { 3248 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset( 3249 (op_mode == IN_PLACE ? 3250 ut_params->ibuf : ut_params->obuf), 3251 uint8_t *, data_pad_len); 3252 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3253 (op_mode == IN_PLACE ? 3254 ut_params->ibuf : ut_params->obuf), 3255 data_pad_len); 3256 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3257 } else { 3258 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3); 3259 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ? 3260 sym_op->m_src : sym_op->m_dst); 3261 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) { 3262 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 3263 sgl_buf = sgl_buf->next; 3264 } 3265 3266 /* The last segment should be large enough to hold full digest */ 3267 if (sgl_buf->data_len < auth_tag_len) { 3268 rte_pktmbuf_free(sgl_buf->next); 3269 sgl_buf->next = NULL; 3270 TEST_ASSERT_NOT_NULL(rte_pktmbuf_append(sgl_buf, 3271 auth_tag_len - sgl_buf->data_len), 3272 "No room to append auth tag"); 3273 } 3274 3275 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf, 3276 uint8_t *, remaining_off); 3277 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf, 3278 remaining_off); 3279 memset(sym_op->auth.digest.data, 0, remaining_off); 3280 while (sgl_buf->next != NULL) { 3281 memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *), 3282 0, rte_pktmbuf_data_len(sgl_buf)); 3283 sgl_buf = sgl_buf->next; 3284 } 3285 } 3286 3287 /* Copy digest for the verification */ 3288 if (verify) 3289 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3290 3291 /* Copy cipher and auth IVs at the end of the crypto operation */ 3292 uint8_t *iv_ptr = rte_crypto_op_ctod_offset( 3293 ut_params->op, uint8_t *, IV_OFFSET); 3294 3295 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 3296 iv_ptr += cipher_iv_len; 3297 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 3298 3299 /* Only copy over the offset data needed from src to dst in OOP, 3300 * if the auth and cipher offsets are not aligned 3301 */ 3302 if (op_mode == OUT_OF_PLACE) { 3303 if (cipher_offset > auth_offset) 3304 rte_memcpy( 3305 rte_pktmbuf_mtod_offset( 3306 sym_op->m_dst, 3307 uint8_t *, auth_offset >> 3), 3308 rte_pktmbuf_mtod_offset( 3309 sym_op->m_src, 3310 uint8_t *, auth_offset >> 3), 3311 ((cipher_offset >> 3) - (auth_offset >> 3))); 3312 } 3313 3314 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 3315 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 3316 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 3317 sym_op->cipher.data.length = cipher_len; 3318 sym_op->cipher.data.offset = cipher_offset; 3319 } else { 3320 sym_op->cipher.data.length = cipher_len >> 3; 3321 sym_op->cipher.data.offset = cipher_offset >> 3; 3322 } 3323 3324 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 3325 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 3326 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 3327 sym_op->auth.data.length = auth_len; 3328 sym_op->auth.data.offset = auth_offset; 3329 } else { 3330 sym_op->auth.data.length = auth_len >> 3; 3331 sym_op->auth.data.offset = auth_offset >> 3; 3332 } 3333 3334 return 0; 3335 } 3336 3337 static int 3338 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) 3339 { 3340 struct crypto_testsuite_params *ts_params = &testsuite_params; 3341 struct crypto_unittest_params *ut_params = &unittest_params; 3342 3343 int retval; 3344 unsigned plaintext_pad_len; 3345 unsigned plaintext_len; 3346 uint8_t *plaintext; 3347 struct rte_cryptodev_info dev_info; 3348 3349 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3350 uint64_t feat_flags = dev_info.feature_flags; 3351 3352 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3353 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3354 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3355 return TEST_SKIPPED; 3356 } 3357 3358 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3359 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3360 printf("Device doesn't support RAW data-path APIs.\n"); 3361 return TEST_SKIPPED; 3362 } 3363 3364 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3365 return TEST_SKIPPED; 3366 3367 /* Verify the capabilities */ 3368 struct rte_cryptodev_sym_capability_idx cap_idx; 3369 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3370 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3371 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3372 &cap_idx) == NULL) 3373 return TEST_SKIPPED; 3374 3375 /* Create SNOW 3G session */ 3376 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3377 tdata->key.data, tdata->key.len, 3378 tdata->auth_iv.len, tdata->digest.len, 3379 RTE_CRYPTO_AUTH_OP_GENERATE, 3380 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3381 if (retval < 0) 3382 return retval; 3383 3384 /* alloc mbuf and set payload */ 3385 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3386 3387 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3388 rte_pktmbuf_tailroom(ut_params->ibuf)); 3389 3390 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3391 /* Append data which is padded to a multiple of */ 3392 /* the algorithms block size */ 3393 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3394 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3395 plaintext_pad_len); 3396 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3397 3398 /* Create SNOW 3G operation */ 3399 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3400 tdata->auth_iv.data, tdata->auth_iv.len, 3401 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3402 tdata->validAuthLenInBits.len, 3403 0); 3404 if (retval < 0) 3405 return retval; 3406 3407 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3408 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 3409 0); 3410 if (retval != TEST_SUCCESS) 3411 return retval; 3412 } else 3413 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3414 ut_params->op); 3415 ut_params->obuf = ut_params->op->sym->m_src; 3416 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3417 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 3418 uint8_t *, 3419 plaintext_pad_len); 3420 3421 /* Validate obuf */ 3422 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3423 ut_params->digest, 3424 tdata->digest.data, 3425 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 3426 "SNOW 3G Generated auth tag not as expected"); 3427 3428 return 0; 3429 } 3430 3431 static int 3432 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) 3433 { 3434 struct crypto_testsuite_params *ts_params = &testsuite_params; 3435 struct crypto_unittest_params *ut_params = &unittest_params; 3436 3437 int retval; 3438 unsigned plaintext_pad_len; 3439 unsigned plaintext_len; 3440 uint8_t *plaintext; 3441 struct rte_cryptodev_info dev_info; 3442 3443 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3444 uint64_t feat_flags = dev_info.feature_flags; 3445 3446 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3447 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3448 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3449 return TEST_SKIPPED; 3450 } 3451 3452 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3453 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3454 printf("Device doesn't support RAW data-path APIs.\n"); 3455 return TEST_SKIPPED; 3456 } 3457 3458 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3459 return TEST_SKIPPED; 3460 3461 /* Verify the capabilities */ 3462 struct rte_cryptodev_sym_capability_idx cap_idx; 3463 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3464 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3465 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3466 &cap_idx) == NULL) 3467 return TEST_SKIPPED; 3468 3469 /* Create SNOW 3G session */ 3470 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3471 tdata->key.data, tdata->key.len, 3472 tdata->auth_iv.len, tdata->digest.len, 3473 RTE_CRYPTO_AUTH_OP_VERIFY, 3474 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3475 if (retval < 0) 3476 return retval; 3477 /* alloc mbuf and set payload */ 3478 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3479 3480 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3481 rte_pktmbuf_tailroom(ut_params->ibuf)); 3482 3483 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3484 /* Append data which is padded to a multiple of */ 3485 /* the algorithms block size */ 3486 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3487 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3488 plaintext_pad_len); 3489 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3490 3491 /* Create SNOW 3G operation */ 3492 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3493 tdata->digest.len, 3494 tdata->auth_iv.data, tdata->auth_iv.len, 3495 plaintext_pad_len, 3496 RTE_CRYPTO_AUTH_OP_VERIFY, 3497 tdata->validAuthLenInBits.len, 3498 0); 3499 if (retval < 0) 3500 return retval; 3501 3502 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3503 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 3504 0); 3505 if (retval != TEST_SUCCESS) 3506 return retval; 3507 } else 3508 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3509 ut_params->op); 3510 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3511 ut_params->obuf = ut_params->op->sym->m_src; 3512 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 3513 uint8_t *, 3514 plaintext_pad_len); 3515 3516 /* Validate obuf */ 3517 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3518 return 0; 3519 else 3520 return -1; 3521 3522 return 0; 3523 } 3524 3525 static int 3526 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata) 3527 { 3528 struct crypto_testsuite_params *ts_params = &testsuite_params; 3529 struct crypto_unittest_params *ut_params = &unittest_params; 3530 3531 int retval; 3532 unsigned plaintext_pad_len; 3533 unsigned plaintext_len; 3534 uint8_t *plaintext; 3535 struct rte_cryptodev_info dev_info; 3536 3537 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3538 uint64_t feat_flags = dev_info.feature_flags; 3539 3540 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3541 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3542 printf("Device doesn't support RAW data-path APIs.\n"); 3543 return TEST_SKIPPED; 3544 } 3545 3546 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3547 return TEST_SKIPPED; 3548 3549 /* Verify the capabilities */ 3550 struct rte_cryptodev_sym_capability_idx cap_idx; 3551 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3552 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3553 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3554 &cap_idx) == NULL) 3555 return TEST_SKIPPED; 3556 3557 /* Create KASUMI session */ 3558 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3559 tdata->key.data, tdata->key.len, 3560 0, tdata->digest.len, 3561 RTE_CRYPTO_AUTH_OP_GENERATE, 3562 RTE_CRYPTO_AUTH_KASUMI_F9); 3563 if (retval < 0) 3564 return retval; 3565 3566 /* alloc mbuf and set payload */ 3567 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3568 3569 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3570 rte_pktmbuf_tailroom(ut_params->ibuf)); 3571 3572 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3573 /* Append data which is padded to a multiple of */ 3574 /* the algorithms block size */ 3575 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3576 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3577 plaintext_pad_len); 3578 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3579 3580 /* Create KASUMI operation */ 3581 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3582 NULL, 0, 3583 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3584 tdata->plaintext.len, 3585 0); 3586 if (retval < 0) 3587 return retval; 3588 3589 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3590 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 3591 ut_params->op); 3592 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3593 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 3594 0); 3595 if (retval != TEST_SUCCESS) 3596 return retval; 3597 } else 3598 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3599 ut_params->op); 3600 3601 ut_params->obuf = ut_params->op->sym->m_src; 3602 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3603 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 3604 uint8_t *, 3605 plaintext_pad_len); 3606 3607 /* Validate obuf */ 3608 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3609 ut_params->digest, 3610 tdata->digest.data, 3611 DIGEST_BYTE_LENGTH_KASUMI_F9, 3612 "KASUMI Generated auth tag not as expected"); 3613 3614 return 0; 3615 } 3616 3617 static int 3618 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata) 3619 { 3620 struct crypto_testsuite_params *ts_params = &testsuite_params; 3621 struct crypto_unittest_params *ut_params = &unittest_params; 3622 3623 int retval; 3624 unsigned plaintext_pad_len; 3625 unsigned plaintext_len; 3626 uint8_t *plaintext; 3627 struct rte_cryptodev_info dev_info; 3628 3629 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3630 uint64_t feat_flags = dev_info.feature_flags; 3631 3632 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3633 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3634 printf("Device doesn't support RAW data-path APIs.\n"); 3635 return TEST_SKIPPED; 3636 } 3637 3638 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3639 return TEST_SKIPPED; 3640 3641 /* Verify the capabilities */ 3642 struct rte_cryptodev_sym_capability_idx cap_idx; 3643 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3644 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3645 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3646 &cap_idx) == NULL) 3647 return TEST_SKIPPED; 3648 3649 /* Create KASUMI session */ 3650 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3651 tdata->key.data, tdata->key.len, 3652 0, tdata->digest.len, 3653 RTE_CRYPTO_AUTH_OP_VERIFY, 3654 RTE_CRYPTO_AUTH_KASUMI_F9); 3655 if (retval < 0) 3656 return retval; 3657 /* alloc mbuf and set payload */ 3658 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3659 3660 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3661 rte_pktmbuf_tailroom(ut_params->ibuf)); 3662 3663 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3664 /* Append data which is padded to a multiple */ 3665 /* of the algorithms block size */ 3666 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3667 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3668 plaintext_pad_len); 3669 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3670 3671 /* Create KASUMI operation */ 3672 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3673 tdata->digest.len, 3674 NULL, 0, 3675 plaintext_pad_len, 3676 RTE_CRYPTO_AUTH_OP_VERIFY, 3677 tdata->plaintext.len, 3678 0); 3679 if (retval < 0) 3680 return retval; 3681 3682 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3683 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 3684 0); 3685 if (retval != TEST_SUCCESS) 3686 return retval; 3687 } else 3688 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3689 ut_params->op); 3690 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3691 ut_params->obuf = ut_params->op->sym->m_src; 3692 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 3693 uint8_t *, 3694 plaintext_pad_len); 3695 3696 /* Validate obuf */ 3697 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3698 return 0; 3699 else 3700 return -1; 3701 3702 return 0; 3703 } 3704 3705 static int 3706 test_snow3g_hash_generate_test_case_1(void) 3707 { 3708 return test_snow3g_authentication(&snow3g_hash_test_case_1); 3709 } 3710 3711 static int 3712 test_snow3g_hash_generate_test_case_2(void) 3713 { 3714 return test_snow3g_authentication(&snow3g_hash_test_case_2); 3715 } 3716 3717 static int 3718 test_snow3g_hash_generate_test_case_3(void) 3719 { 3720 return test_snow3g_authentication(&snow3g_hash_test_case_3); 3721 } 3722 3723 static int 3724 test_snow3g_hash_generate_test_case_4(void) 3725 { 3726 return test_snow3g_authentication(&snow3g_hash_test_case_4); 3727 } 3728 3729 static int 3730 test_snow3g_hash_generate_test_case_5(void) 3731 { 3732 return test_snow3g_authentication(&snow3g_hash_test_case_5); 3733 } 3734 3735 static int 3736 test_snow3g_hash_generate_test_case_6(void) 3737 { 3738 return test_snow3g_authentication(&snow3g_hash_test_case_6); 3739 } 3740 3741 static int 3742 test_snow3g_hash_verify_test_case_1(void) 3743 { 3744 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1); 3745 3746 } 3747 3748 static int 3749 test_snow3g_hash_verify_test_case_2(void) 3750 { 3751 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2); 3752 } 3753 3754 static int 3755 test_snow3g_hash_verify_test_case_3(void) 3756 { 3757 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3); 3758 } 3759 3760 static int 3761 test_snow3g_hash_verify_test_case_4(void) 3762 { 3763 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4); 3764 } 3765 3766 static int 3767 test_snow3g_hash_verify_test_case_5(void) 3768 { 3769 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5); 3770 } 3771 3772 static int 3773 test_snow3g_hash_verify_test_case_6(void) 3774 { 3775 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6); 3776 } 3777 3778 static int 3779 test_kasumi_hash_generate_test_case_1(void) 3780 { 3781 return test_kasumi_authentication(&kasumi_hash_test_case_1); 3782 } 3783 3784 static int 3785 test_kasumi_hash_generate_test_case_2(void) 3786 { 3787 return test_kasumi_authentication(&kasumi_hash_test_case_2); 3788 } 3789 3790 static int 3791 test_kasumi_hash_generate_test_case_3(void) 3792 { 3793 return test_kasumi_authentication(&kasumi_hash_test_case_3); 3794 } 3795 3796 static int 3797 test_kasumi_hash_generate_test_case_4(void) 3798 { 3799 return test_kasumi_authentication(&kasumi_hash_test_case_4); 3800 } 3801 3802 static int 3803 test_kasumi_hash_generate_test_case_5(void) 3804 { 3805 return test_kasumi_authentication(&kasumi_hash_test_case_5); 3806 } 3807 3808 static int 3809 test_kasumi_hash_generate_test_case_6(void) 3810 { 3811 return test_kasumi_authentication(&kasumi_hash_test_case_6); 3812 } 3813 3814 static int 3815 test_kasumi_hash_verify_test_case_1(void) 3816 { 3817 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1); 3818 } 3819 3820 static int 3821 test_kasumi_hash_verify_test_case_2(void) 3822 { 3823 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2); 3824 } 3825 3826 static int 3827 test_kasumi_hash_verify_test_case_3(void) 3828 { 3829 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3); 3830 } 3831 3832 static int 3833 test_kasumi_hash_verify_test_case_4(void) 3834 { 3835 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4); 3836 } 3837 3838 static int 3839 test_kasumi_hash_verify_test_case_5(void) 3840 { 3841 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5); 3842 } 3843 3844 static int 3845 test_kasumi_encryption(const struct kasumi_test_data *tdata) 3846 { 3847 struct crypto_testsuite_params *ts_params = &testsuite_params; 3848 struct crypto_unittest_params *ut_params = &unittest_params; 3849 3850 int retval; 3851 uint8_t *plaintext, *ciphertext; 3852 unsigned plaintext_pad_len; 3853 unsigned plaintext_len; 3854 struct rte_cryptodev_info dev_info; 3855 3856 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3857 uint64_t feat_flags = dev_info.feature_flags; 3858 3859 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3860 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3861 printf("Device doesn't support RAW data-path APIs.\n"); 3862 return TEST_SKIPPED; 3863 } 3864 3865 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3866 return TEST_SKIPPED; 3867 3868 /* Verify the capabilities */ 3869 struct rte_cryptodev_sym_capability_idx cap_idx; 3870 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3871 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3872 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3873 &cap_idx) == NULL) 3874 return TEST_SKIPPED; 3875 3876 /* Create KASUMI session */ 3877 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3878 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3879 RTE_CRYPTO_CIPHER_KASUMI_F8, 3880 tdata->key.data, tdata->key.len, 3881 tdata->cipher_iv.len); 3882 if (retval < 0) 3883 return retval; 3884 3885 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3886 3887 /* Clear mbuf payload */ 3888 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3889 rte_pktmbuf_tailroom(ut_params->ibuf)); 3890 3891 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3892 /* Append data which is padded to a multiple */ 3893 /* of the algorithms block size */ 3894 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3895 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3896 plaintext_pad_len); 3897 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3898 3899 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3900 3901 /* Create KASUMI operation */ 3902 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3903 tdata->cipher_iv.len, 3904 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3905 tdata->validCipherOffsetInBits.len); 3906 if (retval < 0) 3907 return retval; 3908 3909 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3910 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 3911 tdata->cipher_iv.len); 3912 if (retval != TEST_SUCCESS) 3913 return retval; 3914 } else 3915 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3916 ut_params->op); 3917 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3918 3919 ut_params->obuf = ut_params->op->sym->m_dst; 3920 if (ut_params->obuf) 3921 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3922 else 3923 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3924 3925 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3926 3927 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3928 (tdata->validCipherOffsetInBits.len >> 3); 3929 /* Validate obuf */ 3930 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3931 ciphertext, 3932 reference_ciphertext, 3933 tdata->validCipherLenInBits.len, 3934 "KASUMI Ciphertext data not as expected"); 3935 return 0; 3936 } 3937 3938 static int 3939 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata) 3940 { 3941 struct crypto_testsuite_params *ts_params = &testsuite_params; 3942 struct crypto_unittest_params *ut_params = &unittest_params; 3943 3944 int retval; 3945 3946 unsigned int plaintext_pad_len; 3947 unsigned int plaintext_len; 3948 3949 uint8_t buffer[10000]; 3950 const uint8_t *ciphertext; 3951 3952 struct rte_cryptodev_info dev_info; 3953 3954 /* Verify the capabilities */ 3955 struct rte_cryptodev_sym_capability_idx cap_idx; 3956 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3957 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3958 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3959 &cap_idx) == NULL) 3960 return TEST_SKIPPED; 3961 3962 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3963 3964 uint64_t feat_flags = dev_info.feature_flags; 3965 3966 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 3967 printf("Device doesn't support in-place scatter-gather. " 3968 "Test Skipped.\n"); 3969 return TEST_SKIPPED; 3970 } 3971 3972 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3973 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3974 printf("Device doesn't support RAW data-path APIs.\n"); 3975 return TEST_SKIPPED; 3976 } 3977 3978 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3979 return TEST_SKIPPED; 3980 3981 /* Create KASUMI session */ 3982 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3983 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3984 RTE_CRYPTO_CIPHER_KASUMI_F8, 3985 tdata->key.data, tdata->key.len, 3986 tdata->cipher_iv.len); 3987 if (retval < 0) 3988 return retval; 3989 3990 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3991 3992 3993 /* Append data which is padded to a multiple */ 3994 /* of the algorithms block size */ 3995 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3996 3997 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3998 plaintext_pad_len, 10, 0); 3999 4000 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 4001 4002 /* Create KASUMI operation */ 4003 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4004 tdata->cipher_iv.len, 4005 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4006 tdata->validCipherOffsetInBits.len); 4007 if (retval < 0) 4008 return retval; 4009 4010 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4011 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4012 tdata->cipher_iv.len); 4013 if (retval != TEST_SUCCESS) 4014 return retval; 4015 } else 4016 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4017 ut_params->op); 4018 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4019 4020 ut_params->obuf = ut_params->op->sym->m_dst; 4021 4022 if (ut_params->obuf) 4023 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4024 plaintext_len, buffer); 4025 else 4026 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 4027 tdata->validCipherOffsetInBits.len >> 3, 4028 plaintext_len, buffer); 4029 4030 /* Validate obuf */ 4031 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4032 4033 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 4034 (tdata->validCipherOffsetInBits.len >> 3); 4035 /* Validate obuf */ 4036 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4037 ciphertext, 4038 reference_ciphertext, 4039 tdata->validCipherLenInBits.len, 4040 "KASUMI Ciphertext data not as expected"); 4041 return 0; 4042 } 4043 4044 static int 4045 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata) 4046 { 4047 struct crypto_testsuite_params *ts_params = &testsuite_params; 4048 struct crypto_unittest_params *ut_params = &unittest_params; 4049 4050 int retval; 4051 uint8_t *plaintext, *ciphertext; 4052 unsigned plaintext_pad_len; 4053 unsigned plaintext_len; 4054 4055 /* Verify the capabilities */ 4056 struct rte_cryptodev_sym_capability_idx cap_idx; 4057 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4058 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4059 /* Data-path service does not support OOP */ 4060 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4061 &cap_idx) == NULL) 4062 return TEST_SKIPPED; 4063 4064 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4065 return TEST_SKIPPED; 4066 4067 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4068 return TEST_SKIPPED; 4069 4070 /* Create KASUMI session */ 4071 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4072 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4073 RTE_CRYPTO_CIPHER_KASUMI_F8, 4074 tdata->key.data, tdata->key.len, 4075 tdata->cipher_iv.len); 4076 if (retval < 0) 4077 return retval; 4078 4079 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4080 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4081 4082 /* Clear mbuf payload */ 4083 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4084 rte_pktmbuf_tailroom(ut_params->ibuf)); 4085 4086 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4087 /* Append data which is padded to a multiple */ 4088 /* of the algorithms block size */ 4089 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 4090 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4091 plaintext_pad_len); 4092 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4093 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4094 4095 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4096 4097 /* Create KASUMI operation */ 4098 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4099 tdata->cipher_iv.len, 4100 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4101 tdata->validCipherOffsetInBits.len); 4102 if (retval < 0) 4103 return retval; 4104 4105 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4106 ut_params->op); 4107 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4108 4109 ut_params->obuf = ut_params->op->sym->m_dst; 4110 if (ut_params->obuf) 4111 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4112 else 4113 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 4114 4115 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4116 4117 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 4118 (tdata->validCipherOffsetInBits.len >> 3); 4119 /* Validate obuf */ 4120 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4121 ciphertext, 4122 reference_ciphertext, 4123 tdata->validCipherLenInBits.len, 4124 "KASUMI Ciphertext data not as expected"); 4125 return 0; 4126 } 4127 4128 static int 4129 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata) 4130 { 4131 struct crypto_testsuite_params *ts_params = &testsuite_params; 4132 struct crypto_unittest_params *ut_params = &unittest_params; 4133 4134 int retval; 4135 unsigned int plaintext_pad_len; 4136 unsigned int plaintext_len; 4137 4138 const uint8_t *ciphertext; 4139 uint8_t buffer[2048]; 4140 4141 struct rte_cryptodev_info dev_info; 4142 4143 /* Verify the capabilities */ 4144 struct rte_cryptodev_sym_capability_idx cap_idx; 4145 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4146 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4147 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4148 &cap_idx) == NULL) 4149 return TEST_SKIPPED; 4150 4151 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4152 return TEST_SKIPPED; 4153 4154 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4155 return TEST_SKIPPED; 4156 4157 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4158 4159 uint64_t feat_flags = dev_info.feature_flags; 4160 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 4161 printf("Device doesn't support out-of-place scatter-gather " 4162 "in both input and output mbufs. " 4163 "Test Skipped.\n"); 4164 return TEST_SKIPPED; 4165 } 4166 4167 /* Create KASUMI session */ 4168 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4169 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4170 RTE_CRYPTO_CIPHER_KASUMI_F8, 4171 tdata->key.data, tdata->key.len, 4172 tdata->cipher_iv.len); 4173 if (retval < 0) 4174 return retval; 4175 4176 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4177 /* Append data which is padded to a multiple */ 4178 /* of the algorithms block size */ 4179 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 4180 4181 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4182 plaintext_pad_len, 10, 0); 4183 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4184 plaintext_pad_len, 3, 0); 4185 4186 /* Append data which is padded to a multiple */ 4187 /* of the algorithms block size */ 4188 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 4189 4190 /* Create KASUMI operation */ 4191 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4192 tdata->cipher_iv.len, 4193 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4194 tdata->validCipherOffsetInBits.len); 4195 if (retval < 0) 4196 return retval; 4197 4198 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4199 ut_params->op); 4200 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4201 4202 ut_params->obuf = ut_params->op->sym->m_dst; 4203 if (ut_params->obuf) 4204 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4205 plaintext_pad_len, buffer); 4206 else 4207 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 4208 tdata->validCipherOffsetInBits.len >> 3, 4209 plaintext_pad_len, buffer); 4210 4211 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 4212 (tdata->validCipherOffsetInBits.len >> 3); 4213 /* Validate obuf */ 4214 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4215 ciphertext, 4216 reference_ciphertext, 4217 tdata->validCipherLenInBits.len, 4218 "KASUMI Ciphertext data not as expected"); 4219 return 0; 4220 } 4221 4222 4223 static int 4224 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata) 4225 { 4226 struct crypto_testsuite_params *ts_params = &testsuite_params; 4227 struct crypto_unittest_params *ut_params = &unittest_params; 4228 4229 int retval; 4230 uint8_t *ciphertext, *plaintext; 4231 unsigned ciphertext_pad_len; 4232 unsigned ciphertext_len; 4233 4234 /* Verify the capabilities */ 4235 struct rte_cryptodev_sym_capability_idx cap_idx; 4236 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4237 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4238 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4239 &cap_idx) == NULL) 4240 return TEST_SKIPPED; 4241 4242 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4243 return TEST_SKIPPED; 4244 4245 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4246 return TEST_SKIPPED; 4247 4248 /* Create KASUMI session */ 4249 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4250 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4251 RTE_CRYPTO_CIPHER_KASUMI_F8, 4252 tdata->key.data, tdata->key.len, 4253 tdata->cipher_iv.len); 4254 if (retval < 0) 4255 return retval; 4256 4257 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4258 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4259 4260 /* Clear mbuf payload */ 4261 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4262 rte_pktmbuf_tailroom(ut_params->ibuf)); 4263 4264 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4265 /* Append data which is padded to a multiple */ 4266 /* of the algorithms block size */ 4267 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4268 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4269 ciphertext_pad_len); 4270 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4271 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4272 4273 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4274 4275 /* Create KASUMI operation */ 4276 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4277 tdata->cipher_iv.len, 4278 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4279 tdata->validCipherOffsetInBits.len); 4280 if (retval < 0) 4281 return retval; 4282 4283 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4284 ut_params->op); 4285 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4286 4287 ut_params->obuf = ut_params->op->sym->m_dst; 4288 if (ut_params->obuf) 4289 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4290 else 4291 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4292 4293 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4294 4295 const uint8_t *reference_plaintext = tdata->plaintext.data + 4296 (tdata->validCipherOffsetInBits.len >> 3); 4297 /* Validate obuf */ 4298 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4299 plaintext, 4300 reference_plaintext, 4301 tdata->validCipherLenInBits.len, 4302 "KASUMI Plaintext data not as expected"); 4303 return 0; 4304 } 4305 4306 static int 4307 test_kasumi_decryption(const struct kasumi_test_data *tdata) 4308 { 4309 struct crypto_testsuite_params *ts_params = &testsuite_params; 4310 struct crypto_unittest_params *ut_params = &unittest_params; 4311 4312 int retval; 4313 uint8_t *ciphertext, *plaintext; 4314 unsigned ciphertext_pad_len; 4315 unsigned ciphertext_len; 4316 struct rte_cryptodev_info dev_info; 4317 4318 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4319 uint64_t feat_flags = dev_info.feature_flags; 4320 4321 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4322 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4323 printf("Device doesn't support RAW data-path APIs.\n"); 4324 return TEST_SKIPPED; 4325 } 4326 4327 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4328 return TEST_SKIPPED; 4329 4330 /* Verify the capabilities */ 4331 struct rte_cryptodev_sym_capability_idx cap_idx; 4332 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4333 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4334 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4335 &cap_idx) == NULL) 4336 return TEST_SKIPPED; 4337 4338 /* Create KASUMI session */ 4339 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4340 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4341 RTE_CRYPTO_CIPHER_KASUMI_F8, 4342 tdata->key.data, tdata->key.len, 4343 tdata->cipher_iv.len); 4344 if (retval < 0) 4345 return retval; 4346 4347 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4348 4349 /* Clear mbuf payload */ 4350 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4351 rte_pktmbuf_tailroom(ut_params->ibuf)); 4352 4353 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4354 /* Append data which is padded to a multiple */ 4355 /* of the algorithms block size */ 4356 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4357 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4358 ciphertext_pad_len); 4359 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4360 4361 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4362 4363 /* Create KASUMI operation */ 4364 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4365 tdata->cipher_iv.len, 4366 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4367 tdata->validCipherOffsetInBits.len); 4368 if (retval < 0) 4369 return retval; 4370 4371 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4372 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4373 0); 4374 if (retval != TEST_SUCCESS) 4375 return retval; 4376 } else 4377 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4378 ut_params->op); 4379 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4380 4381 ut_params->obuf = ut_params->op->sym->m_dst; 4382 if (ut_params->obuf) 4383 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4384 else 4385 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4386 4387 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4388 4389 const uint8_t *reference_plaintext = tdata->plaintext.data + 4390 (tdata->validCipherOffsetInBits.len >> 3); 4391 /* Validate obuf */ 4392 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4393 plaintext, 4394 reference_plaintext, 4395 tdata->validCipherLenInBits.len, 4396 "KASUMI Plaintext data not as expected"); 4397 return 0; 4398 } 4399 4400 static int 4401 test_snow3g_encryption(const struct snow3g_test_data *tdata) 4402 { 4403 struct crypto_testsuite_params *ts_params = &testsuite_params; 4404 struct crypto_unittest_params *ut_params = &unittest_params; 4405 4406 int retval; 4407 uint8_t *plaintext, *ciphertext; 4408 unsigned plaintext_pad_len; 4409 unsigned plaintext_len; 4410 struct rte_cryptodev_info dev_info; 4411 4412 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4413 uint64_t feat_flags = dev_info.feature_flags; 4414 4415 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4416 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4417 printf("Device doesn't support RAW data-path APIs.\n"); 4418 return TEST_SKIPPED; 4419 } 4420 4421 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4422 return TEST_SKIPPED; 4423 4424 /* Verify the capabilities */ 4425 struct rte_cryptodev_sym_capability_idx cap_idx; 4426 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4427 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4428 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4429 &cap_idx) == NULL) 4430 return TEST_SKIPPED; 4431 4432 /* Create SNOW 3G session */ 4433 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4434 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4435 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4436 tdata->key.data, tdata->key.len, 4437 tdata->cipher_iv.len); 4438 if (retval < 0) 4439 return retval; 4440 4441 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4442 4443 /* Clear mbuf payload */ 4444 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4445 rte_pktmbuf_tailroom(ut_params->ibuf)); 4446 4447 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4448 /* Append data which is padded to a multiple of */ 4449 /* the algorithms block size */ 4450 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4451 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4452 plaintext_pad_len); 4453 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4454 4455 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4456 4457 /* Create SNOW 3G operation */ 4458 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4459 tdata->cipher_iv.len, 4460 tdata->validCipherLenInBits.len, 4461 0); 4462 if (retval < 0) 4463 return retval; 4464 4465 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4466 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4467 tdata->cipher_iv.len); 4468 if (retval != TEST_SUCCESS) 4469 return retval; 4470 } else 4471 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4472 ut_params->op); 4473 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4474 4475 ut_params->obuf = ut_params->op->sym->m_dst; 4476 if (ut_params->obuf) 4477 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4478 else 4479 ciphertext = plaintext; 4480 4481 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4482 4483 /* Validate obuf */ 4484 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4485 ciphertext, 4486 tdata->ciphertext.data, 4487 tdata->validDataLenInBits.len, 4488 "SNOW 3G Ciphertext data not as expected"); 4489 return 0; 4490 } 4491 4492 4493 static int 4494 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) 4495 { 4496 struct crypto_testsuite_params *ts_params = &testsuite_params; 4497 struct crypto_unittest_params *ut_params = &unittest_params; 4498 uint8_t *plaintext, *ciphertext; 4499 4500 int retval; 4501 unsigned plaintext_pad_len; 4502 unsigned plaintext_len; 4503 struct rte_cryptodev_info dev_info; 4504 4505 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4506 uint64_t feat_flags = dev_info.feature_flags; 4507 4508 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4509 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4510 printf("Device does not support RAW data-path APIs.\n"); 4511 return -ENOTSUP; 4512 } 4513 4514 /* Verify the capabilities */ 4515 struct rte_cryptodev_sym_capability_idx cap_idx; 4516 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4517 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4518 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4519 &cap_idx) == NULL) 4520 return TEST_SKIPPED; 4521 4522 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4523 return TEST_SKIPPED; 4524 4525 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4526 return TEST_SKIPPED; 4527 4528 /* Create SNOW 3G session */ 4529 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4530 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4531 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4532 tdata->key.data, tdata->key.len, 4533 tdata->cipher_iv.len); 4534 if (retval < 0) 4535 return retval; 4536 4537 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4538 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4539 4540 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4541 "Failed to allocate input buffer in mempool"); 4542 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4543 "Failed to allocate output buffer in mempool"); 4544 4545 /* Clear mbuf payload */ 4546 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4547 rte_pktmbuf_tailroom(ut_params->ibuf)); 4548 4549 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4550 /* Append data which is padded to a multiple of */ 4551 /* the algorithms block size */ 4552 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4553 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4554 plaintext_pad_len); 4555 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4556 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4557 4558 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4559 4560 /* Create SNOW 3G operation */ 4561 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4562 tdata->cipher_iv.len, 4563 tdata->validCipherLenInBits.len, 4564 0); 4565 if (retval < 0) 4566 return retval; 4567 4568 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4569 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4570 tdata->cipher_iv.len); 4571 if (retval != TEST_SUCCESS) 4572 return retval; 4573 } else 4574 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4575 ut_params->op); 4576 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4577 4578 ut_params->obuf = ut_params->op->sym->m_dst; 4579 if (ut_params->obuf) 4580 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4581 else 4582 ciphertext = plaintext; 4583 4584 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4585 4586 /* Validate obuf */ 4587 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4588 ciphertext, 4589 tdata->ciphertext.data, 4590 tdata->validDataLenInBits.len, 4591 "SNOW 3G Ciphertext data not as expected"); 4592 return 0; 4593 } 4594 4595 static int 4596 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata, 4597 uint8_t sgl_in, uint8_t sgl_out) 4598 { 4599 struct crypto_testsuite_params *ts_params = &testsuite_params; 4600 struct crypto_unittest_params *ut_params = &unittest_params; 4601 4602 int retval; 4603 unsigned int plaintext_pad_len; 4604 unsigned int plaintext_len; 4605 uint8_t buffer[10000]; 4606 const uint8_t *ciphertext; 4607 4608 struct rte_cryptodev_info dev_info; 4609 4610 /* Verify the capabilities */ 4611 struct rte_cryptodev_sym_capability_idx cap_idx; 4612 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4613 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4614 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4615 &cap_idx) == NULL) 4616 return TEST_SKIPPED; 4617 4618 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4619 return TEST_SKIPPED; 4620 4621 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4622 return TEST_SKIPPED; 4623 4624 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4625 4626 uint64_t feat_flags = dev_info.feature_flags; 4627 4628 if (((sgl_in && sgl_out) && !(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 4629 || ((!sgl_in && sgl_out) && 4630 !(feat_flags & RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 4631 || ((sgl_in && !sgl_out) && 4632 !(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))) { 4633 printf("Device doesn't support out-of-place scatter gather type. " 4634 "Test Skipped.\n"); 4635 return TEST_SKIPPED; 4636 } 4637 4638 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4639 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4640 printf("Device does not support RAW data-path APIs.\n"); 4641 return -ENOTSUP; 4642 } 4643 4644 /* Create SNOW 3G session */ 4645 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4646 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4647 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4648 tdata->key.data, tdata->key.len, 4649 tdata->cipher_iv.len); 4650 if (retval < 0) 4651 return retval; 4652 4653 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4654 /* Append data which is padded to a multiple of */ 4655 /* the algorithms block size */ 4656 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4657 4658 if (sgl_in) 4659 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4660 plaintext_pad_len, 10, 0); 4661 else { 4662 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4663 rte_pktmbuf_append(ut_params->ibuf, plaintext_pad_len); 4664 } 4665 4666 if (sgl_out) 4667 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4668 plaintext_pad_len, 3, 0); 4669 else { 4670 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4671 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4672 } 4673 4674 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4675 "Failed to allocate input buffer in mempool"); 4676 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4677 "Failed to allocate output buffer in mempool"); 4678 4679 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 4680 4681 /* Create SNOW 3G operation */ 4682 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4683 tdata->cipher_iv.len, 4684 tdata->validCipherLenInBits.len, 4685 0); 4686 if (retval < 0) 4687 return retval; 4688 4689 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4690 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4691 tdata->cipher_iv.len); 4692 if (retval != TEST_SUCCESS) 4693 return retval; 4694 } else 4695 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4696 ut_params->op); 4697 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4698 4699 ut_params->obuf = ut_params->op->sym->m_dst; 4700 if (ut_params->obuf) 4701 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4702 plaintext_len, buffer); 4703 else 4704 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4705 plaintext_len, buffer); 4706 4707 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4708 4709 /* Validate obuf */ 4710 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4711 ciphertext, 4712 tdata->ciphertext.data, 4713 tdata->validDataLenInBits.len, 4714 "SNOW 3G Ciphertext data not as expected"); 4715 4716 return 0; 4717 } 4718 4719 /* Shift right a buffer by "offset" bits, "offset" < 8 */ 4720 static void 4721 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) 4722 { 4723 uint8_t curr_byte, prev_byte; 4724 uint32_t length_in_bytes = ceil_byte_length(length + offset); 4725 uint8_t lower_byte_mask = (1 << offset) - 1; 4726 unsigned i; 4727 4728 prev_byte = buffer[0]; 4729 buffer[0] >>= offset; 4730 4731 for (i = 1; i < length_in_bytes; i++) { 4732 curr_byte = buffer[i]; 4733 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | 4734 (curr_byte >> offset); 4735 prev_byte = curr_byte; 4736 } 4737 } 4738 4739 static int 4740 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) 4741 { 4742 struct crypto_testsuite_params *ts_params = &testsuite_params; 4743 struct crypto_unittest_params *ut_params = &unittest_params; 4744 uint8_t *plaintext, *ciphertext; 4745 int retval; 4746 uint32_t plaintext_len; 4747 uint32_t plaintext_pad_len; 4748 uint8_t extra_offset = 4; 4749 uint8_t *expected_ciphertext_shifted; 4750 struct rte_cryptodev_info dev_info; 4751 4752 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4753 uint64_t feat_flags = dev_info.feature_flags; 4754 4755 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4756 ((tdata->validDataLenInBits.len % 8) != 0)) { 4757 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4758 return TEST_SKIPPED; 4759 } 4760 4761 /* Verify the capabilities */ 4762 struct rte_cryptodev_sym_capability_idx cap_idx; 4763 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4764 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4765 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4766 &cap_idx) == NULL) 4767 return TEST_SKIPPED; 4768 4769 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4770 return TEST_SKIPPED; 4771 4772 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4773 return TEST_SKIPPED; 4774 4775 /* Create SNOW 3G session */ 4776 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4777 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4778 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4779 tdata->key.data, tdata->key.len, 4780 tdata->cipher_iv.len); 4781 if (retval < 0) 4782 return retval; 4783 4784 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4785 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4786 4787 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4788 "Failed to allocate input buffer in mempool"); 4789 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4790 "Failed to allocate output buffer in mempool"); 4791 4792 /* Clear mbuf payload */ 4793 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4794 rte_pktmbuf_tailroom(ut_params->ibuf)); 4795 4796 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset); 4797 /* 4798 * Append data which is padded to a 4799 * multiple of the algorithms block size 4800 */ 4801 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4802 4803 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, 4804 plaintext_pad_len); 4805 4806 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4807 4808 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); 4809 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); 4810 4811 #ifdef RTE_APP_TEST_DEBUG 4812 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); 4813 #endif 4814 /* Create SNOW 3G operation */ 4815 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4816 tdata->cipher_iv.len, 4817 tdata->validCipherLenInBits.len, 4818 extra_offset); 4819 if (retval < 0) 4820 return retval; 4821 4822 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4823 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4824 tdata->cipher_iv.len); 4825 if (retval != TEST_SUCCESS) 4826 return retval; 4827 } else 4828 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4829 ut_params->op); 4830 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4831 4832 ut_params->obuf = ut_params->op->sym->m_dst; 4833 if (ut_params->obuf) 4834 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4835 else 4836 ciphertext = plaintext; 4837 4838 #ifdef RTE_APP_TEST_DEBUG 4839 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4840 #endif 4841 4842 expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8); 4843 4844 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, 4845 "failed to reserve memory for ciphertext shifted\n"); 4846 4847 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, 4848 ceil_byte_length(tdata->ciphertext.len)); 4849 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, 4850 extra_offset); 4851 /* Validate obuf */ 4852 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4853 ciphertext, 4854 expected_ciphertext_shifted, 4855 tdata->validDataLenInBits.len, 4856 extra_offset, 4857 "SNOW 3G Ciphertext data not as expected"); 4858 return 0; 4859 } 4860 4861 static int test_snow3g_decryption(const struct snow3g_test_data *tdata) 4862 { 4863 struct crypto_testsuite_params *ts_params = &testsuite_params; 4864 struct crypto_unittest_params *ut_params = &unittest_params; 4865 4866 int retval; 4867 4868 uint8_t *plaintext, *ciphertext; 4869 unsigned ciphertext_pad_len; 4870 unsigned ciphertext_len; 4871 struct rte_cryptodev_info dev_info; 4872 4873 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4874 uint64_t feat_flags = dev_info.feature_flags; 4875 4876 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4877 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4878 printf("Device doesn't support RAW data-path APIs.\n"); 4879 return TEST_SKIPPED; 4880 } 4881 4882 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4883 return TEST_SKIPPED; 4884 4885 /* Verify the capabilities */ 4886 struct rte_cryptodev_sym_capability_idx cap_idx; 4887 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4888 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4889 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4890 &cap_idx) == NULL) 4891 return TEST_SKIPPED; 4892 4893 /* Create SNOW 3G session */ 4894 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4895 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4896 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4897 tdata->key.data, tdata->key.len, 4898 tdata->cipher_iv.len); 4899 if (retval < 0) 4900 return retval; 4901 4902 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4903 4904 /* Clear mbuf payload */ 4905 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4906 rte_pktmbuf_tailroom(ut_params->ibuf)); 4907 4908 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4909 /* Append data which is padded to a multiple of */ 4910 /* the algorithms block size */ 4911 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4912 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4913 ciphertext_pad_len); 4914 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4915 4916 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4917 4918 /* Create SNOW 3G operation */ 4919 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4920 tdata->cipher_iv.len, 4921 tdata->validCipherLenInBits.len, 4922 tdata->cipher.offset_bits); 4923 if (retval < 0) 4924 return retval; 4925 4926 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4927 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4928 tdata->cipher_iv.len); 4929 if (retval != TEST_SUCCESS) 4930 return retval; 4931 } else 4932 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4933 ut_params->op); 4934 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4935 ut_params->obuf = ut_params->op->sym->m_dst; 4936 if (ut_params->obuf) 4937 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4938 else 4939 plaintext = ciphertext; 4940 4941 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4942 4943 /* Validate obuf */ 4944 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4945 tdata->plaintext.data, 4946 tdata->validDataLenInBits.len, 4947 "SNOW 3G Plaintext data not as expected"); 4948 return 0; 4949 } 4950 4951 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) 4952 { 4953 struct crypto_testsuite_params *ts_params = &testsuite_params; 4954 struct crypto_unittest_params *ut_params = &unittest_params; 4955 4956 int retval; 4957 4958 uint8_t *plaintext, *ciphertext; 4959 unsigned ciphertext_pad_len; 4960 unsigned ciphertext_len; 4961 struct rte_cryptodev_info dev_info; 4962 4963 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4964 uint64_t feat_flags = dev_info.feature_flags; 4965 4966 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4967 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4968 printf("Device does not support RAW data-path APIs.\n"); 4969 return -ENOTSUP; 4970 } 4971 /* Verify the capabilities */ 4972 struct rte_cryptodev_sym_capability_idx cap_idx; 4973 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4974 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4975 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4976 &cap_idx) == NULL) 4977 return TEST_SKIPPED; 4978 4979 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4980 return TEST_SKIPPED; 4981 4982 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4983 return TEST_SKIPPED; 4984 4985 /* Create SNOW 3G session */ 4986 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4987 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4988 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4989 tdata->key.data, tdata->key.len, 4990 tdata->cipher_iv.len); 4991 if (retval < 0) 4992 return retval; 4993 4994 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4995 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4996 4997 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4998 "Failed to allocate input buffer"); 4999 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5000 "Failed to allocate output buffer"); 5001 5002 /* Clear mbuf payload */ 5003 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5004 rte_pktmbuf_tailroom(ut_params->ibuf)); 5005 5006 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5007 rte_pktmbuf_tailroom(ut_params->obuf)); 5008 5009 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5010 /* Append data which is padded to a multiple of */ 5011 /* the algorithms block size */ 5012 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5013 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5014 ciphertext_pad_len); 5015 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5016 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5017 5018 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 5019 5020 /* Create SNOW 3G operation */ 5021 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 5022 tdata->cipher_iv.len, 5023 tdata->validCipherLenInBits.len, 5024 0); 5025 if (retval < 0) 5026 return retval; 5027 5028 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5029 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 5030 tdata->cipher_iv.len); 5031 if (retval != TEST_SUCCESS) 5032 return retval; 5033 } else 5034 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5035 ut_params->op); 5036 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5037 ut_params->obuf = ut_params->op->sym->m_dst; 5038 if (ut_params->obuf) 5039 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 5040 else 5041 plaintext = ciphertext; 5042 5043 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 5044 5045 /* Validate obuf */ 5046 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 5047 tdata->plaintext.data, 5048 tdata->validDataLenInBits.len, 5049 "SNOW 3G Plaintext data not as expected"); 5050 return 0; 5051 } 5052 5053 static int 5054 test_zuc_cipher_auth(const struct wireless_test_data *tdata) 5055 { 5056 struct crypto_testsuite_params *ts_params = &testsuite_params; 5057 struct crypto_unittest_params *ut_params = &unittest_params; 5058 5059 int retval; 5060 5061 uint8_t *plaintext, *ciphertext; 5062 unsigned int plaintext_pad_len; 5063 unsigned int plaintext_len; 5064 5065 struct rte_cryptodev_info dev_info; 5066 5067 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5068 uint64_t feat_flags = dev_info.feature_flags; 5069 5070 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 5071 ((tdata->validAuthLenInBits.len % 8 != 0) || 5072 (tdata->validDataLenInBits.len % 8 != 0))) { 5073 printf("Device doesn't support NON-Byte Aligned Data.\n"); 5074 return TEST_SKIPPED; 5075 } 5076 5077 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5078 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5079 printf("Device doesn't support RAW data-path APIs.\n"); 5080 return TEST_SKIPPED; 5081 } 5082 5083 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5084 return TEST_SKIPPED; 5085 5086 /* Check if device supports ZUC EEA3 */ 5087 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 5088 tdata->key.len, tdata->cipher_iv.len) < 0) 5089 return TEST_SKIPPED; 5090 5091 /* Check if device supports ZUC EIA3 */ 5092 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 5093 tdata->key.len, tdata->auth_iv.len, 5094 tdata->digest.len) < 0) 5095 return TEST_SKIPPED; 5096 5097 /* Create ZUC session */ 5098 retval = create_zuc_cipher_auth_encrypt_generate_session( 5099 ts_params->valid_devs[0], 5100 tdata); 5101 if (retval != 0) 5102 return retval; 5103 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5104 5105 /* clear mbuf payload */ 5106 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5107 rte_pktmbuf_tailroom(ut_params->ibuf)); 5108 5109 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5110 /* Append data which is padded to a multiple of */ 5111 /* the algorithms block size */ 5112 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5113 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5114 plaintext_pad_len); 5115 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5116 5117 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5118 5119 /* Create ZUC operation */ 5120 retval = create_zuc_cipher_hash_generate_operation(tdata); 5121 if (retval < 0) 5122 return retval; 5123 5124 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5125 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5126 tdata->cipher_iv.len); 5127 if (retval != TEST_SUCCESS) 5128 return retval; 5129 } else 5130 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5131 ut_params->op); 5132 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5133 ut_params->obuf = ut_params->op->sym->m_src; 5134 if (ut_params->obuf) 5135 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 5136 else 5137 ciphertext = plaintext; 5138 5139 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 5140 /* Validate obuf */ 5141 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5142 ciphertext, 5143 tdata->ciphertext.data, 5144 tdata->validDataLenInBits.len, 5145 "ZUC Ciphertext data not as expected"); 5146 5147 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 5148 uint8_t *, 5149 plaintext_pad_len); 5150 5151 /* Validate obuf */ 5152 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5153 ut_params->digest, 5154 tdata->digest.data, 5155 tdata->digest.len, 5156 "ZUC Generated auth tag not as expected"); 5157 return 0; 5158 } 5159 5160 static int 5161 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) 5162 { 5163 struct crypto_testsuite_params *ts_params = &testsuite_params; 5164 struct crypto_unittest_params *ut_params = &unittest_params; 5165 5166 int retval; 5167 5168 uint8_t *plaintext, *ciphertext; 5169 unsigned plaintext_pad_len; 5170 unsigned plaintext_len; 5171 struct rte_cryptodev_info dev_info; 5172 5173 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5174 uint64_t feat_flags = dev_info.feature_flags; 5175 5176 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5177 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5178 printf("Device doesn't support RAW data-path APIs.\n"); 5179 return TEST_SKIPPED; 5180 } 5181 5182 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5183 return TEST_SKIPPED; 5184 5185 /* Verify the capabilities */ 5186 struct rte_cryptodev_sym_capability_idx cap_idx; 5187 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5188 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5189 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5190 &cap_idx) == NULL) 5191 return TEST_SKIPPED; 5192 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5193 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5194 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5195 &cap_idx) == NULL) 5196 return TEST_SKIPPED; 5197 5198 /* Create SNOW 3G session */ 5199 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0], 5200 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5201 RTE_CRYPTO_AUTH_OP_GENERATE, 5202 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5203 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5204 tdata->key.data, tdata->key.len, 5205 tdata->key.data, tdata->key.len, 5206 tdata->auth_iv.len, tdata->digest.len, 5207 tdata->cipher_iv.len); 5208 if (retval != 0) 5209 return retval; 5210 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5211 5212 /* clear mbuf payload */ 5213 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5214 rte_pktmbuf_tailroom(ut_params->ibuf)); 5215 5216 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5217 /* Append data which is padded to a multiple of */ 5218 /* the algorithms block size */ 5219 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5220 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5221 plaintext_pad_len); 5222 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5223 5224 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5225 5226 /* Create SNOW 3G operation */ 5227 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 5228 tdata->digest.len, tdata->auth_iv.data, 5229 tdata->auth_iv.len, 5230 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5231 tdata->cipher_iv.data, tdata->cipher_iv.len, 5232 tdata->validCipherLenInBits.len, 5233 0, 5234 tdata->validAuthLenInBits.len, 5235 0 5236 ); 5237 if (retval < 0) 5238 return retval; 5239 5240 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5241 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5242 tdata->cipher_iv.len); 5243 if (retval != TEST_SUCCESS) 5244 return retval; 5245 } else 5246 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5247 ut_params->op); 5248 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5249 ut_params->obuf = ut_params->op->sym->m_src; 5250 if (ut_params->obuf) 5251 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 5252 else 5253 ciphertext = plaintext; 5254 5255 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 5256 /* Validate obuf */ 5257 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5258 ciphertext, 5259 tdata->ciphertext.data, 5260 tdata->validDataLenInBits.len, 5261 "SNOW 3G Ciphertext data not as expected"); 5262 5263 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 5264 uint8_t *, 5265 plaintext_pad_len); 5266 5267 /* Validate obuf */ 5268 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5269 ut_params->digest, 5270 tdata->digest.data, 5271 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5272 "SNOW 3G Generated auth tag not as expected"); 5273 return 0; 5274 } 5275 5276 static int 5277 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata, 5278 uint8_t op_mode, uint8_t verify) 5279 { 5280 struct crypto_testsuite_params *ts_params = &testsuite_params; 5281 struct crypto_unittest_params *ut_params = &unittest_params; 5282 5283 int retval; 5284 5285 uint8_t *plaintext = NULL, *ciphertext = NULL; 5286 unsigned int plaintext_pad_len; 5287 unsigned int plaintext_len; 5288 unsigned int ciphertext_pad_len; 5289 unsigned int ciphertext_len; 5290 unsigned int digest_offset; 5291 5292 struct rte_cryptodev_info dev_info; 5293 5294 /* Verify the capabilities */ 5295 struct rte_cryptodev_sym_capability_idx cap_idx; 5296 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5297 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5298 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5299 &cap_idx) == NULL) 5300 return TEST_SKIPPED; 5301 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5302 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5303 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5304 &cap_idx) == NULL) 5305 return TEST_SKIPPED; 5306 5307 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5308 return TEST_SKIPPED; 5309 5310 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5311 5312 uint64_t feat_flags = dev_info.feature_flags; 5313 5314 if (op_mode == OUT_OF_PLACE) { 5315 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5316 printf("Device doesn't support digest encrypted.\n"); 5317 return TEST_SKIPPED; 5318 } 5319 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5320 return TEST_SKIPPED; 5321 } 5322 5323 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5324 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5325 printf("Device doesn't support RAW data-path APIs.\n"); 5326 return TEST_SKIPPED; 5327 } 5328 5329 /* Create SNOW 3G session */ 5330 retval = create_wireless_algo_auth_cipher_session( 5331 ts_params->valid_devs[0], 5332 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5333 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5334 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5335 : RTE_CRYPTO_AUTH_OP_GENERATE), 5336 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5337 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5338 tdata->key.data, tdata->key.len, 5339 tdata->key.data, tdata->key.len, 5340 tdata->auth_iv.len, tdata->digest.len, 5341 tdata->cipher_iv.len); 5342 if (retval != 0) 5343 return retval; 5344 5345 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5346 if (op_mode == OUT_OF_PLACE) 5347 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5348 5349 /* clear mbuf payload */ 5350 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5351 rte_pktmbuf_tailroom(ut_params->ibuf)); 5352 if (op_mode == OUT_OF_PLACE) 5353 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5354 rte_pktmbuf_tailroom(ut_params->obuf)); 5355 5356 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5357 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5358 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5359 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5360 5361 if (verify) { 5362 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5363 ciphertext_pad_len); 5364 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5365 if (op_mode == OUT_OF_PLACE) 5366 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5367 debug_hexdump(stdout, "ciphertext:", ciphertext, 5368 ciphertext_len); 5369 } else { 5370 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5371 plaintext_pad_len); 5372 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5373 if (op_mode == OUT_OF_PLACE) 5374 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5375 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5376 } 5377 5378 /* Create SNOW 3G operation */ 5379 retval = create_wireless_algo_auth_cipher_operation( 5380 tdata->digest.data, tdata->digest.len, 5381 tdata->cipher_iv.data, tdata->cipher_iv.len, 5382 tdata->auth_iv.data, tdata->auth_iv.len, 5383 (tdata->digest.offset_bytes == 0 ? 5384 (verify ? ciphertext_pad_len : plaintext_pad_len) 5385 : tdata->digest.offset_bytes), 5386 tdata->validCipherLenInBits.len, 5387 tdata->cipher.offset_bits, 5388 tdata->validAuthLenInBits.len, 5389 tdata->auth.offset_bits, 5390 op_mode, 0, verify); 5391 5392 if (retval < 0) 5393 return retval; 5394 5395 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5396 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5397 tdata->cipher_iv.len); 5398 if (retval != TEST_SUCCESS) 5399 return retval; 5400 } else 5401 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5402 ut_params->op); 5403 5404 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5405 5406 ut_params->obuf = (op_mode == IN_PLACE ? 5407 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5408 5409 if (verify) { 5410 if (ut_params->obuf) 5411 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5412 uint8_t *); 5413 else 5414 plaintext = ciphertext + 5415 (tdata->cipher.offset_bits >> 3); 5416 5417 debug_hexdump(stdout, "plaintext:", plaintext, 5418 (tdata->plaintext.len >> 3) - tdata->digest.len); 5419 debug_hexdump(stdout, "plaintext expected:", 5420 tdata->plaintext.data, 5421 (tdata->plaintext.len >> 3) - tdata->digest.len); 5422 } else { 5423 if (ut_params->obuf) 5424 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5425 uint8_t *); 5426 else 5427 ciphertext = plaintext; 5428 5429 debug_hexdump(stdout, "ciphertext:", ciphertext, 5430 ciphertext_len); 5431 debug_hexdump(stdout, "ciphertext expected:", 5432 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5433 5434 if (tdata->digest.offset_bytes == 0) 5435 digest_offset = plaintext_pad_len; 5436 else 5437 digest_offset = tdata->digest.offset_bytes; 5438 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 5439 uint8_t *, digest_offset); 5440 5441 debug_hexdump(stdout, "digest:", ut_params->digest, 5442 tdata->digest.len); 5443 debug_hexdump(stdout, "digest expected:", tdata->digest.data, 5444 tdata->digest.len); 5445 } 5446 5447 /* Validate obuf */ 5448 if (verify) { 5449 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5450 plaintext, 5451 tdata->plaintext.data, 5452 (tdata->plaintext.len - tdata->cipher.offset_bits - 5453 (tdata->digest.len << 3)), 5454 tdata->cipher.offset_bits, 5455 "SNOW 3G Plaintext data not as expected"); 5456 } else { 5457 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5458 ciphertext, 5459 tdata->ciphertext.data, 5460 (tdata->validDataLenInBits.len - 5461 tdata->cipher.offset_bits), 5462 tdata->cipher.offset_bits, 5463 "SNOW 3G Ciphertext data not as expected"); 5464 5465 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5466 ut_params->digest, 5467 tdata->digest.data, 5468 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5469 "SNOW 3G Generated auth tag not as expected"); 5470 } 5471 return 0; 5472 } 5473 5474 static int 5475 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata, 5476 uint8_t op_mode, uint8_t verify) 5477 { 5478 struct crypto_testsuite_params *ts_params = &testsuite_params; 5479 struct crypto_unittest_params *ut_params = &unittest_params; 5480 5481 int retval; 5482 5483 const uint8_t *plaintext = NULL; 5484 const uint8_t *ciphertext = NULL; 5485 const uint8_t *digest = NULL; 5486 unsigned int plaintext_pad_len; 5487 unsigned int plaintext_len; 5488 unsigned int ciphertext_pad_len; 5489 unsigned int ciphertext_len; 5490 uint8_t buffer[10000]; 5491 uint8_t digest_buffer[10000]; 5492 5493 struct rte_cryptodev_info dev_info; 5494 5495 /* Verify the capabilities */ 5496 struct rte_cryptodev_sym_capability_idx cap_idx; 5497 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5498 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5499 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5500 &cap_idx) == NULL) 5501 return TEST_SKIPPED; 5502 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5503 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5504 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5505 &cap_idx) == NULL) 5506 return TEST_SKIPPED; 5507 5508 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5509 return TEST_SKIPPED; 5510 5511 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5512 5513 uint64_t feat_flags = dev_info.feature_flags; 5514 5515 if (op_mode == IN_PLACE) { 5516 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5517 printf("Device doesn't support in-place scatter-gather " 5518 "in both input and output mbufs.\n"); 5519 return TEST_SKIPPED; 5520 } 5521 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5522 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5523 printf("Device doesn't support RAW data-path APIs.\n"); 5524 return TEST_SKIPPED; 5525 } 5526 } else { 5527 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5528 return TEST_SKIPPED; 5529 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5530 printf("Device doesn't support out-of-place scatter-gather " 5531 "in both input and output mbufs.\n"); 5532 return TEST_SKIPPED; 5533 } 5534 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5535 printf("Device doesn't support digest encrypted.\n"); 5536 return TEST_SKIPPED; 5537 } 5538 } 5539 5540 /* Create SNOW 3G session */ 5541 retval = create_wireless_algo_auth_cipher_session( 5542 ts_params->valid_devs[0], 5543 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5544 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5545 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5546 : RTE_CRYPTO_AUTH_OP_GENERATE), 5547 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5548 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5549 tdata->key.data, tdata->key.len, 5550 tdata->key.data, tdata->key.len, 5551 tdata->auth_iv.len, tdata->digest.len, 5552 tdata->cipher_iv.len); 5553 5554 if (retval != 0) 5555 return retval; 5556 5557 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5558 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5559 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5560 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5561 5562 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5563 plaintext_pad_len, 15, 0); 5564 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5565 "Failed to allocate input buffer in mempool"); 5566 5567 if (op_mode == OUT_OF_PLACE) { 5568 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5569 plaintext_pad_len, 15, 0); 5570 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5571 "Failed to allocate output buffer in mempool"); 5572 } 5573 5574 if (verify) { 5575 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5576 tdata->ciphertext.data); 5577 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5578 ciphertext_len, buffer); 5579 debug_hexdump(stdout, "ciphertext:", ciphertext, 5580 ciphertext_len); 5581 } else { 5582 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5583 tdata->plaintext.data); 5584 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5585 plaintext_len, buffer); 5586 debug_hexdump(stdout, "plaintext:", plaintext, 5587 plaintext_len); 5588 } 5589 memset(buffer, 0, sizeof(buffer)); 5590 5591 /* Create SNOW 3G operation */ 5592 retval = create_wireless_algo_auth_cipher_operation( 5593 tdata->digest.data, tdata->digest.len, 5594 tdata->cipher_iv.data, tdata->cipher_iv.len, 5595 tdata->auth_iv.data, tdata->auth_iv.len, 5596 (tdata->digest.offset_bytes == 0 ? 5597 (verify ? ciphertext_pad_len : plaintext_pad_len) 5598 : tdata->digest.offset_bytes), 5599 tdata->validCipherLenInBits.len, 5600 tdata->cipher.offset_bits, 5601 tdata->validAuthLenInBits.len, 5602 tdata->auth.offset_bits, 5603 op_mode, 1, verify); 5604 5605 if (retval < 0) 5606 return retval; 5607 5608 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5609 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5610 tdata->cipher_iv.len); 5611 if (retval != TEST_SUCCESS) 5612 return retval; 5613 } else 5614 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5615 ut_params->op); 5616 5617 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5618 5619 ut_params->obuf = (op_mode == IN_PLACE ? 5620 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5621 5622 if (verify) { 5623 if (ut_params->obuf) 5624 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5625 plaintext_len, buffer); 5626 else 5627 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5628 plaintext_len, buffer); 5629 5630 debug_hexdump(stdout, "plaintext:", plaintext, 5631 (tdata->plaintext.len >> 3) - tdata->digest.len); 5632 debug_hexdump(stdout, "plaintext expected:", 5633 tdata->plaintext.data, 5634 (tdata->plaintext.len >> 3) - tdata->digest.len); 5635 } else { 5636 if (ut_params->obuf) 5637 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5638 ciphertext_len, buffer); 5639 else 5640 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5641 ciphertext_len, buffer); 5642 5643 debug_hexdump(stdout, "ciphertext:", ciphertext, 5644 ciphertext_len); 5645 debug_hexdump(stdout, "ciphertext expected:", 5646 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5647 5648 if (ut_params->obuf) 5649 digest = rte_pktmbuf_read(ut_params->obuf, 5650 (tdata->digest.offset_bytes == 0 ? 5651 plaintext_pad_len : tdata->digest.offset_bytes), 5652 tdata->digest.len, digest_buffer); 5653 else 5654 digest = rte_pktmbuf_read(ut_params->ibuf, 5655 (tdata->digest.offset_bytes == 0 ? 5656 plaintext_pad_len : tdata->digest.offset_bytes), 5657 tdata->digest.len, digest_buffer); 5658 5659 debug_hexdump(stdout, "digest:", digest, 5660 tdata->digest.len); 5661 debug_hexdump(stdout, "digest expected:", 5662 tdata->digest.data, tdata->digest.len); 5663 } 5664 5665 /* Validate obuf */ 5666 if (verify) { 5667 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5668 plaintext, 5669 tdata->plaintext.data, 5670 (tdata->plaintext.len - tdata->cipher.offset_bits - 5671 (tdata->digest.len << 3)), 5672 tdata->cipher.offset_bits, 5673 "SNOW 3G Plaintext data not as expected"); 5674 } else { 5675 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5676 ciphertext, 5677 tdata->ciphertext.data, 5678 (tdata->validDataLenInBits.len - 5679 tdata->cipher.offset_bits), 5680 tdata->cipher.offset_bits, 5681 "SNOW 3G Ciphertext data not as expected"); 5682 5683 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5684 digest, 5685 tdata->digest.data, 5686 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5687 "SNOW 3G Generated auth tag not as expected"); 5688 } 5689 return 0; 5690 } 5691 5692 static int 5693 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata, 5694 uint8_t op_mode, uint8_t verify) 5695 { 5696 struct crypto_testsuite_params *ts_params = &testsuite_params; 5697 struct crypto_unittest_params *ut_params = &unittest_params; 5698 5699 int retval; 5700 5701 uint8_t *plaintext = NULL, *ciphertext = NULL; 5702 unsigned int plaintext_pad_len; 5703 unsigned int plaintext_len; 5704 unsigned int ciphertext_pad_len; 5705 unsigned int ciphertext_len; 5706 unsigned int digest_offset; 5707 5708 struct rte_cryptodev_info dev_info; 5709 5710 /* Verify the capabilities */ 5711 struct rte_cryptodev_sym_capability_idx cap_idx; 5712 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5713 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5714 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5715 &cap_idx) == NULL) 5716 return TEST_SKIPPED; 5717 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5718 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5719 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5720 &cap_idx) == NULL) 5721 return TEST_SKIPPED; 5722 5723 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5724 5725 uint64_t feat_flags = dev_info.feature_flags; 5726 5727 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5728 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5729 printf("Device doesn't support RAW data-path APIs.\n"); 5730 return TEST_SKIPPED; 5731 } 5732 5733 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5734 return TEST_SKIPPED; 5735 5736 if (op_mode == OUT_OF_PLACE) { 5737 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5738 return TEST_SKIPPED; 5739 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5740 printf("Device doesn't support digest encrypted.\n"); 5741 return TEST_SKIPPED; 5742 } 5743 } 5744 5745 /* Create KASUMI session */ 5746 retval = create_wireless_algo_auth_cipher_session( 5747 ts_params->valid_devs[0], 5748 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5749 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5750 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5751 : RTE_CRYPTO_AUTH_OP_GENERATE), 5752 RTE_CRYPTO_AUTH_KASUMI_F9, 5753 RTE_CRYPTO_CIPHER_KASUMI_F8, 5754 tdata->key.data, tdata->key.len, 5755 tdata->key.data, tdata->key.len, 5756 0, tdata->digest.len, 5757 tdata->cipher_iv.len); 5758 5759 if (retval != 0) 5760 return retval; 5761 5762 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5763 if (op_mode == OUT_OF_PLACE) 5764 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5765 5766 /* clear mbuf payload */ 5767 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5768 rte_pktmbuf_tailroom(ut_params->ibuf)); 5769 if (op_mode == OUT_OF_PLACE) 5770 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5771 rte_pktmbuf_tailroom(ut_params->obuf)); 5772 5773 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5774 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5775 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5776 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5777 5778 if (verify) { 5779 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5780 ciphertext_pad_len); 5781 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5782 if (op_mode == OUT_OF_PLACE) 5783 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5784 debug_hexdump(stdout, "ciphertext:", ciphertext, 5785 ciphertext_len); 5786 } else { 5787 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5788 plaintext_pad_len); 5789 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5790 if (op_mode == OUT_OF_PLACE) 5791 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5792 debug_hexdump(stdout, "plaintext:", plaintext, 5793 plaintext_len); 5794 } 5795 5796 /* Create KASUMI operation */ 5797 retval = create_wireless_algo_auth_cipher_operation( 5798 tdata->digest.data, tdata->digest.len, 5799 tdata->cipher_iv.data, tdata->cipher_iv.len, 5800 NULL, 0, 5801 (tdata->digest.offset_bytes == 0 ? 5802 (verify ? ciphertext_pad_len : plaintext_pad_len) 5803 : tdata->digest.offset_bytes), 5804 tdata->validCipherLenInBits.len, 5805 tdata->validCipherOffsetInBits.len, 5806 tdata->validAuthLenInBits.len, 5807 0, 5808 op_mode, 0, verify); 5809 5810 if (retval < 0) 5811 return retval; 5812 5813 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5814 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5815 tdata->cipher_iv.len); 5816 if (retval != TEST_SUCCESS) 5817 return retval; 5818 } else 5819 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5820 ut_params->op); 5821 5822 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5823 5824 ut_params->obuf = (op_mode == IN_PLACE ? 5825 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5826 5827 5828 if (verify) { 5829 if (ut_params->obuf) 5830 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5831 uint8_t *); 5832 else 5833 plaintext = ciphertext; 5834 5835 debug_hexdump(stdout, "plaintext:", plaintext, 5836 (tdata->plaintext.len >> 3) - tdata->digest.len); 5837 debug_hexdump(stdout, "plaintext expected:", 5838 tdata->plaintext.data, 5839 (tdata->plaintext.len >> 3) - tdata->digest.len); 5840 } else { 5841 if (ut_params->obuf) 5842 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5843 uint8_t *); 5844 else 5845 ciphertext = plaintext; 5846 5847 debug_hexdump(stdout, "ciphertext:", ciphertext, 5848 ciphertext_len); 5849 debug_hexdump(stdout, "ciphertext expected:", 5850 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5851 5852 if (tdata->digest.offset_bytes == 0) 5853 digest_offset = plaintext_pad_len; 5854 else 5855 digest_offset = tdata->digest.offset_bytes; 5856 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 5857 uint8_t *, digest_offset); 5858 5859 debug_hexdump(stdout, "digest:", ut_params->digest, 5860 tdata->digest.len); 5861 debug_hexdump(stdout, "digest expected:", 5862 tdata->digest.data, tdata->digest.len); 5863 } 5864 5865 /* Validate obuf */ 5866 if (verify) { 5867 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5868 plaintext, 5869 tdata->plaintext.data, 5870 tdata->plaintext.len >> 3, 5871 "KASUMI Plaintext data not as expected"); 5872 } else { 5873 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5874 ciphertext, 5875 tdata->ciphertext.data, 5876 tdata->ciphertext.len >> 3, 5877 "KASUMI Ciphertext data not as expected"); 5878 5879 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5880 ut_params->digest, 5881 tdata->digest.data, 5882 DIGEST_BYTE_LENGTH_KASUMI_F9, 5883 "KASUMI Generated auth tag not as expected"); 5884 } 5885 return 0; 5886 } 5887 5888 static int 5889 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata, 5890 uint8_t op_mode, uint8_t verify) 5891 { 5892 struct crypto_testsuite_params *ts_params = &testsuite_params; 5893 struct crypto_unittest_params *ut_params = &unittest_params; 5894 5895 int retval; 5896 5897 const uint8_t *plaintext = NULL; 5898 const uint8_t *ciphertext = NULL; 5899 const uint8_t *digest = NULL; 5900 unsigned int plaintext_pad_len; 5901 unsigned int plaintext_len; 5902 unsigned int ciphertext_pad_len; 5903 unsigned int ciphertext_len; 5904 uint8_t buffer[10000]; 5905 uint8_t digest_buffer[10000]; 5906 5907 struct rte_cryptodev_info dev_info; 5908 5909 /* Verify the capabilities */ 5910 struct rte_cryptodev_sym_capability_idx cap_idx; 5911 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5912 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5913 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5914 &cap_idx) == NULL) 5915 return TEST_SKIPPED; 5916 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5917 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5918 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5919 &cap_idx) == NULL) 5920 return TEST_SKIPPED; 5921 5922 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5923 return TEST_SKIPPED; 5924 5925 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5926 5927 uint64_t feat_flags = dev_info.feature_flags; 5928 5929 if (op_mode == IN_PLACE) { 5930 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5931 printf("Device doesn't support in-place scatter-gather " 5932 "in both input and output mbufs.\n"); 5933 return TEST_SKIPPED; 5934 } 5935 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5936 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5937 printf("Device doesn't support RAW data-path APIs.\n"); 5938 return TEST_SKIPPED; 5939 } 5940 } else { 5941 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5942 return TEST_SKIPPED; 5943 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5944 printf("Device doesn't support out-of-place scatter-gather " 5945 "in both input and output mbufs.\n"); 5946 return TEST_SKIPPED; 5947 } 5948 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5949 printf("Device doesn't support digest encrypted.\n"); 5950 return TEST_SKIPPED; 5951 } 5952 } 5953 5954 /* Create KASUMI session */ 5955 retval = create_wireless_algo_auth_cipher_session( 5956 ts_params->valid_devs[0], 5957 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5958 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5959 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5960 : RTE_CRYPTO_AUTH_OP_GENERATE), 5961 RTE_CRYPTO_AUTH_KASUMI_F9, 5962 RTE_CRYPTO_CIPHER_KASUMI_F8, 5963 tdata->key.data, tdata->key.len, 5964 tdata->key.data, tdata->key.len, 5965 0, tdata->digest.len, 5966 tdata->cipher_iv.len); 5967 5968 if (retval != 0) 5969 return retval; 5970 5971 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5972 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5973 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5974 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5975 5976 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5977 plaintext_pad_len, 15, 0); 5978 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5979 "Failed to allocate input buffer in mempool"); 5980 5981 if (op_mode == OUT_OF_PLACE) { 5982 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5983 plaintext_pad_len, 15, 0); 5984 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5985 "Failed to allocate output buffer in mempool"); 5986 } 5987 5988 if (verify) { 5989 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5990 tdata->ciphertext.data); 5991 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5992 ciphertext_len, buffer); 5993 debug_hexdump(stdout, "ciphertext:", ciphertext, 5994 ciphertext_len); 5995 } else { 5996 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5997 tdata->plaintext.data); 5998 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5999 plaintext_len, buffer); 6000 debug_hexdump(stdout, "plaintext:", plaintext, 6001 plaintext_len); 6002 } 6003 memset(buffer, 0, sizeof(buffer)); 6004 6005 /* Create KASUMI operation */ 6006 retval = create_wireless_algo_auth_cipher_operation( 6007 tdata->digest.data, tdata->digest.len, 6008 tdata->cipher_iv.data, tdata->cipher_iv.len, 6009 NULL, 0, 6010 (tdata->digest.offset_bytes == 0 ? 6011 (verify ? ciphertext_pad_len : plaintext_pad_len) 6012 : tdata->digest.offset_bytes), 6013 tdata->validCipherLenInBits.len, 6014 tdata->validCipherOffsetInBits.len, 6015 tdata->validAuthLenInBits.len, 6016 0, 6017 op_mode, 1, verify); 6018 6019 if (retval < 0) 6020 return retval; 6021 6022 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6023 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 6024 tdata->cipher_iv.len); 6025 if (retval != TEST_SUCCESS) 6026 return retval; 6027 } else 6028 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6029 ut_params->op); 6030 6031 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6032 6033 ut_params->obuf = (op_mode == IN_PLACE ? 6034 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6035 6036 if (verify) { 6037 if (ut_params->obuf) 6038 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 6039 plaintext_len, buffer); 6040 else 6041 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6042 plaintext_len, buffer); 6043 6044 debug_hexdump(stdout, "plaintext:", plaintext, 6045 (tdata->plaintext.len >> 3) - tdata->digest.len); 6046 debug_hexdump(stdout, "plaintext expected:", 6047 tdata->plaintext.data, 6048 (tdata->plaintext.len >> 3) - tdata->digest.len); 6049 } else { 6050 if (ut_params->obuf) 6051 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 6052 ciphertext_len, buffer); 6053 else 6054 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6055 ciphertext_len, buffer); 6056 6057 debug_hexdump(stdout, "ciphertext:", ciphertext, 6058 ciphertext_len); 6059 debug_hexdump(stdout, "ciphertext expected:", 6060 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6061 6062 if (ut_params->obuf) 6063 digest = rte_pktmbuf_read(ut_params->obuf, 6064 (tdata->digest.offset_bytes == 0 ? 6065 plaintext_pad_len : tdata->digest.offset_bytes), 6066 tdata->digest.len, digest_buffer); 6067 else 6068 digest = rte_pktmbuf_read(ut_params->ibuf, 6069 (tdata->digest.offset_bytes == 0 ? 6070 plaintext_pad_len : tdata->digest.offset_bytes), 6071 tdata->digest.len, digest_buffer); 6072 6073 debug_hexdump(stdout, "digest:", digest, 6074 tdata->digest.len); 6075 debug_hexdump(stdout, "digest expected:", 6076 tdata->digest.data, tdata->digest.len); 6077 } 6078 6079 /* Validate obuf */ 6080 if (verify) { 6081 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6082 plaintext, 6083 tdata->plaintext.data, 6084 tdata->plaintext.len >> 3, 6085 "KASUMI Plaintext data not as expected"); 6086 } else { 6087 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6088 ciphertext, 6089 tdata->ciphertext.data, 6090 tdata->validDataLenInBits.len, 6091 "KASUMI Ciphertext data not as expected"); 6092 6093 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6094 digest, 6095 tdata->digest.data, 6096 DIGEST_BYTE_LENGTH_KASUMI_F9, 6097 "KASUMI Generated auth tag not as expected"); 6098 } 6099 return 0; 6100 } 6101 6102 static int 6103 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata) 6104 { 6105 struct crypto_testsuite_params *ts_params = &testsuite_params; 6106 struct crypto_unittest_params *ut_params = &unittest_params; 6107 6108 int retval; 6109 6110 uint8_t *plaintext, *ciphertext; 6111 unsigned plaintext_pad_len; 6112 unsigned plaintext_len; 6113 struct rte_cryptodev_info dev_info; 6114 6115 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6116 uint64_t feat_flags = dev_info.feature_flags; 6117 6118 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6119 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6120 printf("Device doesn't support RAW data-path APIs.\n"); 6121 return TEST_SKIPPED; 6122 } 6123 6124 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6125 return TEST_SKIPPED; 6126 6127 /* Verify the capabilities */ 6128 struct rte_cryptodev_sym_capability_idx cap_idx; 6129 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 6130 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 6131 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 6132 &cap_idx) == NULL) 6133 return TEST_SKIPPED; 6134 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 6135 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 6136 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 6137 &cap_idx) == NULL) 6138 return TEST_SKIPPED; 6139 6140 /* Create KASUMI session */ 6141 retval = create_wireless_algo_cipher_auth_session( 6142 ts_params->valid_devs[0], 6143 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6144 RTE_CRYPTO_AUTH_OP_GENERATE, 6145 RTE_CRYPTO_AUTH_KASUMI_F9, 6146 RTE_CRYPTO_CIPHER_KASUMI_F8, 6147 tdata->key.data, tdata->key.len, 6148 tdata->key.data, tdata->key.len, 6149 0, tdata->digest.len, 6150 tdata->cipher_iv.len); 6151 if (retval != 0) 6152 return retval; 6153 6154 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6155 6156 /* clear mbuf payload */ 6157 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6158 rte_pktmbuf_tailroom(ut_params->ibuf)); 6159 6160 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6161 /* Append data which is padded to a multiple of */ 6162 /* the algorithms block size */ 6163 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6164 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6165 plaintext_pad_len); 6166 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6167 6168 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6169 6170 /* Create KASUMI operation */ 6171 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 6172 tdata->digest.len, NULL, 0, 6173 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 6174 tdata->cipher_iv.data, tdata->cipher_iv.len, 6175 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 6176 tdata->validCipherOffsetInBits.len, 6177 tdata->validAuthLenInBits.len, 6178 0 6179 ); 6180 if (retval < 0) 6181 return retval; 6182 6183 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6184 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 6185 tdata->cipher_iv.len); 6186 if (retval != TEST_SUCCESS) 6187 return retval; 6188 } else 6189 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6190 ut_params->op); 6191 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6192 6193 if (ut_params->op->sym->m_dst) 6194 ut_params->obuf = ut_params->op->sym->m_dst; 6195 else 6196 ut_params->obuf = ut_params->op->sym->m_src; 6197 6198 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 6199 tdata->validCipherOffsetInBits.len >> 3); 6200 6201 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 6202 uint8_t *, 6203 plaintext_pad_len); 6204 6205 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 6206 (tdata->validCipherOffsetInBits.len >> 3); 6207 /* Validate obuf */ 6208 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6209 ciphertext, 6210 reference_ciphertext, 6211 tdata->validCipherLenInBits.len, 6212 "KASUMI Ciphertext data not as expected"); 6213 6214 /* Validate obuf */ 6215 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6216 ut_params->digest, 6217 tdata->digest.data, 6218 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 6219 "KASUMI Generated auth tag not as expected"); 6220 return 0; 6221 } 6222 6223 static int 6224 check_cipher_capability(const struct crypto_testsuite_params *ts_params, 6225 const enum rte_crypto_cipher_algorithm cipher_algo, 6226 const uint16_t key_size, const uint16_t iv_size) 6227 { 6228 struct rte_cryptodev_sym_capability_idx cap_idx; 6229 const struct rte_cryptodev_symmetric_capability *cap; 6230 6231 /* Check if device supports the algorithm */ 6232 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 6233 cap_idx.algo.cipher = cipher_algo; 6234 6235 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 6236 &cap_idx); 6237 6238 if (cap == NULL) 6239 return -1; 6240 6241 /* Check if device supports key size and IV size */ 6242 if (rte_cryptodev_sym_capability_check_cipher(cap, key_size, 6243 iv_size) < 0) { 6244 return -1; 6245 } 6246 6247 return 0; 6248 } 6249 6250 static int 6251 check_auth_capability(const struct crypto_testsuite_params *ts_params, 6252 const enum rte_crypto_auth_algorithm auth_algo, 6253 const uint16_t key_size, const uint16_t iv_size, 6254 const uint16_t tag_size) 6255 { 6256 struct rte_cryptodev_sym_capability_idx cap_idx; 6257 const struct rte_cryptodev_symmetric_capability *cap; 6258 6259 /* Check if device supports the algorithm */ 6260 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 6261 cap_idx.algo.auth = auth_algo; 6262 6263 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 6264 &cap_idx); 6265 6266 if (cap == NULL) 6267 return -1; 6268 6269 /* Check if device supports key size and IV size */ 6270 if (rte_cryptodev_sym_capability_check_auth(cap, key_size, 6271 tag_size, iv_size) < 0) { 6272 return -1; 6273 } 6274 6275 return 0; 6276 } 6277 6278 static int 6279 test_zuc_cipher(const struct wireless_test_data *tdata, 6280 enum rte_crypto_cipher_operation direction) 6281 { 6282 struct crypto_testsuite_params *ts_params = &testsuite_params; 6283 struct crypto_unittest_params *ut_params = &unittest_params; 6284 6285 int retval; 6286 uint8_t *plaintext = NULL; 6287 uint8_t *ciphertext = NULL; 6288 unsigned int plaintext_pad_len, ciphertext_pad_len; 6289 unsigned int plaintext_len = 0; 6290 unsigned int ciphertext_len = 0; 6291 struct rte_cryptodev_info dev_info; 6292 6293 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6294 uint64_t feat_flags = dev_info.feature_flags; 6295 6296 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6297 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6298 printf("Device doesn't support RAW data-path APIs.\n"); 6299 return TEST_SKIPPED; 6300 } 6301 6302 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6303 return TEST_SKIPPED; 6304 6305 /* Check if device supports ZUC EEA3 */ 6306 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6307 tdata->key.len, tdata->cipher_iv.len) < 0) 6308 return TEST_SKIPPED; 6309 6310 /* Create ZUC session */ 6311 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 6312 direction, 6313 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6314 tdata->key.data, tdata->key.len, 6315 tdata->cipher_iv.len); 6316 if (retval != 0) 6317 return retval; 6318 6319 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6320 6321 /* Clear mbuf payload */ 6322 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6323 rte_pktmbuf_tailroom(ut_params->ibuf)); 6324 6325 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6326 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6327 /* Append data which is padded to a multiple */ 6328 /* of the algorithms block size */ 6329 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6330 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6331 plaintext_pad_len); 6332 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6333 6334 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6335 } else { 6336 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6337 /* Append data which is padded to a multiple */ 6338 /* of the algorithms block size */ 6339 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 6340 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6341 ciphertext_pad_len); 6342 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6343 6344 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 6345 } 6346 6347 /* Create ZUC operation */ 6348 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6349 tdata->cipher_iv.len, 6350 tdata->plaintext.len, 6351 tdata->validCipherOffsetInBits.len); 6352 if (retval < 0) 6353 return retval; 6354 6355 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6356 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 6357 tdata->cipher_iv.len); 6358 if (retval != TEST_SUCCESS) 6359 return retval; 6360 } else 6361 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6362 ut_params->op); 6363 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6364 6365 ut_params->obuf = ut_params->op->sym->m_dst; 6366 6367 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6368 if (ut_params->obuf) 6369 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 6370 else 6371 ciphertext = plaintext; 6372 6373 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6374 6375 /* Validate obuf */ 6376 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6377 ciphertext, 6378 tdata->ciphertext.data, 6379 tdata->validCipherLenInBits.len, 6380 "ZUC Ciphertext data not as expected"); 6381 } else { 6382 if (ut_params->obuf) 6383 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 6384 else 6385 plaintext = ciphertext; 6386 6387 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 6388 6389 const uint8_t *reference_plaintext = tdata->plaintext.data + 6390 (tdata->validCipherOffsetInBits.len >> 3); 6391 6392 /* Validate obuf */ 6393 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6394 plaintext, 6395 reference_plaintext, 6396 tdata->validCipherLenInBits.len, 6397 "ZUC Plaintext data not as expected"); 6398 } 6399 6400 return 0; 6401 } 6402 6403 static int 6404 test_zuc_cipher_sgl(const struct wireless_test_data *tdata, 6405 enum rte_crypto_cipher_operation direction) 6406 { 6407 struct crypto_testsuite_params *ts_params = &testsuite_params; 6408 struct crypto_unittest_params *ut_params = &unittest_params; 6409 6410 int retval; 6411 6412 unsigned int plaintext_pad_len, ciphertext_pad_len; 6413 unsigned int plaintext_len = 0; 6414 unsigned int ciphertext_len = 0; 6415 const uint8_t *ciphertext, *plaintext; 6416 uint8_t buffer[2048]; 6417 struct rte_cryptodev_info dev_info; 6418 6419 /* Check if device supports ZUC EEA3 */ 6420 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6421 tdata->key.len, tdata->cipher_iv.len) < 0) 6422 return TEST_SKIPPED; 6423 6424 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6425 return TEST_SKIPPED; 6426 6427 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6428 6429 uint64_t feat_flags = dev_info.feature_flags; 6430 6431 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6432 printf("Device doesn't support in-place scatter-gather. " 6433 "Test Skipped.\n"); 6434 return TEST_SKIPPED; 6435 } 6436 6437 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6438 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6439 printf("Device doesn't support RAW data-path APIs.\n"); 6440 return TEST_SKIPPED; 6441 } 6442 6443 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6444 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6445 6446 /* Append data which is padded to a multiple */ 6447 /* of the algorithms block size */ 6448 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6449 6450 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6451 plaintext_pad_len, 10, 0); 6452 6453 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6454 tdata->plaintext.data); 6455 } else { 6456 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6457 6458 /* Append data which is padded to a multiple */ 6459 /* of the algorithms block size */ 6460 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 6461 6462 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6463 ciphertext_pad_len, 10, 0); 6464 6465 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6466 tdata->ciphertext.data); 6467 6468 } 6469 6470 /* Create ZUC session */ 6471 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 6472 direction, 6473 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6474 tdata->key.data, tdata->key.len, 6475 tdata->cipher_iv.len); 6476 if (retval < 0) 6477 return retval; 6478 6479 /* Clear mbuf payload */ 6480 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) 6481 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 6482 else 6483 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, tdata->ciphertext.data); 6484 6485 /* Create ZUC operation */ 6486 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6487 tdata->cipher_iv.len, tdata->plaintext.len, 6488 tdata->validCipherOffsetInBits.len); 6489 if (retval < 0) 6490 return retval; 6491 6492 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6493 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 6494 tdata->cipher_iv.len); 6495 if (retval != TEST_SUCCESS) 6496 return retval; 6497 } else 6498 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6499 ut_params->op); 6500 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6501 6502 ut_params->obuf = ut_params->op->sym->m_dst; 6503 6504 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6505 if (ut_params->obuf) 6506 ciphertext = rte_pktmbuf_read(ut_params->obuf, 6507 0, plaintext_len, buffer); 6508 else 6509 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 6510 0, plaintext_len, buffer); 6511 6512 /* Validate obuf */ 6513 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6514 6515 /* Validate obuf */ 6516 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6517 ciphertext, 6518 tdata->ciphertext.data, 6519 tdata->validCipherLenInBits.len, 6520 "ZUC Ciphertext data not as expected"); 6521 } else { 6522 if (ut_params->obuf) 6523 plaintext = rte_pktmbuf_read(ut_params->obuf, 6524 0, ciphertext_len, buffer); 6525 else 6526 plaintext = rte_pktmbuf_read(ut_params->ibuf, 6527 0, ciphertext_len, buffer); 6528 6529 /* Validate obuf */ 6530 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 6531 6532 /* Validate obuf */ 6533 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6534 plaintext, 6535 tdata->plaintext.data, 6536 tdata->validCipherLenInBits.len, 6537 "ZUC Plaintext data not as expected"); 6538 } 6539 6540 return 0; 6541 } 6542 6543 static int 6544 test_zuc_authentication(const struct wireless_test_data *tdata, 6545 enum rte_crypto_auth_operation auth_op) 6546 { 6547 struct crypto_testsuite_params *ts_params = &testsuite_params; 6548 struct crypto_unittest_params *ut_params = &unittest_params; 6549 6550 int retval; 6551 unsigned plaintext_pad_len; 6552 unsigned plaintext_len; 6553 uint8_t *plaintext; 6554 6555 struct rte_cryptodev_info dev_info; 6556 6557 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6558 uint64_t feat_flags = dev_info.feature_flags; 6559 6560 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 6561 (tdata->validAuthLenInBits.len % 8 != 0)) { 6562 printf("Device doesn't support NON-Byte Aligned Data.\n"); 6563 return TEST_SKIPPED; 6564 } 6565 6566 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6567 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6568 printf("Device doesn't support RAW data-path APIs.\n"); 6569 return TEST_SKIPPED; 6570 } 6571 6572 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6573 return TEST_SKIPPED; 6574 6575 /* Check if device supports ZUC EIA3 */ 6576 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6577 tdata->key.len, tdata->auth_iv.len, 6578 tdata->digest.len) < 0) 6579 return TEST_SKIPPED; 6580 6581 /* Create ZUC session */ 6582 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 6583 tdata->key.data, tdata->key.len, 6584 tdata->auth_iv.len, tdata->digest.len, 6585 auth_op, RTE_CRYPTO_AUTH_ZUC_EIA3); 6586 if (retval != 0) 6587 return retval; 6588 6589 /* alloc mbuf and set payload */ 6590 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6591 6592 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6593 rte_pktmbuf_tailroom(ut_params->ibuf)); 6594 6595 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6596 /* Append data which is padded to a multiple of */ 6597 /* the algorithms block size */ 6598 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6599 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6600 plaintext_pad_len); 6601 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6602 6603 /* Create ZUC operation */ 6604 retval = create_wireless_algo_hash_operation(tdata->digest.data, 6605 tdata->digest.len, 6606 tdata->auth_iv.data, tdata->auth_iv.len, 6607 plaintext_pad_len, 6608 auth_op, tdata->validAuthLenInBits.len, 0); 6609 if (retval < 0) 6610 return retval; 6611 6612 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6613 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 6614 0); 6615 if (retval != TEST_SUCCESS) 6616 return retval; 6617 } else 6618 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6619 ut_params->op); 6620 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6621 ut_params->obuf = ut_params->op->sym->m_src; 6622 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 6623 uint8_t *, 6624 plaintext_pad_len); 6625 6626 if (auth_op != RTE_CRYPTO_AUTH_OP_VERIFY) { 6627 /* Validate obuf */ 6628 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6629 ut_params->digest, 6630 tdata->digest.data, 6631 tdata->digest.len, 6632 "ZUC Generated auth tag not as expected"); 6633 return 0; 6634 } 6635 6636 /* Validate obuf */ 6637 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 6638 return 0; 6639 else 6640 return -1; 6641 6642 return 0; 6643 } 6644 6645 static int 6646 test_zuc_auth_cipher(const struct wireless_test_data *tdata, 6647 uint8_t op_mode, uint8_t verify) 6648 { 6649 struct crypto_testsuite_params *ts_params = &testsuite_params; 6650 struct crypto_unittest_params *ut_params = &unittest_params; 6651 6652 int retval; 6653 6654 uint8_t *plaintext = NULL, *ciphertext = NULL; 6655 unsigned int plaintext_pad_len; 6656 unsigned int plaintext_len; 6657 unsigned int ciphertext_pad_len; 6658 unsigned int ciphertext_len; 6659 unsigned int digest_offset; 6660 6661 struct rte_cryptodev_info dev_info; 6662 6663 /* Check if device supports ZUC EEA3 */ 6664 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6665 tdata->key.len, tdata->cipher_iv.len) < 0) 6666 return TEST_SKIPPED; 6667 6668 /* Check if device supports ZUC EIA3 */ 6669 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6670 tdata->key.len, tdata->auth_iv.len, 6671 tdata->digest.len) < 0) 6672 return TEST_SKIPPED; 6673 6674 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6675 return TEST_SKIPPED; 6676 6677 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6678 6679 uint64_t feat_flags = dev_info.feature_flags; 6680 6681 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6682 printf("Device doesn't support digest encrypted.\n"); 6683 return TEST_SKIPPED; 6684 } 6685 if (op_mode == IN_PLACE) { 6686 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6687 printf("Device doesn't support in-place scatter-gather " 6688 "in both input and output mbufs.\n"); 6689 return TEST_SKIPPED; 6690 } 6691 6692 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6693 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6694 printf("Device doesn't support RAW data-path APIs.\n"); 6695 return TEST_SKIPPED; 6696 } 6697 } else { 6698 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6699 return TEST_SKIPPED; 6700 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6701 printf("Device doesn't support out-of-place scatter-gather " 6702 "in both input and output mbufs.\n"); 6703 return TEST_SKIPPED; 6704 } 6705 } 6706 6707 /* Create ZUC session */ 6708 retval = create_wireless_algo_auth_cipher_session( 6709 ts_params->valid_devs[0], 6710 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6711 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6712 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6713 : RTE_CRYPTO_AUTH_OP_GENERATE), 6714 RTE_CRYPTO_AUTH_ZUC_EIA3, 6715 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6716 tdata->key.data, tdata->key.len, 6717 tdata->key.data, tdata->key.len, 6718 tdata->auth_iv.len, tdata->digest.len, 6719 tdata->cipher_iv.len); 6720 6721 if (retval != 0) 6722 return retval; 6723 6724 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6725 if (op_mode == OUT_OF_PLACE) 6726 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6727 6728 /* clear mbuf payload */ 6729 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6730 rte_pktmbuf_tailroom(ut_params->ibuf)); 6731 if (op_mode == OUT_OF_PLACE) 6732 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 6733 rte_pktmbuf_tailroom(ut_params->obuf)); 6734 6735 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6736 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6737 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6738 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6739 6740 if (verify) { 6741 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6742 ciphertext_pad_len); 6743 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6744 debug_hexdump(stdout, "ciphertext:", ciphertext, 6745 ciphertext_len); 6746 } else { 6747 /* make sure enough space to cover partial digest verify case */ 6748 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6749 ciphertext_pad_len); 6750 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6751 debug_hexdump(stdout, "plaintext:", plaintext, 6752 plaintext_len); 6753 } 6754 6755 if (op_mode == OUT_OF_PLACE) 6756 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 6757 6758 /* Create ZUC operation */ 6759 retval = create_wireless_algo_auth_cipher_operation( 6760 tdata->digest.data, tdata->digest.len, 6761 tdata->cipher_iv.data, tdata->cipher_iv.len, 6762 tdata->auth_iv.data, tdata->auth_iv.len, 6763 (tdata->digest.offset_bytes == 0 ? 6764 (verify ? ciphertext_pad_len : plaintext_pad_len) 6765 : tdata->digest.offset_bytes), 6766 tdata->validCipherLenInBits.len, 6767 tdata->validCipherOffsetInBits.len, 6768 tdata->validAuthLenInBits.len, 6769 0, 6770 op_mode, 0, verify); 6771 6772 if (retval < 0) 6773 return retval; 6774 6775 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6776 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 6777 tdata->cipher_iv.len); 6778 if (retval != TEST_SUCCESS) 6779 return retval; 6780 } else 6781 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6782 ut_params->op); 6783 6784 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6785 6786 ut_params->obuf = (op_mode == IN_PLACE ? 6787 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6788 6789 6790 if (verify) { 6791 if (ut_params->obuf) 6792 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 6793 uint8_t *); 6794 else 6795 plaintext = ciphertext; 6796 6797 debug_hexdump(stdout, "plaintext:", plaintext, 6798 (tdata->plaintext.len >> 3) - tdata->digest.len); 6799 debug_hexdump(stdout, "plaintext expected:", 6800 tdata->plaintext.data, 6801 (tdata->plaintext.len >> 3) - tdata->digest.len); 6802 } else { 6803 if (ut_params->obuf) 6804 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 6805 uint8_t *); 6806 else 6807 ciphertext = plaintext; 6808 6809 debug_hexdump(stdout, "ciphertext:", ciphertext, 6810 ciphertext_len); 6811 debug_hexdump(stdout, "ciphertext expected:", 6812 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6813 6814 if (tdata->digest.offset_bytes == 0) 6815 digest_offset = plaintext_pad_len; 6816 else 6817 digest_offset = tdata->digest.offset_bytes; 6818 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 6819 uint8_t *, digest_offset); 6820 6821 debug_hexdump(stdout, "digest:", ut_params->digest, 6822 tdata->digest.len); 6823 debug_hexdump(stdout, "digest expected:", 6824 tdata->digest.data, tdata->digest.len); 6825 } 6826 6827 /* Validate obuf */ 6828 if (verify) { 6829 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6830 plaintext, 6831 tdata->plaintext.data, 6832 tdata->plaintext.len >> 3, 6833 "ZUC Plaintext data not as expected"); 6834 } else { 6835 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6836 ciphertext, 6837 tdata->ciphertext.data, 6838 tdata->ciphertext.len >> 3, 6839 "ZUC Ciphertext data not as expected"); 6840 6841 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6842 ut_params->digest, 6843 tdata->digest.data, 6844 tdata->digest.len, 6845 "ZUC Generated auth tag not as expected"); 6846 } 6847 return 0; 6848 } 6849 6850 static int 6851 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata, 6852 uint8_t op_mode, uint8_t verify) 6853 { 6854 struct crypto_testsuite_params *ts_params = &testsuite_params; 6855 struct crypto_unittest_params *ut_params = &unittest_params; 6856 6857 int retval; 6858 6859 const uint8_t *plaintext = NULL; 6860 const uint8_t *ciphertext = NULL; 6861 const uint8_t *digest = NULL; 6862 unsigned int plaintext_pad_len; 6863 unsigned int plaintext_len; 6864 unsigned int ciphertext_pad_len; 6865 unsigned int ciphertext_len; 6866 uint8_t buffer[10000]; 6867 uint8_t digest_buffer[10000]; 6868 6869 struct rte_cryptodev_info dev_info; 6870 6871 /* Check if device supports ZUC EEA3 */ 6872 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6873 tdata->key.len, tdata->cipher_iv.len) < 0) 6874 return TEST_SKIPPED; 6875 6876 /* Check if device supports ZUC EIA3 */ 6877 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6878 tdata->key.len, tdata->auth_iv.len, 6879 tdata->digest.len) < 0) 6880 return TEST_SKIPPED; 6881 6882 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6883 return TEST_SKIPPED; 6884 6885 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6886 6887 uint64_t feat_flags = dev_info.feature_flags; 6888 6889 if (op_mode == IN_PLACE) { 6890 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6891 printf("Device doesn't support in-place scatter-gather " 6892 "in both input and output mbufs.\n"); 6893 return TEST_SKIPPED; 6894 } 6895 6896 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6897 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6898 printf("Device doesn't support RAW data-path APIs.\n"); 6899 return TEST_SKIPPED; 6900 } 6901 } else { 6902 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6903 return TEST_SKIPPED; 6904 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6905 printf("Device doesn't support out-of-place scatter-gather " 6906 "in both input and output mbufs.\n"); 6907 return TEST_SKIPPED; 6908 } 6909 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6910 printf("Device doesn't support digest encrypted.\n"); 6911 return TEST_SKIPPED; 6912 } 6913 } 6914 6915 /* Create ZUC session */ 6916 retval = create_wireless_algo_auth_cipher_session( 6917 ts_params->valid_devs[0], 6918 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6919 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6920 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6921 : RTE_CRYPTO_AUTH_OP_GENERATE), 6922 RTE_CRYPTO_AUTH_ZUC_EIA3, 6923 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6924 tdata->key.data, tdata->key.len, 6925 tdata->key.data, tdata->key.len, 6926 tdata->auth_iv.len, tdata->digest.len, 6927 tdata->cipher_iv.len); 6928 6929 if (retval != 0) 6930 return retval; 6931 6932 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6933 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6934 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6935 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6936 6937 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6938 plaintext_pad_len, 15, 0); 6939 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6940 "Failed to allocate input buffer in mempool"); 6941 6942 if (op_mode == OUT_OF_PLACE) { 6943 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 6944 plaintext_pad_len, 15, 0); 6945 TEST_ASSERT_NOT_NULL(ut_params->obuf, 6946 "Failed to allocate output buffer in mempool"); 6947 } 6948 6949 if (verify) { 6950 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6951 tdata->ciphertext.data); 6952 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6953 ciphertext_len, buffer); 6954 debug_hexdump(stdout, "ciphertext:", ciphertext, 6955 ciphertext_len); 6956 } else { 6957 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6958 tdata->plaintext.data); 6959 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6960 plaintext_len, buffer); 6961 debug_hexdump(stdout, "plaintext:", plaintext, 6962 plaintext_len); 6963 } 6964 memset(buffer, 0, sizeof(buffer)); 6965 6966 /* Create ZUC operation */ 6967 retval = create_wireless_algo_auth_cipher_operation( 6968 tdata->digest.data, tdata->digest.len, 6969 tdata->cipher_iv.data, tdata->cipher_iv.len, 6970 tdata->auth_iv.data, tdata->auth_iv.len, 6971 (tdata->digest.offset_bytes == 0 ? 6972 (verify ? ciphertext_pad_len : plaintext_pad_len) 6973 : tdata->digest.offset_bytes), 6974 tdata->validCipherLenInBits.len, 6975 tdata->validCipherOffsetInBits.len, 6976 tdata->validAuthLenInBits.len, 6977 0, 6978 op_mode, 1, verify); 6979 6980 if (retval < 0) 6981 return retval; 6982 6983 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6984 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 6985 tdata->cipher_iv.len); 6986 if (retval != TEST_SUCCESS) 6987 return retval; 6988 } else 6989 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6990 ut_params->op); 6991 6992 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6993 6994 ut_params->obuf = (op_mode == IN_PLACE ? 6995 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6996 6997 if (verify) { 6998 if (ut_params->obuf) 6999 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 7000 plaintext_len, buffer); 7001 else 7002 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7003 plaintext_len, buffer); 7004 7005 debug_hexdump(stdout, "plaintext:", plaintext, 7006 (tdata->plaintext.len >> 3) - tdata->digest.len); 7007 debug_hexdump(stdout, "plaintext expected:", 7008 tdata->plaintext.data, 7009 (tdata->plaintext.len >> 3) - tdata->digest.len); 7010 } else { 7011 if (ut_params->obuf) 7012 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 7013 ciphertext_len, buffer); 7014 else 7015 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7016 ciphertext_len, buffer); 7017 7018 debug_hexdump(stdout, "ciphertext:", ciphertext, 7019 ciphertext_len); 7020 debug_hexdump(stdout, "ciphertext expected:", 7021 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 7022 7023 if (ut_params->obuf) 7024 digest = rte_pktmbuf_read(ut_params->obuf, 7025 (tdata->digest.offset_bytes == 0 ? 7026 plaintext_pad_len : tdata->digest.offset_bytes), 7027 tdata->digest.len, digest_buffer); 7028 else 7029 digest = rte_pktmbuf_read(ut_params->ibuf, 7030 (tdata->digest.offset_bytes == 0 ? 7031 plaintext_pad_len : tdata->digest.offset_bytes), 7032 tdata->digest.len, digest_buffer); 7033 7034 debug_hexdump(stdout, "digest:", digest, 7035 tdata->digest.len); 7036 debug_hexdump(stdout, "digest expected:", 7037 tdata->digest.data, tdata->digest.len); 7038 } 7039 7040 /* Validate obuf */ 7041 if (verify) { 7042 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7043 plaintext, 7044 tdata->plaintext.data, 7045 tdata->plaintext.len >> 3, 7046 "ZUC Plaintext data not as expected"); 7047 } else { 7048 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7049 ciphertext, 7050 tdata->ciphertext.data, 7051 tdata->validDataLenInBits.len, 7052 "ZUC Ciphertext data not as expected"); 7053 7054 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7055 digest, 7056 tdata->digest.data, 7057 tdata->digest.len, 7058 "ZUC Generated auth tag not as expected"); 7059 } 7060 return 0; 7061 } 7062 7063 static int 7064 test_kasumi_encryption_test_case_1(void) 7065 { 7066 return test_kasumi_encryption(&kasumi_test_case_1); 7067 } 7068 7069 static int 7070 test_kasumi_encryption_test_case_1_sgl(void) 7071 { 7072 return test_kasumi_encryption_sgl(&kasumi_test_case_1); 7073 } 7074 7075 static int 7076 test_kasumi_encryption_test_case_1_oop(void) 7077 { 7078 return test_kasumi_encryption_oop(&kasumi_test_case_1); 7079 } 7080 7081 static int 7082 test_kasumi_encryption_test_case_1_oop_sgl(void) 7083 { 7084 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1); 7085 } 7086 7087 static int 7088 test_kasumi_encryption_test_case_2(void) 7089 { 7090 return test_kasumi_encryption(&kasumi_test_case_2); 7091 } 7092 7093 static int 7094 test_kasumi_encryption_test_case_3(void) 7095 { 7096 return test_kasumi_encryption(&kasumi_test_case_3); 7097 } 7098 7099 static int 7100 test_kasumi_encryption_test_case_4(void) 7101 { 7102 return test_kasumi_encryption(&kasumi_test_case_4); 7103 } 7104 7105 static int 7106 test_kasumi_encryption_test_case_5(void) 7107 { 7108 return test_kasumi_encryption(&kasumi_test_case_5); 7109 } 7110 7111 static int 7112 test_kasumi_decryption_test_case_1(void) 7113 { 7114 return test_kasumi_decryption(&kasumi_test_case_1); 7115 } 7116 7117 static int 7118 test_kasumi_decryption_test_case_1_oop(void) 7119 { 7120 return test_kasumi_decryption_oop(&kasumi_test_case_1); 7121 } 7122 7123 static int 7124 test_kasumi_decryption_test_case_2(void) 7125 { 7126 return test_kasumi_decryption(&kasumi_test_case_2); 7127 } 7128 7129 static int 7130 test_kasumi_decryption_test_case_3(void) 7131 { 7132 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 7133 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7134 return TEST_SKIPPED; 7135 return test_kasumi_decryption(&kasumi_test_case_3); 7136 } 7137 7138 static int 7139 test_kasumi_decryption_test_case_4(void) 7140 { 7141 return test_kasumi_decryption(&kasumi_test_case_4); 7142 } 7143 7144 static int 7145 test_kasumi_decryption_test_case_5(void) 7146 { 7147 return test_kasumi_decryption(&kasumi_test_case_5); 7148 } 7149 static int 7150 test_snow3g_encryption_test_case_1(void) 7151 { 7152 return test_snow3g_encryption(&snow3g_test_case_1); 7153 } 7154 7155 static int 7156 test_snow3g_encryption_test_case_1_oop(void) 7157 { 7158 return test_snow3g_encryption_oop(&snow3g_test_case_1); 7159 } 7160 7161 static int 7162 test_snow3g_encryption_test_case_1_oop_sgl(void) 7163 { 7164 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 1, 1); 7165 } 7166 7167 static int 7168 test_snow3g_encryption_test_case_1_oop_lb_in_sgl_out(void) 7169 { 7170 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 0, 1); 7171 } 7172 7173 static int 7174 test_snow3g_encryption_test_case_1_oop_sgl_in_lb_out(void) 7175 { 7176 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 1, 0); 7177 } 7178 7179 static int 7180 test_snow3g_encryption_test_case_1_offset_oop(void) 7181 { 7182 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); 7183 } 7184 7185 static int 7186 test_snow3g_encryption_test_case_2(void) 7187 { 7188 return test_snow3g_encryption(&snow3g_test_case_2); 7189 } 7190 7191 static int 7192 test_snow3g_encryption_test_case_3(void) 7193 { 7194 return test_snow3g_encryption(&snow3g_test_case_3); 7195 } 7196 7197 static int 7198 test_snow3g_encryption_test_case_4(void) 7199 { 7200 return test_snow3g_encryption(&snow3g_test_case_4); 7201 } 7202 7203 static int 7204 test_snow3g_encryption_test_case_5(void) 7205 { 7206 return test_snow3g_encryption(&snow3g_test_case_5); 7207 } 7208 7209 static int 7210 test_snow3g_decryption_test_case_1(void) 7211 { 7212 return test_snow3g_decryption(&snow3g_test_case_1); 7213 } 7214 7215 static int 7216 test_snow3g_decryption_test_case_1_oop(void) 7217 { 7218 return test_snow3g_decryption_oop(&snow3g_test_case_1); 7219 } 7220 7221 static int 7222 test_snow3g_decryption_test_case_2(void) 7223 { 7224 return test_snow3g_decryption(&snow3g_test_case_2); 7225 } 7226 7227 static int 7228 test_snow3g_decryption_test_case_3(void) 7229 { 7230 return test_snow3g_decryption(&snow3g_test_case_3); 7231 } 7232 7233 static int 7234 test_snow3g_decryption_test_case_4(void) 7235 { 7236 return test_snow3g_decryption(&snow3g_test_case_4); 7237 } 7238 7239 static int 7240 test_snow3g_decryption_test_case_5(void) 7241 { 7242 return test_snow3g_decryption(&snow3g_test_case_5); 7243 } 7244 7245 /* 7246 * Function prepares snow3g_hash_test_data from snow3g_test_data. 7247 * Pattern digest from snow3g_test_data must be allocated as 7248 * 4 last bytes in plaintext. 7249 */ 7250 static void 7251 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern, 7252 struct snow3g_hash_test_data *output) 7253 { 7254 if ((pattern != NULL) && (output != NULL)) { 7255 output->key.len = pattern->key.len; 7256 7257 memcpy(output->key.data, 7258 pattern->key.data, pattern->key.len); 7259 7260 output->auth_iv.len = pattern->auth_iv.len; 7261 7262 memcpy(output->auth_iv.data, 7263 pattern->auth_iv.data, pattern->auth_iv.len); 7264 7265 output->plaintext.len = pattern->plaintext.len; 7266 7267 memcpy(output->plaintext.data, 7268 pattern->plaintext.data, pattern->plaintext.len >> 3); 7269 7270 output->digest.len = pattern->digest.len; 7271 7272 memcpy(output->digest.data, 7273 &pattern->plaintext.data[pattern->digest.offset_bytes], 7274 pattern->digest.len); 7275 7276 output->validAuthLenInBits.len = 7277 pattern->validAuthLenInBits.len; 7278 } 7279 } 7280 7281 /* 7282 * Test case verify computed cipher and digest from snow3g_test_case_7 data. 7283 */ 7284 static int 7285 test_snow3g_decryption_with_digest_test_case_1(void) 7286 { 7287 int ret; 7288 struct snow3g_hash_test_data snow3g_hash_data; 7289 struct rte_cryptodev_info dev_info; 7290 struct crypto_testsuite_params *ts_params = &testsuite_params; 7291 7292 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7293 uint64_t feat_flags = dev_info.feature_flags; 7294 7295 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7296 printf("Device doesn't support encrypted digest operations.\n"); 7297 return TEST_SKIPPED; 7298 } 7299 7300 /* 7301 * Function prepare data for hash verification test case. 7302 * Digest is allocated in 4 last bytes in plaintext, pattern. 7303 */ 7304 snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data); 7305 7306 ret = test_snow3g_decryption(&snow3g_test_case_7); 7307 if (ret != 0) 7308 return ret; 7309 7310 return test_snow3g_authentication_verify(&snow3g_hash_data); 7311 } 7312 7313 static int 7314 test_snow3g_cipher_auth_test_case_1(void) 7315 { 7316 return test_snow3g_cipher_auth(&snow3g_test_case_3); 7317 } 7318 7319 static int 7320 test_snow3g_auth_cipher_test_case_1(void) 7321 { 7322 return test_snow3g_auth_cipher( 7323 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0); 7324 } 7325 7326 static int 7327 test_snow3g_auth_cipher_test_case_2(void) 7328 { 7329 return test_snow3g_auth_cipher( 7330 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0); 7331 } 7332 7333 static int 7334 test_snow3g_auth_cipher_test_case_2_oop(void) 7335 { 7336 return test_snow3g_auth_cipher( 7337 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7338 } 7339 7340 static int 7341 test_snow3g_auth_cipher_part_digest_enc(void) 7342 { 7343 return test_snow3g_auth_cipher( 7344 &snow3g_auth_cipher_partial_digest_encryption, 7345 IN_PLACE, 0); 7346 } 7347 7348 static int 7349 test_snow3g_auth_cipher_part_digest_enc_oop(void) 7350 { 7351 return test_snow3g_auth_cipher( 7352 &snow3g_auth_cipher_partial_digest_encryption, 7353 OUT_OF_PLACE, 0); 7354 } 7355 7356 static int 7357 test_snow3g_auth_cipher_test_case_3_sgl(void) 7358 { 7359 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 7360 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7361 return TEST_SKIPPED; 7362 return test_snow3g_auth_cipher_sgl( 7363 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0); 7364 } 7365 7366 static int 7367 test_snow3g_auth_cipher_test_case_3_oop_sgl(void) 7368 { 7369 return test_snow3g_auth_cipher_sgl( 7370 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0); 7371 } 7372 7373 static int 7374 test_snow3g_auth_cipher_part_digest_enc_sgl(void) 7375 { 7376 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 7377 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7378 return TEST_SKIPPED; 7379 return test_snow3g_auth_cipher_sgl( 7380 &snow3g_auth_cipher_partial_digest_encryption, 7381 IN_PLACE, 0); 7382 } 7383 7384 static int 7385 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void) 7386 { 7387 return test_snow3g_auth_cipher_sgl( 7388 &snow3g_auth_cipher_partial_digest_encryption, 7389 OUT_OF_PLACE, 0); 7390 } 7391 7392 static int 7393 test_snow3g_auth_cipher_total_digest_enc_1(void) 7394 { 7395 return test_snow3g_auth_cipher( 7396 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 0); 7397 } 7398 7399 static int 7400 test_snow3g_auth_cipher_total_digest_enc_1_oop(void) 7401 { 7402 return test_snow3g_auth_cipher( 7403 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 0); 7404 } 7405 7406 static int 7407 test_snow3g_auth_cipher_total_digest_enc_1_sgl(void) 7408 { 7409 return test_snow3g_auth_cipher_sgl( 7410 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 0); 7411 } 7412 7413 static int 7414 test_snow3g_auth_cipher_total_digest_enc_1_oop_sgl(void) 7415 { 7416 return test_snow3g_auth_cipher_sgl( 7417 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 0); 7418 } 7419 7420 static int 7421 test_snow3g_auth_cipher_verify_test_case_1(void) 7422 { 7423 return test_snow3g_auth_cipher( 7424 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1); 7425 } 7426 7427 static int 7428 test_snow3g_auth_cipher_verify_test_case_2(void) 7429 { 7430 return test_snow3g_auth_cipher( 7431 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1); 7432 } 7433 7434 static int 7435 test_snow3g_auth_cipher_verify_test_case_2_oop(void) 7436 { 7437 return test_snow3g_auth_cipher( 7438 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7439 } 7440 7441 static int 7442 test_snow3g_auth_cipher_verify_part_digest_enc(void) 7443 { 7444 return test_snow3g_auth_cipher( 7445 &snow3g_auth_cipher_partial_digest_encryption, 7446 IN_PLACE, 1); 7447 } 7448 7449 static int 7450 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void) 7451 { 7452 return test_snow3g_auth_cipher( 7453 &snow3g_auth_cipher_partial_digest_encryption, 7454 OUT_OF_PLACE, 1); 7455 } 7456 7457 static int 7458 test_snow3g_auth_cipher_verify_test_case_3_sgl(void) 7459 { 7460 return test_snow3g_auth_cipher_sgl( 7461 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1); 7462 } 7463 7464 static int 7465 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void) 7466 { 7467 return test_snow3g_auth_cipher_sgl( 7468 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1); 7469 } 7470 7471 static int 7472 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void) 7473 { 7474 return test_snow3g_auth_cipher_sgl( 7475 &snow3g_auth_cipher_partial_digest_encryption, 7476 IN_PLACE, 1); 7477 } 7478 7479 static int 7480 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void) 7481 { 7482 return test_snow3g_auth_cipher_sgl( 7483 &snow3g_auth_cipher_partial_digest_encryption, 7484 OUT_OF_PLACE, 1); 7485 } 7486 7487 static int 7488 test_snow3g_auth_cipher_verify_total_digest_enc_1(void) 7489 { 7490 return test_snow3g_auth_cipher( 7491 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 1); 7492 } 7493 7494 static int 7495 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop(void) 7496 { 7497 return test_snow3g_auth_cipher( 7498 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 1); 7499 } 7500 7501 static int 7502 test_snow3g_auth_cipher_verify_total_digest_enc_1_sgl(void) 7503 { 7504 return test_snow3g_auth_cipher_sgl( 7505 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 1); 7506 } 7507 7508 static int 7509 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop_sgl(void) 7510 { 7511 return test_snow3g_auth_cipher_sgl( 7512 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 1); 7513 } 7514 7515 static int 7516 test_snow3g_auth_cipher_with_digest_test_case_1(void) 7517 { 7518 return test_snow3g_auth_cipher( 7519 &snow3g_test_case_7, IN_PLACE, 0); 7520 } 7521 7522 static int 7523 test_kasumi_auth_cipher_test_case_1(void) 7524 { 7525 return test_kasumi_auth_cipher( 7526 &kasumi_test_case_3, IN_PLACE, 0); 7527 } 7528 7529 static int 7530 test_kasumi_auth_cipher_test_case_2(void) 7531 { 7532 return test_kasumi_auth_cipher( 7533 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7534 } 7535 7536 static int 7537 test_kasumi_auth_cipher_test_case_2_oop(void) 7538 { 7539 return test_kasumi_auth_cipher( 7540 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7541 } 7542 7543 static int 7544 test_kasumi_auth_cipher_test_case_2_sgl(void) 7545 { 7546 return test_kasumi_auth_cipher_sgl( 7547 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7548 } 7549 7550 static int 7551 test_kasumi_auth_cipher_test_case_2_oop_sgl(void) 7552 { 7553 return test_kasumi_auth_cipher_sgl( 7554 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7555 } 7556 7557 static int 7558 test_kasumi_auth_cipher_verify_test_case_1(void) 7559 { 7560 return test_kasumi_auth_cipher( 7561 &kasumi_test_case_3, IN_PLACE, 1); 7562 } 7563 7564 static int 7565 test_kasumi_auth_cipher_verify_test_case_2(void) 7566 { 7567 return test_kasumi_auth_cipher( 7568 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7569 } 7570 7571 static int 7572 test_kasumi_auth_cipher_verify_test_case_2_oop(void) 7573 { 7574 return test_kasumi_auth_cipher( 7575 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7576 } 7577 7578 static int 7579 test_kasumi_auth_cipher_verify_test_case_2_sgl(void) 7580 { 7581 return test_kasumi_auth_cipher_sgl( 7582 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7583 } 7584 7585 static int 7586 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void) 7587 { 7588 return test_kasumi_auth_cipher_sgl( 7589 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7590 } 7591 7592 static int 7593 test_kasumi_cipher_auth_test_case_1(void) 7594 { 7595 return test_kasumi_cipher_auth(&kasumi_test_case_6); 7596 } 7597 7598 static int 7599 test_zuc_encryption_test_case_1(void) 7600 { 7601 return test_zuc_cipher(&zuc_test_case_cipher_193b, 7602 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7603 } 7604 7605 static int 7606 test_zuc_encryption_test_case_2(void) 7607 { 7608 return test_zuc_cipher(&zuc_test_case_cipher_800b, 7609 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7610 } 7611 7612 static int 7613 test_zuc_encryption_test_case_3(void) 7614 { 7615 return test_zuc_cipher(&zuc_test_case_cipher_1570b, 7616 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7617 } 7618 7619 static int 7620 test_zuc_encryption_test_case_4(void) 7621 { 7622 return test_zuc_cipher(&zuc_test_case_cipher_2798b, 7623 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7624 } 7625 7626 static int 7627 test_zuc_encryption_test_case_5(void) 7628 { 7629 return test_zuc_cipher(&zuc_test_case_cipher_4019b, 7630 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7631 } 7632 7633 static int 7634 test_zuc_encryption_test_case_6_sgl(void) 7635 { 7636 return test_zuc_cipher_sgl(&zuc_test_case_cipher_193b, 7637 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7638 } 7639 7640 static int 7641 test_zuc_decryption_test_case_1(void) 7642 { 7643 return test_zuc_cipher(&zuc_test_case_cipher_193b, 7644 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7645 } 7646 7647 static int 7648 test_zuc_decryption_test_case_2(void) 7649 { 7650 return test_zuc_cipher(&zuc_test_case_cipher_800b, 7651 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7652 } 7653 7654 static int 7655 test_zuc_decryption_test_case_3(void) 7656 { 7657 return test_zuc_cipher(&zuc_test_case_cipher_1570b, 7658 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7659 } 7660 7661 static int 7662 test_zuc_decryption_test_case_4(void) 7663 { 7664 return test_zuc_cipher(&zuc_test_case_cipher_2798b, 7665 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7666 } 7667 7668 static int 7669 test_zuc_decryption_test_case_5(void) 7670 { 7671 return test_zuc_cipher(&zuc_test_case_cipher_4019b, 7672 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7673 } 7674 7675 static int 7676 test_zuc_decryption_test_case_6_sgl(void) 7677 { 7678 return test_zuc_cipher_sgl(&zuc_test_case_cipher_193b, 7679 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7680 } 7681 7682 static int 7683 test_zuc_hash_generate_test_case_1(void) 7684 { 7685 return test_zuc_authentication(&zuc_test_case_auth_1b, 7686 RTE_CRYPTO_AUTH_OP_GENERATE); 7687 } 7688 7689 static int 7690 test_zuc_hash_generate_test_case_2(void) 7691 { 7692 return test_zuc_authentication(&zuc_test_case_auth_90b, 7693 RTE_CRYPTO_AUTH_OP_GENERATE); 7694 } 7695 7696 static int 7697 test_zuc_hash_generate_test_case_3(void) 7698 { 7699 return test_zuc_authentication(&zuc_test_case_auth_577b, 7700 RTE_CRYPTO_AUTH_OP_GENERATE); 7701 } 7702 7703 static int 7704 test_zuc_hash_generate_test_case_4(void) 7705 { 7706 return test_zuc_authentication(&zuc_test_case_auth_2079b, 7707 RTE_CRYPTO_AUTH_OP_GENERATE); 7708 } 7709 7710 static int 7711 test_zuc_hash_generate_test_case_5(void) 7712 { 7713 return test_zuc_authentication(&zuc_test_auth_5670b, 7714 RTE_CRYPTO_AUTH_OP_GENERATE); 7715 } 7716 7717 static int 7718 test_zuc_hash_generate_test_case_6(void) 7719 { 7720 return test_zuc_authentication(&zuc_test_case_auth_128b, 7721 RTE_CRYPTO_AUTH_OP_GENERATE); 7722 } 7723 7724 static int 7725 test_zuc_hash_generate_test_case_7(void) 7726 { 7727 return test_zuc_authentication(&zuc_test_case_auth_2080b, 7728 RTE_CRYPTO_AUTH_OP_GENERATE); 7729 } 7730 7731 static int 7732 test_zuc_hash_generate_test_case_8(void) 7733 { 7734 return test_zuc_authentication(&zuc_test_case_auth_584b, 7735 RTE_CRYPTO_AUTH_OP_GENERATE); 7736 } 7737 7738 static int 7739 test_zuc_hash_verify_test_case_1(void) 7740 { 7741 return test_zuc_authentication(&zuc_test_case_auth_1b, 7742 RTE_CRYPTO_AUTH_OP_VERIFY); 7743 } 7744 7745 static int 7746 test_zuc_hash_verify_test_case_2(void) 7747 { 7748 return test_zuc_authentication(&zuc_test_case_auth_90b, 7749 RTE_CRYPTO_AUTH_OP_VERIFY); 7750 } 7751 7752 static int 7753 test_zuc_hash_verify_test_case_3(void) 7754 { 7755 return test_zuc_authentication(&zuc_test_case_auth_577b, 7756 RTE_CRYPTO_AUTH_OP_VERIFY); 7757 } 7758 7759 static int 7760 test_zuc_hash_verify_test_case_4(void) 7761 { 7762 return test_zuc_authentication(&zuc_test_case_auth_2079b, 7763 RTE_CRYPTO_AUTH_OP_VERIFY); 7764 } 7765 7766 static int 7767 test_zuc_hash_verify_test_case_5(void) 7768 { 7769 return test_zuc_authentication(&zuc_test_auth_5670b, 7770 RTE_CRYPTO_AUTH_OP_VERIFY); 7771 } 7772 7773 static int 7774 test_zuc_hash_verify_test_case_6(void) 7775 { 7776 return test_zuc_authentication(&zuc_test_case_auth_128b, 7777 RTE_CRYPTO_AUTH_OP_VERIFY); 7778 } 7779 7780 static int 7781 test_zuc_hash_verify_test_case_7(void) 7782 { 7783 return test_zuc_authentication(&zuc_test_case_auth_2080b, 7784 RTE_CRYPTO_AUTH_OP_VERIFY); 7785 } 7786 7787 static int 7788 test_zuc_hash_verify_test_case_8(void) 7789 { 7790 return test_zuc_authentication(&zuc_test_case_auth_584b, 7791 RTE_CRYPTO_AUTH_OP_VERIFY); 7792 } 7793 7794 static int 7795 test_zuc_cipher_auth_test_case_1(void) 7796 { 7797 return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b); 7798 } 7799 7800 static int 7801 test_zuc_cipher_auth_test_case_2(void) 7802 { 7803 return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b); 7804 } 7805 7806 static int 7807 test_zuc_auth_cipher_test_case_1(void) 7808 { 7809 return test_zuc_auth_cipher( 7810 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7811 } 7812 7813 static int 7814 test_zuc_auth_cipher_test_case_1_oop(void) 7815 { 7816 return test_zuc_auth_cipher( 7817 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7818 } 7819 7820 static int 7821 test_zuc_auth_cipher_test_case_1_sgl(void) 7822 { 7823 return test_zuc_auth_cipher_sgl( 7824 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7825 } 7826 7827 static int 7828 test_zuc_auth_cipher_test_case_1_oop_sgl(void) 7829 { 7830 return test_zuc_auth_cipher_sgl( 7831 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7832 } 7833 7834 static int 7835 test_zuc_auth_cipher_test_case_2(void) 7836 { 7837 return test_zuc_auth_cipher( 7838 &zuc_auth_cipher_test_case_2, IN_PLACE, 0); 7839 } 7840 7841 static int 7842 test_zuc_auth_cipher_test_case_2_oop(void) 7843 { 7844 return test_zuc_auth_cipher( 7845 &zuc_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7846 } 7847 7848 static int 7849 test_zuc_auth_cipher_verify_test_case_1(void) 7850 { 7851 return test_zuc_auth_cipher( 7852 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7853 } 7854 7855 static int 7856 test_zuc_auth_cipher_verify_test_case_1_oop(void) 7857 { 7858 return test_zuc_auth_cipher( 7859 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7860 } 7861 7862 static int 7863 test_zuc_auth_cipher_verify_test_case_1_sgl(void) 7864 { 7865 return test_zuc_auth_cipher_sgl( 7866 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7867 } 7868 7869 static int 7870 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void) 7871 { 7872 return test_zuc_auth_cipher_sgl( 7873 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7874 } 7875 7876 static int 7877 test_zuc_auth_cipher_verify_test_case_2(void) 7878 { 7879 return test_zuc_auth_cipher( 7880 &zuc_auth_cipher_test_case_2, IN_PLACE, 1); 7881 } 7882 7883 static int 7884 test_zuc_auth_cipher_verify_test_case_2_oop(void) 7885 { 7886 return test_zuc_auth_cipher( 7887 &zuc_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7888 } 7889 7890 static int 7891 test_zuc256_encryption_test_case_1(void) 7892 { 7893 return test_zuc_cipher(&zuc256_test_case_cipher_1, 7894 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7895 } 7896 7897 static int 7898 test_zuc256_encryption_test_case_2(void) 7899 { 7900 return test_zuc_cipher(&zuc256_test_case_cipher_2, 7901 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7902 } 7903 7904 static int 7905 test_zuc256_decryption_test_case_1(void) 7906 { 7907 return test_zuc_cipher(&zuc256_test_case_cipher_1, 7908 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7909 } 7910 7911 static int 7912 test_zuc256_decryption_test_case_2(void) 7913 { 7914 return test_zuc_cipher(&zuc256_test_case_cipher_2, 7915 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7916 } 7917 7918 static int 7919 test_zuc256_hash_generate_4b_tag_test_case_1(void) 7920 { 7921 return test_zuc_authentication(&zuc256_test_case_auth_1, 7922 RTE_CRYPTO_AUTH_OP_GENERATE); 7923 } 7924 7925 static int 7926 test_zuc256_hash_generate_4b_tag_test_case_2(void) 7927 { 7928 return test_zuc_authentication(&zuc256_test_case_auth_2, 7929 RTE_CRYPTO_AUTH_OP_GENERATE); 7930 } 7931 7932 static int 7933 test_zuc256_hash_generate_4b_tag_test_case_3(void) 7934 { 7935 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b, 7936 RTE_CRYPTO_AUTH_OP_GENERATE); 7937 } 7938 7939 static int 7940 test_zuc256_hash_generate_8b_tag_test_case_1(void) 7941 { 7942 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b, 7943 RTE_CRYPTO_AUTH_OP_GENERATE); 7944 } 7945 7946 static int 7947 test_zuc256_hash_generate_16b_tag_test_case_1(void) 7948 { 7949 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b, 7950 RTE_CRYPTO_AUTH_OP_GENERATE); 7951 } 7952 7953 static int 7954 test_zuc256_hash_verify_4b_tag_test_case_1(void) 7955 { 7956 return test_zuc_authentication(&zuc256_test_case_auth_1, 7957 RTE_CRYPTO_AUTH_OP_VERIFY); 7958 } 7959 7960 static int 7961 test_zuc256_hash_verify_4b_tag_test_case_2(void) 7962 { 7963 return test_zuc_authentication(&zuc256_test_case_auth_2, 7964 RTE_CRYPTO_AUTH_OP_VERIFY); 7965 } 7966 7967 static int 7968 test_zuc256_hash_verify_4b_tag_test_case_3(void) 7969 { 7970 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b, 7971 RTE_CRYPTO_AUTH_OP_VERIFY); 7972 } 7973 7974 static int 7975 test_zuc256_hash_verify_8b_tag_test_case_1(void) 7976 { 7977 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b, 7978 RTE_CRYPTO_AUTH_OP_VERIFY); 7979 } 7980 7981 static int 7982 test_zuc256_hash_verify_16b_tag_test_case_1(void) 7983 { 7984 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b, 7985 RTE_CRYPTO_AUTH_OP_VERIFY); 7986 } 7987 7988 static int 7989 test_zuc256_cipher_auth_4b_tag_test_case_1(void) 7990 { 7991 return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_1); 7992 } 7993 7994 static int 7995 test_zuc256_cipher_auth_4b_tag_test_case_2(void) 7996 { 7997 return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_2); 7998 } 7999 8000 static int 8001 test_zuc256_cipher_auth_8b_tag_test_case_1(void) 8002 { 8003 return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_3); 8004 } 8005 8006 static int 8007 test_zuc256_cipher_auth_16b_tag_test_case_1(void) 8008 { 8009 return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_4); 8010 } 8011 8012 static int 8013 test_zuc256_auth_cipher_4b_tag_test_case_1(void) 8014 { 8015 return test_zuc_auth_cipher( 8016 &zuc256_auth_cipher_test_case_1, IN_PLACE, 0); 8017 } 8018 8019 static int 8020 test_zuc256_auth_cipher_4b_tag_test_case_2(void) 8021 { 8022 return test_zuc_auth_cipher( 8023 &zuc256_auth_cipher_test_case_2, IN_PLACE, 0); 8024 } 8025 8026 static int 8027 test_zuc256_auth_cipher_8b_tag_test_case_1(void) 8028 { 8029 return test_zuc_auth_cipher( 8030 &zuc256_auth_cipher_test_case_3, IN_PLACE, 0); 8031 } 8032 8033 static int 8034 test_zuc256_auth_cipher_16b_tag_test_case_1(void) 8035 { 8036 return test_zuc_auth_cipher( 8037 &zuc256_auth_cipher_test_case_4, IN_PLACE, 0); 8038 } 8039 8040 static int 8041 test_zuc256_auth_cipher_verify_4b_tag_test_case_1(void) 8042 { 8043 return test_zuc_auth_cipher( 8044 &zuc256_auth_cipher_test_case_1, IN_PLACE, 1); 8045 } 8046 8047 static int 8048 test_zuc256_auth_cipher_verify_4b_tag_test_case_2(void) 8049 { 8050 return test_zuc_auth_cipher( 8051 &zuc256_auth_cipher_test_case_2, IN_PLACE, 1); 8052 } 8053 8054 static int 8055 test_zuc256_auth_cipher_verify_8b_tag_test_case_1(void) 8056 { 8057 return test_zuc_auth_cipher( 8058 &zuc256_auth_cipher_test_case_3, IN_PLACE, 1); 8059 } 8060 8061 static int 8062 test_zuc256_auth_cipher_verify_16b_tag_test_case_1(void) 8063 { 8064 return test_zuc_auth_cipher( 8065 &zuc256_auth_cipher_test_case_4, IN_PLACE, 1); 8066 } 8067 8068 static int 8069 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata) 8070 { 8071 uint8_t dev_id = testsuite_params.valid_devs[0]; 8072 8073 struct rte_cryptodev_sym_capability_idx cap_idx; 8074 8075 /* Check if device supports particular cipher algorithm */ 8076 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8077 cap_idx.algo.cipher = tdata->cipher_algo; 8078 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 8079 return TEST_SKIPPED; 8080 8081 /* Check if device supports particular hash algorithm */ 8082 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8083 cap_idx.algo.auth = tdata->auth_algo; 8084 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 8085 return TEST_SKIPPED; 8086 8087 return 0; 8088 } 8089 8090 static int 8091 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata, 8092 uint8_t op_mode, uint8_t verify) 8093 { 8094 struct crypto_testsuite_params *ts_params = &testsuite_params; 8095 struct crypto_unittest_params *ut_params = &unittest_params; 8096 8097 int retval; 8098 8099 uint8_t *plaintext = NULL, *ciphertext = NULL; 8100 unsigned int plaintext_pad_len; 8101 unsigned int plaintext_len; 8102 unsigned int ciphertext_pad_len; 8103 unsigned int ciphertext_len; 8104 unsigned int digest_offset; 8105 8106 struct rte_cryptodev_info dev_info; 8107 struct rte_crypto_op *op; 8108 8109 /* Check if device supports particular algorithms separately */ 8110 if (test_mixed_check_if_unsupported(tdata)) 8111 return TEST_SKIPPED; 8112 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 8113 return TEST_SKIPPED; 8114 8115 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8116 return TEST_SKIPPED; 8117 8118 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8119 8120 uint64_t feat_flags = dev_info.feature_flags; 8121 8122 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 8123 printf("Device doesn't support digest encrypted.\n"); 8124 return TEST_SKIPPED; 8125 } 8126 8127 /* Create the session */ 8128 if (verify) 8129 retval = create_wireless_algo_cipher_auth_session( 8130 ts_params->valid_devs[0], 8131 RTE_CRYPTO_CIPHER_OP_DECRYPT, 8132 RTE_CRYPTO_AUTH_OP_VERIFY, 8133 tdata->auth_algo, 8134 tdata->cipher_algo, 8135 tdata->auth_key.data, tdata->auth_key.len, 8136 tdata->cipher_key.data, tdata->cipher_key.len, 8137 tdata->auth_iv.len, tdata->digest_enc.len, 8138 tdata->cipher_iv.len); 8139 else 8140 retval = create_wireless_algo_auth_cipher_session( 8141 ts_params->valid_devs[0], 8142 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8143 RTE_CRYPTO_AUTH_OP_GENERATE, 8144 tdata->auth_algo, 8145 tdata->cipher_algo, 8146 tdata->auth_key.data, tdata->auth_key.len, 8147 tdata->cipher_key.data, tdata->cipher_key.len, 8148 tdata->auth_iv.len, tdata->digest_enc.len, 8149 tdata->cipher_iv.len); 8150 if (retval != 0) 8151 return retval; 8152 8153 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8154 if (op_mode == OUT_OF_PLACE) 8155 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8156 8157 /* clear mbuf payload */ 8158 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8159 rte_pktmbuf_tailroom(ut_params->ibuf)); 8160 if (op_mode == OUT_OF_PLACE) { 8161 8162 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 8163 rte_pktmbuf_tailroom(ut_params->obuf)); 8164 } 8165 8166 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 8167 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 8168 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 8169 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 8170 8171 if (verify) { 8172 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8173 ciphertext_pad_len); 8174 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 8175 debug_hexdump(stdout, "ciphertext:", ciphertext, 8176 ciphertext_len); 8177 } else { 8178 /* make sure enough space to cover partial digest verify case */ 8179 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8180 ciphertext_pad_len); 8181 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 8182 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 8183 } 8184 8185 if (op_mode == OUT_OF_PLACE) 8186 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 8187 8188 /* Create the operation */ 8189 retval = create_wireless_algo_auth_cipher_operation( 8190 tdata->digest_enc.data, tdata->digest_enc.len, 8191 tdata->cipher_iv.data, tdata->cipher_iv.len, 8192 tdata->auth_iv.data, tdata->auth_iv.len, 8193 (tdata->digest_enc.offset == 0 ? 8194 plaintext_pad_len 8195 : tdata->digest_enc.offset), 8196 tdata->validCipherLen.len_bits, 8197 tdata->cipher.offset_bits, 8198 tdata->validAuthLen.len_bits, 8199 tdata->auth.offset_bits, 8200 op_mode, 0, verify); 8201 8202 if (retval < 0) 8203 return retval; 8204 8205 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 8206 8207 /* Check if the op failed because the device doesn't */ 8208 /* support this particular combination of algorithms */ 8209 if (op == NULL && ut_params->op->status == 8210 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 8211 printf("Device doesn't support this mixed combination. " 8212 "Test Skipped.\n"); 8213 return TEST_SKIPPED; 8214 } 8215 ut_params->op = op; 8216 8217 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 8218 8219 ut_params->obuf = (op_mode == IN_PLACE ? 8220 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 8221 8222 if (verify) { 8223 if (ut_params->obuf) 8224 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 8225 uint8_t *); 8226 else 8227 plaintext = ciphertext + 8228 (tdata->cipher.offset_bits >> 3); 8229 8230 debug_hexdump(stdout, "plaintext:", plaintext, 8231 tdata->plaintext.len_bits >> 3); 8232 debug_hexdump(stdout, "plaintext expected:", 8233 tdata->plaintext.data, 8234 tdata->plaintext.len_bits >> 3); 8235 } else { 8236 if (ut_params->obuf) 8237 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 8238 uint8_t *); 8239 else 8240 ciphertext = plaintext; 8241 8242 debug_hexdump(stdout, "ciphertext:", ciphertext, 8243 ciphertext_len); 8244 debug_hexdump(stdout, "ciphertext expected:", 8245 tdata->ciphertext.data, 8246 tdata->ciphertext.len_bits >> 3); 8247 8248 if (tdata->digest_enc.offset == 0) 8249 digest_offset = plaintext_pad_len; 8250 else 8251 digest_offset = tdata->digest_enc.offset; 8252 8253 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 8254 uint8_t *, digest_offset); 8255 8256 debug_hexdump(stdout, "digest:", ut_params->digest, 8257 tdata->digest_enc.len); 8258 debug_hexdump(stdout, "digest expected:", 8259 tdata->digest_enc.data, 8260 tdata->digest_enc.len); 8261 } 8262 8263 if (!verify) { 8264 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8265 ut_params->digest, 8266 tdata->digest_enc.data, 8267 tdata->digest_enc.len, 8268 "Generated auth tag not as expected"); 8269 } 8270 8271 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 8272 if (verify) { 8273 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 8274 plaintext, 8275 tdata->plaintext.data, 8276 tdata->plaintext.len_bits >> 3, 8277 "Plaintext data not as expected"); 8278 } else { 8279 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 8280 ciphertext, 8281 tdata->ciphertext.data, 8282 tdata->validDataLen.len_bits, 8283 "Ciphertext data not as expected"); 8284 } 8285 } 8286 8287 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8288 "crypto op processing failed"); 8289 8290 return 0; 8291 } 8292 8293 static int 8294 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata, 8295 uint8_t op_mode, uint8_t verify) 8296 { 8297 struct crypto_testsuite_params *ts_params = &testsuite_params; 8298 struct crypto_unittest_params *ut_params = &unittest_params; 8299 8300 int retval; 8301 8302 const uint8_t *plaintext = NULL; 8303 const uint8_t *ciphertext = NULL; 8304 const uint8_t *digest = NULL; 8305 unsigned int plaintext_pad_len; 8306 unsigned int plaintext_len; 8307 unsigned int ciphertext_pad_len; 8308 unsigned int ciphertext_len; 8309 uint8_t buffer[10000]; 8310 uint8_t digest_buffer[10000]; 8311 8312 struct rte_cryptodev_info dev_info; 8313 struct rte_crypto_op *op; 8314 8315 /* Check if device supports particular algorithms */ 8316 if (test_mixed_check_if_unsupported(tdata)) 8317 return TEST_SKIPPED; 8318 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 8319 return TEST_SKIPPED; 8320 8321 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8322 8323 uint64_t feat_flags = dev_info.feature_flags; 8324 8325 if (op_mode == IN_PLACE) { 8326 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 8327 printf("Device doesn't support in-place scatter-gather " 8328 "in both input and output mbufs.\n"); 8329 return TEST_SKIPPED; 8330 } 8331 } else { 8332 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 8333 printf("Device doesn't support out-of-place scatter-gather " 8334 "in both input and output mbufs.\n"); 8335 return TEST_SKIPPED; 8336 } 8337 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 8338 printf("Device doesn't support digest encrypted.\n"); 8339 return TEST_SKIPPED; 8340 } 8341 } 8342 8343 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8344 return TEST_SKIPPED; 8345 8346 /* Create the session */ 8347 if (verify) 8348 retval = create_wireless_algo_cipher_auth_session( 8349 ts_params->valid_devs[0], 8350 RTE_CRYPTO_CIPHER_OP_DECRYPT, 8351 RTE_CRYPTO_AUTH_OP_VERIFY, 8352 tdata->auth_algo, 8353 tdata->cipher_algo, 8354 tdata->auth_key.data, tdata->auth_key.len, 8355 tdata->cipher_key.data, tdata->cipher_key.len, 8356 tdata->auth_iv.len, tdata->digest_enc.len, 8357 tdata->cipher_iv.len); 8358 else 8359 retval = create_wireless_algo_auth_cipher_session( 8360 ts_params->valid_devs[0], 8361 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8362 RTE_CRYPTO_AUTH_OP_GENERATE, 8363 tdata->auth_algo, 8364 tdata->cipher_algo, 8365 tdata->auth_key.data, tdata->auth_key.len, 8366 tdata->cipher_key.data, tdata->cipher_key.len, 8367 tdata->auth_iv.len, tdata->digest_enc.len, 8368 tdata->cipher_iv.len); 8369 if (retval != 0) 8370 return retval; 8371 8372 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 8373 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 8374 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 8375 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 8376 8377 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 8378 ciphertext_pad_len, 15, 0); 8379 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 8380 "Failed to allocate input buffer in mempool"); 8381 8382 if (op_mode == OUT_OF_PLACE) { 8383 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 8384 plaintext_pad_len, 15, 0); 8385 TEST_ASSERT_NOT_NULL(ut_params->obuf, 8386 "Failed to allocate output buffer in mempool"); 8387 } 8388 8389 if (verify) { 8390 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 8391 tdata->ciphertext.data); 8392 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 8393 ciphertext_len, buffer); 8394 debug_hexdump(stdout, "ciphertext:", ciphertext, 8395 ciphertext_len); 8396 } else { 8397 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 8398 tdata->plaintext.data); 8399 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 8400 plaintext_len, buffer); 8401 debug_hexdump(stdout, "plaintext:", plaintext, 8402 plaintext_len); 8403 } 8404 memset(buffer, 0, sizeof(buffer)); 8405 8406 /* Create the operation */ 8407 retval = create_wireless_algo_auth_cipher_operation( 8408 tdata->digest_enc.data, tdata->digest_enc.len, 8409 tdata->cipher_iv.data, tdata->cipher_iv.len, 8410 tdata->auth_iv.data, tdata->auth_iv.len, 8411 (tdata->digest_enc.offset == 0 ? 8412 plaintext_pad_len 8413 : tdata->digest_enc.offset), 8414 tdata->validCipherLen.len_bits, 8415 tdata->cipher.offset_bits, 8416 tdata->validAuthLen.len_bits, 8417 tdata->auth.offset_bits, 8418 op_mode, 1, verify); 8419 8420 if (retval < 0) 8421 return retval; 8422 8423 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 8424 8425 /* Check if the op failed because the device doesn't */ 8426 /* support this particular combination of algorithms */ 8427 if (op == NULL && ut_params->op->status == 8428 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 8429 printf("Device doesn't support this mixed combination. " 8430 "Test Skipped.\n"); 8431 return TEST_SKIPPED; 8432 } 8433 ut_params->op = op; 8434 8435 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 8436 8437 ut_params->obuf = (op_mode == IN_PLACE ? 8438 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 8439 8440 if (verify) { 8441 if (ut_params->obuf) 8442 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 8443 plaintext_len, buffer); 8444 else 8445 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 8446 plaintext_len, buffer); 8447 8448 debug_hexdump(stdout, "plaintext:", plaintext, 8449 (tdata->plaintext.len_bits >> 3) - 8450 tdata->digest_enc.len); 8451 debug_hexdump(stdout, "plaintext expected:", 8452 tdata->plaintext.data, 8453 (tdata->plaintext.len_bits >> 3) - 8454 tdata->digest_enc.len); 8455 } else { 8456 if (ut_params->obuf) 8457 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 8458 ciphertext_len, buffer); 8459 else 8460 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 8461 ciphertext_len, buffer); 8462 8463 debug_hexdump(stdout, "ciphertext:", ciphertext, 8464 ciphertext_len); 8465 debug_hexdump(stdout, "ciphertext expected:", 8466 tdata->ciphertext.data, 8467 tdata->ciphertext.len_bits >> 3); 8468 8469 if (ut_params->obuf) 8470 digest = rte_pktmbuf_read(ut_params->obuf, 8471 (tdata->digest_enc.offset == 0 ? 8472 plaintext_pad_len : 8473 tdata->digest_enc.offset), 8474 tdata->digest_enc.len, digest_buffer); 8475 else 8476 digest = rte_pktmbuf_read(ut_params->ibuf, 8477 (tdata->digest_enc.offset == 0 ? 8478 plaintext_pad_len : 8479 tdata->digest_enc.offset), 8480 tdata->digest_enc.len, digest_buffer); 8481 8482 debug_hexdump(stdout, "digest:", digest, 8483 tdata->digest_enc.len); 8484 debug_hexdump(stdout, "digest expected:", 8485 tdata->digest_enc.data, tdata->digest_enc.len); 8486 } 8487 8488 if (!verify) { 8489 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8490 digest, 8491 tdata->digest_enc.data, 8492 tdata->digest_enc.len, 8493 "Generated auth tag not as expected"); 8494 } 8495 8496 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 8497 if (verify) { 8498 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 8499 plaintext, 8500 tdata->plaintext.data, 8501 tdata->plaintext.len_bits >> 3, 8502 "Plaintext data not as expected"); 8503 } else { 8504 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 8505 ciphertext, 8506 tdata->ciphertext.data, 8507 tdata->validDataLen.len_bits, 8508 "Ciphertext data not as expected"); 8509 } 8510 } 8511 8512 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8513 "crypto op processing failed"); 8514 8515 return 0; 8516 } 8517 8518 /** AUTH AES CMAC + CIPHER AES CTR */ 8519 8520 static int 8521 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 8522 { 8523 return test_mixed_auth_cipher( 8524 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8525 } 8526 8527 static int 8528 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 8529 { 8530 return test_mixed_auth_cipher( 8531 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8532 } 8533 8534 static int 8535 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 8536 { 8537 return test_mixed_auth_cipher_sgl( 8538 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8539 } 8540 8541 static int 8542 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 8543 { 8544 return test_mixed_auth_cipher_sgl( 8545 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8546 } 8547 8548 static int 8549 test_aes_cmac_aes_ctr_digest_enc_test_case_2(void) 8550 { 8551 return test_mixed_auth_cipher( 8552 &auth_aes_cmac_cipher_aes_ctr_test_case_2, IN_PLACE, 0); 8553 } 8554 8555 static int 8556 test_aes_cmac_aes_ctr_digest_enc_test_case_2_oop(void) 8557 { 8558 return test_mixed_auth_cipher( 8559 &auth_aes_cmac_cipher_aes_ctr_test_case_2, OUT_OF_PLACE, 0); 8560 } 8561 8562 static int 8563 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 8564 { 8565 return test_mixed_auth_cipher( 8566 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8567 } 8568 8569 static int 8570 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2(void) 8571 { 8572 return test_mixed_auth_cipher( 8573 &auth_aes_cmac_cipher_aes_ctr_test_case_2, IN_PLACE, 1); 8574 } 8575 8576 static int 8577 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 8578 { 8579 return test_mixed_auth_cipher( 8580 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8581 } 8582 8583 static int 8584 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 8585 { 8586 return test_mixed_auth_cipher_sgl( 8587 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8588 } 8589 8590 static int 8591 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 8592 { 8593 return test_mixed_auth_cipher_sgl( 8594 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8595 } 8596 8597 static int 8598 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2_oop(void) 8599 { 8600 return test_mixed_auth_cipher( 8601 &auth_aes_cmac_cipher_aes_ctr_test_case_2, OUT_OF_PLACE, 1); 8602 } 8603 8604 /** MIXED AUTH + CIPHER */ 8605 8606 static int 8607 test_auth_zuc_cipher_snow_test_case_1(void) 8608 { 8609 return test_mixed_auth_cipher( 8610 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 8611 } 8612 8613 static int 8614 test_verify_auth_zuc_cipher_snow_test_case_1(void) 8615 { 8616 return test_mixed_auth_cipher( 8617 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 8618 } 8619 8620 static int 8621 test_auth_zuc_cipher_snow_test_case_1_inplace(void) 8622 { 8623 return test_mixed_auth_cipher( 8624 &auth_zuc_cipher_snow_test_case_1, IN_PLACE, 0); 8625 } 8626 8627 static int 8628 test_verify_auth_zuc_cipher_snow_test_case_1_inplace(void) 8629 { 8630 return test_mixed_auth_cipher( 8631 &auth_zuc_cipher_snow_test_case_1, IN_PLACE, 1); 8632 } 8633 8634 8635 static int 8636 test_auth_aes_cmac_cipher_snow_test_case_1(void) 8637 { 8638 return test_mixed_auth_cipher( 8639 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 8640 } 8641 8642 static int 8643 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void) 8644 { 8645 return test_mixed_auth_cipher( 8646 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 8647 } 8648 8649 static int 8650 test_auth_aes_cmac_cipher_snow_test_case_1_inplace(void) 8651 { 8652 return test_mixed_auth_cipher( 8653 &auth_aes_cmac_cipher_snow_test_case_1, IN_PLACE, 0); 8654 } 8655 8656 static int 8657 test_verify_auth_aes_cmac_cipher_snow_test_case_1_inplace(void) 8658 { 8659 return test_mixed_auth_cipher( 8660 &auth_aes_cmac_cipher_snow_test_case_1, IN_PLACE, 1); 8661 } 8662 8663 static int 8664 test_auth_zuc_cipher_aes_ctr_test_case_1(void) 8665 { 8666 return test_mixed_auth_cipher( 8667 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8668 } 8669 8670 static int 8671 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void) 8672 { 8673 return test_mixed_auth_cipher( 8674 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8675 } 8676 8677 static int 8678 test_auth_zuc_cipher_aes_ctr_test_case_1_inplace(void) 8679 { 8680 return test_mixed_auth_cipher( 8681 &auth_zuc_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8682 } 8683 8684 static int 8685 test_verify_auth_zuc_cipher_aes_ctr_test_case_1_inplace(void) 8686 { 8687 return test_mixed_auth_cipher( 8688 &auth_zuc_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8689 } 8690 8691 static int 8692 test_auth_snow_cipher_aes_ctr_test_case_1(void) 8693 { 8694 return test_mixed_auth_cipher( 8695 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8696 } 8697 8698 static int 8699 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void) 8700 { 8701 return test_mixed_auth_cipher( 8702 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8703 } 8704 8705 static int 8706 test_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl(void) 8707 { 8708 return test_mixed_auth_cipher_sgl( 8709 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8710 } 8711 8712 static int 8713 test_auth_snow_cipher_aes_ctr_test_case_1_inplace(void) 8714 { 8715 return test_mixed_auth_cipher( 8716 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8717 } 8718 8719 static int 8720 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl(void) 8721 { 8722 return test_mixed_auth_cipher_sgl( 8723 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8724 } 8725 8726 static int 8727 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace(void) 8728 { 8729 return test_mixed_auth_cipher( 8730 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8731 } 8732 8733 static int 8734 test_auth_snow_cipher_zuc_test_case_1(void) 8735 { 8736 return test_mixed_auth_cipher( 8737 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 8738 } 8739 8740 static int 8741 test_verify_auth_snow_cipher_zuc_test_case_1(void) 8742 { 8743 return test_mixed_auth_cipher( 8744 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 8745 } 8746 8747 static int 8748 test_auth_snow_cipher_zuc_test_case_1_inplace(void) 8749 { 8750 return test_mixed_auth_cipher( 8751 &auth_snow_cipher_zuc_test_case_1, IN_PLACE, 0); 8752 } 8753 8754 static int 8755 test_verify_auth_snow_cipher_zuc_test_case_1_inplace(void) 8756 { 8757 return test_mixed_auth_cipher( 8758 &auth_snow_cipher_zuc_test_case_1, IN_PLACE, 1); 8759 } 8760 8761 static int 8762 test_auth_aes_cmac_cipher_zuc_test_case_1(void) 8763 { 8764 return test_mixed_auth_cipher( 8765 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 8766 } 8767 8768 static int 8769 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void) 8770 { 8771 return test_mixed_auth_cipher( 8772 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 8773 } 8774 static int 8775 test_auth_aes_cmac_cipher_zuc_test_case_1_inplace(void) 8776 { 8777 return test_mixed_auth_cipher( 8778 &auth_aes_cmac_cipher_zuc_test_case_1, IN_PLACE, 0); 8779 } 8780 8781 static int 8782 test_verify_auth_aes_cmac_cipher_zuc_test_case_1_inplace(void) 8783 { 8784 return test_mixed_auth_cipher( 8785 &auth_aes_cmac_cipher_zuc_test_case_1, IN_PLACE, 1); 8786 } 8787 8788 static int 8789 test_auth_null_cipher_snow_test_case_1(void) 8790 { 8791 return test_mixed_auth_cipher( 8792 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 8793 } 8794 8795 static int 8796 test_verify_auth_null_cipher_snow_test_case_1(void) 8797 { 8798 return test_mixed_auth_cipher( 8799 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 8800 } 8801 8802 static int 8803 test_auth_null_cipher_zuc_test_case_1(void) 8804 { 8805 return test_mixed_auth_cipher( 8806 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 8807 } 8808 8809 static int 8810 test_verify_auth_null_cipher_zuc_test_case_1(void) 8811 { 8812 return test_mixed_auth_cipher( 8813 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 8814 } 8815 8816 static int 8817 test_auth_snow_cipher_null_test_case_1(void) 8818 { 8819 return test_mixed_auth_cipher( 8820 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0); 8821 } 8822 8823 static int 8824 test_verify_auth_snow_cipher_null_test_case_1(void) 8825 { 8826 return test_mixed_auth_cipher( 8827 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1); 8828 } 8829 8830 static int 8831 test_auth_zuc_cipher_null_test_case_1(void) 8832 { 8833 return test_mixed_auth_cipher( 8834 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0); 8835 } 8836 8837 static int 8838 test_verify_auth_zuc_cipher_null_test_case_1(void) 8839 { 8840 return test_mixed_auth_cipher( 8841 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1); 8842 } 8843 8844 static int 8845 test_auth_null_cipher_aes_ctr_test_case_1(void) 8846 { 8847 return test_mixed_auth_cipher( 8848 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8849 } 8850 8851 static int 8852 test_verify_auth_null_cipher_aes_ctr_test_case_1(void) 8853 { 8854 return test_mixed_auth_cipher( 8855 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8856 } 8857 8858 static int 8859 test_auth_aes_cmac_cipher_null_test_case_1(void) 8860 { 8861 return test_mixed_auth_cipher( 8862 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0); 8863 } 8864 8865 static int 8866 test_verify_auth_aes_cmac_cipher_null_test_case_1(void) 8867 { 8868 return test_mixed_auth_cipher( 8869 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1); 8870 } 8871 8872 /* ***** AEAD algorithm Tests ***** */ 8873 8874 static int 8875 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo, 8876 enum rte_crypto_aead_operation op, 8877 const uint8_t *key, const uint8_t key_len, 8878 const uint16_t aad_len, const uint8_t auth_len, 8879 uint8_t iv_len) 8880 { 8881 uint8_t aead_key[key_len]; 8882 8883 struct crypto_testsuite_params *ts_params = &testsuite_params; 8884 struct crypto_unittest_params *ut_params = &unittest_params; 8885 8886 memcpy(aead_key, key, key_len); 8887 8888 /* Setup AEAD Parameters */ 8889 ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 8890 ut_params->aead_xform.next = NULL; 8891 ut_params->aead_xform.aead.algo = algo; 8892 ut_params->aead_xform.aead.op = op; 8893 ut_params->aead_xform.aead.key.data = aead_key; 8894 ut_params->aead_xform.aead.key.length = key_len; 8895 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 8896 ut_params->aead_xform.aead.iv.length = iv_len; 8897 ut_params->aead_xform.aead.digest_length = auth_len; 8898 ut_params->aead_xform.aead.aad_length = aad_len; 8899 8900 debug_hexdump(stdout, "key:", key, key_len); 8901 8902 /* Create Crypto session*/ 8903 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 8904 &ut_params->aead_xform, ts_params->session_mpool); 8905 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 8906 return TEST_SKIPPED; 8907 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 8908 return 0; 8909 } 8910 8911 static int 8912 create_aead_xform(struct rte_crypto_op *op, 8913 enum rte_crypto_aead_algorithm algo, 8914 enum rte_crypto_aead_operation aead_op, 8915 uint8_t *key, const uint8_t key_len, 8916 const uint8_t aad_len, const uint8_t auth_len, 8917 uint8_t iv_len) 8918 { 8919 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1), 8920 "failed to allocate space for crypto transform"); 8921 8922 struct rte_crypto_sym_op *sym_op = op->sym; 8923 8924 /* Setup AEAD Parameters */ 8925 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD; 8926 sym_op->xform->next = NULL; 8927 sym_op->xform->aead.algo = algo; 8928 sym_op->xform->aead.op = aead_op; 8929 sym_op->xform->aead.key.data = key; 8930 sym_op->xform->aead.key.length = key_len; 8931 sym_op->xform->aead.iv.offset = IV_OFFSET; 8932 sym_op->xform->aead.iv.length = iv_len; 8933 sym_op->xform->aead.digest_length = auth_len; 8934 sym_op->xform->aead.aad_length = aad_len; 8935 8936 debug_hexdump(stdout, "key:", key, key_len); 8937 8938 return 0; 8939 } 8940 8941 static int 8942 create_aead_operation(enum rte_crypto_aead_operation op, 8943 const struct aead_test_data *tdata) 8944 { 8945 struct crypto_testsuite_params *ts_params = &testsuite_params; 8946 struct crypto_unittest_params *ut_params = &unittest_params; 8947 8948 uint8_t *plaintext, *ciphertext; 8949 unsigned int aad_pad_len, plaintext_pad_len; 8950 8951 /* Generate Crypto op data structure */ 8952 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8953 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8954 TEST_ASSERT_NOT_NULL(ut_params->op, 8955 "Failed to allocate symmetric crypto operation struct"); 8956 8957 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 8958 8959 /* Append aad data */ 8960 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 8961 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16); 8962 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8963 aad_pad_len); 8964 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8965 "no room to append aad"); 8966 8967 sym_op->aead.aad.phys_addr = 8968 rte_pktmbuf_iova(ut_params->ibuf); 8969 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 8970 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len); 8971 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data + 18, 8972 tdata->aad.len); 8973 8974 /* Append IV at the end of the crypto operation*/ 8975 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8976 uint8_t *, IV_OFFSET); 8977 8978 /* Copy IV 1 byte after the IV pointer, according to the API */ 8979 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len); 8980 debug_hexdump(stdout, "iv:", iv_ptr + 1, 8981 tdata->iv.len); 8982 } else { 8983 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 8984 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8985 aad_pad_len); 8986 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8987 "no room to append aad"); 8988 8989 sym_op->aead.aad.phys_addr = 8990 rte_pktmbuf_iova(ut_params->ibuf); 8991 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len); 8992 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 8993 tdata->aad.len); 8994 8995 /* Append IV at the end of the crypto operation*/ 8996 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8997 uint8_t *, IV_OFFSET); 8998 8999 if (tdata->iv.len == 0) { 9000 rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH); 9001 debug_hexdump(stdout, "iv:", iv_ptr, 9002 AES_GCM_J0_LENGTH); 9003 } else { 9004 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 9005 debug_hexdump(stdout, "iv:", iv_ptr, 9006 tdata->iv.len); 9007 } 9008 } 9009 9010 /* Append plaintext/ciphertext */ 9011 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 9012 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 9013 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9014 plaintext_pad_len); 9015 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 9016 9017 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 9018 debug_hexdump(stdout, "plaintext:", plaintext, 9019 tdata->plaintext.len); 9020 9021 if (ut_params->obuf) { 9022 ciphertext = (uint8_t *)rte_pktmbuf_append( 9023 ut_params->obuf, 9024 plaintext_pad_len + aad_pad_len); 9025 TEST_ASSERT_NOT_NULL(ciphertext, 9026 "no room to append ciphertext"); 9027 9028 memset(ciphertext + aad_pad_len, 0, 9029 tdata->ciphertext.len); 9030 } 9031 } else { 9032 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); 9033 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9034 plaintext_pad_len); 9035 TEST_ASSERT_NOT_NULL(ciphertext, 9036 "no room to append ciphertext"); 9037 9038 memcpy(ciphertext, tdata->ciphertext.data, 9039 tdata->ciphertext.len); 9040 debug_hexdump(stdout, "ciphertext:", ciphertext, 9041 tdata->ciphertext.len); 9042 9043 if (ut_params->obuf) { 9044 plaintext = (uint8_t *)rte_pktmbuf_append( 9045 ut_params->obuf, 9046 plaintext_pad_len + aad_pad_len); 9047 TEST_ASSERT_NOT_NULL(plaintext, 9048 "no room to append plaintext"); 9049 9050 memset(plaintext + aad_pad_len, 0, 9051 tdata->plaintext.len); 9052 } 9053 } 9054 9055 /* Append digest data */ 9056 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 9057 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 9058 ut_params->obuf ? ut_params->obuf : 9059 ut_params->ibuf, 9060 tdata->auth_tag.len); 9061 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 9062 "no room to append digest"); 9063 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len); 9064 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 9065 ut_params->obuf ? ut_params->obuf : 9066 ut_params->ibuf, 9067 plaintext_pad_len + 9068 aad_pad_len); 9069 } else { 9070 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 9071 ut_params->ibuf, tdata->auth_tag.len); 9072 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 9073 "no room to append digest"); 9074 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 9075 ut_params->ibuf, 9076 plaintext_pad_len + aad_pad_len); 9077 9078 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 9079 tdata->auth_tag.len); 9080 debug_hexdump(stdout, "digest:", 9081 sym_op->aead.digest.data, 9082 tdata->auth_tag.len); 9083 } 9084 9085 sym_op->aead.data.length = tdata->plaintext.len; 9086 sym_op->aead.data.offset = aad_pad_len; 9087 9088 return 0; 9089 } 9090 9091 static int 9092 test_authenticated_encryption_helper(const struct aead_test_data *tdata, bool use_ext_mbuf) 9093 { 9094 struct crypto_testsuite_params *ts_params = &testsuite_params; 9095 struct crypto_unittest_params *ut_params = &unittest_params; 9096 9097 int retval; 9098 uint8_t *ciphertext, *auth_tag; 9099 uint16_t plaintext_pad_len; 9100 uint32_t i; 9101 struct rte_cryptodev_info dev_info; 9102 9103 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9104 uint64_t feat_flags = dev_info.feature_flags; 9105 9106 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9107 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9108 printf("Device doesn't support RAW data-path APIs.\n"); 9109 return TEST_SKIPPED; 9110 } 9111 9112 /* Verify the capabilities */ 9113 struct rte_cryptodev_sym_capability_idx cap_idx; 9114 const struct rte_cryptodev_symmetric_capability *capability; 9115 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9116 cap_idx.algo.aead = tdata->algo; 9117 capability = rte_cryptodev_sym_capability_get( 9118 ts_params->valid_devs[0], &cap_idx); 9119 if (capability == NULL) 9120 return TEST_SKIPPED; 9121 if (rte_cryptodev_sym_capability_check_aead( 9122 capability, tdata->key.len, tdata->auth_tag.len, 9123 tdata->aad.len, tdata->iv.len)) 9124 return TEST_SKIPPED; 9125 9126 /* Create AEAD session */ 9127 retval = create_aead_session(ts_params->valid_devs[0], 9128 tdata->algo, 9129 RTE_CRYPTO_AEAD_OP_ENCRYPT, 9130 tdata->key.data, tdata->key.len, 9131 tdata->aad.len, tdata->auth_tag.len, 9132 tdata->iv.len); 9133 if (retval != TEST_SUCCESS) 9134 return retval; 9135 9136 if (tdata->aad.len > MBUF_SIZE) { 9137 if (use_ext_mbuf) { 9138 ut_params->ibuf = ext_mbuf_create(ts_params->large_mbuf_pool, 9139 AEAD_TEXT_MAX_LENGTH, 9140 1 /* nb_segs */, 9141 NULL); 9142 } else { 9143 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 9144 } 9145 /* Populate full size of add data */ 9146 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 9147 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 9148 } else { 9149 if (use_ext_mbuf) { 9150 ut_params->ibuf = ext_mbuf_create(ts_params->mbuf_pool, 9151 AEAD_TEXT_MAX_LENGTH, 9152 1 /* nb_segs */, 9153 NULL); 9154 } else { 9155 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9156 } 9157 } 9158 9159 /* clear mbuf payload */ 9160 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9161 rte_pktmbuf_tailroom(ut_params->ibuf)); 9162 9163 /* Create AEAD operation */ 9164 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 9165 if (retval < 0) 9166 return retval; 9167 9168 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9169 9170 ut_params->op->sym->m_src = ut_params->ibuf; 9171 9172 /* Process crypto operation */ 9173 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9174 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 9175 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 9176 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 9177 0); 9178 if (retval != TEST_SUCCESS) 9179 return retval; 9180 } else 9181 TEST_ASSERT_NOT_NULL( 9182 process_crypto_request(ts_params->valid_devs[0], 9183 ut_params->op), "failed to process sym crypto op"); 9184 9185 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9186 "crypto op processing failed"); 9187 9188 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 9189 9190 if (ut_params->op->sym->m_dst) { 9191 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 9192 uint8_t *); 9193 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 9194 uint8_t *, plaintext_pad_len); 9195 } else { 9196 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 9197 uint8_t *, 9198 ut_params->op->sym->cipher.data.offset); 9199 auth_tag = ciphertext + plaintext_pad_len; 9200 } 9201 9202 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 9203 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 9204 9205 /* Validate obuf */ 9206 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9207 ciphertext, 9208 tdata->ciphertext.data, 9209 tdata->ciphertext.len, 9210 "Ciphertext data not as expected"); 9211 9212 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9213 auth_tag, 9214 tdata->auth_tag.data, 9215 tdata->auth_tag.len, 9216 "Generated auth tag not as expected"); 9217 9218 return 0; 9219 9220 } 9221 9222 static int 9223 test_authenticated_encryption(const struct aead_test_data *tdata) 9224 { 9225 return test_authenticated_encryption_helper(tdata, false); 9226 } 9227 9228 #ifdef RTE_LIB_SECURITY 9229 static int 9230 security_proto_supported(enum rte_security_session_action_type action, 9231 enum rte_security_session_protocol proto) 9232 { 9233 struct crypto_testsuite_params *ts_params = &testsuite_params; 9234 9235 const struct rte_security_capability *capabilities; 9236 const struct rte_security_capability *capability; 9237 uint16_t i = 0; 9238 9239 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 9240 9241 9242 capabilities = rte_security_capabilities_get(ctx); 9243 9244 if (capabilities == NULL) 9245 return -ENOTSUP; 9246 9247 while ((capability = &capabilities[i++])->action != 9248 RTE_SECURITY_ACTION_TYPE_NONE) { 9249 if (capability->action == action && 9250 capability->protocol == proto) 9251 return 0; 9252 } 9253 9254 return -ENOTSUP; 9255 } 9256 9257 /* Basic algorithm run function for async inplace mode. 9258 * Creates a session from input parameters and runs one operation 9259 * on input_vec. Checks the output of the crypto operation against 9260 * output_vec. 9261 */ 9262 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc, 9263 enum rte_crypto_auth_operation opa, 9264 const uint8_t *input_vec, unsigned int input_vec_len, 9265 const uint8_t *output_vec, 9266 unsigned int output_vec_len, 9267 enum rte_crypto_cipher_algorithm cipher_alg, 9268 const uint8_t *cipher_key, uint32_t cipher_key_len, 9269 enum rte_crypto_auth_algorithm auth_alg, 9270 const uint8_t *auth_key, uint32_t auth_key_len, 9271 uint8_t bearer, enum rte_security_pdcp_domain domain, 9272 uint8_t packet_direction, uint8_t sn_size, 9273 uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap) 9274 { 9275 struct crypto_testsuite_params *ts_params = &testsuite_params; 9276 struct crypto_unittest_params *ut_params = &unittest_params; 9277 uint8_t *plaintext; 9278 int ret = TEST_SUCCESS; 9279 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 9280 struct rte_cryptodev_info dev_info; 9281 uint64_t feat_flags; 9282 9283 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9284 feat_flags = dev_info.feature_flags; 9285 9286 /* Verify the capabilities */ 9287 struct rte_security_capability_idx sec_cap_idx; 9288 9289 sec_cap_idx.action = ut_params->type; 9290 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 9291 sec_cap_idx.pdcp.domain = domain; 9292 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 9293 return TEST_SKIPPED; 9294 9295 /* Generate test mbuf data */ 9296 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9297 9298 /* clear mbuf payload */ 9299 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9300 rte_pktmbuf_tailroom(ut_params->ibuf)); 9301 9302 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9303 input_vec_len); 9304 memcpy(plaintext, input_vec, input_vec_len); 9305 9306 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9307 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9308 printf("Device does not support RAW data-path APIs.\n"); 9309 return TEST_SKIPPED; 9310 } 9311 /* Out of place support */ 9312 if (oop) { 9313 /* 9314 * For out-op-place we need to alloc another mbuf 9315 */ 9316 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9317 rte_pktmbuf_append(ut_params->obuf, output_vec_len); 9318 } 9319 9320 /* Setup Cipher Parameters */ 9321 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9322 ut_params->cipher_xform.cipher.algo = cipher_alg; 9323 ut_params->cipher_xform.cipher.op = opc; 9324 ut_params->cipher_xform.cipher.key.data = cipher_key; 9325 ut_params->cipher_xform.cipher.key.length = cipher_key_len; 9326 ut_params->cipher_xform.cipher.iv.length = 9327 packet_direction ? 4 : 0; 9328 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 9329 9330 /* Setup HMAC Parameters if ICV header is required */ 9331 if (auth_alg != 0) { 9332 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9333 ut_params->auth_xform.next = NULL; 9334 ut_params->auth_xform.auth.algo = auth_alg; 9335 ut_params->auth_xform.auth.op = opa; 9336 ut_params->auth_xform.auth.key.data = auth_key; 9337 ut_params->auth_xform.auth.key.length = auth_key_len; 9338 9339 ut_params->cipher_xform.next = &ut_params->auth_xform; 9340 } else { 9341 ut_params->cipher_xform.next = NULL; 9342 } 9343 9344 struct rte_security_session_conf sess_conf = { 9345 .action_type = ut_params->type, 9346 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 9347 {.pdcp = { 9348 .bearer = bearer, 9349 .domain = domain, 9350 .pkt_dir = packet_direction, 9351 .sn_size = sn_size, 9352 .hfn = packet_direction ? 0 : hfn, 9353 /** 9354 * hfn can be set as pdcp_test_hfn[i] 9355 * if hfn_ovrd is not set. Here, PDCP 9356 * packet direction is just used to 9357 * run half of the cases with session 9358 * HFN and other half with per packet 9359 * HFN. 9360 */ 9361 .hfn_threshold = hfn_threshold, 9362 .hfn_ovrd = packet_direction ? 1 : 0, 9363 .sdap_enabled = sdap, 9364 } }, 9365 .crypto_xform = &ut_params->cipher_xform 9366 }; 9367 9368 /* Create security session */ 9369 ut_params->sec_session = rte_security_session_create(ctx, 9370 &sess_conf, ts_params->session_mpool); 9371 9372 if (!ut_params->sec_session) { 9373 printf("TestCase %s()-%d line %d failed %s: ", 9374 __func__, i, __LINE__, "Failed to allocate session"); 9375 ret = TEST_FAILED; 9376 goto on_err; 9377 } 9378 9379 /* Generate crypto op data structure */ 9380 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9381 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9382 if (!ut_params->op) { 9383 printf("TestCase %s()-%d line %d failed %s: ", 9384 __func__, i, __LINE__, 9385 "Failed to allocate symmetric crypto operation struct"); 9386 ret = TEST_FAILED; 9387 goto on_err; 9388 } 9389 9390 uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op, 9391 uint32_t *, IV_OFFSET); 9392 *per_pkt_hfn = packet_direction ? hfn : 0; 9393 9394 rte_security_attach_session(ut_params->op, ut_params->sec_session); 9395 9396 /* set crypto operation source mbuf */ 9397 ut_params->op->sym->m_src = ut_params->ibuf; 9398 if (oop) 9399 ut_params->op->sym->m_dst = ut_params->obuf; 9400 9401 /* Process crypto operation */ 9402 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 9403 /* filling lengths */ 9404 ut_params->op->sym->cipher.data.length = ut_params->op->sym->m_src->pkt_len; 9405 ut_params->op->sym->auth.data.length = ut_params->op->sym->m_src->pkt_len; 9406 9407 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 0); 9408 if (ret != TEST_SUCCESS) 9409 return ret; 9410 } else { 9411 ut_params->op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 9412 } 9413 if (ut_params->op == NULL) { 9414 printf("TestCase %s()-%d line %d failed %s: ", 9415 __func__, i, __LINE__, 9416 "failed to process sym crypto op"); 9417 ret = TEST_FAILED; 9418 goto on_err; 9419 } 9420 9421 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 9422 printf("TestCase %s()-%d line %d failed %s: ", 9423 __func__, i, __LINE__, "crypto op processing failed"); 9424 ret = TEST_FAILED; 9425 goto on_err; 9426 } 9427 9428 /* Validate obuf */ 9429 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 9430 uint8_t *); 9431 if (oop) { 9432 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 9433 uint8_t *); 9434 } 9435 9436 if (memcmp(ciphertext, output_vec, output_vec_len)) { 9437 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 9438 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len); 9439 rte_hexdump(stdout, "reference", output_vec, output_vec_len); 9440 ret = TEST_FAILED; 9441 goto on_err; 9442 } 9443 9444 on_err: 9445 rte_crypto_op_free(ut_params->op); 9446 ut_params->op = NULL; 9447 9448 if (ut_params->sec_session) 9449 rte_security_session_destroy(ctx, ut_params->sec_session); 9450 ut_params->sec_session = NULL; 9451 9452 rte_pktmbuf_free(ut_params->ibuf); 9453 ut_params->ibuf = NULL; 9454 if (oop) { 9455 rte_pktmbuf_free(ut_params->obuf); 9456 ut_params->obuf = NULL; 9457 } 9458 9459 return ret; 9460 } 9461 9462 static int 9463 test_pdcp_proto_SGL(int i, int oop, 9464 enum rte_crypto_cipher_operation opc, 9465 enum rte_crypto_auth_operation opa, 9466 uint8_t *input_vec, 9467 unsigned int input_vec_len, 9468 uint8_t *output_vec, 9469 unsigned int output_vec_len, 9470 uint32_t fragsz, 9471 uint32_t fragsz_oop) 9472 { 9473 struct crypto_testsuite_params *ts_params = &testsuite_params; 9474 struct crypto_unittest_params *ut_params = &unittest_params; 9475 uint8_t *plaintext; 9476 struct rte_mbuf *buf, *buf_oop = NULL; 9477 int ret = TEST_SUCCESS; 9478 int to_trn = 0; 9479 int to_trn_tbl[16]; 9480 int segs = 1; 9481 unsigned int trn_data = 0; 9482 struct rte_cryptodev_info dev_info; 9483 uint64_t feat_flags; 9484 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 9485 struct rte_mbuf *temp_mbuf; 9486 9487 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9488 feat_flags = dev_info.feature_flags; 9489 9490 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9491 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9492 printf("Device does not support RAW data-path APIs.\n"); 9493 return -ENOTSUP; 9494 } 9495 /* Verify the capabilities */ 9496 struct rte_security_capability_idx sec_cap_idx; 9497 9498 sec_cap_idx.action = ut_params->type; 9499 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 9500 sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain; 9501 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 9502 return TEST_SKIPPED; 9503 9504 if (fragsz > input_vec_len) 9505 fragsz = input_vec_len; 9506 9507 uint16_t plaintext_len = fragsz; 9508 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 9509 9510 if (fragsz_oop > output_vec_len) 9511 frag_size_oop = output_vec_len; 9512 9513 int ecx = 0; 9514 if (input_vec_len % fragsz != 0) { 9515 if (input_vec_len / fragsz + 1 > 16) 9516 return 1; 9517 } else if (input_vec_len / fragsz > 16) 9518 return 1; 9519 9520 /* Out of place support */ 9521 if (oop) { 9522 /* 9523 * For out-op-place we need to alloc another mbuf 9524 */ 9525 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9526 rte_pktmbuf_append(ut_params->obuf, frag_size_oop); 9527 buf_oop = ut_params->obuf; 9528 } 9529 9530 /* Generate test mbuf data */ 9531 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9532 9533 /* clear mbuf payload */ 9534 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9535 rte_pktmbuf_tailroom(ut_params->ibuf)); 9536 9537 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9538 plaintext_len); 9539 memcpy(plaintext, input_vec, plaintext_len); 9540 trn_data += plaintext_len; 9541 9542 buf = ut_params->ibuf; 9543 9544 /* 9545 * Loop until no more fragments 9546 */ 9547 9548 while (trn_data < input_vec_len) { 9549 ++segs; 9550 to_trn = (input_vec_len - trn_data < fragsz) ? 9551 (input_vec_len - trn_data) : fragsz; 9552 9553 to_trn_tbl[ecx++] = to_trn; 9554 9555 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9556 buf = buf->next; 9557 9558 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 9559 rte_pktmbuf_tailroom(buf)); 9560 9561 /* OOP */ 9562 if (oop && !fragsz_oop) { 9563 buf_oop->next = 9564 rte_pktmbuf_alloc(ts_params->mbuf_pool); 9565 buf_oop = buf_oop->next; 9566 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 9567 0, rte_pktmbuf_tailroom(buf_oop)); 9568 rte_pktmbuf_append(buf_oop, to_trn); 9569 } 9570 9571 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 9572 to_trn); 9573 9574 memcpy(plaintext, input_vec + trn_data, to_trn); 9575 trn_data += to_trn; 9576 } 9577 9578 ut_params->ibuf->nb_segs = segs; 9579 9580 segs = 1; 9581 if (fragsz_oop && oop) { 9582 to_trn = 0; 9583 ecx = 0; 9584 9585 trn_data = frag_size_oop; 9586 while (trn_data < output_vec_len) { 9587 ++segs; 9588 to_trn = 9589 (output_vec_len - trn_data < 9590 frag_size_oop) ? 9591 (output_vec_len - trn_data) : 9592 frag_size_oop; 9593 9594 to_trn_tbl[ecx++] = to_trn; 9595 9596 buf_oop->next = 9597 rte_pktmbuf_alloc(ts_params->mbuf_pool); 9598 buf_oop = buf_oop->next; 9599 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 9600 0, rte_pktmbuf_tailroom(buf_oop)); 9601 rte_pktmbuf_append(buf_oop, to_trn); 9602 9603 trn_data += to_trn; 9604 } 9605 ut_params->obuf->nb_segs = segs; 9606 } 9607 9608 /* Setup Cipher Parameters */ 9609 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9610 ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg; 9611 ut_params->cipher_xform.cipher.op = opc; 9612 ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i]; 9613 ut_params->cipher_xform.cipher.key.length = 9614 pdcp_test_params[i].cipher_key_len; 9615 ut_params->cipher_xform.cipher.iv.length = 0; 9616 9617 /* Setup HMAC Parameters if ICV header is required */ 9618 if (pdcp_test_params[i].auth_alg != 0) { 9619 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9620 ut_params->auth_xform.next = NULL; 9621 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg; 9622 ut_params->auth_xform.auth.op = opa; 9623 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i]; 9624 ut_params->auth_xform.auth.key.length = 9625 pdcp_test_params[i].auth_key_len; 9626 9627 ut_params->cipher_xform.next = &ut_params->auth_xform; 9628 } else { 9629 ut_params->cipher_xform.next = NULL; 9630 } 9631 9632 struct rte_security_session_conf sess_conf = { 9633 .action_type = ut_params->type, 9634 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 9635 {.pdcp = { 9636 .bearer = pdcp_test_bearer[i], 9637 .domain = pdcp_test_params[i].domain, 9638 .pkt_dir = pdcp_test_packet_direction[i], 9639 .sn_size = pdcp_test_data_sn_size[i], 9640 .hfn = pdcp_test_hfn[i], 9641 .hfn_threshold = pdcp_test_hfn_threshold[i], 9642 .hfn_ovrd = 0, 9643 } }, 9644 .crypto_xform = &ut_params->cipher_xform 9645 }; 9646 9647 /* Create security session */ 9648 ut_params->sec_session = rte_security_session_create(ctx, 9649 &sess_conf, ts_params->session_mpool); 9650 9651 if (!ut_params->sec_session) { 9652 printf("TestCase %s()-%d line %d failed %s: ", 9653 __func__, i, __LINE__, "Failed to allocate session"); 9654 ret = TEST_FAILED; 9655 goto on_err; 9656 } 9657 9658 /* Generate crypto op data structure */ 9659 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9660 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9661 if (!ut_params->op) { 9662 printf("TestCase %s()-%d line %d failed %s: ", 9663 __func__, i, __LINE__, 9664 "Failed to allocate symmetric crypto operation struct"); 9665 ret = TEST_FAILED; 9666 goto on_err; 9667 } 9668 9669 rte_security_attach_session(ut_params->op, ut_params->sec_session); 9670 9671 /* set crypto operation source mbuf */ 9672 ut_params->op->sym->m_src = ut_params->ibuf; 9673 if (oop) 9674 ut_params->op->sym->m_dst = ut_params->obuf; 9675 9676 /* Process crypto operation */ 9677 temp_mbuf = ut_params->op->sym->m_src; 9678 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 9679 /* filling lengths */ 9680 while (temp_mbuf) { 9681 ut_params->op->sym->cipher.data.length 9682 += temp_mbuf->pkt_len; 9683 ut_params->op->sym->auth.data.length 9684 += temp_mbuf->pkt_len; 9685 temp_mbuf = temp_mbuf->next; 9686 } 9687 9688 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 0); 9689 if (ret != TEST_SUCCESS) 9690 return ret; 9691 } else { 9692 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 9693 ut_params->op); 9694 } 9695 if (ut_params->op == NULL) { 9696 printf("TestCase %s()-%d line %d failed %s: ", 9697 __func__, i, __LINE__, 9698 "failed to process sym crypto op"); 9699 ret = TEST_FAILED; 9700 goto on_err; 9701 } 9702 9703 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 9704 printf("TestCase %s()-%d line %d failed %s: ", 9705 __func__, i, __LINE__, "crypto op processing failed"); 9706 ret = TEST_FAILED; 9707 goto on_err; 9708 } 9709 9710 /* Validate obuf */ 9711 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 9712 uint8_t *); 9713 if (oop) { 9714 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 9715 uint8_t *); 9716 } 9717 if (fragsz_oop) 9718 fragsz = frag_size_oop; 9719 if (memcmp(ciphertext, output_vec, fragsz)) { 9720 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 9721 rte_hexdump(stdout, "encrypted", ciphertext, fragsz); 9722 rte_hexdump(stdout, "reference", output_vec, fragsz); 9723 ret = TEST_FAILED; 9724 goto on_err; 9725 } 9726 9727 buf = ut_params->op->sym->m_src->next; 9728 if (oop) 9729 buf = ut_params->op->sym->m_dst->next; 9730 9731 unsigned int off = fragsz; 9732 9733 ecx = 0; 9734 while (buf) { 9735 ciphertext = rte_pktmbuf_mtod(buf, 9736 uint8_t *); 9737 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) { 9738 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 9739 rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]); 9740 rte_hexdump(stdout, "reference", output_vec + off, 9741 to_trn_tbl[ecx]); 9742 ret = TEST_FAILED; 9743 goto on_err; 9744 } 9745 off += to_trn_tbl[ecx++]; 9746 buf = buf->next; 9747 } 9748 on_err: 9749 rte_crypto_op_free(ut_params->op); 9750 ut_params->op = NULL; 9751 9752 if (ut_params->sec_session) 9753 rte_security_session_destroy(ctx, ut_params->sec_session); 9754 ut_params->sec_session = NULL; 9755 9756 rte_pktmbuf_free(ut_params->ibuf); 9757 ut_params->ibuf = NULL; 9758 if (oop) { 9759 rte_pktmbuf_free(ut_params->obuf); 9760 ut_params->obuf = NULL; 9761 } 9762 9763 return ret; 9764 } 9765 9766 int 9767 test_pdcp_proto_cplane_encap(int i) 9768 { 9769 return test_pdcp_proto( 9770 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 9771 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9772 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9773 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9774 pdcp_test_params[i].cipher_key_len, 9775 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9776 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9777 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9778 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9779 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9780 } 9781 9782 int 9783 test_pdcp_proto_uplane_encap(int i) 9784 { 9785 return test_pdcp_proto( 9786 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 9787 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9788 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 9789 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9790 pdcp_test_params[i].cipher_key_len, 9791 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9792 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9793 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9794 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9795 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9796 } 9797 9798 int 9799 test_pdcp_proto_uplane_encap_with_int(int i) 9800 { 9801 return test_pdcp_proto( 9802 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 9803 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9804 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9805 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9806 pdcp_test_params[i].cipher_key_len, 9807 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9808 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9809 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9810 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9811 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9812 } 9813 9814 int 9815 test_pdcp_proto_cplane_decap(int i) 9816 { 9817 return test_pdcp_proto( 9818 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 9819 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9820 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9821 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9822 pdcp_test_params[i].cipher_key_len, 9823 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9824 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9825 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9826 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9827 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9828 } 9829 9830 int 9831 test_pdcp_proto_uplane_decap(int i) 9832 { 9833 return test_pdcp_proto( 9834 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 9835 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 9836 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9837 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9838 pdcp_test_params[i].cipher_key_len, 9839 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9840 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9841 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9842 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9843 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9844 } 9845 9846 int 9847 test_pdcp_proto_uplane_decap_with_int(int i) 9848 { 9849 return test_pdcp_proto( 9850 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 9851 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9852 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9853 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9854 pdcp_test_params[i].cipher_key_len, 9855 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9856 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9857 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9858 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9859 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9860 } 9861 9862 static int 9863 test_PDCP_PROTO_SGL_in_place_32B(void) 9864 { 9865 /* i can be used for running any PDCP case 9866 * In this case it is uplane 12-bit AES-SNOW DL encap 9867 */ 9868 int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK; 9869 return test_pdcp_proto_SGL(i, IN_PLACE, 9870 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9871 RTE_CRYPTO_AUTH_OP_GENERATE, 9872 pdcp_test_data_in[i], 9873 pdcp_test_data_in_len[i], 9874 pdcp_test_data_out[i], 9875 pdcp_test_data_in_len[i]+4, 9876 32, 0); 9877 } 9878 static int 9879 test_PDCP_PROTO_SGL_oop_32B_128B(void) 9880 { 9881 /* i can be used for running any PDCP case 9882 * In this case it is uplane 18-bit NULL-NULL DL encap 9883 */ 9884 int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK; 9885 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9886 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9887 RTE_CRYPTO_AUTH_OP_GENERATE, 9888 pdcp_test_data_in[i], 9889 pdcp_test_data_in_len[i], 9890 pdcp_test_data_out[i], 9891 pdcp_test_data_in_len[i]+4, 9892 32, 128); 9893 } 9894 static int 9895 test_PDCP_PROTO_SGL_oop_32B_40B(void) 9896 { 9897 /* i can be used for running any PDCP case 9898 * In this case it is uplane 18-bit AES DL encap 9899 */ 9900 int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET 9901 + DOWNLINK; 9902 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9903 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9904 RTE_CRYPTO_AUTH_OP_GENERATE, 9905 pdcp_test_data_in[i], 9906 pdcp_test_data_in_len[i], 9907 pdcp_test_data_out[i], 9908 pdcp_test_data_in_len[i], 9909 32, 40); 9910 } 9911 static int 9912 test_PDCP_PROTO_SGL_oop_128B_32B(void) 9913 { 9914 /* i can be used for running any PDCP case 9915 * In this case it is cplane 12-bit AES-ZUC DL encap 9916 */ 9917 int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK; 9918 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9919 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9920 RTE_CRYPTO_AUTH_OP_GENERATE, 9921 pdcp_test_data_in[i], 9922 pdcp_test_data_in_len[i], 9923 pdcp_test_data_out[i], 9924 pdcp_test_data_in_len[i]+4, 9925 128, 32); 9926 } 9927 9928 static int 9929 test_PDCP_SDAP_PROTO_encap_all(void) 9930 { 9931 int i = 0, size = 0; 9932 int err, all_err = TEST_SUCCESS; 9933 const struct pdcp_sdap_test *cur_test; 9934 9935 size = RTE_DIM(list_pdcp_sdap_tests); 9936 9937 for (i = 0; i < size; i++) { 9938 cur_test = &list_pdcp_sdap_tests[i]; 9939 err = test_pdcp_proto( 9940 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9941 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9942 cur_test->in_len, cur_test->data_out, 9943 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9944 cur_test->param.cipher_alg, cur_test->cipher_key, 9945 cur_test->param.cipher_key_len, 9946 cur_test->param.auth_alg, 9947 cur_test->auth_key, cur_test->param.auth_key_len, 9948 cur_test->bearer, cur_test->param.domain, 9949 cur_test->packet_direction, cur_test->sn_size, 9950 cur_test->hfn, 9951 cur_test->hfn_threshold, SDAP_ENABLED); 9952 if (err) { 9953 printf("\t%d) %s: Encapsulation failed\n", 9954 cur_test->test_idx, 9955 cur_test->param.name); 9956 err = TEST_FAILED; 9957 } else { 9958 printf("\t%d) %s: Encap PASS\n", cur_test->test_idx, 9959 cur_test->param.name); 9960 err = TEST_SUCCESS; 9961 } 9962 all_err += err; 9963 } 9964 9965 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9966 9967 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9968 } 9969 9970 static int 9971 test_PDCP_PROTO_short_mac(void) 9972 { 9973 int i = 0, size = 0; 9974 int err, all_err = TEST_SUCCESS; 9975 const struct pdcp_short_mac_test *cur_test; 9976 9977 size = RTE_DIM(list_pdcp_smac_tests); 9978 9979 for (i = 0; i < size; i++) { 9980 cur_test = &list_pdcp_smac_tests[i]; 9981 err = test_pdcp_proto( 9982 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9983 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9984 cur_test->in_len, cur_test->data_out, 9985 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9986 RTE_CRYPTO_CIPHER_NULL, NULL, 9987 0, cur_test->param.auth_alg, 9988 cur_test->auth_key, cur_test->param.auth_key_len, 9989 0, cur_test->param.domain, 0, 0, 9990 0, 0, 0); 9991 if (err) { 9992 printf("\t%d) %s: Short MAC test failed\n", 9993 cur_test->test_idx, 9994 cur_test->param.name); 9995 err = TEST_FAILED; 9996 } else { 9997 printf("\t%d) %s: Short MAC test PASS\n", 9998 cur_test->test_idx, 9999 cur_test->param.name); 10000 rte_hexdump(stdout, "MAC I", 10001 cur_test->data_out + cur_test->in_len + 2, 10002 2); 10003 err = TEST_SUCCESS; 10004 } 10005 all_err += err; 10006 } 10007 10008 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 10009 10010 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 10011 10012 } 10013 10014 static int 10015 test_PDCP_SDAP_PROTO_decap_all(void) 10016 { 10017 int i = 0, size = 0; 10018 int err, all_err = TEST_SUCCESS; 10019 const struct pdcp_sdap_test *cur_test; 10020 10021 size = RTE_DIM(list_pdcp_sdap_tests); 10022 10023 for (i = 0; i < size; i++) { 10024 cur_test = &list_pdcp_sdap_tests[i]; 10025 err = test_pdcp_proto( 10026 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, 10027 RTE_CRYPTO_AUTH_OP_VERIFY, 10028 cur_test->data_out, 10029 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 10030 cur_test->data_in, cur_test->in_len, 10031 cur_test->param.cipher_alg, 10032 cur_test->cipher_key, cur_test->param.cipher_key_len, 10033 cur_test->param.auth_alg, cur_test->auth_key, 10034 cur_test->param.auth_key_len, cur_test->bearer, 10035 cur_test->param.domain, cur_test->packet_direction, 10036 cur_test->sn_size, cur_test->hfn, 10037 cur_test->hfn_threshold, SDAP_ENABLED); 10038 if (err) { 10039 printf("\t%d) %s: Decapsulation failed\n", 10040 cur_test->test_idx, 10041 cur_test->param.name); 10042 err = TEST_FAILED; 10043 } else { 10044 printf("\t%d) %s: Decap PASS\n", cur_test->test_idx, 10045 cur_test->param.name); 10046 err = TEST_SUCCESS; 10047 } 10048 all_err += err; 10049 } 10050 10051 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 10052 10053 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 10054 } 10055 10056 static int 10057 test_ipsec_proto_crypto_op_enq(struct crypto_testsuite_params *ts_params, 10058 struct crypto_unittest_params *ut_params, 10059 struct rte_security_ipsec_xform *ipsec_xform, 10060 const struct ipsec_test_data *td, 10061 const struct ipsec_test_flags *flags, 10062 int pkt_num) 10063 { 10064 uint8_t dev_id = ts_params->valid_devs[0]; 10065 enum rte_security_ipsec_sa_direction dir; 10066 int ret; 10067 10068 dir = ipsec_xform->direction; 10069 10070 /* Generate crypto op data structure */ 10071 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10072 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10073 if (!ut_params->op) { 10074 printf("Could not allocate crypto op"); 10075 return TEST_FAILED; 10076 } 10077 10078 /* Attach session to operation */ 10079 rte_security_attach_session(ut_params->op, ut_params->sec_session); 10080 10081 /* Set crypto operation mbufs */ 10082 ut_params->op->sym->m_src = ut_params->ibuf; 10083 ut_params->op->sym->m_dst = NULL; 10084 10085 /* Copy IV in crypto operation when IV generation is disabled */ 10086 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS && 10087 ipsec_xform->options.iv_gen_disable == 1) { 10088 uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op, 10089 uint8_t *, 10090 IV_OFFSET); 10091 int len; 10092 10093 if (td->aead) 10094 len = td->xform.aead.aead.iv.length; 10095 else if (td->aes_gmac) 10096 len = td->xform.chain.auth.auth.iv.length; 10097 else 10098 len = td->xform.chain.cipher.cipher.iv.length; 10099 10100 memcpy(iv, td->iv.data, len); 10101 } 10102 10103 /* Process crypto operation */ 10104 process_crypto_request(dev_id, ut_params->op); 10105 10106 ret = test_ipsec_status_check(td, ut_params->op, flags, dir, pkt_num); 10107 10108 rte_crypto_op_free(ut_params->op); 10109 ut_params->op = NULL; 10110 10111 return ret; 10112 } 10113 10114 static int 10115 test_ipsec_proto_mbuf_enq(struct crypto_testsuite_params *ts_params, 10116 struct crypto_unittest_params *ut_params, 10117 void *ctx) 10118 { 10119 uint64_t timeout, userdata; 10120 struct rte_ether_hdr *hdr; 10121 struct rte_mbuf *m; 10122 void **sec_sess; 10123 int ret; 10124 10125 RTE_SET_USED(ts_params); 10126 10127 hdr = (void *)rte_pktmbuf_prepend(ut_params->ibuf, sizeof(struct rte_ether_hdr)); 10128 hdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4); 10129 10130 ut_params->ibuf->l2_len = sizeof(struct rte_ether_hdr); 10131 ut_params->ibuf->port = 0; 10132 10133 sec_sess = &ut_params->sec_session; 10134 ret = rte_security_inb_pkt_rx_inject(ctx, &ut_params->ibuf, sec_sess, 1); 10135 10136 if (ret != 1) 10137 return TEST_FAILED; 10138 10139 ut_params->ibuf = NULL; 10140 10141 /* Add a timeout for 1 s */ 10142 timeout = rte_get_tsc_cycles() + rte_get_tsc_hz(); 10143 10144 do { 10145 /* Get packet from port 0, queue 0 */ 10146 ret = rte_eth_rx_burst(0, 0, &m, 1); 10147 } while ((ret == 0) && (rte_get_tsc_cycles() < timeout)); 10148 10149 if (ret == 0) { 10150 printf("Could not receive packets from ethdev\n"); 10151 return TEST_FAILED; 10152 } 10153 10154 if (m == NULL) { 10155 printf("Received mbuf is NULL\n"); 10156 return TEST_FAILED; 10157 } 10158 10159 ut_params->ibuf = m; 10160 10161 if (!(m->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD)) { 10162 printf("Received packet is not Rx security processed\n"); 10163 return TEST_FAILED; 10164 } 10165 10166 if (m->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED) { 10167 printf("Received packet has failed Rx security processing\n"); 10168 return TEST_FAILED; 10169 } 10170 10171 /* 10172 * 'ut_params' is set as userdata. Verify that the field is returned 10173 * correctly. 10174 */ 10175 userdata = *(uint64_t *)rte_security_dynfield(m); 10176 if (userdata != (uint64_t)ut_params) { 10177 printf("Userdata retrieved not matching expected\n"); 10178 return TEST_FAILED; 10179 } 10180 10181 /* Trim L2 header */ 10182 rte_pktmbuf_adj(m, sizeof(struct rte_ether_hdr)); 10183 10184 return TEST_SUCCESS; 10185 } 10186 10187 static int 10188 test_ipsec_proto_process(const struct ipsec_test_data td[], 10189 struct ipsec_test_data res_d[], 10190 int nb_td, 10191 bool silent, 10192 const struct ipsec_test_flags *flags) 10193 { 10194 uint16_t v6_src[8] = {0x2607, 0xf8b0, 0x400c, 0x0c03, 0x0000, 0x0000, 10195 0x0000, 0x001a}; 10196 uint16_t v6_dst[8] = {0x2001, 0x0470, 0xe5bf, 0xdead, 0x4957, 0x2174, 10197 0xe82c, 0x4887}; 10198 const struct rte_ipv4_hdr *ipv4 = 10199 (const struct rte_ipv4_hdr *)td[0].output_text.data; 10200 int nb_segs = flags->nb_segs_in_mbuf ? flags->nb_segs_in_mbuf : 1; 10201 struct crypto_testsuite_params *ts_params = &testsuite_params; 10202 struct crypto_unittest_params *ut_params = &unittest_params; 10203 struct rte_security_capability_idx sec_cap_idx; 10204 const struct rte_security_capability *sec_cap; 10205 struct rte_security_ipsec_xform ipsec_xform; 10206 uint8_t dev_id = ts_params->valid_devs[0]; 10207 enum rte_security_ipsec_sa_direction dir; 10208 struct ipsec_test_data *res_d_tmp = NULL; 10209 uint8_t input_text[IPSEC_TEXT_MAX_LEN]; 10210 int salt_len, i, ret = TEST_SUCCESS; 10211 void *ctx; 10212 uint32_t src, dst; 10213 uint32_t verify; 10214 10215 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 10216 gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 10217 10218 /* Use first test data to create session */ 10219 10220 /* Copy IPsec xform */ 10221 memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform)); 10222 10223 dir = ipsec_xform.direction; 10224 verify = flags->tunnel_hdr_verify; 10225 10226 memcpy(&src, &ipv4->src_addr, sizeof(ipv4->src_addr)); 10227 memcpy(&dst, &ipv4->dst_addr, sizeof(ipv4->dst_addr)); 10228 10229 if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) { 10230 if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR) 10231 src += 1; 10232 else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR) 10233 dst += 1; 10234 } 10235 10236 if (td->ipsec_xform.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) { 10237 if (td->ipsec_xform.tunnel.type == 10238 RTE_SECURITY_IPSEC_TUNNEL_IPV4) { 10239 memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, 10240 sizeof(src)); 10241 memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, 10242 sizeof(dst)); 10243 10244 if (flags->df == TEST_IPSEC_SET_DF_0_INNER_1) 10245 ipsec_xform.tunnel.ipv4.df = 0; 10246 10247 if (flags->df == TEST_IPSEC_SET_DF_1_INNER_0) 10248 ipsec_xform.tunnel.ipv4.df = 1; 10249 10250 if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1) 10251 ipsec_xform.tunnel.ipv4.dscp = 0; 10252 10253 if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0) 10254 ipsec_xform.tunnel.ipv4.dscp = 10255 TEST_IPSEC_DSCP_VAL; 10256 10257 } else { 10258 if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1) 10259 ipsec_xform.tunnel.ipv6.dscp = 0; 10260 10261 if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0) 10262 ipsec_xform.tunnel.ipv6.dscp = 10263 TEST_IPSEC_DSCP_VAL; 10264 10265 memcpy(&ipsec_xform.tunnel.ipv6.src_addr, &v6_src, 10266 sizeof(v6_src)); 10267 memcpy(&ipsec_xform.tunnel.ipv6.dst_addr, &v6_dst, 10268 sizeof(v6_dst)); 10269 } 10270 } 10271 10272 ctx = rte_cryptodev_get_sec_ctx(dev_id); 10273 10274 sec_cap_idx.action = ut_params->type; 10275 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC; 10276 sec_cap_idx.ipsec.proto = ipsec_xform.proto; 10277 sec_cap_idx.ipsec.mode = ipsec_xform.mode; 10278 sec_cap_idx.ipsec.direction = ipsec_xform.direction; 10279 10280 if (flags->udp_encap) 10281 ipsec_xform.options.udp_encap = 1; 10282 10283 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 10284 if (sec_cap == NULL) 10285 return TEST_SKIPPED; 10286 10287 /* Copy cipher session parameters */ 10288 if (td[0].aead) { 10289 memcpy(&ut_params->aead_xform, &td[0].xform.aead, 10290 sizeof(ut_params->aead_xform)); 10291 ut_params->aead_xform.aead.key.data = td[0].key.data; 10292 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 10293 10294 /* Verify crypto capabilities */ 10295 if (test_sec_crypto_caps_aead_verify(sec_cap, &ut_params->aead_xform) != 0) { 10296 if (!silent) 10297 RTE_LOG(INFO, USER1, 10298 "Crypto capabilities not supported\n"); 10299 return TEST_SKIPPED; 10300 } 10301 } else if (td[0].auth_only) { 10302 memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth, 10303 sizeof(ut_params->auth_xform)); 10304 ut_params->auth_xform.auth.key.data = td[0].auth_key.data; 10305 10306 if (test_sec_crypto_caps_auth_verify(sec_cap, &ut_params->auth_xform) != 0) { 10307 if (!silent) 10308 RTE_LOG(INFO, USER1, 10309 "Auth crypto capabilities not supported\n"); 10310 return TEST_SKIPPED; 10311 } 10312 } else { 10313 memcpy(&ut_params->cipher_xform, &td[0].xform.chain.cipher, 10314 sizeof(ut_params->cipher_xform)); 10315 memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth, 10316 sizeof(ut_params->auth_xform)); 10317 ut_params->cipher_xform.cipher.key.data = td[0].key.data; 10318 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 10319 ut_params->auth_xform.auth.key.data = td[0].auth_key.data; 10320 10321 /* Verify crypto capabilities */ 10322 10323 if (test_sec_crypto_caps_cipher_verify(sec_cap, &ut_params->cipher_xform) != 0) { 10324 if (!silent) 10325 RTE_LOG(INFO, USER1, 10326 "Cipher crypto capabilities not supported\n"); 10327 return TEST_SKIPPED; 10328 } 10329 10330 if (test_sec_crypto_caps_auth_verify(sec_cap, &ut_params->auth_xform) != 0) { 10331 if (!silent) 10332 RTE_LOG(INFO, USER1, 10333 "Auth crypto capabilities not supported\n"); 10334 return TEST_SKIPPED; 10335 } 10336 } 10337 10338 if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0) 10339 return TEST_SKIPPED; 10340 10341 struct rte_security_session_conf sess_conf = { 10342 .action_type = ut_params->type, 10343 .protocol = RTE_SECURITY_PROTOCOL_IPSEC, 10344 }; 10345 10346 if (td[0].aead || td[0].aes_gmac) { 10347 salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len); 10348 memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len); 10349 } 10350 10351 if (td[0].aead) { 10352 sess_conf.ipsec = ipsec_xform; 10353 sess_conf.crypto_xform = &ut_params->aead_xform; 10354 } else if (td[0].auth_only) { 10355 sess_conf.ipsec = ipsec_xform; 10356 sess_conf.crypto_xform = &ut_params->auth_xform; 10357 } else { 10358 sess_conf.ipsec = ipsec_xform; 10359 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) { 10360 sess_conf.crypto_xform = &ut_params->cipher_xform; 10361 ut_params->cipher_xform.next = &ut_params->auth_xform; 10362 } else { 10363 sess_conf.crypto_xform = &ut_params->auth_xform; 10364 ut_params->auth_xform.next = &ut_params->cipher_xform; 10365 } 10366 } 10367 10368 if (dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS && flags->rx_inject) 10369 sess_conf.userdata = ut_params; 10370 10371 /* Create security session */ 10372 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 10373 ts_params->session_mpool); 10374 10375 if (ut_params->sec_session == NULL) 10376 return TEST_SKIPPED; 10377 10378 for (i = 0; i < nb_td; i++) { 10379 if (flags->antireplay && 10380 (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)) { 10381 sess_conf.ipsec.esn.value = td[i].ipsec_xform.esn.value; 10382 ret = rte_security_session_update(ctx, 10383 ut_params->sec_session, &sess_conf); 10384 if (ret) { 10385 printf("Could not update sequence number in " 10386 "session\n"); 10387 return TEST_SKIPPED; 10388 } 10389 } 10390 10391 /* Copy test data before modification */ 10392 memcpy(input_text, td[i].input_text.data, td[i].input_text.len); 10393 if (test_ipsec_pkt_update(input_text, flags)) { 10394 ret = TEST_FAILED; 10395 goto mbuf_free; 10396 } 10397 10398 /* Setup source mbuf payload */ 10399 if (flags->use_ext_mbuf) { 10400 ut_params->ibuf = ext_mbuf_create(ts_params->mbuf_pool, 10401 td[i].input_text.len, nb_segs, input_text); 10402 } else { 10403 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 10404 td[i].input_text.len, nb_segs, 0); 10405 pktmbuf_write(ut_params->ibuf, 0, td[i].input_text.len, input_text); 10406 } 10407 10408 if (dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS && flags->rx_inject) 10409 ret = test_ipsec_proto_mbuf_enq(ts_params, ut_params, 10410 ctx); 10411 else 10412 ret = test_ipsec_proto_crypto_op_enq(ts_params, 10413 ut_params, 10414 &ipsec_xform, 10415 &td[i], flags, 10416 i + 1); 10417 10418 if (ret != TEST_SUCCESS) 10419 goto mbuf_free; 10420 10421 if (res_d != NULL) 10422 res_d_tmp = &res_d[i]; 10423 10424 ret = test_ipsec_post_process(ut_params->ibuf, &td[i], 10425 res_d_tmp, silent, flags); 10426 if (ret != TEST_SUCCESS) 10427 goto mbuf_free; 10428 10429 ret = test_ipsec_stats_verify(ctx, ut_params->sec_session, 10430 flags, dir); 10431 if (ret != TEST_SUCCESS) 10432 goto mbuf_free; 10433 10434 rte_pktmbuf_free(ut_params->ibuf); 10435 ut_params->ibuf = NULL; 10436 } 10437 10438 mbuf_free: 10439 if (flags->use_ext_mbuf) 10440 ext_mbuf_memzone_free(nb_segs); 10441 10442 rte_pktmbuf_free(ut_params->ibuf); 10443 ut_params->ibuf = NULL; 10444 10445 if (ut_params->sec_session) 10446 rte_security_session_destroy(ctx, ut_params->sec_session); 10447 ut_params->sec_session = NULL; 10448 10449 return ret; 10450 } 10451 10452 static int 10453 test_ipsec_proto_known_vec(const void *test_data) 10454 { 10455 struct ipsec_test_data td_outb; 10456 struct ipsec_test_flags flags; 10457 10458 memset(&flags, 0, sizeof(flags)); 10459 10460 memcpy(&td_outb, test_data, sizeof(td_outb)); 10461 10462 if (td_outb.aes_gmac || td_outb.aead || 10463 ((td_outb.ipsec_xform.proto != RTE_SECURITY_IPSEC_SA_PROTO_AH) && 10464 (td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL))) { 10465 /* Disable IV gen to be able to test with known vectors */ 10466 td_outb.ipsec_xform.options.iv_gen_disable = 1; 10467 } 10468 10469 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 10470 } 10471 10472 static int 10473 test_ipsec_proto_known_vec_ext_mbuf(const void *test_data) 10474 { 10475 struct ipsec_test_data td_outb; 10476 struct ipsec_test_flags flags; 10477 10478 memset(&flags, 0, sizeof(flags)); 10479 flags.use_ext_mbuf = true; 10480 10481 memcpy(&td_outb, test_data, sizeof(td_outb)); 10482 10483 if (td_outb.aes_gmac || td_outb.aead || 10484 ((td_outb.ipsec_xform.proto != RTE_SECURITY_IPSEC_SA_PROTO_AH) && 10485 (td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL))) { 10486 /* Disable IV gen to be able to test with known vectors */ 10487 td_outb.ipsec_xform.options.iv_gen_disable = 1; 10488 } 10489 10490 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 10491 } 10492 10493 static int 10494 test_ipsec_proto_known_vec_inb(const void *test_data) 10495 { 10496 const struct ipsec_test_data *td = test_data; 10497 struct ipsec_test_flags flags; 10498 struct ipsec_test_data td_inb; 10499 10500 memset(&flags, 0, sizeof(flags)); 10501 10502 if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) 10503 test_ipsec_td_in_from_out(td, &td_inb); 10504 else 10505 memcpy(&td_inb, td, sizeof(td_inb)); 10506 10507 return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags); 10508 } 10509 10510 static int 10511 test_ipsec_proto_known_vec_fragmented(const void *test_data) 10512 { 10513 struct ipsec_test_data td_outb; 10514 struct ipsec_test_flags flags; 10515 10516 memset(&flags, 0, sizeof(flags)); 10517 flags.fragment = true; 10518 10519 memcpy(&td_outb, test_data, sizeof(td_outb)); 10520 10521 /* Disable IV gen to be able to test with known vectors */ 10522 td_outb.ipsec_xform.options.iv_gen_disable = 1; 10523 10524 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 10525 } 10526 10527 static int 10528 test_ipsec_proto_known_vec_inb_rx_inject(const void *test_data) 10529 { 10530 const struct ipsec_test_data *td = test_data; 10531 struct ipsec_test_flags flags; 10532 struct ipsec_test_data td_inb; 10533 10534 memset(&flags, 0, sizeof(flags)); 10535 flags.rx_inject = true; 10536 10537 if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) 10538 test_ipsec_td_in_from_out(td, &td_inb); 10539 else 10540 memcpy(&td_inb, td, sizeof(td_inb)); 10541 10542 return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags); 10543 } 10544 10545 static int 10546 test_ipsec_proto_all(const struct ipsec_test_flags *flags) 10547 { 10548 struct ipsec_test_data td_outb[TEST_SEC_PKTS_MAX]; 10549 struct ipsec_test_data td_inb[TEST_SEC_PKTS_MAX]; 10550 unsigned int i, nb_pkts = 1, pass_cnt = 0; 10551 int ret; 10552 10553 if (flags->iv_gen || 10554 flags->sa_expiry_pkts_soft || 10555 flags->sa_expiry_pkts_hard) 10556 nb_pkts = TEST_SEC_PKTS_MAX; 10557 10558 for (i = 0; i < RTE_DIM(sec_alg_list); i++) { 10559 test_ipsec_td_prepare(sec_alg_list[i].param1, 10560 sec_alg_list[i].param2, 10561 flags, 10562 td_outb, 10563 nb_pkts); 10564 10565 if (!td_outb->aead) { 10566 enum rte_crypto_cipher_algorithm cipher_alg; 10567 enum rte_crypto_auth_algorithm auth_alg; 10568 10569 cipher_alg = td_outb->xform.chain.cipher.cipher.algo; 10570 auth_alg = td_outb->xform.chain.auth.auth.algo; 10571 10572 if (td_outb->aes_gmac && cipher_alg != RTE_CRYPTO_CIPHER_NULL) 10573 continue; 10574 10575 /* ICV is not applicable for NULL auth */ 10576 if (flags->icv_corrupt && 10577 auth_alg == RTE_CRYPTO_AUTH_NULL) 10578 continue; 10579 10580 /* IV is not applicable for NULL cipher */ 10581 if (flags->iv_gen && 10582 cipher_alg == RTE_CRYPTO_CIPHER_NULL) 10583 continue; 10584 } 10585 10586 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 10587 flags); 10588 if (ret == TEST_SKIPPED) 10589 continue; 10590 10591 if (ret == TEST_FAILED) 10592 return TEST_FAILED; 10593 10594 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags); 10595 10596 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 10597 flags); 10598 if (ret == TEST_SKIPPED) 10599 continue; 10600 10601 if (ret == TEST_FAILED) 10602 return TEST_FAILED; 10603 10604 if (flags->display_alg) 10605 test_sec_alg_display(sec_alg_list[i].param1, sec_alg_list[i].param2); 10606 10607 pass_cnt++; 10608 } 10609 10610 if (pass_cnt > 0) 10611 return TEST_SUCCESS; 10612 else 10613 return TEST_SKIPPED; 10614 } 10615 10616 static int 10617 test_ipsec_ah_proto_all(const struct ipsec_test_flags *flags) 10618 { 10619 struct ipsec_test_data td_outb[TEST_SEC_PKTS_MAX]; 10620 struct ipsec_test_data td_inb[TEST_SEC_PKTS_MAX]; 10621 unsigned int i, nb_pkts = 1, pass_cnt = 0; 10622 int ret; 10623 10624 for (i = 0; i < RTE_DIM(sec_auth_only_alg_list); i++) { 10625 test_ipsec_td_prepare(sec_auth_only_alg_list[i].param1, 10626 sec_auth_only_alg_list[i].param2, 10627 flags, 10628 td_outb, 10629 nb_pkts); 10630 10631 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 10632 flags); 10633 if (ret == TEST_SKIPPED) 10634 continue; 10635 10636 if (ret == TEST_FAILED) 10637 return TEST_FAILED; 10638 10639 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags); 10640 10641 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 10642 flags); 10643 if (ret == TEST_SKIPPED) 10644 continue; 10645 10646 if (ret == TEST_FAILED) 10647 return TEST_FAILED; 10648 10649 if (flags->display_alg) 10650 test_sec_alg_display(sec_auth_only_alg_list[i].param1, 10651 sec_auth_only_alg_list[i].param2); 10652 10653 pass_cnt++; 10654 } 10655 10656 if (pass_cnt > 0) 10657 return TEST_SUCCESS; 10658 else 10659 return TEST_SKIPPED; 10660 } 10661 10662 static int 10663 test_ipsec_proto_display_list(void) 10664 { 10665 struct ipsec_test_flags flags; 10666 10667 memset(&flags, 0, sizeof(flags)); 10668 10669 flags.display_alg = true; 10670 10671 return test_ipsec_proto_all(&flags); 10672 } 10673 10674 static int 10675 test_ipsec_proto_ah_tunnel_ipv4(void) 10676 { 10677 struct ipsec_test_flags flags; 10678 10679 memset(&flags, 0, sizeof(flags)); 10680 10681 flags.ah = true; 10682 flags.display_alg = true; 10683 10684 return test_ipsec_ah_proto_all(&flags); 10685 } 10686 10687 static int 10688 test_ipsec_proto_ah_transport_ipv4(void) 10689 { 10690 struct ipsec_test_flags flags; 10691 10692 memset(&flags, 0, sizeof(flags)); 10693 10694 flags.ah = true; 10695 flags.transport = true; 10696 10697 return test_ipsec_ah_proto_all(&flags); 10698 } 10699 10700 static int 10701 test_ipsec_proto_iv_gen(void) 10702 { 10703 struct ipsec_test_flags flags; 10704 10705 memset(&flags, 0, sizeof(flags)); 10706 10707 flags.iv_gen = true; 10708 10709 return test_ipsec_proto_all(&flags); 10710 } 10711 10712 static int 10713 test_ipsec_proto_sa_exp_pkts_soft(void) 10714 { 10715 struct ipsec_test_flags flags; 10716 10717 memset(&flags, 0, sizeof(flags)); 10718 10719 flags.sa_expiry_pkts_soft = true; 10720 10721 return test_ipsec_proto_all(&flags); 10722 } 10723 10724 static int 10725 test_ipsec_proto_sa_exp_pkts_hard(void) 10726 { 10727 struct ipsec_test_flags flags; 10728 10729 memset(&flags, 0, sizeof(flags)); 10730 10731 flags.sa_expiry_pkts_hard = true; 10732 10733 return test_ipsec_proto_all(&flags); 10734 } 10735 10736 static int 10737 test_ipsec_proto_err_icv_corrupt(void) 10738 { 10739 struct ipsec_test_flags flags; 10740 10741 memset(&flags, 0, sizeof(flags)); 10742 10743 flags.icv_corrupt = true; 10744 10745 return test_ipsec_proto_all(&flags); 10746 } 10747 10748 static int 10749 test_ipsec_proto_udp_encap_custom_ports(void) 10750 { 10751 struct ipsec_test_flags flags; 10752 10753 if (gbl_driver_id == rte_cryptodev_driver_id_get( 10754 RTE_STR(CRYPTODEV_NAME_CN10K_PMD))) 10755 return TEST_SKIPPED; 10756 10757 memset(&flags, 0, sizeof(flags)); 10758 10759 flags.udp_encap = true; 10760 flags.udp_encap_custom_ports = true; 10761 10762 return test_ipsec_proto_all(&flags); 10763 } 10764 10765 static int 10766 test_ipsec_proto_udp_encap(void) 10767 { 10768 struct ipsec_test_flags flags; 10769 10770 memset(&flags, 0, sizeof(flags)); 10771 10772 flags.udp_encap = true; 10773 10774 return test_ipsec_proto_all(&flags); 10775 } 10776 10777 static int 10778 test_ipsec_proto_tunnel_src_dst_addr_verify(void) 10779 { 10780 struct ipsec_test_flags flags; 10781 10782 memset(&flags, 0, sizeof(flags)); 10783 10784 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR; 10785 10786 return test_ipsec_proto_all(&flags); 10787 } 10788 10789 static int 10790 test_ipsec_proto_tunnel_dst_addr_verify(void) 10791 { 10792 struct ipsec_test_flags flags; 10793 10794 memset(&flags, 0, sizeof(flags)); 10795 10796 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR; 10797 10798 return test_ipsec_proto_all(&flags); 10799 } 10800 10801 static int 10802 test_ipsec_proto_udp_ports_verify(void) 10803 { 10804 struct ipsec_test_flags flags; 10805 10806 memset(&flags, 0, sizeof(flags)); 10807 10808 flags.udp_encap = true; 10809 flags.udp_ports_verify = true; 10810 10811 return test_ipsec_proto_all(&flags); 10812 } 10813 10814 static int 10815 test_ipsec_proto_inner_ip_csum(void) 10816 { 10817 struct ipsec_test_flags flags; 10818 10819 memset(&flags, 0, sizeof(flags)); 10820 10821 flags.ip_csum = true; 10822 10823 return test_ipsec_proto_all(&flags); 10824 } 10825 10826 static int 10827 test_ipsec_proto_inner_l4_csum(void) 10828 { 10829 struct ipsec_test_flags flags; 10830 10831 memset(&flags, 0, sizeof(flags)); 10832 10833 flags.l4_csum = true; 10834 10835 return test_ipsec_proto_all(&flags); 10836 } 10837 10838 static int 10839 test_ipsec_proto_tunnel_v4_in_v4(void) 10840 { 10841 struct ipsec_test_flags flags; 10842 10843 memset(&flags, 0, sizeof(flags)); 10844 10845 flags.ipv6 = false; 10846 flags.tunnel_ipv6 = false; 10847 10848 return test_ipsec_proto_all(&flags); 10849 } 10850 10851 static int 10852 test_ipsec_proto_tunnel_v6_in_v6(void) 10853 { 10854 struct ipsec_test_flags flags; 10855 10856 memset(&flags, 0, sizeof(flags)); 10857 10858 flags.ipv6 = true; 10859 flags.tunnel_ipv6 = true; 10860 10861 return test_ipsec_proto_all(&flags); 10862 } 10863 10864 static int 10865 test_ipsec_proto_tunnel_v4_in_v6(void) 10866 { 10867 struct ipsec_test_flags flags; 10868 10869 memset(&flags, 0, sizeof(flags)); 10870 10871 flags.ipv6 = false; 10872 flags.tunnel_ipv6 = true; 10873 10874 return test_ipsec_proto_all(&flags); 10875 } 10876 10877 static int 10878 test_ipsec_proto_tunnel_v6_in_v4(void) 10879 { 10880 struct ipsec_test_flags flags; 10881 10882 memset(&flags, 0, sizeof(flags)); 10883 10884 flags.ipv6 = true; 10885 flags.tunnel_ipv6 = false; 10886 10887 return test_ipsec_proto_all(&flags); 10888 } 10889 10890 static int 10891 test_ipsec_proto_transport_v4(void) 10892 { 10893 struct ipsec_test_flags flags; 10894 10895 memset(&flags, 0, sizeof(flags)); 10896 10897 flags.ipv6 = false; 10898 flags.transport = true; 10899 10900 return test_ipsec_proto_all(&flags); 10901 } 10902 10903 static int 10904 test_ipsec_proto_transport_l4_csum(void) 10905 { 10906 struct ipsec_test_flags flags = { 10907 .l4_csum = true, 10908 .transport = true, 10909 }; 10910 10911 return test_ipsec_proto_all(&flags); 10912 } 10913 10914 static int 10915 test_ipsec_proto_stats(void) 10916 { 10917 struct ipsec_test_flags flags; 10918 10919 memset(&flags, 0, sizeof(flags)); 10920 10921 flags.stats_success = true; 10922 10923 return test_ipsec_proto_all(&flags); 10924 } 10925 10926 static int 10927 test_ipsec_proto_pkt_fragment(void) 10928 { 10929 struct ipsec_test_flags flags; 10930 10931 memset(&flags, 0, sizeof(flags)); 10932 10933 flags.fragment = true; 10934 10935 return test_ipsec_proto_all(&flags); 10936 10937 } 10938 10939 static int 10940 test_ipsec_proto_copy_df_inner_0(void) 10941 { 10942 struct ipsec_test_flags flags; 10943 10944 memset(&flags, 0, sizeof(flags)); 10945 10946 flags.df = TEST_IPSEC_COPY_DF_INNER_0; 10947 10948 return test_ipsec_proto_all(&flags); 10949 } 10950 10951 static int 10952 test_ipsec_proto_copy_df_inner_1(void) 10953 { 10954 struct ipsec_test_flags flags; 10955 10956 memset(&flags, 0, sizeof(flags)); 10957 10958 flags.df = TEST_IPSEC_COPY_DF_INNER_1; 10959 10960 return test_ipsec_proto_all(&flags); 10961 } 10962 10963 static int 10964 test_ipsec_proto_set_df_0_inner_1(void) 10965 { 10966 struct ipsec_test_flags flags; 10967 10968 memset(&flags, 0, sizeof(flags)); 10969 10970 flags.df = TEST_IPSEC_SET_DF_0_INNER_1; 10971 10972 return test_ipsec_proto_all(&flags); 10973 } 10974 10975 static int 10976 test_ipsec_proto_set_df_1_inner_0(void) 10977 { 10978 struct ipsec_test_flags flags; 10979 10980 memset(&flags, 0, sizeof(flags)); 10981 10982 flags.df = TEST_IPSEC_SET_DF_1_INNER_0; 10983 10984 return test_ipsec_proto_all(&flags); 10985 } 10986 10987 static int 10988 test_ipsec_proto_ipv4_copy_dscp_inner_0(void) 10989 { 10990 struct ipsec_test_flags flags; 10991 10992 memset(&flags, 0, sizeof(flags)); 10993 10994 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0; 10995 10996 return test_ipsec_proto_all(&flags); 10997 } 10998 10999 static int 11000 test_ipsec_proto_ipv4_copy_dscp_inner_1(void) 11001 { 11002 struct ipsec_test_flags flags; 11003 11004 memset(&flags, 0, sizeof(flags)); 11005 11006 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1; 11007 11008 return test_ipsec_proto_all(&flags); 11009 } 11010 11011 static int 11012 test_ipsec_proto_ipv4_set_dscp_0_inner_1(void) 11013 { 11014 struct ipsec_test_flags flags; 11015 11016 if (gbl_driver_id == rte_cryptodev_driver_id_get( 11017 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 11018 return TEST_SKIPPED; 11019 11020 memset(&flags, 0, sizeof(flags)); 11021 11022 flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1; 11023 11024 return test_ipsec_proto_all(&flags); 11025 } 11026 11027 static int 11028 test_ipsec_proto_ipv4_set_dscp_1_inner_0(void) 11029 { 11030 struct ipsec_test_flags flags; 11031 11032 if (gbl_driver_id == rte_cryptodev_driver_id_get( 11033 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 11034 return TEST_SKIPPED; 11035 11036 memset(&flags, 0, sizeof(flags)); 11037 11038 flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0; 11039 11040 return test_ipsec_proto_all(&flags); 11041 } 11042 11043 static int 11044 test_ipsec_proto_ipv6_copy_dscp_inner_0(void) 11045 { 11046 struct ipsec_test_flags flags; 11047 11048 memset(&flags, 0, sizeof(flags)); 11049 11050 flags.ipv6 = true; 11051 flags.tunnel_ipv6 = true; 11052 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0; 11053 11054 return test_ipsec_proto_all(&flags); 11055 } 11056 11057 static int 11058 test_ipsec_proto_ipv6_copy_dscp_inner_1(void) 11059 { 11060 struct ipsec_test_flags flags; 11061 11062 memset(&flags, 0, sizeof(flags)); 11063 11064 flags.ipv6 = true; 11065 flags.tunnel_ipv6 = true; 11066 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1; 11067 11068 return test_ipsec_proto_all(&flags); 11069 } 11070 11071 static int 11072 test_ipsec_proto_ipv6_set_dscp_0_inner_1(void) 11073 { 11074 struct ipsec_test_flags flags; 11075 11076 if (gbl_driver_id == rte_cryptodev_driver_id_get( 11077 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 11078 return TEST_SKIPPED; 11079 11080 memset(&flags, 0, sizeof(flags)); 11081 11082 flags.ipv6 = true; 11083 flags.tunnel_ipv6 = true; 11084 flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1; 11085 11086 return test_ipsec_proto_all(&flags); 11087 } 11088 11089 static int 11090 test_ipsec_proto_ipv6_set_dscp_1_inner_0(void) 11091 { 11092 struct ipsec_test_flags flags; 11093 11094 if (gbl_driver_id == rte_cryptodev_driver_id_get( 11095 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 11096 return TEST_SKIPPED; 11097 11098 memset(&flags, 0, sizeof(flags)); 11099 11100 flags.ipv6 = true; 11101 flags.tunnel_ipv6 = true; 11102 flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0; 11103 11104 return test_ipsec_proto_all(&flags); 11105 } 11106 11107 static int 11108 test_ipsec_proto_sgl(void) 11109 { 11110 struct crypto_testsuite_params *ts_params = &testsuite_params; 11111 struct rte_cryptodev_info dev_info; 11112 11113 struct ipsec_test_flags flags = { 11114 .nb_segs_in_mbuf = 5 11115 }; 11116 11117 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11118 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 11119 printf("Device doesn't support in-place scatter-gather. " 11120 "Test Skipped.\n"); 11121 return TEST_SKIPPED; 11122 } 11123 11124 return test_ipsec_proto_all(&flags); 11125 } 11126 11127 static int 11128 test_ipsec_proto_sgl_ext_mbuf(void) 11129 { 11130 struct crypto_testsuite_params *ts_params = &testsuite_params; 11131 struct rte_cryptodev_info dev_info; 11132 11133 struct ipsec_test_flags flags = { 11134 .nb_segs_in_mbuf = 5, 11135 .use_ext_mbuf = 1 11136 }; 11137 11138 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11139 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 11140 printf("Device doesn't support in-place scatter-gather. " 11141 "Test Skipped.\n"); 11142 return TEST_SKIPPED; 11143 } 11144 11145 return test_ipsec_proto_all(&flags); 11146 } 11147 11148 static int 11149 test_ipsec_pkt_replay(const void *test_data, const uint64_t esn[], 11150 bool replayed_pkt[], uint32_t nb_pkts, bool esn_en, 11151 uint64_t winsz) 11152 { 11153 struct ipsec_test_data td_outb[TEST_SEC_PKTS_MAX]; 11154 struct ipsec_test_data td_inb[TEST_SEC_PKTS_MAX]; 11155 struct ipsec_test_flags flags; 11156 uint32_t i = 0, ret = 0; 11157 11158 if (nb_pkts == 0) 11159 return TEST_FAILED; 11160 11161 memset(&flags, 0, sizeof(flags)); 11162 flags.antireplay = true; 11163 11164 for (i = 0; i < nb_pkts; i++) { 11165 memcpy(&td_outb[i], test_data, sizeof(td_outb[i])); 11166 td_outb[i].ipsec_xform.options.iv_gen_disable = 1; 11167 td_outb[i].ipsec_xform.replay_win_sz = winsz; 11168 td_outb[i].ipsec_xform.options.esn = esn_en; 11169 } 11170 11171 for (i = 0; i < nb_pkts; i++) 11172 td_outb[i].ipsec_xform.esn.value = esn[i]; 11173 11174 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 11175 &flags); 11176 if (ret != TEST_SUCCESS) 11177 return ret; 11178 11179 test_ipsec_td_update(td_inb, td_outb, nb_pkts, &flags); 11180 11181 for (i = 0; i < nb_pkts; i++) { 11182 td_inb[i].ipsec_xform.options.esn = esn_en; 11183 /* Set antireplay flag for packets to be dropped */ 11184 td_inb[i].ar_packet = replayed_pkt[i]; 11185 } 11186 11187 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 11188 &flags); 11189 11190 return ret; 11191 } 11192 11193 static int 11194 test_ipsec_proto_pkt_antireplay(const void *test_data, uint64_t winsz) 11195 { 11196 11197 uint32_t nb_pkts = 5; 11198 bool replayed_pkt[5]; 11199 uint64_t esn[5]; 11200 11201 /* 1. Advance the TOP of the window to WS * 2 */ 11202 esn[0] = winsz * 2; 11203 /* 2. Test sequence number within the new window(WS + 1) */ 11204 esn[1] = winsz + 1; 11205 /* 3. Test sequence number less than the window BOTTOM */ 11206 esn[2] = winsz; 11207 /* 4. Test sequence number in the middle of the window */ 11208 esn[3] = winsz + (winsz / 2); 11209 /* 5. Test replay of the packet in the middle of the window */ 11210 esn[4] = winsz + (winsz / 2); 11211 11212 replayed_pkt[0] = false; 11213 replayed_pkt[1] = false; 11214 replayed_pkt[2] = true; 11215 replayed_pkt[3] = false; 11216 replayed_pkt[4] = true; 11217 11218 return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts, 11219 false, winsz); 11220 } 11221 11222 static int 11223 test_ipsec_proto_pkt_antireplay1024(const void *test_data) 11224 { 11225 return test_ipsec_proto_pkt_antireplay(test_data, 1024); 11226 } 11227 11228 static int 11229 test_ipsec_proto_pkt_antireplay2048(const void *test_data) 11230 { 11231 return test_ipsec_proto_pkt_antireplay(test_data, 2048); 11232 } 11233 11234 static int 11235 test_ipsec_proto_pkt_antireplay4096(const void *test_data) 11236 { 11237 return test_ipsec_proto_pkt_antireplay(test_data, 4096); 11238 } 11239 11240 static int 11241 test_ipsec_proto_pkt_esn_antireplay(const void *test_data, uint64_t winsz) 11242 { 11243 11244 uint32_t nb_pkts = 7; 11245 bool replayed_pkt[7]; 11246 uint64_t esn[7]; 11247 11248 /* Set the initial sequence number */ 11249 esn[0] = (uint64_t)(0xFFFFFFFF - winsz); 11250 /* 1. Advance the TOP of the window to (1<<32 + WS/2) */ 11251 esn[1] = (uint64_t)((1ULL << 32) + (winsz / 2)); 11252 /* 2. Test sequence number within new window (1<<32 + WS/2 + 1) */ 11253 esn[2] = (uint64_t)((1ULL << 32) - (winsz / 2) + 1); 11254 /* 3. Test with sequence number within window (1<<32 - 1) */ 11255 esn[3] = (uint64_t)((1ULL << 32) - 1); 11256 /* 4. Test with sequence number within window (1<<32 - 1) */ 11257 esn[4] = (uint64_t)(1ULL << 32); 11258 /* 5. Test with duplicate sequence number within 11259 * new window (1<<32 - 1) 11260 */ 11261 esn[5] = (uint64_t)((1ULL << 32) - 1); 11262 /* 6. Test with duplicate sequence number within new window (1<<32) */ 11263 esn[6] = (uint64_t)(1ULL << 32); 11264 11265 replayed_pkt[0] = false; 11266 replayed_pkt[1] = false; 11267 replayed_pkt[2] = false; 11268 replayed_pkt[3] = false; 11269 replayed_pkt[4] = false; 11270 replayed_pkt[5] = true; 11271 replayed_pkt[6] = true; 11272 11273 return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts, 11274 true, winsz); 11275 } 11276 11277 static int 11278 test_ipsec_proto_pkt_esn_antireplay1024(const void *test_data) 11279 { 11280 return test_ipsec_proto_pkt_esn_antireplay(test_data, 1024); 11281 } 11282 11283 static int 11284 test_ipsec_proto_pkt_esn_antireplay2048(const void *test_data) 11285 { 11286 return test_ipsec_proto_pkt_esn_antireplay(test_data, 2048); 11287 } 11288 11289 static int 11290 test_ipsec_proto_pkt_esn_antireplay4096(const void *test_data) 11291 { 11292 return test_ipsec_proto_pkt_esn_antireplay(test_data, 4096); 11293 } 11294 11295 static int 11296 test_PDCP_PROTO_all(void) 11297 { 11298 struct crypto_testsuite_params *ts_params = &testsuite_params; 11299 struct crypto_unittest_params *ut_params = &unittest_params; 11300 struct rte_cryptodev_info dev_info; 11301 int status; 11302 11303 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11304 uint64_t feat_flags = dev_info.feature_flags; 11305 11306 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 11307 return TEST_SKIPPED; 11308 11309 /* Set action type */ 11310 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 11311 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 11312 gbl_action_type; 11313 11314 if (security_proto_supported(ut_params->type, 11315 RTE_SECURITY_PROTOCOL_PDCP) < 0) 11316 return TEST_SKIPPED; 11317 11318 status = test_PDCP_PROTO_cplane_encap_all(); 11319 status += test_PDCP_PROTO_cplane_decap_all(); 11320 status += test_PDCP_PROTO_uplane_encap_all(); 11321 status += test_PDCP_PROTO_uplane_decap_all(); 11322 status += test_PDCP_PROTO_SGL_in_place_32B(); 11323 status += test_PDCP_PROTO_SGL_oop_32B_128B(); 11324 status += test_PDCP_PROTO_SGL_oop_32B_40B(); 11325 status += test_PDCP_PROTO_SGL_oop_128B_32B(); 11326 status += test_PDCP_SDAP_PROTO_encap_all(); 11327 status += test_PDCP_SDAP_PROTO_decap_all(); 11328 status += test_PDCP_PROTO_short_mac(); 11329 11330 if (status) 11331 return TEST_FAILED; 11332 else 11333 return TEST_SUCCESS; 11334 } 11335 11336 static int 11337 test_ipsec_proto_ipv4_ttl_decrement(void) 11338 { 11339 struct ipsec_test_flags flags = { 11340 .dec_ttl_or_hop_limit = true 11341 }; 11342 11343 return test_ipsec_proto_all(&flags); 11344 } 11345 11346 static int 11347 test_ipsec_proto_ipv6_hop_limit_decrement(void) 11348 { 11349 struct ipsec_test_flags flags = { 11350 .ipv6 = true, 11351 .dec_ttl_or_hop_limit = true 11352 }; 11353 11354 return test_ipsec_proto_all(&flags); 11355 } 11356 11357 static int 11358 test_docsis_proto_uplink(const void *data) 11359 { 11360 const struct docsis_test_data *d_td = data; 11361 struct crypto_testsuite_params *ts_params = &testsuite_params; 11362 struct crypto_unittest_params *ut_params = &unittest_params; 11363 uint8_t *plaintext = NULL; 11364 uint8_t *ciphertext = NULL; 11365 uint8_t *iv_ptr; 11366 int32_t cipher_len, crc_len; 11367 uint32_t crc_data_len; 11368 int ret = TEST_SUCCESS; 11369 11370 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 11371 11372 /* Verify the capabilities */ 11373 struct rte_security_capability_idx sec_cap_idx; 11374 const struct rte_security_capability *sec_cap; 11375 const struct rte_cryptodev_capabilities *crypto_cap; 11376 const struct rte_cryptodev_symmetric_capability *sym_cap; 11377 int j = 0; 11378 11379 /* Set action type */ 11380 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 11381 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 11382 gbl_action_type; 11383 11384 if (security_proto_supported(ut_params->type, 11385 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 11386 return TEST_SKIPPED; 11387 11388 sec_cap_idx.action = ut_params->type; 11389 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 11390 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK; 11391 11392 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 11393 if (sec_cap == NULL) 11394 return TEST_SKIPPED; 11395 11396 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 11397 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 11398 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 11399 crypto_cap->sym.xform_type == 11400 RTE_CRYPTO_SYM_XFORM_CIPHER && 11401 crypto_cap->sym.cipher.algo == 11402 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 11403 sym_cap = &crypto_cap->sym; 11404 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 11405 d_td->key.len, 11406 d_td->iv.len) == 0) 11407 break; 11408 } 11409 } 11410 11411 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 11412 return TEST_SKIPPED; 11413 11414 /* Setup source mbuf payload */ 11415 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11416 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11417 rte_pktmbuf_tailroom(ut_params->ibuf)); 11418 11419 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11420 d_td->ciphertext.len); 11421 11422 memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len); 11423 11424 /* Setup cipher session parameters */ 11425 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11426 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 11427 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 11428 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 11429 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 11430 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 11431 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 11432 ut_params->cipher_xform.next = NULL; 11433 11434 /* Setup DOCSIS session parameters */ 11435 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK; 11436 11437 struct rte_security_session_conf sess_conf = { 11438 .action_type = ut_params->type, 11439 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 11440 .docsis = ut_params->docsis_xform, 11441 .crypto_xform = &ut_params->cipher_xform, 11442 }; 11443 11444 /* Create security session */ 11445 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 11446 ts_params->session_mpool); 11447 11448 if (!ut_params->sec_session) { 11449 printf("Test function %s line %u: failed to allocate session\n", 11450 __func__, __LINE__); 11451 ret = TEST_FAILED; 11452 goto on_err; 11453 } 11454 11455 /* Generate crypto op data structure */ 11456 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11457 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11458 if (!ut_params->op) { 11459 printf("Test function %s line %u: failed to allocate symmetric " 11460 "crypto operation\n", __func__, __LINE__); 11461 ret = TEST_FAILED; 11462 goto on_err; 11463 } 11464 11465 /* Setup CRC operation parameters */ 11466 crc_len = d_td->ciphertext.no_crc == false ? 11467 (d_td->ciphertext.len - 11468 d_td->ciphertext.crc_offset - 11469 RTE_ETHER_CRC_LEN) : 11470 0; 11471 crc_len = crc_len > 0 ? crc_len : 0; 11472 crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN; 11473 ut_params->op->sym->auth.data.length = crc_len; 11474 ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset; 11475 11476 /* Setup cipher operation parameters */ 11477 cipher_len = d_td->ciphertext.no_cipher == false ? 11478 (d_td->ciphertext.len - 11479 d_td->ciphertext.cipher_offset) : 11480 0; 11481 cipher_len = cipher_len > 0 ? cipher_len : 0; 11482 ut_params->op->sym->cipher.data.length = cipher_len; 11483 ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset; 11484 11485 /* Setup cipher IV */ 11486 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 11487 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 11488 11489 /* Attach session to operation */ 11490 rte_security_attach_session(ut_params->op, ut_params->sec_session); 11491 11492 /* Set crypto operation mbufs */ 11493 ut_params->op->sym->m_src = ut_params->ibuf; 11494 ut_params->op->sym->m_dst = NULL; 11495 11496 /* Process crypto operation */ 11497 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 11498 NULL) { 11499 printf("Test function %s line %u: failed to process security " 11500 "crypto op\n", __func__, __LINE__); 11501 ret = TEST_FAILED; 11502 goto on_err; 11503 } 11504 11505 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 11506 printf("Test function %s line %u: failed to process crypto op\n", 11507 __func__, __LINE__); 11508 ret = TEST_FAILED; 11509 goto on_err; 11510 } 11511 11512 /* Validate plaintext */ 11513 plaintext = ciphertext; 11514 11515 if (memcmp(plaintext, d_td->plaintext.data, 11516 d_td->plaintext.len - crc_data_len)) { 11517 printf("Test function %s line %u: plaintext not as expected\n", 11518 __func__, __LINE__); 11519 rte_hexdump(stdout, "expected", d_td->plaintext.data, 11520 d_td->plaintext.len); 11521 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len); 11522 ret = TEST_FAILED; 11523 goto on_err; 11524 } 11525 11526 on_err: 11527 rte_crypto_op_free(ut_params->op); 11528 ut_params->op = NULL; 11529 11530 if (ut_params->sec_session) 11531 rte_security_session_destroy(ctx, ut_params->sec_session); 11532 ut_params->sec_session = NULL; 11533 11534 rte_pktmbuf_free(ut_params->ibuf); 11535 ut_params->ibuf = NULL; 11536 11537 return ret; 11538 } 11539 11540 static int 11541 test_docsis_proto_downlink(const void *data) 11542 { 11543 const struct docsis_test_data *d_td = data; 11544 struct crypto_testsuite_params *ts_params = &testsuite_params; 11545 struct crypto_unittest_params *ut_params = &unittest_params; 11546 uint8_t *plaintext = NULL; 11547 uint8_t *ciphertext = NULL; 11548 uint8_t *iv_ptr; 11549 int32_t cipher_len, crc_len; 11550 int ret = TEST_SUCCESS; 11551 11552 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 11553 11554 /* Verify the capabilities */ 11555 struct rte_security_capability_idx sec_cap_idx; 11556 const struct rte_security_capability *sec_cap; 11557 const struct rte_cryptodev_capabilities *crypto_cap; 11558 const struct rte_cryptodev_symmetric_capability *sym_cap; 11559 int j = 0; 11560 11561 /* Set action type */ 11562 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 11563 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 11564 gbl_action_type; 11565 11566 if (security_proto_supported(ut_params->type, 11567 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 11568 return TEST_SKIPPED; 11569 11570 sec_cap_idx.action = ut_params->type; 11571 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 11572 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 11573 11574 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 11575 if (sec_cap == NULL) 11576 return TEST_SKIPPED; 11577 11578 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 11579 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 11580 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 11581 crypto_cap->sym.xform_type == 11582 RTE_CRYPTO_SYM_XFORM_CIPHER && 11583 crypto_cap->sym.cipher.algo == 11584 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 11585 sym_cap = &crypto_cap->sym; 11586 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 11587 d_td->key.len, 11588 d_td->iv.len) == 0) 11589 break; 11590 } 11591 } 11592 11593 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 11594 return TEST_SKIPPED; 11595 11596 /* Setup source mbuf payload */ 11597 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11598 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11599 rte_pktmbuf_tailroom(ut_params->ibuf)); 11600 11601 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11602 d_td->plaintext.len); 11603 11604 memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len); 11605 11606 /* Setup cipher session parameters */ 11607 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11608 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 11609 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 11610 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 11611 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 11612 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 11613 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 11614 ut_params->cipher_xform.next = NULL; 11615 11616 /* Setup DOCSIS session parameters */ 11617 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 11618 11619 struct rte_security_session_conf sess_conf = { 11620 .action_type = ut_params->type, 11621 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 11622 .docsis = ut_params->docsis_xform, 11623 .crypto_xform = &ut_params->cipher_xform, 11624 }; 11625 11626 /* Create security session */ 11627 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 11628 ts_params->session_mpool); 11629 11630 if (!ut_params->sec_session) { 11631 printf("Test function %s line %u: failed to allocate session\n", 11632 __func__, __LINE__); 11633 ret = TEST_FAILED; 11634 goto on_err; 11635 } 11636 11637 /* Generate crypto op data structure */ 11638 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11639 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11640 if (!ut_params->op) { 11641 printf("Test function %s line %u: failed to allocate symmetric " 11642 "crypto operation\n", __func__, __LINE__); 11643 ret = TEST_FAILED; 11644 goto on_err; 11645 } 11646 11647 /* Setup CRC operation parameters */ 11648 crc_len = d_td->plaintext.no_crc == false ? 11649 (d_td->plaintext.len - 11650 d_td->plaintext.crc_offset - 11651 RTE_ETHER_CRC_LEN) : 11652 0; 11653 crc_len = crc_len > 0 ? crc_len : 0; 11654 ut_params->op->sym->auth.data.length = crc_len; 11655 ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset; 11656 11657 /* Setup cipher operation parameters */ 11658 cipher_len = d_td->plaintext.no_cipher == false ? 11659 (d_td->plaintext.len - 11660 d_td->plaintext.cipher_offset) : 11661 0; 11662 cipher_len = cipher_len > 0 ? cipher_len : 0; 11663 ut_params->op->sym->cipher.data.length = cipher_len; 11664 ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset; 11665 11666 /* Setup cipher IV */ 11667 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 11668 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 11669 11670 /* Attach session to operation */ 11671 rte_security_attach_session(ut_params->op, ut_params->sec_session); 11672 11673 /* Set crypto operation mbufs */ 11674 ut_params->op->sym->m_src = ut_params->ibuf; 11675 ut_params->op->sym->m_dst = NULL; 11676 11677 /* Process crypto operation */ 11678 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 11679 NULL) { 11680 printf("Test function %s line %u: failed to process crypto op\n", 11681 __func__, __LINE__); 11682 ret = TEST_FAILED; 11683 goto on_err; 11684 } 11685 11686 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 11687 printf("Test function %s line %u: crypto op processing failed\n", 11688 __func__, __LINE__); 11689 ret = TEST_FAILED; 11690 goto on_err; 11691 } 11692 11693 /* Validate ciphertext */ 11694 ciphertext = plaintext; 11695 11696 if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) { 11697 printf("Test function %s line %u: plaintext not as expected\n", 11698 __func__, __LINE__); 11699 rte_hexdump(stdout, "expected", d_td->ciphertext.data, 11700 d_td->ciphertext.len); 11701 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len); 11702 ret = TEST_FAILED; 11703 goto on_err; 11704 } 11705 11706 on_err: 11707 rte_crypto_op_free(ut_params->op); 11708 ut_params->op = NULL; 11709 11710 if (ut_params->sec_session) 11711 rte_security_session_destroy(ctx, ut_params->sec_session); 11712 ut_params->sec_session = NULL; 11713 11714 rte_pktmbuf_free(ut_params->ibuf); 11715 ut_params->ibuf = NULL; 11716 11717 return ret; 11718 } 11719 11720 static void 11721 test_tls_record_imp_nonce_update(const struct tls_record_test_data *td, 11722 struct rte_security_tls_record_xform *tls_record_xform) 11723 { 11724 unsigned int imp_nonce_len; 11725 uint8_t *imp_nonce; 11726 11727 switch (tls_record_xform->ver) { 11728 case RTE_SECURITY_VERSION_TLS_1_2: 11729 imp_nonce_len = RTE_SECURITY_TLS_1_2_IMP_NONCE_LEN; 11730 imp_nonce = tls_record_xform->tls_1_2.imp_nonce; 11731 break; 11732 case RTE_SECURITY_VERSION_DTLS_1_2: 11733 imp_nonce_len = RTE_SECURITY_DTLS_1_2_IMP_NONCE_LEN; 11734 imp_nonce = tls_record_xform->dtls_1_2.imp_nonce; 11735 break; 11736 case RTE_SECURITY_VERSION_TLS_1_3: 11737 imp_nonce_len = RTE_SECURITY_TLS_1_3_IMP_NONCE_LEN; 11738 imp_nonce = tls_record_xform->tls_1_3.imp_nonce; 11739 break; 11740 default: 11741 return; 11742 } 11743 11744 imp_nonce_len = RTE_MIN(imp_nonce_len, td[0].imp_nonce.len); 11745 memcpy(imp_nonce, td[0].imp_nonce.data, imp_nonce_len); 11746 } 11747 11748 static int 11749 test_tls_record_proto_process(const struct tls_record_test_data td[], 11750 struct tls_record_test_data res_d[], int nb_td, bool silent, 11751 const struct tls_record_test_flags *flags) 11752 { 11753 int nb_segs = flags->nb_segs_in_mbuf ? flags->nb_segs_in_mbuf : 1; 11754 struct crypto_testsuite_params *ts_params = &testsuite_params; 11755 struct crypto_unittest_params *ut_params = &unittest_params; 11756 struct rte_security_tls_record_xform tls_record_xform; 11757 struct rte_security_capability_idx sec_cap_idx; 11758 const struct rte_security_capability *sec_cap; 11759 struct tls_record_test_data *res_d_tmp = NULL; 11760 enum rte_security_tls_sess_type sess_type; 11761 uint8_t dev_id = ts_params->valid_devs[0]; 11762 struct rte_security_ctx *ctx; 11763 int i, ret = TEST_SUCCESS; 11764 11765 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 11766 gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 11767 11768 /* Use first test data to create session */ 11769 11770 /* Copy TLS record xform */ 11771 memcpy(&tls_record_xform, &td[0].tls_record_xform, sizeof(tls_record_xform)); 11772 11773 sess_type = tls_record_xform.type; 11774 11775 ctx = rte_cryptodev_get_sec_ctx(dev_id); 11776 11777 sec_cap_idx.action = ut_params->type; 11778 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_TLS_RECORD; 11779 sec_cap_idx.tls_record.type = tls_record_xform.type; 11780 sec_cap_idx.tls_record.ver = tls_record_xform.ver; 11781 11782 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 11783 if (sec_cap == NULL) 11784 return TEST_SKIPPED; 11785 11786 /* Copy cipher session parameters */ 11787 if (td[0].aead) { 11788 memcpy(&ut_params->aead_xform, &td[0].xform.aead, sizeof(ut_params->aead_xform)); 11789 ut_params->aead_xform.aead.key.data = td[0].key.data; 11790 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 11791 11792 /* Verify crypto capabilities */ 11793 if (test_sec_crypto_caps_aead_verify(sec_cap, &ut_params->aead_xform) != 0) { 11794 if (!silent) 11795 RTE_LOG(INFO, USER1, "Crypto capabilities not supported\n"); 11796 return TEST_SKIPPED; 11797 } 11798 } else { 11799 memcpy(&ut_params->cipher_xform, &td[0].xform.chain.cipher, 11800 sizeof(ut_params->cipher_xform)); 11801 memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth, 11802 sizeof(ut_params->auth_xform)); 11803 ut_params->cipher_xform.cipher.key.data = td[0].key.data; 11804 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 11805 ut_params->auth_xform.auth.key.data = td[0].auth_key.data; 11806 11807 /* Verify crypto capabilities */ 11808 11809 if (test_sec_crypto_caps_cipher_verify(sec_cap, &ut_params->cipher_xform) != 0) { 11810 if (!silent) 11811 RTE_LOG(INFO, USER1, "Cipher crypto capabilities not supported\n"); 11812 return TEST_SKIPPED; 11813 } 11814 11815 if (test_sec_crypto_caps_auth_verify(sec_cap, &ut_params->auth_xform) != 0) { 11816 if (!silent) 11817 RTE_LOG(INFO, USER1, "Auth crypto capabilities not supported\n"); 11818 return TEST_SKIPPED; 11819 } 11820 } 11821 11822 if (test_tls_record_sec_caps_verify(&tls_record_xform, sec_cap, silent) != 0) 11823 return TEST_SKIPPED; 11824 11825 struct rte_security_session_conf sess_conf = { 11826 .action_type = ut_params->type, 11827 .protocol = RTE_SECURITY_PROTOCOL_TLS_RECORD, 11828 }; 11829 11830 if (td[0].aead) 11831 test_tls_record_imp_nonce_update(&td[0], &tls_record_xform); 11832 11833 sess_conf.tls_record = tls_record_xform; 11834 11835 if (td[0].aead) { 11836 sess_conf.crypto_xform = &ut_params->aead_xform; 11837 } else { 11838 if (sess_type == RTE_SECURITY_TLS_SESS_TYPE_READ) { 11839 sess_conf.crypto_xform = &ut_params->cipher_xform; 11840 ut_params->cipher_xform.next = &ut_params->auth_xform; 11841 } else { 11842 sess_conf.crypto_xform = &ut_params->auth_xform; 11843 ut_params->auth_xform.next = &ut_params->cipher_xform; 11844 } 11845 } 11846 11847 /* Create security session */ 11848 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 11849 ts_params->session_mpool); 11850 if (ut_params->sec_session == NULL) 11851 return TEST_SKIPPED; 11852 11853 for (i = 0; i < nb_td; i++) { 11854 /* Setup source mbuf payload */ 11855 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, td[i].input_text.len, 11856 nb_segs, 0); 11857 pktmbuf_write(ut_params->ibuf, 0, td[i].input_text.len, td[i].input_text.data); 11858 11859 /* Generate crypto op data structure */ 11860 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11861 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11862 if (ut_params->op == NULL) { 11863 printf("Could not allocate crypto op"); 11864 ret = TEST_FAILED; 11865 goto crypto_op_free; 11866 } 11867 11868 /* Attach session to operation */ 11869 rte_security_attach_session(ut_params->op, ut_params->sec_session); 11870 11871 /* Set crypto operation mbufs */ 11872 ut_params->op->sym->m_src = ut_params->ibuf; 11873 ut_params->op->sym->m_dst = NULL; 11874 ut_params->op->param1.tls_record.content_type = td[i].app_type; 11875 11876 /* Copy IV in crypto operation when IV generation is disabled */ 11877 if (sess_type == RTE_SECURITY_TLS_SESS_TYPE_WRITE && 11878 tls_record_xform.options.iv_gen_disable == 1) { 11879 uint8_t *iv; 11880 int len; 11881 11882 iv = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET); 11883 if (td[i].aead) 11884 len = td[i].xform.aead.aead.iv.length - 4; 11885 else 11886 len = td[i].xform.chain.cipher.cipher.iv.length; 11887 memcpy(iv, td[i].iv.data, len); 11888 } 11889 11890 /* Process crypto operation */ 11891 process_crypto_request(dev_id, ut_params->op); 11892 11893 ret = test_tls_record_status_check(ut_params->op); 11894 if (ret != TEST_SUCCESS) 11895 goto crypto_op_free; 11896 11897 if (res_d != NULL) 11898 res_d_tmp = &res_d[i]; 11899 11900 ret = test_tls_record_post_process(ut_params->ibuf, &td[i], res_d_tmp, silent); 11901 if (ret != TEST_SUCCESS) 11902 goto crypto_op_free; 11903 11904 11905 rte_crypto_op_free(ut_params->op); 11906 ut_params->op = NULL; 11907 11908 rte_pktmbuf_free(ut_params->ibuf); 11909 ut_params->ibuf = NULL; 11910 } 11911 11912 crypto_op_free: 11913 rte_crypto_op_free(ut_params->op); 11914 ut_params->op = NULL; 11915 11916 rte_pktmbuf_free(ut_params->ibuf); 11917 ut_params->ibuf = NULL; 11918 11919 if (ut_params->sec_session) 11920 rte_security_session_destroy(ctx, ut_params->sec_session); 11921 ut_params->sec_session = NULL; 11922 11923 RTE_SET_USED(flags); 11924 11925 return ret; 11926 } 11927 11928 static int 11929 test_tls_record_proto_known_vec(const void *test_data) 11930 { 11931 struct tls_record_test_data td_write; 11932 struct tls_record_test_flags flags; 11933 11934 memset(&flags, 0, sizeof(flags)); 11935 11936 memcpy(&td_write, test_data, sizeof(td_write)); 11937 11938 /* Disable IV gen to be able to test with known vectors */ 11939 td_write.tls_record_xform.options.iv_gen_disable = 1; 11940 11941 return test_tls_record_proto_process(&td_write, NULL, 1, false, &flags); 11942 } 11943 11944 static int 11945 test_tls_record_proto_known_vec_read(const void *test_data) 11946 { 11947 const struct tls_record_test_data *td = test_data; 11948 struct tls_record_test_flags flags; 11949 struct tls_record_test_data td_inb; 11950 11951 memset(&flags, 0, sizeof(flags)); 11952 11953 if (td->tls_record_xform.type == RTE_SECURITY_TLS_SESS_TYPE_WRITE) 11954 test_tls_record_td_read_from_write(td, &td_inb); 11955 else 11956 memcpy(&td_inb, td, sizeof(td_inb)); 11957 11958 return test_tls_record_proto_process(&td_inb, NULL, 1, false, &flags); 11959 } 11960 11961 static int 11962 test_tls_record_proto_all(const struct tls_record_test_flags *flags) 11963 { 11964 unsigned int i, nb_pkts = 1, pass_cnt = 0, payload_len, max_payload_len; 11965 struct tls_record_test_data td_outb[TEST_SEC_PKTS_MAX]; 11966 struct tls_record_test_data td_inb[TEST_SEC_PKTS_MAX]; 11967 int ret; 11968 11969 switch (flags->tls_version) { 11970 case RTE_SECURITY_VERSION_TLS_1_2: 11971 max_payload_len = TLS_1_2_RECORD_PLAINTEXT_MAX_LEN; 11972 break; 11973 case RTE_SECURITY_VERSION_TLS_1_3: 11974 max_payload_len = TLS_1_3_RECORD_PLAINTEXT_MAX_LEN; 11975 break; 11976 case RTE_SECURITY_VERSION_DTLS_1_2: 11977 max_payload_len = DTLS_1_2_RECORD_PLAINTEXT_MAX_LEN; 11978 break; 11979 default: 11980 max_payload_len = 0; 11981 } 11982 11983 for (i = 0; i < RTE_DIM(sec_alg_list); i++) { 11984 payload_len = TLS_RECORD_PLAINTEXT_MIN_LEN; 11985 if (flags->nb_segs_in_mbuf) 11986 payload_len = RTE_MAX(payload_len, flags->nb_segs_in_mbuf); 11987 11988 if (flags->zero_len) 11989 payload_len = 0; 11990 again: 11991 test_tls_record_td_prepare(sec_alg_list[i].param1, sec_alg_list[i].param2, flags, 11992 td_outb, nb_pkts, payload_len); 11993 11994 ret = test_tls_record_proto_process(td_outb, td_inb, nb_pkts, true, flags); 11995 if (ret == TEST_SKIPPED) 11996 continue; 11997 11998 if (flags->zero_len && 11999 ((flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE) || 12000 (flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE) || 12001 (flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE))) { 12002 if (ret == TEST_SUCCESS) 12003 return TEST_FAILED; 12004 goto skip_decrypt; 12005 } else if (ret == TEST_FAILED) { 12006 return TEST_FAILED; 12007 } 12008 12009 test_tls_record_td_update(td_inb, td_outb, nb_pkts, flags); 12010 12011 ret = test_tls_record_proto_process(td_inb, NULL, nb_pkts, true, flags); 12012 if (ret == TEST_SKIPPED) 12013 continue; 12014 12015 if (flags->pkt_corruption) { 12016 if (ret == TEST_SUCCESS) 12017 return TEST_FAILED; 12018 } else { 12019 if (ret == TEST_FAILED) 12020 return TEST_FAILED; 12021 } 12022 12023 skip_decrypt: 12024 if (flags->data_walkthrough && (++payload_len <= max_payload_len)) 12025 goto again; 12026 12027 if (flags->display_alg) 12028 test_sec_alg_display(sec_alg_list[i].param1, sec_alg_list[i].param2); 12029 12030 pass_cnt++; 12031 } 12032 12033 if (pass_cnt > 0) 12034 return TEST_SUCCESS; 12035 else 12036 return TEST_SKIPPED; 12037 } 12038 12039 static int 12040 test_tls_1_2_record_proto_data_walkthrough(void) 12041 { 12042 struct tls_record_test_flags flags; 12043 12044 memset(&flags, 0, sizeof(flags)); 12045 12046 flags.data_walkthrough = true; 12047 flags.tls_version = RTE_SECURITY_VERSION_TLS_1_2; 12048 12049 return test_tls_record_proto_all(&flags); 12050 } 12051 12052 static int 12053 test_tls_1_2_record_proto_display_list(void) 12054 { 12055 struct tls_record_test_flags flags; 12056 12057 memset(&flags, 0, sizeof(flags)); 12058 12059 flags.display_alg = true; 12060 flags.tls_version = RTE_SECURITY_VERSION_TLS_1_2; 12061 12062 return test_tls_record_proto_all(&flags); 12063 } 12064 12065 static int 12066 test_tls_1_2_record_proto_sgl(void) 12067 { 12068 struct tls_record_test_flags flags = { 12069 .nb_segs_in_mbuf = 5, 12070 .tls_version = RTE_SECURITY_VERSION_TLS_1_2 12071 }; 12072 struct crypto_testsuite_params *ts_params = &testsuite_params; 12073 struct rte_cryptodev_info dev_info; 12074 12075 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12076 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 12077 printf("Device doesn't support in-place scatter-gather. Test Skipped.\n"); 12078 return TEST_SKIPPED; 12079 } 12080 12081 return test_tls_record_proto_all(&flags); 12082 } 12083 12084 static int 12085 test_tls_record_proto_sgl_data_walkthrough(enum rte_security_tls_version tls_version) 12086 { 12087 struct tls_record_test_flags flags = { 12088 .nb_segs_in_mbuf = 5, 12089 .tls_version = tls_version, 12090 .data_walkthrough = true 12091 }; 12092 struct crypto_testsuite_params *ts_params = &testsuite_params; 12093 struct rte_cryptodev_info dev_info; 12094 12095 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12096 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 12097 printf("Device doesn't support in-place scatter-gather. Test Skipped.\n"); 12098 return TEST_SKIPPED; 12099 } 12100 12101 return test_tls_record_proto_all(&flags); 12102 } 12103 12104 static int 12105 test_tls_1_2_record_proto_sgl_data_walkthrough(void) 12106 { 12107 return test_tls_record_proto_sgl_data_walkthrough(RTE_SECURITY_VERSION_TLS_1_2); 12108 } 12109 12110 static int 12111 test_tls_record_proto_corrupt_pkt(void) 12112 { 12113 struct tls_record_test_flags flags = { 12114 .pkt_corruption = 1 12115 }; 12116 struct crypto_testsuite_params *ts_params = &testsuite_params; 12117 struct rte_cryptodev_info dev_info; 12118 12119 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12120 12121 return test_tls_record_proto_all(&flags); 12122 } 12123 12124 static int 12125 test_tls_record_proto_custom_content_type(void) 12126 { 12127 struct tls_record_test_flags flags = { 12128 .content_type = TLS_RECORD_TEST_CONTENT_TYPE_CUSTOM 12129 }; 12130 struct crypto_testsuite_params *ts_params = &testsuite_params; 12131 struct rte_cryptodev_info dev_info; 12132 12133 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12134 12135 return test_tls_record_proto_all(&flags); 12136 } 12137 12138 static int 12139 test_tls_record_proto_zero_len(void) 12140 { 12141 struct tls_record_test_flags flags = { 12142 .zero_len = 1 12143 }; 12144 struct crypto_testsuite_params *ts_params = &testsuite_params; 12145 struct rte_cryptodev_info dev_info; 12146 12147 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12148 12149 return test_tls_record_proto_all(&flags); 12150 } 12151 12152 static int 12153 test_tls_record_proto_zero_len_non_app(void) 12154 { 12155 struct tls_record_test_flags flags = { 12156 .zero_len = 1, 12157 .content_type = TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE, 12158 }; 12159 struct crypto_testsuite_params *ts_params = &testsuite_params; 12160 struct rte_cryptodev_info dev_info; 12161 12162 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12163 12164 return test_tls_record_proto_all(&flags); 12165 } 12166 12167 static int 12168 test_dtls_1_2_record_proto_data_walkthrough(void) 12169 { 12170 struct tls_record_test_flags flags; 12171 12172 memset(&flags, 0, sizeof(flags)); 12173 12174 flags.data_walkthrough = true; 12175 flags.tls_version = RTE_SECURITY_VERSION_DTLS_1_2; 12176 12177 return test_tls_record_proto_all(&flags); 12178 } 12179 12180 static int 12181 test_dtls_1_2_record_proto_display_list(void) 12182 { 12183 struct tls_record_test_flags flags; 12184 12185 memset(&flags, 0, sizeof(flags)); 12186 12187 flags.display_alg = true; 12188 flags.tls_version = RTE_SECURITY_VERSION_DTLS_1_2; 12189 12190 return test_tls_record_proto_all(&flags); 12191 } 12192 12193 static int 12194 test_dtls_1_2_record_proto_sgl(void) 12195 { 12196 struct tls_record_test_flags flags = { 12197 .nb_segs_in_mbuf = 5, 12198 .tls_version = RTE_SECURITY_VERSION_DTLS_1_2 12199 }; 12200 struct crypto_testsuite_params *ts_params = &testsuite_params; 12201 struct rte_cryptodev_info dev_info; 12202 12203 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12204 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 12205 printf("Device doesn't support in-place scatter-gather. Test Skipped.\n"); 12206 return TEST_SKIPPED; 12207 } 12208 12209 return test_tls_record_proto_all(&flags); 12210 } 12211 12212 static int 12213 test_dtls_1_2_record_proto_sgl_data_walkthrough(void) 12214 { 12215 return test_tls_record_proto_sgl_data_walkthrough(RTE_SECURITY_VERSION_DTLS_1_2); 12216 } 12217 12218 static int 12219 test_dtls_1_2_record_proto_corrupt_pkt(void) 12220 { 12221 struct tls_record_test_flags flags = { 12222 .pkt_corruption = 1, 12223 .tls_version = RTE_SECURITY_VERSION_DTLS_1_2 12224 }; 12225 struct crypto_testsuite_params *ts_params = &testsuite_params; 12226 struct rte_cryptodev_info dev_info; 12227 12228 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12229 12230 return test_tls_record_proto_all(&flags); 12231 } 12232 12233 static int 12234 test_dtls_1_2_record_proto_custom_content_type(void) 12235 { 12236 struct tls_record_test_flags flags = { 12237 .content_type = TLS_RECORD_TEST_CONTENT_TYPE_CUSTOM, 12238 .tls_version = RTE_SECURITY_VERSION_DTLS_1_2 12239 }; 12240 struct crypto_testsuite_params *ts_params = &testsuite_params; 12241 struct rte_cryptodev_info dev_info; 12242 12243 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12244 12245 return test_tls_record_proto_all(&flags); 12246 } 12247 12248 static int 12249 test_dtls_1_2_record_proto_zero_len(void) 12250 { 12251 struct tls_record_test_flags flags = { 12252 .zero_len = 1, 12253 .tls_version = RTE_SECURITY_VERSION_DTLS_1_2 12254 }; 12255 struct crypto_testsuite_params *ts_params = &testsuite_params; 12256 struct rte_cryptodev_info dev_info; 12257 12258 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12259 12260 return test_tls_record_proto_all(&flags); 12261 } 12262 12263 static int 12264 test_dtls_1_2_record_proto_zero_len_non_app(void) 12265 { 12266 struct tls_record_test_flags flags = { 12267 .zero_len = 1, 12268 .content_type = TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE, 12269 .tls_version = RTE_SECURITY_VERSION_DTLS_1_2 12270 }; 12271 struct crypto_testsuite_params *ts_params = &testsuite_params; 12272 struct rte_cryptodev_info dev_info; 12273 12274 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12275 12276 return test_tls_record_proto_all(&flags); 12277 } 12278 12279 #endif 12280 12281 static int 12282 test_AES_GCM_authenticated_encryption_test_case_1(void) 12283 { 12284 return test_authenticated_encryption(&gcm_test_case_1); 12285 } 12286 12287 static int 12288 test_AES_GCM_authenticated_encryption_test_case_2(void) 12289 { 12290 return test_authenticated_encryption(&gcm_test_case_2); 12291 } 12292 12293 static int 12294 test_AES_GCM_authenticated_encryption_test_case_3(void) 12295 { 12296 return test_authenticated_encryption(&gcm_test_case_3); 12297 } 12298 12299 static int 12300 test_AES_GCM_authenticated_encryption_test_case_3_ext_mbuf(void) 12301 { 12302 return test_authenticated_encryption_helper(&gcm_test_case_3, true); 12303 } 12304 12305 static int 12306 test_AES_GCM_authenticated_encryption_test_case_4(void) 12307 { 12308 return test_authenticated_encryption(&gcm_test_case_4); 12309 } 12310 12311 static int 12312 test_AES_GCM_authenticated_encryption_test_case_5(void) 12313 { 12314 return test_authenticated_encryption(&gcm_test_case_5); 12315 } 12316 12317 static int 12318 test_AES_GCM_authenticated_encryption_test_case_6(void) 12319 { 12320 return test_authenticated_encryption(&gcm_test_case_6); 12321 } 12322 12323 static int 12324 test_AES_GCM_authenticated_encryption_test_case_7(void) 12325 { 12326 return test_authenticated_encryption(&gcm_test_case_7); 12327 } 12328 12329 static int 12330 test_AES_GCM_authenticated_encryption_test_case_8(void) 12331 { 12332 return test_authenticated_encryption(&gcm_test_case_8); 12333 } 12334 12335 static int 12336 test_AES_GCM_J0_authenticated_encryption_test_case_1(void) 12337 { 12338 return test_authenticated_encryption(&gcm_J0_test_case_1); 12339 } 12340 12341 static int 12342 test_AES_GCM_auth_encryption_test_case_192_1(void) 12343 { 12344 return test_authenticated_encryption(&gcm_test_case_192_1); 12345 } 12346 12347 static int 12348 test_AES_GCM_auth_encryption_test_case_192_2(void) 12349 { 12350 return test_authenticated_encryption(&gcm_test_case_192_2); 12351 } 12352 12353 static int 12354 test_AES_GCM_auth_encryption_test_case_192_3(void) 12355 { 12356 return test_authenticated_encryption(&gcm_test_case_192_3); 12357 } 12358 12359 static int 12360 test_AES_GCM_auth_encryption_test_case_192_4(void) 12361 { 12362 return test_authenticated_encryption(&gcm_test_case_192_4); 12363 } 12364 12365 static int 12366 test_AES_GCM_auth_encryption_test_case_192_5(void) 12367 { 12368 return test_authenticated_encryption(&gcm_test_case_192_5); 12369 } 12370 12371 static int 12372 test_AES_GCM_auth_encryption_test_case_192_6(void) 12373 { 12374 return test_authenticated_encryption(&gcm_test_case_192_6); 12375 } 12376 12377 static int 12378 test_AES_GCM_auth_encryption_test_case_192_7(void) 12379 { 12380 return test_authenticated_encryption(&gcm_test_case_192_7); 12381 } 12382 12383 static int 12384 test_AES_GCM_auth_encryption_test_case_256_1(void) 12385 { 12386 return test_authenticated_encryption(&gcm_test_case_256_1); 12387 } 12388 12389 static int 12390 test_AES_GCM_auth_encryption_test_case_256_2(void) 12391 { 12392 return test_authenticated_encryption(&gcm_test_case_256_2); 12393 } 12394 12395 static int 12396 test_AES_GCM_auth_encryption_test_case_256_3(void) 12397 { 12398 return test_authenticated_encryption(&gcm_test_case_256_3); 12399 } 12400 12401 static int 12402 test_AES_GCM_auth_encryption_test_case_256_4(void) 12403 { 12404 return test_authenticated_encryption(&gcm_test_case_256_4); 12405 } 12406 12407 static int 12408 test_AES_GCM_auth_encryption_test_case_256_5(void) 12409 { 12410 return test_authenticated_encryption(&gcm_test_case_256_5); 12411 } 12412 12413 static int 12414 test_AES_GCM_auth_encryption_test_case_256_6(void) 12415 { 12416 return test_authenticated_encryption(&gcm_test_case_256_6); 12417 } 12418 12419 static int 12420 test_AES_GCM_auth_encryption_test_case_256_7(void) 12421 { 12422 return test_authenticated_encryption(&gcm_test_case_256_7); 12423 } 12424 12425 static int 12426 test_AES_GCM_auth_encryption_test_case_aad_1(void) 12427 { 12428 return test_authenticated_encryption(&gcm_test_case_aad_1); 12429 } 12430 12431 static int 12432 test_AES_GCM_auth_encryption_test_case_aad_2(void) 12433 { 12434 return test_authenticated_encryption(&gcm_test_case_aad_2); 12435 } 12436 12437 static int 12438 test_AES_GCM_auth_encryption_fail_iv_corrupt(void) 12439 { 12440 struct aead_test_data tdata; 12441 int res; 12442 12443 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12444 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12445 tdata.iv.data[0] += 1; 12446 res = test_authenticated_encryption(&tdata); 12447 if (res == TEST_SKIPPED) 12448 return res; 12449 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 12450 return TEST_SUCCESS; 12451 } 12452 12453 static int 12454 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void) 12455 { 12456 struct aead_test_data tdata; 12457 int res; 12458 12459 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12460 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12461 tdata.plaintext.data[0] += 1; 12462 res = test_authenticated_encryption(&tdata); 12463 if (res == TEST_SKIPPED) 12464 return res; 12465 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 12466 return TEST_SUCCESS; 12467 } 12468 12469 static int 12470 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void) 12471 { 12472 struct aead_test_data tdata; 12473 int res; 12474 12475 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12476 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12477 tdata.ciphertext.data[0] += 1; 12478 res = test_authenticated_encryption(&tdata); 12479 if (res == TEST_SKIPPED) 12480 return res; 12481 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 12482 return TEST_SUCCESS; 12483 } 12484 12485 static int 12486 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void) 12487 { 12488 struct aead_test_data tdata; 12489 int res; 12490 12491 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12492 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12493 tdata.aad.len += 1; 12494 res = test_authenticated_encryption(&tdata); 12495 if (res == TEST_SKIPPED) 12496 return res; 12497 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 12498 return TEST_SUCCESS; 12499 } 12500 12501 static int 12502 test_AES_GCM_auth_encryption_fail_aad_corrupt(void) 12503 { 12504 struct aead_test_data tdata; 12505 uint8_t aad[gcm_test_case_7.aad.len]; 12506 int res; 12507 12508 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12509 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12510 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 12511 aad[0] += 1; 12512 tdata.aad.data = aad; 12513 res = test_authenticated_encryption(&tdata); 12514 if (res == TEST_SKIPPED) 12515 return res; 12516 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 12517 return TEST_SUCCESS; 12518 } 12519 12520 static int 12521 test_AES_GCM_auth_encryption_fail_tag_corrupt(void) 12522 { 12523 struct aead_test_data tdata; 12524 int res; 12525 12526 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12527 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12528 tdata.auth_tag.data[0] += 1; 12529 res = test_authenticated_encryption(&tdata); 12530 if (res == TEST_SKIPPED) 12531 return res; 12532 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 12533 return TEST_SUCCESS; 12534 } 12535 12536 static int 12537 test_authenticated_decryption_helper(const struct aead_test_data *tdata, bool use_ext_mbuf) 12538 { 12539 struct crypto_testsuite_params *ts_params = &testsuite_params; 12540 struct crypto_unittest_params *ut_params = &unittest_params; 12541 12542 int retval; 12543 uint8_t *plaintext; 12544 uint32_t i; 12545 struct rte_cryptodev_info dev_info; 12546 12547 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12548 uint64_t feat_flags = dev_info.feature_flags; 12549 12550 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12551 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12552 printf("Device doesn't support RAW data-path APIs.\n"); 12553 return TEST_SKIPPED; 12554 } 12555 12556 /* Verify the capabilities */ 12557 struct rte_cryptodev_sym_capability_idx cap_idx; 12558 const struct rte_cryptodev_symmetric_capability *capability; 12559 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12560 cap_idx.algo.aead = tdata->algo; 12561 capability = rte_cryptodev_sym_capability_get( 12562 ts_params->valid_devs[0], &cap_idx); 12563 if (capability == NULL) 12564 return TEST_SKIPPED; 12565 if (rte_cryptodev_sym_capability_check_aead( 12566 capability, tdata->key.len, tdata->auth_tag.len, 12567 tdata->aad.len, tdata->iv.len)) 12568 return TEST_SKIPPED; 12569 12570 /* Create AEAD session */ 12571 retval = create_aead_session(ts_params->valid_devs[0], 12572 tdata->algo, 12573 RTE_CRYPTO_AEAD_OP_DECRYPT, 12574 tdata->key.data, tdata->key.len, 12575 tdata->aad.len, tdata->auth_tag.len, 12576 tdata->iv.len); 12577 if (retval != TEST_SUCCESS) 12578 return retval; 12579 12580 /* alloc mbuf and set payload */ 12581 if (tdata->aad.len > MBUF_SIZE) { 12582 if (use_ext_mbuf) { 12583 ut_params->ibuf = ext_mbuf_create(ts_params->large_mbuf_pool, 12584 AEAD_TEXT_MAX_LENGTH, 12585 1 /* nb_segs */, 12586 NULL); 12587 } else { 12588 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 12589 } 12590 /* Populate full size of add data */ 12591 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 12592 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 12593 } else { 12594 if (use_ext_mbuf) { 12595 ut_params->ibuf = ext_mbuf_create(ts_params->mbuf_pool, 12596 AEAD_TEXT_MAX_LENGTH, 12597 1 /* nb_segs */, 12598 NULL); 12599 } else { 12600 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12601 } 12602 } 12603 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12604 rte_pktmbuf_tailroom(ut_params->ibuf)); 12605 12606 /* Create AEAD operation */ 12607 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 12608 if (retval < 0) 12609 return retval; 12610 12611 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12612 12613 ut_params->op->sym->m_src = ut_params->ibuf; 12614 12615 /* Process crypto operation */ 12616 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12617 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 12618 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 12619 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 12620 0); 12621 if (retval != TEST_SUCCESS) 12622 return retval; 12623 } else 12624 TEST_ASSERT_NOT_NULL( 12625 process_crypto_request(ts_params->valid_devs[0], 12626 ut_params->op), "failed to process sym crypto op"); 12627 12628 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12629 "crypto op processing failed"); 12630 12631 if (ut_params->op->sym->m_dst) 12632 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 12633 uint8_t *); 12634 else 12635 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 12636 uint8_t *, 12637 ut_params->op->sym->cipher.data.offset); 12638 12639 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 12640 12641 /* Validate obuf */ 12642 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12643 plaintext, 12644 tdata->plaintext.data, 12645 tdata->plaintext.len, 12646 "Plaintext data not as expected"); 12647 12648 TEST_ASSERT_EQUAL(ut_params->op->status, 12649 RTE_CRYPTO_OP_STATUS_SUCCESS, 12650 "Authentication failed"); 12651 12652 return 0; 12653 } 12654 12655 static int 12656 test_authenticated_decryption(const struct aead_test_data *tdata) 12657 { 12658 return test_authenticated_decryption_helper(tdata, false); 12659 } 12660 12661 static int 12662 test_AES_GCM_authenticated_decryption_test_case_1(void) 12663 { 12664 return test_authenticated_decryption(&gcm_test_case_1); 12665 } 12666 12667 static int 12668 test_AES_GCM_authenticated_decryption_test_case_2(void) 12669 { 12670 return test_authenticated_decryption(&gcm_test_case_2); 12671 } 12672 12673 static int 12674 test_AES_GCM_authenticated_decryption_test_case_3(void) 12675 { 12676 return test_authenticated_decryption(&gcm_test_case_3); 12677 } 12678 12679 static int 12680 test_AES_GCM_authenticated_decryption_test_case_3_ext_mbuf(void) 12681 { 12682 return test_authenticated_decryption_helper(&gcm_test_case_3, true); 12683 } 12684 12685 static int 12686 test_AES_GCM_authenticated_decryption_test_case_4(void) 12687 { 12688 return test_authenticated_decryption(&gcm_test_case_4); 12689 } 12690 12691 static int 12692 test_AES_GCM_authenticated_decryption_test_case_5(void) 12693 { 12694 return test_authenticated_decryption(&gcm_test_case_5); 12695 } 12696 12697 static int 12698 test_AES_GCM_authenticated_decryption_test_case_6(void) 12699 { 12700 return test_authenticated_decryption(&gcm_test_case_6); 12701 } 12702 12703 static int 12704 test_AES_GCM_authenticated_decryption_test_case_7(void) 12705 { 12706 return test_authenticated_decryption(&gcm_test_case_7); 12707 } 12708 12709 static int 12710 test_AES_GCM_authenticated_decryption_test_case_8(void) 12711 { 12712 return test_authenticated_decryption(&gcm_test_case_8); 12713 } 12714 12715 static int 12716 test_AES_GCM_J0_authenticated_decryption_test_case_1(void) 12717 { 12718 return test_authenticated_decryption(&gcm_J0_test_case_1); 12719 } 12720 12721 static int 12722 test_AES_GCM_auth_decryption_test_case_192_1(void) 12723 { 12724 return test_authenticated_decryption(&gcm_test_case_192_1); 12725 } 12726 12727 static int 12728 test_AES_GCM_auth_decryption_test_case_192_2(void) 12729 { 12730 return test_authenticated_decryption(&gcm_test_case_192_2); 12731 } 12732 12733 static int 12734 test_AES_GCM_auth_decryption_test_case_192_3(void) 12735 { 12736 return test_authenticated_decryption(&gcm_test_case_192_3); 12737 } 12738 12739 static int 12740 test_AES_GCM_auth_decryption_test_case_192_4(void) 12741 { 12742 return test_authenticated_decryption(&gcm_test_case_192_4); 12743 } 12744 12745 static int 12746 test_AES_GCM_auth_decryption_test_case_192_5(void) 12747 { 12748 return test_authenticated_decryption(&gcm_test_case_192_5); 12749 } 12750 12751 static int 12752 test_AES_GCM_auth_decryption_test_case_192_6(void) 12753 { 12754 return test_authenticated_decryption(&gcm_test_case_192_6); 12755 } 12756 12757 static int 12758 test_AES_GCM_auth_decryption_test_case_192_7(void) 12759 { 12760 return test_authenticated_decryption(&gcm_test_case_192_7); 12761 } 12762 12763 static int 12764 test_AES_GCM_auth_decryption_test_case_256_1(void) 12765 { 12766 return test_authenticated_decryption(&gcm_test_case_256_1); 12767 } 12768 12769 static int 12770 test_AES_GCM_auth_decryption_test_case_256_2(void) 12771 { 12772 return test_authenticated_decryption(&gcm_test_case_256_2); 12773 } 12774 12775 static int 12776 test_AES_GCM_auth_decryption_test_case_256_3(void) 12777 { 12778 return test_authenticated_decryption(&gcm_test_case_256_3); 12779 } 12780 12781 static int 12782 test_AES_GCM_auth_decryption_test_case_256_4(void) 12783 { 12784 return test_authenticated_decryption(&gcm_test_case_256_4); 12785 } 12786 12787 static int 12788 test_AES_GCM_auth_decryption_test_case_256_5(void) 12789 { 12790 return test_authenticated_decryption(&gcm_test_case_256_5); 12791 } 12792 12793 static int 12794 test_AES_GCM_auth_decryption_test_case_256_6(void) 12795 { 12796 return test_authenticated_decryption(&gcm_test_case_256_6); 12797 } 12798 12799 static int 12800 test_AES_GCM_auth_decryption_test_case_256_7(void) 12801 { 12802 return test_authenticated_decryption(&gcm_test_case_256_7); 12803 } 12804 12805 static int 12806 test_AES_GCM_auth_decryption_test_case_256_8(void) 12807 { 12808 return test_authenticated_decryption(&gcm_test_case_256_8); 12809 } 12810 12811 static int 12812 test_AES_GCM_auth_encryption_test_case_256_8(void) 12813 { 12814 return test_authenticated_encryption(&gcm_test_case_256_8); 12815 } 12816 12817 static int 12818 test_AES_GCM_auth_decryption_test_case_aad_1(void) 12819 { 12820 return test_authenticated_decryption(&gcm_test_case_aad_1); 12821 } 12822 12823 static int 12824 test_AES_GCM_auth_decryption_test_case_aad_2(void) 12825 { 12826 return test_authenticated_decryption(&gcm_test_case_aad_2); 12827 } 12828 12829 static int 12830 test_AES_GCM_auth_decryption_fail_iv_corrupt(void) 12831 { 12832 struct aead_test_data tdata; 12833 int res; 12834 12835 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12836 tdata.iv.data[0] += 1; 12837 res = test_authenticated_decryption(&tdata); 12838 if (res == TEST_SKIPPED) 12839 return res; 12840 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12841 return TEST_SUCCESS; 12842 } 12843 12844 static int 12845 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void) 12846 { 12847 struct aead_test_data tdata; 12848 int res; 12849 12850 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12851 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12852 tdata.plaintext.data[0] += 1; 12853 res = test_authenticated_decryption(&tdata); 12854 if (res == TEST_SKIPPED) 12855 return res; 12856 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12857 return TEST_SUCCESS; 12858 } 12859 12860 static int 12861 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void) 12862 { 12863 struct aead_test_data tdata; 12864 int res; 12865 12866 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12867 tdata.ciphertext.data[0] += 1; 12868 res = test_authenticated_decryption(&tdata); 12869 if (res == TEST_SKIPPED) 12870 return res; 12871 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12872 return TEST_SUCCESS; 12873 } 12874 12875 static int 12876 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void) 12877 { 12878 struct aead_test_data tdata; 12879 int res; 12880 12881 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12882 tdata.aad.len += 1; 12883 res = test_authenticated_decryption(&tdata); 12884 if (res == TEST_SKIPPED) 12885 return res; 12886 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12887 return TEST_SUCCESS; 12888 } 12889 12890 static int 12891 test_AES_GCM_auth_decryption_fail_aad_corrupt(void) 12892 { 12893 struct aead_test_data tdata; 12894 uint8_t aad[gcm_test_case_7.aad.len]; 12895 int res; 12896 12897 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12898 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 12899 aad[0] += 1; 12900 tdata.aad.data = aad; 12901 res = test_authenticated_decryption(&tdata); 12902 if (res == TEST_SKIPPED) 12903 return res; 12904 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12905 return TEST_SUCCESS; 12906 } 12907 12908 static int 12909 test_AES_GCM_auth_decryption_fail_tag_corrupt(void) 12910 { 12911 struct aead_test_data tdata; 12912 int res; 12913 12914 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12915 tdata.auth_tag.data[0] += 1; 12916 res = test_authenticated_decryption(&tdata); 12917 if (res == TEST_SKIPPED) 12918 return res; 12919 TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed"); 12920 return TEST_SUCCESS; 12921 } 12922 12923 static int 12924 test_authenticated_encryption_oop(const struct aead_test_data *tdata) 12925 { 12926 struct crypto_testsuite_params *ts_params = &testsuite_params; 12927 struct crypto_unittest_params *ut_params = &unittest_params; 12928 12929 int retval; 12930 uint8_t *ciphertext, *auth_tag; 12931 uint16_t plaintext_pad_len; 12932 struct rte_cryptodev_info dev_info; 12933 12934 /* Verify the capabilities */ 12935 struct rte_cryptodev_sym_capability_idx cap_idx; 12936 const struct rte_cryptodev_symmetric_capability *capability; 12937 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12938 cap_idx.algo.aead = tdata->algo; 12939 capability = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], &cap_idx); 12940 if (capability == NULL) 12941 return TEST_SKIPPED; 12942 if (rte_cryptodev_sym_capability_check_aead( 12943 capability, tdata->key.len, tdata->auth_tag.len, 12944 tdata->aad.len, tdata->iv.len)) 12945 return TEST_SKIPPED; 12946 12947 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12948 uint64_t feat_flags = dev_info.feature_flags; 12949 12950 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12951 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) 12952 return TEST_SKIPPED; 12953 12954 /* not supported with CPU crypto */ 12955 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12956 return TEST_SKIPPED; 12957 12958 /* Create AEAD session */ 12959 retval = create_aead_session(ts_params->valid_devs[0], 12960 tdata->algo, 12961 RTE_CRYPTO_AEAD_OP_ENCRYPT, 12962 tdata->key.data, tdata->key.len, 12963 tdata->aad.len, tdata->auth_tag.len, 12964 tdata->iv.len); 12965 if (retval < 0) 12966 return retval; 12967 12968 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12969 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12970 12971 /* clear mbuf payload */ 12972 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12973 rte_pktmbuf_tailroom(ut_params->ibuf)); 12974 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 12975 rte_pktmbuf_tailroom(ut_params->obuf)); 12976 12977 /* Create AEAD operation */ 12978 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 12979 if (retval < 0) 12980 return retval; 12981 12982 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12983 12984 ut_params->op->sym->m_src = ut_params->ibuf; 12985 ut_params->op->sym->m_dst = ut_params->obuf; 12986 12987 /* Process crypto operation */ 12988 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 12989 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 12990 0); 12991 if (retval != TEST_SUCCESS) 12992 return retval; 12993 } else 12994 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 12995 ut_params->op), "failed to process sym crypto op"); 12996 12997 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12998 "crypto op processing failed"); 12999 13000 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 13001 13002 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 13003 ut_params->op->sym->cipher.data.offset); 13004 auth_tag = ciphertext + plaintext_pad_len; 13005 13006 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 13007 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 13008 13009 /* Validate obuf */ 13010 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13011 ciphertext, 13012 tdata->ciphertext.data, 13013 tdata->ciphertext.len, 13014 "Ciphertext data not as expected"); 13015 13016 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13017 auth_tag, 13018 tdata->auth_tag.data, 13019 tdata->auth_tag.len, 13020 "Generated auth tag not as expected"); 13021 13022 return 0; 13023 13024 } 13025 13026 static int 13027 test_AES_GCM_authenticated_encryption_oop_test_case_1(void) 13028 { 13029 return test_authenticated_encryption_oop(&gcm_test_case_5); 13030 } 13031 13032 static int 13033 test_authenticated_decryption_oop(const struct aead_test_data *tdata) 13034 { 13035 struct crypto_testsuite_params *ts_params = &testsuite_params; 13036 struct crypto_unittest_params *ut_params = &unittest_params; 13037 13038 int retval; 13039 uint8_t *plaintext; 13040 struct rte_cryptodev_info dev_info; 13041 13042 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13043 uint64_t feat_flags = dev_info.feature_flags; 13044 13045 /* Verify the capabilities */ 13046 struct rte_cryptodev_sym_capability_idx cap_idx; 13047 const struct rte_cryptodev_symmetric_capability *capability; 13048 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 13049 cap_idx.algo.aead = tdata->algo; 13050 capability = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], &cap_idx); 13051 13052 if (capability == NULL) 13053 return TEST_SKIPPED; 13054 13055 if (rte_cryptodev_sym_capability_check_aead(capability, tdata->key.len, 13056 tdata->auth_tag.len, tdata->aad.len, tdata->iv.len)) 13057 return TEST_SKIPPED; 13058 13059 /* not supported with CPU crypto and raw data-path APIs*/ 13060 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO || 13061 global_api_test_type == CRYPTODEV_RAW_API_TEST) 13062 return TEST_SKIPPED; 13063 13064 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13065 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13066 printf("Device does not support RAW data-path APIs.\n"); 13067 return TEST_SKIPPED; 13068 } 13069 13070 /* Create AEAD session */ 13071 retval = create_aead_session(ts_params->valid_devs[0], 13072 tdata->algo, 13073 RTE_CRYPTO_AEAD_OP_DECRYPT, 13074 tdata->key.data, tdata->key.len, 13075 tdata->aad.len, tdata->auth_tag.len, 13076 tdata->iv.len); 13077 if (retval < 0) 13078 return retval; 13079 13080 /* alloc mbuf and set payload */ 13081 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13082 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13083 13084 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13085 rte_pktmbuf_tailroom(ut_params->ibuf)); 13086 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 13087 rte_pktmbuf_tailroom(ut_params->obuf)); 13088 13089 /* Create AEAD operation */ 13090 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 13091 if (retval < 0) 13092 return retval; 13093 13094 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13095 13096 ut_params->op->sym->m_src = ut_params->ibuf; 13097 ut_params->op->sym->m_dst = ut_params->obuf; 13098 13099 /* Process crypto operation */ 13100 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 13101 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 13102 0); 13103 if (retval != TEST_SUCCESS) 13104 return retval; 13105 } else 13106 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 13107 ut_params->op), "failed to process sym crypto op"); 13108 13109 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13110 "crypto op processing failed"); 13111 13112 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 13113 ut_params->op->sym->cipher.data.offset); 13114 13115 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 13116 13117 /* Validate obuf */ 13118 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13119 plaintext, 13120 tdata->plaintext.data, 13121 tdata->plaintext.len, 13122 "Plaintext data not as expected"); 13123 13124 TEST_ASSERT_EQUAL(ut_params->op->status, 13125 RTE_CRYPTO_OP_STATUS_SUCCESS, 13126 "Authentication failed"); 13127 return 0; 13128 } 13129 13130 static int 13131 test_AES_GCM_authenticated_decryption_oop_test_case_1(void) 13132 { 13133 return test_authenticated_decryption_oop(&gcm_test_case_5); 13134 } 13135 13136 static int 13137 test_authenticated_encryption_sessionless( 13138 const struct aead_test_data *tdata) 13139 { 13140 struct crypto_testsuite_params *ts_params = &testsuite_params; 13141 struct crypto_unittest_params *ut_params = &unittest_params; 13142 13143 int retval; 13144 uint8_t *ciphertext, *auth_tag; 13145 uint16_t plaintext_pad_len; 13146 uint8_t key[tdata->key.len + 1]; 13147 struct rte_cryptodev_info dev_info; 13148 13149 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13150 uint64_t feat_flags = dev_info.feature_flags; 13151 13152 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 13153 printf("Device doesn't support Sessionless ops.\n"); 13154 return TEST_SKIPPED; 13155 } 13156 13157 /* not supported with CPU crypto */ 13158 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13159 return TEST_SKIPPED; 13160 13161 /* Verify the capabilities */ 13162 struct rte_cryptodev_sym_capability_idx cap_idx; 13163 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 13164 cap_idx.algo.aead = tdata->algo; 13165 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13166 &cap_idx) == NULL) 13167 return TEST_SKIPPED; 13168 13169 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13170 13171 /* clear mbuf payload */ 13172 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13173 rte_pktmbuf_tailroom(ut_params->ibuf)); 13174 13175 /* Create AEAD operation */ 13176 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 13177 if (retval < 0) 13178 return retval; 13179 13180 /* Create GCM xform */ 13181 memcpy(key, tdata->key.data, tdata->key.len); 13182 retval = create_aead_xform(ut_params->op, 13183 tdata->algo, 13184 RTE_CRYPTO_AEAD_OP_ENCRYPT, 13185 key, tdata->key.len, 13186 tdata->aad.len, tdata->auth_tag.len, 13187 tdata->iv.len); 13188 if (retval < 0) 13189 return retval; 13190 13191 ut_params->op->sym->m_src = ut_params->ibuf; 13192 13193 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 13194 RTE_CRYPTO_OP_SESSIONLESS, 13195 "crypto op session type not sessionless"); 13196 13197 /* Process crypto operation */ 13198 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 13199 ut_params->op), "failed to process sym crypto op"); 13200 13201 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 13202 13203 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13204 "crypto op status not success"); 13205 13206 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 13207 13208 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 13209 ut_params->op->sym->cipher.data.offset); 13210 auth_tag = ciphertext + plaintext_pad_len; 13211 13212 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 13213 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 13214 13215 /* Validate obuf */ 13216 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13217 ciphertext, 13218 tdata->ciphertext.data, 13219 tdata->ciphertext.len, 13220 "Ciphertext data not as expected"); 13221 13222 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13223 auth_tag, 13224 tdata->auth_tag.data, 13225 tdata->auth_tag.len, 13226 "Generated auth tag not as expected"); 13227 13228 return 0; 13229 13230 } 13231 13232 static int 13233 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void) 13234 { 13235 return test_authenticated_encryption_sessionless( 13236 &gcm_test_case_5); 13237 } 13238 13239 static int 13240 test_authenticated_decryption_sessionless( 13241 const struct aead_test_data *tdata) 13242 { 13243 struct crypto_testsuite_params *ts_params = &testsuite_params; 13244 struct crypto_unittest_params *ut_params = &unittest_params; 13245 13246 int retval; 13247 uint8_t *plaintext; 13248 uint8_t key[tdata->key.len + 1]; 13249 struct rte_cryptodev_info dev_info; 13250 13251 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13252 uint64_t feat_flags = dev_info.feature_flags; 13253 13254 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 13255 printf("Device doesn't support Sessionless ops.\n"); 13256 return TEST_SKIPPED; 13257 } 13258 13259 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13260 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13261 printf("Device doesn't support RAW data-path APIs.\n"); 13262 return TEST_SKIPPED; 13263 } 13264 13265 /* not supported with CPU crypto */ 13266 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13267 return TEST_SKIPPED; 13268 13269 /* Verify the capabilities */ 13270 struct rte_cryptodev_sym_capability_idx cap_idx; 13271 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 13272 cap_idx.algo.aead = tdata->algo; 13273 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13274 &cap_idx) == NULL) 13275 return TEST_SKIPPED; 13276 13277 /* alloc mbuf and set payload */ 13278 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13279 13280 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13281 rte_pktmbuf_tailroom(ut_params->ibuf)); 13282 13283 /* Create AEAD operation */ 13284 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 13285 if (retval < 0) 13286 return retval; 13287 13288 /* Create AEAD xform */ 13289 memcpy(key, tdata->key.data, tdata->key.len); 13290 retval = create_aead_xform(ut_params->op, 13291 tdata->algo, 13292 RTE_CRYPTO_AEAD_OP_DECRYPT, 13293 key, tdata->key.len, 13294 tdata->aad.len, tdata->auth_tag.len, 13295 tdata->iv.len); 13296 if (retval < 0) 13297 return retval; 13298 13299 ut_params->op->sym->m_src = ut_params->ibuf; 13300 13301 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 13302 RTE_CRYPTO_OP_SESSIONLESS, 13303 "crypto op session type not sessionless"); 13304 13305 /* Process crypto operation */ 13306 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 13307 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 13308 0); 13309 if (retval != TEST_SUCCESS) 13310 return retval; 13311 } else 13312 TEST_ASSERT_NOT_NULL(process_crypto_request( 13313 ts_params->valid_devs[0], ut_params->op), 13314 "failed to process sym crypto op"); 13315 13316 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 13317 13318 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13319 "crypto op status not success"); 13320 13321 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 13322 ut_params->op->sym->cipher.data.offset); 13323 13324 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 13325 13326 /* Validate obuf */ 13327 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13328 plaintext, 13329 tdata->plaintext.data, 13330 tdata->plaintext.len, 13331 "Plaintext data not as expected"); 13332 13333 TEST_ASSERT_EQUAL(ut_params->op->status, 13334 RTE_CRYPTO_OP_STATUS_SUCCESS, 13335 "Authentication failed"); 13336 return 0; 13337 } 13338 13339 static int 13340 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void) 13341 { 13342 return test_authenticated_decryption_sessionless( 13343 &gcm_test_case_5); 13344 } 13345 13346 static int 13347 test_AES_CCM_authenticated_encryption_test_case_128_1(void) 13348 { 13349 return test_authenticated_encryption(&ccm_test_case_128_1); 13350 } 13351 13352 static int 13353 test_AES_CCM_authenticated_encryption_test_case_128_2(void) 13354 { 13355 return test_authenticated_encryption(&ccm_test_case_128_2); 13356 } 13357 13358 static int 13359 test_AES_CCM_authenticated_encryption_test_case_128_3(void) 13360 { 13361 return test_authenticated_encryption(&ccm_test_case_128_3); 13362 } 13363 13364 static int 13365 test_AES_CCM_authenticated_decryption_test_case_128_1(void) 13366 { 13367 return test_authenticated_decryption(&ccm_test_case_128_1); 13368 } 13369 13370 static int 13371 test_AES_CCM_authenticated_decryption_test_case_128_2(void) 13372 { 13373 return test_authenticated_decryption(&ccm_test_case_128_2); 13374 } 13375 13376 static int 13377 test_AES_CCM_authenticated_decryption_test_case_128_3(void) 13378 { 13379 return test_authenticated_decryption(&ccm_test_case_128_3); 13380 } 13381 13382 static int 13383 test_AES_CCM_authenticated_encryption_test_case_192_1(void) 13384 { 13385 return test_authenticated_encryption(&ccm_test_case_192_1); 13386 } 13387 13388 static int 13389 test_AES_CCM_authenticated_encryption_test_case_192_2(void) 13390 { 13391 return test_authenticated_encryption(&ccm_test_case_192_2); 13392 } 13393 13394 static int 13395 test_AES_CCM_authenticated_encryption_test_case_192_3(void) 13396 { 13397 return test_authenticated_encryption(&ccm_test_case_192_3); 13398 } 13399 13400 static int 13401 test_AES_CCM_authenticated_decryption_test_case_192_1(void) 13402 { 13403 return test_authenticated_decryption(&ccm_test_case_192_1); 13404 } 13405 13406 static int 13407 test_AES_CCM_authenticated_decryption_test_case_192_2(void) 13408 { 13409 return test_authenticated_decryption(&ccm_test_case_192_2); 13410 } 13411 13412 static int 13413 test_AES_CCM_authenticated_decryption_test_case_192_3(void) 13414 { 13415 return test_authenticated_decryption(&ccm_test_case_192_3); 13416 } 13417 13418 static int 13419 test_AES_CCM_authenticated_encryption_test_case_256_1(void) 13420 { 13421 return test_authenticated_encryption(&ccm_test_case_256_1); 13422 } 13423 13424 static int 13425 test_AES_CCM_authenticated_encryption_test_case_256_2(void) 13426 { 13427 return test_authenticated_encryption(&ccm_test_case_256_2); 13428 } 13429 13430 static int 13431 test_AES_CCM_authenticated_encryption_test_case_256_3(void) 13432 { 13433 return test_authenticated_encryption(&ccm_test_case_256_3); 13434 } 13435 13436 static int 13437 test_AES_CCM_authenticated_decryption_test_case_256_1(void) 13438 { 13439 return test_authenticated_decryption(&ccm_test_case_256_1); 13440 } 13441 13442 static int 13443 test_AES_CCM_authenticated_decryption_test_case_256_2(void) 13444 { 13445 return test_authenticated_decryption(&ccm_test_case_256_2); 13446 } 13447 13448 static int 13449 test_AES_CCM_authenticated_decryption_test_case_256_3(void) 13450 { 13451 return test_authenticated_decryption(&ccm_test_case_256_3); 13452 } 13453 13454 static int 13455 test_stats(void) 13456 { 13457 struct crypto_testsuite_params *ts_params = &testsuite_params; 13458 struct rte_cryptodev_stats stats; 13459 13460 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13461 return TEST_SKIPPED; 13462 13463 /* Verify the capabilities */ 13464 struct rte_cryptodev_sym_capability_idx cap_idx; 13465 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13466 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 13467 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13468 &cap_idx) == NULL) 13469 return TEST_SKIPPED; 13470 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13471 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 13472 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13473 &cap_idx) == NULL) 13474 return TEST_SKIPPED; 13475 13476 if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 13477 == -ENOTSUP) 13478 return TEST_SKIPPED; 13479 13480 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 13481 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 13482 &stats) == -ENODEV), 13483 "rte_cryptodev_stats_get invalid dev failed"); 13484 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 13485 "rte_cryptodev_stats_get invalid Param failed"); 13486 13487 /* Test expected values */ 13488 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 13489 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 13490 &stats), 13491 "rte_cryptodev_stats_get failed"); 13492 TEST_ASSERT((stats.enqueued_count == 1), 13493 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 13494 TEST_ASSERT((stats.dequeued_count == 1), 13495 "rte_cryptodev_stats_get returned unexpected dequeued stat"); 13496 TEST_ASSERT((stats.enqueue_err_count == 0), 13497 "rte_cryptodev_stats_get returned unexpected enqueued error count stat"); 13498 TEST_ASSERT((stats.dequeue_err_count == 0), 13499 "rte_cryptodev_stats_get returned unexpected dequeued error count stat"); 13500 13501 /* invalid device but should ignore and not reset device stats*/ 13502 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 13503 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 13504 &stats), 13505 "rte_cryptodev_stats_get failed"); 13506 TEST_ASSERT((stats.enqueued_count == 1), 13507 "rte_cryptodev_stats_get returned unexpected enqueued stat after invalid reset"); 13508 13509 /* check that a valid reset clears stats */ 13510 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 13511 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 13512 &stats), 13513 "rte_cryptodev_stats_get failed"); 13514 TEST_ASSERT((stats.enqueued_count == 0), 13515 "rte_cryptodev_stats_get returned unexpected enqueued stat after valid reset"); 13516 TEST_ASSERT((stats.dequeued_count == 0), 13517 "rte_cryptodev_stats_get returned unexpected dequeued stat after valid reset"); 13518 13519 return TEST_SUCCESS; 13520 } 13521 13522 static int 13523 test_device_reconfigure(void) 13524 { 13525 struct crypto_testsuite_params *ts_params = &testsuite_params; 13526 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 13527 struct rte_cryptodev_qp_conf qp_conf = { 13528 .nb_descriptors = MAX_NUM_OPS_INFLIGHT, 13529 .mp_session = ts_params->session_mpool 13530 }; 13531 uint16_t qp_id, dev_id, num_devs = 0; 13532 13533 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 13534 "Need at least %d devices for test", 1); 13535 13536 dev_id = ts_params->valid_devs[0]; 13537 13538 /* Stop the device in case it's started so it can be configured */ 13539 rte_cryptodev_stop(dev_id); 13540 13541 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 13542 "Failed test for rte_cryptodev_configure: " 13543 "dev_num %u", dev_id); 13544 13545 /* Reconfigure with same configure params */ 13546 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 13547 "Failed test for rte_cryptodev_configure: " 13548 "dev_num %u", dev_id); 13549 13550 /* Reconfigure with just one queue pair */ 13551 ts_params->conf.nb_queue_pairs = 1; 13552 13553 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 13554 &ts_params->conf), 13555 "Failed to configure cryptodev: dev_id %u, qp_id %u", 13556 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 13557 13558 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 13559 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 13560 ts_params->valid_devs[0], qp_id, &qp_conf, 13561 rte_cryptodev_socket_id( 13562 ts_params->valid_devs[0])), 13563 "Failed test for " 13564 "rte_cryptodev_queue_pair_setup: num_inflights " 13565 "%u on qp %u on cryptodev %u", 13566 qp_conf.nb_descriptors, qp_id, 13567 ts_params->valid_devs[0]); 13568 } 13569 13570 /* Reconfigure with max number of queue pairs */ 13571 ts_params->conf.nb_queue_pairs = orig_nb_qps; 13572 13573 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 13574 &ts_params->conf), 13575 "Failed to configure cryptodev: dev_id %u, qp_id %u", 13576 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 13577 13578 qp_conf.mp_session = ts_params->session_mpool; 13579 13580 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 13581 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 13582 ts_params->valid_devs[0], qp_id, &qp_conf, 13583 rte_cryptodev_socket_id( 13584 ts_params->valid_devs[0])), 13585 "Failed test for " 13586 "rte_cryptodev_queue_pair_setup: num_inflights " 13587 "%u on qp %u on cryptodev %u", 13588 qp_conf.nb_descriptors, qp_id, 13589 ts_params->valid_devs[0]); 13590 } 13591 13592 /* Start the device */ 13593 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 13594 "Failed to start cryptodev %u", 13595 ts_params->valid_devs[0]); 13596 13597 /* Test expected values */ 13598 return test_AES_CBC_HMAC_SHA1_encrypt_digest(); 13599 } 13600 13601 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 13602 struct crypto_unittest_params *ut_params, 13603 enum rte_crypto_auth_operation op, 13604 const struct HMAC_MD5_vector *test_case) 13605 { 13606 uint8_t key[64]; 13607 13608 memcpy(key, test_case->key.data, test_case->key.len); 13609 13610 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13611 ut_params->auth_xform.next = NULL; 13612 ut_params->auth_xform.auth.op = op; 13613 13614 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 13615 13616 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 13617 ut_params->auth_xform.auth.key.length = test_case->key.len; 13618 ut_params->auth_xform.auth.key.data = key; 13619 13620 ut_params->sess = rte_cryptodev_sym_session_create( 13621 ts_params->valid_devs[0], &ut_params->auth_xform, 13622 ts_params->session_mpool); 13623 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 13624 return TEST_SKIPPED; 13625 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13626 13627 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13628 13629 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13630 rte_pktmbuf_tailroom(ut_params->ibuf)); 13631 13632 return 0; 13633 } 13634 13635 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 13636 const struct HMAC_MD5_vector *test_case, 13637 uint8_t **plaintext) 13638 { 13639 uint16_t plaintext_pad_len; 13640 13641 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 13642 13643 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 13644 16); 13645 13646 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13647 plaintext_pad_len); 13648 memcpy(*plaintext, test_case->plaintext.data, 13649 test_case->plaintext.len); 13650 13651 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 13652 ut_params->ibuf, MD5_DIGEST_LEN); 13653 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13654 "no room to append digest"); 13655 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 13656 ut_params->ibuf, plaintext_pad_len); 13657 13658 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 13659 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 13660 test_case->auth_tag.len); 13661 } 13662 13663 sym_op->auth.data.offset = 0; 13664 sym_op->auth.data.length = test_case->plaintext.len; 13665 13666 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13667 ut_params->op->sym->m_src = ut_params->ibuf; 13668 13669 return 0; 13670 } 13671 13672 static int 13673 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 13674 { 13675 uint16_t plaintext_pad_len; 13676 uint8_t *plaintext, *auth_tag; 13677 int ret; 13678 13679 struct crypto_testsuite_params *ts_params = &testsuite_params; 13680 struct crypto_unittest_params *ut_params = &unittest_params; 13681 struct rte_cryptodev_info dev_info; 13682 13683 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13684 uint64_t feat_flags = dev_info.feature_flags; 13685 13686 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13687 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13688 printf("Device doesn't support RAW data-path APIs.\n"); 13689 return TEST_SKIPPED; 13690 } 13691 13692 /* Verify the capabilities */ 13693 struct rte_cryptodev_sym_capability_idx cap_idx; 13694 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13695 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 13696 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13697 &cap_idx) == NULL) 13698 return TEST_SKIPPED; 13699 13700 if (MD5_HMAC_create_session(ts_params, ut_params, 13701 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 13702 return TEST_FAILED; 13703 13704 /* Generate Crypto op data structure */ 13705 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13706 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13707 TEST_ASSERT_NOT_NULL(ut_params->op, 13708 "Failed to allocate symmetric crypto operation struct"); 13709 13710 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 13711 16); 13712 13713 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 13714 return TEST_FAILED; 13715 13716 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13717 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13718 ut_params->op); 13719 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 13720 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 0); 13721 if (ret != TEST_SUCCESS) 13722 return ret; 13723 } else 13724 TEST_ASSERT_NOT_NULL( 13725 process_crypto_request(ts_params->valid_devs[0], 13726 ut_params->op), 13727 "failed to process sym crypto op"); 13728 13729 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13730 "crypto op processing failed"); 13731 13732 if (ut_params->op->sym->m_dst) { 13733 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 13734 uint8_t *, plaintext_pad_len); 13735 } else { 13736 auth_tag = plaintext + plaintext_pad_len; 13737 } 13738 13739 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13740 auth_tag, 13741 test_case->auth_tag.data, 13742 test_case->auth_tag.len, 13743 "HMAC_MD5 generated tag not as expected"); 13744 13745 return TEST_SUCCESS; 13746 } 13747 13748 static int 13749 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 13750 { 13751 uint8_t *plaintext; 13752 int ret; 13753 13754 struct crypto_testsuite_params *ts_params = &testsuite_params; 13755 struct crypto_unittest_params *ut_params = &unittest_params; 13756 struct rte_cryptodev_info dev_info; 13757 13758 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13759 uint64_t feat_flags = dev_info.feature_flags; 13760 13761 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13762 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13763 printf("Device doesn't support RAW data-path APIs.\n"); 13764 return TEST_SKIPPED; 13765 } 13766 13767 /* Verify the capabilities */ 13768 struct rte_cryptodev_sym_capability_idx cap_idx; 13769 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13770 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 13771 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13772 &cap_idx) == NULL) 13773 return TEST_SKIPPED; 13774 13775 if (MD5_HMAC_create_session(ts_params, ut_params, 13776 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 13777 return TEST_FAILED; 13778 } 13779 13780 /* Generate Crypto op data structure */ 13781 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13782 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13783 TEST_ASSERT_NOT_NULL(ut_params->op, 13784 "Failed to allocate symmetric crypto operation struct"); 13785 13786 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 13787 return TEST_FAILED; 13788 13789 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13790 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13791 ut_params->op); 13792 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 13793 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 0); 13794 if (ret != TEST_SUCCESS) 13795 return ret; 13796 } else 13797 TEST_ASSERT_NOT_NULL( 13798 process_crypto_request(ts_params->valid_devs[0], 13799 ut_params->op), 13800 "failed to process sym crypto op"); 13801 13802 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13803 "HMAC_MD5 crypto op processing failed"); 13804 13805 return TEST_SUCCESS; 13806 } 13807 13808 static int 13809 test_MD5_HMAC_generate_case_1(void) 13810 { 13811 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 13812 } 13813 13814 static int 13815 test_MD5_HMAC_verify_case_1(void) 13816 { 13817 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 13818 } 13819 13820 static int 13821 test_MD5_HMAC_generate_case_2(void) 13822 { 13823 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 13824 } 13825 13826 static int 13827 test_MD5_HMAC_verify_case_2(void) 13828 { 13829 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 13830 } 13831 13832 static int 13833 test_multi_session(void) 13834 { 13835 struct crypto_testsuite_params *ts_params = &testsuite_params; 13836 struct crypto_unittest_params *ut_params = &unittest_params; 13837 struct rte_cryptodev_info dev_info; 13838 int i, nb_sess, ret = TEST_SUCCESS; 13839 void **sessions; 13840 13841 /* Verify the capabilities */ 13842 struct rte_cryptodev_sym_capability_idx cap_idx; 13843 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13844 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 13845 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13846 &cap_idx) == NULL) 13847 return TEST_SKIPPED; 13848 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13849 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 13850 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13851 &cap_idx) == NULL) 13852 return TEST_SKIPPED; 13853 13854 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 13855 aes_cbc_key, hmac_sha512_key); 13856 13857 13858 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13859 13860 sessions = rte_malloc(NULL, 13861 sizeof(void *) * 13862 (MAX_NB_SESSIONS + 1), 0); 13863 13864 /* Create multiple crypto sessions*/ 13865 for (i = 0; i < MAX_NB_SESSIONS; i++) { 13866 sessions[i] = rte_cryptodev_sym_session_create( 13867 ts_params->valid_devs[0], &ut_params->auth_xform, 13868 ts_params->session_mpool); 13869 if (sessions[i] == NULL && rte_errno == ENOTSUP) { 13870 nb_sess = i; 13871 ret = TEST_SKIPPED; 13872 break; 13873 } 13874 13875 TEST_ASSERT_NOT_NULL(sessions[i], 13876 "Session creation failed at session number %u", 13877 i); 13878 13879 /* Attempt to send a request on each session */ 13880 ret = test_AES_CBC_HMAC_SHA512_decrypt_perform( 13881 sessions[i], 13882 ut_params, 13883 ts_params, 13884 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 13885 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 13886 aes_cbc_iv); 13887 13888 /* free crypto operation structure */ 13889 rte_crypto_op_free(ut_params->op); 13890 13891 /* 13892 * free mbuf - both obuf and ibuf are usually the same, 13893 * so check if they point at the same address is necessary, 13894 * to avoid freeing the mbuf twice. 13895 */ 13896 if (ut_params->obuf) { 13897 rte_pktmbuf_free(ut_params->obuf); 13898 if (ut_params->ibuf == ut_params->obuf) 13899 ut_params->ibuf = 0; 13900 ut_params->obuf = 0; 13901 } 13902 if (ut_params->ibuf) { 13903 rte_pktmbuf_free(ut_params->ibuf); 13904 ut_params->ibuf = 0; 13905 } 13906 13907 if (ret != TEST_SUCCESS) { 13908 i++; 13909 break; 13910 } 13911 } 13912 13913 nb_sess = i; 13914 13915 for (i = 0; i < nb_sess; i++) { 13916 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 13917 sessions[i]); 13918 } 13919 13920 rte_free(sessions); 13921 13922 if (ret != TEST_SKIPPED) 13923 TEST_ASSERT_SUCCESS(ret, "Failed to perform decrypt on request number %u.", i - 1); 13924 13925 return ret; 13926 } 13927 13928 struct multi_session_params { 13929 struct crypto_unittest_params ut_params; 13930 uint8_t *cipher_key; 13931 uint8_t *hmac_key; 13932 const uint8_t *cipher; 13933 const uint8_t *digest; 13934 uint8_t *iv; 13935 }; 13936 13937 #define MB_SESSION_NUMBER 3 13938 13939 static int 13940 test_multi_session_random_usage(void) 13941 { 13942 struct crypto_testsuite_params *ts_params = &testsuite_params; 13943 struct rte_cryptodev_info dev_info; 13944 int index = 0, ret = TEST_SUCCESS; 13945 uint32_t nb_sess, i, j; 13946 void **sessions; 13947 struct multi_session_params ut_paramz[] = { 13948 13949 { 13950 .cipher_key = ms_aes_cbc_key0, 13951 .hmac_key = ms_hmac_key0, 13952 .cipher = ms_aes_cbc_cipher0, 13953 .digest = ms_hmac_digest0, 13954 .iv = ms_aes_cbc_iv0 13955 }, 13956 { 13957 .cipher_key = ms_aes_cbc_key1, 13958 .hmac_key = ms_hmac_key1, 13959 .cipher = ms_aes_cbc_cipher1, 13960 .digest = ms_hmac_digest1, 13961 .iv = ms_aes_cbc_iv1 13962 }, 13963 { 13964 .cipher_key = ms_aes_cbc_key2, 13965 .hmac_key = ms_hmac_key2, 13966 .cipher = ms_aes_cbc_cipher2, 13967 .digest = ms_hmac_digest2, 13968 .iv = ms_aes_cbc_iv2 13969 }, 13970 13971 }; 13972 13973 /* Verify the capabilities */ 13974 struct rte_cryptodev_sym_capability_idx cap_idx; 13975 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13976 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 13977 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13978 &cap_idx) == NULL) 13979 return TEST_SKIPPED; 13980 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13981 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 13982 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13983 &cap_idx) == NULL) 13984 return TEST_SKIPPED; 13985 13986 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13987 13988 sessions = rte_malloc(NULL, (sizeof(void *) 13989 * MAX_NB_SESSIONS) + 1, 0); 13990 13991 for (i = 0; i < MB_SESSION_NUMBER; i++) { 13992 13993 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params, 13994 sizeof(struct crypto_unittest_params)); 13995 13996 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 13997 &ut_paramz[i].ut_params, 13998 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 13999 14000 /* Create multiple crypto sessions*/ 14001 sessions[i] = rte_cryptodev_sym_session_create( 14002 ts_params->valid_devs[0], 14003 &ut_paramz[i].ut_params.auth_xform, 14004 ts_params->session_mpool); 14005 if (sessions[i] == NULL && rte_errno == ENOTSUP) { 14006 nb_sess = i; 14007 ret = TEST_SKIPPED; 14008 goto session_clear; 14009 } 14010 14011 TEST_ASSERT_NOT_NULL(sessions[i], 14012 "Session creation failed at session number %u", 14013 i); 14014 } 14015 14016 nb_sess = i; 14017 14018 srand(time(NULL)); 14019 for (i = 0; i < 40000; i++) { 14020 14021 j = rand() % MB_SESSION_NUMBER; 14022 14023 ret = test_AES_CBC_HMAC_SHA512_decrypt_perform( 14024 sessions[j], 14025 &ut_paramz[j].ut_params, 14026 ts_params, ut_paramz[j].cipher, 14027 ut_paramz[j].digest, 14028 ut_paramz[j].iv); 14029 14030 rte_crypto_op_free(ut_paramz[j].ut_params.op); 14031 14032 /* 14033 * free mbuf - both obuf and ibuf are usually the same, 14034 * so check if they point at the same address is necessary, 14035 * to avoid freeing the mbuf twice. 14036 */ 14037 if (ut_paramz[j].ut_params.obuf) { 14038 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 14039 if (ut_paramz[j].ut_params.ibuf 14040 == ut_paramz[j].ut_params.obuf) 14041 ut_paramz[j].ut_params.ibuf = 0; 14042 ut_paramz[j].ut_params.obuf = 0; 14043 } 14044 if (ut_paramz[j].ut_params.ibuf) { 14045 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 14046 ut_paramz[j].ut_params.ibuf = 0; 14047 } 14048 14049 if (ret != TEST_SKIPPED) { 14050 index = i; 14051 break; 14052 } 14053 } 14054 14055 session_clear: 14056 for (i = 0; i < nb_sess; i++) { 14057 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 14058 sessions[i]); 14059 } 14060 14061 rte_free(sessions); 14062 14063 if (ret != TEST_SKIPPED) 14064 TEST_ASSERT_SUCCESS(ret, "Failed to perform decrypt on request number %u.", index); 14065 14066 return TEST_SUCCESS; 14067 } 14068 14069 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab, 14070 0xab, 0xab, 0xab, 0xab, 14071 0xab, 0xab, 0xab, 0xab, 14072 0xab, 0xab, 0xab, 0xab}; 14073 14074 static int 14075 test_null_invalid_operation(void) 14076 { 14077 struct crypto_testsuite_params *ts_params = &testsuite_params; 14078 struct crypto_unittest_params *ut_params = &unittest_params; 14079 14080 /* This test is for NULL PMD only */ 14081 if (gbl_driver_id != rte_cryptodev_driver_id_get( 14082 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 14083 return TEST_SKIPPED; 14084 14085 /* Setup Cipher Parameters */ 14086 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 14087 ut_params->cipher_xform.next = NULL; 14088 14089 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 14090 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 14091 14092 /* Create Crypto session*/ 14093 ut_params->sess = rte_cryptodev_sym_session_create( 14094 ts_params->valid_devs[0], &ut_params->cipher_xform, 14095 ts_params->session_mpool); 14096 TEST_ASSERT(ut_params->sess == NULL, 14097 "Session creation succeeded unexpectedly"); 14098 14099 /* Setup HMAC Parameters */ 14100 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14101 ut_params->auth_xform.next = NULL; 14102 14103 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 14104 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 14105 14106 /* Create Crypto session*/ 14107 ut_params->sess = rte_cryptodev_sym_session_create( 14108 ts_params->valid_devs[0], &ut_params->auth_xform, 14109 ts_params->session_mpool); 14110 TEST_ASSERT(ut_params->sess == NULL, 14111 "Session creation succeeded unexpectedly"); 14112 14113 return TEST_SUCCESS; 14114 } 14115 14116 14117 #define NULL_BURST_LENGTH (32) 14118 14119 static int 14120 test_null_burst_operation(void) 14121 { 14122 struct crypto_testsuite_params *ts_params = &testsuite_params; 14123 struct crypto_unittest_params *ut_params = &unittest_params; 14124 14125 unsigned i, burst_len = NULL_BURST_LENGTH; 14126 14127 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 14128 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 14129 14130 /* This test is for NULL PMD only */ 14131 if (gbl_driver_id != rte_cryptodev_driver_id_get( 14132 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 14133 return TEST_SKIPPED; 14134 14135 /* Setup Cipher Parameters */ 14136 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 14137 ut_params->cipher_xform.next = &ut_params->auth_xform; 14138 14139 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 14140 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 14141 14142 /* Setup HMAC Parameters */ 14143 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14144 ut_params->auth_xform.next = NULL; 14145 14146 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 14147 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 14148 14149 /* Create Crypto session*/ 14150 ut_params->sess = rte_cryptodev_sym_session_create( 14151 ts_params->valid_devs[0], 14152 &ut_params->auth_xform, 14153 ts_params->session_mpool); 14154 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 14155 return TEST_SKIPPED; 14156 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 14157 14158 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 14159 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 14160 burst_len, "failed to generate burst of crypto ops"); 14161 14162 /* Generate an operation for each mbuf in burst */ 14163 for (i = 0; i < burst_len; i++) { 14164 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14165 14166 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 14167 14168 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 14169 sizeof(unsigned)); 14170 *data = i; 14171 14172 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 14173 14174 burst[i]->sym->m_src = m; 14175 } 14176 14177 /* Process crypto operation */ 14178 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 14179 0, burst, burst_len), 14180 burst_len, 14181 "Error enqueuing burst"); 14182 14183 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 14184 0, burst_dequeued, burst_len), 14185 burst_len, 14186 "Error dequeuing burst"); 14187 14188 14189 for (i = 0; i < burst_len; i++) { 14190 TEST_ASSERT_EQUAL( 14191 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 14192 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 14193 uint32_t *), 14194 "data not as expected"); 14195 14196 rte_pktmbuf_free(burst[i]->sym->m_src); 14197 rte_crypto_op_free(burst[i]); 14198 } 14199 14200 return TEST_SUCCESS; 14201 } 14202 14203 static uint16_t 14204 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 14205 uint16_t nb_ops, void *user_param) 14206 { 14207 RTE_SET_USED(dev_id); 14208 RTE_SET_USED(qp_id); 14209 RTE_SET_USED(ops); 14210 RTE_SET_USED(user_param); 14211 14212 printf("crypto enqueue callback called\n"); 14213 return nb_ops; 14214 } 14215 14216 static uint16_t 14217 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 14218 uint16_t nb_ops, void *user_param) 14219 { 14220 RTE_SET_USED(dev_id); 14221 RTE_SET_USED(qp_id); 14222 RTE_SET_USED(ops); 14223 RTE_SET_USED(user_param); 14224 14225 printf("crypto dequeue callback called\n"); 14226 return nb_ops; 14227 } 14228 14229 /* 14230 * Thread using enqueue/dequeue callback with RCU. 14231 */ 14232 static int 14233 test_enqdeq_callback_thread(void *arg) 14234 { 14235 RTE_SET_USED(arg); 14236 /* DP thread calls rte_cryptodev_enqueue_burst()/ 14237 * rte_cryptodev_dequeue_burst() and invokes callback. 14238 */ 14239 test_null_burst_operation(); 14240 return 0; 14241 } 14242 14243 static int 14244 test_enq_callback_setup(void) 14245 { 14246 struct crypto_testsuite_params *ts_params = &testsuite_params; 14247 struct rte_cryptodev_info dev_info; 14248 struct rte_cryptodev_qp_conf qp_conf = { 14249 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 14250 }; 14251 14252 struct rte_cryptodev_cb *cb; 14253 uint16_t qp_id = 0; 14254 14255 /* Stop the device in case it's started so it can be configured */ 14256 rte_cryptodev_stop(ts_params->valid_devs[0]); 14257 14258 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14259 14260 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 14261 &ts_params->conf), 14262 "Failed to configure cryptodev %u", 14263 ts_params->valid_devs[0]); 14264 14265 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 14266 qp_conf.mp_session = ts_params->session_mpool; 14267 14268 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 14269 ts_params->valid_devs[0], qp_id, &qp_conf, 14270 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 14271 "Failed test for " 14272 "rte_cryptodev_queue_pair_setup: num_inflights " 14273 "%u on qp %u on cryptodev %u", 14274 qp_conf.nb_descriptors, qp_id, 14275 ts_params->valid_devs[0]); 14276 14277 /* Test with invalid crypto device */ 14278 cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS, 14279 qp_id, test_enq_callback, NULL); 14280 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 14281 "cryptodev %u did not fail", 14282 qp_id, RTE_CRYPTO_MAX_DEVS); 14283 14284 /* Test with invalid queue pair */ 14285 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 14286 dev_info.max_nb_queue_pairs + 1, 14287 test_enq_callback, NULL); 14288 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 14289 "cryptodev %u did not fail", 14290 dev_info.max_nb_queue_pairs + 1, 14291 ts_params->valid_devs[0]); 14292 14293 /* Test with NULL callback */ 14294 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 14295 qp_id, NULL, NULL); 14296 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 14297 "cryptodev %u did not fail", 14298 qp_id, ts_params->valid_devs[0]); 14299 14300 /* Test with valid configuration */ 14301 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 14302 qp_id, test_enq_callback, NULL); 14303 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 14304 "qp %u on cryptodev %u", 14305 qp_id, ts_params->valid_devs[0]); 14306 14307 rte_cryptodev_start(ts_params->valid_devs[0]); 14308 14309 /* Launch a thread */ 14310 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 14311 rte_get_next_lcore(-1, 1, 0)); 14312 14313 /* Wait until reader exited. */ 14314 rte_eal_mp_wait_lcore(); 14315 14316 /* Test with invalid crypto device */ 14317 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 14318 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 14319 "Expected call to fail as crypto device is invalid"); 14320 14321 /* Test with invalid queue pair */ 14322 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 14323 ts_params->valid_devs[0], 14324 dev_info.max_nb_queue_pairs + 1, cb), 14325 "Expected call to fail as queue pair is invalid"); 14326 14327 /* Test with NULL callback */ 14328 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 14329 ts_params->valid_devs[0], qp_id, NULL), 14330 "Expected call to fail as callback is NULL"); 14331 14332 /* Test with valid configuration */ 14333 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback( 14334 ts_params->valid_devs[0], qp_id, cb), 14335 "Failed test to remove callback on " 14336 "qp %u on cryptodev %u", 14337 qp_id, ts_params->valid_devs[0]); 14338 14339 return TEST_SUCCESS; 14340 } 14341 14342 static int 14343 test_deq_callback_setup(void) 14344 { 14345 struct crypto_testsuite_params *ts_params = &testsuite_params; 14346 struct rte_cryptodev_info dev_info; 14347 struct rte_cryptodev_qp_conf qp_conf = { 14348 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 14349 }; 14350 14351 struct rte_cryptodev_cb *cb; 14352 uint16_t qp_id = 0; 14353 14354 /* Stop the device in case it's started so it can be configured */ 14355 rte_cryptodev_stop(ts_params->valid_devs[0]); 14356 14357 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14358 14359 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 14360 &ts_params->conf), 14361 "Failed to configure cryptodev %u", 14362 ts_params->valid_devs[0]); 14363 14364 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 14365 qp_conf.mp_session = ts_params->session_mpool; 14366 14367 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 14368 ts_params->valid_devs[0], qp_id, &qp_conf, 14369 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 14370 "Failed test for " 14371 "rte_cryptodev_queue_pair_setup: num_inflights " 14372 "%u on qp %u on cryptodev %u", 14373 qp_conf.nb_descriptors, qp_id, 14374 ts_params->valid_devs[0]); 14375 14376 /* Test with invalid crypto device */ 14377 cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS, 14378 qp_id, test_deq_callback, NULL); 14379 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 14380 "cryptodev %u did not fail", 14381 qp_id, RTE_CRYPTO_MAX_DEVS); 14382 14383 /* Test with invalid queue pair */ 14384 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 14385 dev_info.max_nb_queue_pairs + 1, 14386 test_deq_callback, NULL); 14387 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 14388 "cryptodev %u did not fail", 14389 dev_info.max_nb_queue_pairs + 1, 14390 ts_params->valid_devs[0]); 14391 14392 /* Test with NULL callback */ 14393 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 14394 qp_id, NULL, NULL); 14395 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 14396 "cryptodev %u did not fail", 14397 qp_id, ts_params->valid_devs[0]); 14398 14399 /* Test with valid configuration */ 14400 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 14401 qp_id, test_deq_callback, NULL); 14402 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 14403 "qp %u on cryptodev %u", 14404 qp_id, ts_params->valid_devs[0]); 14405 14406 rte_cryptodev_start(ts_params->valid_devs[0]); 14407 14408 /* Launch a thread */ 14409 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 14410 rte_get_next_lcore(-1, 1, 0)); 14411 14412 /* Wait until reader exited. */ 14413 rte_eal_mp_wait_lcore(); 14414 14415 /* Test with invalid crypto device */ 14416 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 14417 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 14418 "Expected call to fail as crypto device is invalid"); 14419 14420 /* Test with invalid queue pair */ 14421 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 14422 ts_params->valid_devs[0], 14423 dev_info.max_nb_queue_pairs + 1, cb), 14424 "Expected call to fail as queue pair is invalid"); 14425 14426 /* Test with NULL callback */ 14427 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 14428 ts_params->valid_devs[0], qp_id, NULL), 14429 "Expected call to fail as callback is NULL"); 14430 14431 /* Test with valid configuration */ 14432 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback( 14433 ts_params->valid_devs[0], qp_id, cb), 14434 "Failed test to remove callback on " 14435 "qp %u on cryptodev %u", 14436 qp_id, ts_params->valid_devs[0]); 14437 14438 return TEST_SUCCESS; 14439 } 14440 14441 static void 14442 generate_gmac_large_plaintext(uint8_t *data) 14443 { 14444 uint16_t i; 14445 14446 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 14447 memcpy(&data[i], &data[0], 32); 14448 } 14449 14450 static int 14451 create_gmac_operation(enum rte_crypto_auth_operation op, 14452 const struct gmac_test_data *tdata) 14453 { 14454 struct crypto_testsuite_params *ts_params = &testsuite_params; 14455 struct crypto_unittest_params *ut_params = &unittest_params; 14456 struct rte_crypto_sym_op *sym_op; 14457 14458 uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 14459 14460 /* Generate Crypto op data structure */ 14461 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 14462 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 14463 TEST_ASSERT_NOT_NULL(ut_params->op, 14464 "Failed to allocate symmetric crypto operation struct"); 14465 14466 sym_op = ut_params->op->sym; 14467 14468 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 14469 ut_params->ibuf, tdata->gmac_tag.len); 14470 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 14471 "no room to append digest"); 14472 14473 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 14474 ut_params->ibuf, plaintext_pad_len); 14475 14476 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 14477 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 14478 tdata->gmac_tag.len); 14479 debug_hexdump(stdout, "digest:", 14480 sym_op->auth.digest.data, 14481 tdata->gmac_tag.len); 14482 } 14483 14484 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 14485 uint8_t *, IV_OFFSET); 14486 14487 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 14488 14489 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 14490 14491 sym_op->cipher.data.length = 0; 14492 sym_op->cipher.data.offset = 0; 14493 14494 sym_op->auth.data.offset = 0; 14495 sym_op->auth.data.length = tdata->plaintext.len; 14496 14497 return 0; 14498 } 14499 14500 static int 14501 create_gmac_operation_sgl(enum rte_crypto_auth_operation op, 14502 const struct gmac_test_data *tdata, 14503 void *digest_mem, uint64_t digest_phys) 14504 { 14505 struct crypto_testsuite_params *ts_params = &testsuite_params; 14506 struct crypto_unittest_params *ut_params = &unittest_params; 14507 struct rte_crypto_sym_op *sym_op; 14508 14509 /* Generate Crypto op data structure */ 14510 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 14511 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 14512 TEST_ASSERT_NOT_NULL(ut_params->op, 14513 "Failed to allocate symmetric crypto operation struct"); 14514 14515 sym_op = ut_params->op->sym; 14516 14517 sym_op->auth.digest.data = digest_mem; 14518 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 14519 "no room to append digest"); 14520 14521 sym_op->auth.digest.phys_addr = digest_phys; 14522 14523 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 14524 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 14525 tdata->gmac_tag.len); 14526 debug_hexdump(stdout, "digest:", 14527 sym_op->auth.digest.data, 14528 tdata->gmac_tag.len); 14529 } 14530 14531 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 14532 uint8_t *, IV_OFFSET); 14533 14534 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 14535 14536 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 14537 14538 sym_op->cipher.data.length = 0; 14539 sym_op->cipher.data.offset = 0; 14540 14541 sym_op->auth.data.offset = 0; 14542 sym_op->auth.data.length = tdata->plaintext.len; 14543 14544 return 0; 14545 } 14546 14547 static int create_gmac_session(uint8_t dev_id, 14548 const struct gmac_test_data *tdata, 14549 enum rte_crypto_auth_operation auth_op) 14550 { 14551 uint8_t auth_key[tdata->key.len]; 14552 14553 struct crypto_testsuite_params *ts_params = &testsuite_params; 14554 struct crypto_unittest_params *ut_params = &unittest_params; 14555 14556 memcpy(auth_key, tdata->key.data, tdata->key.len); 14557 14558 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14559 ut_params->auth_xform.next = NULL; 14560 14561 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 14562 ut_params->auth_xform.auth.op = auth_op; 14563 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 14564 ut_params->auth_xform.auth.key.length = tdata->key.len; 14565 ut_params->auth_xform.auth.key.data = auth_key; 14566 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 14567 ut_params->auth_xform.auth.iv.length = tdata->iv.len; 14568 14569 14570 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 14571 &ut_params->auth_xform, ts_params->session_mpool); 14572 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 14573 return TEST_SKIPPED; 14574 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 14575 14576 return 0; 14577 } 14578 14579 static int 14580 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 14581 { 14582 struct crypto_testsuite_params *ts_params = &testsuite_params; 14583 struct crypto_unittest_params *ut_params = &unittest_params; 14584 struct rte_cryptodev_info dev_info; 14585 14586 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14587 uint64_t feat_flags = dev_info.feature_flags; 14588 14589 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14590 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14591 printf("Device doesn't support RAW data-path APIs.\n"); 14592 return TEST_SKIPPED; 14593 } 14594 14595 int retval; 14596 14597 uint8_t *auth_tag, *plaintext; 14598 uint16_t plaintext_pad_len; 14599 14600 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 14601 "No GMAC length in the source data"); 14602 14603 /* Verify the capabilities */ 14604 struct rte_cryptodev_sym_capability_idx cap_idx; 14605 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14606 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 14607 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14608 &cap_idx) == NULL) 14609 return TEST_SKIPPED; 14610 14611 retval = create_gmac_session(ts_params->valid_devs[0], 14612 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 14613 14614 if (retval == TEST_SKIPPED) 14615 return TEST_SKIPPED; 14616 if (retval < 0) 14617 return retval; 14618 14619 if (tdata->plaintext.len > MBUF_SIZE) 14620 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 14621 else 14622 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14623 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14624 "Failed to allocate input buffer in mempool"); 14625 14626 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14627 rte_pktmbuf_tailroom(ut_params->ibuf)); 14628 14629 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 14630 /* 14631 * Runtime generate the large plain text instead of use hard code 14632 * plain text vector. It is done to avoid create huge source file 14633 * with the test vector. 14634 */ 14635 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 14636 generate_gmac_large_plaintext(tdata->plaintext.data); 14637 14638 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14639 plaintext_pad_len); 14640 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14641 14642 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 14643 debug_hexdump(stdout, "plaintext:", plaintext, 14644 tdata->plaintext.len); 14645 14646 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 14647 tdata); 14648 14649 if (retval < 0) 14650 return retval; 14651 14652 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14653 14654 ut_params->op->sym->m_src = ut_params->ibuf; 14655 14656 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14657 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14658 ut_params->op); 14659 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 14660 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 14661 0); 14662 if (retval != TEST_SUCCESS) 14663 return retval; 14664 } else 14665 TEST_ASSERT_NOT_NULL( 14666 process_crypto_request(ts_params->valid_devs[0], 14667 ut_params->op), "failed to process sym crypto op"); 14668 14669 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14670 "crypto op processing failed"); 14671 14672 if (ut_params->op->sym->m_dst) { 14673 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 14674 uint8_t *, plaintext_pad_len); 14675 } else { 14676 auth_tag = plaintext + plaintext_pad_len; 14677 } 14678 14679 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 14680 14681 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14682 auth_tag, 14683 tdata->gmac_tag.data, 14684 tdata->gmac_tag.len, 14685 "GMAC Generated auth tag not as expected"); 14686 14687 return 0; 14688 } 14689 14690 static int 14691 test_AES_GMAC_authentication_test_case_1(void) 14692 { 14693 return test_AES_GMAC_authentication(&gmac_test_case_1); 14694 } 14695 14696 static int 14697 test_AES_GMAC_authentication_test_case_2(void) 14698 { 14699 return test_AES_GMAC_authentication(&gmac_test_case_2); 14700 } 14701 14702 static int 14703 test_AES_GMAC_authentication_test_case_3(void) 14704 { 14705 return test_AES_GMAC_authentication(&gmac_test_case_3); 14706 } 14707 14708 static int 14709 test_AES_GMAC_authentication_test_case_4(void) 14710 { 14711 return test_AES_GMAC_authentication(&gmac_test_case_4); 14712 } 14713 14714 static int 14715 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 14716 { 14717 struct crypto_testsuite_params *ts_params = &testsuite_params; 14718 struct crypto_unittest_params *ut_params = &unittest_params; 14719 int retval; 14720 uint32_t plaintext_pad_len; 14721 uint8_t *plaintext; 14722 struct rte_cryptodev_info dev_info; 14723 14724 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14725 uint64_t feat_flags = dev_info.feature_flags; 14726 14727 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14728 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14729 printf("Device doesn't support RAW data-path APIs.\n"); 14730 return TEST_SKIPPED; 14731 } 14732 14733 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 14734 "No GMAC length in the source data"); 14735 14736 /* Verify the capabilities */ 14737 struct rte_cryptodev_sym_capability_idx cap_idx; 14738 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14739 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 14740 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14741 &cap_idx) == NULL) 14742 return TEST_SKIPPED; 14743 14744 retval = create_gmac_session(ts_params->valid_devs[0], 14745 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 14746 14747 if (retval == TEST_SKIPPED) 14748 return TEST_SKIPPED; 14749 if (retval < 0) 14750 return retval; 14751 14752 if (tdata->plaintext.len > MBUF_SIZE) 14753 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 14754 else 14755 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14756 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14757 "Failed to allocate input buffer in mempool"); 14758 14759 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14760 rte_pktmbuf_tailroom(ut_params->ibuf)); 14761 14762 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 14763 14764 /* 14765 * Runtime generate the large plain text instead of use hard code 14766 * plain text vector. It is done to avoid create huge source file 14767 * with the test vector. 14768 */ 14769 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 14770 generate_gmac_large_plaintext(tdata->plaintext.data); 14771 14772 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14773 plaintext_pad_len); 14774 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14775 14776 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 14777 debug_hexdump(stdout, "plaintext:", plaintext, 14778 tdata->plaintext.len); 14779 14780 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 14781 tdata); 14782 14783 if (retval < 0) 14784 return retval; 14785 14786 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14787 14788 ut_params->op->sym->m_src = ut_params->ibuf; 14789 14790 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14791 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14792 ut_params->op); 14793 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 14794 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 14795 0); 14796 if (retval != TEST_SUCCESS) 14797 return retval; 14798 } else 14799 TEST_ASSERT_NOT_NULL( 14800 process_crypto_request(ts_params->valid_devs[0], 14801 ut_params->op), "failed to process sym crypto op"); 14802 14803 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14804 "crypto op processing failed"); 14805 14806 return 0; 14807 14808 } 14809 14810 static int 14811 test_AES_GMAC_authentication_verify_test_case_1(void) 14812 { 14813 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 14814 } 14815 14816 static int 14817 test_AES_GMAC_authentication_verify_test_case_2(void) 14818 { 14819 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 14820 } 14821 14822 static int 14823 test_AES_GMAC_authentication_verify_test_case_3(void) 14824 { 14825 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 14826 } 14827 14828 static int 14829 test_AES_GMAC_authentication_verify_test_case_4(void) 14830 { 14831 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 14832 } 14833 14834 static int 14835 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata, 14836 uint32_t fragsz) 14837 { 14838 struct crypto_testsuite_params *ts_params = &testsuite_params; 14839 struct crypto_unittest_params *ut_params = &unittest_params; 14840 struct rte_cryptodev_info dev_info; 14841 uint64_t feature_flags; 14842 unsigned int trn_data = 0; 14843 void *digest_mem = NULL; 14844 uint32_t segs = 1; 14845 unsigned int to_trn = 0; 14846 struct rte_mbuf *buf = NULL; 14847 uint8_t *auth_tag, *plaintext; 14848 int retval; 14849 14850 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 14851 "No GMAC length in the source data"); 14852 14853 /* Verify the capabilities */ 14854 struct rte_cryptodev_sym_capability_idx cap_idx; 14855 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14856 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 14857 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14858 &cap_idx) == NULL) 14859 return TEST_SKIPPED; 14860 14861 /* Check for any input SGL support */ 14862 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14863 feature_flags = dev_info.feature_flags; 14864 14865 if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) || 14866 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) || 14867 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))) 14868 return TEST_SKIPPED; 14869 14870 if (fragsz > tdata->plaintext.len) 14871 fragsz = tdata->plaintext.len; 14872 14873 uint16_t plaintext_len = fragsz; 14874 14875 retval = create_gmac_session(ts_params->valid_devs[0], 14876 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 14877 14878 if (retval == TEST_SKIPPED) 14879 return TEST_SKIPPED; 14880 if (retval < 0) 14881 return retval; 14882 14883 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14884 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14885 "Failed to allocate input buffer in mempool"); 14886 14887 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14888 rte_pktmbuf_tailroom(ut_params->ibuf)); 14889 14890 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14891 plaintext_len); 14892 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14893 14894 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 14895 14896 trn_data += plaintext_len; 14897 14898 buf = ut_params->ibuf; 14899 14900 /* 14901 * Loop until no more fragments 14902 */ 14903 14904 while (trn_data < tdata->plaintext.len) { 14905 ++segs; 14906 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 14907 (tdata->plaintext.len - trn_data) : fragsz; 14908 14909 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14910 buf = buf->next; 14911 14912 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 14913 rte_pktmbuf_tailroom(buf)); 14914 14915 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 14916 to_trn); 14917 14918 memcpy(plaintext, tdata->plaintext.data + trn_data, 14919 to_trn); 14920 trn_data += to_trn; 14921 if (trn_data == tdata->plaintext.len) 14922 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 14923 tdata->gmac_tag.len); 14924 } 14925 ut_params->ibuf->nb_segs = segs; 14926 14927 /* 14928 * Place digest at the end of the last buffer 14929 */ 14930 uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn; 14931 14932 if (!digest_mem) { 14933 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14934 + tdata->gmac_tag.len); 14935 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 14936 tdata->plaintext.len); 14937 } 14938 14939 retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE, 14940 tdata, digest_mem, digest_phys); 14941 14942 if (retval < 0) 14943 return retval; 14944 14945 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14946 14947 ut_params->op->sym->m_src = ut_params->ibuf; 14948 14949 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14950 return TEST_SKIPPED; 14951 14952 TEST_ASSERT_NOT_NULL( 14953 process_crypto_request(ts_params->valid_devs[0], 14954 ut_params->op), "failed to process sym crypto op"); 14955 14956 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14957 "crypto op processing failed"); 14958 14959 auth_tag = digest_mem; 14960 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 14961 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14962 auth_tag, 14963 tdata->gmac_tag.data, 14964 tdata->gmac_tag.len, 14965 "GMAC Generated auth tag not as expected"); 14966 14967 return 0; 14968 } 14969 14970 /* Segment size not multiple of block size (16B) */ 14971 static int 14972 test_AES_GMAC_authentication_SGL_40B(void) 14973 { 14974 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40); 14975 } 14976 14977 static int 14978 test_AES_GMAC_authentication_SGL_80B(void) 14979 { 14980 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80); 14981 } 14982 14983 static int 14984 test_AES_GMAC_authentication_SGL_2048B(void) 14985 { 14986 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048); 14987 } 14988 14989 /* Segment size not multiple of block size (16B) */ 14990 static int 14991 test_AES_GMAC_authentication_SGL_2047B(void) 14992 { 14993 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047); 14994 } 14995 14996 struct test_crypto_vector { 14997 enum rte_crypto_cipher_algorithm crypto_algo; 14998 unsigned int cipher_offset; 14999 unsigned int cipher_len; 15000 15001 struct { 15002 uint8_t data[64]; 15003 unsigned int len; 15004 } cipher_key; 15005 15006 struct { 15007 uint8_t data[64]; 15008 unsigned int len; 15009 } iv; 15010 15011 struct { 15012 const uint8_t *data; 15013 unsigned int len; 15014 } plaintext; 15015 15016 struct { 15017 const uint8_t *data; 15018 unsigned int len; 15019 } ciphertext; 15020 15021 enum rte_crypto_auth_algorithm auth_algo; 15022 unsigned int auth_offset; 15023 15024 struct { 15025 uint8_t data[128]; 15026 unsigned int len; 15027 } auth_key; 15028 15029 struct { 15030 const uint8_t *data; 15031 unsigned int len; 15032 } aad; 15033 15034 struct { 15035 uint8_t data[128]; 15036 unsigned int len; 15037 } digest; 15038 }; 15039 15040 static const struct test_crypto_vector 15041 hmac_sha1_test_crypto_vector = { 15042 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 15043 .plaintext = { 15044 .data = plaintext_hash, 15045 .len = 512 15046 }, 15047 .auth_key = { 15048 .data = { 15049 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 15050 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 15051 0xDE, 0xF4, 0xDE, 0xAD 15052 }, 15053 .len = 20 15054 }, 15055 .digest = { 15056 .data = { 15057 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 15058 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 15059 0x3F, 0x91, 0x64, 0x59 15060 }, 15061 .len = 20 15062 } 15063 }; 15064 15065 static const struct test_crypto_vector 15066 aes128_gmac_test_vector = { 15067 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 15068 .plaintext = { 15069 .data = plaintext_hash, 15070 .len = 512 15071 }, 15072 .iv = { 15073 .data = { 15074 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 15075 0x08, 0x09, 0x0A, 0x0B 15076 }, 15077 .len = 12 15078 }, 15079 .auth_key = { 15080 .data = { 15081 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 15082 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 15083 }, 15084 .len = 16 15085 }, 15086 .digest = { 15087 .data = { 15088 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 15089 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 15090 }, 15091 .len = 16 15092 } 15093 }; 15094 15095 static const struct test_crypto_vector 15096 aes128cbc_hmac_sha1_test_vector = { 15097 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 15098 .cipher_offset = 0, 15099 .cipher_len = 512, 15100 .cipher_key = { 15101 .data = { 15102 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 15103 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 15104 }, 15105 .len = 16 15106 }, 15107 .iv = { 15108 .data = { 15109 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 15110 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 15111 }, 15112 .len = 16 15113 }, 15114 .plaintext = { 15115 .data = plaintext_hash, 15116 .len = 512 15117 }, 15118 .ciphertext = { 15119 .data = ciphertext512_aes128cbc, 15120 .len = 512 15121 }, 15122 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 15123 .auth_offset = 0, 15124 .auth_key = { 15125 .data = { 15126 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 15127 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 15128 0xDE, 0xF4, 0xDE, 0xAD 15129 }, 15130 .len = 20 15131 }, 15132 .digest = { 15133 .data = { 15134 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 15135 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 15136 0x18, 0x8C, 0x1D, 0x32 15137 }, 15138 .len = 20 15139 } 15140 }; 15141 15142 static const struct test_crypto_vector 15143 aes128cbc_hmac_sha1_aad_test_vector = { 15144 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 15145 .cipher_offset = 8, 15146 .cipher_len = 496, 15147 .cipher_key = { 15148 .data = { 15149 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 15150 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 15151 }, 15152 .len = 16 15153 }, 15154 .iv = { 15155 .data = { 15156 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 15157 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 15158 }, 15159 .len = 16 15160 }, 15161 .plaintext = { 15162 .data = plaintext_hash, 15163 .len = 512 15164 }, 15165 .ciphertext = { 15166 .data = ciphertext512_aes128cbc_aad, 15167 .len = 512 15168 }, 15169 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 15170 .auth_offset = 0, 15171 .auth_key = { 15172 .data = { 15173 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 15174 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 15175 0xDE, 0xF4, 0xDE, 0xAD 15176 }, 15177 .len = 20 15178 }, 15179 .digest = { 15180 .data = { 15181 0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F, 15182 0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B, 15183 0x62, 0x0F, 0xFB, 0x10 15184 }, 15185 .len = 20 15186 } 15187 }; 15188 15189 static void 15190 data_corruption(uint8_t *data) 15191 { 15192 data[0] += 1; 15193 } 15194 15195 static void 15196 tag_corruption(uint8_t *data, unsigned int tag_offset) 15197 { 15198 data[tag_offset] += 1; 15199 } 15200 15201 static int 15202 create_auth_session(struct crypto_unittest_params *ut_params, 15203 uint8_t dev_id, 15204 const struct test_crypto_vector *reference, 15205 enum rte_crypto_auth_operation auth_op) 15206 { 15207 struct crypto_testsuite_params *ts_params = &testsuite_params; 15208 uint8_t auth_key[reference->auth_key.len + 1]; 15209 15210 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 15211 15212 /* Setup Authentication Parameters */ 15213 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15214 ut_params->auth_xform.auth.op = auth_op; 15215 ut_params->auth_xform.next = NULL; 15216 ut_params->auth_xform.auth.algo = reference->auth_algo; 15217 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 15218 ut_params->auth_xform.auth.key.data = auth_key; 15219 ut_params->auth_xform.auth.digest_length = reference->digest.len; 15220 15221 /* Create Crypto session*/ 15222 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 15223 &ut_params->auth_xform, 15224 ts_params->session_mpool); 15225 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 15226 return TEST_SKIPPED; 15227 15228 return 0; 15229 } 15230 15231 static int 15232 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 15233 uint8_t dev_id, 15234 const struct test_crypto_vector *reference, 15235 enum rte_crypto_auth_operation auth_op, 15236 enum rte_crypto_cipher_operation cipher_op) 15237 { 15238 struct crypto_testsuite_params *ts_params = &testsuite_params; 15239 uint8_t cipher_key[reference->cipher_key.len + 1]; 15240 uint8_t auth_key[reference->auth_key.len + 1]; 15241 15242 memcpy(cipher_key, reference->cipher_key.data, 15243 reference->cipher_key.len); 15244 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 15245 15246 /* Setup Authentication Parameters */ 15247 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15248 ut_params->auth_xform.auth.op = auth_op; 15249 ut_params->auth_xform.auth.algo = reference->auth_algo; 15250 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 15251 ut_params->auth_xform.auth.key.data = auth_key; 15252 ut_params->auth_xform.auth.digest_length = reference->digest.len; 15253 15254 if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) { 15255 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 15256 ut_params->auth_xform.auth.iv.length = reference->iv.len; 15257 } else { 15258 ut_params->auth_xform.next = &ut_params->cipher_xform; 15259 15260 /* Setup Cipher Parameters */ 15261 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15262 ut_params->cipher_xform.next = NULL; 15263 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 15264 ut_params->cipher_xform.cipher.op = cipher_op; 15265 ut_params->cipher_xform.cipher.key.data = cipher_key; 15266 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 15267 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 15268 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 15269 } 15270 15271 /* Create Crypto session*/ 15272 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 15273 &ut_params->auth_xform, 15274 ts_params->session_mpool); 15275 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 15276 return TEST_SKIPPED; 15277 15278 return 0; 15279 } 15280 15281 static int 15282 create_auth_operation(struct crypto_testsuite_params *ts_params, 15283 struct crypto_unittest_params *ut_params, 15284 const struct test_crypto_vector *reference, 15285 unsigned int auth_generate) 15286 { 15287 /* Generate Crypto op data structure */ 15288 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 15289 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 15290 TEST_ASSERT_NOT_NULL(ut_params->op, 15291 "Failed to allocate pktmbuf offload"); 15292 15293 /* Set crypto operation data parameters */ 15294 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 15295 15296 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 15297 15298 /* set crypto operation source mbuf */ 15299 sym_op->m_src = ut_params->ibuf; 15300 15301 /* digest */ 15302 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 15303 ut_params->ibuf, reference->digest.len); 15304 15305 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 15306 "no room to append auth tag"); 15307 15308 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 15309 ut_params->ibuf, reference->plaintext.len); 15310 15311 if (auth_generate) 15312 memset(sym_op->auth.digest.data, 0, reference->digest.len); 15313 else 15314 memcpy(sym_op->auth.digest.data, 15315 reference->digest.data, 15316 reference->digest.len); 15317 15318 debug_hexdump(stdout, "digest:", 15319 sym_op->auth.digest.data, 15320 reference->digest.len); 15321 15322 sym_op->auth.data.length = reference->plaintext.len; 15323 sym_op->auth.data.offset = 0; 15324 15325 return 0; 15326 } 15327 15328 static int 15329 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 15330 struct crypto_unittest_params *ut_params, 15331 const struct test_crypto_vector *reference, 15332 unsigned int auth_generate) 15333 { 15334 /* Generate Crypto op data structure */ 15335 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 15336 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 15337 TEST_ASSERT_NOT_NULL(ut_params->op, 15338 "Failed to allocate pktmbuf offload"); 15339 15340 /* Set crypto operation data parameters */ 15341 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 15342 15343 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 15344 15345 /* set crypto operation source mbuf */ 15346 sym_op->m_src = ut_params->ibuf; 15347 15348 /* digest */ 15349 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 15350 ut_params->ibuf, reference->digest.len); 15351 15352 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 15353 "no room to append auth tag"); 15354 15355 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 15356 ut_params->ibuf, reference->ciphertext.len); 15357 15358 if (auth_generate) 15359 memset(sym_op->auth.digest.data, 0, reference->digest.len); 15360 else 15361 memcpy(sym_op->auth.digest.data, 15362 reference->digest.data, 15363 reference->digest.len); 15364 15365 debug_hexdump(stdout, "digest:", 15366 sym_op->auth.digest.data, 15367 reference->digest.len); 15368 15369 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 15370 reference->iv.data, reference->iv.len); 15371 15372 sym_op->cipher.data.length = 0; 15373 sym_op->cipher.data.offset = 0; 15374 15375 sym_op->auth.data.length = reference->plaintext.len; 15376 sym_op->auth.data.offset = 0; 15377 15378 return 0; 15379 } 15380 15381 static int 15382 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 15383 struct crypto_unittest_params *ut_params, 15384 const struct test_crypto_vector *reference, 15385 unsigned int auth_generate) 15386 { 15387 /* Generate Crypto op data structure */ 15388 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 15389 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 15390 TEST_ASSERT_NOT_NULL(ut_params->op, 15391 "Failed to allocate pktmbuf offload"); 15392 15393 /* Set crypto operation data parameters */ 15394 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 15395 15396 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 15397 15398 /* set crypto operation source mbuf */ 15399 sym_op->m_src = ut_params->ibuf; 15400 15401 /* digest */ 15402 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 15403 ut_params->ibuf, reference->digest.len); 15404 15405 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 15406 "no room to append auth tag"); 15407 15408 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 15409 ut_params->ibuf, reference->ciphertext.len); 15410 15411 if (auth_generate) 15412 memset(sym_op->auth.digest.data, 0, reference->digest.len); 15413 else 15414 memcpy(sym_op->auth.digest.data, 15415 reference->digest.data, 15416 reference->digest.len); 15417 15418 debug_hexdump(stdout, "digest:", 15419 sym_op->auth.digest.data, 15420 reference->digest.len); 15421 15422 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 15423 reference->iv.data, reference->iv.len); 15424 15425 sym_op->cipher.data.length = reference->cipher_len; 15426 sym_op->cipher.data.offset = reference->cipher_offset; 15427 15428 sym_op->auth.data.length = reference->plaintext.len; 15429 sym_op->auth.data.offset = reference->auth_offset; 15430 15431 return 0; 15432 } 15433 15434 static int 15435 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 15436 struct crypto_unittest_params *ut_params, 15437 const struct test_crypto_vector *reference) 15438 { 15439 return create_auth_operation(ts_params, ut_params, reference, 0); 15440 } 15441 15442 static int 15443 create_auth_verify_GMAC_operation( 15444 struct crypto_testsuite_params *ts_params, 15445 struct crypto_unittest_params *ut_params, 15446 const struct test_crypto_vector *reference) 15447 { 15448 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 15449 } 15450 15451 static int 15452 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params, 15453 struct crypto_unittest_params *ut_params, 15454 const struct test_crypto_vector *reference) 15455 { 15456 return create_cipher_auth_operation(ts_params, ut_params, reference, 0); 15457 } 15458 15459 static int 15460 test_authentication_verify_fail_when_data_corruption( 15461 struct crypto_testsuite_params *ts_params, 15462 struct crypto_unittest_params *ut_params, 15463 const struct test_crypto_vector *reference, 15464 unsigned int data_corrupted) 15465 { 15466 int retval; 15467 15468 uint8_t *plaintext; 15469 struct rte_cryptodev_info dev_info; 15470 15471 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15472 uint64_t feat_flags = dev_info.feature_flags; 15473 15474 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15475 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15476 printf("Device doesn't support RAW data-path APIs.\n"); 15477 return TEST_SKIPPED; 15478 } 15479 15480 /* Verify the capabilities */ 15481 struct rte_cryptodev_sym_capability_idx cap_idx; 15482 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15483 cap_idx.algo.auth = reference->auth_algo; 15484 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15485 &cap_idx) == NULL) 15486 return TEST_SKIPPED; 15487 15488 15489 /* Create session */ 15490 retval = create_auth_session(ut_params, 15491 ts_params->valid_devs[0], 15492 reference, 15493 RTE_CRYPTO_AUTH_OP_VERIFY); 15494 15495 if (retval == TEST_SKIPPED) 15496 return TEST_SKIPPED; 15497 if (retval < 0) 15498 return retval; 15499 15500 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15501 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 15502 "Failed to allocate input buffer in mempool"); 15503 15504 /* clear mbuf payload */ 15505 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15506 rte_pktmbuf_tailroom(ut_params->ibuf)); 15507 15508 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15509 reference->plaintext.len); 15510 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 15511 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 15512 15513 debug_hexdump(stdout, "plaintext:", plaintext, 15514 reference->plaintext.len); 15515 15516 /* Create operation */ 15517 retval = create_auth_verify_operation(ts_params, ut_params, reference); 15518 15519 if (retval < 0) 15520 return retval; 15521 15522 if (data_corrupted) 15523 data_corruption(plaintext); 15524 else 15525 tag_corruption(plaintext, reference->plaintext.len); 15526 15527 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 15528 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 15529 ut_params->op); 15530 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 15531 RTE_CRYPTO_OP_STATUS_SUCCESS, 15532 "authentication not failed"); 15533 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15534 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 15535 0); 15536 if (retval != TEST_SUCCESS) 15537 return retval; 15538 } else { 15539 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 15540 ut_params->op); 15541 } 15542 if (ut_params->op == NULL) 15543 return 0; 15544 else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) 15545 return 0; 15546 15547 return -1; 15548 } 15549 15550 static int 15551 test_authentication_verify_GMAC_fail_when_corruption( 15552 struct crypto_testsuite_params *ts_params, 15553 struct crypto_unittest_params *ut_params, 15554 const struct test_crypto_vector *reference, 15555 unsigned int data_corrupted) 15556 { 15557 int retval; 15558 uint8_t *plaintext; 15559 struct rte_cryptodev_info dev_info; 15560 15561 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15562 uint64_t feat_flags = dev_info.feature_flags; 15563 15564 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15565 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15566 printf("Device doesn't support RAW data-path APIs.\n"); 15567 return TEST_SKIPPED; 15568 } 15569 15570 /* Verify the capabilities */ 15571 struct rte_cryptodev_sym_capability_idx cap_idx; 15572 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15573 cap_idx.algo.auth = reference->auth_algo; 15574 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15575 &cap_idx) == NULL) 15576 return TEST_SKIPPED; 15577 15578 /* Create session */ 15579 retval = create_auth_cipher_session(ut_params, 15580 ts_params->valid_devs[0], 15581 reference, 15582 RTE_CRYPTO_AUTH_OP_VERIFY, 15583 RTE_CRYPTO_CIPHER_OP_DECRYPT); 15584 if (retval == TEST_SKIPPED) 15585 return TEST_SKIPPED; 15586 if (retval < 0) 15587 return retval; 15588 15589 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15590 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 15591 "Failed to allocate input buffer in mempool"); 15592 15593 /* clear mbuf payload */ 15594 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15595 rte_pktmbuf_tailroom(ut_params->ibuf)); 15596 15597 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15598 reference->plaintext.len); 15599 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 15600 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 15601 15602 debug_hexdump(stdout, "plaintext:", plaintext, 15603 reference->plaintext.len); 15604 15605 /* Create operation */ 15606 retval = create_auth_verify_GMAC_operation(ts_params, 15607 ut_params, 15608 reference); 15609 15610 if (retval < 0) 15611 return retval; 15612 15613 if (data_corrupted) 15614 data_corruption(plaintext); 15615 else 15616 tag_corruption(plaintext, reference->aad.len); 15617 15618 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 15619 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 15620 ut_params->op); 15621 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 15622 RTE_CRYPTO_OP_STATUS_SUCCESS, 15623 "authentication not failed"); 15624 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15625 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 15626 0); 15627 if (retval != TEST_SUCCESS) 15628 return retval; 15629 } else { 15630 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 15631 ut_params->op); 15632 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 15633 } 15634 15635 return 0; 15636 } 15637 15638 static int 15639 test_authenticated_decryption_fail_when_corruption( 15640 struct crypto_testsuite_params *ts_params, 15641 struct crypto_unittest_params *ut_params, 15642 const struct test_crypto_vector *reference, 15643 unsigned int data_corrupted) 15644 { 15645 int retval; 15646 15647 uint8_t *ciphertext; 15648 struct rte_cryptodev_info dev_info; 15649 15650 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15651 uint64_t feat_flags = dev_info.feature_flags; 15652 15653 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15654 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15655 printf("Device doesn't support RAW data-path APIs.\n"); 15656 return TEST_SKIPPED; 15657 } 15658 15659 /* Verify the capabilities */ 15660 struct rte_cryptodev_sym_capability_idx cap_idx; 15661 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15662 cap_idx.algo.auth = reference->auth_algo; 15663 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15664 &cap_idx) == NULL) 15665 return TEST_SKIPPED; 15666 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15667 cap_idx.algo.cipher = reference->crypto_algo; 15668 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15669 &cap_idx) == NULL) 15670 return TEST_SKIPPED; 15671 15672 /* Create session */ 15673 retval = create_auth_cipher_session(ut_params, 15674 ts_params->valid_devs[0], 15675 reference, 15676 RTE_CRYPTO_AUTH_OP_VERIFY, 15677 RTE_CRYPTO_CIPHER_OP_DECRYPT); 15678 if (retval == TEST_SKIPPED) 15679 return TEST_SKIPPED; 15680 if (retval < 0) 15681 return retval; 15682 15683 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15684 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 15685 "Failed to allocate input buffer in mempool"); 15686 15687 /* clear mbuf payload */ 15688 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15689 rte_pktmbuf_tailroom(ut_params->ibuf)); 15690 15691 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15692 reference->ciphertext.len); 15693 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 15694 memcpy(ciphertext, reference->ciphertext.data, 15695 reference->ciphertext.len); 15696 15697 /* Create operation */ 15698 retval = create_cipher_auth_verify_operation(ts_params, 15699 ut_params, 15700 reference); 15701 15702 if (retval < 0) 15703 return retval; 15704 15705 if (data_corrupted) 15706 data_corruption(ciphertext); 15707 else 15708 tag_corruption(ciphertext, reference->ciphertext.len); 15709 15710 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 15711 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 15712 ut_params->op); 15713 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 15714 RTE_CRYPTO_OP_STATUS_SUCCESS, 15715 "authentication not failed"); 15716 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15717 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 15718 0); 15719 if (retval != TEST_SUCCESS) 15720 return retval; 15721 } else { 15722 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 15723 ut_params->op); 15724 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 15725 } 15726 15727 return 0; 15728 } 15729 15730 static int 15731 test_authenticated_encrypt_with_esn( 15732 struct crypto_testsuite_params *ts_params, 15733 struct crypto_unittest_params *ut_params, 15734 const struct test_crypto_vector *reference) 15735 { 15736 int retval; 15737 15738 uint8_t *authciphertext, *plaintext, *auth_tag; 15739 uint16_t plaintext_pad_len; 15740 uint8_t cipher_key[reference->cipher_key.len + 1]; 15741 uint8_t auth_key[reference->auth_key.len + 1]; 15742 struct rte_cryptodev_info dev_info; 15743 15744 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15745 uint64_t feat_flags = dev_info.feature_flags; 15746 15747 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15748 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15749 printf("Device doesn't support RAW data-path APIs.\n"); 15750 return TEST_SKIPPED; 15751 } 15752 15753 /* Verify the capabilities */ 15754 struct rte_cryptodev_sym_capability_idx cap_idx; 15755 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15756 cap_idx.algo.auth = reference->auth_algo; 15757 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15758 &cap_idx) == NULL) 15759 return TEST_SKIPPED; 15760 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15761 cap_idx.algo.cipher = reference->crypto_algo; 15762 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15763 &cap_idx) == NULL) 15764 return TEST_SKIPPED; 15765 15766 /* Create session */ 15767 memcpy(cipher_key, reference->cipher_key.data, 15768 reference->cipher_key.len); 15769 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 15770 15771 /* Setup Cipher Parameters */ 15772 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15773 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 15774 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 15775 ut_params->cipher_xform.cipher.key.data = cipher_key; 15776 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 15777 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 15778 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 15779 15780 ut_params->cipher_xform.next = &ut_params->auth_xform; 15781 15782 /* Setup Authentication Parameters */ 15783 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15784 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 15785 ut_params->auth_xform.auth.algo = reference->auth_algo; 15786 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 15787 ut_params->auth_xform.auth.key.data = auth_key; 15788 ut_params->auth_xform.auth.digest_length = reference->digest.len; 15789 ut_params->auth_xform.next = NULL; 15790 15791 /* Create Crypto session*/ 15792 ut_params->sess = rte_cryptodev_sym_session_create( 15793 ts_params->valid_devs[0], &ut_params->cipher_xform, 15794 ts_params->session_mpool); 15795 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 15796 return TEST_SKIPPED; 15797 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 15798 15799 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15800 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 15801 "Failed to allocate input buffer in mempool"); 15802 15803 /* clear mbuf payload */ 15804 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15805 rte_pktmbuf_tailroom(ut_params->ibuf)); 15806 15807 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15808 reference->plaintext.len); 15809 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 15810 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 15811 15812 /* Create operation */ 15813 retval = create_cipher_auth_operation(ts_params, 15814 ut_params, 15815 reference, 0); 15816 15817 if (retval < 0) 15818 return retval; 15819 15820 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 15821 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 15822 ut_params->op); 15823 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15824 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 15825 0); 15826 if (retval != TEST_SUCCESS) 15827 return retval; 15828 } else 15829 ut_params->op = process_crypto_request( 15830 ts_params->valid_devs[0], ut_params->op); 15831 15832 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 15833 15834 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 15835 "crypto op processing failed"); 15836 15837 plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16); 15838 15839 authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 15840 ut_params->op->sym->auth.data.offset); 15841 auth_tag = authciphertext + plaintext_pad_len; 15842 debug_hexdump(stdout, "ciphertext:", authciphertext, 15843 reference->ciphertext.len); 15844 debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len); 15845 15846 /* Validate obuf */ 15847 TEST_ASSERT_BUFFERS_ARE_EQUAL( 15848 authciphertext, 15849 reference->ciphertext.data, 15850 reference->ciphertext.len, 15851 "Ciphertext data not as expected"); 15852 15853 TEST_ASSERT_BUFFERS_ARE_EQUAL( 15854 auth_tag, 15855 reference->digest.data, 15856 reference->digest.len, 15857 "Generated digest not as expected"); 15858 15859 return TEST_SUCCESS; 15860 15861 } 15862 15863 static int 15864 test_authenticated_decrypt_with_esn( 15865 struct crypto_testsuite_params *ts_params, 15866 struct crypto_unittest_params *ut_params, 15867 const struct test_crypto_vector *reference) 15868 { 15869 int retval; 15870 15871 uint8_t *ciphertext; 15872 uint8_t cipher_key[reference->cipher_key.len + 1]; 15873 uint8_t auth_key[reference->auth_key.len + 1]; 15874 struct rte_cryptodev_info dev_info; 15875 15876 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15877 uint64_t feat_flags = dev_info.feature_flags; 15878 15879 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15880 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15881 printf("Device doesn't support RAW data-path APIs.\n"); 15882 return TEST_SKIPPED; 15883 } 15884 15885 /* Verify the capabilities */ 15886 struct rte_cryptodev_sym_capability_idx cap_idx; 15887 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15888 cap_idx.algo.auth = reference->auth_algo; 15889 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15890 &cap_idx) == NULL) 15891 return TEST_SKIPPED; 15892 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15893 cap_idx.algo.cipher = reference->crypto_algo; 15894 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15895 &cap_idx) == NULL) 15896 return TEST_SKIPPED; 15897 15898 /* Create session */ 15899 memcpy(cipher_key, reference->cipher_key.data, 15900 reference->cipher_key.len); 15901 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 15902 15903 /* Setup Authentication Parameters */ 15904 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15905 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 15906 ut_params->auth_xform.auth.algo = reference->auth_algo; 15907 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 15908 ut_params->auth_xform.auth.key.data = auth_key; 15909 ut_params->auth_xform.auth.digest_length = reference->digest.len; 15910 ut_params->auth_xform.next = &ut_params->cipher_xform; 15911 15912 /* Setup Cipher Parameters */ 15913 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15914 ut_params->cipher_xform.next = NULL; 15915 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 15916 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 15917 ut_params->cipher_xform.cipher.key.data = cipher_key; 15918 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 15919 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 15920 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 15921 15922 /* Create Crypto session*/ 15923 ut_params->sess = rte_cryptodev_sym_session_create( 15924 ts_params->valid_devs[0], &ut_params->auth_xform, 15925 ts_params->session_mpool); 15926 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 15927 return TEST_SKIPPED; 15928 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 15929 15930 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15931 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 15932 "Failed to allocate input buffer in mempool"); 15933 15934 /* clear mbuf payload */ 15935 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15936 rte_pktmbuf_tailroom(ut_params->ibuf)); 15937 15938 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15939 reference->ciphertext.len); 15940 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 15941 memcpy(ciphertext, reference->ciphertext.data, 15942 reference->ciphertext.len); 15943 15944 /* Create operation */ 15945 retval = create_cipher_auth_verify_operation(ts_params, 15946 ut_params, 15947 reference); 15948 15949 if (retval < 0) 15950 return retval; 15951 15952 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 15953 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 15954 ut_params->op); 15955 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15956 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 15957 0); 15958 if (retval != TEST_SUCCESS) 15959 return retval; 15960 } else 15961 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 15962 ut_params->op); 15963 15964 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 15965 TEST_ASSERT_EQUAL(ut_params->op->status, 15966 RTE_CRYPTO_OP_STATUS_SUCCESS, 15967 "crypto op processing passed"); 15968 15969 ut_params->obuf = ut_params->op->sym->m_src; 15970 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 15971 15972 return 0; 15973 } 15974 15975 static int 15976 create_aead_operation_SGL(enum rte_crypto_aead_operation op, 15977 const struct aead_test_data *tdata, 15978 void *digest_mem, uint64_t digest_phys) 15979 { 15980 struct crypto_testsuite_params *ts_params = &testsuite_params; 15981 struct crypto_unittest_params *ut_params = &unittest_params; 15982 15983 const unsigned int auth_tag_len = tdata->auth_tag.len; 15984 const unsigned int iv_len = tdata->iv.len; 15985 unsigned int aad_len = tdata->aad.len; 15986 unsigned int aad_len_pad = 0; 15987 15988 /* Generate Crypto op data structure */ 15989 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 15990 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 15991 TEST_ASSERT_NOT_NULL(ut_params->op, 15992 "Failed to allocate symmetric crypto operation struct"); 15993 15994 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 15995 15996 sym_op->aead.digest.data = digest_mem; 15997 15998 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 15999 "no room to append digest"); 16000 16001 sym_op->aead.digest.phys_addr = digest_phys; 16002 16003 if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) { 16004 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 16005 auth_tag_len); 16006 debug_hexdump(stdout, "digest:", 16007 sym_op->aead.digest.data, 16008 auth_tag_len); 16009 } 16010 16011 /* Append aad data */ 16012 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 16013 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 16014 uint8_t *, IV_OFFSET); 16015 16016 /* Copy IV 1 byte after the IV pointer, according to the API */ 16017 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len); 16018 16019 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16); 16020 16021 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 16022 ut_params->ibuf, aad_len); 16023 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 16024 "no room to prepend aad"); 16025 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 16026 ut_params->ibuf); 16027 16028 memset(sym_op->aead.aad.data, 0, aad_len); 16029 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 16030 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 16031 16032 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 16033 debug_hexdump(stdout, "aad:", 16034 sym_op->aead.aad.data, aad_len); 16035 } else { 16036 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 16037 uint8_t *, IV_OFFSET); 16038 16039 rte_memcpy(iv_ptr, tdata->iv.data, iv_len); 16040 16041 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16); 16042 16043 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 16044 ut_params->ibuf, aad_len_pad); 16045 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 16046 "no room to prepend aad"); 16047 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 16048 ut_params->ibuf); 16049 16050 memset(sym_op->aead.aad.data, 0, aad_len); 16051 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 16052 16053 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 16054 debug_hexdump(stdout, "aad:", 16055 sym_op->aead.aad.data, aad_len); 16056 } 16057 16058 sym_op->aead.data.length = tdata->plaintext.len; 16059 sym_op->aead.data.offset = aad_len_pad; 16060 16061 return 0; 16062 } 16063 16064 #define SGL_MAX_NO 16 16065 16066 static int 16067 test_authenticated_encryption_SGL(const struct aead_test_data *tdata, 16068 const int oop, uint32_t fragsz, uint32_t fragsz_oop) 16069 { 16070 struct crypto_testsuite_params *ts_params = &testsuite_params; 16071 struct crypto_unittest_params *ut_params = &unittest_params; 16072 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL; 16073 int retval; 16074 int to_trn = 0; 16075 int to_trn_tbl[SGL_MAX_NO]; 16076 int segs = 1; 16077 unsigned int trn_data = 0; 16078 uint8_t *plaintext, *ciphertext, *auth_tag; 16079 struct rte_cryptodev_info dev_info; 16080 16081 /* Verify the capabilities */ 16082 struct rte_cryptodev_sym_capability_idx cap_idx; 16083 const struct rte_cryptodev_symmetric_capability *capability; 16084 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 16085 cap_idx.algo.aead = tdata->algo; 16086 capability = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], &cap_idx); 16087 if (capability == NULL) 16088 return TEST_SKIPPED; 16089 if (rte_cryptodev_sym_capability_check_aead(capability, tdata->key.len, 16090 tdata->auth_tag.len, tdata->aad.len, tdata->iv.len)) 16091 return TEST_SKIPPED; 16092 16093 /* 16094 * SGL not supported on AESNI_MB PMD CPU crypto, 16095 * OOP not supported on AESNI_GCM CPU crypto 16096 */ 16097 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO && 16098 (gbl_driver_id == rte_cryptodev_driver_id_get( 16099 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) || oop)) 16100 return TEST_SKIPPED; 16101 16102 /* Detailed check for the particular SGL support flag */ 16103 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 16104 if (!oop) { 16105 unsigned int sgl_in = fragsz < tdata->plaintext.len; 16106 if (sgl_in && (!(dev_info.feature_flags & 16107 RTE_CRYPTODEV_FF_IN_PLACE_SGL))) 16108 return TEST_SKIPPED; 16109 16110 uint64_t feat_flags = dev_info.feature_flags; 16111 16112 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 16113 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 16114 printf("Device doesn't support RAW data-path APIs.\n"); 16115 return TEST_SKIPPED; 16116 } 16117 } else { 16118 unsigned int sgl_in = fragsz < tdata->plaintext.len; 16119 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) < 16120 tdata->plaintext.len; 16121 /* Raw data path API does not support OOP */ 16122 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 16123 return TEST_SKIPPED; 16124 if (sgl_in && !sgl_out) { 16125 if (!(dev_info.feature_flags & 16126 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) 16127 return TEST_SKIPPED; 16128 } else if (!sgl_in && sgl_out) { 16129 if (!(dev_info.feature_flags & 16130 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 16131 return TEST_SKIPPED; 16132 } else if (sgl_in && sgl_out) { 16133 if (!(dev_info.feature_flags & 16134 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 16135 return TEST_SKIPPED; 16136 } 16137 } 16138 16139 if (fragsz > tdata->plaintext.len) 16140 fragsz = tdata->plaintext.len; 16141 16142 uint16_t plaintext_len = fragsz; 16143 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 16144 16145 if (fragsz_oop > tdata->plaintext.len) 16146 frag_size_oop = tdata->plaintext.len; 16147 16148 int ecx = 0; 16149 void *digest_mem = NULL; 16150 16151 uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 16152 16153 if (tdata->plaintext.len % fragsz != 0) { 16154 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO) 16155 return 1; 16156 } else { 16157 if (tdata->plaintext.len / fragsz > SGL_MAX_NO) 16158 return 1; 16159 } 16160 16161 /* 16162 * For out-op-place we need to alloc another mbuf 16163 */ 16164 if (oop) { 16165 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 16166 rte_pktmbuf_append(ut_params->obuf, 16167 frag_size_oop + prepend_len); 16168 buf_oop = ut_params->obuf; 16169 } 16170 16171 /* Create AEAD session */ 16172 retval = create_aead_session(ts_params->valid_devs[0], 16173 tdata->algo, 16174 RTE_CRYPTO_AEAD_OP_ENCRYPT, 16175 tdata->key.data, tdata->key.len, 16176 tdata->aad.len, tdata->auth_tag.len, 16177 tdata->iv.len); 16178 if (retval < 0) 16179 return retval; 16180 16181 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 16182 16183 /* clear mbuf payload */ 16184 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 16185 rte_pktmbuf_tailroom(ut_params->ibuf)); 16186 16187 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 16188 plaintext_len); 16189 16190 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 16191 16192 trn_data += plaintext_len; 16193 16194 buf = ut_params->ibuf; 16195 16196 /* 16197 * Loop until no more fragments 16198 */ 16199 16200 while (trn_data < tdata->plaintext.len) { 16201 ++segs; 16202 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 16203 (tdata->plaintext.len - trn_data) : fragsz; 16204 16205 to_trn_tbl[ecx++] = to_trn; 16206 16207 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 16208 buf = buf->next; 16209 16210 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 16211 rte_pktmbuf_tailroom(buf)); 16212 16213 /* OOP */ 16214 if (oop && !fragsz_oop) { 16215 buf_last_oop = buf_oop->next = 16216 rte_pktmbuf_alloc(ts_params->mbuf_pool); 16217 buf_oop = buf_oop->next; 16218 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 16219 0, rte_pktmbuf_tailroom(buf_oop)); 16220 rte_pktmbuf_append(buf_oop, to_trn); 16221 } 16222 16223 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 16224 to_trn); 16225 16226 memcpy(plaintext, tdata->plaintext.data + trn_data, 16227 to_trn); 16228 trn_data += to_trn; 16229 if (trn_data == tdata->plaintext.len) { 16230 if (oop) { 16231 if (!fragsz_oop) 16232 digest_mem = rte_pktmbuf_append(buf_oop, 16233 tdata->auth_tag.len); 16234 } else 16235 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 16236 tdata->auth_tag.len); 16237 } 16238 } 16239 16240 uint64_t digest_phys = 0; 16241 16242 ut_params->ibuf->nb_segs = segs; 16243 16244 segs = 1; 16245 if (fragsz_oop && oop) { 16246 to_trn = 0; 16247 ecx = 0; 16248 16249 if (frag_size_oop == tdata->plaintext.len) { 16250 digest_mem = rte_pktmbuf_append(ut_params->obuf, 16251 tdata->auth_tag.len); 16252 16253 digest_phys = rte_pktmbuf_iova_offset( 16254 ut_params->obuf, 16255 tdata->plaintext.len + prepend_len); 16256 } 16257 16258 trn_data = frag_size_oop; 16259 while (trn_data < tdata->plaintext.len) { 16260 ++segs; 16261 to_trn = 16262 (tdata->plaintext.len - trn_data < 16263 frag_size_oop) ? 16264 (tdata->plaintext.len - trn_data) : 16265 frag_size_oop; 16266 16267 to_trn_tbl[ecx++] = to_trn; 16268 16269 buf_last_oop = buf_oop->next = 16270 rte_pktmbuf_alloc(ts_params->mbuf_pool); 16271 buf_oop = buf_oop->next; 16272 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 16273 0, rte_pktmbuf_tailroom(buf_oop)); 16274 rte_pktmbuf_append(buf_oop, to_trn); 16275 16276 trn_data += to_trn; 16277 16278 if (trn_data == tdata->plaintext.len) { 16279 digest_mem = rte_pktmbuf_append(buf_oop, 16280 tdata->auth_tag.len); 16281 } 16282 } 16283 16284 ut_params->obuf->nb_segs = segs; 16285 } 16286 16287 /* 16288 * Place digest at the end of the last buffer 16289 */ 16290 if (!digest_phys) 16291 digest_phys = rte_pktmbuf_iova(buf) + to_trn; 16292 if (oop && buf_last_oop) 16293 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn; 16294 16295 if (!digest_mem && !oop) { 16296 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 16297 + tdata->auth_tag.len); 16298 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 16299 tdata->plaintext.len); 16300 } 16301 16302 /* Create AEAD operation */ 16303 retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT, 16304 tdata, digest_mem, digest_phys); 16305 16306 if (retval < 0) 16307 return retval; 16308 16309 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 16310 16311 ut_params->op->sym->m_src = ut_params->ibuf; 16312 if (oop) 16313 ut_params->op->sym->m_dst = ut_params->obuf; 16314 16315 /* Process crypto operation */ 16316 if (oop == IN_PLACE && 16317 gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 16318 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 16319 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 16320 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 16321 0); 16322 if (retval != TEST_SUCCESS) 16323 return retval; 16324 } else 16325 TEST_ASSERT_NOT_NULL( 16326 process_crypto_request(ts_params->valid_devs[0], 16327 ut_params->op), "failed to process sym crypto op"); 16328 16329 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 16330 "crypto op processing failed"); 16331 16332 16333 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 16334 uint8_t *, prepend_len); 16335 if (oop) { 16336 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 16337 uint8_t *, prepend_len); 16338 } 16339 16340 if (fragsz_oop) 16341 fragsz = fragsz_oop; 16342 16343 TEST_ASSERT_BUFFERS_ARE_EQUAL( 16344 ciphertext, 16345 tdata->ciphertext.data, 16346 fragsz, 16347 "Ciphertext data not as expected"); 16348 16349 buf = ut_params->op->sym->m_src->next; 16350 if (oop) 16351 buf = ut_params->op->sym->m_dst->next; 16352 16353 unsigned int off = fragsz; 16354 16355 ecx = 0; 16356 while (buf) { 16357 ciphertext = rte_pktmbuf_mtod(buf, 16358 uint8_t *); 16359 16360 TEST_ASSERT_BUFFERS_ARE_EQUAL( 16361 ciphertext, 16362 tdata->ciphertext.data + off, 16363 to_trn_tbl[ecx], 16364 "Ciphertext data not as expected"); 16365 16366 off += to_trn_tbl[ecx++]; 16367 buf = buf->next; 16368 } 16369 16370 auth_tag = digest_mem; 16371 TEST_ASSERT_BUFFERS_ARE_EQUAL( 16372 auth_tag, 16373 tdata->auth_tag.data, 16374 tdata->auth_tag.len, 16375 "Generated auth tag not as expected"); 16376 16377 return 0; 16378 } 16379 16380 static int 16381 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) 16382 { 16383 return test_authenticated_encryption_SGL( 16384 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400); 16385 } 16386 16387 static int 16388 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void) 16389 { 16390 return test_authenticated_encryption_SGL( 16391 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000); 16392 } 16393 16394 static int 16395 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void) 16396 { 16397 return test_authenticated_encryption_SGL( 16398 &gcm_test_case_8, OUT_OF_PLACE, 400, 16399 gcm_test_case_8.plaintext.len); 16400 } 16401 16402 static int 16403 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void) 16404 { 16405 /* This test is not for OPENSSL PMD */ 16406 if (gbl_driver_id == rte_cryptodev_driver_id_get( 16407 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) 16408 return TEST_SKIPPED; 16409 16410 return test_authenticated_encryption_SGL( 16411 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0); 16412 } 16413 16414 static int 16415 test_authentication_verify_fail_when_data_corrupted( 16416 struct crypto_testsuite_params *ts_params, 16417 struct crypto_unittest_params *ut_params, 16418 const struct test_crypto_vector *reference) 16419 { 16420 return test_authentication_verify_fail_when_data_corruption( 16421 ts_params, ut_params, reference, 1); 16422 } 16423 16424 static int 16425 test_authentication_verify_fail_when_tag_corrupted( 16426 struct crypto_testsuite_params *ts_params, 16427 struct crypto_unittest_params *ut_params, 16428 const struct test_crypto_vector *reference) 16429 { 16430 return test_authentication_verify_fail_when_data_corruption( 16431 ts_params, ut_params, reference, 0); 16432 } 16433 16434 static int 16435 test_authentication_verify_GMAC_fail_when_data_corrupted( 16436 struct crypto_testsuite_params *ts_params, 16437 struct crypto_unittest_params *ut_params, 16438 const struct test_crypto_vector *reference) 16439 { 16440 return test_authentication_verify_GMAC_fail_when_corruption( 16441 ts_params, ut_params, reference, 1); 16442 } 16443 16444 static int 16445 test_authentication_verify_GMAC_fail_when_tag_corrupted( 16446 struct crypto_testsuite_params *ts_params, 16447 struct crypto_unittest_params *ut_params, 16448 const struct test_crypto_vector *reference) 16449 { 16450 return test_authentication_verify_GMAC_fail_when_corruption( 16451 ts_params, ut_params, reference, 0); 16452 } 16453 16454 static int 16455 test_authenticated_decryption_fail_when_data_corrupted( 16456 struct crypto_testsuite_params *ts_params, 16457 struct crypto_unittest_params *ut_params, 16458 const struct test_crypto_vector *reference) 16459 { 16460 return test_authenticated_decryption_fail_when_corruption( 16461 ts_params, ut_params, reference, 1); 16462 } 16463 16464 static int 16465 test_authenticated_decryption_fail_when_tag_corrupted( 16466 struct crypto_testsuite_params *ts_params, 16467 struct crypto_unittest_params *ut_params, 16468 const struct test_crypto_vector *reference) 16469 { 16470 return test_authenticated_decryption_fail_when_corruption( 16471 ts_params, ut_params, reference, 0); 16472 } 16473 16474 static int 16475 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 16476 { 16477 return test_authentication_verify_fail_when_data_corrupted( 16478 &testsuite_params, &unittest_params, 16479 &hmac_sha1_test_crypto_vector); 16480 } 16481 16482 static int 16483 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 16484 { 16485 return test_authentication_verify_fail_when_tag_corrupted( 16486 &testsuite_params, &unittest_params, 16487 &hmac_sha1_test_crypto_vector); 16488 } 16489 16490 static int 16491 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 16492 { 16493 return test_authentication_verify_GMAC_fail_when_data_corrupted( 16494 &testsuite_params, &unittest_params, 16495 &aes128_gmac_test_vector); 16496 } 16497 16498 static int 16499 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 16500 { 16501 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 16502 &testsuite_params, &unittest_params, 16503 &aes128_gmac_test_vector); 16504 } 16505 16506 static int 16507 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 16508 { 16509 return test_authenticated_decryption_fail_when_data_corrupted( 16510 &testsuite_params, 16511 &unittest_params, 16512 &aes128cbc_hmac_sha1_test_vector); 16513 } 16514 16515 static int 16516 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 16517 { 16518 return test_authenticated_decryption_fail_when_tag_corrupted( 16519 &testsuite_params, 16520 &unittest_params, 16521 &aes128cbc_hmac_sha1_test_vector); 16522 } 16523 16524 static int 16525 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void) 16526 { 16527 return test_authenticated_encrypt_with_esn( 16528 &testsuite_params, 16529 &unittest_params, 16530 &aes128cbc_hmac_sha1_aad_test_vector); 16531 } 16532 16533 static int 16534 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void) 16535 { 16536 return test_authenticated_decrypt_with_esn( 16537 &testsuite_params, 16538 &unittest_params, 16539 &aes128cbc_hmac_sha1_aad_test_vector); 16540 } 16541 16542 static int 16543 test_chacha20_poly1305_encrypt_test_case_rfc8439(void) 16544 { 16545 return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439); 16546 } 16547 16548 static int 16549 test_chacha20_poly1305_decrypt_test_case_rfc8439(void) 16550 { 16551 return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439); 16552 } 16553 16554 static int 16555 test_chacha20_poly1305_encrypt_SGL_out_of_place(void) 16556 { 16557 return test_authenticated_encryption_SGL( 16558 &chacha20_poly1305_case_2, OUT_OF_PLACE, 32, 16559 chacha20_poly1305_case_2.plaintext.len); 16560 } 16561 16562 #ifdef RTE_CRYPTO_SCHEDULER 16563 16564 /* global AESNI worker IDs for the scheduler test */ 16565 uint8_t aesni_ids[2]; 16566 16567 static int 16568 scheduler_testsuite_setup(void) 16569 { 16570 uint32_t i = 0; 16571 int32_t nb_devs, ret; 16572 char vdev_args[VDEV_ARGS_SIZE] = {""}; 16573 char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core," 16574 "ordering=enable,name=cryptodev_test_scheduler,corelist="}; 16575 uint16_t worker_core_count = 0; 16576 uint16_t socket_id = 0; 16577 16578 if (gbl_driver_id == rte_cryptodev_driver_id_get( 16579 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) { 16580 16581 /* Identify the Worker Cores 16582 * Use 2 worker cores for the device args 16583 */ 16584 RTE_LCORE_FOREACH_WORKER(i) { 16585 if (worker_core_count > 1) 16586 break; 16587 snprintf(vdev_args, sizeof(vdev_args), 16588 "%s%d", temp_str, i); 16589 strcpy(temp_str, vdev_args); 16590 strlcat(temp_str, ";", sizeof(temp_str)); 16591 worker_core_count++; 16592 socket_id = rte_lcore_to_socket_id(i); 16593 } 16594 if (worker_core_count != 2) { 16595 RTE_LOG(ERR, USER1, 16596 "Cryptodev scheduler test require at least " 16597 "two worker cores to run. " 16598 "Please use the correct coremask.\n"); 16599 return TEST_FAILED; 16600 } 16601 strcpy(temp_str, vdev_args); 16602 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", 16603 temp_str, socket_id); 16604 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args); 16605 nb_devs = rte_cryptodev_device_count_by_driver( 16606 rte_cryptodev_driver_id_get( 16607 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))); 16608 if (nb_devs < 1) { 16609 ret = rte_vdev_init( 16610 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD), 16611 vdev_args); 16612 TEST_ASSERT(ret == 0, 16613 "Failed to create instance %u of pmd : %s", 16614 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 16615 } 16616 } 16617 return testsuite_setup(); 16618 } 16619 16620 static int 16621 test_scheduler_attach_worker_op(void) 16622 { 16623 struct crypto_testsuite_params *ts_params = &testsuite_params; 16624 uint8_t sched_id = ts_params->valid_devs[0]; 16625 uint32_t i, nb_devs_attached = 0; 16626 int ret; 16627 char vdev_name[32]; 16628 unsigned int count = rte_cryptodev_count(); 16629 16630 /* create 2 AESNI_MB vdevs on top of existing devices */ 16631 for (i = count; i < count + 2; i++) { 16632 snprintf(vdev_name, sizeof(vdev_name), "%s_%u", 16633 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), 16634 i); 16635 ret = rte_vdev_init(vdev_name, NULL); 16636 16637 TEST_ASSERT(ret == 0, 16638 "Failed to create instance %u of" 16639 " pmd : %s", 16640 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 16641 16642 if (ret < 0) { 16643 RTE_LOG(ERR, USER1, 16644 "Failed to create 2 AESNI MB PMDs.\n"); 16645 return TEST_SKIPPED; 16646 } 16647 } 16648 16649 /* attach 2 AESNI_MB cdevs */ 16650 for (i = count; i < count + 2; i++) { 16651 struct rte_cryptodev_info info; 16652 unsigned int session_size; 16653 16654 rte_cryptodev_info_get(i, &info); 16655 if (info.driver_id != rte_cryptodev_driver_id_get( 16656 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) 16657 continue; 16658 16659 session_size = rte_cryptodev_sym_get_private_session_size(i); 16660 /* 16661 * Create the session mempool again, since now there are new devices 16662 * to use the mempool. 16663 */ 16664 if (ts_params->session_mpool) { 16665 rte_mempool_free(ts_params->session_mpool); 16666 ts_params->session_mpool = NULL; 16667 } 16668 16669 if (info.sym.max_nb_sessions != 0 && 16670 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 16671 RTE_LOG(ERR, USER1, 16672 "Device does not support " 16673 "at least %u sessions\n", 16674 MAX_NB_SESSIONS); 16675 return TEST_FAILED; 16676 } 16677 /* 16678 * Create mempool with maximum number of sessions, 16679 * to include the session headers 16680 */ 16681 if (ts_params->session_mpool == NULL) { 16682 ts_params->session_mpool = 16683 rte_cryptodev_sym_session_pool_create( 16684 "test_sess_mp", 16685 MAX_NB_SESSIONS, session_size, 16686 0, 0, SOCKET_ID_ANY); 16687 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 16688 "session mempool allocation failed"); 16689 } 16690 16691 ts_params->qp_conf.mp_session = ts_params->session_mpool; 16692 16693 ret = rte_cryptodev_scheduler_worker_attach(sched_id, 16694 (uint8_t)i); 16695 16696 TEST_ASSERT(ret == 0, 16697 "Failed to attach device %u of pmd : %s", i, 16698 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 16699 16700 aesni_ids[nb_devs_attached] = (uint8_t)i; 16701 16702 nb_devs_attached++; 16703 } 16704 16705 return 0; 16706 } 16707 16708 static int 16709 test_scheduler_detach_worker_op(void) 16710 { 16711 struct crypto_testsuite_params *ts_params = &testsuite_params; 16712 uint8_t sched_id = ts_params->valid_devs[0]; 16713 uint32_t i; 16714 int ret; 16715 16716 for (i = 0; i < 2; i++) { 16717 ret = rte_cryptodev_scheduler_worker_detach(sched_id, 16718 aesni_ids[i]); 16719 TEST_ASSERT(ret == 0, 16720 "Failed to detach device %u", aesni_ids[i]); 16721 } 16722 16723 return 0; 16724 } 16725 16726 static int 16727 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode) 16728 { 16729 struct crypto_testsuite_params *ts_params = &testsuite_params; 16730 uint8_t sched_id = ts_params->valid_devs[0]; 16731 /* set mode */ 16732 return rte_cryptodev_scheduler_mode_set(sched_id, 16733 scheduler_mode); 16734 } 16735 16736 static int 16737 test_scheduler_mode_roundrobin_op(void) 16738 { 16739 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) == 16740 0, "Failed to set roundrobin mode"); 16741 return 0; 16742 16743 } 16744 16745 static int 16746 test_scheduler_mode_multicore_op(void) 16747 { 16748 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) == 16749 0, "Failed to set multicore mode"); 16750 16751 return 0; 16752 } 16753 16754 static int 16755 test_scheduler_mode_failover_op(void) 16756 { 16757 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) == 16758 0, "Failed to set failover mode"); 16759 16760 return 0; 16761 } 16762 16763 static int 16764 test_scheduler_mode_pkt_size_distr_op(void) 16765 { 16766 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) == 16767 0, "Failed to set pktsize mode"); 16768 16769 return 0; 16770 } 16771 16772 static int 16773 scheduler_multicore_testsuite_setup(void) 16774 { 16775 if (test_scheduler_attach_worker_op() < 0) 16776 return TEST_SKIPPED; 16777 if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0) 16778 return TEST_SKIPPED; 16779 return 0; 16780 } 16781 16782 static int 16783 scheduler_roundrobin_testsuite_setup(void) 16784 { 16785 if (test_scheduler_attach_worker_op() < 0) 16786 return TEST_SKIPPED; 16787 if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0) 16788 return TEST_SKIPPED; 16789 return 0; 16790 } 16791 16792 static int 16793 scheduler_failover_testsuite_setup(void) 16794 { 16795 if (test_scheduler_attach_worker_op() < 0) 16796 return TEST_SKIPPED; 16797 if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0) 16798 return TEST_SKIPPED; 16799 return 0; 16800 } 16801 16802 static int 16803 scheduler_pkt_size_distr_testsuite_setup(void) 16804 { 16805 if (test_scheduler_attach_worker_op() < 0) 16806 return TEST_SKIPPED; 16807 if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0) 16808 return TEST_SKIPPED; 16809 return 0; 16810 } 16811 16812 static void 16813 scheduler_mode_testsuite_teardown(void) 16814 { 16815 test_scheduler_detach_worker_op(); 16816 } 16817 16818 #endif /* RTE_CRYPTO_SCHEDULER */ 16819 16820 static struct unit_test_suite end_testsuite = { 16821 .suite_name = NULL, 16822 .setup = NULL, 16823 .teardown = NULL, 16824 .unit_test_suites = NULL 16825 }; 16826 16827 #ifdef RTE_LIB_SECURITY 16828 static struct unit_test_suite ipsec_proto_testsuite = { 16829 .suite_name = "IPsec Proto Unit Test Suite", 16830 .setup = ipsec_proto_testsuite_setup, 16831 .unit_test_cases = { 16832 TEST_CASE_NAMED_WITH_DATA( 16833 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 16834 ut_setup_security, ut_teardown, 16835 test_ipsec_proto_known_vec, &pkt_aes_128_gcm), 16836 TEST_CASE_NAMED_WITH_DATA( 16837 "Outbound known vector ext_mbuf mode (ESP tunnel mode IPv4 AES-GCM 128)", 16838 ut_setup_security, ut_teardown, 16839 test_ipsec_proto_known_vec_ext_mbuf, &pkt_aes_128_gcm), 16840 TEST_CASE_NAMED_WITH_DATA( 16841 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 16842 ut_setup_security, ut_teardown, 16843 test_ipsec_proto_known_vec, &pkt_aes_192_gcm), 16844 TEST_CASE_NAMED_WITH_DATA( 16845 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 16846 ut_setup_security, ut_teardown, 16847 test_ipsec_proto_known_vec, &pkt_aes_256_gcm), 16848 TEST_CASE_NAMED_WITH_DATA( 16849 "Outbound known vector (ESP tunnel mode IPv4 AES-CCM 256)", 16850 ut_setup_security, ut_teardown, 16851 test_ipsec_proto_known_vec, &pkt_aes_256_ccm), 16852 TEST_CASE_NAMED_WITH_DATA( 16853 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC MD5 [12B ICV])", 16854 ut_setup_security, ut_teardown, 16855 test_ipsec_proto_known_vec, 16856 &pkt_aes_128_cbc_md5), 16857 TEST_CASE_NAMED_WITH_DATA( 16858 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])", 16859 ut_setup_security, ut_teardown, 16860 test_ipsec_proto_known_vec, 16861 &pkt_aes_128_cbc_hmac_sha256), 16862 TEST_CASE_NAMED_WITH_DATA( 16863 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])", 16864 ut_setup_security, ut_teardown, 16865 test_ipsec_proto_known_vec, 16866 &pkt_aes_128_cbc_hmac_sha384), 16867 TEST_CASE_NAMED_WITH_DATA( 16868 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])", 16869 ut_setup_security, ut_teardown, 16870 test_ipsec_proto_known_vec, 16871 &pkt_aes_128_cbc_hmac_sha512), 16872 TEST_CASE_NAMED_WITH_DATA( 16873 "Outbound known vector (ESP tunnel mode IPv6 AES-GCM 128)", 16874 ut_setup_security, ut_teardown, 16875 test_ipsec_proto_known_vec, &pkt_aes_256_gcm_v6), 16876 TEST_CASE_NAMED_WITH_DATA( 16877 "Outbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])", 16878 ut_setup_security, ut_teardown, 16879 test_ipsec_proto_known_vec, 16880 &pkt_aes_128_cbc_hmac_sha256_v6), 16881 TEST_CASE_NAMED_WITH_DATA( 16882 "Outbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])", 16883 ut_setup_security, ut_teardown, 16884 test_ipsec_proto_known_vec, 16885 &pkt_null_aes_xcbc), 16886 TEST_CASE_NAMED_WITH_DATA( 16887 "Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA256 [16B ICV])", 16888 ut_setup_security, ut_teardown, 16889 test_ipsec_proto_known_vec, 16890 &pkt_des_cbc_hmac_sha256), 16891 TEST_CASE_NAMED_WITH_DATA( 16892 "Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA384 [24B ICV])", 16893 ut_setup_security, ut_teardown, 16894 test_ipsec_proto_known_vec, 16895 &pkt_des_cbc_hmac_sha384), 16896 TEST_CASE_NAMED_WITH_DATA( 16897 "Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA512 [32B ICV])", 16898 ut_setup_security, ut_teardown, 16899 test_ipsec_proto_known_vec, 16900 &pkt_des_cbc_hmac_sha512), 16901 TEST_CASE_NAMED_WITH_DATA( 16902 "Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA256 [16B ICV])", 16903 ut_setup_security, ut_teardown, 16904 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha256), 16905 TEST_CASE_NAMED_WITH_DATA( 16906 "Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA384 [24B ICV])", 16907 ut_setup_security, ut_teardown, 16908 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha384), 16909 TEST_CASE_NAMED_WITH_DATA( 16910 "Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA512 [32B ICV])", 16911 ut_setup_security, ut_teardown, 16912 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha512), 16913 TEST_CASE_NAMED_WITH_DATA( 16914 "Outbound known vector (ESP tunnel mode IPv6 DES-CBC HMAC-SHA256 [16B ICV])", 16915 ut_setup_security, ut_teardown, 16916 test_ipsec_proto_known_vec, 16917 &pkt_des_cbc_hmac_sha256_v6), 16918 TEST_CASE_NAMED_WITH_DATA( 16919 "Outbound known vector (ESP tunnel mode IPv6 3DES-CBC HMAC-SHA256 [16B ICV])", 16920 ut_setup_security, ut_teardown, 16921 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha256_v6), 16922 TEST_CASE_NAMED_WITH_DATA( 16923 "Outbound known vector (AH tunnel mode IPv4 HMAC-SHA256)", 16924 ut_setup_security, ut_teardown, 16925 test_ipsec_proto_known_vec, 16926 &pkt_ah_tunnel_sha256), 16927 TEST_CASE_NAMED_WITH_DATA( 16928 "Outbound known vector (AH transport mode IPv4 HMAC-SHA256)", 16929 ut_setup_security, ut_teardown, 16930 test_ipsec_proto_known_vec, 16931 &pkt_ah_transport_sha256), 16932 TEST_CASE_NAMED_WITH_DATA( 16933 "Outbound known vector (AH transport mode IPv4 AES-GMAC 128)", 16934 ut_setup_security, ut_teardown, 16935 test_ipsec_proto_known_vec, 16936 &pkt_ah_ipv4_aes_gmac_128), 16937 TEST_CASE_NAMED_WITH_DATA( 16938 "Outbound fragmented packet", 16939 ut_setup_security, ut_teardown, 16940 test_ipsec_proto_known_vec_fragmented, 16941 &pkt_aes_128_gcm_frag), 16942 TEST_CASE_NAMED_WITH_DATA( 16943 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 16944 ut_setup_security, ut_teardown, 16945 test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm), 16946 TEST_CASE_NAMED_WITH_DATA( 16947 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 16948 ut_setup_security, ut_teardown, 16949 test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm), 16950 TEST_CASE_NAMED_WITH_DATA( 16951 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 16952 ut_setup_security, ut_teardown, 16953 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm), 16954 TEST_CASE_NAMED_WITH_DATA( 16955 "Inbound known vector (ESP tunnel mode IPv4 AES-CCM 256)", 16956 ut_setup_security, ut_teardown, 16957 test_ipsec_proto_known_vec_inb, &pkt_aes_256_ccm), 16958 TEST_CASE_NAMED_WITH_DATA( 16959 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)", 16960 ut_setup_security, ut_teardown, 16961 test_ipsec_proto_known_vec_inb, &pkt_aes_128_cbc_null), 16962 TEST_CASE_NAMED_WITH_DATA( 16963 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC MD5 [12B ICV])", 16964 ut_setup_security, ut_teardown, 16965 test_ipsec_proto_known_vec_inb, 16966 &pkt_aes_128_cbc_md5), 16967 TEST_CASE_NAMED_WITH_DATA( 16968 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])", 16969 ut_setup_security, ut_teardown, 16970 test_ipsec_proto_known_vec_inb, 16971 &pkt_aes_128_cbc_hmac_sha256), 16972 TEST_CASE_NAMED_WITH_DATA( 16973 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])", 16974 ut_setup_security, ut_teardown, 16975 test_ipsec_proto_known_vec_inb, 16976 &pkt_aes_128_cbc_hmac_sha384), 16977 TEST_CASE_NAMED_WITH_DATA( 16978 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])", 16979 ut_setup_security, ut_teardown, 16980 test_ipsec_proto_known_vec_inb, 16981 &pkt_aes_128_cbc_hmac_sha512), 16982 TEST_CASE_NAMED_WITH_DATA( 16983 "Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)", 16984 ut_setup_security, ut_teardown, 16985 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm_v6), 16986 TEST_CASE_NAMED_WITH_DATA( 16987 "Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])", 16988 ut_setup_security, ut_teardown, 16989 test_ipsec_proto_known_vec_inb, 16990 &pkt_aes_128_cbc_hmac_sha256_v6), 16991 TEST_CASE_NAMED_WITH_DATA( 16992 "Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])", 16993 ut_setup_security, ut_teardown, 16994 test_ipsec_proto_known_vec_inb, 16995 &pkt_null_aes_xcbc), 16996 TEST_CASE_NAMED_WITH_DATA( 16997 "Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA256 [16B ICV])", 16998 ut_setup_security, ut_teardown, 16999 test_ipsec_proto_known_vec_inb, 17000 &pkt_des_cbc_hmac_sha256), 17001 TEST_CASE_NAMED_WITH_DATA( 17002 "Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA384 [24B ICV])", 17003 ut_setup_security, ut_teardown, 17004 test_ipsec_proto_known_vec_inb, 17005 &pkt_des_cbc_hmac_sha384), 17006 TEST_CASE_NAMED_WITH_DATA( 17007 "Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA512 [32B ICV])", 17008 ut_setup_security, ut_teardown, 17009 test_ipsec_proto_known_vec_inb, 17010 &pkt_des_cbc_hmac_sha512), 17011 TEST_CASE_NAMED_WITH_DATA( 17012 "Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA256 [16B ICV])", 17013 ut_setup_security, ut_teardown, 17014 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha256), 17015 TEST_CASE_NAMED_WITH_DATA( 17016 "Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA384 [24B ICV])", 17017 ut_setup_security, ut_teardown, 17018 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha384), 17019 TEST_CASE_NAMED_WITH_DATA( 17020 "Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA512 [32B ICV])", 17021 ut_setup_security, ut_teardown, 17022 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha512), 17023 TEST_CASE_NAMED_WITH_DATA( 17024 "Inbound known vector (ESP tunnel mode IPv6 DES-CBC HMAC-SHA256 [16B ICV])", 17025 ut_setup_security, ut_teardown, 17026 test_ipsec_proto_known_vec_inb, 17027 &pkt_des_cbc_hmac_sha256_v6), 17028 TEST_CASE_NAMED_WITH_DATA( 17029 "Inbound known vector (ESP tunnel mode IPv6 3DES-CBC HMAC-SHA256 [16B ICV])", 17030 ut_setup_security, ut_teardown, 17031 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha256_v6), 17032 TEST_CASE_NAMED_WITH_DATA( 17033 "Inbound known vector (AH tunnel mode IPv4 HMAC-SHA256)", 17034 ut_setup_security, ut_teardown, 17035 test_ipsec_proto_known_vec_inb, 17036 &pkt_ah_tunnel_sha256), 17037 TEST_CASE_NAMED_WITH_DATA( 17038 "Inbound known vector (AH transport mode IPv4 HMAC-SHA256)", 17039 ut_setup_security, ut_teardown, 17040 test_ipsec_proto_known_vec_inb, 17041 &pkt_ah_transport_sha256), 17042 TEST_CASE_NAMED_WITH_DATA( 17043 "Inbound known vector (AH transport mode IPv4 AES-GMAC 128)", 17044 ut_setup_security, ut_teardown, 17045 test_ipsec_proto_known_vec_inb, 17046 &pkt_ah_ipv4_aes_gmac_128), 17047 TEST_CASE_NAMED_ST( 17048 "Combined test alg list", 17049 ut_setup_security, ut_teardown, 17050 test_ipsec_proto_display_list), 17051 TEST_CASE_NAMED_ST( 17052 "Combined test alg list (AH)", 17053 ut_setup_security, ut_teardown, 17054 test_ipsec_proto_ah_tunnel_ipv4), 17055 TEST_CASE_NAMED_ST( 17056 "IV generation", 17057 ut_setup_security, ut_teardown, 17058 test_ipsec_proto_iv_gen), 17059 TEST_CASE_NAMED_ST( 17060 "UDP encapsulation", 17061 ut_setup_security, ut_teardown, 17062 test_ipsec_proto_udp_encap), 17063 TEST_CASE_NAMED_ST( 17064 "UDP encapsulation with custom ports", 17065 ut_setup_security, ut_teardown, 17066 test_ipsec_proto_udp_encap_custom_ports), 17067 TEST_CASE_NAMED_ST( 17068 "UDP encapsulation ports verification test", 17069 ut_setup_security, ut_teardown, 17070 test_ipsec_proto_udp_ports_verify), 17071 TEST_CASE_NAMED_ST( 17072 "SA expiry packets soft", 17073 ut_setup_security, ut_teardown, 17074 test_ipsec_proto_sa_exp_pkts_soft), 17075 TEST_CASE_NAMED_ST( 17076 "SA expiry packets hard", 17077 ut_setup_security, ut_teardown, 17078 test_ipsec_proto_sa_exp_pkts_hard), 17079 TEST_CASE_NAMED_ST( 17080 "Negative test: ICV corruption", 17081 ut_setup_security, ut_teardown, 17082 test_ipsec_proto_err_icv_corrupt), 17083 TEST_CASE_NAMED_ST( 17084 "Tunnel dst addr verification", 17085 ut_setup_security, ut_teardown, 17086 test_ipsec_proto_tunnel_dst_addr_verify), 17087 TEST_CASE_NAMED_ST( 17088 "Tunnel src and dst addr verification", 17089 ut_setup_security, ut_teardown, 17090 test_ipsec_proto_tunnel_src_dst_addr_verify), 17091 TEST_CASE_NAMED_ST( 17092 "Inner IP checksum", 17093 ut_setup_security, ut_teardown, 17094 test_ipsec_proto_inner_ip_csum), 17095 TEST_CASE_NAMED_ST( 17096 "Inner L4 checksum", 17097 ut_setup_security, ut_teardown, 17098 test_ipsec_proto_inner_l4_csum), 17099 TEST_CASE_NAMED_ST( 17100 "Tunnel IPv4 in IPv4", 17101 ut_setup_security, ut_teardown, 17102 test_ipsec_proto_tunnel_v4_in_v4), 17103 TEST_CASE_NAMED_ST( 17104 "Tunnel IPv6 in IPv6", 17105 ut_setup_security, ut_teardown, 17106 test_ipsec_proto_tunnel_v6_in_v6), 17107 TEST_CASE_NAMED_ST( 17108 "Tunnel IPv4 in IPv6", 17109 ut_setup_security, ut_teardown, 17110 test_ipsec_proto_tunnel_v4_in_v6), 17111 TEST_CASE_NAMED_ST( 17112 "Tunnel IPv6 in IPv4", 17113 ut_setup_security, ut_teardown, 17114 test_ipsec_proto_tunnel_v6_in_v4), 17115 TEST_CASE_NAMED_ST( 17116 "Transport IPv4", 17117 ut_setup_security, ut_teardown, 17118 test_ipsec_proto_transport_v4), 17119 TEST_CASE_NAMED_ST( 17120 "AH transport IPv4", 17121 ut_setup_security, ut_teardown, 17122 test_ipsec_proto_ah_transport_ipv4), 17123 TEST_CASE_NAMED_ST( 17124 "Transport l4 checksum", 17125 ut_setup_security, ut_teardown, 17126 test_ipsec_proto_transport_l4_csum), 17127 TEST_CASE_NAMED_ST( 17128 "Statistics: success", 17129 ut_setup_security, ut_teardown, 17130 test_ipsec_proto_stats), 17131 TEST_CASE_NAMED_ST( 17132 "Fragmented packet", 17133 ut_setup_security, ut_teardown, 17134 test_ipsec_proto_pkt_fragment), 17135 TEST_CASE_NAMED_ST( 17136 "Tunnel header copy DF (inner 0)", 17137 ut_setup_security, ut_teardown, 17138 test_ipsec_proto_copy_df_inner_0), 17139 TEST_CASE_NAMED_ST( 17140 "Tunnel header copy DF (inner 1)", 17141 ut_setup_security, ut_teardown, 17142 test_ipsec_proto_copy_df_inner_1), 17143 TEST_CASE_NAMED_ST( 17144 "Tunnel header set DF 0 (inner 1)", 17145 ut_setup_security, ut_teardown, 17146 test_ipsec_proto_set_df_0_inner_1), 17147 TEST_CASE_NAMED_ST( 17148 "Tunnel header set DF 1 (inner 0)", 17149 ut_setup_security, ut_teardown, 17150 test_ipsec_proto_set_df_1_inner_0), 17151 TEST_CASE_NAMED_ST( 17152 "Tunnel header IPv4 copy DSCP (inner 0)", 17153 ut_setup_security, ut_teardown, 17154 test_ipsec_proto_ipv4_copy_dscp_inner_0), 17155 TEST_CASE_NAMED_ST( 17156 "Tunnel header IPv4 copy DSCP (inner 1)", 17157 ut_setup_security, ut_teardown, 17158 test_ipsec_proto_ipv4_copy_dscp_inner_1), 17159 TEST_CASE_NAMED_ST( 17160 "Tunnel header IPv4 set DSCP 0 (inner 1)", 17161 ut_setup_security, ut_teardown, 17162 test_ipsec_proto_ipv4_set_dscp_0_inner_1), 17163 TEST_CASE_NAMED_ST( 17164 "Tunnel header IPv4 set DSCP 1 (inner 0)", 17165 ut_setup_security, ut_teardown, 17166 test_ipsec_proto_ipv4_set_dscp_1_inner_0), 17167 TEST_CASE_NAMED_ST( 17168 "Tunnel header IPv6 copy DSCP (inner 0)", 17169 ut_setup_security, ut_teardown, 17170 test_ipsec_proto_ipv6_copy_dscp_inner_0), 17171 TEST_CASE_NAMED_ST( 17172 "Tunnel header IPv6 copy DSCP (inner 1)", 17173 ut_setup_security, ut_teardown, 17174 test_ipsec_proto_ipv6_copy_dscp_inner_1), 17175 TEST_CASE_NAMED_ST( 17176 "Tunnel header IPv6 set DSCP 0 (inner 1)", 17177 ut_setup_security, ut_teardown, 17178 test_ipsec_proto_ipv6_set_dscp_0_inner_1), 17179 TEST_CASE_NAMED_ST( 17180 "Tunnel header IPv6 set DSCP 1 (inner 0)", 17181 ut_setup_security, ut_teardown, 17182 test_ipsec_proto_ipv6_set_dscp_1_inner_0), 17183 TEST_CASE_NAMED_WITH_DATA( 17184 "Antireplay with window size 1024", 17185 ut_setup_security, ut_teardown, 17186 test_ipsec_proto_pkt_antireplay1024, &pkt_aes_128_gcm), 17187 TEST_CASE_NAMED_WITH_DATA( 17188 "Antireplay with window size 2048", 17189 ut_setup_security, ut_teardown, 17190 test_ipsec_proto_pkt_antireplay2048, &pkt_aes_128_gcm), 17191 TEST_CASE_NAMED_WITH_DATA( 17192 "Antireplay with window size 4096", 17193 ut_setup_security, ut_teardown, 17194 test_ipsec_proto_pkt_antireplay4096, &pkt_aes_128_gcm), 17195 TEST_CASE_NAMED_WITH_DATA( 17196 "ESN and Antireplay with window size 1024", 17197 ut_setup_security, ut_teardown, 17198 test_ipsec_proto_pkt_esn_antireplay1024, 17199 &pkt_aes_128_gcm), 17200 TEST_CASE_NAMED_WITH_DATA( 17201 "ESN and Antireplay with window size 2048", 17202 ut_setup_security, ut_teardown, 17203 test_ipsec_proto_pkt_esn_antireplay2048, 17204 &pkt_aes_128_gcm), 17205 TEST_CASE_NAMED_WITH_DATA( 17206 "ESN and Antireplay with window size 4096", 17207 ut_setup_security, ut_teardown, 17208 test_ipsec_proto_pkt_esn_antireplay4096, 17209 &pkt_aes_128_gcm), 17210 TEST_CASE_NAMED_ST( 17211 "Tunnel header IPv4 decrement inner TTL", 17212 ut_setup_security, ut_teardown, 17213 test_ipsec_proto_ipv4_ttl_decrement), 17214 TEST_CASE_NAMED_ST( 17215 "Tunnel header IPv6 decrement inner hop limit", 17216 ut_setup_security, ut_teardown, 17217 test_ipsec_proto_ipv6_hop_limit_decrement), 17218 TEST_CASE_NAMED_ST( 17219 "Multi-segmented mode", 17220 ut_setup_security, ut_teardown, 17221 test_ipsec_proto_sgl), 17222 TEST_CASE_NAMED_ST( 17223 "Multi-segmented external mbuf mode", 17224 ut_setup_security, ut_teardown, 17225 test_ipsec_proto_sgl_ext_mbuf), 17226 TEST_CASE_NAMED_WITH_DATA( 17227 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128) Rx inject", 17228 ut_setup_security_rx_inject, ut_teardown_rx_inject, 17229 test_ipsec_proto_known_vec_inb_rx_inject, &pkt_aes_128_gcm), 17230 TEST_CASES_END() /**< NULL terminate unit test array */ 17231 } 17232 }; 17233 17234 static struct unit_test_suite pdcp_proto_testsuite = { 17235 .suite_name = "PDCP Proto Unit Test Suite", 17236 .setup = pdcp_proto_testsuite_setup, 17237 .unit_test_cases = { 17238 TEST_CASE_ST(ut_setup_security, ut_teardown, 17239 test_PDCP_PROTO_all), 17240 TEST_CASES_END() /**< NULL terminate unit test array */ 17241 } 17242 }; 17243 17244 static struct unit_test_suite tls12_record_proto_testsuite = { 17245 .suite_name = "TLS 1.2 Record Protocol Unit Test Suite", 17246 .setup = tls_record_proto_testsuite_setup, 17247 .unit_test_cases = { 17248 TEST_CASE_NAMED_WITH_DATA( 17249 "Write record known vector AES-GCM-128 (vector 1)", 17250 ut_setup_security, ut_teardown, 17251 test_tls_record_proto_known_vec, &tls_test_data_aes_128_gcm_v1), 17252 TEST_CASE_NAMED_WITH_DATA( 17253 "Write record known vector AES-GCM-128 (vector 2)", 17254 ut_setup_security, ut_teardown, 17255 test_tls_record_proto_known_vec, &tls_test_data_aes_128_gcm_v2), 17256 TEST_CASE_NAMED_WITH_DATA( 17257 "Write record known vector AES-GCM-256", 17258 ut_setup_security, ut_teardown, 17259 test_tls_record_proto_known_vec, &tls_test_data_aes_256_gcm), 17260 TEST_CASE_NAMED_WITH_DATA( 17261 "Write record known vector AES-CBC-128-SHA1", 17262 ut_setup_security, ut_teardown, 17263 test_tls_record_proto_known_vec, &tls_test_data_aes_128_cbc_sha1_hmac), 17264 TEST_CASE_NAMED_WITH_DATA( 17265 "Write record known vector AES-128-CBC-SHA256", 17266 ut_setup_security, ut_teardown, 17267 test_tls_record_proto_known_vec, &tls_test_data_aes_128_cbc_sha256_hmac), 17268 TEST_CASE_NAMED_WITH_DATA( 17269 "Write record known vector AES-256-CBC-SHA1", 17270 ut_setup_security, ut_teardown, 17271 test_tls_record_proto_known_vec, &tls_test_data_aes_256_cbc_sha1_hmac), 17272 TEST_CASE_NAMED_WITH_DATA( 17273 "Write record known vector AES-256-CBC-SHA256", 17274 ut_setup_security, ut_teardown, 17275 test_tls_record_proto_known_vec, &tls_test_data_aes_256_cbc_sha256_hmac), 17276 TEST_CASE_NAMED_WITH_DATA( 17277 "Write record known vector AES-256-CBC-SHA384", 17278 ut_setup_security, ut_teardown, 17279 test_tls_record_proto_known_vec, &tls_test_data_aes_256_cbc_sha384_hmac), 17280 TEST_CASE_NAMED_WITH_DATA( 17281 "Write record known vector 3DES-CBC-SHA1-HMAC", 17282 ut_setup_security, ut_teardown, 17283 test_tls_record_proto_known_vec, &tls_test_data_3des_cbc_sha1_hmac), 17284 TEST_CASE_NAMED_WITH_DATA( 17285 "Write record known vector NULL-SHA1-HMAC", 17286 ut_setup_security, ut_teardown, 17287 test_tls_record_proto_known_vec, &tls_test_data_null_cipher_sha1_hmac), 17288 TEST_CASE_NAMED_WITH_DATA( 17289 "Write record known vector CHACHA20-POLY1305", 17290 ut_setup_security, ut_teardown, 17291 test_tls_record_proto_known_vec, &tls_test_data_chacha20_poly1305), 17292 17293 TEST_CASE_NAMED_WITH_DATA( 17294 "Read record known vector AES-GCM-128 (vector 1)", 17295 ut_setup_security, ut_teardown, 17296 test_tls_record_proto_known_vec_read, &tls_test_data_aes_128_gcm_v1), 17297 TEST_CASE_NAMED_WITH_DATA( 17298 "Read record known vector AES-GCM-128 (vector 2)", 17299 ut_setup_security, ut_teardown, 17300 test_tls_record_proto_known_vec_read, &tls_test_data_aes_128_gcm_v2), 17301 TEST_CASE_NAMED_WITH_DATA( 17302 "Read record known vector AES-GCM-256", 17303 ut_setup_security, ut_teardown, 17304 test_tls_record_proto_known_vec_read, &tls_test_data_aes_256_gcm), 17305 TEST_CASE_NAMED_WITH_DATA( 17306 "Read record known vector AES-128-CBC-SHA1", 17307 ut_setup_security, ut_teardown, 17308 test_tls_record_proto_known_vec_read, &tls_test_data_aes_128_cbc_sha1_hmac), 17309 TEST_CASE_NAMED_WITH_DATA( 17310 "Read record known vector AES-128-CBC-SHA256", 17311 ut_setup_security, ut_teardown, 17312 test_tls_record_proto_known_vec_read, 17313 &tls_test_data_aes_128_cbc_sha256_hmac), 17314 TEST_CASE_NAMED_WITH_DATA( 17315 "Read record known vector AES-256-CBC-SHA1", 17316 ut_setup_security, ut_teardown, 17317 test_tls_record_proto_known_vec_read, &tls_test_data_aes_256_cbc_sha1_hmac), 17318 TEST_CASE_NAMED_WITH_DATA( 17319 "Read record known vector AES-256-CBC-SHA256", 17320 ut_setup_security, ut_teardown, 17321 test_tls_record_proto_known_vec_read, 17322 &tls_test_data_aes_256_cbc_sha256_hmac), 17323 TEST_CASE_NAMED_WITH_DATA( 17324 "Read record known vector AES-256-CBC-SHA384", 17325 ut_setup_security, ut_teardown, 17326 test_tls_record_proto_known_vec_read, 17327 &tls_test_data_aes_256_cbc_sha384_hmac), 17328 TEST_CASE_NAMED_WITH_DATA( 17329 "Read record known vector 3DES-CBC-SHA1-HMAC", 17330 ut_setup_security, ut_teardown, 17331 test_tls_record_proto_known_vec_read, &tls_test_data_3des_cbc_sha1_hmac), 17332 TEST_CASE_NAMED_WITH_DATA( 17333 "Read record known vector NULL-SHA1-HMAC", 17334 ut_setup_security, ut_teardown, 17335 test_tls_record_proto_known_vec_read, &tls_test_data_null_cipher_sha1_hmac), 17336 TEST_CASE_NAMED_WITH_DATA( 17337 "Read record known vector CHACHA20-POLY1305", 17338 ut_setup_security, ut_teardown, 17339 test_tls_record_proto_known_vec_read, &tls_test_data_chacha20_poly1305), 17340 17341 TEST_CASE_NAMED_ST( 17342 "Combined test alg list", 17343 ut_setup_security, ut_teardown, 17344 test_tls_1_2_record_proto_display_list), 17345 TEST_CASE_NAMED_ST( 17346 "Data walkthrough combined test alg list", 17347 ut_setup_security, ut_teardown, 17348 test_tls_1_2_record_proto_data_walkthrough), 17349 TEST_CASE_NAMED_ST( 17350 "Multi-segmented mode", 17351 ut_setup_security, ut_teardown, 17352 test_tls_1_2_record_proto_sgl), 17353 TEST_CASE_NAMED_ST( 17354 "Multi-segmented mode data walkthrough", 17355 ut_setup_security, ut_teardown, 17356 test_tls_1_2_record_proto_sgl_data_walkthrough), 17357 TEST_CASE_NAMED_ST( 17358 "TLS packet header corruption", 17359 ut_setup_security, ut_teardown, 17360 test_tls_record_proto_corrupt_pkt), 17361 TEST_CASE_NAMED_ST( 17362 "Custom content type", 17363 ut_setup_security, ut_teardown, 17364 test_tls_record_proto_custom_content_type), 17365 TEST_CASE_NAMED_ST( 17366 "Zero len TLS record with content type as app", 17367 ut_setup_security, ut_teardown, 17368 test_tls_record_proto_zero_len), 17369 TEST_CASE_NAMED_ST( 17370 "Zero len TLS record with content type as ctrl", 17371 ut_setup_security, ut_teardown, 17372 test_tls_record_proto_zero_len_non_app), 17373 TEST_CASES_END() /**< NULL terminate unit test array */ 17374 } 17375 }; 17376 17377 static struct unit_test_suite dtls12_record_proto_testsuite = { 17378 .suite_name = "DTLS 1.2 Record Protocol Unit Test Suite", 17379 .setup = tls_record_proto_testsuite_setup, 17380 .unit_test_cases = { 17381 TEST_CASE_NAMED_WITH_DATA( 17382 "Write record known vector AES-GCM-128", 17383 ut_setup_security, ut_teardown, 17384 test_tls_record_proto_known_vec, &dtls_test_data_aes_128_gcm), 17385 TEST_CASE_NAMED_WITH_DATA( 17386 "Write record known vector AES-GCM-256", 17387 ut_setup_security, ut_teardown, 17388 test_tls_record_proto_known_vec, &dtls_test_data_aes_256_gcm), 17389 TEST_CASE_NAMED_WITH_DATA( 17390 "Write record known vector AES-128-CBC-SHA1", 17391 ut_setup_security, ut_teardown, 17392 test_tls_record_proto_known_vec, 17393 &dtls_test_data_aes_128_cbc_sha1_hmac), 17394 TEST_CASE_NAMED_WITH_DATA( 17395 "Write record known vector AES-128-CBC-SHA256", 17396 ut_setup_security, ut_teardown, 17397 test_tls_record_proto_known_vec, 17398 &dtls_test_data_aes_128_cbc_sha256_hmac), 17399 TEST_CASE_NAMED_WITH_DATA( 17400 "Write record known vector AES-256-CBC-SHA1", 17401 ut_setup_security, ut_teardown, 17402 test_tls_record_proto_known_vec, 17403 &dtls_test_data_aes_256_cbc_sha1_hmac), 17404 TEST_CASE_NAMED_WITH_DATA( 17405 "Write record known vector AES-256-CBC-SHA256", 17406 ut_setup_security, ut_teardown, 17407 test_tls_record_proto_known_vec, 17408 &dtls_test_data_aes_256_cbc_sha256_hmac), 17409 TEST_CASE_NAMED_WITH_DATA( 17410 "Write record known vector AES-256-CBC-SHA384", 17411 ut_setup_security, ut_teardown, 17412 test_tls_record_proto_known_vec, 17413 &dtls_test_data_aes_256_cbc_sha384_hmac), 17414 TEST_CASE_NAMED_WITH_DATA( 17415 "Write record known vector 3DES-CBC-SHA1-HMAC", 17416 ut_setup_security, ut_teardown, 17417 test_tls_record_proto_known_vec, 17418 &dtls_test_data_3des_cbc_sha1_hmac), 17419 TEST_CASE_NAMED_WITH_DATA( 17420 "Write record known vector NULL-SHA1-HMAC", 17421 ut_setup_security, ut_teardown, 17422 test_tls_record_proto_known_vec, 17423 &dtls_test_data_null_cipher_sha1_hmac), 17424 TEST_CASE_NAMED_WITH_DATA( 17425 "Write record known vector CHACHA20-POLY1305", 17426 ut_setup_security, ut_teardown, 17427 test_tls_record_proto_known_vec, &dtls_test_data_chacha20_poly1305), 17428 TEST_CASE_NAMED_WITH_DATA( 17429 "Read record known vector AES-GCM-128", 17430 ut_setup_security, ut_teardown, 17431 test_tls_record_proto_known_vec_read, &dtls_test_data_aes_128_gcm), 17432 TEST_CASE_NAMED_WITH_DATA( 17433 "Read record known vector AES-GCM-256", 17434 ut_setup_security, ut_teardown, 17435 test_tls_record_proto_known_vec_read, &dtls_test_data_aes_256_gcm), 17436 TEST_CASE_NAMED_WITH_DATA( 17437 "Read record known vector AES-128-CBC-SHA1", 17438 ut_setup_security, ut_teardown, 17439 test_tls_record_proto_known_vec_read, 17440 &dtls_test_data_aes_128_cbc_sha1_hmac), 17441 TEST_CASE_NAMED_WITH_DATA( 17442 "Read record known vector AES-128-CBC-SHA256", 17443 ut_setup_security, ut_teardown, 17444 test_tls_record_proto_known_vec_read, 17445 &dtls_test_data_aes_128_cbc_sha256_hmac), 17446 TEST_CASE_NAMED_WITH_DATA( 17447 "Read record known vector AES-256-CBC-SHA1", 17448 ut_setup_security, ut_teardown, 17449 test_tls_record_proto_known_vec_read, 17450 &dtls_test_data_aes_256_cbc_sha1_hmac), 17451 TEST_CASE_NAMED_WITH_DATA( 17452 "Read record known vector AES-256-CBC-SHA256", 17453 ut_setup_security, ut_teardown, 17454 test_tls_record_proto_known_vec_read, 17455 &dtls_test_data_aes_256_cbc_sha256_hmac), 17456 TEST_CASE_NAMED_WITH_DATA( 17457 "Read record known vector AES-256-CBC-SHA384", 17458 ut_setup_security, ut_teardown, 17459 test_tls_record_proto_known_vec_read, 17460 &dtls_test_data_aes_256_cbc_sha384_hmac), 17461 TEST_CASE_NAMED_WITH_DATA( 17462 "Read record known vector 3DES-CBC-SHA1-HMAC", 17463 ut_setup_security, ut_teardown, 17464 test_tls_record_proto_known_vec_read, 17465 &dtls_test_data_3des_cbc_sha1_hmac), 17466 TEST_CASE_NAMED_WITH_DATA( 17467 "Read record known vector NULL-SHA1-HMAC", 17468 ut_setup_security, ut_teardown, 17469 test_tls_record_proto_known_vec_read, 17470 &dtls_test_data_null_cipher_sha1_hmac), 17471 TEST_CASE_NAMED_WITH_DATA( 17472 "Read record known vector CHACHA20-POLY1305", 17473 ut_setup_security, ut_teardown, 17474 test_tls_record_proto_known_vec_read, &dtls_test_data_chacha20_poly1305), 17475 17476 TEST_CASE_NAMED_ST( 17477 "Combined test alg list", 17478 ut_setup_security, ut_teardown, 17479 test_dtls_1_2_record_proto_display_list), 17480 TEST_CASE_NAMED_ST( 17481 "Data walkthrough combined test alg list", 17482 ut_setup_security, ut_teardown, 17483 test_dtls_1_2_record_proto_data_walkthrough), 17484 TEST_CASE_NAMED_ST( 17485 "Multi-segmented mode", 17486 ut_setup_security, ut_teardown, 17487 test_dtls_1_2_record_proto_sgl), 17488 TEST_CASE_NAMED_ST( 17489 "Multi-segmented mode data walkthrough", 17490 ut_setup_security, ut_teardown, 17491 test_dtls_1_2_record_proto_sgl_data_walkthrough), 17492 TEST_CASE_NAMED_ST( 17493 "Packet corruption", 17494 ut_setup_security, ut_teardown, 17495 test_dtls_1_2_record_proto_corrupt_pkt), 17496 TEST_CASE_NAMED_ST( 17497 "Custom content type", 17498 ut_setup_security, ut_teardown, 17499 test_dtls_1_2_record_proto_custom_content_type), 17500 TEST_CASE_NAMED_ST( 17501 "Zero len DTLS record with content type as app", 17502 ut_setup_security, ut_teardown, 17503 test_dtls_1_2_record_proto_zero_len), 17504 TEST_CASE_NAMED_ST( 17505 "Zero len DTLS record with content type as ctrl", 17506 ut_setup_security, ut_teardown, 17507 test_dtls_1_2_record_proto_zero_len_non_app), 17508 TEST_CASES_END() /**< NULL terminate unit test array */ 17509 } 17510 }; 17511 17512 #define ADD_UPLINK_TESTCASE(data) \ 17513 TEST_CASE_NAMED_WITH_DATA(data.test_descr_uplink, ut_setup_security, \ 17514 ut_teardown, test_docsis_proto_uplink, (const void *) &data), \ 17515 17516 #define ADD_DOWNLINK_TESTCASE(data) \ 17517 TEST_CASE_NAMED_WITH_DATA(data.test_descr_downlink, ut_setup_security, \ 17518 ut_teardown, test_docsis_proto_downlink, (const void *) &data), \ 17519 17520 static struct unit_test_suite docsis_proto_testsuite = { 17521 .suite_name = "DOCSIS Proto Unit Test Suite", 17522 .setup = docsis_proto_testsuite_setup, 17523 .unit_test_cases = { 17524 /* Uplink */ 17525 ADD_UPLINK_TESTCASE(docsis_test_case_1) 17526 ADD_UPLINK_TESTCASE(docsis_test_case_2) 17527 ADD_UPLINK_TESTCASE(docsis_test_case_3) 17528 ADD_UPLINK_TESTCASE(docsis_test_case_4) 17529 ADD_UPLINK_TESTCASE(docsis_test_case_5) 17530 ADD_UPLINK_TESTCASE(docsis_test_case_6) 17531 ADD_UPLINK_TESTCASE(docsis_test_case_7) 17532 ADD_UPLINK_TESTCASE(docsis_test_case_8) 17533 ADD_UPLINK_TESTCASE(docsis_test_case_9) 17534 ADD_UPLINK_TESTCASE(docsis_test_case_10) 17535 ADD_UPLINK_TESTCASE(docsis_test_case_11) 17536 ADD_UPLINK_TESTCASE(docsis_test_case_12) 17537 ADD_UPLINK_TESTCASE(docsis_test_case_13) 17538 ADD_UPLINK_TESTCASE(docsis_test_case_14) 17539 ADD_UPLINK_TESTCASE(docsis_test_case_15) 17540 ADD_UPLINK_TESTCASE(docsis_test_case_16) 17541 ADD_UPLINK_TESTCASE(docsis_test_case_17) 17542 ADD_UPLINK_TESTCASE(docsis_test_case_18) 17543 ADD_UPLINK_TESTCASE(docsis_test_case_19) 17544 ADD_UPLINK_TESTCASE(docsis_test_case_20) 17545 ADD_UPLINK_TESTCASE(docsis_test_case_21) 17546 ADD_UPLINK_TESTCASE(docsis_test_case_22) 17547 ADD_UPLINK_TESTCASE(docsis_test_case_23) 17548 ADD_UPLINK_TESTCASE(docsis_test_case_24) 17549 ADD_UPLINK_TESTCASE(docsis_test_case_25) 17550 ADD_UPLINK_TESTCASE(docsis_test_case_26) 17551 /* Downlink */ 17552 ADD_DOWNLINK_TESTCASE(docsis_test_case_1) 17553 ADD_DOWNLINK_TESTCASE(docsis_test_case_2) 17554 ADD_DOWNLINK_TESTCASE(docsis_test_case_3) 17555 ADD_DOWNLINK_TESTCASE(docsis_test_case_4) 17556 ADD_DOWNLINK_TESTCASE(docsis_test_case_5) 17557 ADD_DOWNLINK_TESTCASE(docsis_test_case_6) 17558 ADD_DOWNLINK_TESTCASE(docsis_test_case_7) 17559 ADD_DOWNLINK_TESTCASE(docsis_test_case_8) 17560 ADD_DOWNLINK_TESTCASE(docsis_test_case_9) 17561 ADD_DOWNLINK_TESTCASE(docsis_test_case_10) 17562 ADD_DOWNLINK_TESTCASE(docsis_test_case_11) 17563 ADD_DOWNLINK_TESTCASE(docsis_test_case_12) 17564 ADD_DOWNLINK_TESTCASE(docsis_test_case_13) 17565 ADD_DOWNLINK_TESTCASE(docsis_test_case_14) 17566 ADD_DOWNLINK_TESTCASE(docsis_test_case_15) 17567 ADD_DOWNLINK_TESTCASE(docsis_test_case_16) 17568 ADD_DOWNLINK_TESTCASE(docsis_test_case_17) 17569 ADD_DOWNLINK_TESTCASE(docsis_test_case_18) 17570 ADD_DOWNLINK_TESTCASE(docsis_test_case_19) 17571 ADD_DOWNLINK_TESTCASE(docsis_test_case_20) 17572 ADD_DOWNLINK_TESTCASE(docsis_test_case_21) 17573 ADD_DOWNLINK_TESTCASE(docsis_test_case_22) 17574 ADD_DOWNLINK_TESTCASE(docsis_test_case_23) 17575 ADD_DOWNLINK_TESTCASE(docsis_test_case_24) 17576 ADD_DOWNLINK_TESTCASE(docsis_test_case_25) 17577 ADD_DOWNLINK_TESTCASE(docsis_test_case_26) 17578 TEST_CASES_END() /**< NULL terminate unit test array */ 17579 } 17580 }; 17581 #endif 17582 17583 static struct unit_test_suite cryptodev_gen_testsuite = { 17584 .suite_name = "Crypto General Unit Test Suite", 17585 .setup = crypto_gen_testsuite_setup, 17586 .unit_test_cases = { 17587 TEST_CASE_ST(ut_setup, ut_teardown, 17588 test_device_reconfigure), 17589 TEST_CASE_ST(ut_setup, ut_teardown, 17590 test_device_configure_invalid_dev_id), 17591 TEST_CASE_ST(ut_setup, ut_teardown, 17592 test_queue_pair_descriptor_setup), 17593 TEST_CASE_ST(ut_setup, ut_teardown, 17594 test_device_configure_invalid_queue_pair_ids), 17595 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 17596 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup), 17597 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup), 17598 TEST_CASES_END() /**< NULL terminate unit test array */ 17599 } 17600 }; 17601 17602 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = { 17603 .suite_name = "Negative HMAC SHA1 Unit Test Suite", 17604 .setup = negative_hmac_sha1_testsuite_setup, 17605 .unit_test_cases = { 17606 /** Negative tests */ 17607 TEST_CASE_ST(ut_setup, ut_teardown, 17608 authentication_verify_HMAC_SHA1_fail_data_corrupt), 17609 TEST_CASE_ST(ut_setup, ut_teardown, 17610 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 17611 TEST_CASE_ST(ut_setup, ut_teardown, 17612 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 17613 TEST_CASE_ST(ut_setup, ut_teardown, 17614 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 17615 17616 TEST_CASES_END() /**< NULL terminate unit test array */ 17617 } 17618 }; 17619 17620 static struct unit_test_suite cryptodev_multi_session_testsuite = { 17621 .suite_name = "Multi Session Unit Test Suite", 17622 .setup = multi_session_testsuite_setup, 17623 .unit_test_cases = { 17624 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 17625 TEST_CASE_ST(ut_setup, ut_teardown, 17626 test_multi_session_random_usage), 17627 17628 TEST_CASES_END() /**< NULL terminate unit test array */ 17629 } 17630 }; 17631 17632 static struct unit_test_suite cryptodev_null_testsuite = { 17633 .suite_name = "NULL Test Suite", 17634 .setup = null_testsuite_setup, 17635 .unit_test_cases = { 17636 TEST_CASE_ST(ut_setup, ut_teardown, 17637 test_null_invalid_operation), 17638 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation), 17639 TEST_CASES_END() 17640 } 17641 }; 17642 17643 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite = { 17644 .suite_name = "AES CCM Authenticated Test Suite", 17645 .setup = aes_ccm_auth_testsuite_setup, 17646 .unit_test_cases = { 17647 /** AES CCM Authenticated Encryption 128 bits key*/ 17648 TEST_CASE_ST(ut_setup, ut_teardown, 17649 test_AES_CCM_authenticated_encryption_test_case_128_1), 17650 TEST_CASE_ST(ut_setup, ut_teardown, 17651 test_AES_CCM_authenticated_encryption_test_case_128_2), 17652 TEST_CASE_ST(ut_setup, ut_teardown, 17653 test_AES_CCM_authenticated_encryption_test_case_128_3), 17654 17655 /** AES CCM Authenticated Decryption 128 bits key*/ 17656 TEST_CASE_ST(ut_setup, ut_teardown, 17657 test_AES_CCM_authenticated_decryption_test_case_128_1), 17658 TEST_CASE_ST(ut_setup, ut_teardown, 17659 test_AES_CCM_authenticated_decryption_test_case_128_2), 17660 TEST_CASE_ST(ut_setup, ut_teardown, 17661 test_AES_CCM_authenticated_decryption_test_case_128_3), 17662 17663 /** AES CCM Authenticated Encryption 192 bits key */ 17664 TEST_CASE_ST(ut_setup, ut_teardown, 17665 test_AES_CCM_authenticated_encryption_test_case_192_1), 17666 TEST_CASE_ST(ut_setup, ut_teardown, 17667 test_AES_CCM_authenticated_encryption_test_case_192_2), 17668 TEST_CASE_ST(ut_setup, ut_teardown, 17669 test_AES_CCM_authenticated_encryption_test_case_192_3), 17670 17671 /** AES CCM Authenticated Decryption 192 bits key*/ 17672 TEST_CASE_ST(ut_setup, ut_teardown, 17673 test_AES_CCM_authenticated_decryption_test_case_192_1), 17674 TEST_CASE_ST(ut_setup, ut_teardown, 17675 test_AES_CCM_authenticated_decryption_test_case_192_2), 17676 TEST_CASE_ST(ut_setup, ut_teardown, 17677 test_AES_CCM_authenticated_decryption_test_case_192_3), 17678 17679 /** AES CCM Authenticated Encryption 256 bits key */ 17680 TEST_CASE_ST(ut_setup, ut_teardown, 17681 test_AES_CCM_authenticated_encryption_test_case_256_1), 17682 TEST_CASE_ST(ut_setup, ut_teardown, 17683 test_AES_CCM_authenticated_encryption_test_case_256_2), 17684 TEST_CASE_ST(ut_setup, ut_teardown, 17685 test_AES_CCM_authenticated_encryption_test_case_256_3), 17686 17687 /** AES CCM Authenticated Decryption 256 bits key*/ 17688 TEST_CASE_ST(ut_setup, ut_teardown, 17689 test_AES_CCM_authenticated_decryption_test_case_256_1), 17690 TEST_CASE_ST(ut_setup, ut_teardown, 17691 test_AES_CCM_authenticated_decryption_test_case_256_2), 17692 TEST_CASE_ST(ut_setup, ut_teardown, 17693 test_AES_CCM_authenticated_decryption_test_case_256_3), 17694 TEST_CASES_END() 17695 } 17696 }; 17697 17698 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite = { 17699 .suite_name = "AES GCM Authenticated Test Suite", 17700 .setup = aes_gcm_auth_testsuite_setup, 17701 .unit_test_cases = { 17702 /** AES GCM Authenticated Encryption */ 17703 TEST_CASE_ST(ut_setup, ut_teardown, 17704 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 17705 TEST_CASE_ST(ut_setup, ut_teardown, 17706 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 17707 TEST_CASE_ST(ut_setup, ut_teardown, 17708 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 17709 TEST_CASE_ST(ut_setup, ut_teardown, 17710 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 17711 TEST_CASE_ST(ut_setup, ut_teardown, 17712 test_AES_GCM_authenticated_encryption_test_case_1), 17713 TEST_CASE_ST(ut_setup, ut_teardown, 17714 test_AES_GCM_authenticated_encryption_test_case_2), 17715 TEST_CASE_ST(ut_setup, ut_teardown, 17716 test_AES_GCM_authenticated_encryption_test_case_3), 17717 TEST_CASE_ST(ut_setup, ut_teardown, 17718 test_AES_GCM_authenticated_encryption_test_case_4), 17719 TEST_CASE_ST(ut_setup, ut_teardown, 17720 test_AES_GCM_authenticated_encryption_test_case_5), 17721 TEST_CASE_ST(ut_setup, ut_teardown, 17722 test_AES_GCM_authenticated_encryption_test_case_6), 17723 TEST_CASE_ST(ut_setup, ut_teardown, 17724 test_AES_GCM_authenticated_encryption_test_case_7), 17725 TEST_CASE_ST(ut_setup, ut_teardown, 17726 test_AES_GCM_authenticated_encryption_test_case_8), 17727 TEST_CASE_ST(ut_setup, ut_teardown, 17728 test_AES_GCM_J0_authenticated_encryption_test_case_1), 17729 17730 /** AES GCM Authenticated Decryption */ 17731 TEST_CASE_ST(ut_setup, ut_teardown, 17732 test_AES_GCM_authenticated_decryption_test_case_1), 17733 TEST_CASE_ST(ut_setup, ut_teardown, 17734 test_AES_GCM_authenticated_decryption_test_case_2), 17735 TEST_CASE_ST(ut_setup, ut_teardown, 17736 test_AES_GCM_authenticated_decryption_test_case_3), 17737 TEST_CASE_ST(ut_setup, ut_teardown, 17738 test_AES_GCM_authenticated_decryption_test_case_4), 17739 TEST_CASE_ST(ut_setup, ut_teardown, 17740 test_AES_GCM_authenticated_decryption_test_case_5), 17741 TEST_CASE_ST(ut_setup, ut_teardown, 17742 test_AES_GCM_authenticated_decryption_test_case_6), 17743 TEST_CASE_ST(ut_setup, ut_teardown, 17744 test_AES_GCM_authenticated_decryption_test_case_7), 17745 TEST_CASE_ST(ut_setup, ut_teardown, 17746 test_AES_GCM_authenticated_decryption_test_case_8), 17747 TEST_CASE_ST(ut_setup, ut_teardown, 17748 test_AES_GCM_J0_authenticated_decryption_test_case_1), 17749 17750 /** AES GCM Authenticated Encryption 192 bits key */ 17751 TEST_CASE_ST(ut_setup, ut_teardown, 17752 test_AES_GCM_auth_encryption_test_case_192_1), 17753 TEST_CASE_ST(ut_setup, ut_teardown, 17754 test_AES_GCM_auth_encryption_test_case_192_2), 17755 TEST_CASE_ST(ut_setup, ut_teardown, 17756 test_AES_GCM_auth_encryption_test_case_192_3), 17757 TEST_CASE_ST(ut_setup, ut_teardown, 17758 test_AES_GCM_auth_encryption_test_case_192_4), 17759 TEST_CASE_ST(ut_setup, ut_teardown, 17760 test_AES_GCM_auth_encryption_test_case_192_5), 17761 TEST_CASE_ST(ut_setup, ut_teardown, 17762 test_AES_GCM_auth_encryption_test_case_192_6), 17763 TEST_CASE_ST(ut_setup, ut_teardown, 17764 test_AES_GCM_auth_encryption_test_case_192_7), 17765 17766 /** AES GCM Authenticated Decryption 192 bits key */ 17767 TEST_CASE_ST(ut_setup, ut_teardown, 17768 test_AES_GCM_auth_decryption_test_case_192_1), 17769 TEST_CASE_ST(ut_setup, ut_teardown, 17770 test_AES_GCM_auth_decryption_test_case_192_2), 17771 TEST_CASE_ST(ut_setup, ut_teardown, 17772 test_AES_GCM_auth_decryption_test_case_192_3), 17773 TEST_CASE_ST(ut_setup, ut_teardown, 17774 test_AES_GCM_auth_decryption_test_case_192_4), 17775 TEST_CASE_ST(ut_setup, ut_teardown, 17776 test_AES_GCM_auth_decryption_test_case_192_5), 17777 TEST_CASE_ST(ut_setup, ut_teardown, 17778 test_AES_GCM_auth_decryption_test_case_192_6), 17779 TEST_CASE_ST(ut_setup, ut_teardown, 17780 test_AES_GCM_auth_decryption_test_case_192_7), 17781 17782 /** AES GCM Authenticated Encryption 256 bits key */ 17783 TEST_CASE_ST(ut_setup, ut_teardown, 17784 test_AES_GCM_auth_encryption_test_case_256_1), 17785 TEST_CASE_ST(ut_setup, ut_teardown, 17786 test_AES_GCM_auth_encryption_test_case_256_2), 17787 TEST_CASE_ST(ut_setup, ut_teardown, 17788 test_AES_GCM_auth_encryption_test_case_256_3), 17789 TEST_CASE_ST(ut_setup, ut_teardown, 17790 test_AES_GCM_auth_encryption_test_case_256_4), 17791 TEST_CASE_ST(ut_setup, ut_teardown, 17792 test_AES_GCM_auth_encryption_test_case_256_5), 17793 TEST_CASE_ST(ut_setup, ut_teardown, 17794 test_AES_GCM_auth_encryption_test_case_256_6), 17795 TEST_CASE_ST(ut_setup, ut_teardown, 17796 test_AES_GCM_auth_encryption_test_case_256_7), 17797 TEST_CASE_ST(ut_setup, ut_teardown, 17798 test_AES_GCM_auth_encryption_test_case_256_8), 17799 17800 /** AES GCM Authenticated Decryption 256 bits key */ 17801 TEST_CASE_ST(ut_setup, ut_teardown, 17802 test_AES_GCM_auth_decryption_test_case_256_1), 17803 TEST_CASE_ST(ut_setup, ut_teardown, 17804 test_AES_GCM_auth_decryption_test_case_256_2), 17805 TEST_CASE_ST(ut_setup, ut_teardown, 17806 test_AES_GCM_auth_decryption_test_case_256_3), 17807 TEST_CASE_ST(ut_setup, ut_teardown, 17808 test_AES_GCM_auth_decryption_test_case_256_4), 17809 TEST_CASE_ST(ut_setup, ut_teardown, 17810 test_AES_GCM_auth_decryption_test_case_256_5), 17811 TEST_CASE_ST(ut_setup, ut_teardown, 17812 test_AES_GCM_auth_decryption_test_case_256_6), 17813 TEST_CASE_ST(ut_setup, ut_teardown, 17814 test_AES_GCM_auth_decryption_test_case_256_7), 17815 TEST_CASE_ST(ut_setup, ut_teardown, 17816 test_AES_GCM_auth_decryption_test_case_256_8), 17817 17818 /** AES GCM Authenticated Encryption big aad size */ 17819 TEST_CASE_ST(ut_setup, ut_teardown, 17820 test_AES_GCM_auth_encryption_test_case_aad_1), 17821 TEST_CASE_ST(ut_setup, ut_teardown, 17822 test_AES_GCM_auth_encryption_test_case_aad_2), 17823 17824 /** AES GCM Authenticated Decryption big aad size */ 17825 TEST_CASE_ST(ut_setup, ut_teardown, 17826 test_AES_GCM_auth_decryption_test_case_aad_1), 17827 TEST_CASE_ST(ut_setup, ut_teardown, 17828 test_AES_GCM_auth_decryption_test_case_aad_2), 17829 17830 /** Out of place tests */ 17831 TEST_CASE_ST(ut_setup, ut_teardown, 17832 test_AES_GCM_authenticated_encryption_oop_test_case_1), 17833 TEST_CASE_ST(ut_setup, ut_teardown, 17834 test_AES_GCM_authenticated_decryption_oop_test_case_1), 17835 17836 /** Session-less tests */ 17837 TEST_CASE_ST(ut_setup, ut_teardown, 17838 test_AES_GCM_authenticated_encryption_sessionless_test_case_1), 17839 TEST_CASE_ST(ut_setup, ut_teardown, 17840 test_AES_GCM_authenticated_decryption_sessionless_test_case_1), 17841 17842 /** AES GCM external mbuf tests */ 17843 TEST_CASE_ST(ut_setup, ut_teardown, 17844 test_AES_GCM_authenticated_encryption_test_case_3_ext_mbuf), 17845 TEST_CASE_ST(ut_setup, ut_teardown, 17846 test_AES_GCM_authenticated_decryption_test_case_3_ext_mbuf), 17847 17848 TEST_CASES_END() 17849 } 17850 }; 17851 17852 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite = { 17853 .suite_name = "AES GMAC Authentication Test Suite", 17854 .setup = aes_gmac_auth_testsuite_setup, 17855 .unit_test_cases = { 17856 TEST_CASE_ST(ut_setup, ut_teardown, 17857 test_AES_GMAC_authentication_test_case_1), 17858 TEST_CASE_ST(ut_setup, ut_teardown, 17859 test_AES_GMAC_authentication_verify_test_case_1), 17860 TEST_CASE_ST(ut_setup, ut_teardown, 17861 test_AES_GMAC_authentication_test_case_2), 17862 TEST_CASE_ST(ut_setup, ut_teardown, 17863 test_AES_GMAC_authentication_verify_test_case_2), 17864 TEST_CASE_ST(ut_setup, ut_teardown, 17865 test_AES_GMAC_authentication_test_case_3), 17866 TEST_CASE_ST(ut_setup, ut_teardown, 17867 test_AES_GMAC_authentication_verify_test_case_3), 17868 TEST_CASE_ST(ut_setup, ut_teardown, 17869 test_AES_GMAC_authentication_test_case_4), 17870 TEST_CASE_ST(ut_setup, ut_teardown, 17871 test_AES_GMAC_authentication_verify_test_case_4), 17872 TEST_CASE_ST(ut_setup, ut_teardown, 17873 test_AES_GMAC_authentication_SGL_40B), 17874 TEST_CASE_ST(ut_setup, ut_teardown, 17875 test_AES_GMAC_authentication_SGL_80B), 17876 TEST_CASE_ST(ut_setup, ut_teardown, 17877 test_AES_GMAC_authentication_SGL_2048B), 17878 TEST_CASE_ST(ut_setup, ut_teardown, 17879 test_AES_GMAC_authentication_SGL_2047B), 17880 17881 TEST_CASES_END() 17882 } 17883 }; 17884 17885 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite = { 17886 .suite_name = "Chacha20-Poly1305 Test Suite", 17887 .setup = chacha20_poly1305_testsuite_setup, 17888 .unit_test_cases = { 17889 TEST_CASE_ST(ut_setup, ut_teardown, 17890 test_chacha20_poly1305_encrypt_test_case_rfc8439), 17891 TEST_CASE_ST(ut_setup, ut_teardown, 17892 test_chacha20_poly1305_decrypt_test_case_rfc8439), 17893 TEST_CASE_ST(ut_setup, ut_teardown, 17894 test_chacha20_poly1305_encrypt_SGL_out_of_place), 17895 TEST_CASES_END() 17896 } 17897 }; 17898 17899 static struct unit_test_suite cryptodev_snow3g_testsuite = { 17900 .suite_name = "SNOW 3G Test Suite", 17901 .setup = snow3g_testsuite_setup, 17902 .unit_test_cases = { 17903 /** SNOW 3G encrypt only (UEA2) */ 17904 TEST_CASE_ST(ut_setup, ut_teardown, 17905 test_snow3g_encryption_test_case_1), 17906 TEST_CASE_ST(ut_setup, ut_teardown, 17907 test_snow3g_encryption_test_case_2), 17908 TEST_CASE_ST(ut_setup, ut_teardown, 17909 test_snow3g_encryption_test_case_3), 17910 TEST_CASE_ST(ut_setup, ut_teardown, 17911 test_snow3g_encryption_test_case_4), 17912 TEST_CASE_ST(ut_setup, ut_teardown, 17913 test_snow3g_encryption_test_case_5), 17914 17915 TEST_CASE_ST(ut_setup, ut_teardown, 17916 test_snow3g_encryption_test_case_1_oop), 17917 TEST_CASE_ST(ut_setup, ut_teardown, 17918 test_snow3g_encryption_test_case_1_oop_sgl), 17919 TEST_CASE_ST(ut_setup, ut_teardown, 17920 test_snow3g_encryption_test_case_1_oop_lb_in_sgl_out), 17921 TEST_CASE_ST(ut_setup, ut_teardown, 17922 test_snow3g_encryption_test_case_1_oop_sgl_in_lb_out), 17923 TEST_CASE_ST(ut_setup, ut_teardown, 17924 test_snow3g_encryption_test_case_1_offset_oop), 17925 TEST_CASE_ST(ut_setup, ut_teardown, 17926 test_snow3g_decryption_test_case_1_oop), 17927 17928 /** SNOW 3G generate auth, then encrypt (UEA2) */ 17929 TEST_CASE_ST(ut_setup, ut_teardown, 17930 test_snow3g_auth_cipher_test_case_1), 17931 TEST_CASE_ST(ut_setup, ut_teardown, 17932 test_snow3g_auth_cipher_test_case_2), 17933 TEST_CASE_ST(ut_setup, ut_teardown, 17934 test_snow3g_auth_cipher_test_case_2_oop), 17935 TEST_CASE_ST(ut_setup, ut_teardown, 17936 test_snow3g_auth_cipher_part_digest_enc), 17937 TEST_CASE_ST(ut_setup, ut_teardown, 17938 test_snow3g_auth_cipher_part_digest_enc_oop), 17939 TEST_CASE_ST(ut_setup, ut_teardown, 17940 test_snow3g_auth_cipher_test_case_3_sgl), 17941 TEST_CASE_ST(ut_setup, ut_teardown, 17942 test_snow3g_auth_cipher_test_case_3_oop_sgl), 17943 TEST_CASE_ST(ut_setup, ut_teardown, 17944 test_snow3g_auth_cipher_part_digest_enc_sgl), 17945 TEST_CASE_ST(ut_setup, ut_teardown, 17946 test_snow3g_auth_cipher_part_digest_enc_oop_sgl), 17947 TEST_CASE_ST(ut_setup, ut_teardown, 17948 test_snow3g_auth_cipher_total_digest_enc_1), 17949 TEST_CASE_ST(ut_setup, ut_teardown, 17950 test_snow3g_auth_cipher_total_digest_enc_1_oop), 17951 TEST_CASE_ST(ut_setup, ut_teardown, 17952 test_snow3g_auth_cipher_total_digest_enc_1_sgl), 17953 TEST_CASE_ST(ut_setup, ut_teardown, 17954 test_snow3g_auth_cipher_total_digest_enc_1_oop_sgl), 17955 17956 /** SNOW 3G decrypt (UEA2), then verify auth */ 17957 TEST_CASE_ST(ut_setup, ut_teardown, 17958 test_snow3g_auth_cipher_verify_test_case_1), 17959 TEST_CASE_ST(ut_setup, ut_teardown, 17960 test_snow3g_auth_cipher_verify_test_case_2), 17961 TEST_CASE_ST(ut_setup, ut_teardown, 17962 test_snow3g_auth_cipher_verify_test_case_2_oop), 17963 TEST_CASE_ST(ut_setup, ut_teardown, 17964 test_snow3g_auth_cipher_verify_part_digest_enc), 17965 TEST_CASE_ST(ut_setup, ut_teardown, 17966 test_snow3g_auth_cipher_verify_part_digest_enc_oop), 17967 TEST_CASE_ST(ut_setup, ut_teardown, 17968 test_snow3g_auth_cipher_verify_test_case_3_sgl), 17969 TEST_CASE_ST(ut_setup, ut_teardown, 17970 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl), 17971 TEST_CASE_ST(ut_setup, ut_teardown, 17972 test_snow3g_auth_cipher_verify_part_digest_enc_sgl), 17973 TEST_CASE_ST(ut_setup, ut_teardown, 17974 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl), 17975 TEST_CASE_ST(ut_setup, ut_teardown, 17976 test_snow3g_auth_cipher_verify_total_digest_enc_1), 17977 TEST_CASE_ST(ut_setup, ut_teardown, 17978 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop), 17979 TEST_CASE_ST(ut_setup, ut_teardown, 17980 test_snow3g_auth_cipher_verify_total_digest_enc_1_sgl), 17981 TEST_CASE_ST(ut_setup, ut_teardown, 17982 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop_sgl), 17983 17984 /** SNOW 3G decrypt only (UEA2) */ 17985 TEST_CASE_ST(ut_setup, ut_teardown, 17986 test_snow3g_decryption_test_case_1), 17987 TEST_CASE_ST(ut_setup, ut_teardown, 17988 test_snow3g_decryption_test_case_2), 17989 TEST_CASE_ST(ut_setup, ut_teardown, 17990 test_snow3g_decryption_test_case_3), 17991 TEST_CASE_ST(ut_setup, ut_teardown, 17992 test_snow3g_decryption_test_case_4), 17993 TEST_CASE_ST(ut_setup, ut_teardown, 17994 test_snow3g_decryption_test_case_5), 17995 TEST_CASE_ST(ut_setup, ut_teardown, 17996 test_snow3g_decryption_with_digest_test_case_1), 17997 TEST_CASE_ST(ut_setup, ut_teardown, 17998 test_snow3g_hash_generate_test_case_1), 17999 TEST_CASE_ST(ut_setup, ut_teardown, 18000 test_snow3g_hash_generate_test_case_2), 18001 TEST_CASE_ST(ut_setup, ut_teardown, 18002 test_snow3g_hash_generate_test_case_3), 18003 18004 /* Tests with buffers which length is not byte-aligned */ 18005 TEST_CASE_ST(ut_setup, ut_teardown, 18006 test_snow3g_hash_generate_test_case_4), 18007 TEST_CASE_ST(ut_setup, ut_teardown, 18008 test_snow3g_hash_generate_test_case_5), 18009 TEST_CASE_ST(ut_setup, ut_teardown, 18010 test_snow3g_hash_generate_test_case_6), 18011 TEST_CASE_ST(ut_setup, ut_teardown, 18012 test_snow3g_hash_verify_test_case_1), 18013 TEST_CASE_ST(ut_setup, ut_teardown, 18014 test_snow3g_hash_verify_test_case_2), 18015 TEST_CASE_ST(ut_setup, ut_teardown, 18016 test_snow3g_hash_verify_test_case_3), 18017 18018 /* Tests with buffers which length is not byte-aligned */ 18019 TEST_CASE_ST(ut_setup, ut_teardown, 18020 test_snow3g_hash_verify_test_case_4), 18021 TEST_CASE_ST(ut_setup, ut_teardown, 18022 test_snow3g_hash_verify_test_case_5), 18023 TEST_CASE_ST(ut_setup, ut_teardown, 18024 test_snow3g_hash_verify_test_case_6), 18025 TEST_CASE_ST(ut_setup, ut_teardown, 18026 test_snow3g_cipher_auth_test_case_1), 18027 TEST_CASE_ST(ut_setup, ut_teardown, 18028 test_snow3g_auth_cipher_with_digest_test_case_1), 18029 TEST_CASES_END() 18030 } 18031 }; 18032 18033 static struct unit_test_suite cryptodev_zuc_testsuite = { 18034 .suite_name = "ZUC Test Suite", 18035 .setup = zuc_testsuite_setup, 18036 .unit_test_cases = { 18037 /** ZUC encrypt only (EEA3) */ 18038 TEST_CASE_ST(ut_setup, ut_teardown, 18039 test_zuc_encryption_test_case_1), 18040 TEST_CASE_ST(ut_setup, ut_teardown, 18041 test_zuc_encryption_test_case_2), 18042 TEST_CASE_ST(ut_setup, ut_teardown, 18043 test_zuc_encryption_test_case_3), 18044 TEST_CASE_ST(ut_setup, ut_teardown, 18045 test_zuc_encryption_test_case_4), 18046 TEST_CASE_ST(ut_setup, ut_teardown, 18047 test_zuc_encryption_test_case_5), 18048 TEST_CASE_ST(ut_setup, ut_teardown, 18049 test_zuc_encryption_test_case_6_sgl), 18050 18051 /** ZUC decrypt only (EEA3) */ 18052 TEST_CASE_ST(ut_setup, ut_teardown, 18053 test_zuc_decryption_test_case_1), 18054 TEST_CASE_ST(ut_setup, ut_teardown, 18055 test_zuc_decryption_test_case_2), 18056 TEST_CASE_ST(ut_setup, ut_teardown, 18057 test_zuc_decryption_test_case_3), 18058 TEST_CASE_ST(ut_setup, ut_teardown, 18059 test_zuc_decryption_test_case_4), 18060 TEST_CASE_ST(ut_setup, ut_teardown, 18061 test_zuc_decryption_test_case_5), 18062 TEST_CASE_ST(ut_setup, ut_teardown, 18063 test_zuc_decryption_test_case_6_sgl), 18064 18065 /** ZUC authenticate (EIA3) */ 18066 TEST_CASE_ST(ut_setup, ut_teardown, 18067 test_zuc_hash_generate_test_case_1), 18068 TEST_CASE_ST(ut_setup, ut_teardown, 18069 test_zuc_hash_generate_test_case_2), 18070 TEST_CASE_ST(ut_setup, ut_teardown, 18071 test_zuc_hash_generate_test_case_3), 18072 TEST_CASE_ST(ut_setup, ut_teardown, 18073 test_zuc_hash_generate_test_case_4), 18074 TEST_CASE_ST(ut_setup, ut_teardown, 18075 test_zuc_hash_generate_test_case_5), 18076 TEST_CASE_ST(ut_setup, ut_teardown, 18077 test_zuc_hash_generate_test_case_6), 18078 TEST_CASE_ST(ut_setup, ut_teardown, 18079 test_zuc_hash_generate_test_case_7), 18080 TEST_CASE_ST(ut_setup, ut_teardown, 18081 test_zuc_hash_generate_test_case_8), 18082 18083 /** ZUC verify (EIA3) */ 18084 TEST_CASE_ST(ut_setup, ut_teardown, 18085 test_zuc_hash_verify_test_case_1), 18086 TEST_CASE_ST(ut_setup, ut_teardown, 18087 test_zuc_hash_verify_test_case_2), 18088 TEST_CASE_ST(ut_setup, ut_teardown, 18089 test_zuc_hash_verify_test_case_3), 18090 TEST_CASE_ST(ut_setup, ut_teardown, 18091 test_zuc_hash_verify_test_case_4), 18092 TEST_CASE_ST(ut_setup, ut_teardown, 18093 test_zuc_hash_verify_test_case_5), 18094 TEST_CASE_ST(ut_setup, ut_teardown, 18095 test_zuc_hash_verify_test_case_6), 18096 TEST_CASE_ST(ut_setup, ut_teardown, 18097 test_zuc_hash_verify_test_case_7), 18098 TEST_CASE_ST(ut_setup, ut_teardown, 18099 test_zuc_hash_verify_test_case_8), 18100 18101 /** ZUC alg-chain (EEA3/EIA3) */ 18102 TEST_CASE_ST(ut_setup, ut_teardown, 18103 test_zuc_cipher_auth_test_case_1), 18104 TEST_CASE_ST(ut_setup, ut_teardown, 18105 test_zuc_cipher_auth_test_case_2), 18106 18107 /** ZUC generate auth, then encrypt (EEA3) */ 18108 TEST_CASE_ST(ut_setup, ut_teardown, 18109 test_zuc_auth_cipher_test_case_1), 18110 TEST_CASE_ST(ut_setup, ut_teardown, 18111 test_zuc_auth_cipher_test_case_1_oop), 18112 TEST_CASE_ST(ut_setup, ut_teardown, 18113 test_zuc_auth_cipher_test_case_1_sgl), 18114 TEST_CASE_ST(ut_setup, ut_teardown, 18115 test_zuc_auth_cipher_test_case_1_oop_sgl), 18116 TEST_CASE_ST(ut_setup, ut_teardown, 18117 test_zuc_auth_cipher_test_case_2), 18118 TEST_CASE_ST(ut_setup, ut_teardown, 18119 test_zuc_auth_cipher_test_case_2_oop), 18120 18121 /** ZUC decrypt (EEA3), then verify auth */ 18122 TEST_CASE_ST(ut_setup, ut_teardown, 18123 test_zuc_auth_cipher_verify_test_case_1), 18124 TEST_CASE_ST(ut_setup, ut_teardown, 18125 test_zuc_auth_cipher_verify_test_case_1_oop), 18126 TEST_CASE_ST(ut_setup, ut_teardown, 18127 test_zuc_auth_cipher_verify_test_case_1_sgl), 18128 TEST_CASE_ST(ut_setup, ut_teardown, 18129 test_zuc_auth_cipher_verify_test_case_1_oop_sgl), 18130 TEST_CASE_ST(ut_setup, ut_teardown, 18131 test_zuc_auth_cipher_verify_test_case_2), 18132 TEST_CASE_ST(ut_setup, ut_teardown, 18133 test_zuc_auth_cipher_verify_test_case_2_oop), 18134 18135 /** ZUC-256 encrypt only **/ 18136 TEST_CASE_ST(ut_setup, ut_teardown, 18137 test_zuc256_encryption_test_case_1), 18138 TEST_CASE_ST(ut_setup, ut_teardown, 18139 test_zuc256_encryption_test_case_2), 18140 18141 /** ZUC-256 decrypt only **/ 18142 TEST_CASE_ST(ut_setup, ut_teardown, 18143 test_zuc256_decryption_test_case_1), 18144 TEST_CASE_ST(ut_setup, ut_teardown, 18145 test_zuc256_decryption_test_case_2), 18146 18147 /** ZUC-256 authentication only **/ 18148 TEST_CASE_ST(ut_setup, ut_teardown, 18149 test_zuc256_hash_generate_4b_tag_test_case_1), 18150 TEST_CASE_ST(ut_setup, ut_teardown, 18151 test_zuc256_hash_generate_4b_tag_test_case_2), 18152 TEST_CASE_ST(ut_setup, ut_teardown, 18153 test_zuc256_hash_generate_4b_tag_test_case_3), 18154 TEST_CASE_ST(ut_setup, ut_teardown, 18155 test_zuc256_hash_generate_8b_tag_test_case_1), 18156 TEST_CASE_ST(ut_setup, ut_teardown, 18157 test_zuc256_hash_generate_16b_tag_test_case_1), 18158 18159 /** ZUC-256 authentication verify only **/ 18160 TEST_CASE_ST(ut_setup, ut_teardown, 18161 test_zuc256_hash_verify_4b_tag_test_case_1), 18162 TEST_CASE_ST(ut_setup, ut_teardown, 18163 test_zuc256_hash_verify_4b_tag_test_case_2), 18164 TEST_CASE_ST(ut_setup, ut_teardown, 18165 test_zuc256_hash_verify_4b_tag_test_case_3), 18166 TEST_CASE_ST(ut_setup, ut_teardown, 18167 test_zuc256_hash_verify_8b_tag_test_case_1), 18168 TEST_CASE_ST(ut_setup, ut_teardown, 18169 test_zuc256_hash_verify_16b_tag_test_case_1), 18170 18171 /** ZUC-256 encrypt and authenticate **/ 18172 TEST_CASE_ST(ut_setup, ut_teardown, 18173 test_zuc256_cipher_auth_4b_tag_test_case_1), 18174 TEST_CASE_ST(ut_setup, ut_teardown, 18175 test_zuc256_cipher_auth_4b_tag_test_case_2), 18176 TEST_CASE_ST(ut_setup, ut_teardown, 18177 test_zuc256_cipher_auth_8b_tag_test_case_1), 18178 TEST_CASE_ST(ut_setup, ut_teardown, 18179 test_zuc256_cipher_auth_16b_tag_test_case_1), 18180 18181 /** ZUC-256 generate auth, then encrypt */ 18182 TEST_CASE_ST(ut_setup, ut_teardown, 18183 test_zuc256_auth_cipher_4b_tag_test_case_1), 18184 TEST_CASE_ST(ut_setup, ut_teardown, 18185 test_zuc256_auth_cipher_4b_tag_test_case_2), 18186 TEST_CASE_ST(ut_setup, ut_teardown, 18187 test_zuc256_auth_cipher_8b_tag_test_case_1), 18188 TEST_CASE_ST(ut_setup, ut_teardown, 18189 test_zuc256_auth_cipher_16b_tag_test_case_1), 18190 18191 /** ZUC-256 decrypt, then verify auth */ 18192 TEST_CASE_ST(ut_setup, ut_teardown, 18193 test_zuc256_auth_cipher_verify_4b_tag_test_case_1), 18194 TEST_CASE_ST(ut_setup, ut_teardown, 18195 test_zuc256_auth_cipher_verify_4b_tag_test_case_2), 18196 TEST_CASE_ST(ut_setup, ut_teardown, 18197 test_zuc256_auth_cipher_verify_8b_tag_test_case_1), 18198 TEST_CASE_ST(ut_setup, ut_teardown, 18199 test_zuc256_auth_cipher_verify_16b_tag_test_case_1), 18200 18201 TEST_CASES_END() 18202 } 18203 }; 18204 18205 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite = { 18206 .suite_name = "HMAC_MD5 Authentication Test Suite", 18207 .setup = hmac_md5_auth_testsuite_setup, 18208 .unit_test_cases = { 18209 TEST_CASE_ST(ut_setup, ut_teardown, 18210 test_MD5_HMAC_generate_case_1), 18211 TEST_CASE_ST(ut_setup, ut_teardown, 18212 test_MD5_HMAC_verify_case_1), 18213 TEST_CASE_ST(ut_setup, ut_teardown, 18214 test_MD5_HMAC_generate_case_2), 18215 TEST_CASE_ST(ut_setup, ut_teardown, 18216 test_MD5_HMAC_verify_case_2), 18217 TEST_CASES_END() 18218 } 18219 }; 18220 18221 static struct unit_test_suite cryptodev_kasumi_testsuite = { 18222 .suite_name = "Kasumi Test Suite", 18223 .setup = kasumi_testsuite_setup, 18224 .unit_test_cases = { 18225 /** KASUMI hash only (UIA1) */ 18226 TEST_CASE_ST(ut_setup, ut_teardown, 18227 test_kasumi_hash_generate_test_case_1), 18228 TEST_CASE_ST(ut_setup, ut_teardown, 18229 test_kasumi_hash_generate_test_case_2), 18230 TEST_CASE_ST(ut_setup, ut_teardown, 18231 test_kasumi_hash_generate_test_case_3), 18232 TEST_CASE_ST(ut_setup, ut_teardown, 18233 test_kasumi_hash_generate_test_case_4), 18234 TEST_CASE_ST(ut_setup, ut_teardown, 18235 test_kasumi_hash_generate_test_case_5), 18236 TEST_CASE_ST(ut_setup, ut_teardown, 18237 test_kasumi_hash_generate_test_case_6), 18238 18239 TEST_CASE_ST(ut_setup, ut_teardown, 18240 test_kasumi_hash_verify_test_case_1), 18241 TEST_CASE_ST(ut_setup, ut_teardown, 18242 test_kasumi_hash_verify_test_case_2), 18243 TEST_CASE_ST(ut_setup, ut_teardown, 18244 test_kasumi_hash_verify_test_case_3), 18245 TEST_CASE_ST(ut_setup, ut_teardown, 18246 test_kasumi_hash_verify_test_case_4), 18247 TEST_CASE_ST(ut_setup, ut_teardown, 18248 test_kasumi_hash_verify_test_case_5), 18249 18250 /** KASUMI encrypt only (UEA1) */ 18251 TEST_CASE_ST(ut_setup, ut_teardown, 18252 test_kasumi_encryption_test_case_1), 18253 TEST_CASE_ST(ut_setup, ut_teardown, 18254 test_kasumi_encryption_test_case_1_sgl), 18255 TEST_CASE_ST(ut_setup, ut_teardown, 18256 test_kasumi_encryption_test_case_1_oop), 18257 TEST_CASE_ST(ut_setup, ut_teardown, 18258 test_kasumi_encryption_test_case_1_oop_sgl), 18259 TEST_CASE_ST(ut_setup, ut_teardown, 18260 test_kasumi_encryption_test_case_2), 18261 TEST_CASE_ST(ut_setup, ut_teardown, 18262 test_kasumi_encryption_test_case_3), 18263 TEST_CASE_ST(ut_setup, ut_teardown, 18264 test_kasumi_encryption_test_case_4), 18265 TEST_CASE_ST(ut_setup, ut_teardown, 18266 test_kasumi_encryption_test_case_5), 18267 18268 /** KASUMI decrypt only (UEA1) */ 18269 TEST_CASE_ST(ut_setup, ut_teardown, 18270 test_kasumi_decryption_test_case_1), 18271 TEST_CASE_ST(ut_setup, ut_teardown, 18272 test_kasumi_decryption_test_case_2), 18273 TEST_CASE_ST(ut_setup, ut_teardown, 18274 test_kasumi_decryption_test_case_3), 18275 TEST_CASE_ST(ut_setup, ut_teardown, 18276 test_kasumi_decryption_test_case_4), 18277 TEST_CASE_ST(ut_setup, ut_teardown, 18278 test_kasumi_decryption_test_case_5), 18279 TEST_CASE_ST(ut_setup, ut_teardown, 18280 test_kasumi_decryption_test_case_1_oop), 18281 TEST_CASE_ST(ut_setup, ut_teardown, 18282 test_kasumi_cipher_auth_test_case_1), 18283 18284 /** KASUMI generate auth, then encrypt (F8) */ 18285 TEST_CASE_ST(ut_setup, ut_teardown, 18286 test_kasumi_auth_cipher_test_case_1), 18287 TEST_CASE_ST(ut_setup, ut_teardown, 18288 test_kasumi_auth_cipher_test_case_2), 18289 TEST_CASE_ST(ut_setup, ut_teardown, 18290 test_kasumi_auth_cipher_test_case_2_oop), 18291 TEST_CASE_ST(ut_setup, ut_teardown, 18292 test_kasumi_auth_cipher_test_case_2_sgl), 18293 TEST_CASE_ST(ut_setup, ut_teardown, 18294 test_kasumi_auth_cipher_test_case_2_oop_sgl), 18295 18296 /** KASUMI decrypt (F8), then verify auth */ 18297 TEST_CASE_ST(ut_setup, ut_teardown, 18298 test_kasumi_auth_cipher_verify_test_case_1), 18299 TEST_CASE_ST(ut_setup, ut_teardown, 18300 test_kasumi_auth_cipher_verify_test_case_2), 18301 TEST_CASE_ST(ut_setup, ut_teardown, 18302 test_kasumi_auth_cipher_verify_test_case_2_oop), 18303 TEST_CASE_ST(ut_setup, ut_teardown, 18304 test_kasumi_auth_cipher_verify_test_case_2_sgl), 18305 TEST_CASE_ST(ut_setup, ut_teardown, 18306 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl), 18307 18308 TEST_CASES_END() 18309 } 18310 }; 18311 18312 static struct unit_test_suite cryptodev_esn_testsuite = { 18313 .suite_name = "ESN Test Suite", 18314 .setup = esn_testsuite_setup, 18315 .unit_test_cases = { 18316 TEST_CASE_ST(ut_setup, ut_teardown, 18317 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 18318 TEST_CASE_ST(ut_setup, ut_teardown, 18319 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 18320 TEST_CASES_END() 18321 } 18322 }; 18323 18324 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite = { 18325 .suite_name = "Negative AES GCM Test Suite", 18326 .setup = negative_aes_gcm_testsuite_setup, 18327 .unit_test_cases = { 18328 TEST_CASE_ST(ut_setup, ut_teardown, 18329 test_AES_GCM_auth_encryption_fail_iv_corrupt), 18330 TEST_CASE_ST(ut_setup, ut_teardown, 18331 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 18332 TEST_CASE_ST(ut_setup, ut_teardown, 18333 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 18334 TEST_CASE_ST(ut_setup, ut_teardown, 18335 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 18336 TEST_CASE_ST(ut_setup, ut_teardown, 18337 test_AES_GCM_auth_encryption_fail_aad_corrupt), 18338 TEST_CASE_ST(ut_setup, ut_teardown, 18339 test_AES_GCM_auth_encryption_fail_tag_corrupt), 18340 TEST_CASE_ST(ut_setup, ut_teardown, 18341 test_AES_GCM_auth_decryption_fail_iv_corrupt), 18342 TEST_CASE_ST(ut_setup, ut_teardown, 18343 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 18344 TEST_CASE_ST(ut_setup, ut_teardown, 18345 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 18346 TEST_CASE_ST(ut_setup, ut_teardown, 18347 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 18348 TEST_CASE_ST(ut_setup, ut_teardown, 18349 test_AES_GCM_auth_decryption_fail_aad_corrupt), 18350 TEST_CASE_ST(ut_setup, ut_teardown, 18351 test_AES_GCM_auth_decryption_fail_tag_corrupt), 18352 18353 TEST_CASES_END() 18354 } 18355 }; 18356 18357 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite = { 18358 .suite_name = "Negative AES GMAC Test Suite", 18359 .setup = negative_aes_gmac_testsuite_setup, 18360 .unit_test_cases = { 18361 TEST_CASE_ST(ut_setup, ut_teardown, 18362 authentication_verify_AES128_GMAC_fail_data_corrupt), 18363 TEST_CASE_ST(ut_setup, ut_teardown, 18364 authentication_verify_AES128_GMAC_fail_tag_corrupt), 18365 18366 TEST_CASES_END() 18367 } 18368 }; 18369 18370 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite = { 18371 .suite_name = "Mixed CIPHER + HASH algorithms Test Suite", 18372 .setup = mixed_cipher_hash_testsuite_setup, 18373 .unit_test_cases = { 18374 /** AUTH AES CMAC + CIPHER AES CTR */ 18375 TEST_CASE_ST(ut_setup, ut_teardown, 18376 test_aes_cmac_aes_ctr_digest_enc_test_case_1), 18377 TEST_CASE_ST(ut_setup, ut_teardown, 18378 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 18379 TEST_CASE_ST(ut_setup, ut_teardown, 18380 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 18381 TEST_CASE_ST(ut_setup, ut_teardown, 18382 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 18383 TEST_CASE_ST(ut_setup, ut_teardown, 18384 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1), 18385 TEST_CASE_ST(ut_setup, ut_teardown, 18386 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 18387 TEST_CASE_ST(ut_setup, ut_teardown, 18388 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 18389 TEST_CASE_ST(ut_setup, ut_teardown, 18390 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 18391 TEST_CASE_ST(ut_setup, ut_teardown, 18392 test_aes_cmac_aes_ctr_digest_enc_test_case_2), 18393 TEST_CASE_ST(ut_setup, ut_teardown, 18394 test_aes_cmac_aes_ctr_digest_enc_test_case_2_oop), 18395 TEST_CASE_ST(ut_setup, ut_teardown, 18396 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2), 18397 TEST_CASE_ST(ut_setup, ut_teardown, 18398 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2_oop), 18399 18400 /** AUTH ZUC + CIPHER SNOW3G */ 18401 TEST_CASE_ST(ut_setup, ut_teardown, 18402 test_auth_zuc_cipher_snow_test_case_1), 18403 TEST_CASE_ST(ut_setup, ut_teardown, 18404 test_verify_auth_zuc_cipher_snow_test_case_1), 18405 TEST_CASE_ST(ut_setup, ut_teardown, 18406 test_auth_zuc_cipher_snow_test_case_1_inplace), 18407 TEST_CASE_ST(ut_setup, ut_teardown, 18408 test_verify_auth_zuc_cipher_snow_test_case_1_inplace), 18409 /** AUTH AES CMAC + CIPHER SNOW3G */ 18410 TEST_CASE_ST(ut_setup, ut_teardown, 18411 test_auth_aes_cmac_cipher_snow_test_case_1), 18412 TEST_CASE_ST(ut_setup, ut_teardown, 18413 test_verify_auth_aes_cmac_cipher_snow_test_case_1), 18414 TEST_CASE_ST(ut_setup, ut_teardown, 18415 test_auth_aes_cmac_cipher_snow_test_case_1_inplace), 18416 TEST_CASE_ST(ut_setup, ut_teardown, 18417 test_verify_auth_aes_cmac_cipher_snow_test_case_1_inplace), 18418 /** AUTH ZUC + CIPHER AES CTR */ 18419 TEST_CASE_ST(ut_setup, ut_teardown, 18420 test_auth_zuc_cipher_aes_ctr_test_case_1), 18421 TEST_CASE_ST(ut_setup, ut_teardown, 18422 test_verify_auth_zuc_cipher_aes_ctr_test_case_1), 18423 TEST_CASE_ST(ut_setup, ut_teardown, 18424 test_auth_zuc_cipher_aes_ctr_test_case_1_inplace), 18425 TEST_CASE_ST(ut_setup, ut_teardown, 18426 test_verify_auth_zuc_cipher_aes_ctr_test_case_1_inplace), 18427 /** AUTH SNOW3G + CIPHER AES CTR */ 18428 TEST_CASE_ST(ut_setup, ut_teardown, 18429 test_auth_snow_cipher_aes_ctr_test_case_1), 18430 TEST_CASE_ST(ut_setup, ut_teardown, 18431 test_verify_auth_snow_cipher_aes_ctr_test_case_1), 18432 TEST_CASE_ST(ut_setup, ut_teardown, 18433 test_auth_snow_cipher_aes_ctr_test_case_1_inplace), 18434 TEST_CASE_ST(ut_setup, ut_teardown, 18435 test_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl), 18436 TEST_CASE_ST(ut_setup, ut_teardown, 18437 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace), 18438 TEST_CASE_ST(ut_setup, ut_teardown, 18439 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl), 18440 /** AUTH SNOW3G + CIPHER ZUC */ 18441 TEST_CASE_ST(ut_setup, ut_teardown, 18442 test_auth_snow_cipher_zuc_test_case_1), 18443 TEST_CASE_ST(ut_setup, ut_teardown, 18444 test_verify_auth_snow_cipher_zuc_test_case_1), 18445 TEST_CASE_ST(ut_setup, ut_teardown, 18446 test_auth_snow_cipher_zuc_test_case_1_inplace), 18447 TEST_CASE_ST(ut_setup, ut_teardown, 18448 test_verify_auth_snow_cipher_zuc_test_case_1_inplace), 18449 /** AUTH AES CMAC + CIPHER ZUC */ 18450 TEST_CASE_ST(ut_setup, ut_teardown, 18451 test_auth_aes_cmac_cipher_zuc_test_case_1), 18452 TEST_CASE_ST(ut_setup, ut_teardown, 18453 test_verify_auth_aes_cmac_cipher_zuc_test_case_1), 18454 TEST_CASE_ST(ut_setup, ut_teardown, 18455 test_auth_aes_cmac_cipher_zuc_test_case_1_inplace), 18456 TEST_CASE_ST(ut_setup, ut_teardown, 18457 test_verify_auth_aes_cmac_cipher_zuc_test_case_1_inplace), 18458 18459 /** AUTH NULL + CIPHER SNOW3G */ 18460 TEST_CASE_ST(ut_setup, ut_teardown, 18461 test_auth_null_cipher_snow_test_case_1), 18462 TEST_CASE_ST(ut_setup, ut_teardown, 18463 test_verify_auth_null_cipher_snow_test_case_1), 18464 /** AUTH NULL + CIPHER ZUC */ 18465 TEST_CASE_ST(ut_setup, ut_teardown, 18466 test_auth_null_cipher_zuc_test_case_1), 18467 TEST_CASE_ST(ut_setup, ut_teardown, 18468 test_verify_auth_null_cipher_zuc_test_case_1), 18469 /** AUTH SNOW3G + CIPHER NULL */ 18470 TEST_CASE_ST(ut_setup, ut_teardown, 18471 test_auth_snow_cipher_null_test_case_1), 18472 TEST_CASE_ST(ut_setup, ut_teardown, 18473 test_verify_auth_snow_cipher_null_test_case_1), 18474 /** AUTH ZUC + CIPHER NULL */ 18475 TEST_CASE_ST(ut_setup, ut_teardown, 18476 test_auth_zuc_cipher_null_test_case_1), 18477 TEST_CASE_ST(ut_setup, ut_teardown, 18478 test_verify_auth_zuc_cipher_null_test_case_1), 18479 /** AUTH NULL + CIPHER AES CTR */ 18480 TEST_CASE_ST(ut_setup, ut_teardown, 18481 test_auth_null_cipher_aes_ctr_test_case_1), 18482 TEST_CASE_ST(ut_setup, ut_teardown, 18483 test_verify_auth_null_cipher_aes_ctr_test_case_1), 18484 /** AUTH AES CMAC + CIPHER NULL */ 18485 TEST_CASE_ST(ut_setup, ut_teardown, 18486 test_auth_aes_cmac_cipher_null_test_case_1), 18487 TEST_CASE_ST(ut_setup, ut_teardown, 18488 test_verify_auth_aes_cmac_cipher_null_test_case_1), 18489 TEST_CASES_END() 18490 } 18491 }; 18492 18493 static int 18494 run_cryptodev_testsuite(const char *pmd_name) 18495 { 18496 uint8_t ret, j, i = 0, blk_start_idx = 0; 18497 const enum blockcipher_test_type blk_suites[] = { 18498 BLKCIPHER_AES_CHAIN_TYPE, 18499 BLKCIPHER_AES_CIPHERONLY_TYPE, 18500 BLKCIPHER_AES_DOCSIS_TYPE, 18501 BLKCIPHER_3DES_CHAIN_TYPE, 18502 BLKCIPHER_3DES_CIPHERONLY_TYPE, 18503 BLKCIPHER_DES_CIPHERONLY_TYPE, 18504 BLKCIPHER_DES_DOCSIS_TYPE, 18505 BLKCIPHER_SM4_CHAIN_TYPE, 18506 BLKCIPHER_SM4_CIPHERONLY_TYPE, 18507 BLKCIPHER_AUTHONLY_TYPE}; 18508 struct unit_test_suite *static_suites[] = { 18509 &cryptodev_multi_session_testsuite, 18510 &cryptodev_null_testsuite, 18511 &cryptodev_aes_ccm_auth_testsuite, 18512 &cryptodev_aes_gcm_auth_testsuite, 18513 &cryptodev_aes_gmac_auth_testsuite, 18514 &cryptodev_snow3g_testsuite, 18515 &cryptodev_chacha20_poly1305_testsuite, 18516 &cryptodev_zuc_testsuite, 18517 &cryptodev_hmac_md5_auth_testsuite, 18518 &cryptodev_kasumi_testsuite, 18519 &cryptodev_esn_testsuite, 18520 &cryptodev_negative_aes_gcm_testsuite, 18521 &cryptodev_negative_aes_gmac_testsuite, 18522 &cryptodev_mixed_cipher_hash_testsuite, 18523 &cryptodev_negative_hmac_sha1_testsuite, 18524 &cryptodev_gen_testsuite, 18525 #ifdef RTE_LIB_SECURITY 18526 &ipsec_proto_testsuite, 18527 &pdcp_proto_testsuite, 18528 &docsis_proto_testsuite, 18529 &tls12_record_proto_testsuite, 18530 &dtls12_record_proto_testsuite, 18531 #endif 18532 &end_testsuite 18533 }; 18534 static struct unit_test_suite ts = { 18535 .suite_name = "Cryptodev Unit Test Suite", 18536 .setup = testsuite_setup, 18537 .teardown = testsuite_teardown, 18538 .unit_test_cases = {TEST_CASES_END()} 18539 }; 18540 18541 gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name); 18542 18543 if (gbl_driver_id == -1) { 18544 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name); 18545 return TEST_SKIPPED; 18546 } 18547 18548 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 18549 (RTE_DIM(blk_suites) + RTE_DIM(static_suites))); 18550 18551 ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites)); 18552 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 18553 ret = unit_test_suite_runner(&ts); 18554 18555 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites)); 18556 free(ts.unit_test_suites); 18557 return ret; 18558 } 18559 18560 static int 18561 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name) 18562 { 18563 struct rte_cryptodev_info dev_info; 18564 uint8_t i, nb_devs; 18565 int driver_id; 18566 18567 driver_id = rte_cryptodev_driver_id_get(pmd_name); 18568 if (driver_id == -1) { 18569 RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name); 18570 return TEST_SKIPPED; 18571 } 18572 18573 nb_devs = rte_cryptodev_count(); 18574 if (nb_devs < 1) { 18575 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 18576 return TEST_SKIPPED; 18577 } 18578 18579 for (i = 0; i < nb_devs; i++) { 18580 rte_cryptodev_info_get(i, &dev_info); 18581 if (dev_info.driver_id == driver_id) { 18582 if (!(dev_info.feature_flags & flag)) { 18583 RTE_LOG(INFO, USER1, "%s not supported\n", 18584 flag_name); 18585 return TEST_SKIPPED; 18586 } 18587 return 0; /* found */ 18588 } 18589 } 18590 18591 RTE_LOG(INFO, USER1, "%s not supported\n", flag_name); 18592 return TEST_SKIPPED; 18593 } 18594 18595 static int 18596 test_cryptodev_qat(void) 18597 { 18598 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 18599 } 18600 18601 static int 18602 test_cryptodev_uadk(void) 18603 { 18604 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_UADK_PMD)); 18605 } 18606 18607 static int 18608 test_cryptodev_virtio(void) 18609 { 18610 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)); 18611 } 18612 18613 static int 18614 test_cryptodev_aesni_mb(void) 18615 { 18616 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 18617 } 18618 18619 static int 18620 test_cryptodev_cpu_aesni_mb(void) 18621 { 18622 int32_t rc; 18623 enum rte_security_session_action_type at = gbl_action_type; 18624 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 18625 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 18626 gbl_action_type = at; 18627 return rc; 18628 } 18629 18630 static int 18631 test_cryptodev_chacha_poly_mb(void) 18632 { 18633 int32_t rc; 18634 enum rte_security_session_action_type at = gbl_action_type; 18635 rc = run_cryptodev_testsuite( 18636 RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD)); 18637 gbl_action_type = at; 18638 return rc; 18639 } 18640 18641 static int 18642 test_cryptodev_openssl(void) 18643 { 18644 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 18645 } 18646 18647 static int 18648 test_cryptodev_aesni_gcm(void) 18649 { 18650 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 18651 } 18652 18653 static int 18654 test_cryptodev_cpu_aesni_gcm(void) 18655 { 18656 int32_t rc; 18657 enum rte_security_session_action_type at = gbl_action_type; 18658 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 18659 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 18660 gbl_action_type = at; 18661 return rc; 18662 } 18663 18664 static int 18665 test_cryptodev_mlx5(void) 18666 { 18667 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD)); 18668 } 18669 18670 static int 18671 test_cryptodev_null(void) 18672 { 18673 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 18674 } 18675 18676 static int 18677 test_cryptodev_sw_snow3g(void) 18678 { 18679 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 18680 } 18681 18682 static int 18683 test_cryptodev_sw_kasumi(void) 18684 { 18685 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 18686 } 18687 18688 static int 18689 test_cryptodev_sw_zuc(void) 18690 { 18691 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 18692 } 18693 18694 static int 18695 test_cryptodev_armv8(void) 18696 { 18697 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 18698 } 18699 18700 static int 18701 test_cryptodev_mrvl(void) 18702 { 18703 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 18704 } 18705 18706 #ifdef RTE_CRYPTO_SCHEDULER 18707 18708 static int 18709 test_cryptodev_scheduler(void) 18710 { 18711 uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0; 18712 const enum blockcipher_test_type blk_suites[] = { 18713 BLKCIPHER_AES_CHAIN_TYPE, 18714 BLKCIPHER_AES_CIPHERONLY_TYPE, 18715 BLKCIPHER_AUTHONLY_TYPE 18716 }; 18717 static struct unit_test_suite scheduler_multicore = { 18718 .suite_name = "Scheduler Multicore Unit Test Suite", 18719 .setup = scheduler_multicore_testsuite_setup, 18720 .teardown = scheduler_mode_testsuite_teardown, 18721 .unit_test_cases = {TEST_CASES_END()} 18722 }; 18723 static struct unit_test_suite scheduler_round_robin = { 18724 .suite_name = "Scheduler Round Robin Unit Test Suite", 18725 .setup = scheduler_roundrobin_testsuite_setup, 18726 .teardown = scheduler_mode_testsuite_teardown, 18727 .unit_test_cases = {TEST_CASES_END()} 18728 }; 18729 static struct unit_test_suite scheduler_failover = { 18730 .suite_name = "Scheduler Failover Unit Test Suite", 18731 .setup = scheduler_failover_testsuite_setup, 18732 .teardown = scheduler_mode_testsuite_teardown, 18733 .unit_test_cases = {TEST_CASES_END()} 18734 }; 18735 static struct unit_test_suite scheduler_pkt_size_distr = { 18736 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite", 18737 .setup = scheduler_pkt_size_distr_testsuite_setup, 18738 .teardown = scheduler_mode_testsuite_teardown, 18739 .unit_test_cases = {TEST_CASES_END()} 18740 }; 18741 struct unit_test_suite *sched_mode_suites[] = { 18742 &scheduler_multicore, 18743 &scheduler_round_robin, 18744 &scheduler_failover, 18745 &scheduler_pkt_size_distr 18746 }; 18747 static struct unit_test_suite scheduler_config = { 18748 .suite_name = "Crypto Device Scheduler Config Unit Test Suite", 18749 .unit_test_cases = { 18750 TEST_CASE(test_scheduler_attach_worker_op), 18751 TEST_CASE(test_scheduler_mode_multicore_op), 18752 TEST_CASE(test_scheduler_mode_roundrobin_op), 18753 TEST_CASE(test_scheduler_mode_failover_op), 18754 TEST_CASE(test_scheduler_mode_pkt_size_distr_op), 18755 TEST_CASE(test_scheduler_detach_worker_op), 18756 18757 TEST_CASES_END() /**< NULL terminate array */ 18758 } 18759 }; 18760 struct unit_test_suite *static_suites[] = { 18761 &scheduler_config, 18762 &end_testsuite 18763 }; 18764 struct unit_test_suite *sched_mode_static_suites[] = { 18765 #ifdef RTE_LIB_SECURITY 18766 &docsis_proto_testsuite, 18767 #endif 18768 &end_testsuite 18769 }; 18770 static struct unit_test_suite ts = { 18771 .suite_name = "Scheduler Unit Test Suite", 18772 .setup = scheduler_testsuite_setup, 18773 .teardown = testsuite_teardown, 18774 .unit_test_cases = {TEST_CASES_END()} 18775 }; 18776 18777 gbl_driver_id = rte_cryptodev_driver_id_get( 18778 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 18779 18780 if (gbl_driver_id == -1) { 18781 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n"); 18782 return TEST_SKIPPED; 18783 } 18784 18785 if (rte_cryptodev_driver_id_get( 18786 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) { 18787 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 18788 return TEST_SKIPPED; 18789 } 18790 18791 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 18792 uint8_t blk_i = 0; 18793 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof 18794 (struct unit_test_suite *) * 18795 (RTE_DIM(blk_suites) + 18796 RTE_DIM(sched_mode_static_suites) + 1)); 18797 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]), 18798 blk_suites, RTE_DIM(blk_suites)); 18799 ADD_STATIC_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]), 18800 sched_mode_static_suites, 18801 RTE_DIM(sched_mode_static_suites)); 18802 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite; 18803 } 18804 18805 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 18806 (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites))); 18807 ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites, 18808 RTE_DIM(sched_mode_suites)); 18809 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 18810 ret = unit_test_suite_runner(&ts); 18811 18812 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 18813 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, 18814 (*sched_mode_suites[sched_i]), 18815 RTE_DIM(blk_suites)); 18816 free(sched_mode_suites[sched_i]->unit_test_suites); 18817 } 18818 free(ts.unit_test_suites); 18819 return ret; 18820 } 18821 18822 REGISTER_DRIVER_TEST(cryptodev_scheduler_autotest, test_cryptodev_scheduler); 18823 18824 #endif 18825 18826 static int 18827 test_cryptodev_dpaa2_sec(void) 18828 { 18829 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 18830 } 18831 18832 static int 18833 test_cryptodev_dpaa_sec(void) 18834 { 18835 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 18836 } 18837 18838 static int 18839 test_cryptodev_ccp(void) 18840 { 18841 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 18842 } 18843 18844 static int 18845 test_cryptodev_octeontx(void) 18846 { 18847 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)); 18848 } 18849 18850 static int 18851 test_cryptodev_caam_jr(void) 18852 { 18853 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)); 18854 } 18855 18856 static int 18857 test_cryptodev_nitrox(void) 18858 { 18859 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD)); 18860 } 18861 18862 static int 18863 test_cryptodev_bcmfs(void) 18864 { 18865 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD)); 18866 } 18867 18868 static int 18869 run_cryptodev_raw_testsuite(const char *pmd_name) 18870 { 18871 int ret; 18872 18873 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, "RAW API"); 18874 if (ret) 18875 return ret; 18876 18877 global_api_test_type = CRYPTODEV_RAW_API_TEST; 18878 ret = run_cryptodev_testsuite(pmd_name); 18879 global_api_test_type = CRYPTODEV_API_TEST; 18880 18881 return ret; 18882 } 18883 18884 static int 18885 test_cryptodev_qat_raw_api(void) 18886 { 18887 return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 18888 } 18889 18890 static int 18891 test_cryptodev_cn9k(void) 18892 { 18893 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD)); 18894 } 18895 18896 static int 18897 test_cryptodev_cn10k(void) 18898 { 18899 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD)); 18900 } 18901 18902 static int 18903 test_cryptodev_cn10k_raw_api(void) 18904 { 18905 return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD)); 18906 } 18907 18908 static int 18909 test_cryptodev_dpaa2_sec_raw_api(void) 18910 { 18911 return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 18912 } 18913 18914 static int 18915 test_cryptodev_dpaa_sec_raw_api(void) 18916 { 18917 return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 18918 } 18919 18920 REGISTER_DRIVER_TEST(cryptodev_cn10k_raw_api_autotest, 18921 test_cryptodev_cn10k_raw_api); 18922 REGISTER_DRIVER_TEST(cryptodev_dpaa2_sec_raw_api_autotest, 18923 test_cryptodev_dpaa2_sec_raw_api); 18924 REGISTER_DRIVER_TEST(cryptodev_dpaa_sec_raw_api_autotest, 18925 test_cryptodev_dpaa_sec_raw_api); 18926 REGISTER_DRIVER_TEST(cryptodev_qat_raw_api_autotest, 18927 test_cryptodev_qat_raw_api); 18928 REGISTER_DRIVER_TEST(cryptodev_qat_autotest, test_cryptodev_qat); 18929 REGISTER_DRIVER_TEST(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 18930 REGISTER_DRIVER_TEST(cryptodev_cpu_aesni_mb_autotest, 18931 test_cryptodev_cpu_aesni_mb); 18932 REGISTER_DRIVER_TEST(cryptodev_chacha_poly_mb_autotest, 18933 test_cryptodev_chacha_poly_mb); 18934 REGISTER_DRIVER_TEST(cryptodev_openssl_autotest, test_cryptodev_openssl); 18935 REGISTER_DRIVER_TEST(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 18936 REGISTER_DRIVER_TEST(cryptodev_cpu_aesni_gcm_autotest, 18937 test_cryptodev_cpu_aesni_gcm); 18938 REGISTER_DRIVER_TEST(cryptodev_mlx5_autotest, test_cryptodev_mlx5); 18939 REGISTER_DRIVER_TEST(cryptodev_null_autotest, test_cryptodev_null); 18940 REGISTER_DRIVER_TEST(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 18941 REGISTER_DRIVER_TEST(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 18942 REGISTER_DRIVER_TEST(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 18943 REGISTER_DRIVER_TEST(cryptodev_sw_armv8_autotest, test_cryptodev_armv8); 18944 REGISTER_DRIVER_TEST(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl); 18945 REGISTER_DRIVER_TEST(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec); 18946 REGISTER_DRIVER_TEST(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec); 18947 REGISTER_DRIVER_TEST(cryptodev_ccp_autotest, test_cryptodev_ccp); 18948 REGISTER_DRIVER_TEST(cryptodev_uadk_autotest, test_cryptodev_uadk); 18949 REGISTER_DRIVER_TEST(cryptodev_virtio_autotest, test_cryptodev_virtio); 18950 REGISTER_DRIVER_TEST(cryptodev_octeontx_autotest, test_cryptodev_octeontx); 18951 REGISTER_DRIVER_TEST(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr); 18952 REGISTER_DRIVER_TEST(cryptodev_nitrox_autotest, test_cryptodev_nitrox); 18953 REGISTER_DRIVER_TEST(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs); 18954 REGISTER_DRIVER_TEST(cryptodev_cn9k_autotest, test_cryptodev_cn9k); 18955 REGISTER_DRIVER_TEST(cryptodev_cn10k_autotest, test_cryptodev_cn10k); 18956