1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2015-2020 Intel Corporation 3 * Copyright 2020 NXP 4 */ 5 6 #include <time.h> 7 8 #include <rte_common.h> 9 #include <rte_hexdump.h> 10 #include <rte_mbuf.h> 11 #include <rte_malloc.h> 12 #include <rte_memcpy.h> 13 #include <rte_pause.h> 14 #include <rte_bus_vdev.h> 15 #include <rte_ether.h> 16 #include <rte_errno.h> 17 18 #include <rte_crypto.h> 19 #include <rte_cryptodev.h> 20 #include <rte_ethdev.h> 21 #include <rte_ip.h> 22 #include <rte_string_fns.h> 23 #include <rte_tcp.h> 24 #include <rte_udp.h> 25 26 #ifdef RTE_CRYPTO_SCHEDULER 27 #include <rte_cryptodev_scheduler.h> 28 #include <rte_cryptodev_scheduler_operations.h> 29 #endif 30 31 #include <rte_lcore.h> 32 33 #include "test.h" 34 #include "test_cryptodev.h" 35 36 #include "test_cryptodev_blockcipher.h" 37 #include "test_cryptodev_aes_test_vectors.h" 38 #include "test_cryptodev_des_test_vectors.h" 39 #include "test_cryptodev_hash_test_vectors.h" 40 #include "test_cryptodev_kasumi_test_vectors.h" 41 #include "test_cryptodev_kasumi_hash_test_vectors.h" 42 #include "test_cryptodev_snow3g_test_vectors.h" 43 #include "test_cryptodev_snow3g_hash_test_vectors.h" 44 #include "test_cryptodev_zuc_test_vectors.h" 45 #include "test_cryptodev_aead_test_vectors.h" 46 #include "test_cryptodev_hmac_test_vectors.h" 47 #include "test_cryptodev_mixed_test_vectors.h" 48 #include "test_cryptodev_sm4_test_vectors.h" 49 #ifdef RTE_LIB_SECURITY 50 #include "test_cryptodev_security_ipsec.h" 51 #include "test_cryptodev_security_ipsec_test_vectors.h" 52 #include "test_cryptodev_security_pdcp_test_vectors.h" 53 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h" 54 #include "test_cryptodev_security_pdcp_test_func.h" 55 #include "test_cryptodev_security_docsis_test_vectors.h" 56 #include "test_cryptodev_security_tls_record.h" 57 #include "test_security_proto.h" 58 59 #define SDAP_DISABLED 0 60 #define SDAP_ENABLED 1 61 #endif 62 63 #define VDEV_ARGS_SIZE 100 64 #define MAX_NB_SESSIONS 4 65 66 #define MAX_DRV_SERVICE_CTX_SIZE 256 67 68 #define MAX_RAW_DEQUEUE_COUNT 65535 69 70 #define IN_PLACE 0 71 #define OUT_OF_PLACE 1 72 73 static int gbl_driver_id; 74 75 static enum rte_security_session_action_type gbl_action_type = 76 RTE_SECURITY_ACTION_TYPE_NONE; 77 78 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST; 79 80 struct crypto_unittest_params { 81 struct rte_crypto_sym_xform cipher_xform; 82 struct rte_crypto_sym_xform auth_xform; 83 struct rte_crypto_sym_xform aead_xform; 84 #ifdef RTE_LIB_SECURITY 85 struct rte_security_docsis_xform docsis_xform; 86 #endif 87 88 union { 89 void *sess; 90 #ifdef RTE_LIB_SECURITY 91 void *sec_session; 92 #endif 93 }; 94 #ifdef RTE_LIB_SECURITY 95 enum rte_security_session_action_type type; 96 #endif 97 struct rte_crypto_op *op; 98 99 struct rte_mbuf *obuf, *ibuf; 100 101 uint8_t *digest; 102 }; 103 104 #define ALIGN_POW2_ROUNDUP(num, align) \ 105 (((num) + (align) - 1) & ~((align) - 1)) 106 107 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts) \ 108 for (j = 0; j < num_child_ts; index++, j++) \ 109 parent_ts.unit_test_suites[index] = child_ts[j] 110 111 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types) \ 112 for (j = 0; j < num_blk_types; index++, j++) \ 113 parent_ts.unit_test_suites[index] = \ 114 build_blockcipher_test_suite(blk_types[j]) 115 116 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types) \ 117 for (j = index; j < index + num_blk_types; j++) \ 118 free_blockcipher_test_suite(parent_ts.unit_test_suites[j]) 119 120 /* 121 * Forward declarations. 122 */ 123 static int 124 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 125 struct crypto_unittest_params *ut_params, uint8_t *cipher_key, 126 uint8_t *hmac_key); 127 128 static int 129 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess, 130 struct crypto_unittest_params *ut_params, 131 struct crypto_testsuite_params *ts_param, 132 const uint8_t *cipher, 133 const uint8_t *digest, 134 const uint8_t *iv); 135 136 static int 137 security_proto_supported(enum rte_security_session_action_type action, 138 enum rte_security_session_protocol proto); 139 140 static int 141 dev_configure_and_start(uint64_t ff_disable); 142 143 static int 144 check_cipher_capability(const struct crypto_testsuite_params *ts_params, 145 const enum rte_crypto_cipher_algorithm cipher_algo, 146 const uint16_t key_size, const uint16_t iv_size); 147 148 static int 149 check_auth_capability(const struct crypto_testsuite_params *ts_params, 150 const enum rte_crypto_auth_algorithm auth_algo, 151 const uint16_t key_size, const uint16_t iv_size, 152 const uint16_t tag_size); 153 154 static struct rte_mbuf * 155 setup_test_string(struct rte_mempool *mpool, 156 const char *string, size_t len, uint8_t blocksize) 157 { 158 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool); 159 size_t t_len = len - (blocksize ? (len % blocksize) : 0); 160 161 if (m) { 162 char *dst; 163 164 memset(m->buf_addr, 0, m->buf_len); 165 dst = rte_pktmbuf_append(m, t_len); 166 if (!dst) { 167 rte_pktmbuf_free(m); 168 return NULL; 169 } 170 if (string != NULL) 171 rte_memcpy(dst, string, t_len); 172 else 173 memset(dst, 0, t_len); 174 } 175 176 return m; 177 } 178 179 /* Get number of bytes in X bits (rounding up) */ 180 static uint32_t 181 ceil_byte_length(uint32_t num_bits) 182 { 183 if (num_bits % 8) 184 return ((num_bits >> 3) + 1); 185 else 186 return (num_bits >> 3); 187 } 188 189 static void 190 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused, 191 uint8_t is_op_success) 192 { 193 struct rte_crypto_op *op = user_data; 194 op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS : 195 RTE_CRYPTO_OP_STATUS_ERROR; 196 } 197 198 static struct crypto_testsuite_params testsuite_params = { NULL }; 199 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params; 200 static struct crypto_unittest_params unittest_params; 201 202 int 203 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id, 204 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth, 205 uint8_t len_in_bits, uint8_t cipher_iv_len) 206 { 207 struct rte_crypto_sym_op *sop = op->sym; 208 struct rte_crypto_op *ret_op = NULL; 209 struct rte_crypto_vec data_vec[UINT8_MAX], dest_data_vec[UINT8_MAX]; 210 struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv; 211 union rte_crypto_sym_ofs ofs; 212 struct rte_crypto_sym_vec vec; 213 struct rte_crypto_sgl sgl, dest_sgl; 214 uint32_t max_len; 215 union rte_cryptodev_session_ctx sess; 216 uint64_t auth_end_iova; 217 uint32_t count = 0; 218 struct rte_crypto_raw_dp_ctx *ctx; 219 uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0, 220 auth_len = 0; 221 int32_t n; 222 uint32_t n_success; 223 int ctx_service_size; 224 int32_t status = 0; 225 int enqueue_status, dequeue_status; 226 struct crypto_unittest_params *ut_params = &unittest_params; 227 int is_sgl = sop->m_src->nb_segs > 1; 228 int ret = TEST_SUCCESS, is_oop = 0; 229 230 ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id); 231 if (ctx_service_size < 0) 232 return TEST_SKIPPED; 233 234 ctx = malloc(ctx_service_size); 235 if (ctx == NULL) 236 return TEST_FAILED; 237 238 /* Both are enums, setting crypto_sess will suit any session type */ 239 sess.crypto_sess = op->sym->session; 240 241 ret = rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx, op->sess_type, sess, 0); 242 if (ret == -ENOTSUP) { 243 ret = TEST_SKIPPED; 244 goto exit; 245 } else if (ret) { 246 ret = TEST_FAILED; 247 goto exit; 248 } 249 250 cipher_iv.iova = 0; 251 cipher_iv.va = NULL; 252 aad_auth_iv.iova = 0; 253 aad_auth_iv.va = NULL; 254 digest.iova = 0; 255 digest.va = NULL; 256 sgl.vec = data_vec; 257 vec.num = 1; 258 vec.src_sgl = &sgl; 259 vec.iv = &cipher_iv; 260 vec.digest = &digest; 261 vec.aad = &aad_auth_iv; 262 vec.status = &status; 263 264 ofs.raw = 0; 265 266 if ((sop->m_dst != NULL) && (sop->m_dst != sop->m_src)) 267 is_oop = 1; 268 269 if (is_cipher && is_auth) { 270 cipher_offset = sop->cipher.data.offset; 271 cipher_len = sop->cipher.data.length; 272 auth_offset = sop->auth.data.offset; 273 auth_len = sop->auth.data.length; 274 max_len = RTE_MAX(cipher_offset + cipher_len, 275 auth_offset + auth_len); 276 if (len_in_bits) { 277 max_len = max_len >> 3; 278 cipher_offset = cipher_offset >> 3; 279 auth_offset = auth_offset >> 3; 280 cipher_len = cipher_len >> 3; 281 auth_len = auth_len >> 3; 282 } 283 ofs.ofs.cipher.head = cipher_offset; 284 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 285 ofs.ofs.auth.head = auth_offset; 286 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 287 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 288 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 289 aad_auth_iv.va = rte_crypto_op_ctod_offset( 290 op, void *, IV_OFFSET + cipher_iv_len); 291 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 292 cipher_iv_len); 293 digest.va = (void *)sop->auth.digest.data; 294 digest.iova = sop->auth.digest.phys_addr; 295 296 if (is_sgl) { 297 uint32_t remaining_off = auth_offset + auth_len; 298 struct rte_mbuf *sgl_buf = sop->m_src; 299 if (is_oop) 300 sgl_buf = sop->m_dst; 301 302 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf) 303 && sgl_buf->next != NULL) { 304 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 305 sgl_buf = sgl_buf->next; 306 } 307 308 auth_end_iova = (uint64_t)rte_pktmbuf_iova_offset( 309 sgl_buf, remaining_off); 310 } else { 311 auth_end_iova = rte_pktmbuf_iova(op->sym->m_src) + 312 auth_offset + auth_len; 313 } 314 /* Then check if digest-encrypted conditions are met */ 315 if ((auth_offset + auth_len < cipher_offset + cipher_len) && 316 (digest.iova == auth_end_iova) && is_sgl) 317 max_len = RTE_MAX(max_len, 318 auth_offset + auth_len + 319 ut_params->auth_xform.auth.digest_length); 320 321 } else if (is_cipher) { 322 cipher_offset = sop->cipher.data.offset; 323 cipher_len = sop->cipher.data.length; 324 max_len = cipher_len + cipher_offset; 325 if (len_in_bits) { 326 max_len = max_len >> 3; 327 cipher_offset = cipher_offset >> 3; 328 cipher_len = cipher_len >> 3; 329 } 330 ofs.ofs.cipher.head = cipher_offset; 331 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 332 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 333 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 334 335 } else if (is_auth) { 336 auth_offset = sop->auth.data.offset; 337 auth_len = sop->auth.data.length; 338 max_len = auth_len + auth_offset; 339 if (len_in_bits) { 340 max_len = max_len >> 3; 341 auth_offset = auth_offset >> 3; 342 auth_len = auth_len >> 3; 343 } 344 ofs.ofs.auth.head = auth_offset; 345 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 346 aad_auth_iv.va = rte_crypto_op_ctod_offset( 347 op, void *, IV_OFFSET + cipher_iv_len); 348 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 349 cipher_iv_len); 350 digest.va = (void *)sop->auth.digest.data; 351 digest.iova = sop->auth.digest.phys_addr; 352 353 } else { /* aead */ 354 cipher_offset = sop->aead.data.offset; 355 cipher_len = sop->aead.data.length; 356 max_len = cipher_len + cipher_offset; 357 if (len_in_bits) { 358 max_len = max_len >> 3; 359 cipher_offset = cipher_offset >> 3; 360 cipher_len = cipher_len >> 3; 361 } 362 ofs.ofs.cipher.head = cipher_offset; 363 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 364 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 365 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 366 aad_auth_iv.va = (void *)sop->aead.aad.data; 367 aad_auth_iv.iova = sop->aead.aad.phys_addr; 368 digest.va = (void *)sop->aead.digest.data; 369 digest.iova = sop->aead.digest.phys_addr; 370 } 371 372 n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len, 373 data_vec, RTE_DIM(data_vec)); 374 if (n < 0 || n > sop->m_src->nb_segs) { 375 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 376 goto exit; 377 } 378 379 sgl.num = n; 380 /* Out of place */ 381 if (is_oop) { 382 dest_sgl.vec = dest_data_vec; 383 vec.dest_sgl = &dest_sgl; 384 n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len, 385 dest_data_vec, RTE_DIM(dest_data_vec)); 386 if (n < 0 || n > sop->m_dst->nb_segs) { 387 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 388 goto exit; 389 } 390 dest_sgl.num = n; 391 } else 392 vec.dest_sgl = NULL; 393 394 if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op, 395 &enqueue_status) < 1) { 396 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 397 goto exit; 398 } 399 400 if (enqueue_status == 0) { 401 status = rte_cryptodev_raw_enqueue_done(ctx, 1); 402 if (status < 0) { 403 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 404 goto exit; 405 } 406 } else if (enqueue_status < 0) { 407 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 408 goto exit; 409 } 410 411 n = n_success = 0; 412 while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) { 413 n = rte_cryptodev_raw_dequeue_burst(ctx, 414 NULL, 1, post_process_raw_dp_op, 415 (void **)&ret_op, 0, &n_success, 416 &dequeue_status); 417 if (dequeue_status < 0) { 418 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 419 goto exit; 420 } 421 if (n == 0) 422 rte_pause(); 423 } 424 425 if (n == 1 && dequeue_status == 0) { 426 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) { 427 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 428 goto exit; 429 } 430 } 431 432 op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op || 433 ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR || 434 n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR : 435 RTE_CRYPTO_OP_STATUS_SUCCESS; 436 437 exit: 438 free(ctx); 439 return ret; 440 } 441 442 static void 443 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op) 444 { 445 int32_t n, st; 446 struct rte_crypto_sym_op *sop; 447 union rte_crypto_sym_ofs ofs; 448 struct rte_crypto_sgl sgl; 449 struct rte_crypto_sym_vec symvec; 450 struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr; 451 struct rte_crypto_vec vec[UINT8_MAX]; 452 453 sop = op->sym; 454 455 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset, 456 sop->aead.data.length, vec, RTE_DIM(vec)); 457 458 if (n < 0 || n != sop->m_src->nb_segs) { 459 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 460 return; 461 } 462 463 sgl.vec = vec; 464 sgl.num = n; 465 symvec.src_sgl = &sgl; 466 symvec.iv = &iv_ptr; 467 symvec.digest = &digest_ptr; 468 symvec.aad = &aad_ptr; 469 symvec.status = &st; 470 symvec.num = 1; 471 472 /* for CPU crypto the IOVA address is not required */ 473 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 474 digest_ptr.va = (void *)sop->aead.digest.data; 475 aad_ptr.va = (void *)sop->aead.aad.data; 476 477 ofs.raw = 0; 478 479 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 480 &symvec); 481 482 if (n != 1) 483 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 484 else 485 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 486 } 487 488 static void 489 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op) 490 { 491 int32_t n, st; 492 struct rte_crypto_sym_op *sop; 493 union rte_crypto_sym_ofs ofs; 494 struct rte_crypto_sgl sgl; 495 struct rte_crypto_sym_vec symvec; 496 struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr; 497 struct rte_crypto_vec vec[UINT8_MAX]; 498 499 sop = op->sym; 500 501 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset, 502 sop->auth.data.length, vec, RTE_DIM(vec)); 503 504 if (n < 0 || n != sop->m_src->nb_segs) { 505 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 506 return; 507 } 508 509 sgl.vec = vec; 510 sgl.num = n; 511 symvec.src_sgl = &sgl; 512 symvec.iv = &iv_ptr; 513 symvec.digest = &digest_ptr; 514 symvec.status = &st; 515 symvec.num = 1; 516 517 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 518 digest_ptr.va = (void *)sop->auth.digest.data; 519 520 ofs.raw = 0; 521 ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset; 522 ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) - 523 (sop->cipher.data.offset + sop->cipher.data.length); 524 525 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 526 &symvec); 527 528 if (n != 1) 529 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 530 else 531 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 532 } 533 534 static struct rte_crypto_op * 535 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op) 536 { 537 538 RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO); 539 540 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 541 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n"); 542 return NULL; 543 } 544 545 op = NULL; 546 547 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 548 rte_pause(); 549 550 if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 551 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status); 552 return NULL; 553 } 554 555 return op; 556 } 557 558 static int 559 testsuite_setup(void) 560 { 561 struct crypto_testsuite_params *ts_params = &testsuite_params; 562 struct rte_cryptodev_info info; 563 uint32_t i = 0, nb_devs, dev_id; 564 uint16_t qp_id; 565 566 memset(ts_params, 0, sizeof(*ts_params)); 567 568 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 569 if (ts_params->mbuf_pool == NULL) { 570 /* Not already created so create */ 571 ts_params->mbuf_pool = rte_pktmbuf_pool_create( 572 "CRYPTO_MBUFPOOL", 573 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE, 574 rte_socket_id()); 575 if (ts_params->mbuf_pool == NULL) { 576 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n"); 577 return TEST_FAILED; 578 } 579 } 580 581 ts_params->large_mbuf_pool = rte_mempool_lookup( 582 "CRYPTO_LARGE_MBUFPOOL"); 583 if (ts_params->large_mbuf_pool == NULL) { 584 /* Not already created so create */ 585 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create( 586 "CRYPTO_LARGE_MBUFPOOL", 587 1, 0, 0, UINT16_MAX, 588 rte_socket_id()); 589 if (ts_params->large_mbuf_pool == NULL) { 590 RTE_LOG(ERR, USER1, 591 "Can't create CRYPTO_LARGE_MBUFPOOL\n"); 592 return TEST_FAILED; 593 } 594 } 595 596 ts_params->op_mpool = rte_crypto_op_pool_create( 597 "MBUF_CRYPTO_SYM_OP_POOL", 598 RTE_CRYPTO_OP_TYPE_SYMMETRIC, 599 NUM_MBUFS, MBUF_CACHE_SIZE, 600 DEFAULT_NUM_XFORMS * 601 sizeof(struct rte_crypto_sym_xform) + 602 MAXIMUM_IV_LENGTH, 603 rte_socket_id()); 604 if (ts_params->op_mpool == NULL) { 605 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n"); 606 return TEST_FAILED; 607 } 608 609 nb_devs = rte_cryptodev_count(); 610 if (nb_devs < 1) { 611 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 612 return TEST_SKIPPED; 613 } 614 615 if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) { 616 RTE_LOG(WARNING, USER1, "No %s devices found?\n", 617 rte_cryptodev_driver_name_get(gbl_driver_id)); 618 return TEST_SKIPPED; 619 } 620 621 /* Create list of valid crypto devs */ 622 for (i = 0; i < nb_devs; i++) { 623 rte_cryptodev_info_get(i, &info); 624 if (info.driver_id == gbl_driver_id) 625 ts_params->valid_devs[ts_params->valid_dev_count++] = i; 626 } 627 628 if (ts_params->valid_dev_count < 1) 629 return TEST_FAILED; 630 631 /* Set up all the qps on the first of the valid devices found */ 632 633 dev_id = ts_params->valid_devs[0]; 634 635 rte_cryptodev_info_get(dev_id, &info); 636 637 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; 638 ts_params->conf.socket_id = SOCKET_ID_ANY; 639 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY; 640 641 unsigned int session_size = 642 rte_cryptodev_sym_get_private_session_size(dev_id); 643 644 #ifdef RTE_LIB_SECURITY 645 unsigned int security_session_size = rte_security_session_get_size( 646 rte_cryptodev_get_sec_ctx(dev_id)); 647 648 if (session_size < security_session_size) 649 session_size = security_session_size; 650 #endif 651 /* 652 * Create mempool with maximum number of sessions. 653 */ 654 if (info.sym.max_nb_sessions != 0 && 655 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 656 RTE_LOG(ERR, USER1, "Device does not support " 657 "at least %u sessions\n", 658 MAX_NB_SESSIONS); 659 return TEST_FAILED; 660 } 661 662 ts_params->session_mpool = rte_cryptodev_sym_session_pool_create( 663 "test_sess_mp", MAX_NB_SESSIONS, session_size, 0, 0, 664 SOCKET_ID_ANY); 665 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 666 "session mempool allocation failed"); 667 668 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, 669 &ts_params->conf), 670 "Failed to configure cryptodev %u with %u qps", 671 dev_id, ts_params->conf.nb_queue_pairs); 672 673 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 674 ts_params->qp_conf.mp_session = ts_params->session_mpool; 675 676 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 677 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 678 dev_id, qp_id, &ts_params->qp_conf, 679 rte_cryptodev_socket_id(dev_id)), 680 "Failed to setup queue pair %u on cryptodev %u", 681 qp_id, dev_id); 682 } 683 684 return TEST_SUCCESS; 685 } 686 687 static void 688 testsuite_teardown(void) 689 { 690 struct crypto_testsuite_params *ts_params = &testsuite_params; 691 int res; 692 693 if (ts_params->mbuf_pool != NULL) { 694 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 695 rte_mempool_avail_count(ts_params->mbuf_pool)); 696 } 697 698 if (ts_params->op_mpool != NULL) { 699 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", 700 rte_mempool_avail_count(ts_params->op_mpool)); 701 } 702 703 if (ts_params->session_mpool != NULL) { 704 rte_mempool_free(ts_params->session_mpool); 705 ts_params->session_mpool = NULL; 706 } 707 708 res = rte_cryptodev_close(ts_params->valid_devs[0]); 709 if (res) 710 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res); 711 } 712 713 static int 714 check_capabilities_supported(enum rte_crypto_sym_xform_type type, 715 const int *algs, uint16_t num_algs) 716 { 717 uint8_t dev_id = testsuite_params.valid_devs[0]; 718 bool some_alg_supported = FALSE; 719 uint16_t i; 720 721 for (i = 0; i < num_algs && !some_alg_supported; i++) { 722 struct rte_cryptodev_sym_capability_idx alg = { 723 type, {algs[i]} 724 }; 725 if (rte_cryptodev_sym_capability_get(dev_id, 726 &alg) != NULL) 727 some_alg_supported = TRUE; 728 } 729 if (!some_alg_supported) 730 return TEST_SKIPPED; 731 732 return 0; 733 } 734 735 int 736 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers, 737 uint16_t num_ciphers) 738 { 739 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER, 740 (const int *) ciphers, num_ciphers); 741 } 742 743 int 744 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths, 745 uint16_t num_auths) 746 { 747 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH, 748 (const int *) auths, num_auths); 749 } 750 751 int 752 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads, 753 uint16_t num_aeads) 754 { 755 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD, 756 (const int *) aeads, num_aeads); 757 } 758 759 static int 760 null_testsuite_setup(void) 761 { 762 struct crypto_testsuite_params *ts_params = &testsuite_params; 763 uint8_t dev_id = ts_params->valid_devs[0]; 764 struct rte_cryptodev_info dev_info; 765 const enum rte_crypto_cipher_algorithm ciphers[] = { 766 RTE_CRYPTO_CIPHER_NULL 767 }; 768 const enum rte_crypto_auth_algorithm auths[] = { 769 RTE_CRYPTO_AUTH_NULL 770 }; 771 772 rte_cryptodev_info_get(dev_id, &dev_info); 773 774 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 775 RTE_LOG(INFO, USER1, "Feature flag requirements for NULL " 776 "testsuite not met\n"); 777 return TEST_SKIPPED; 778 } 779 780 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 781 && check_auth_capabilities_supported(auths, 782 RTE_DIM(auths)) != 0) { 783 RTE_LOG(INFO, USER1, "Capability requirements for NULL " 784 "testsuite not met\n"); 785 return TEST_SKIPPED; 786 } 787 788 return 0; 789 } 790 791 static int 792 crypto_gen_testsuite_setup(void) 793 { 794 struct crypto_testsuite_params *ts_params = &testsuite_params; 795 uint8_t dev_id = ts_params->valid_devs[0]; 796 struct rte_cryptodev_info dev_info; 797 798 rte_cryptodev_info_get(dev_id, &dev_info); 799 800 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 801 RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen " 802 "testsuite not met\n"); 803 return TEST_SKIPPED; 804 } 805 806 return 0; 807 } 808 809 #ifdef RTE_LIB_SECURITY 810 static int 811 sec_proto_testsuite_setup(enum rte_security_session_protocol protocol) 812 { 813 struct crypto_testsuite_params *ts_params = &testsuite_params; 814 struct crypto_unittest_params *ut_params = &unittest_params; 815 struct rte_cryptodev_info dev_info; 816 int ret = 0; 817 818 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 819 820 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) { 821 RTE_LOG(INFO, USER1, 822 "Feature flag requirements for security protocol testsuite not met\n"); 823 return TEST_SKIPPED; 824 } 825 826 /* Reconfigure to enable security */ 827 ret = dev_configure_and_start(0); 828 if (ret != TEST_SUCCESS) 829 return ret; 830 831 /* Set action type */ 832 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 833 834 if (security_proto_supported(RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, protocol) < 0) { 835 RTE_LOG(INFO, USER1, 836 "Capability requirements for security protocol test not met\n"); 837 ret = TEST_SKIPPED; 838 } 839 840 test_sec_alg_list_populate(); 841 test_sec_auth_only_alg_list_populate(); 842 843 /* 844 * Stop the device. Device would be started again by individual test 845 * case setup routine. 846 */ 847 rte_cryptodev_stop(ts_params->valid_devs[0]); 848 849 return ret; 850 } 851 852 static int 853 ipsec_proto_testsuite_setup(void) 854 { 855 return sec_proto_testsuite_setup(RTE_SECURITY_PROTOCOL_IPSEC); 856 } 857 858 static int 859 tls_record_proto_testsuite_setup(void) 860 { 861 return sec_proto_testsuite_setup(RTE_SECURITY_PROTOCOL_TLS_RECORD); 862 } 863 864 static int 865 pdcp_proto_testsuite_setup(void) 866 { 867 struct crypto_testsuite_params *ts_params = &testsuite_params; 868 uint8_t dev_id = ts_params->valid_devs[0]; 869 struct rte_cryptodev_info dev_info; 870 const enum rte_crypto_cipher_algorithm ciphers[] = { 871 RTE_CRYPTO_CIPHER_NULL, 872 RTE_CRYPTO_CIPHER_AES_CTR, 873 RTE_CRYPTO_CIPHER_ZUC_EEA3, 874 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 875 }; 876 const enum rte_crypto_auth_algorithm auths[] = { 877 RTE_CRYPTO_AUTH_NULL, 878 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 879 RTE_CRYPTO_AUTH_AES_CMAC, 880 RTE_CRYPTO_AUTH_ZUC_EIA3 881 }; 882 883 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_auth_key)); 884 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_bearer)); 885 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_crypto_key)); 886 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_in)); 887 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_in_len)); 888 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_out)); 889 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_sn_size)); 890 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_hfn)); 891 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_hfn_threshold)); 892 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_packet_direction)); 893 894 rte_cryptodev_info_get(dev_id, &dev_info); 895 896 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 897 !(dev_info.feature_flags & 898 RTE_CRYPTODEV_FF_SECURITY)) { 899 RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto " 900 "testsuite not met\n"); 901 return TEST_SKIPPED; 902 } 903 904 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 905 && check_auth_capabilities_supported(auths, 906 RTE_DIM(auths)) != 0) { 907 RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto " 908 "testsuite not met\n"); 909 return TEST_SKIPPED; 910 } 911 912 return 0; 913 } 914 915 static int 916 docsis_proto_testsuite_setup(void) 917 { 918 struct crypto_testsuite_params *ts_params = &testsuite_params; 919 uint8_t dev_id = ts_params->valid_devs[0]; 920 struct rte_cryptodev_info dev_info; 921 const enum rte_crypto_cipher_algorithm ciphers[] = { 922 RTE_CRYPTO_CIPHER_AES_DOCSISBPI 923 }; 924 925 rte_cryptodev_info_get(dev_id, &dev_info); 926 927 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 928 !(dev_info.feature_flags & 929 RTE_CRYPTODEV_FF_SECURITY)) { 930 RTE_LOG(INFO, USER1, "Feature flag requirements for DOCSIS " 931 "Proto testsuite not met\n"); 932 return TEST_SKIPPED; 933 } 934 935 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { 936 RTE_LOG(INFO, USER1, "Capability requirements for DOCSIS Proto " 937 "testsuite not met\n"); 938 return TEST_SKIPPED; 939 } 940 941 return 0; 942 } 943 #endif 944 945 static int 946 aes_ccm_auth_testsuite_setup(void) 947 { 948 struct crypto_testsuite_params *ts_params = &testsuite_params; 949 uint8_t dev_id = ts_params->valid_devs[0]; 950 struct rte_cryptodev_info dev_info; 951 const enum rte_crypto_aead_algorithm aeads[] = { 952 RTE_CRYPTO_AEAD_AES_CCM 953 }; 954 955 rte_cryptodev_info_get(dev_id, &dev_info); 956 957 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 958 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 959 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 960 RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM " 961 "testsuite not met\n"); 962 return TEST_SKIPPED; 963 } 964 965 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 966 RTE_LOG(INFO, USER1, "Capability requirements for AES CCM " 967 "testsuite not met\n"); 968 return TEST_SKIPPED; 969 } 970 971 return 0; 972 } 973 974 static int 975 aes_gcm_auth_testsuite_setup(void) 976 { 977 struct crypto_testsuite_params *ts_params = &testsuite_params; 978 uint8_t dev_id = ts_params->valid_devs[0]; 979 struct rte_cryptodev_info dev_info; 980 const enum rte_crypto_aead_algorithm aeads[] = { 981 RTE_CRYPTO_AEAD_AES_GCM 982 }; 983 984 rte_cryptodev_info_get(dev_id, &dev_info); 985 986 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 987 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM " 988 "testsuite not met\n"); 989 return TEST_SKIPPED; 990 } 991 992 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 993 RTE_LOG(INFO, USER1, "Capability requirements for AES GCM " 994 "testsuite not met\n"); 995 return TEST_SKIPPED; 996 } 997 998 return 0; 999 } 1000 1001 static int 1002 aes_gmac_auth_testsuite_setup(void) 1003 { 1004 struct crypto_testsuite_params *ts_params = &testsuite_params; 1005 uint8_t dev_id = ts_params->valid_devs[0]; 1006 struct rte_cryptodev_info dev_info; 1007 const enum rte_crypto_auth_algorithm auths[] = { 1008 RTE_CRYPTO_AUTH_AES_GMAC 1009 }; 1010 1011 rte_cryptodev_info_get(dev_id, &dev_info); 1012 1013 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1014 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1015 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1016 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC " 1017 "testsuite not met\n"); 1018 return TEST_SKIPPED; 1019 } 1020 1021 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1022 RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC " 1023 "testsuite not met\n"); 1024 return TEST_SKIPPED; 1025 } 1026 1027 return 0; 1028 } 1029 1030 static int 1031 chacha20_poly1305_testsuite_setup(void) 1032 { 1033 struct crypto_testsuite_params *ts_params = &testsuite_params; 1034 uint8_t dev_id = ts_params->valid_devs[0]; 1035 struct rte_cryptodev_info dev_info; 1036 const enum rte_crypto_aead_algorithm aeads[] = { 1037 RTE_CRYPTO_AEAD_CHACHA20_POLY1305 1038 }; 1039 1040 rte_cryptodev_info_get(dev_id, &dev_info); 1041 1042 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1043 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1044 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1045 RTE_LOG(INFO, USER1, "Feature flag requirements for " 1046 "Chacha20-Poly1305 testsuite not met\n"); 1047 return TEST_SKIPPED; 1048 } 1049 1050 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1051 RTE_LOG(INFO, USER1, "Capability requirements for " 1052 "Chacha20-Poly1305 testsuite not met\n"); 1053 return TEST_SKIPPED; 1054 } 1055 1056 return 0; 1057 } 1058 1059 static int 1060 snow3g_testsuite_setup(void) 1061 { 1062 struct crypto_testsuite_params *ts_params = &testsuite_params; 1063 uint8_t dev_id = ts_params->valid_devs[0]; 1064 struct rte_cryptodev_info dev_info; 1065 const enum rte_crypto_cipher_algorithm ciphers[] = { 1066 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1067 1068 }; 1069 const enum rte_crypto_auth_algorithm auths[] = { 1070 RTE_CRYPTO_AUTH_SNOW3G_UIA2 1071 }; 1072 1073 rte_cryptodev_info_get(dev_id, &dev_info); 1074 1075 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1076 RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G " 1077 "testsuite not met\n"); 1078 return TEST_SKIPPED; 1079 } 1080 1081 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1082 && check_auth_capabilities_supported(auths, 1083 RTE_DIM(auths)) != 0) { 1084 RTE_LOG(INFO, USER1, "Capability requirements for Snow3G " 1085 "testsuite not met\n"); 1086 return TEST_SKIPPED; 1087 } 1088 1089 return 0; 1090 } 1091 1092 static int 1093 zuc_testsuite_setup(void) 1094 { 1095 struct crypto_testsuite_params *ts_params = &testsuite_params; 1096 uint8_t dev_id = ts_params->valid_devs[0]; 1097 struct rte_cryptodev_info dev_info; 1098 const enum rte_crypto_cipher_algorithm ciphers[] = { 1099 RTE_CRYPTO_CIPHER_ZUC_EEA3 1100 }; 1101 const enum rte_crypto_auth_algorithm auths[] = { 1102 RTE_CRYPTO_AUTH_ZUC_EIA3 1103 }; 1104 1105 rte_cryptodev_info_get(dev_id, &dev_info); 1106 1107 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1108 RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC " 1109 "testsuite not met\n"); 1110 return TEST_SKIPPED; 1111 } 1112 1113 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1114 && check_auth_capabilities_supported(auths, 1115 RTE_DIM(auths)) != 0) { 1116 RTE_LOG(INFO, USER1, "Capability requirements for ZUC " 1117 "testsuite not met\n"); 1118 return TEST_SKIPPED; 1119 } 1120 1121 return 0; 1122 } 1123 1124 static int 1125 hmac_md5_auth_testsuite_setup(void) 1126 { 1127 struct crypto_testsuite_params *ts_params = &testsuite_params; 1128 uint8_t dev_id = ts_params->valid_devs[0]; 1129 struct rte_cryptodev_info dev_info; 1130 const enum rte_crypto_auth_algorithm auths[] = { 1131 RTE_CRYPTO_AUTH_MD5_HMAC 1132 }; 1133 1134 rte_cryptodev_info_get(dev_id, &dev_info); 1135 1136 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1137 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1138 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1139 RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 " 1140 "Auth testsuite not met\n"); 1141 return TEST_SKIPPED; 1142 } 1143 1144 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1145 RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 " 1146 "testsuite not met\n"); 1147 return TEST_SKIPPED; 1148 } 1149 1150 return 0; 1151 } 1152 1153 static int 1154 kasumi_testsuite_setup(void) 1155 { 1156 struct crypto_testsuite_params *ts_params = &testsuite_params; 1157 uint8_t dev_id = ts_params->valid_devs[0]; 1158 struct rte_cryptodev_info dev_info; 1159 const enum rte_crypto_cipher_algorithm ciphers[] = { 1160 RTE_CRYPTO_CIPHER_KASUMI_F8 1161 }; 1162 const enum rte_crypto_auth_algorithm auths[] = { 1163 RTE_CRYPTO_AUTH_KASUMI_F9 1164 }; 1165 1166 rte_cryptodev_info_get(dev_id, &dev_info); 1167 1168 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1169 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1170 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1171 RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi " 1172 "testsuite not met\n"); 1173 return TEST_SKIPPED; 1174 } 1175 1176 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1177 && check_auth_capabilities_supported(auths, 1178 RTE_DIM(auths)) != 0) { 1179 RTE_LOG(INFO, USER1, "Capability requirements for Kasumi " 1180 "testsuite not met\n"); 1181 return TEST_SKIPPED; 1182 } 1183 1184 return 0; 1185 } 1186 1187 static int 1188 negative_aes_gcm_testsuite_setup(void) 1189 { 1190 struct crypto_testsuite_params *ts_params = &testsuite_params; 1191 uint8_t dev_id = ts_params->valid_devs[0]; 1192 struct rte_cryptodev_info dev_info; 1193 const enum rte_crypto_aead_algorithm aeads[] = { 1194 RTE_CRYPTO_AEAD_AES_GCM 1195 }; 1196 1197 rte_cryptodev_info_get(dev_id, &dev_info); 1198 1199 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1200 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1201 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1202 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1203 "AES GCM testsuite not met\n"); 1204 return TEST_SKIPPED; 1205 } 1206 1207 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1208 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1209 "AES GCM testsuite not met\n"); 1210 return TEST_SKIPPED; 1211 } 1212 1213 return 0; 1214 } 1215 1216 static int 1217 negative_aes_gmac_testsuite_setup(void) 1218 { 1219 struct crypto_testsuite_params *ts_params = &testsuite_params; 1220 uint8_t dev_id = ts_params->valid_devs[0]; 1221 struct rte_cryptodev_info dev_info; 1222 const enum rte_crypto_auth_algorithm auths[] = { 1223 RTE_CRYPTO_AUTH_AES_GMAC 1224 }; 1225 1226 rte_cryptodev_info_get(dev_id, &dev_info); 1227 1228 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1229 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1230 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1231 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1232 "AES GMAC testsuite not met\n"); 1233 return TEST_SKIPPED; 1234 } 1235 1236 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1237 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1238 "AES GMAC testsuite not met\n"); 1239 return TEST_SKIPPED; 1240 } 1241 1242 return 0; 1243 } 1244 1245 static int 1246 mixed_cipher_hash_testsuite_setup(void) 1247 { 1248 struct crypto_testsuite_params *ts_params = &testsuite_params; 1249 uint8_t dev_id = ts_params->valid_devs[0]; 1250 struct rte_cryptodev_info dev_info; 1251 uint64_t feat_flags; 1252 const enum rte_crypto_cipher_algorithm ciphers[] = { 1253 RTE_CRYPTO_CIPHER_NULL, 1254 RTE_CRYPTO_CIPHER_AES_CTR, 1255 RTE_CRYPTO_CIPHER_ZUC_EEA3, 1256 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1257 }; 1258 const enum rte_crypto_auth_algorithm auths[] = { 1259 RTE_CRYPTO_AUTH_NULL, 1260 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 1261 RTE_CRYPTO_AUTH_AES_CMAC, 1262 RTE_CRYPTO_AUTH_ZUC_EIA3 1263 }; 1264 1265 rte_cryptodev_info_get(dev_id, &dev_info); 1266 feat_flags = dev_info.feature_flags; 1267 1268 if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1269 (global_api_test_type == CRYPTODEV_RAW_API_TEST)) { 1270 RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed " 1271 "Cipher Hash testsuite not met\n"); 1272 return TEST_SKIPPED; 1273 } 1274 1275 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1276 && check_auth_capabilities_supported(auths, 1277 RTE_DIM(auths)) != 0) { 1278 RTE_LOG(INFO, USER1, "Capability requirements for Mixed " 1279 "Cipher Hash testsuite not met\n"); 1280 return TEST_SKIPPED; 1281 } 1282 1283 return 0; 1284 } 1285 1286 static int 1287 esn_testsuite_setup(void) 1288 { 1289 struct crypto_testsuite_params *ts_params = &testsuite_params; 1290 uint8_t dev_id = ts_params->valid_devs[0]; 1291 struct rte_cryptodev_info dev_info; 1292 const enum rte_crypto_cipher_algorithm ciphers[] = { 1293 RTE_CRYPTO_CIPHER_AES_CBC 1294 }; 1295 const enum rte_crypto_auth_algorithm auths[] = { 1296 RTE_CRYPTO_AUTH_SHA1_HMAC 1297 }; 1298 1299 rte_cryptodev_info_get(dev_id, &dev_info); 1300 1301 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1302 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1303 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1304 RTE_LOG(INFO, USER1, "Feature flag requirements for ESN " 1305 "testsuite not met\n"); 1306 return TEST_SKIPPED; 1307 } 1308 1309 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1310 && check_auth_capabilities_supported(auths, 1311 RTE_DIM(auths)) != 0) { 1312 RTE_LOG(INFO, USER1, "Capability requirements for ESN " 1313 "testsuite not met\n"); 1314 return TEST_SKIPPED; 1315 } 1316 1317 return 0; 1318 } 1319 1320 static int 1321 multi_session_testsuite_setup(void) 1322 { 1323 struct crypto_testsuite_params *ts_params = &testsuite_params; 1324 uint8_t dev_id = ts_params->valid_devs[0]; 1325 struct rte_cryptodev_info dev_info; 1326 const enum rte_crypto_cipher_algorithm ciphers[] = { 1327 RTE_CRYPTO_CIPHER_AES_CBC 1328 }; 1329 const enum rte_crypto_auth_algorithm auths[] = { 1330 RTE_CRYPTO_AUTH_SHA512_HMAC 1331 }; 1332 1333 rte_cryptodev_info_get(dev_id, &dev_info); 1334 1335 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1336 RTE_LOG(INFO, USER1, "Feature flag requirements for Multi " 1337 "Session testsuite not met\n"); 1338 return TEST_SKIPPED; 1339 } 1340 1341 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1342 && check_auth_capabilities_supported(auths, 1343 RTE_DIM(auths)) != 0) { 1344 RTE_LOG(INFO, USER1, "Capability requirements for Multi " 1345 "Session testsuite not met\n"); 1346 return TEST_SKIPPED; 1347 } 1348 1349 return 0; 1350 } 1351 1352 static int 1353 negative_hmac_sha1_testsuite_setup(void) 1354 { 1355 struct crypto_testsuite_params *ts_params = &testsuite_params; 1356 uint8_t dev_id = ts_params->valid_devs[0]; 1357 struct rte_cryptodev_info dev_info; 1358 const enum rte_crypto_cipher_algorithm ciphers[] = { 1359 RTE_CRYPTO_CIPHER_AES_CBC 1360 }; 1361 const enum rte_crypto_auth_algorithm auths[] = { 1362 RTE_CRYPTO_AUTH_SHA1_HMAC 1363 }; 1364 1365 rte_cryptodev_info_get(dev_id, &dev_info); 1366 1367 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1368 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1369 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1370 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1371 "HMAC SHA1 testsuite not met\n"); 1372 return TEST_SKIPPED; 1373 } 1374 1375 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1376 && check_auth_capabilities_supported(auths, 1377 RTE_DIM(auths)) != 0) { 1378 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1379 "HMAC SHA1 testsuite not met\n"); 1380 return TEST_SKIPPED; 1381 } 1382 1383 return 0; 1384 } 1385 1386 static int 1387 dev_configure_and_start(uint64_t ff_disable) 1388 { 1389 struct crypto_testsuite_params *ts_params = &testsuite_params; 1390 struct crypto_unittest_params *ut_params = &unittest_params; 1391 1392 uint16_t qp_id; 1393 1394 /* Clear unit test parameters before running test */ 1395 memset(ut_params, 0, sizeof(*ut_params)); 1396 1397 /* Reconfigure device to default parameters */ 1398 ts_params->conf.socket_id = SOCKET_ID_ANY; 1399 ts_params->conf.ff_disable = ff_disable; 1400 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 1401 ts_params->qp_conf.mp_session = ts_params->session_mpool; 1402 1403 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1404 &ts_params->conf), 1405 "Failed to configure cryptodev %u", 1406 ts_params->valid_devs[0]); 1407 1408 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { 1409 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1410 ts_params->valid_devs[0], qp_id, 1411 &ts_params->qp_conf, 1412 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1413 "Failed to setup queue pair %u on cryptodev %u", 1414 qp_id, ts_params->valid_devs[0]); 1415 } 1416 1417 1418 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 1419 1420 /* Start the device */ 1421 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 1422 "Failed to start cryptodev %u", 1423 ts_params->valid_devs[0]); 1424 1425 return TEST_SUCCESS; 1426 } 1427 1428 int 1429 ut_setup(void) 1430 { 1431 /* Configure and start the device with security feature disabled */ 1432 return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY); 1433 } 1434 1435 static int 1436 ut_setup_security(void) 1437 { 1438 /* Configure and start the device with no features disabled */ 1439 return dev_configure_and_start(0); 1440 } 1441 1442 static int 1443 ut_setup_security_rx_inject(void) 1444 { 1445 struct rte_mempool *mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 1446 struct crypto_testsuite_params *ts_params = &testsuite_params; 1447 struct rte_eth_conf port_conf = { 1448 .rxmode = { 1449 .offloads = RTE_ETH_RX_OFFLOAD_CHECKSUM | 1450 RTE_ETH_RX_OFFLOAD_SECURITY, 1451 }, 1452 .txmode = { 1453 .offloads = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE, 1454 }, 1455 .lpbk_mode = 1, /* Enable loopback */ 1456 }; 1457 struct rte_cryptodev_info dev_info; 1458 struct rte_eth_rxconf rx_conf = { 1459 .rx_thresh = { 1460 .pthresh = 8, 1461 .hthresh = 8, 1462 .wthresh = 8, 1463 }, 1464 .rx_free_thresh = 32, 1465 }; 1466 uint16_t nb_ports; 1467 void *sec_ctx; 1468 int ret; 1469 1470 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 1471 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY_RX_INJECT) || 1472 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) { 1473 RTE_LOG(INFO, USER1, 1474 "Feature requirements for IPsec Rx inject test case not met\n"); 1475 return TEST_SKIPPED; 1476 } 1477 1478 sec_ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 1479 if (sec_ctx == NULL) 1480 return TEST_SKIPPED; 1481 1482 nb_ports = rte_eth_dev_count_avail(); 1483 if (nb_ports == 0) 1484 return TEST_SKIPPED; 1485 1486 ret = rte_eth_dev_configure(0 /* port_id */, 1487 1 /* nb_rx_queue */, 1488 0 /* nb_tx_queue */, 1489 &port_conf); 1490 if (ret) { 1491 printf("Could not configure ethdev port 0 [err=%d]\n", ret); 1492 return TEST_SKIPPED; 1493 } 1494 1495 /* Rx queue setup */ 1496 ret = rte_eth_rx_queue_setup(0 /* port_id */, 1497 0 /* rx_queue_id */, 1498 1024 /* nb_rx_desc */, 1499 SOCKET_ID_ANY, 1500 &rx_conf, 1501 mbuf_pool); 1502 if (ret) { 1503 printf("Could not setup eth port 0 queue 0\n"); 1504 return TEST_SKIPPED; 1505 } 1506 1507 ret = rte_security_rx_inject_configure(sec_ctx, 0, true); 1508 if (ret) { 1509 printf("Could not enable Rx inject offload"); 1510 return TEST_SKIPPED; 1511 } 1512 1513 ret = rte_eth_dev_start(0); 1514 if (ret) { 1515 printf("Could not start ethdev"); 1516 return TEST_SKIPPED; 1517 } 1518 1519 ret = rte_eth_promiscuous_enable(0); 1520 if (ret) { 1521 printf("Could not enable promiscuous mode"); 1522 return TEST_SKIPPED; 1523 } 1524 1525 /* Configure and start cryptodev with no features disabled */ 1526 return dev_configure_and_start(0); 1527 } 1528 1529 static inline void 1530 ext_mbuf_callback_fn_free(void *addr __rte_unused, void *opaque __rte_unused) 1531 { 1532 } 1533 1534 static inline void 1535 ext_mbuf_memzone_free(int nb_segs) 1536 { 1537 int i; 1538 1539 for (i = 0; i <= nb_segs; i++) { 1540 char mz_name[RTE_MEMZONE_NAMESIZE]; 1541 const struct rte_memzone *memzone; 1542 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "ext_buf_%d", i); 1543 memzone = rte_memzone_lookup(mz_name); 1544 if (memzone != NULL) { 1545 rte_memzone_free(memzone); 1546 memzone = NULL; 1547 } 1548 } 1549 } 1550 1551 static inline struct rte_mbuf * 1552 ext_mbuf_create(struct rte_mempool *mbuf_pool, int pkt_len, 1553 int nb_segs, const void *input_text) 1554 { 1555 struct rte_mbuf *m = NULL, *mbuf = NULL; 1556 size_t data_off = 0; 1557 uint8_t *dst; 1558 int i, size; 1559 int t_len; 1560 1561 if (pkt_len < 1) { 1562 printf("Packet size must be 1 or more (is %d)\n", pkt_len); 1563 return NULL; 1564 } 1565 1566 if (nb_segs < 1) { 1567 printf("Number of segments must be 1 or more (is %d)\n", 1568 nb_segs); 1569 return NULL; 1570 } 1571 1572 t_len = pkt_len >= nb_segs ? pkt_len / nb_segs : 1; 1573 size = pkt_len; 1574 1575 /* Create chained mbuf_src with external buffer */ 1576 for (i = 0; size > 0; i++) { 1577 struct rte_mbuf_ext_shared_info *ret_shinfo = NULL; 1578 uint16_t data_len = RTE_MIN(size, t_len); 1579 char mz_name[RTE_MEMZONE_NAMESIZE]; 1580 const struct rte_memzone *memzone; 1581 void *ext_buf_addr = NULL; 1582 rte_iova_t buf_iova; 1583 bool freed = false; 1584 uint16_t buf_len; 1585 1586 buf_len = RTE_ALIGN_CEIL(data_len + 1024 + 1587 sizeof(struct rte_mbuf_ext_shared_info), 8); 1588 1589 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "ext_buf_%d", i); 1590 memzone = rte_memzone_lookup(mz_name); 1591 if (memzone != NULL && memzone->len != buf_len) { 1592 rte_memzone_free(memzone); 1593 memzone = NULL; 1594 } 1595 if (memzone == NULL) { 1596 memzone = rte_memzone_reserve_aligned(mz_name, buf_len, SOCKET_ID_ANY, 1597 RTE_MEMZONE_IOVA_CONTIG, RTE_CACHE_LINE_SIZE); 1598 if (memzone == NULL) { 1599 printf("Can't allocate memory zone %s\n", mz_name); 1600 return NULL; 1601 } 1602 } 1603 1604 ext_buf_addr = memzone->addr; 1605 if (input_text) 1606 memcpy(ext_buf_addr, RTE_PTR_ADD(input_text, data_off), data_len); 1607 1608 /* Create buffer to hold rte_mbuf header */ 1609 m = rte_pktmbuf_alloc(mbuf_pool); 1610 if (i == 0) 1611 mbuf = m; 1612 1613 if (m == NULL) { 1614 printf("Cannot create segment for source mbuf"); 1615 goto fail; 1616 } 1617 1618 /* Save shared data (like callback function) in external buffer's end */ 1619 ret_shinfo = rte_pktmbuf_ext_shinfo_init_helper(ext_buf_addr, &buf_len, 1620 ext_mbuf_callback_fn_free, &freed); 1621 if (ret_shinfo == NULL) { 1622 printf("Shared mem initialization failed!\n"); 1623 goto fail; 1624 } 1625 1626 buf_iova = rte_mem_virt2iova(ext_buf_addr); 1627 1628 /* Attach external buffer to mbuf */ 1629 rte_pktmbuf_attach_extbuf(m, ext_buf_addr, buf_iova, buf_len, 1630 ret_shinfo); 1631 if (m->ol_flags != RTE_MBUF_F_EXTERNAL) { 1632 printf("External buffer is not attached to mbuf\n"); 1633 goto fail; 1634 } 1635 1636 if (input_text) { 1637 dst = (uint8_t *)rte_pktmbuf_append(m, data_len); 1638 if (dst == NULL) { 1639 printf("Cannot append %d bytes to the mbuf\n", data_len); 1640 goto fail; 1641 } 1642 } 1643 1644 if (mbuf != m) 1645 rte_pktmbuf_chain(mbuf, m); 1646 1647 size -= data_len; 1648 data_off += data_len; 1649 } 1650 1651 return mbuf; 1652 1653 fail: 1654 rte_pktmbuf_free(mbuf); 1655 ext_mbuf_memzone_free(nb_segs); 1656 return NULL; 1657 } 1658 1659 void 1660 ut_teardown(void) 1661 { 1662 struct crypto_testsuite_params *ts_params = &testsuite_params; 1663 struct crypto_unittest_params *ut_params = &unittest_params; 1664 1665 /* free crypto session structure */ 1666 #ifdef RTE_LIB_SECURITY 1667 if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) { 1668 if (ut_params->sec_session) { 1669 rte_security_session_destroy(rte_cryptodev_get_sec_ctx 1670 (ts_params->valid_devs[0]), 1671 ut_params->sec_session); 1672 ut_params->sec_session = NULL; 1673 } 1674 } else 1675 #endif 1676 { 1677 if (ut_params->sess) { 1678 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 1679 ut_params->sess); 1680 ut_params->sess = NULL; 1681 } 1682 } 1683 1684 /* free crypto operation structure */ 1685 rte_crypto_op_free(ut_params->op); 1686 1687 /* 1688 * free mbuf - both obuf and ibuf are usually the same, 1689 * so check if they point at the same address is necessary, 1690 * to avoid freeing the mbuf twice. 1691 */ 1692 if (ut_params->obuf) { 1693 rte_pktmbuf_free(ut_params->obuf); 1694 if (ut_params->ibuf == ut_params->obuf) 1695 ut_params->ibuf = 0; 1696 ut_params->obuf = 0; 1697 } 1698 if (ut_params->ibuf) { 1699 ext_mbuf_memzone_free(1); 1700 rte_pktmbuf_free(ut_params->ibuf); 1701 ut_params->ibuf = 0; 1702 } 1703 1704 if (ts_params->mbuf_pool != NULL) 1705 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 1706 rte_mempool_avail_count(ts_params->mbuf_pool)); 1707 1708 /* Stop the device */ 1709 rte_cryptodev_stop(ts_params->valid_devs[0]); 1710 } 1711 1712 static void 1713 ut_teardown_rx_inject(void) 1714 { 1715 struct crypto_testsuite_params *ts_params = &testsuite_params; 1716 void *sec_ctx; 1717 int ret; 1718 1719 if (rte_eth_dev_count_avail() != 0) { 1720 ret = rte_eth_dev_reset(0); 1721 if (ret) 1722 printf("Could not reset eth port 0"); 1723 1724 } 1725 1726 ut_teardown(); 1727 1728 sec_ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 1729 if (sec_ctx == NULL) 1730 return; 1731 1732 ret = rte_security_rx_inject_configure(sec_ctx, 0, false); 1733 if (ret) { 1734 printf("Could not disable Rx inject offload"); 1735 return; 1736 } 1737 } 1738 1739 static int 1740 test_device_configure_invalid_dev_id(void) 1741 { 1742 struct crypto_testsuite_params *ts_params = &testsuite_params; 1743 uint16_t dev_id, num_devs = 0; 1744 1745 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 1746 "Need at least %d devices for test", 1); 1747 1748 /* valid dev_id values */ 1749 dev_id = ts_params->valid_devs[0]; 1750 1751 /* Stop the device in case it's started so it can be configured */ 1752 rte_cryptodev_stop(dev_id); 1753 1754 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 1755 "Failed test for rte_cryptodev_configure: " 1756 "invalid dev_num %u", dev_id); 1757 1758 /* invalid dev_id values */ 1759 dev_id = num_devs; 1760 1761 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1762 "Failed test for rte_cryptodev_configure: " 1763 "invalid dev_num %u", dev_id); 1764 1765 dev_id = 0xff; 1766 1767 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1768 "Failed test for rte_cryptodev_configure:" 1769 "invalid dev_num %u", dev_id); 1770 1771 return TEST_SUCCESS; 1772 } 1773 1774 static int 1775 test_device_configure_invalid_queue_pair_ids(void) 1776 { 1777 struct crypto_testsuite_params *ts_params = &testsuite_params; 1778 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 1779 1780 /* Stop the device in case it's started so it can be configured */ 1781 rte_cryptodev_stop(ts_params->valid_devs[0]); 1782 1783 /* valid - max value queue pairs */ 1784 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1785 1786 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1787 &ts_params->conf), 1788 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1789 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 1790 1791 /* valid - one queue pairs */ 1792 ts_params->conf.nb_queue_pairs = 1; 1793 1794 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1795 &ts_params->conf), 1796 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1797 ts_params->valid_devs[0], 1798 ts_params->conf.nb_queue_pairs); 1799 1800 1801 /* invalid - zero queue pairs */ 1802 ts_params->conf.nb_queue_pairs = 0; 1803 1804 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1805 &ts_params->conf), 1806 "Failed test for rte_cryptodev_configure, dev_id %u," 1807 " invalid qps: %u", 1808 ts_params->valid_devs[0], 1809 ts_params->conf.nb_queue_pairs); 1810 1811 1812 /* invalid - max value supported by field queue pairs */ 1813 ts_params->conf.nb_queue_pairs = UINT16_MAX; 1814 1815 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1816 &ts_params->conf), 1817 "Failed test for rte_cryptodev_configure, dev_id %u," 1818 " invalid qps: %u", 1819 ts_params->valid_devs[0], 1820 ts_params->conf.nb_queue_pairs); 1821 1822 1823 /* invalid - max value + 1 queue pairs */ 1824 ts_params->conf.nb_queue_pairs = orig_nb_qps + 1; 1825 1826 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1827 &ts_params->conf), 1828 "Failed test for rte_cryptodev_configure, dev_id %u," 1829 " invalid qps: %u", 1830 ts_params->valid_devs[0], 1831 ts_params->conf.nb_queue_pairs); 1832 1833 /* revert to original testsuite value */ 1834 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1835 1836 return TEST_SUCCESS; 1837 } 1838 1839 static int 1840 test_queue_pair_descriptor_setup(void) 1841 { 1842 struct crypto_testsuite_params *ts_params = &testsuite_params; 1843 struct rte_cryptodev_qp_conf qp_conf = { 1844 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 1845 }; 1846 uint16_t qp_id; 1847 1848 /* Stop the device in case it's started so it can be configured */ 1849 rte_cryptodev_stop(ts_params->valid_devs[0]); 1850 1851 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1852 &ts_params->conf), 1853 "Failed to configure cryptodev %u", 1854 ts_params->valid_devs[0]); 1855 1856 /* 1857 * Test various ring sizes on this device. memzones can't be 1858 * freed so are re-used if ring is released and re-created. 1859 */ 1860 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/ 1861 qp_conf.mp_session = ts_params->session_mpool; 1862 1863 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1864 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1865 ts_params->valid_devs[0], qp_id, &qp_conf, 1866 rte_cryptodev_socket_id( 1867 ts_params->valid_devs[0])), 1868 "Failed test for " 1869 "rte_cryptodev_queue_pair_setup: num_inflights " 1870 "%u on qp %u on cryptodev %u", 1871 qp_conf.nb_descriptors, qp_id, 1872 ts_params->valid_devs[0]); 1873 } 1874 1875 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2); 1876 1877 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1878 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1879 ts_params->valid_devs[0], qp_id, &qp_conf, 1880 rte_cryptodev_socket_id( 1881 ts_params->valid_devs[0])), 1882 "Failed test for" 1883 " rte_cryptodev_queue_pair_setup: num_inflights" 1884 " %u on qp %u on cryptodev %u", 1885 qp_conf.nb_descriptors, qp_id, 1886 ts_params->valid_devs[0]); 1887 } 1888 1889 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */ 1890 1891 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1892 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1893 ts_params->valid_devs[0], qp_id, &qp_conf, 1894 rte_cryptodev_socket_id( 1895 ts_params->valid_devs[0])), 1896 "Failed test for " 1897 "rte_cryptodev_queue_pair_setup: num_inflights" 1898 " %u on qp %u on cryptodev %u", 1899 qp_conf.nb_descriptors, qp_id, 1900 ts_params->valid_devs[0]); 1901 } 1902 1903 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 1904 1905 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1906 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1907 ts_params->valid_devs[0], qp_id, &qp_conf, 1908 rte_cryptodev_socket_id( 1909 ts_params->valid_devs[0])), 1910 "Failed test for" 1911 " rte_cryptodev_queue_pair_setup:" 1912 "num_inflights %u on qp %u on cryptodev %u", 1913 qp_conf.nb_descriptors, qp_id, 1914 ts_params->valid_devs[0]); 1915 } 1916 1917 /* test invalid queue pair id */ 1918 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */ 1919 1920 qp_id = ts_params->conf.nb_queue_pairs; /*invalid */ 1921 1922 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1923 ts_params->valid_devs[0], 1924 qp_id, &qp_conf, 1925 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1926 "Failed test for rte_cryptodev_queue_pair_setup:" 1927 "invalid qp %u on cryptodev %u", 1928 qp_id, ts_params->valid_devs[0]); 1929 1930 qp_id = 0xffff; /*invalid*/ 1931 1932 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1933 ts_params->valid_devs[0], 1934 qp_id, &qp_conf, 1935 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1936 "Failed test for rte_cryptodev_queue_pair_setup:" 1937 "invalid qp %u on cryptodev %u", 1938 qp_id, ts_params->valid_devs[0]); 1939 1940 return TEST_SUCCESS; 1941 } 1942 1943 /* ***** Plaintext data for tests ***** */ 1944 1945 const char catch_22_quote_1[] = 1946 "There was only one catch and that was Catch-22, which " 1947 "specified that a concern for one's safety in the face of " 1948 "dangers that were real and immediate was the process of a " 1949 "rational mind. Orr was crazy and could be grounded. All he " 1950 "had to do was ask; and as soon as he did, he would no longer " 1951 "be crazy and would have to fly more missions. Orr would be " 1952 "crazy to fly more missions and sane if he didn't, but if he " 1953 "was sane he had to fly them. If he flew them he was crazy " 1954 "and didn't have to; but if he didn't want to he was sane and " 1955 "had to. Yossarian was moved very deeply by the absolute " 1956 "simplicity of this clause of Catch-22 and let out a " 1957 "respectful whistle. \"That's some catch, that Catch-22\", he " 1958 "observed. \"It's the best there is,\" Doc Daneeka agreed."; 1959 1960 const char catch_22_quote[] = 1961 "What a lousy earth! He wondered how many people were " 1962 "destitute that same night even in his own prosperous country, " 1963 "how many homes were shanties, how many husbands were drunk " 1964 "and wives socked, and how many children were bullied, abused, " 1965 "or abandoned. How many families hungered for food they could " 1966 "not afford to buy? How many hearts were broken? How many " 1967 "suicides would take place that same night, how many people " 1968 "would go insane? How many cockroaches and landlords would " 1969 "triumph? How many winners were losers, successes failures, " 1970 "and rich men poor men? How many wise guys were stupid? How " 1971 "many happy endings were unhappy endings? How many honest men " 1972 "were liars, brave men cowards, loyal men traitors, how many " 1973 "sainted men were corrupt, how many people in positions of " 1974 "trust had sold their souls to bodyguards, how many had never " 1975 "had souls? How many straight-and-narrow paths were crooked " 1976 "paths? How many best families were worst families and how " 1977 "many good people were bad people? When you added them all up " 1978 "and then subtracted, you might be left with only the children, " 1979 "and perhaps with Albert Einstein and an old violinist or " 1980 "sculptor somewhere."; 1981 1982 #define QUOTE_480_BYTES (480) 1983 #define QUOTE_512_BYTES (512) 1984 #define QUOTE_768_BYTES (768) 1985 #define QUOTE_1024_BYTES (1024) 1986 1987 1988 1989 /* ***** SHA1 Hash Tests ***** */ 1990 1991 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1) 1992 1993 static uint8_t hmac_sha1_key[] = { 1994 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 1995 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 1996 0xDE, 0xF4, 0xDE, 0xAD }; 1997 1998 /* ***** SHA224 Hash Tests ***** */ 1999 2000 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224) 2001 2002 2003 /* ***** AES-CBC Cipher Tests ***** */ 2004 2005 #define CIPHER_KEY_LENGTH_AES_CBC (16) 2006 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC) 2007 2008 static uint8_t aes_cbc_key[] = { 2009 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 2010 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A }; 2011 2012 static uint8_t aes_cbc_iv[] = { 2013 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 2014 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; 2015 2016 2017 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */ 2018 2019 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = { 2020 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, 2021 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, 2022 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, 2023 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, 2024 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E, 2025 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08, 2026 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0, 2027 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01, 2028 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57, 2029 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE, 2030 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9, 2031 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9, 2032 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D, 2033 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3, 2034 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46, 2035 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3, 2036 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80, 2037 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92, 2038 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5, 2039 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5, 2040 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2, 2041 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5, 2042 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2043 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76, 2044 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4, 2045 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62, 2046 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4, 2047 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4, 2048 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54, 2049 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61, 2050 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91, 2051 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A, 2052 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF, 2053 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F, 2054 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28, 2055 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E, 2056 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7, 2057 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76, 2058 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6, 2059 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03, 2060 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C, 2061 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2, 2062 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6, 2063 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96, 2064 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6, 2065 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA, 2066 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87, 2067 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55, 2068 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B, 2069 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98, 2070 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53, 2071 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A, 2072 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26, 2073 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36, 2074 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36, 2075 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D, 2076 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E, 2077 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E, 2078 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A, 2079 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6, 2080 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4, 2081 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7, 2082 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1, 2083 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C 2084 }; 2085 2086 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = { 2087 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60, 2088 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 2089 0x18, 0x8c, 0x1d, 0x32 2090 }; 2091 2092 2093 /* Multisession Vector context Test */ 2094 /*Begin Session 0 */ 2095 static uint8_t ms_aes_cbc_key0[] = { 2096 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2097 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2098 }; 2099 2100 static uint8_t ms_aes_cbc_iv0[] = { 2101 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2102 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2103 }; 2104 2105 static const uint8_t ms_aes_cbc_cipher0[] = { 2106 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38, 2107 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC, 2108 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB, 2109 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9, 2110 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D, 2111 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4, 2112 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34, 2113 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F, 2114 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99, 2115 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED, 2116 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D, 2117 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24, 2118 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71, 2119 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72, 2120 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E, 2121 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD, 2122 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18, 2123 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6, 2124 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29, 2125 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C, 2126 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96, 2127 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26, 2128 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55, 2129 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46, 2130 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B, 2131 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4, 2132 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7, 2133 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5, 2134 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0, 2135 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E, 2136 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D, 2137 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44, 2138 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76, 2139 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3, 2140 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83, 2141 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85, 2142 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45, 2143 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25, 2144 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A, 2145 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1, 2146 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA, 2147 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3, 2148 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4, 2149 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60, 2150 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A, 2151 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A, 2152 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9, 2153 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55, 2154 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13, 2155 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B, 2156 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1, 2157 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0, 2158 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3, 2159 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23, 2160 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B, 2161 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07, 2162 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB, 2163 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1, 2164 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F, 2165 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F, 2166 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84, 2167 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B, 2168 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17, 2169 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF 2170 }; 2171 2172 2173 static uint8_t ms_hmac_key0[] = { 2174 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2175 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2176 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2177 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2178 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2179 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2180 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2181 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2182 }; 2183 2184 static const uint8_t ms_hmac_digest0[] = { 2185 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51, 2186 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F, 2187 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C, 2188 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4, 2189 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56, 2190 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4, 2191 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23, 2192 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90 2193 }; 2194 2195 /* End Session 0 */ 2196 /* Begin session 1 */ 2197 2198 static uint8_t ms_aes_cbc_key1[] = { 2199 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2200 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2201 }; 2202 2203 static uint8_t ms_aes_cbc_iv1[] = { 2204 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2205 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2206 }; 2207 2208 static const uint8_t ms_aes_cbc_cipher1[] = { 2209 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71, 2210 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23, 2211 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09, 2212 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A, 2213 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C, 2214 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F, 2215 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9, 2216 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66, 2217 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43, 2218 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB, 2219 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23, 2220 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29, 2221 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26, 2222 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F, 2223 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68, 2224 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77, 2225 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8, 2226 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97, 2227 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3, 2228 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90, 2229 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5, 2230 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E, 2231 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45, 2232 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B, 2233 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5, 2234 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D, 2235 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E, 2236 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD, 2237 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE, 2238 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1, 2239 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F, 2240 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25, 2241 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1, 2242 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3, 2243 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE, 2244 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6, 2245 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52, 2246 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA, 2247 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63, 2248 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E, 2249 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA, 2250 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB, 2251 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71, 2252 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF, 2253 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A, 2254 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95, 2255 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73, 2256 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49, 2257 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB, 2258 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B, 2259 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC, 2260 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED, 2261 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02, 2262 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4, 2263 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF, 2264 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82, 2265 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D, 2266 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6, 2267 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9, 2268 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35, 2269 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0, 2270 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53, 2271 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5, 2272 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3 2273 2274 }; 2275 2276 static uint8_t ms_hmac_key1[] = { 2277 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2278 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2279 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2280 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2281 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2282 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2283 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2284 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2285 }; 2286 2287 static const uint8_t ms_hmac_digest1[] = { 2288 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69, 2289 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50, 2290 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20, 2291 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD, 2292 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9, 2293 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4, 2294 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA, 2295 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F 2296 }; 2297 /* End Session 1 */ 2298 /* Begin Session 2 */ 2299 static uint8_t ms_aes_cbc_key2[] = { 2300 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2301 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2302 }; 2303 2304 static uint8_t ms_aes_cbc_iv2[] = { 2305 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2306 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2307 }; 2308 2309 static const uint8_t ms_aes_cbc_cipher2[] = { 2310 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91, 2311 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97, 2312 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8, 2313 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5, 2314 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98, 2315 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69, 2316 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09, 2317 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF, 2318 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44, 2319 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B, 2320 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9, 2321 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34, 2322 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99, 2323 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF, 2324 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC, 2325 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26, 2326 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3, 2327 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF, 2328 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3, 2329 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3, 2330 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA, 2331 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13, 2332 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38, 2333 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71, 2334 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC, 2335 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1, 2336 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E, 2337 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22, 2338 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62, 2339 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72, 2340 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6, 2341 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6, 2342 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44, 2343 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24, 2344 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5, 2345 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E, 2346 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17, 2347 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9, 2348 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D, 2349 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D, 2350 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22, 2351 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9, 2352 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49, 2353 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E, 2354 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B, 2355 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2, 2356 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95, 2357 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07, 2358 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3, 2359 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A, 2360 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57, 2361 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84, 2362 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61, 2363 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF, 2364 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17, 2365 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A, 2366 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1, 2367 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53, 2368 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7, 2369 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2, 2370 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A, 2371 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8, 2372 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70, 2373 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92 2374 }; 2375 2376 static uint8_t ms_hmac_key2[] = { 2377 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2378 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2379 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2380 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2381 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2382 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2383 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2384 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2385 }; 2386 2387 static const uint8_t ms_hmac_digest2[] = { 2388 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF, 2389 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6, 2390 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77, 2391 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27, 2392 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82, 2393 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24, 2394 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E, 2395 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59 2396 }; 2397 2398 /* End Session 2 */ 2399 2400 2401 static int 2402 test_AES_CBC_HMAC_SHA1_encrypt_digest(void) 2403 { 2404 struct crypto_testsuite_params *ts_params = &testsuite_params; 2405 struct crypto_unittest_params *ut_params = &unittest_params; 2406 /* Verify the capabilities */ 2407 struct rte_cryptodev_sym_capability_idx cap_idx; 2408 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2409 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 2410 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2411 &cap_idx) == NULL) 2412 return TEST_SKIPPED; 2413 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2414 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 2415 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2416 &cap_idx) == NULL) 2417 return TEST_SKIPPED; 2418 2419 /* Generate test mbuf data and space for digest */ 2420 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2421 catch_22_quote, QUOTE_512_BYTES, 0); 2422 2423 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2424 DIGEST_BYTE_LENGTH_SHA1); 2425 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2426 2427 /* Setup Cipher Parameters */ 2428 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2429 ut_params->cipher_xform.next = &ut_params->auth_xform; 2430 2431 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2432 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 2433 ut_params->cipher_xform.cipher.key.data = aes_cbc_key; 2434 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2435 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2436 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2437 2438 /* Setup HMAC Parameters */ 2439 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2440 2441 ut_params->auth_xform.next = NULL; 2442 2443 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 2444 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 2445 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; 2446 ut_params->auth_xform.auth.key.data = hmac_sha1_key; 2447 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; 2448 2449 rte_errno = 0; 2450 ut_params->sess = rte_cryptodev_sym_session_create( 2451 ts_params->valid_devs[0], &ut_params->cipher_xform, 2452 ts_params->session_mpool); 2453 if (rte_errno == ENOTSUP) 2454 return TEST_SKIPPED; 2455 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2456 2457 /* Generate crypto op data structure */ 2458 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2459 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2460 TEST_ASSERT_NOT_NULL(ut_params->op, 2461 "Failed to allocate symmetric crypto operation struct"); 2462 2463 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2464 2465 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2466 2467 /* set crypto operation source mbuf */ 2468 sym_op->m_src = ut_params->ibuf; 2469 2470 /* Set crypto operation authentication parameters */ 2471 sym_op->auth.digest.data = ut_params->digest; 2472 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2473 ut_params->ibuf, QUOTE_512_BYTES); 2474 2475 sym_op->auth.data.offset = 0; 2476 sym_op->auth.data.length = QUOTE_512_BYTES; 2477 2478 /* Copy IV at the end of the crypto operation */ 2479 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2480 aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC); 2481 2482 /* Set crypto operation cipher parameters */ 2483 sym_op->cipher.data.offset = 0; 2484 sym_op->cipher.data.length = QUOTE_512_BYTES; 2485 2486 /* Process crypto operation */ 2487 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2488 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2489 ut_params->op); 2490 else 2491 TEST_ASSERT_NOT_NULL( 2492 process_crypto_request(ts_params->valid_devs[0], 2493 ut_params->op), 2494 "failed to process sym crypto op"); 2495 2496 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2497 "crypto op processing failed"); 2498 2499 /* Validate obuf */ 2500 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 2501 uint8_t *); 2502 2503 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, 2504 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 2505 QUOTE_512_BYTES, 2506 "ciphertext data not as expected"); 2507 2508 uint8_t *digest = ciphertext + QUOTE_512_BYTES; 2509 2510 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, 2511 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, 2512 gbl_driver_id == rte_cryptodev_driver_id_get( 2513 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ? 2514 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : 2515 DIGEST_BYTE_LENGTH_SHA1, 2516 "Generated digest data not as expected"); 2517 2518 return TEST_SUCCESS; 2519 } 2520 2521 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ 2522 2523 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) 2524 2525 static uint8_t hmac_sha512_key[] = { 2526 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 2527 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2528 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2529 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60, 2530 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1, 2531 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2532 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76, 2533 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 }; 2534 2535 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = { 2536 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8, 2537 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48, 2538 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8, 2539 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70, 2540 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8, 2541 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E, 2542 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D, 2543 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A }; 2544 2545 2546 2547 static int 2548 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2549 struct crypto_unittest_params *ut_params, 2550 uint8_t *cipher_key, 2551 uint8_t *hmac_key); 2552 2553 static int 2554 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess, 2555 struct crypto_unittest_params *ut_params, 2556 struct crypto_testsuite_params *ts_params, 2557 const uint8_t *cipher, 2558 const uint8_t *digest, 2559 const uint8_t *iv); 2560 2561 2562 static int 2563 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2564 struct crypto_unittest_params *ut_params, 2565 uint8_t *cipher_key, 2566 uint8_t *hmac_key) 2567 { 2568 2569 /* Setup Cipher Parameters */ 2570 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2571 ut_params->cipher_xform.next = NULL; 2572 2573 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2574 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 2575 ut_params->cipher_xform.cipher.key.data = cipher_key; 2576 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2577 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2578 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2579 2580 /* Setup HMAC Parameters */ 2581 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2582 ut_params->auth_xform.next = &ut_params->cipher_xform; 2583 2584 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 2585 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC; 2586 ut_params->auth_xform.auth.key.data = hmac_key; 2587 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512; 2588 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512; 2589 2590 return TEST_SUCCESS; 2591 } 2592 2593 2594 static int 2595 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess, 2596 struct crypto_unittest_params *ut_params, 2597 struct crypto_testsuite_params *ts_params, 2598 const uint8_t *cipher, 2599 const uint8_t *digest, 2600 const uint8_t *iv) 2601 { 2602 int ret; 2603 2604 /* Generate test mbuf data and digest */ 2605 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2606 (const char *) 2607 cipher, 2608 QUOTE_512_BYTES, 0); 2609 2610 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2611 DIGEST_BYTE_LENGTH_SHA512); 2612 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2613 2614 rte_memcpy(ut_params->digest, 2615 digest, 2616 DIGEST_BYTE_LENGTH_SHA512); 2617 2618 /* Generate Crypto op data structure */ 2619 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2620 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2621 TEST_ASSERT_NOT_NULL(ut_params->op, 2622 "Failed to allocate symmetric crypto operation struct"); 2623 2624 rte_crypto_op_attach_sym_session(ut_params->op, sess); 2625 2626 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2627 2628 /* set crypto operation source mbuf */ 2629 sym_op->m_src = ut_params->ibuf; 2630 2631 sym_op->auth.digest.data = ut_params->digest; 2632 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2633 ut_params->ibuf, QUOTE_512_BYTES); 2634 2635 sym_op->auth.data.offset = 0; 2636 sym_op->auth.data.length = QUOTE_512_BYTES; 2637 2638 /* Copy IV at the end of the crypto operation */ 2639 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2640 iv, CIPHER_IV_LENGTH_AES_CBC); 2641 2642 sym_op->cipher.data.offset = 0; 2643 sym_op->cipher.data.length = QUOTE_512_BYTES; 2644 2645 /* Process crypto operation */ 2646 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2647 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2648 ut_params->op); 2649 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 2650 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 0); 2651 if (ret != TEST_SUCCESS) 2652 return ret; 2653 } else 2654 TEST_ASSERT_NOT_NULL( 2655 process_crypto_request(ts_params->valid_devs[0], 2656 ut_params->op), 2657 "failed to process sym crypto op"); 2658 2659 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2660 "crypto op processing failed"); 2661 2662 ut_params->obuf = ut_params->op->sym->m_src; 2663 2664 /* Validate obuf */ 2665 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2666 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 2667 catch_22_quote, 2668 QUOTE_512_BYTES, 2669 "Plaintext data not as expected"); 2670 2671 /* Validate obuf */ 2672 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2673 "Digest verification failed"); 2674 2675 return TEST_SUCCESS; 2676 } 2677 2678 /* ***** SNOW 3G Tests ***** */ 2679 static int 2680 create_wireless_algo_hash_session(uint8_t dev_id, 2681 const uint8_t *key, const uint8_t key_len, 2682 const uint8_t iv_len, const uint8_t auth_len, 2683 enum rte_crypto_auth_operation op, 2684 enum rte_crypto_auth_algorithm algo) 2685 { 2686 uint8_t hash_key[key_len]; 2687 2688 struct crypto_testsuite_params *ts_params = &testsuite_params; 2689 struct crypto_unittest_params *ut_params = &unittest_params; 2690 2691 memcpy(hash_key, key, key_len); 2692 2693 debug_hexdump(stdout, "key:", key, key_len); 2694 2695 /* Setup Authentication Parameters */ 2696 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2697 ut_params->auth_xform.next = NULL; 2698 2699 ut_params->auth_xform.auth.op = op; 2700 ut_params->auth_xform.auth.algo = algo; 2701 ut_params->auth_xform.auth.key.length = key_len; 2702 ut_params->auth_xform.auth.key.data = hash_key; 2703 ut_params->auth_xform.auth.digest_length = auth_len; 2704 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 2705 ut_params->auth_xform.auth.iv.length = iv_len; 2706 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2707 &ut_params->auth_xform, ts_params->session_mpool); 2708 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2709 return TEST_SKIPPED; 2710 2711 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2712 return 0; 2713 } 2714 2715 static int 2716 create_wireless_algo_cipher_session(uint8_t dev_id, 2717 enum rte_crypto_cipher_operation op, 2718 enum rte_crypto_cipher_algorithm algo, 2719 const uint8_t *key, const uint8_t key_len, 2720 uint8_t iv_len) 2721 { 2722 uint8_t cipher_key[key_len]; 2723 struct crypto_testsuite_params *ts_params = &testsuite_params; 2724 struct crypto_unittest_params *ut_params = &unittest_params; 2725 2726 memcpy(cipher_key, key, key_len); 2727 2728 /* Setup Cipher Parameters */ 2729 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2730 ut_params->cipher_xform.next = NULL; 2731 2732 ut_params->cipher_xform.cipher.algo = algo; 2733 ut_params->cipher_xform.cipher.op = op; 2734 ut_params->cipher_xform.cipher.key.data = cipher_key; 2735 ut_params->cipher_xform.cipher.key.length = key_len; 2736 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2737 ut_params->cipher_xform.cipher.iv.length = iv_len; 2738 2739 debug_hexdump(stdout, "key:", key, key_len); 2740 2741 /* Create Crypto session */ 2742 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2743 &ut_params->cipher_xform, ts_params->session_mpool); 2744 2745 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2746 return TEST_SKIPPED; 2747 2748 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2749 return 0; 2750 } 2751 2752 static int 2753 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len, 2754 unsigned int cipher_len, 2755 unsigned int cipher_offset) 2756 { 2757 struct crypto_testsuite_params *ts_params = &testsuite_params; 2758 struct crypto_unittest_params *ut_params = &unittest_params; 2759 2760 /* Generate Crypto op data structure */ 2761 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2762 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2763 TEST_ASSERT_NOT_NULL(ut_params->op, 2764 "Failed to allocate pktmbuf offload"); 2765 2766 /* Set crypto operation data parameters */ 2767 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2768 2769 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2770 2771 /* set crypto operation source mbuf */ 2772 sym_op->m_src = ut_params->ibuf; 2773 2774 /* iv */ 2775 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2776 iv, iv_len); 2777 sym_op->cipher.data.length = cipher_len; 2778 sym_op->cipher.data.offset = cipher_offset; 2779 return 0; 2780 } 2781 2782 static int 2783 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len, 2784 unsigned int cipher_len, 2785 unsigned int cipher_offset) 2786 { 2787 struct crypto_testsuite_params *ts_params = &testsuite_params; 2788 struct crypto_unittest_params *ut_params = &unittest_params; 2789 2790 /* Generate Crypto op data structure */ 2791 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2792 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2793 TEST_ASSERT_NOT_NULL(ut_params->op, 2794 "Failed to allocate pktmbuf offload"); 2795 2796 /* Set crypto operation data parameters */ 2797 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2798 2799 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2800 2801 /* set crypto operation source mbuf */ 2802 sym_op->m_src = ut_params->ibuf; 2803 sym_op->m_dst = ut_params->obuf; 2804 2805 /* iv */ 2806 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2807 iv, iv_len); 2808 sym_op->cipher.data.length = cipher_len; 2809 sym_op->cipher.data.offset = cipher_offset; 2810 return 0; 2811 } 2812 2813 static int 2814 create_wireless_algo_cipher_auth_session(uint8_t dev_id, 2815 enum rte_crypto_cipher_operation cipher_op, 2816 enum rte_crypto_auth_operation auth_op, 2817 enum rte_crypto_auth_algorithm auth_algo, 2818 enum rte_crypto_cipher_algorithm cipher_algo, 2819 const uint8_t *a_key, uint8_t a_key_len, 2820 const uint8_t *c_key, uint8_t c_key_len, 2821 uint8_t auth_iv_len, uint8_t auth_len, 2822 uint8_t cipher_iv_len) 2823 2824 { 2825 struct crypto_testsuite_params *ts_params = &testsuite_params; 2826 struct crypto_unittest_params *ut_params = &unittest_params; 2827 2828 /* Setup Authentication Parameters */ 2829 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2830 ut_params->auth_xform.next = NULL; 2831 2832 ut_params->auth_xform.auth.op = auth_op; 2833 ut_params->auth_xform.auth.algo = auth_algo; 2834 ut_params->auth_xform.auth.key.length = a_key_len; 2835 ut_params->auth_xform.auth.key.data = a_key; 2836 ut_params->auth_xform.auth.digest_length = auth_len; 2837 /* Auth IV will be after cipher IV */ 2838 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2839 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2840 2841 /* Setup Cipher Parameters */ 2842 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2843 ut_params->cipher_xform.next = &ut_params->auth_xform; 2844 2845 ut_params->cipher_xform.cipher.algo = cipher_algo; 2846 ut_params->cipher_xform.cipher.op = cipher_op; 2847 ut_params->cipher_xform.cipher.key.data = c_key; 2848 ut_params->cipher_xform.cipher.key.length = c_key_len; 2849 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2850 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2851 2852 debug_hexdump(stdout, "Auth key:", a_key, c_key_len); 2853 debug_hexdump(stdout, "Cipher key:", c_key, c_key_len); 2854 2855 /* Create Crypto session*/ 2856 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2857 &ut_params->cipher_xform, ts_params->session_mpool); 2858 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2859 return TEST_SKIPPED; 2860 2861 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2862 return 0; 2863 } 2864 2865 static int 2866 create_wireless_cipher_auth_session(uint8_t dev_id, 2867 enum rte_crypto_cipher_operation cipher_op, 2868 enum rte_crypto_auth_operation auth_op, 2869 enum rte_crypto_auth_algorithm auth_algo, 2870 enum rte_crypto_cipher_algorithm cipher_algo, 2871 const struct wireless_test_data *tdata) 2872 { 2873 const uint8_t key_len = tdata->key.len; 2874 uint8_t cipher_auth_key[key_len]; 2875 2876 struct crypto_testsuite_params *ts_params = &testsuite_params; 2877 struct crypto_unittest_params *ut_params = &unittest_params; 2878 const uint8_t *key = tdata->key.data; 2879 const uint8_t auth_len = tdata->digest.len; 2880 uint8_t cipher_iv_len = tdata->cipher_iv.len; 2881 uint8_t auth_iv_len = tdata->auth_iv.len; 2882 2883 memcpy(cipher_auth_key, key, key_len); 2884 2885 /* Setup Authentication Parameters */ 2886 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2887 ut_params->auth_xform.next = NULL; 2888 2889 ut_params->auth_xform.auth.op = auth_op; 2890 ut_params->auth_xform.auth.algo = auth_algo; 2891 ut_params->auth_xform.auth.key.length = key_len; 2892 /* Hash key = cipher key */ 2893 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2894 ut_params->auth_xform.auth.digest_length = auth_len; 2895 /* Auth IV will be after cipher IV */ 2896 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2897 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2898 2899 /* Setup Cipher Parameters */ 2900 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2901 ut_params->cipher_xform.next = &ut_params->auth_xform; 2902 2903 ut_params->cipher_xform.cipher.algo = cipher_algo; 2904 ut_params->cipher_xform.cipher.op = cipher_op; 2905 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2906 ut_params->cipher_xform.cipher.key.length = key_len; 2907 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2908 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2909 2910 2911 debug_hexdump(stdout, "key:", key, key_len); 2912 2913 /* Create Crypto session*/ 2914 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2915 &ut_params->cipher_xform, ts_params->session_mpool); 2916 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2917 return TEST_SKIPPED; 2918 2919 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2920 return 0; 2921 } 2922 2923 static int 2924 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id, 2925 const struct wireless_test_data *tdata) 2926 { 2927 return create_wireless_cipher_auth_session(dev_id, 2928 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2929 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3, 2930 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata); 2931 } 2932 2933 static int 2934 create_wireless_algo_auth_cipher_session(uint8_t dev_id, 2935 enum rte_crypto_cipher_operation cipher_op, 2936 enum rte_crypto_auth_operation auth_op, 2937 enum rte_crypto_auth_algorithm auth_algo, 2938 enum rte_crypto_cipher_algorithm cipher_algo, 2939 const uint8_t *a_key, const uint8_t a_key_len, 2940 const uint8_t *c_key, const uint8_t c_key_len, 2941 uint8_t auth_iv_len, uint8_t auth_len, 2942 uint8_t cipher_iv_len) 2943 { 2944 struct crypto_testsuite_params *ts_params = &testsuite_params; 2945 struct crypto_unittest_params *ut_params = &unittest_params; 2946 2947 /* Setup Authentication Parameters */ 2948 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2949 ut_params->auth_xform.auth.op = auth_op; 2950 ut_params->auth_xform.next = &ut_params->cipher_xform; 2951 ut_params->auth_xform.auth.algo = auth_algo; 2952 ut_params->auth_xform.auth.key.length = a_key_len; 2953 ut_params->auth_xform.auth.key.data = a_key; 2954 ut_params->auth_xform.auth.digest_length = auth_len; 2955 /* Auth IV will be after cipher IV */ 2956 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2957 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2958 2959 /* Setup Cipher Parameters */ 2960 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2961 ut_params->cipher_xform.next = NULL; 2962 ut_params->cipher_xform.cipher.algo = cipher_algo; 2963 ut_params->cipher_xform.cipher.op = cipher_op; 2964 ut_params->cipher_xform.cipher.key.data = c_key; 2965 ut_params->cipher_xform.cipher.key.length = c_key_len; 2966 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2967 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2968 2969 debug_hexdump(stdout, "Auth key:", a_key, a_key_len); 2970 debug_hexdump(stdout, "Cipher key:", c_key, c_key_len); 2971 2972 /* Create Crypto session*/ 2973 if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 2974 ut_params->auth_xform.next = NULL; 2975 ut_params->cipher_xform.next = &ut_params->auth_xform; 2976 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2977 &ut_params->cipher_xform, ts_params->session_mpool); 2978 } else 2979 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2980 &ut_params->auth_xform, ts_params->session_mpool); 2981 2982 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2983 return TEST_SKIPPED; 2984 2985 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2986 2987 return 0; 2988 } 2989 2990 static int 2991 create_wireless_algo_hash_operation(const uint8_t *auth_tag, 2992 unsigned int auth_tag_len, 2993 const uint8_t *iv, unsigned int iv_len, 2994 unsigned int data_pad_len, 2995 enum rte_crypto_auth_operation op, 2996 unsigned int auth_len, unsigned int auth_offset) 2997 { 2998 struct crypto_testsuite_params *ts_params = &testsuite_params; 2999 3000 struct crypto_unittest_params *ut_params = &unittest_params; 3001 3002 /* Generate Crypto op data structure */ 3003 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3004 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3005 TEST_ASSERT_NOT_NULL(ut_params->op, 3006 "Failed to allocate pktmbuf offload"); 3007 3008 /* Set crypto operation data parameters */ 3009 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 3010 3011 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3012 3013 /* set crypto operation source mbuf */ 3014 sym_op->m_src = ut_params->ibuf; 3015 3016 /* iv */ 3017 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 3018 iv, iv_len); 3019 /* digest */ 3020 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 3021 ut_params->ibuf, auth_tag_len); 3022 3023 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 3024 "no room to append auth tag"); 3025 ut_params->digest = sym_op->auth.digest.data; 3026 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3027 ut_params->ibuf, data_pad_len); 3028 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 3029 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3030 else 3031 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3032 3033 debug_hexdump(stdout, "digest:", 3034 sym_op->auth.digest.data, 3035 auth_tag_len); 3036 3037 sym_op->auth.data.length = auth_len; 3038 sym_op->auth.data.offset = auth_offset; 3039 3040 return 0; 3041 } 3042 3043 static int 3044 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata, 3045 enum rte_crypto_auth_operation op) 3046 { 3047 struct crypto_testsuite_params *ts_params = &testsuite_params; 3048 struct crypto_unittest_params *ut_params = &unittest_params; 3049 3050 const uint8_t *auth_tag = tdata->digest.data; 3051 const unsigned int auth_tag_len = tdata->digest.len; 3052 unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len); 3053 unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3054 3055 const uint8_t *cipher_iv = tdata->cipher_iv.data; 3056 const uint8_t cipher_iv_len = tdata->cipher_iv.len; 3057 const uint8_t *auth_iv = tdata->auth_iv.data; 3058 const uint8_t auth_iv_len = tdata->auth_iv.len; 3059 const unsigned int cipher_len = tdata->validCipherLenInBits.len; 3060 const unsigned int auth_len = tdata->validAuthLenInBits.len; 3061 3062 /* Generate Crypto op data structure */ 3063 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3064 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3065 TEST_ASSERT_NOT_NULL(ut_params->op, 3066 "Failed to allocate pktmbuf offload"); 3067 /* Set crypto operation data parameters */ 3068 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 3069 3070 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3071 3072 /* set crypto operation source mbuf */ 3073 sym_op->m_src = ut_params->ibuf; 3074 3075 /* digest */ 3076 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 3077 ut_params->ibuf, auth_tag_len); 3078 3079 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 3080 "no room to append auth tag"); 3081 ut_params->digest = sym_op->auth.digest.data; 3082 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3083 ut_params->ibuf, data_pad_len); 3084 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 3085 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3086 else 3087 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3088 3089 debug_hexdump(stdout, "digest:", 3090 sym_op->auth.digest.data, 3091 auth_tag_len); 3092 3093 /* Copy cipher and auth IVs at the end of the crypto operation */ 3094 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 3095 IV_OFFSET); 3096 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 3097 iv_ptr += cipher_iv_len; 3098 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 3099 3100 sym_op->cipher.data.length = cipher_len; 3101 sym_op->cipher.data.offset = 0; 3102 sym_op->auth.data.length = auth_len; 3103 sym_op->auth.data.offset = 0; 3104 3105 return 0; 3106 } 3107 3108 static int 3109 create_zuc_cipher_hash_generate_operation( 3110 const struct wireless_test_data *tdata) 3111 { 3112 return create_wireless_cipher_hash_operation(tdata, 3113 RTE_CRYPTO_AUTH_OP_GENERATE); 3114 } 3115 3116 static int 3117 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag, 3118 const unsigned auth_tag_len, 3119 const uint8_t *auth_iv, uint8_t auth_iv_len, 3120 unsigned data_pad_len, 3121 enum rte_crypto_auth_operation op, 3122 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 3123 const unsigned cipher_len, const unsigned cipher_offset, 3124 const unsigned auth_len, const unsigned auth_offset) 3125 { 3126 struct crypto_testsuite_params *ts_params = &testsuite_params; 3127 struct crypto_unittest_params *ut_params = &unittest_params; 3128 3129 enum rte_crypto_cipher_algorithm cipher_algo = 3130 ut_params->cipher_xform.cipher.algo; 3131 enum rte_crypto_auth_algorithm auth_algo = 3132 ut_params->auth_xform.auth.algo; 3133 3134 /* Generate Crypto op data structure */ 3135 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3136 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3137 TEST_ASSERT_NOT_NULL(ut_params->op, 3138 "Failed to allocate pktmbuf offload"); 3139 /* Set crypto operation data parameters */ 3140 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 3141 3142 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3143 3144 /* set crypto operation source mbuf */ 3145 sym_op->m_src = ut_params->ibuf; 3146 3147 /* digest */ 3148 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 3149 ut_params->ibuf, auth_tag_len); 3150 3151 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 3152 "no room to append auth tag"); 3153 ut_params->digest = sym_op->auth.digest.data; 3154 3155 if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) { 3156 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3157 ut_params->ibuf, data_pad_len); 3158 } else { 3159 struct rte_mbuf *m = ut_params->ibuf; 3160 unsigned int offset = data_pad_len; 3161 3162 while (offset > m->data_len && m->next != NULL) { 3163 offset -= m->data_len; 3164 m = m->next; 3165 } 3166 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3167 m, offset); 3168 } 3169 3170 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 3171 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3172 else 3173 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3174 3175 debug_hexdump(stdout, "digest:", 3176 sym_op->auth.digest.data, 3177 auth_tag_len); 3178 3179 /* Copy cipher and auth IVs at the end of the crypto operation */ 3180 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 3181 IV_OFFSET); 3182 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 3183 iv_ptr += cipher_iv_len; 3184 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 3185 3186 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 3187 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 3188 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 3189 sym_op->cipher.data.length = cipher_len; 3190 sym_op->cipher.data.offset = cipher_offset; 3191 } else { 3192 sym_op->cipher.data.length = cipher_len >> 3; 3193 sym_op->cipher.data.offset = cipher_offset >> 3; 3194 } 3195 3196 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 3197 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 3198 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 3199 sym_op->auth.data.length = auth_len; 3200 sym_op->auth.data.offset = auth_offset; 3201 } else { 3202 sym_op->auth.data.length = auth_len >> 3; 3203 sym_op->auth.data.offset = auth_offset >> 3; 3204 } 3205 3206 return 0; 3207 } 3208 3209 static int 3210 create_wireless_algo_auth_cipher_operation( 3211 const uint8_t *auth_tag, unsigned int auth_tag_len, 3212 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 3213 const uint8_t *auth_iv, uint8_t auth_iv_len, 3214 unsigned int data_pad_len, 3215 unsigned int cipher_len, unsigned int cipher_offset, 3216 unsigned int auth_len, unsigned int auth_offset, 3217 uint8_t op_mode, uint8_t do_sgl, uint8_t verify) 3218 { 3219 struct crypto_testsuite_params *ts_params = &testsuite_params; 3220 struct crypto_unittest_params *ut_params = &unittest_params; 3221 3222 enum rte_crypto_cipher_algorithm cipher_algo = 3223 ut_params->cipher_xform.cipher.algo; 3224 enum rte_crypto_auth_algorithm auth_algo = 3225 ut_params->auth_xform.auth.algo; 3226 3227 /* Generate Crypto op data structure */ 3228 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3229 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3230 TEST_ASSERT_NOT_NULL(ut_params->op, 3231 "Failed to allocate pktmbuf offload"); 3232 3233 /* Set crypto operation data parameters */ 3234 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 3235 3236 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3237 3238 /* set crypto operation mbufs */ 3239 sym_op->m_src = ut_params->ibuf; 3240 if (op_mode == OUT_OF_PLACE) 3241 sym_op->m_dst = ut_params->obuf; 3242 3243 /* digest */ 3244 if (!do_sgl) { 3245 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset( 3246 (op_mode == IN_PLACE ? 3247 ut_params->ibuf : ut_params->obuf), 3248 uint8_t *, data_pad_len); 3249 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3250 (op_mode == IN_PLACE ? 3251 ut_params->ibuf : ut_params->obuf), 3252 data_pad_len); 3253 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3254 } else { 3255 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3); 3256 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ? 3257 sym_op->m_src : sym_op->m_dst); 3258 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) { 3259 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 3260 sgl_buf = sgl_buf->next; 3261 } 3262 3263 /* The last segment should be large enough to hold full digest */ 3264 if (sgl_buf->data_len < auth_tag_len) { 3265 rte_pktmbuf_free(sgl_buf->next); 3266 sgl_buf->next = NULL; 3267 TEST_ASSERT_NOT_NULL(rte_pktmbuf_append(sgl_buf, 3268 auth_tag_len - sgl_buf->data_len), 3269 "No room to append auth tag"); 3270 } 3271 3272 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf, 3273 uint8_t *, remaining_off); 3274 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf, 3275 remaining_off); 3276 memset(sym_op->auth.digest.data, 0, remaining_off); 3277 while (sgl_buf->next != NULL) { 3278 memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *), 3279 0, rte_pktmbuf_data_len(sgl_buf)); 3280 sgl_buf = sgl_buf->next; 3281 } 3282 } 3283 3284 /* Copy digest for the verification */ 3285 if (verify) 3286 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3287 3288 /* Copy cipher and auth IVs at the end of the crypto operation */ 3289 uint8_t *iv_ptr = rte_crypto_op_ctod_offset( 3290 ut_params->op, uint8_t *, IV_OFFSET); 3291 3292 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 3293 iv_ptr += cipher_iv_len; 3294 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 3295 3296 /* Only copy over the offset data needed from src to dst in OOP, 3297 * if the auth and cipher offsets are not aligned 3298 */ 3299 if (op_mode == OUT_OF_PLACE) { 3300 if (cipher_offset > auth_offset) 3301 rte_memcpy( 3302 rte_pktmbuf_mtod_offset( 3303 sym_op->m_dst, 3304 uint8_t *, auth_offset >> 3), 3305 rte_pktmbuf_mtod_offset( 3306 sym_op->m_src, 3307 uint8_t *, auth_offset >> 3), 3308 ((cipher_offset >> 3) - (auth_offset >> 3))); 3309 } 3310 3311 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 3312 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 3313 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 3314 sym_op->cipher.data.length = cipher_len; 3315 sym_op->cipher.data.offset = cipher_offset; 3316 } else { 3317 sym_op->cipher.data.length = cipher_len >> 3; 3318 sym_op->cipher.data.offset = cipher_offset >> 3; 3319 } 3320 3321 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 3322 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 3323 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 3324 sym_op->auth.data.length = auth_len; 3325 sym_op->auth.data.offset = auth_offset; 3326 } else { 3327 sym_op->auth.data.length = auth_len >> 3; 3328 sym_op->auth.data.offset = auth_offset >> 3; 3329 } 3330 3331 return 0; 3332 } 3333 3334 static int 3335 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) 3336 { 3337 struct crypto_testsuite_params *ts_params = &testsuite_params; 3338 struct crypto_unittest_params *ut_params = &unittest_params; 3339 3340 int retval; 3341 unsigned plaintext_pad_len; 3342 unsigned plaintext_len; 3343 uint8_t *plaintext; 3344 struct rte_cryptodev_info dev_info; 3345 3346 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3347 uint64_t feat_flags = dev_info.feature_flags; 3348 3349 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3350 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3351 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3352 return TEST_SKIPPED; 3353 } 3354 3355 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3356 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3357 printf("Device doesn't support RAW data-path APIs.\n"); 3358 return TEST_SKIPPED; 3359 } 3360 3361 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3362 return TEST_SKIPPED; 3363 3364 /* Verify the capabilities */ 3365 struct rte_cryptodev_sym_capability_idx cap_idx; 3366 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3367 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3368 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3369 &cap_idx) == NULL) 3370 return TEST_SKIPPED; 3371 3372 /* Create SNOW 3G session */ 3373 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3374 tdata->key.data, tdata->key.len, 3375 tdata->auth_iv.len, tdata->digest.len, 3376 RTE_CRYPTO_AUTH_OP_GENERATE, 3377 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3378 if (retval < 0) 3379 return retval; 3380 3381 /* alloc mbuf and set payload */ 3382 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3383 3384 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3385 rte_pktmbuf_tailroom(ut_params->ibuf)); 3386 3387 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3388 /* Append data which is padded to a multiple of */ 3389 /* the algorithms block size */ 3390 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3391 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3392 plaintext_pad_len); 3393 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3394 3395 /* Create SNOW 3G operation */ 3396 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3397 tdata->auth_iv.data, tdata->auth_iv.len, 3398 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3399 tdata->validAuthLenInBits.len, 3400 0); 3401 if (retval < 0) 3402 return retval; 3403 3404 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3405 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 3406 0); 3407 if (retval != TEST_SUCCESS) 3408 return retval; 3409 } else 3410 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3411 ut_params->op); 3412 ut_params->obuf = ut_params->op->sym->m_src; 3413 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3414 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 3415 uint8_t *, 3416 plaintext_pad_len); 3417 3418 /* Validate obuf */ 3419 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3420 ut_params->digest, 3421 tdata->digest.data, 3422 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 3423 "SNOW 3G Generated auth tag not as expected"); 3424 3425 return 0; 3426 } 3427 3428 static int 3429 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) 3430 { 3431 struct crypto_testsuite_params *ts_params = &testsuite_params; 3432 struct crypto_unittest_params *ut_params = &unittest_params; 3433 3434 int retval; 3435 unsigned plaintext_pad_len; 3436 unsigned plaintext_len; 3437 uint8_t *plaintext; 3438 struct rte_cryptodev_info dev_info; 3439 3440 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3441 uint64_t feat_flags = dev_info.feature_flags; 3442 3443 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3444 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3445 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3446 return TEST_SKIPPED; 3447 } 3448 3449 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3450 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3451 printf("Device doesn't support RAW data-path APIs.\n"); 3452 return TEST_SKIPPED; 3453 } 3454 3455 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3456 return TEST_SKIPPED; 3457 3458 /* Verify the capabilities */ 3459 struct rte_cryptodev_sym_capability_idx cap_idx; 3460 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3461 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3462 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3463 &cap_idx) == NULL) 3464 return TEST_SKIPPED; 3465 3466 /* Create SNOW 3G session */ 3467 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3468 tdata->key.data, tdata->key.len, 3469 tdata->auth_iv.len, tdata->digest.len, 3470 RTE_CRYPTO_AUTH_OP_VERIFY, 3471 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3472 if (retval < 0) 3473 return retval; 3474 /* alloc mbuf and set payload */ 3475 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3476 3477 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3478 rte_pktmbuf_tailroom(ut_params->ibuf)); 3479 3480 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3481 /* Append data which is padded to a multiple of */ 3482 /* the algorithms block size */ 3483 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3484 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3485 plaintext_pad_len); 3486 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3487 3488 /* Create SNOW 3G operation */ 3489 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3490 tdata->digest.len, 3491 tdata->auth_iv.data, tdata->auth_iv.len, 3492 plaintext_pad_len, 3493 RTE_CRYPTO_AUTH_OP_VERIFY, 3494 tdata->validAuthLenInBits.len, 3495 0); 3496 if (retval < 0) 3497 return retval; 3498 3499 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3500 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 3501 0); 3502 if (retval != TEST_SUCCESS) 3503 return retval; 3504 } else 3505 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3506 ut_params->op); 3507 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3508 ut_params->obuf = ut_params->op->sym->m_src; 3509 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 3510 uint8_t *, 3511 plaintext_pad_len); 3512 3513 /* Validate obuf */ 3514 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3515 return 0; 3516 else 3517 return -1; 3518 3519 return 0; 3520 } 3521 3522 static int 3523 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata) 3524 { 3525 struct crypto_testsuite_params *ts_params = &testsuite_params; 3526 struct crypto_unittest_params *ut_params = &unittest_params; 3527 3528 int retval; 3529 unsigned plaintext_pad_len; 3530 unsigned plaintext_len; 3531 uint8_t *plaintext; 3532 struct rte_cryptodev_info dev_info; 3533 3534 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3535 uint64_t feat_flags = dev_info.feature_flags; 3536 3537 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3538 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3539 printf("Device doesn't support RAW data-path APIs.\n"); 3540 return TEST_SKIPPED; 3541 } 3542 3543 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3544 return TEST_SKIPPED; 3545 3546 /* Verify the capabilities */ 3547 struct rte_cryptodev_sym_capability_idx cap_idx; 3548 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3549 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3550 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3551 &cap_idx) == NULL) 3552 return TEST_SKIPPED; 3553 3554 /* Create KASUMI session */ 3555 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3556 tdata->key.data, tdata->key.len, 3557 0, tdata->digest.len, 3558 RTE_CRYPTO_AUTH_OP_GENERATE, 3559 RTE_CRYPTO_AUTH_KASUMI_F9); 3560 if (retval < 0) 3561 return retval; 3562 3563 /* alloc mbuf and set payload */ 3564 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3565 3566 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3567 rte_pktmbuf_tailroom(ut_params->ibuf)); 3568 3569 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3570 /* Append data which is padded to a multiple of */ 3571 /* the algorithms block size */ 3572 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3573 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3574 plaintext_pad_len); 3575 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3576 3577 /* Create KASUMI operation */ 3578 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3579 NULL, 0, 3580 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3581 tdata->plaintext.len, 3582 0); 3583 if (retval < 0) 3584 return retval; 3585 3586 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3587 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 3588 ut_params->op); 3589 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3590 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 3591 0); 3592 if (retval != TEST_SUCCESS) 3593 return retval; 3594 } else 3595 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3596 ut_params->op); 3597 3598 ut_params->obuf = ut_params->op->sym->m_src; 3599 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3600 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 3601 uint8_t *, 3602 plaintext_pad_len); 3603 3604 /* Validate obuf */ 3605 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3606 ut_params->digest, 3607 tdata->digest.data, 3608 DIGEST_BYTE_LENGTH_KASUMI_F9, 3609 "KASUMI Generated auth tag not as expected"); 3610 3611 return 0; 3612 } 3613 3614 static int 3615 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata) 3616 { 3617 struct crypto_testsuite_params *ts_params = &testsuite_params; 3618 struct crypto_unittest_params *ut_params = &unittest_params; 3619 3620 int retval; 3621 unsigned plaintext_pad_len; 3622 unsigned plaintext_len; 3623 uint8_t *plaintext; 3624 struct rte_cryptodev_info dev_info; 3625 3626 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3627 uint64_t feat_flags = dev_info.feature_flags; 3628 3629 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3630 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3631 printf("Device doesn't support RAW data-path APIs.\n"); 3632 return TEST_SKIPPED; 3633 } 3634 3635 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3636 return TEST_SKIPPED; 3637 3638 /* Verify the capabilities */ 3639 struct rte_cryptodev_sym_capability_idx cap_idx; 3640 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3641 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3642 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3643 &cap_idx) == NULL) 3644 return TEST_SKIPPED; 3645 3646 /* Create KASUMI session */ 3647 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3648 tdata->key.data, tdata->key.len, 3649 0, tdata->digest.len, 3650 RTE_CRYPTO_AUTH_OP_VERIFY, 3651 RTE_CRYPTO_AUTH_KASUMI_F9); 3652 if (retval < 0) 3653 return retval; 3654 /* alloc mbuf and set payload */ 3655 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3656 3657 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3658 rte_pktmbuf_tailroom(ut_params->ibuf)); 3659 3660 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3661 /* Append data which is padded to a multiple */ 3662 /* of the algorithms block size */ 3663 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3664 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3665 plaintext_pad_len); 3666 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3667 3668 /* Create KASUMI operation */ 3669 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3670 tdata->digest.len, 3671 NULL, 0, 3672 plaintext_pad_len, 3673 RTE_CRYPTO_AUTH_OP_VERIFY, 3674 tdata->plaintext.len, 3675 0); 3676 if (retval < 0) 3677 return retval; 3678 3679 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3680 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 3681 0); 3682 if (retval != TEST_SUCCESS) 3683 return retval; 3684 } else 3685 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3686 ut_params->op); 3687 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3688 ut_params->obuf = ut_params->op->sym->m_src; 3689 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 3690 uint8_t *, 3691 plaintext_pad_len); 3692 3693 /* Validate obuf */ 3694 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3695 return 0; 3696 else 3697 return -1; 3698 3699 return 0; 3700 } 3701 3702 static int 3703 test_snow3g_hash_generate_test_case_1(void) 3704 { 3705 return test_snow3g_authentication(&snow3g_hash_test_case_1); 3706 } 3707 3708 static int 3709 test_snow3g_hash_generate_test_case_2(void) 3710 { 3711 return test_snow3g_authentication(&snow3g_hash_test_case_2); 3712 } 3713 3714 static int 3715 test_snow3g_hash_generate_test_case_3(void) 3716 { 3717 return test_snow3g_authentication(&snow3g_hash_test_case_3); 3718 } 3719 3720 static int 3721 test_snow3g_hash_generate_test_case_4(void) 3722 { 3723 return test_snow3g_authentication(&snow3g_hash_test_case_4); 3724 } 3725 3726 static int 3727 test_snow3g_hash_generate_test_case_5(void) 3728 { 3729 return test_snow3g_authentication(&snow3g_hash_test_case_5); 3730 } 3731 3732 static int 3733 test_snow3g_hash_generate_test_case_6(void) 3734 { 3735 return test_snow3g_authentication(&snow3g_hash_test_case_6); 3736 } 3737 3738 static int 3739 test_snow3g_hash_verify_test_case_1(void) 3740 { 3741 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1); 3742 3743 } 3744 3745 static int 3746 test_snow3g_hash_verify_test_case_2(void) 3747 { 3748 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2); 3749 } 3750 3751 static int 3752 test_snow3g_hash_verify_test_case_3(void) 3753 { 3754 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3); 3755 } 3756 3757 static int 3758 test_snow3g_hash_verify_test_case_4(void) 3759 { 3760 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4); 3761 } 3762 3763 static int 3764 test_snow3g_hash_verify_test_case_5(void) 3765 { 3766 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5); 3767 } 3768 3769 static int 3770 test_snow3g_hash_verify_test_case_6(void) 3771 { 3772 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6); 3773 } 3774 3775 static int 3776 test_kasumi_hash_generate_test_case_1(void) 3777 { 3778 return test_kasumi_authentication(&kasumi_hash_test_case_1); 3779 } 3780 3781 static int 3782 test_kasumi_hash_generate_test_case_2(void) 3783 { 3784 return test_kasumi_authentication(&kasumi_hash_test_case_2); 3785 } 3786 3787 static int 3788 test_kasumi_hash_generate_test_case_3(void) 3789 { 3790 return test_kasumi_authentication(&kasumi_hash_test_case_3); 3791 } 3792 3793 static int 3794 test_kasumi_hash_generate_test_case_4(void) 3795 { 3796 return test_kasumi_authentication(&kasumi_hash_test_case_4); 3797 } 3798 3799 static int 3800 test_kasumi_hash_generate_test_case_5(void) 3801 { 3802 return test_kasumi_authentication(&kasumi_hash_test_case_5); 3803 } 3804 3805 static int 3806 test_kasumi_hash_generate_test_case_6(void) 3807 { 3808 return test_kasumi_authentication(&kasumi_hash_test_case_6); 3809 } 3810 3811 static int 3812 test_kasumi_hash_verify_test_case_1(void) 3813 { 3814 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1); 3815 } 3816 3817 static int 3818 test_kasumi_hash_verify_test_case_2(void) 3819 { 3820 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2); 3821 } 3822 3823 static int 3824 test_kasumi_hash_verify_test_case_3(void) 3825 { 3826 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3); 3827 } 3828 3829 static int 3830 test_kasumi_hash_verify_test_case_4(void) 3831 { 3832 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4); 3833 } 3834 3835 static int 3836 test_kasumi_hash_verify_test_case_5(void) 3837 { 3838 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5); 3839 } 3840 3841 static int 3842 test_kasumi_encryption(const struct kasumi_test_data *tdata) 3843 { 3844 struct crypto_testsuite_params *ts_params = &testsuite_params; 3845 struct crypto_unittest_params *ut_params = &unittest_params; 3846 3847 int retval; 3848 uint8_t *plaintext, *ciphertext; 3849 unsigned plaintext_pad_len; 3850 unsigned plaintext_len; 3851 struct rte_cryptodev_info dev_info; 3852 3853 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3854 uint64_t feat_flags = dev_info.feature_flags; 3855 3856 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3857 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3858 printf("Device doesn't support RAW data-path APIs.\n"); 3859 return TEST_SKIPPED; 3860 } 3861 3862 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3863 return TEST_SKIPPED; 3864 3865 /* Verify the capabilities */ 3866 struct rte_cryptodev_sym_capability_idx cap_idx; 3867 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3868 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3869 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3870 &cap_idx) == NULL) 3871 return TEST_SKIPPED; 3872 3873 /* Create KASUMI session */ 3874 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3875 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3876 RTE_CRYPTO_CIPHER_KASUMI_F8, 3877 tdata->key.data, tdata->key.len, 3878 tdata->cipher_iv.len); 3879 if (retval < 0) 3880 return retval; 3881 3882 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3883 3884 /* Clear mbuf payload */ 3885 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3886 rte_pktmbuf_tailroom(ut_params->ibuf)); 3887 3888 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3889 /* Append data which is padded to a multiple */ 3890 /* of the algorithms block size */ 3891 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3892 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3893 plaintext_pad_len); 3894 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3895 3896 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3897 3898 /* Create KASUMI operation */ 3899 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3900 tdata->cipher_iv.len, 3901 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3902 tdata->validCipherOffsetInBits.len); 3903 if (retval < 0) 3904 return retval; 3905 3906 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3907 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 3908 tdata->cipher_iv.len); 3909 if (retval != TEST_SUCCESS) 3910 return retval; 3911 } else 3912 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3913 ut_params->op); 3914 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3915 3916 ut_params->obuf = ut_params->op->sym->m_dst; 3917 if (ut_params->obuf) 3918 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3919 else 3920 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3921 3922 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3923 3924 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3925 (tdata->validCipherOffsetInBits.len >> 3); 3926 /* Validate obuf */ 3927 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3928 ciphertext, 3929 reference_ciphertext, 3930 tdata->validCipherLenInBits.len, 3931 "KASUMI Ciphertext data not as expected"); 3932 return 0; 3933 } 3934 3935 static int 3936 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata) 3937 { 3938 struct crypto_testsuite_params *ts_params = &testsuite_params; 3939 struct crypto_unittest_params *ut_params = &unittest_params; 3940 3941 int retval; 3942 3943 unsigned int plaintext_pad_len; 3944 unsigned int plaintext_len; 3945 3946 uint8_t buffer[10000]; 3947 const uint8_t *ciphertext; 3948 3949 struct rte_cryptodev_info dev_info; 3950 3951 /* Verify the capabilities */ 3952 struct rte_cryptodev_sym_capability_idx cap_idx; 3953 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3954 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3955 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3956 &cap_idx) == NULL) 3957 return TEST_SKIPPED; 3958 3959 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3960 3961 uint64_t feat_flags = dev_info.feature_flags; 3962 3963 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 3964 printf("Device doesn't support in-place scatter-gather. " 3965 "Test Skipped.\n"); 3966 return TEST_SKIPPED; 3967 } 3968 3969 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3970 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3971 printf("Device doesn't support RAW data-path APIs.\n"); 3972 return TEST_SKIPPED; 3973 } 3974 3975 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3976 return TEST_SKIPPED; 3977 3978 /* Create KASUMI session */ 3979 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3980 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3981 RTE_CRYPTO_CIPHER_KASUMI_F8, 3982 tdata->key.data, tdata->key.len, 3983 tdata->cipher_iv.len); 3984 if (retval < 0) 3985 return retval; 3986 3987 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3988 3989 3990 /* Append data which is padded to a multiple */ 3991 /* of the algorithms block size */ 3992 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3993 3994 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3995 plaintext_pad_len, 10, 0); 3996 3997 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3998 3999 /* Create KASUMI operation */ 4000 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4001 tdata->cipher_iv.len, 4002 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4003 tdata->validCipherOffsetInBits.len); 4004 if (retval < 0) 4005 return retval; 4006 4007 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4008 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4009 tdata->cipher_iv.len); 4010 if (retval != TEST_SUCCESS) 4011 return retval; 4012 } else 4013 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4014 ut_params->op); 4015 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4016 4017 ut_params->obuf = ut_params->op->sym->m_dst; 4018 4019 if (ut_params->obuf) 4020 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4021 plaintext_len, buffer); 4022 else 4023 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 4024 tdata->validCipherOffsetInBits.len >> 3, 4025 plaintext_len, buffer); 4026 4027 /* Validate obuf */ 4028 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4029 4030 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 4031 (tdata->validCipherOffsetInBits.len >> 3); 4032 /* Validate obuf */ 4033 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4034 ciphertext, 4035 reference_ciphertext, 4036 tdata->validCipherLenInBits.len, 4037 "KASUMI Ciphertext data not as expected"); 4038 return 0; 4039 } 4040 4041 static int 4042 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata) 4043 { 4044 struct crypto_testsuite_params *ts_params = &testsuite_params; 4045 struct crypto_unittest_params *ut_params = &unittest_params; 4046 4047 int retval; 4048 uint8_t *plaintext, *ciphertext; 4049 unsigned plaintext_pad_len; 4050 unsigned plaintext_len; 4051 4052 /* Verify the capabilities */ 4053 struct rte_cryptodev_sym_capability_idx cap_idx; 4054 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4055 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4056 /* Data-path service does not support OOP */ 4057 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4058 &cap_idx) == NULL) 4059 return TEST_SKIPPED; 4060 4061 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4062 return TEST_SKIPPED; 4063 4064 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4065 return TEST_SKIPPED; 4066 4067 /* Create KASUMI session */ 4068 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4069 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4070 RTE_CRYPTO_CIPHER_KASUMI_F8, 4071 tdata->key.data, tdata->key.len, 4072 tdata->cipher_iv.len); 4073 if (retval < 0) 4074 return retval; 4075 4076 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4077 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4078 4079 /* Clear mbuf payload */ 4080 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4081 rte_pktmbuf_tailroom(ut_params->ibuf)); 4082 4083 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4084 /* Append data which is padded to a multiple */ 4085 /* of the algorithms block size */ 4086 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 4087 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4088 plaintext_pad_len); 4089 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4090 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4091 4092 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4093 4094 /* Create KASUMI operation */ 4095 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4096 tdata->cipher_iv.len, 4097 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4098 tdata->validCipherOffsetInBits.len); 4099 if (retval < 0) 4100 return retval; 4101 4102 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4103 ut_params->op); 4104 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4105 4106 ut_params->obuf = ut_params->op->sym->m_dst; 4107 if (ut_params->obuf) 4108 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4109 else 4110 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 4111 4112 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4113 4114 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 4115 (tdata->validCipherOffsetInBits.len >> 3); 4116 /* Validate obuf */ 4117 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4118 ciphertext, 4119 reference_ciphertext, 4120 tdata->validCipherLenInBits.len, 4121 "KASUMI Ciphertext data not as expected"); 4122 return 0; 4123 } 4124 4125 static int 4126 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata) 4127 { 4128 struct crypto_testsuite_params *ts_params = &testsuite_params; 4129 struct crypto_unittest_params *ut_params = &unittest_params; 4130 4131 int retval; 4132 unsigned int plaintext_pad_len; 4133 unsigned int plaintext_len; 4134 4135 const uint8_t *ciphertext; 4136 uint8_t buffer[2048]; 4137 4138 struct rte_cryptodev_info dev_info; 4139 4140 /* Verify the capabilities */ 4141 struct rte_cryptodev_sym_capability_idx cap_idx; 4142 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4143 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4144 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4145 &cap_idx) == NULL) 4146 return TEST_SKIPPED; 4147 4148 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4149 return TEST_SKIPPED; 4150 4151 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4152 return TEST_SKIPPED; 4153 4154 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4155 4156 uint64_t feat_flags = dev_info.feature_flags; 4157 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 4158 printf("Device doesn't support out-of-place scatter-gather " 4159 "in both input and output mbufs. " 4160 "Test Skipped.\n"); 4161 return TEST_SKIPPED; 4162 } 4163 4164 /* Create KASUMI session */ 4165 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4166 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4167 RTE_CRYPTO_CIPHER_KASUMI_F8, 4168 tdata->key.data, tdata->key.len, 4169 tdata->cipher_iv.len); 4170 if (retval < 0) 4171 return retval; 4172 4173 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4174 /* Append data which is padded to a multiple */ 4175 /* of the algorithms block size */ 4176 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 4177 4178 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4179 plaintext_pad_len, 10, 0); 4180 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4181 plaintext_pad_len, 3, 0); 4182 4183 /* Append data which is padded to a multiple */ 4184 /* of the algorithms block size */ 4185 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 4186 4187 /* Create KASUMI operation */ 4188 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4189 tdata->cipher_iv.len, 4190 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4191 tdata->validCipherOffsetInBits.len); 4192 if (retval < 0) 4193 return retval; 4194 4195 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4196 ut_params->op); 4197 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4198 4199 ut_params->obuf = ut_params->op->sym->m_dst; 4200 if (ut_params->obuf) 4201 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4202 plaintext_pad_len, buffer); 4203 else 4204 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 4205 tdata->validCipherOffsetInBits.len >> 3, 4206 plaintext_pad_len, buffer); 4207 4208 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 4209 (tdata->validCipherOffsetInBits.len >> 3); 4210 /* Validate obuf */ 4211 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4212 ciphertext, 4213 reference_ciphertext, 4214 tdata->validCipherLenInBits.len, 4215 "KASUMI Ciphertext data not as expected"); 4216 return 0; 4217 } 4218 4219 4220 static int 4221 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata) 4222 { 4223 struct crypto_testsuite_params *ts_params = &testsuite_params; 4224 struct crypto_unittest_params *ut_params = &unittest_params; 4225 4226 int retval; 4227 uint8_t *ciphertext, *plaintext; 4228 unsigned ciphertext_pad_len; 4229 unsigned ciphertext_len; 4230 4231 /* Verify the capabilities */ 4232 struct rte_cryptodev_sym_capability_idx cap_idx; 4233 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4234 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4235 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4236 &cap_idx) == NULL) 4237 return TEST_SKIPPED; 4238 4239 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4240 return TEST_SKIPPED; 4241 4242 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4243 return TEST_SKIPPED; 4244 4245 /* Create KASUMI session */ 4246 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4247 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4248 RTE_CRYPTO_CIPHER_KASUMI_F8, 4249 tdata->key.data, tdata->key.len, 4250 tdata->cipher_iv.len); 4251 if (retval < 0) 4252 return retval; 4253 4254 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4255 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4256 4257 /* Clear mbuf payload */ 4258 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4259 rte_pktmbuf_tailroom(ut_params->ibuf)); 4260 4261 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4262 /* Append data which is padded to a multiple */ 4263 /* of the algorithms block size */ 4264 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4265 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4266 ciphertext_pad_len); 4267 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4268 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4269 4270 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4271 4272 /* Create KASUMI operation */ 4273 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4274 tdata->cipher_iv.len, 4275 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4276 tdata->validCipherOffsetInBits.len); 4277 if (retval < 0) 4278 return retval; 4279 4280 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4281 ut_params->op); 4282 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4283 4284 ut_params->obuf = ut_params->op->sym->m_dst; 4285 if (ut_params->obuf) 4286 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4287 else 4288 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4289 4290 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4291 4292 const uint8_t *reference_plaintext = tdata->plaintext.data + 4293 (tdata->validCipherOffsetInBits.len >> 3); 4294 /* Validate obuf */ 4295 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4296 plaintext, 4297 reference_plaintext, 4298 tdata->validCipherLenInBits.len, 4299 "KASUMI Plaintext data not as expected"); 4300 return 0; 4301 } 4302 4303 static int 4304 test_kasumi_decryption(const struct kasumi_test_data *tdata) 4305 { 4306 struct crypto_testsuite_params *ts_params = &testsuite_params; 4307 struct crypto_unittest_params *ut_params = &unittest_params; 4308 4309 int retval; 4310 uint8_t *ciphertext, *plaintext; 4311 unsigned ciphertext_pad_len; 4312 unsigned ciphertext_len; 4313 struct rte_cryptodev_info dev_info; 4314 4315 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4316 uint64_t feat_flags = dev_info.feature_flags; 4317 4318 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4319 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4320 printf("Device doesn't support RAW data-path APIs.\n"); 4321 return TEST_SKIPPED; 4322 } 4323 4324 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4325 return TEST_SKIPPED; 4326 4327 /* Verify the capabilities */ 4328 struct rte_cryptodev_sym_capability_idx cap_idx; 4329 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4330 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4331 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4332 &cap_idx) == NULL) 4333 return TEST_SKIPPED; 4334 4335 /* Create KASUMI session */ 4336 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4337 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4338 RTE_CRYPTO_CIPHER_KASUMI_F8, 4339 tdata->key.data, tdata->key.len, 4340 tdata->cipher_iv.len); 4341 if (retval < 0) 4342 return retval; 4343 4344 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4345 4346 /* Clear mbuf payload */ 4347 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4348 rte_pktmbuf_tailroom(ut_params->ibuf)); 4349 4350 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4351 /* Append data which is padded to a multiple */ 4352 /* of the algorithms block size */ 4353 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4354 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4355 ciphertext_pad_len); 4356 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4357 4358 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4359 4360 /* Create KASUMI operation */ 4361 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4362 tdata->cipher_iv.len, 4363 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4364 tdata->validCipherOffsetInBits.len); 4365 if (retval < 0) 4366 return retval; 4367 4368 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4369 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4370 0); 4371 if (retval != TEST_SUCCESS) 4372 return retval; 4373 } else 4374 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4375 ut_params->op); 4376 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4377 4378 ut_params->obuf = ut_params->op->sym->m_dst; 4379 if (ut_params->obuf) 4380 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4381 else 4382 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4383 4384 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4385 4386 const uint8_t *reference_plaintext = tdata->plaintext.data + 4387 (tdata->validCipherOffsetInBits.len >> 3); 4388 /* Validate obuf */ 4389 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4390 plaintext, 4391 reference_plaintext, 4392 tdata->validCipherLenInBits.len, 4393 "KASUMI Plaintext data not as expected"); 4394 return 0; 4395 } 4396 4397 static int 4398 test_snow3g_encryption(const struct snow3g_test_data *tdata) 4399 { 4400 struct crypto_testsuite_params *ts_params = &testsuite_params; 4401 struct crypto_unittest_params *ut_params = &unittest_params; 4402 4403 int retval; 4404 uint8_t *plaintext, *ciphertext; 4405 unsigned plaintext_pad_len; 4406 unsigned plaintext_len; 4407 struct rte_cryptodev_info dev_info; 4408 4409 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4410 uint64_t feat_flags = dev_info.feature_flags; 4411 4412 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4413 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4414 printf("Device doesn't support RAW data-path APIs.\n"); 4415 return TEST_SKIPPED; 4416 } 4417 4418 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4419 return TEST_SKIPPED; 4420 4421 /* Verify the capabilities */ 4422 struct rte_cryptodev_sym_capability_idx cap_idx; 4423 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4424 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4425 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4426 &cap_idx) == NULL) 4427 return TEST_SKIPPED; 4428 4429 /* Create SNOW 3G session */ 4430 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4431 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4432 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4433 tdata->key.data, tdata->key.len, 4434 tdata->cipher_iv.len); 4435 if (retval < 0) 4436 return retval; 4437 4438 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4439 4440 /* Clear mbuf payload */ 4441 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4442 rte_pktmbuf_tailroom(ut_params->ibuf)); 4443 4444 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4445 /* Append data which is padded to a multiple of */ 4446 /* the algorithms block size */ 4447 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4448 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4449 plaintext_pad_len); 4450 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4451 4452 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4453 4454 /* Create SNOW 3G operation */ 4455 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4456 tdata->cipher_iv.len, 4457 tdata->validCipherLenInBits.len, 4458 0); 4459 if (retval < 0) 4460 return retval; 4461 4462 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4463 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4464 tdata->cipher_iv.len); 4465 if (retval != TEST_SUCCESS) 4466 return retval; 4467 } else 4468 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4469 ut_params->op); 4470 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4471 4472 ut_params->obuf = ut_params->op->sym->m_dst; 4473 if (ut_params->obuf) 4474 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4475 else 4476 ciphertext = plaintext; 4477 4478 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4479 4480 /* Validate obuf */ 4481 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4482 ciphertext, 4483 tdata->ciphertext.data, 4484 tdata->validDataLenInBits.len, 4485 "SNOW 3G Ciphertext data not as expected"); 4486 return 0; 4487 } 4488 4489 4490 static int 4491 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) 4492 { 4493 struct crypto_testsuite_params *ts_params = &testsuite_params; 4494 struct crypto_unittest_params *ut_params = &unittest_params; 4495 uint8_t *plaintext, *ciphertext; 4496 4497 int retval; 4498 unsigned plaintext_pad_len; 4499 unsigned plaintext_len; 4500 struct rte_cryptodev_info dev_info; 4501 4502 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4503 uint64_t feat_flags = dev_info.feature_flags; 4504 4505 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4506 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4507 printf("Device does not support RAW data-path APIs.\n"); 4508 return -ENOTSUP; 4509 } 4510 4511 /* Verify the capabilities */ 4512 struct rte_cryptodev_sym_capability_idx cap_idx; 4513 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4514 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4515 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4516 &cap_idx) == NULL) 4517 return TEST_SKIPPED; 4518 4519 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4520 return TEST_SKIPPED; 4521 4522 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4523 return TEST_SKIPPED; 4524 4525 /* Create SNOW 3G session */ 4526 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4527 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4528 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4529 tdata->key.data, tdata->key.len, 4530 tdata->cipher_iv.len); 4531 if (retval < 0) 4532 return retval; 4533 4534 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4535 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4536 4537 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4538 "Failed to allocate input buffer in mempool"); 4539 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4540 "Failed to allocate output buffer in mempool"); 4541 4542 /* Clear mbuf payload */ 4543 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4544 rte_pktmbuf_tailroom(ut_params->ibuf)); 4545 4546 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4547 /* Append data which is padded to a multiple of */ 4548 /* the algorithms block size */ 4549 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4550 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4551 plaintext_pad_len); 4552 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4553 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4554 4555 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4556 4557 /* Create SNOW 3G operation */ 4558 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4559 tdata->cipher_iv.len, 4560 tdata->validCipherLenInBits.len, 4561 0); 4562 if (retval < 0) 4563 return retval; 4564 4565 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4566 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4567 tdata->cipher_iv.len); 4568 if (retval != TEST_SUCCESS) 4569 return retval; 4570 } else 4571 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4572 ut_params->op); 4573 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4574 4575 ut_params->obuf = ut_params->op->sym->m_dst; 4576 if (ut_params->obuf) 4577 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4578 else 4579 ciphertext = plaintext; 4580 4581 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4582 4583 /* Validate obuf */ 4584 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4585 ciphertext, 4586 tdata->ciphertext.data, 4587 tdata->validDataLenInBits.len, 4588 "SNOW 3G Ciphertext data not as expected"); 4589 return 0; 4590 } 4591 4592 static int 4593 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata, 4594 uint8_t sgl_in, uint8_t sgl_out) 4595 { 4596 struct crypto_testsuite_params *ts_params = &testsuite_params; 4597 struct crypto_unittest_params *ut_params = &unittest_params; 4598 4599 int retval; 4600 unsigned int plaintext_pad_len; 4601 unsigned int plaintext_len; 4602 uint8_t buffer[10000]; 4603 const uint8_t *ciphertext; 4604 4605 struct rte_cryptodev_info dev_info; 4606 4607 /* Verify the capabilities */ 4608 struct rte_cryptodev_sym_capability_idx cap_idx; 4609 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4610 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4611 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4612 &cap_idx) == NULL) 4613 return TEST_SKIPPED; 4614 4615 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4616 return TEST_SKIPPED; 4617 4618 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4619 return TEST_SKIPPED; 4620 4621 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4622 4623 uint64_t feat_flags = dev_info.feature_flags; 4624 4625 if (((sgl_in && sgl_out) && !(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 4626 || ((!sgl_in && sgl_out) && 4627 !(feat_flags & RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 4628 || ((sgl_in && !sgl_out) && 4629 !(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))) { 4630 printf("Device doesn't support out-of-place scatter gather type. " 4631 "Test Skipped.\n"); 4632 return TEST_SKIPPED; 4633 } 4634 4635 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4636 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4637 printf("Device does not support RAW data-path APIs.\n"); 4638 return -ENOTSUP; 4639 } 4640 4641 /* Create SNOW 3G session */ 4642 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4643 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4644 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4645 tdata->key.data, tdata->key.len, 4646 tdata->cipher_iv.len); 4647 if (retval < 0) 4648 return retval; 4649 4650 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4651 /* Append data which is padded to a multiple of */ 4652 /* the algorithms block size */ 4653 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4654 4655 if (sgl_in) 4656 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4657 plaintext_pad_len, 10, 0); 4658 else { 4659 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4660 rte_pktmbuf_append(ut_params->ibuf, plaintext_pad_len); 4661 } 4662 4663 if (sgl_out) 4664 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4665 plaintext_pad_len, 3, 0); 4666 else { 4667 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4668 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4669 } 4670 4671 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4672 "Failed to allocate input buffer in mempool"); 4673 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4674 "Failed to allocate output buffer in mempool"); 4675 4676 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 4677 4678 /* Create SNOW 3G operation */ 4679 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4680 tdata->cipher_iv.len, 4681 tdata->validCipherLenInBits.len, 4682 0); 4683 if (retval < 0) 4684 return retval; 4685 4686 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4687 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4688 tdata->cipher_iv.len); 4689 if (retval != TEST_SUCCESS) 4690 return retval; 4691 } else 4692 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4693 ut_params->op); 4694 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4695 4696 ut_params->obuf = ut_params->op->sym->m_dst; 4697 if (ut_params->obuf) 4698 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4699 plaintext_len, buffer); 4700 else 4701 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4702 plaintext_len, buffer); 4703 4704 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4705 4706 /* Validate obuf */ 4707 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4708 ciphertext, 4709 tdata->ciphertext.data, 4710 tdata->validDataLenInBits.len, 4711 "SNOW 3G Ciphertext data not as expected"); 4712 4713 return 0; 4714 } 4715 4716 /* Shift right a buffer by "offset" bits, "offset" < 8 */ 4717 static void 4718 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) 4719 { 4720 uint8_t curr_byte, prev_byte; 4721 uint32_t length_in_bytes = ceil_byte_length(length + offset); 4722 uint8_t lower_byte_mask = (1 << offset) - 1; 4723 unsigned i; 4724 4725 prev_byte = buffer[0]; 4726 buffer[0] >>= offset; 4727 4728 for (i = 1; i < length_in_bytes; i++) { 4729 curr_byte = buffer[i]; 4730 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | 4731 (curr_byte >> offset); 4732 prev_byte = curr_byte; 4733 } 4734 } 4735 4736 static int 4737 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) 4738 { 4739 struct crypto_testsuite_params *ts_params = &testsuite_params; 4740 struct crypto_unittest_params *ut_params = &unittest_params; 4741 uint8_t *plaintext, *ciphertext; 4742 int retval; 4743 uint32_t plaintext_len; 4744 uint32_t plaintext_pad_len; 4745 uint8_t extra_offset = 4; 4746 uint8_t *expected_ciphertext_shifted; 4747 struct rte_cryptodev_info dev_info; 4748 4749 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4750 uint64_t feat_flags = dev_info.feature_flags; 4751 4752 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4753 ((tdata->validDataLenInBits.len % 8) != 0)) { 4754 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4755 return TEST_SKIPPED; 4756 } 4757 4758 /* Verify the capabilities */ 4759 struct rte_cryptodev_sym_capability_idx cap_idx; 4760 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4761 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4762 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4763 &cap_idx) == NULL) 4764 return TEST_SKIPPED; 4765 4766 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4767 return TEST_SKIPPED; 4768 4769 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4770 return TEST_SKIPPED; 4771 4772 /* Create SNOW 3G session */ 4773 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4774 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4775 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4776 tdata->key.data, tdata->key.len, 4777 tdata->cipher_iv.len); 4778 if (retval < 0) 4779 return retval; 4780 4781 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4782 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4783 4784 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4785 "Failed to allocate input buffer in mempool"); 4786 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4787 "Failed to allocate output buffer in mempool"); 4788 4789 /* Clear mbuf payload */ 4790 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4791 rte_pktmbuf_tailroom(ut_params->ibuf)); 4792 4793 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset); 4794 /* 4795 * Append data which is padded to a 4796 * multiple of the algorithms block size 4797 */ 4798 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4799 4800 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, 4801 plaintext_pad_len); 4802 4803 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4804 4805 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); 4806 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); 4807 4808 #ifdef RTE_APP_TEST_DEBUG 4809 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); 4810 #endif 4811 /* Create SNOW 3G operation */ 4812 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4813 tdata->cipher_iv.len, 4814 tdata->validCipherLenInBits.len, 4815 extra_offset); 4816 if (retval < 0) 4817 return retval; 4818 4819 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4820 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4821 tdata->cipher_iv.len); 4822 if (retval != TEST_SUCCESS) 4823 return retval; 4824 } else 4825 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4826 ut_params->op); 4827 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4828 4829 ut_params->obuf = ut_params->op->sym->m_dst; 4830 if (ut_params->obuf) 4831 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4832 else 4833 ciphertext = plaintext; 4834 4835 #ifdef RTE_APP_TEST_DEBUG 4836 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4837 #endif 4838 4839 expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8); 4840 4841 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, 4842 "failed to reserve memory for ciphertext shifted\n"); 4843 4844 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, 4845 ceil_byte_length(tdata->ciphertext.len)); 4846 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, 4847 extra_offset); 4848 /* Validate obuf */ 4849 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4850 ciphertext, 4851 expected_ciphertext_shifted, 4852 tdata->validDataLenInBits.len, 4853 extra_offset, 4854 "SNOW 3G Ciphertext data not as expected"); 4855 return 0; 4856 } 4857 4858 static int test_snow3g_decryption(const struct snow3g_test_data *tdata) 4859 { 4860 struct crypto_testsuite_params *ts_params = &testsuite_params; 4861 struct crypto_unittest_params *ut_params = &unittest_params; 4862 4863 int retval; 4864 4865 uint8_t *plaintext, *ciphertext; 4866 unsigned ciphertext_pad_len; 4867 unsigned ciphertext_len; 4868 struct rte_cryptodev_info dev_info; 4869 4870 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4871 uint64_t feat_flags = dev_info.feature_flags; 4872 4873 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4874 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4875 printf("Device doesn't support RAW data-path APIs.\n"); 4876 return TEST_SKIPPED; 4877 } 4878 4879 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4880 return TEST_SKIPPED; 4881 4882 /* Verify the capabilities */ 4883 struct rte_cryptodev_sym_capability_idx cap_idx; 4884 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4885 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4886 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4887 &cap_idx) == NULL) 4888 return TEST_SKIPPED; 4889 4890 /* Create SNOW 3G session */ 4891 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4892 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4893 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4894 tdata->key.data, tdata->key.len, 4895 tdata->cipher_iv.len); 4896 if (retval < 0) 4897 return retval; 4898 4899 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4900 4901 /* Clear mbuf payload */ 4902 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4903 rte_pktmbuf_tailroom(ut_params->ibuf)); 4904 4905 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4906 /* Append data which is padded to a multiple of */ 4907 /* the algorithms block size */ 4908 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4909 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4910 ciphertext_pad_len); 4911 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4912 4913 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4914 4915 /* Create SNOW 3G operation */ 4916 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4917 tdata->cipher_iv.len, 4918 tdata->validCipherLenInBits.len, 4919 tdata->cipher.offset_bits); 4920 if (retval < 0) 4921 return retval; 4922 4923 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4924 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4925 tdata->cipher_iv.len); 4926 if (retval != TEST_SUCCESS) 4927 return retval; 4928 } else 4929 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4930 ut_params->op); 4931 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4932 ut_params->obuf = ut_params->op->sym->m_dst; 4933 if (ut_params->obuf) 4934 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4935 else 4936 plaintext = ciphertext; 4937 4938 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4939 4940 /* Validate obuf */ 4941 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4942 tdata->plaintext.data, 4943 tdata->validDataLenInBits.len, 4944 "SNOW 3G Plaintext data not as expected"); 4945 return 0; 4946 } 4947 4948 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) 4949 { 4950 struct crypto_testsuite_params *ts_params = &testsuite_params; 4951 struct crypto_unittest_params *ut_params = &unittest_params; 4952 4953 int retval; 4954 4955 uint8_t *plaintext, *ciphertext; 4956 unsigned ciphertext_pad_len; 4957 unsigned ciphertext_len; 4958 struct rte_cryptodev_info dev_info; 4959 4960 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4961 uint64_t feat_flags = dev_info.feature_flags; 4962 4963 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4964 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4965 printf("Device does not support RAW data-path APIs.\n"); 4966 return -ENOTSUP; 4967 } 4968 /* Verify the capabilities */ 4969 struct rte_cryptodev_sym_capability_idx cap_idx; 4970 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4971 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4972 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4973 &cap_idx) == NULL) 4974 return TEST_SKIPPED; 4975 4976 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4977 return TEST_SKIPPED; 4978 4979 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4980 return TEST_SKIPPED; 4981 4982 /* Create SNOW 3G session */ 4983 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4984 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4985 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4986 tdata->key.data, tdata->key.len, 4987 tdata->cipher_iv.len); 4988 if (retval < 0) 4989 return retval; 4990 4991 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4992 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4993 4994 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4995 "Failed to allocate input buffer"); 4996 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4997 "Failed to allocate output buffer"); 4998 4999 /* Clear mbuf payload */ 5000 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5001 rte_pktmbuf_tailroom(ut_params->ibuf)); 5002 5003 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5004 rte_pktmbuf_tailroom(ut_params->obuf)); 5005 5006 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5007 /* Append data which is padded to a multiple of */ 5008 /* the algorithms block size */ 5009 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5010 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5011 ciphertext_pad_len); 5012 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5013 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5014 5015 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 5016 5017 /* Create SNOW 3G operation */ 5018 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 5019 tdata->cipher_iv.len, 5020 tdata->validCipherLenInBits.len, 5021 0); 5022 if (retval < 0) 5023 return retval; 5024 5025 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5026 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 5027 tdata->cipher_iv.len); 5028 if (retval != TEST_SUCCESS) 5029 return retval; 5030 } else 5031 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5032 ut_params->op); 5033 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5034 ut_params->obuf = ut_params->op->sym->m_dst; 5035 if (ut_params->obuf) 5036 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 5037 else 5038 plaintext = ciphertext; 5039 5040 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 5041 5042 /* Validate obuf */ 5043 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 5044 tdata->plaintext.data, 5045 tdata->validDataLenInBits.len, 5046 "SNOW 3G Plaintext data not as expected"); 5047 return 0; 5048 } 5049 5050 static int 5051 test_zuc_cipher_auth(const struct wireless_test_data *tdata) 5052 { 5053 struct crypto_testsuite_params *ts_params = &testsuite_params; 5054 struct crypto_unittest_params *ut_params = &unittest_params; 5055 5056 int retval; 5057 5058 uint8_t *plaintext, *ciphertext; 5059 unsigned int plaintext_pad_len; 5060 unsigned int plaintext_len; 5061 5062 struct rte_cryptodev_info dev_info; 5063 5064 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5065 uint64_t feat_flags = dev_info.feature_flags; 5066 5067 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 5068 ((tdata->validAuthLenInBits.len % 8 != 0) || 5069 (tdata->validDataLenInBits.len % 8 != 0))) { 5070 printf("Device doesn't support NON-Byte Aligned Data.\n"); 5071 return TEST_SKIPPED; 5072 } 5073 5074 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5075 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5076 printf("Device doesn't support RAW data-path APIs.\n"); 5077 return TEST_SKIPPED; 5078 } 5079 5080 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5081 return TEST_SKIPPED; 5082 5083 /* Check if device supports ZUC EEA3 */ 5084 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 5085 tdata->key.len, tdata->cipher_iv.len) < 0) 5086 return TEST_SKIPPED; 5087 5088 /* Check if device supports ZUC EIA3 */ 5089 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 5090 tdata->key.len, tdata->auth_iv.len, 5091 tdata->digest.len) < 0) 5092 return TEST_SKIPPED; 5093 5094 /* Create ZUC session */ 5095 retval = create_zuc_cipher_auth_encrypt_generate_session( 5096 ts_params->valid_devs[0], 5097 tdata); 5098 if (retval != 0) 5099 return retval; 5100 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5101 5102 /* clear mbuf payload */ 5103 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5104 rte_pktmbuf_tailroom(ut_params->ibuf)); 5105 5106 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5107 /* Append data which is padded to a multiple of */ 5108 /* the algorithms block size */ 5109 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5110 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5111 plaintext_pad_len); 5112 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5113 5114 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5115 5116 /* Create ZUC operation */ 5117 retval = create_zuc_cipher_hash_generate_operation(tdata); 5118 if (retval < 0) 5119 return retval; 5120 5121 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5122 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5123 tdata->cipher_iv.len); 5124 if (retval != TEST_SUCCESS) 5125 return retval; 5126 } else 5127 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5128 ut_params->op); 5129 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5130 ut_params->obuf = ut_params->op->sym->m_src; 5131 if (ut_params->obuf) 5132 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 5133 else 5134 ciphertext = plaintext; 5135 5136 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 5137 /* Validate obuf */ 5138 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5139 ciphertext, 5140 tdata->ciphertext.data, 5141 tdata->validDataLenInBits.len, 5142 "ZUC Ciphertext data not as expected"); 5143 5144 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 5145 uint8_t *, 5146 plaintext_pad_len); 5147 5148 /* Validate obuf */ 5149 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5150 ut_params->digest, 5151 tdata->digest.data, 5152 tdata->digest.len, 5153 "ZUC Generated auth tag not as expected"); 5154 return 0; 5155 } 5156 5157 static int 5158 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) 5159 { 5160 struct crypto_testsuite_params *ts_params = &testsuite_params; 5161 struct crypto_unittest_params *ut_params = &unittest_params; 5162 5163 int retval; 5164 5165 uint8_t *plaintext, *ciphertext; 5166 unsigned plaintext_pad_len; 5167 unsigned plaintext_len; 5168 struct rte_cryptodev_info dev_info; 5169 5170 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5171 uint64_t feat_flags = dev_info.feature_flags; 5172 5173 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5174 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5175 printf("Device doesn't support RAW data-path APIs.\n"); 5176 return TEST_SKIPPED; 5177 } 5178 5179 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5180 return TEST_SKIPPED; 5181 5182 /* Verify the capabilities */ 5183 struct rte_cryptodev_sym_capability_idx cap_idx; 5184 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5185 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5186 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5187 &cap_idx) == NULL) 5188 return TEST_SKIPPED; 5189 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5190 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5191 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5192 &cap_idx) == NULL) 5193 return TEST_SKIPPED; 5194 5195 /* Create SNOW 3G session */ 5196 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0], 5197 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5198 RTE_CRYPTO_AUTH_OP_GENERATE, 5199 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5200 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5201 tdata->key.data, tdata->key.len, 5202 tdata->key.data, tdata->key.len, 5203 tdata->auth_iv.len, tdata->digest.len, 5204 tdata->cipher_iv.len); 5205 if (retval != 0) 5206 return retval; 5207 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5208 5209 /* clear mbuf payload */ 5210 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5211 rte_pktmbuf_tailroom(ut_params->ibuf)); 5212 5213 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5214 /* Append data which is padded to a multiple of */ 5215 /* the algorithms block size */ 5216 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5217 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5218 plaintext_pad_len); 5219 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5220 5221 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5222 5223 /* Create SNOW 3G operation */ 5224 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 5225 tdata->digest.len, tdata->auth_iv.data, 5226 tdata->auth_iv.len, 5227 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5228 tdata->cipher_iv.data, tdata->cipher_iv.len, 5229 tdata->validCipherLenInBits.len, 5230 0, 5231 tdata->validAuthLenInBits.len, 5232 0 5233 ); 5234 if (retval < 0) 5235 return retval; 5236 5237 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5238 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5239 tdata->cipher_iv.len); 5240 if (retval != TEST_SUCCESS) 5241 return retval; 5242 } else 5243 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5244 ut_params->op); 5245 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5246 ut_params->obuf = ut_params->op->sym->m_src; 5247 if (ut_params->obuf) 5248 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 5249 else 5250 ciphertext = plaintext; 5251 5252 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 5253 /* Validate obuf */ 5254 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5255 ciphertext, 5256 tdata->ciphertext.data, 5257 tdata->validDataLenInBits.len, 5258 "SNOW 3G Ciphertext data not as expected"); 5259 5260 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 5261 uint8_t *, 5262 plaintext_pad_len); 5263 5264 /* Validate obuf */ 5265 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5266 ut_params->digest, 5267 tdata->digest.data, 5268 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5269 "SNOW 3G Generated auth tag not as expected"); 5270 return 0; 5271 } 5272 5273 static int 5274 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata, 5275 uint8_t op_mode, uint8_t verify) 5276 { 5277 struct crypto_testsuite_params *ts_params = &testsuite_params; 5278 struct crypto_unittest_params *ut_params = &unittest_params; 5279 5280 int retval; 5281 5282 uint8_t *plaintext = NULL, *ciphertext = NULL; 5283 unsigned int plaintext_pad_len; 5284 unsigned int plaintext_len; 5285 unsigned int ciphertext_pad_len; 5286 unsigned int ciphertext_len; 5287 unsigned int digest_offset; 5288 5289 struct rte_cryptodev_info dev_info; 5290 5291 /* Verify the capabilities */ 5292 struct rte_cryptodev_sym_capability_idx cap_idx; 5293 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5294 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5295 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5296 &cap_idx) == NULL) 5297 return TEST_SKIPPED; 5298 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5299 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5300 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5301 &cap_idx) == NULL) 5302 return TEST_SKIPPED; 5303 5304 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5305 return TEST_SKIPPED; 5306 5307 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5308 5309 uint64_t feat_flags = dev_info.feature_flags; 5310 5311 if (op_mode == OUT_OF_PLACE) { 5312 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5313 printf("Device doesn't support digest encrypted.\n"); 5314 return TEST_SKIPPED; 5315 } 5316 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5317 return TEST_SKIPPED; 5318 } 5319 5320 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5321 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5322 printf("Device doesn't support RAW data-path APIs.\n"); 5323 return TEST_SKIPPED; 5324 } 5325 5326 /* Create SNOW 3G session */ 5327 retval = create_wireless_algo_auth_cipher_session( 5328 ts_params->valid_devs[0], 5329 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5330 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5331 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5332 : RTE_CRYPTO_AUTH_OP_GENERATE), 5333 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5334 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5335 tdata->key.data, tdata->key.len, 5336 tdata->key.data, tdata->key.len, 5337 tdata->auth_iv.len, tdata->digest.len, 5338 tdata->cipher_iv.len); 5339 if (retval != 0) 5340 return retval; 5341 5342 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5343 if (op_mode == OUT_OF_PLACE) 5344 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5345 5346 /* clear mbuf payload */ 5347 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5348 rte_pktmbuf_tailroom(ut_params->ibuf)); 5349 if (op_mode == OUT_OF_PLACE) 5350 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5351 rte_pktmbuf_tailroom(ut_params->obuf)); 5352 5353 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5354 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5355 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5356 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5357 5358 if (verify) { 5359 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5360 ciphertext_pad_len); 5361 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5362 if (op_mode == OUT_OF_PLACE) 5363 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5364 debug_hexdump(stdout, "ciphertext:", ciphertext, 5365 ciphertext_len); 5366 } else { 5367 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5368 plaintext_pad_len); 5369 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5370 if (op_mode == OUT_OF_PLACE) 5371 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5372 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5373 } 5374 5375 /* Create SNOW 3G operation */ 5376 retval = create_wireless_algo_auth_cipher_operation( 5377 tdata->digest.data, tdata->digest.len, 5378 tdata->cipher_iv.data, tdata->cipher_iv.len, 5379 tdata->auth_iv.data, tdata->auth_iv.len, 5380 (tdata->digest.offset_bytes == 0 ? 5381 (verify ? ciphertext_pad_len : plaintext_pad_len) 5382 : tdata->digest.offset_bytes), 5383 tdata->validCipherLenInBits.len, 5384 tdata->cipher.offset_bits, 5385 tdata->validAuthLenInBits.len, 5386 tdata->auth.offset_bits, 5387 op_mode, 0, verify); 5388 5389 if (retval < 0) 5390 return retval; 5391 5392 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5393 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5394 tdata->cipher_iv.len); 5395 if (retval != TEST_SUCCESS) 5396 return retval; 5397 } else 5398 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5399 ut_params->op); 5400 5401 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5402 5403 ut_params->obuf = (op_mode == IN_PLACE ? 5404 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5405 5406 if (verify) { 5407 if (ut_params->obuf) 5408 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5409 uint8_t *); 5410 else 5411 plaintext = ciphertext + 5412 (tdata->cipher.offset_bits >> 3); 5413 5414 debug_hexdump(stdout, "plaintext:", plaintext, 5415 (tdata->plaintext.len >> 3) - tdata->digest.len); 5416 debug_hexdump(stdout, "plaintext expected:", 5417 tdata->plaintext.data, 5418 (tdata->plaintext.len >> 3) - tdata->digest.len); 5419 } else { 5420 if (ut_params->obuf) 5421 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5422 uint8_t *); 5423 else 5424 ciphertext = plaintext; 5425 5426 debug_hexdump(stdout, "ciphertext:", ciphertext, 5427 ciphertext_len); 5428 debug_hexdump(stdout, "ciphertext expected:", 5429 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5430 5431 if (tdata->digest.offset_bytes == 0) 5432 digest_offset = plaintext_pad_len; 5433 else 5434 digest_offset = tdata->digest.offset_bytes; 5435 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 5436 uint8_t *, digest_offset); 5437 5438 debug_hexdump(stdout, "digest:", ut_params->digest, 5439 tdata->digest.len); 5440 debug_hexdump(stdout, "digest expected:", tdata->digest.data, 5441 tdata->digest.len); 5442 } 5443 5444 /* Validate obuf */ 5445 if (verify) { 5446 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5447 plaintext, 5448 tdata->plaintext.data, 5449 (tdata->plaintext.len - tdata->cipher.offset_bits - 5450 (tdata->digest.len << 3)), 5451 tdata->cipher.offset_bits, 5452 "SNOW 3G Plaintext data not as expected"); 5453 } else { 5454 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5455 ciphertext, 5456 tdata->ciphertext.data, 5457 (tdata->validDataLenInBits.len - 5458 tdata->cipher.offset_bits), 5459 tdata->cipher.offset_bits, 5460 "SNOW 3G Ciphertext data not as expected"); 5461 5462 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5463 ut_params->digest, 5464 tdata->digest.data, 5465 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5466 "SNOW 3G Generated auth tag not as expected"); 5467 } 5468 return 0; 5469 } 5470 5471 static int 5472 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata, 5473 uint8_t op_mode, uint8_t verify) 5474 { 5475 struct crypto_testsuite_params *ts_params = &testsuite_params; 5476 struct crypto_unittest_params *ut_params = &unittest_params; 5477 5478 int retval; 5479 5480 const uint8_t *plaintext = NULL; 5481 const uint8_t *ciphertext = NULL; 5482 const uint8_t *digest = NULL; 5483 unsigned int plaintext_pad_len; 5484 unsigned int plaintext_len; 5485 unsigned int ciphertext_pad_len; 5486 unsigned int ciphertext_len; 5487 uint8_t buffer[10000]; 5488 uint8_t digest_buffer[10000]; 5489 5490 struct rte_cryptodev_info dev_info; 5491 5492 /* Verify the capabilities */ 5493 struct rte_cryptodev_sym_capability_idx cap_idx; 5494 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5495 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5496 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5497 &cap_idx) == NULL) 5498 return TEST_SKIPPED; 5499 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5500 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5501 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5502 &cap_idx) == NULL) 5503 return TEST_SKIPPED; 5504 5505 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5506 return TEST_SKIPPED; 5507 5508 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5509 5510 uint64_t feat_flags = dev_info.feature_flags; 5511 5512 if (op_mode == IN_PLACE) { 5513 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5514 printf("Device doesn't support in-place scatter-gather " 5515 "in both input and output mbufs.\n"); 5516 return TEST_SKIPPED; 5517 } 5518 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5519 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5520 printf("Device doesn't support RAW data-path APIs.\n"); 5521 return TEST_SKIPPED; 5522 } 5523 } else { 5524 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5525 return TEST_SKIPPED; 5526 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5527 printf("Device doesn't support out-of-place scatter-gather " 5528 "in both input and output mbufs.\n"); 5529 return TEST_SKIPPED; 5530 } 5531 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5532 printf("Device doesn't support digest encrypted.\n"); 5533 return TEST_SKIPPED; 5534 } 5535 } 5536 5537 /* Create SNOW 3G session */ 5538 retval = create_wireless_algo_auth_cipher_session( 5539 ts_params->valid_devs[0], 5540 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5541 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5542 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5543 : RTE_CRYPTO_AUTH_OP_GENERATE), 5544 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5545 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5546 tdata->key.data, tdata->key.len, 5547 tdata->key.data, tdata->key.len, 5548 tdata->auth_iv.len, tdata->digest.len, 5549 tdata->cipher_iv.len); 5550 5551 if (retval != 0) 5552 return retval; 5553 5554 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5555 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5556 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5557 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5558 5559 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5560 plaintext_pad_len, 15, 0); 5561 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5562 "Failed to allocate input buffer in mempool"); 5563 5564 if (op_mode == OUT_OF_PLACE) { 5565 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5566 plaintext_pad_len, 15, 0); 5567 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5568 "Failed to allocate output buffer in mempool"); 5569 } 5570 5571 if (verify) { 5572 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5573 tdata->ciphertext.data); 5574 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5575 ciphertext_len, buffer); 5576 debug_hexdump(stdout, "ciphertext:", ciphertext, 5577 ciphertext_len); 5578 } else { 5579 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5580 tdata->plaintext.data); 5581 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5582 plaintext_len, buffer); 5583 debug_hexdump(stdout, "plaintext:", plaintext, 5584 plaintext_len); 5585 } 5586 memset(buffer, 0, sizeof(buffer)); 5587 5588 /* Create SNOW 3G operation */ 5589 retval = create_wireless_algo_auth_cipher_operation( 5590 tdata->digest.data, tdata->digest.len, 5591 tdata->cipher_iv.data, tdata->cipher_iv.len, 5592 tdata->auth_iv.data, tdata->auth_iv.len, 5593 (tdata->digest.offset_bytes == 0 ? 5594 (verify ? ciphertext_pad_len : plaintext_pad_len) 5595 : tdata->digest.offset_bytes), 5596 tdata->validCipherLenInBits.len, 5597 tdata->cipher.offset_bits, 5598 tdata->validAuthLenInBits.len, 5599 tdata->auth.offset_bits, 5600 op_mode, 1, verify); 5601 5602 if (retval < 0) 5603 return retval; 5604 5605 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5606 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5607 tdata->cipher_iv.len); 5608 if (retval != TEST_SUCCESS) 5609 return retval; 5610 } else 5611 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5612 ut_params->op); 5613 5614 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5615 5616 ut_params->obuf = (op_mode == IN_PLACE ? 5617 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5618 5619 if (verify) { 5620 if (ut_params->obuf) 5621 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5622 plaintext_len, buffer); 5623 else 5624 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5625 plaintext_len, buffer); 5626 5627 debug_hexdump(stdout, "plaintext:", plaintext, 5628 (tdata->plaintext.len >> 3) - tdata->digest.len); 5629 debug_hexdump(stdout, "plaintext expected:", 5630 tdata->plaintext.data, 5631 (tdata->plaintext.len >> 3) - tdata->digest.len); 5632 } else { 5633 if (ut_params->obuf) 5634 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5635 ciphertext_len, buffer); 5636 else 5637 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5638 ciphertext_len, buffer); 5639 5640 debug_hexdump(stdout, "ciphertext:", ciphertext, 5641 ciphertext_len); 5642 debug_hexdump(stdout, "ciphertext expected:", 5643 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5644 5645 if (ut_params->obuf) 5646 digest = rte_pktmbuf_read(ut_params->obuf, 5647 (tdata->digest.offset_bytes == 0 ? 5648 plaintext_pad_len : tdata->digest.offset_bytes), 5649 tdata->digest.len, digest_buffer); 5650 else 5651 digest = rte_pktmbuf_read(ut_params->ibuf, 5652 (tdata->digest.offset_bytes == 0 ? 5653 plaintext_pad_len : tdata->digest.offset_bytes), 5654 tdata->digest.len, digest_buffer); 5655 5656 debug_hexdump(stdout, "digest:", digest, 5657 tdata->digest.len); 5658 debug_hexdump(stdout, "digest expected:", 5659 tdata->digest.data, tdata->digest.len); 5660 } 5661 5662 /* Validate obuf */ 5663 if (verify) { 5664 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5665 plaintext, 5666 tdata->plaintext.data, 5667 (tdata->plaintext.len - tdata->cipher.offset_bits - 5668 (tdata->digest.len << 3)), 5669 tdata->cipher.offset_bits, 5670 "SNOW 3G Plaintext data not as expected"); 5671 } else { 5672 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5673 ciphertext, 5674 tdata->ciphertext.data, 5675 (tdata->validDataLenInBits.len - 5676 tdata->cipher.offset_bits), 5677 tdata->cipher.offset_bits, 5678 "SNOW 3G Ciphertext data not as expected"); 5679 5680 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5681 digest, 5682 tdata->digest.data, 5683 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5684 "SNOW 3G Generated auth tag not as expected"); 5685 } 5686 return 0; 5687 } 5688 5689 static int 5690 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata, 5691 uint8_t op_mode, uint8_t verify) 5692 { 5693 struct crypto_testsuite_params *ts_params = &testsuite_params; 5694 struct crypto_unittest_params *ut_params = &unittest_params; 5695 5696 int retval; 5697 5698 uint8_t *plaintext = NULL, *ciphertext = NULL; 5699 unsigned int plaintext_pad_len; 5700 unsigned int plaintext_len; 5701 unsigned int ciphertext_pad_len; 5702 unsigned int ciphertext_len; 5703 unsigned int digest_offset; 5704 5705 struct rte_cryptodev_info dev_info; 5706 5707 /* Verify the capabilities */ 5708 struct rte_cryptodev_sym_capability_idx cap_idx; 5709 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5710 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5711 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5712 &cap_idx) == NULL) 5713 return TEST_SKIPPED; 5714 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5715 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5716 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5717 &cap_idx) == NULL) 5718 return TEST_SKIPPED; 5719 5720 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5721 5722 uint64_t feat_flags = dev_info.feature_flags; 5723 5724 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5725 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5726 printf("Device doesn't support RAW data-path APIs.\n"); 5727 return TEST_SKIPPED; 5728 } 5729 5730 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5731 return TEST_SKIPPED; 5732 5733 if (op_mode == OUT_OF_PLACE) { 5734 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5735 return TEST_SKIPPED; 5736 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5737 printf("Device doesn't support digest encrypted.\n"); 5738 return TEST_SKIPPED; 5739 } 5740 } 5741 5742 /* Create KASUMI session */ 5743 retval = create_wireless_algo_auth_cipher_session( 5744 ts_params->valid_devs[0], 5745 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5746 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5747 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5748 : RTE_CRYPTO_AUTH_OP_GENERATE), 5749 RTE_CRYPTO_AUTH_KASUMI_F9, 5750 RTE_CRYPTO_CIPHER_KASUMI_F8, 5751 tdata->key.data, tdata->key.len, 5752 tdata->key.data, tdata->key.len, 5753 0, tdata->digest.len, 5754 tdata->cipher_iv.len); 5755 5756 if (retval != 0) 5757 return retval; 5758 5759 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5760 if (op_mode == OUT_OF_PLACE) 5761 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5762 5763 /* clear mbuf payload */ 5764 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5765 rte_pktmbuf_tailroom(ut_params->ibuf)); 5766 if (op_mode == OUT_OF_PLACE) 5767 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5768 rte_pktmbuf_tailroom(ut_params->obuf)); 5769 5770 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5771 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5772 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5773 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5774 5775 if (verify) { 5776 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5777 ciphertext_pad_len); 5778 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5779 if (op_mode == OUT_OF_PLACE) 5780 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5781 debug_hexdump(stdout, "ciphertext:", ciphertext, 5782 ciphertext_len); 5783 } else { 5784 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5785 plaintext_pad_len); 5786 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5787 if (op_mode == OUT_OF_PLACE) 5788 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5789 debug_hexdump(stdout, "plaintext:", plaintext, 5790 plaintext_len); 5791 } 5792 5793 /* Create KASUMI operation */ 5794 retval = create_wireless_algo_auth_cipher_operation( 5795 tdata->digest.data, tdata->digest.len, 5796 tdata->cipher_iv.data, tdata->cipher_iv.len, 5797 NULL, 0, 5798 (tdata->digest.offset_bytes == 0 ? 5799 (verify ? ciphertext_pad_len : plaintext_pad_len) 5800 : tdata->digest.offset_bytes), 5801 tdata->validCipherLenInBits.len, 5802 tdata->validCipherOffsetInBits.len, 5803 tdata->validAuthLenInBits.len, 5804 0, 5805 op_mode, 0, verify); 5806 5807 if (retval < 0) 5808 return retval; 5809 5810 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5811 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5812 tdata->cipher_iv.len); 5813 if (retval != TEST_SUCCESS) 5814 return retval; 5815 } else 5816 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5817 ut_params->op); 5818 5819 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5820 5821 ut_params->obuf = (op_mode == IN_PLACE ? 5822 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5823 5824 5825 if (verify) { 5826 if (ut_params->obuf) 5827 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5828 uint8_t *); 5829 else 5830 plaintext = ciphertext; 5831 5832 debug_hexdump(stdout, "plaintext:", plaintext, 5833 (tdata->plaintext.len >> 3) - tdata->digest.len); 5834 debug_hexdump(stdout, "plaintext expected:", 5835 tdata->plaintext.data, 5836 (tdata->plaintext.len >> 3) - tdata->digest.len); 5837 } else { 5838 if (ut_params->obuf) 5839 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5840 uint8_t *); 5841 else 5842 ciphertext = plaintext; 5843 5844 debug_hexdump(stdout, "ciphertext:", ciphertext, 5845 ciphertext_len); 5846 debug_hexdump(stdout, "ciphertext expected:", 5847 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5848 5849 if (tdata->digest.offset_bytes == 0) 5850 digest_offset = plaintext_pad_len; 5851 else 5852 digest_offset = tdata->digest.offset_bytes; 5853 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 5854 uint8_t *, digest_offset); 5855 5856 debug_hexdump(stdout, "digest:", ut_params->digest, 5857 tdata->digest.len); 5858 debug_hexdump(stdout, "digest expected:", 5859 tdata->digest.data, tdata->digest.len); 5860 } 5861 5862 /* Validate obuf */ 5863 if (verify) { 5864 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5865 plaintext, 5866 tdata->plaintext.data, 5867 tdata->plaintext.len >> 3, 5868 "KASUMI Plaintext data not as expected"); 5869 } else { 5870 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5871 ciphertext, 5872 tdata->ciphertext.data, 5873 tdata->ciphertext.len >> 3, 5874 "KASUMI Ciphertext data not as expected"); 5875 5876 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5877 ut_params->digest, 5878 tdata->digest.data, 5879 DIGEST_BYTE_LENGTH_KASUMI_F9, 5880 "KASUMI Generated auth tag not as expected"); 5881 } 5882 return 0; 5883 } 5884 5885 static int 5886 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata, 5887 uint8_t op_mode, uint8_t verify) 5888 { 5889 struct crypto_testsuite_params *ts_params = &testsuite_params; 5890 struct crypto_unittest_params *ut_params = &unittest_params; 5891 5892 int retval; 5893 5894 const uint8_t *plaintext = NULL; 5895 const uint8_t *ciphertext = NULL; 5896 const uint8_t *digest = NULL; 5897 unsigned int plaintext_pad_len; 5898 unsigned int plaintext_len; 5899 unsigned int ciphertext_pad_len; 5900 unsigned int ciphertext_len; 5901 uint8_t buffer[10000]; 5902 uint8_t digest_buffer[10000]; 5903 5904 struct rte_cryptodev_info dev_info; 5905 5906 /* Verify the capabilities */ 5907 struct rte_cryptodev_sym_capability_idx cap_idx; 5908 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5909 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5910 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5911 &cap_idx) == NULL) 5912 return TEST_SKIPPED; 5913 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5914 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5915 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5916 &cap_idx) == NULL) 5917 return TEST_SKIPPED; 5918 5919 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5920 return TEST_SKIPPED; 5921 5922 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5923 5924 uint64_t feat_flags = dev_info.feature_flags; 5925 5926 if (op_mode == IN_PLACE) { 5927 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5928 printf("Device doesn't support in-place scatter-gather " 5929 "in both input and output mbufs.\n"); 5930 return TEST_SKIPPED; 5931 } 5932 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5933 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5934 printf("Device doesn't support RAW data-path APIs.\n"); 5935 return TEST_SKIPPED; 5936 } 5937 } else { 5938 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5939 return TEST_SKIPPED; 5940 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5941 printf("Device doesn't support out-of-place scatter-gather " 5942 "in both input and output mbufs.\n"); 5943 return TEST_SKIPPED; 5944 } 5945 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5946 printf("Device doesn't support digest encrypted.\n"); 5947 return TEST_SKIPPED; 5948 } 5949 } 5950 5951 /* Create KASUMI session */ 5952 retval = create_wireless_algo_auth_cipher_session( 5953 ts_params->valid_devs[0], 5954 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5955 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5956 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5957 : RTE_CRYPTO_AUTH_OP_GENERATE), 5958 RTE_CRYPTO_AUTH_KASUMI_F9, 5959 RTE_CRYPTO_CIPHER_KASUMI_F8, 5960 tdata->key.data, tdata->key.len, 5961 tdata->key.data, tdata->key.len, 5962 0, tdata->digest.len, 5963 tdata->cipher_iv.len); 5964 5965 if (retval != 0) 5966 return retval; 5967 5968 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5969 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5970 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5971 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5972 5973 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5974 plaintext_pad_len, 15, 0); 5975 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5976 "Failed to allocate input buffer in mempool"); 5977 5978 if (op_mode == OUT_OF_PLACE) { 5979 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5980 plaintext_pad_len, 15, 0); 5981 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5982 "Failed to allocate output buffer in mempool"); 5983 } 5984 5985 if (verify) { 5986 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5987 tdata->ciphertext.data); 5988 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5989 ciphertext_len, buffer); 5990 debug_hexdump(stdout, "ciphertext:", ciphertext, 5991 ciphertext_len); 5992 } else { 5993 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5994 tdata->plaintext.data); 5995 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5996 plaintext_len, buffer); 5997 debug_hexdump(stdout, "plaintext:", plaintext, 5998 plaintext_len); 5999 } 6000 memset(buffer, 0, sizeof(buffer)); 6001 6002 /* Create KASUMI operation */ 6003 retval = create_wireless_algo_auth_cipher_operation( 6004 tdata->digest.data, tdata->digest.len, 6005 tdata->cipher_iv.data, tdata->cipher_iv.len, 6006 NULL, 0, 6007 (tdata->digest.offset_bytes == 0 ? 6008 (verify ? ciphertext_pad_len : plaintext_pad_len) 6009 : tdata->digest.offset_bytes), 6010 tdata->validCipherLenInBits.len, 6011 tdata->validCipherOffsetInBits.len, 6012 tdata->validAuthLenInBits.len, 6013 0, 6014 op_mode, 1, verify); 6015 6016 if (retval < 0) 6017 return retval; 6018 6019 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6020 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 6021 tdata->cipher_iv.len); 6022 if (retval != TEST_SUCCESS) 6023 return retval; 6024 } else 6025 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6026 ut_params->op); 6027 6028 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6029 6030 ut_params->obuf = (op_mode == IN_PLACE ? 6031 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6032 6033 if (verify) { 6034 if (ut_params->obuf) 6035 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 6036 plaintext_len, buffer); 6037 else 6038 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6039 plaintext_len, buffer); 6040 6041 debug_hexdump(stdout, "plaintext:", plaintext, 6042 (tdata->plaintext.len >> 3) - tdata->digest.len); 6043 debug_hexdump(stdout, "plaintext expected:", 6044 tdata->plaintext.data, 6045 (tdata->plaintext.len >> 3) - tdata->digest.len); 6046 } else { 6047 if (ut_params->obuf) 6048 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 6049 ciphertext_len, buffer); 6050 else 6051 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6052 ciphertext_len, buffer); 6053 6054 debug_hexdump(stdout, "ciphertext:", ciphertext, 6055 ciphertext_len); 6056 debug_hexdump(stdout, "ciphertext expected:", 6057 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6058 6059 if (ut_params->obuf) 6060 digest = rte_pktmbuf_read(ut_params->obuf, 6061 (tdata->digest.offset_bytes == 0 ? 6062 plaintext_pad_len : tdata->digest.offset_bytes), 6063 tdata->digest.len, digest_buffer); 6064 else 6065 digest = rte_pktmbuf_read(ut_params->ibuf, 6066 (tdata->digest.offset_bytes == 0 ? 6067 plaintext_pad_len : tdata->digest.offset_bytes), 6068 tdata->digest.len, digest_buffer); 6069 6070 debug_hexdump(stdout, "digest:", digest, 6071 tdata->digest.len); 6072 debug_hexdump(stdout, "digest expected:", 6073 tdata->digest.data, tdata->digest.len); 6074 } 6075 6076 /* Validate obuf */ 6077 if (verify) { 6078 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6079 plaintext, 6080 tdata->plaintext.data, 6081 tdata->plaintext.len >> 3, 6082 "KASUMI Plaintext data not as expected"); 6083 } else { 6084 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6085 ciphertext, 6086 tdata->ciphertext.data, 6087 tdata->validDataLenInBits.len, 6088 "KASUMI Ciphertext data not as expected"); 6089 6090 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6091 digest, 6092 tdata->digest.data, 6093 DIGEST_BYTE_LENGTH_KASUMI_F9, 6094 "KASUMI Generated auth tag not as expected"); 6095 } 6096 return 0; 6097 } 6098 6099 static int 6100 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata) 6101 { 6102 struct crypto_testsuite_params *ts_params = &testsuite_params; 6103 struct crypto_unittest_params *ut_params = &unittest_params; 6104 6105 int retval; 6106 6107 uint8_t *plaintext, *ciphertext; 6108 unsigned plaintext_pad_len; 6109 unsigned plaintext_len; 6110 struct rte_cryptodev_info dev_info; 6111 6112 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6113 uint64_t feat_flags = dev_info.feature_flags; 6114 6115 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6116 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6117 printf("Device doesn't support RAW data-path APIs.\n"); 6118 return TEST_SKIPPED; 6119 } 6120 6121 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6122 return TEST_SKIPPED; 6123 6124 /* Verify the capabilities */ 6125 struct rte_cryptodev_sym_capability_idx cap_idx; 6126 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 6127 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 6128 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 6129 &cap_idx) == NULL) 6130 return TEST_SKIPPED; 6131 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 6132 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 6133 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 6134 &cap_idx) == NULL) 6135 return TEST_SKIPPED; 6136 6137 /* Create KASUMI session */ 6138 retval = create_wireless_algo_cipher_auth_session( 6139 ts_params->valid_devs[0], 6140 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6141 RTE_CRYPTO_AUTH_OP_GENERATE, 6142 RTE_CRYPTO_AUTH_KASUMI_F9, 6143 RTE_CRYPTO_CIPHER_KASUMI_F8, 6144 tdata->key.data, tdata->key.len, 6145 tdata->key.data, tdata->key.len, 6146 0, tdata->digest.len, 6147 tdata->cipher_iv.len); 6148 if (retval != 0) 6149 return retval; 6150 6151 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6152 6153 /* clear mbuf payload */ 6154 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6155 rte_pktmbuf_tailroom(ut_params->ibuf)); 6156 6157 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6158 /* Append data which is padded to a multiple of */ 6159 /* the algorithms block size */ 6160 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6161 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6162 plaintext_pad_len); 6163 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6164 6165 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6166 6167 /* Create KASUMI operation */ 6168 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 6169 tdata->digest.len, NULL, 0, 6170 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 6171 tdata->cipher_iv.data, tdata->cipher_iv.len, 6172 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 6173 tdata->validCipherOffsetInBits.len, 6174 tdata->validAuthLenInBits.len, 6175 0 6176 ); 6177 if (retval < 0) 6178 return retval; 6179 6180 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6181 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 6182 tdata->cipher_iv.len); 6183 if (retval != TEST_SUCCESS) 6184 return retval; 6185 } else 6186 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6187 ut_params->op); 6188 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6189 6190 if (ut_params->op->sym->m_dst) 6191 ut_params->obuf = ut_params->op->sym->m_dst; 6192 else 6193 ut_params->obuf = ut_params->op->sym->m_src; 6194 6195 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 6196 tdata->validCipherOffsetInBits.len >> 3); 6197 6198 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 6199 uint8_t *, 6200 plaintext_pad_len); 6201 6202 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 6203 (tdata->validCipherOffsetInBits.len >> 3); 6204 /* Validate obuf */ 6205 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6206 ciphertext, 6207 reference_ciphertext, 6208 tdata->validCipherLenInBits.len, 6209 "KASUMI Ciphertext data not as expected"); 6210 6211 /* Validate obuf */ 6212 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6213 ut_params->digest, 6214 tdata->digest.data, 6215 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 6216 "KASUMI Generated auth tag not as expected"); 6217 return 0; 6218 } 6219 6220 static int 6221 check_cipher_capability(const struct crypto_testsuite_params *ts_params, 6222 const enum rte_crypto_cipher_algorithm cipher_algo, 6223 const uint16_t key_size, const uint16_t iv_size) 6224 { 6225 struct rte_cryptodev_sym_capability_idx cap_idx; 6226 const struct rte_cryptodev_symmetric_capability *cap; 6227 6228 /* Check if device supports the algorithm */ 6229 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 6230 cap_idx.algo.cipher = cipher_algo; 6231 6232 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 6233 &cap_idx); 6234 6235 if (cap == NULL) 6236 return -1; 6237 6238 /* Check if device supports key size and IV size */ 6239 if (rte_cryptodev_sym_capability_check_cipher(cap, key_size, 6240 iv_size) < 0) { 6241 return -1; 6242 } 6243 6244 return 0; 6245 } 6246 6247 static int 6248 check_auth_capability(const struct crypto_testsuite_params *ts_params, 6249 const enum rte_crypto_auth_algorithm auth_algo, 6250 const uint16_t key_size, const uint16_t iv_size, 6251 const uint16_t tag_size) 6252 { 6253 struct rte_cryptodev_sym_capability_idx cap_idx; 6254 const struct rte_cryptodev_symmetric_capability *cap; 6255 6256 /* Check if device supports the algorithm */ 6257 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 6258 cap_idx.algo.auth = auth_algo; 6259 6260 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 6261 &cap_idx); 6262 6263 if (cap == NULL) 6264 return -1; 6265 6266 /* Check if device supports key size and IV size */ 6267 if (rte_cryptodev_sym_capability_check_auth(cap, key_size, 6268 tag_size, iv_size) < 0) { 6269 return -1; 6270 } 6271 6272 return 0; 6273 } 6274 6275 static int 6276 test_zuc_cipher(const struct wireless_test_data *tdata, 6277 enum rte_crypto_cipher_operation direction) 6278 { 6279 struct crypto_testsuite_params *ts_params = &testsuite_params; 6280 struct crypto_unittest_params *ut_params = &unittest_params; 6281 6282 int retval; 6283 uint8_t *plaintext = NULL; 6284 uint8_t *ciphertext = NULL; 6285 unsigned int plaintext_pad_len, ciphertext_pad_len; 6286 unsigned int plaintext_len = 0; 6287 unsigned int ciphertext_len = 0; 6288 struct rte_cryptodev_info dev_info; 6289 6290 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6291 uint64_t feat_flags = dev_info.feature_flags; 6292 6293 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6294 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6295 printf("Device doesn't support RAW data-path APIs.\n"); 6296 return TEST_SKIPPED; 6297 } 6298 6299 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6300 return TEST_SKIPPED; 6301 6302 /* Check if device supports ZUC EEA3 */ 6303 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6304 tdata->key.len, tdata->cipher_iv.len) < 0) 6305 return TEST_SKIPPED; 6306 6307 /* Create ZUC session */ 6308 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 6309 direction, 6310 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6311 tdata->key.data, tdata->key.len, 6312 tdata->cipher_iv.len); 6313 if (retval != 0) 6314 return retval; 6315 6316 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6317 6318 /* Clear mbuf payload */ 6319 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6320 rte_pktmbuf_tailroom(ut_params->ibuf)); 6321 6322 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6323 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6324 /* Append data which is padded to a multiple */ 6325 /* of the algorithms block size */ 6326 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6327 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6328 plaintext_pad_len); 6329 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6330 6331 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6332 } else { 6333 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6334 /* Append data which is padded to a multiple */ 6335 /* of the algorithms block size */ 6336 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 6337 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6338 ciphertext_pad_len); 6339 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6340 6341 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 6342 } 6343 6344 /* Create ZUC operation */ 6345 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6346 tdata->cipher_iv.len, 6347 tdata->plaintext.len, 6348 tdata->validCipherOffsetInBits.len); 6349 if (retval < 0) 6350 return retval; 6351 6352 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6353 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 6354 tdata->cipher_iv.len); 6355 if (retval != TEST_SUCCESS) 6356 return retval; 6357 } else 6358 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6359 ut_params->op); 6360 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6361 6362 ut_params->obuf = ut_params->op->sym->m_dst; 6363 6364 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6365 if (ut_params->obuf) 6366 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 6367 else 6368 ciphertext = plaintext; 6369 6370 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6371 6372 /* Validate obuf */ 6373 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6374 ciphertext, 6375 tdata->ciphertext.data, 6376 tdata->validCipherLenInBits.len, 6377 "ZUC Ciphertext data not as expected"); 6378 } else { 6379 if (ut_params->obuf) 6380 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 6381 else 6382 plaintext = ciphertext; 6383 6384 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 6385 6386 const uint8_t *reference_plaintext = tdata->plaintext.data + 6387 (tdata->validCipherOffsetInBits.len >> 3); 6388 6389 /* Validate obuf */ 6390 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6391 plaintext, 6392 reference_plaintext, 6393 tdata->validCipherLenInBits.len, 6394 "ZUC Plaintext data not as expected"); 6395 } 6396 6397 return 0; 6398 } 6399 6400 static int 6401 test_zuc_cipher_sgl(const struct wireless_test_data *tdata, 6402 enum rte_crypto_cipher_operation direction) 6403 { 6404 struct crypto_testsuite_params *ts_params = &testsuite_params; 6405 struct crypto_unittest_params *ut_params = &unittest_params; 6406 6407 int retval; 6408 6409 unsigned int plaintext_pad_len, ciphertext_pad_len; 6410 unsigned int plaintext_len = 0; 6411 unsigned int ciphertext_len = 0; 6412 const uint8_t *ciphertext, *plaintext; 6413 uint8_t buffer[2048]; 6414 struct rte_cryptodev_info dev_info; 6415 6416 /* Check if device supports ZUC EEA3 */ 6417 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6418 tdata->key.len, tdata->cipher_iv.len) < 0) 6419 return TEST_SKIPPED; 6420 6421 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6422 return TEST_SKIPPED; 6423 6424 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6425 6426 uint64_t feat_flags = dev_info.feature_flags; 6427 6428 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6429 printf("Device doesn't support in-place scatter-gather. " 6430 "Test Skipped.\n"); 6431 return TEST_SKIPPED; 6432 } 6433 6434 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6435 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6436 printf("Device doesn't support RAW data-path APIs.\n"); 6437 return TEST_SKIPPED; 6438 } 6439 6440 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6441 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6442 6443 /* Append data which is padded to a multiple */ 6444 /* of the algorithms block size */ 6445 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6446 6447 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6448 plaintext_pad_len, 10, 0); 6449 6450 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6451 tdata->plaintext.data); 6452 } else { 6453 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6454 6455 /* Append data which is padded to a multiple */ 6456 /* of the algorithms block size */ 6457 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 6458 6459 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6460 ciphertext_pad_len, 10, 0); 6461 6462 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6463 tdata->ciphertext.data); 6464 6465 } 6466 6467 /* Create ZUC session */ 6468 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 6469 direction, 6470 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6471 tdata->key.data, tdata->key.len, 6472 tdata->cipher_iv.len); 6473 if (retval < 0) 6474 return retval; 6475 6476 /* Clear mbuf payload */ 6477 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) 6478 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 6479 else 6480 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, tdata->ciphertext.data); 6481 6482 /* Create ZUC operation */ 6483 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6484 tdata->cipher_iv.len, tdata->plaintext.len, 6485 tdata->validCipherOffsetInBits.len); 6486 if (retval < 0) 6487 return retval; 6488 6489 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6490 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 6491 tdata->cipher_iv.len); 6492 if (retval != TEST_SUCCESS) 6493 return retval; 6494 } else 6495 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6496 ut_params->op); 6497 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6498 6499 ut_params->obuf = ut_params->op->sym->m_dst; 6500 6501 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6502 if (ut_params->obuf) 6503 ciphertext = rte_pktmbuf_read(ut_params->obuf, 6504 0, plaintext_len, buffer); 6505 else 6506 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 6507 0, plaintext_len, buffer); 6508 6509 /* Validate obuf */ 6510 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6511 6512 /* Validate obuf */ 6513 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6514 ciphertext, 6515 tdata->ciphertext.data, 6516 tdata->validCipherLenInBits.len, 6517 "ZUC Ciphertext data not as expected"); 6518 } else { 6519 if (ut_params->obuf) 6520 plaintext = rte_pktmbuf_read(ut_params->obuf, 6521 0, ciphertext_len, buffer); 6522 else 6523 plaintext = rte_pktmbuf_read(ut_params->ibuf, 6524 0, ciphertext_len, buffer); 6525 6526 /* Validate obuf */ 6527 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 6528 6529 /* Validate obuf */ 6530 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6531 plaintext, 6532 tdata->plaintext.data, 6533 tdata->validCipherLenInBits.len, 6534 "ZUC Plaintext data not as expected"); 6535 } 6536 6537 return 0; 6538 } 6539 6540 static int 6541 test_zuc_authentication(const struct wireless_test_data *tdata, 6542 enum rte_crypto_auth_operation auth_op) 6543 { 6544 struct crypto_testsuite_params *ts_params = &testsuite_params; 6545 struct crypto_unittest_params *ut_params = &unittest_params; 6546 6547 int retval; 6548 unsigned plaintext_pad_len; 6549 unsigned plaintext_len; 6550 uint8_t *plaintext; 6551 6552 struct rte_cryptodev_info dev_info; 6553 6554 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6555 uint64_t feat_flags = dev_info.feature_flags; 6556 6557 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 6558 (tdata->validAuthLenInBits.len % 8 != 0)) { 6559 printf("Device doesn't support NON-Byte Aligned Data.\n"); 6560 return TEST_SKIPPED; 6561 } 6562 6563 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6564 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6565 printf("Device doesn't support RAW data-path APIs.\n"); 6566 return TEST_SKIPPED; 6567 } 6568 6569 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6570 return TEST_SKIPPED; 6571 6572 /* Check if device supports ZUC EIA3 */ 6573 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6574 tdata->key.len, tdata->auth_iv.len, 6575 tdata->digest.len) < 0) 6576 return TEST_SKIPPED; 6577 6578 /* Create ZUC session */ 6579 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 6580 tdata->key.data, tdata->key.len, 6581 tdata->auth_iv.len, tdata->digest.len, 6582 auth_op, RTE_CRYPTO_AUTH_ZUC_EIA3); 6583 if (retval != 0) 6584 return retval; 6585 6586 /* alloc mbuf and set payload */ 6587 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6588 6589 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6590 rte_pktmbuf_tailroom(ut_params->ibuf)); 6591 6592 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6593 /* Append data which is padded to a multiple of */ 6594 /* the algorithms block size */ 6595 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6596 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6597 plaintext_pad_len); 6598 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6599 6600 /* Create ZUC operation */ 6601 retval = create_wireless_algo_hash_operation(tdata->digest.data, 6602 tdata->digest.len, 6603 tdata->auth_iv.data, tdata->auth_iv.len, 6604 plaintext_pad_len, 6605 auth_op, tdata->validAuthLenInBits.len, 0); 6606 if (retval < 0) 6607 return retval; 6608 6609 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6610 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 6611 0); 6612 if (retval != TEST_SUCCESS) 6613 return retval; 6614 } else 6615 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6616 ut_params->op); 6617 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6618 ut_params->obuf = ut_params->op->sym->m_src; 6619 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 6620 uint8_t *, 6621 plaintext_pad_len); 6622 6623 if (auth_op != RTE_CRYPTO_AUTH_OP_VERIFY) { 6624 /* Validate obuf */ 6625 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6626 ut_params->digest, 6627 tdata->digest.data, 6628 tdata->digest.len, 6629 "ZUC Generated auth tag not as expected"); 6630 return 0; 6631 } 6632 6633 /* Validate obuf */ 6634 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 6635 return 0; 6636 else 6637 return -1; 6638 6639 return 0; 6640 } 6641 6642 static int 6643 test_zuc_auth_cipher(const struct wireless_test_data *tdata, 6644 uint8_t op_mode, uint8_t verify) 6645 { 6646 struct crypto_testsuite_params *ts_params = &testsuite_params; 6647 struct crypto_unittest_params *ut_params = &unittest_params; 6648 6649 int retval; 6650 6651 uint8_t *plaintext = NULL, *ciphertext = NULL; 6652 unsigned int plaintext_pad_len; 6653 unsigned int plaintext_len; 6654 unsigned int ciphertext_pad_len; 6655 unsigned int ciphertext_len; 6656 unsigned int digest_offset; 6657 6658 struct rte_cryptodev_info dev_info; 6659 6660 /* Check if device supports ZUC EEA3 */ 6661 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6662 tdata->key.len, tdata->cipher_iv.len) < 0) 6663 return TEST_SKIPPED; 6664 6665 /* Check if device supports ZUC EIA3 */ 6666 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6667 tdata->key.len, tdata->auth_iv.len, 6668 tdata->digest.len) < 0) 6669 return TEST_SKIPPED; 6670 6671 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6672 return TEST_SKIPPED; 6673 6674 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6675 6676 uint64_t feat_flags = dev_info.feature_flags; 6677 6678 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6679 printf("Device doesn't support digest encrypted.\n"); 6680 return TEST_SKIPPED; 6681 } 6682 if (op_mode == IN_PLACE) { 6683 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6684 printf("Device doesn't support in-place scatter-gather " 6685 "in both input and output mbufs.\n"); 6686 return TEST_SKIPPED; 6687 } 6688 6689 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6690 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6691 printf("Device doesn't support RAW data-path APIs.\n"); 6692 return TEST_SKIPPED; 6693 } 6694 } else { 6695 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6696 return TEST_SKIPPED; 6697 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6698 printf("Device doesn't support out-of-place scatter-gather " 6699 "in both input and output mbufs.\n"); 6700 return TEST_SKIPPED; 6701 } 6702 } 6703 6704 /* Create ZUC session */ 6705 retval = create_wireless_algo_auth_cipher_session( 6706 ts_params->valid_devs[0], 6707 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6708 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6709 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6710 : RTE_CRYPTO_AUTH_OP_GENERATE), 6711 RTE_CRYPTO_AUTH_ZUC_EIA3, 6712 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6713 tdata->key.data, tdata->key.len, 6714 tdata->key.data, tdata->key.len, 6715 tdata->auth_iv.len, tdata->digest.len, 6716 tdata->cipher_iv.len); 6717 6718 if (retval != 0) 6719 return retval; 6720 6721 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6722 if (op_mode == OUT_OF_PLACE) 6723 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6724 6725 /* clear mbuf payload */ 6726 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6727 rte_pktmbuf_tailroom(ut_params->ibuf)); 6728 if (op_mode == OUT_OF_PLACE) 6729 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 6730 rte_pktmbuf_tailroom(ut_params->obuf)); 6731 6732 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6733 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6734 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6735 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6736 6737 if (verify) { 6738 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6739 ciphertext_pad_len); 6740 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6741 debug_hexdump(stdout, "ciphertext:", ciphertext, 6742 ciphertext_len); 6743 } else { 6744 /* make sure enough space to cover partial digest verify case */ 6745 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6746 ciphertext_pad_len); 6747 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6748 debug_hexdump(stdout, "plaintext:", plaintext, 6749 plaintext_len); 6750 } 6751 6752 if (op_mode == OUT_OF_PLACE) 6753 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 6754 6755 /* Create ZUC operation */ 6756 retval = create_wireless_algo_auth_cipher_operation( 6757 tdata->digest.data, tdata->digest.len, 6758 tdata->cipher_iv.data, tdata->cipher_iv.len, 6759 tdata->auth_iv.data, tdata->auth_iv.len, 6760 (tdata->digest.offset_bytes == 0 ? 6761 (verify ? ciphertext_pad_len : plaintext_pad_len) 6762 : tdata->digest.offset_bytes), 6763 tdata->validCipherLenInBits.len, 6764 tdata->validCipherOffsetInBits.len, 6765 tdata->validAuthLenInBits.len, 6766 0, 6767 op_mode, 0, verify); 6768 6769 if (retval < 0) 6770 return retval; 6771 6772 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6773 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 6774 tdata->cipher_iv.len); 6775 if (retval != TEST_SUCCESS) 6776 return retval; 6777 } else 6778 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6779 ut_params->op); 6780 6781 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6782 6783 ut_params->obuf = (op_mode == IN_PLACE ? 6784 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6785 6786 6787 if (verify) { 6788 if (ut_params->obuf) 6789 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 6790 uint8_t *); 6791 else 6792 plaintext = ciphertext; 6793 6794 debug_hexdump(stdout, "plaintext:", plaintext, 6795 (tdata->plaintext.len >> 3) - tdata->digest.len); 6796 debug_hexdump(stdout, "plaintext expected:", 6797 tdata->plaintext.data, 6798 (tdata->plaintext.len >> 3) - tdata->digest.len); 6799 } else { 6800 if (ut_params->obuf) 6801 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 6802 uint8_t *); 6803 else 6804 ciphertext = plaintext; 6805 6806 debug_hexdump(stdout, "ciphertext:", ciphertext, 6807 ciphertext_len); 6808 debug_hexdump(stdout, "ciphertext expected:", 6809 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6810 6811 if (tdata->digest.offset_bytes == 0) 6812 digest_offset = plaintext_pad_len; 6813 else 6814 digest_offset = tdata->digest.offset_bytes; 6815 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 6816 uint8_t *, digest_offset); 6817 6818 debug_hexdump(stdout, "digest:", ut_params->digest, 6819 tdata->digest.len); 6820 debug_hexdump(stdout, "digest expected:", 6821 tdata->digest.data, tdata->digest.len); 6822 } 6823 6824 /* Validate obuf */ 6825 if (verify) { 6826 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6827 plaintext, 6828 tdata->plaintext.data, 6829 tdata->plaintext.len >> 3, 6830 "ZUC Plaintext data not as expected"); 6831 } else { 6832 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6833 ciphertext, 6834 tdata->ciphertext.data, 6835 tdata->ciphertext.len >> 3, 6836 "ZUC Ciphertext data not as expected"); 6837 6838 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6839 ut_params->digest, 6840 tdata->digest.data, 6841 tdata->digest.len, 6842 "ZUC Generated auth tag not as expected"); 6843 } 6844 return 0; 6845 } 6846 6847 static int 6848 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata, 6849 uint8_t op_mode, uint8_t verify) 6850 { 6851 struct crypto_testsuite_params *ts_params = &testsuite_params; 6852 struct crypto_unittest_params *ut_params = &unittest_params; 6853 6854 int retval; 6855 6856 const uint8_t *plaintext = NULL; 6857 const uint8_t *ciphertext = NULL; 6858 const uint8_t *digest = NULL; 6859 unsigned int plaintext_pad_len; 6860 unsigned int plaintext_len; 6861 unsigned int ciphertext_pad_len; 6862 unsigned int ciphertext_len; 6863 uint8_t buffer[10000]; 6864 uint8_t digest_buffer[10000]; 6865 6866 struct rte_cryptodev_info dev_info; 6867 6868 /* Check if device supports ZUC EEA3 */ 6869 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6870 tdata->key.len, tdata->cipher_iv.len) < 0) 6871 return TEST_SKIPPED; 6872 6873 /* Check if device supports ZUC EIA3 */ 6874 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6875 tdata->key.len, tdata->auth_iv.len, 6876 tdata->digest.len) < 0) 6877 return TEST_SKIPPED; 6878 6879 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6880 return TEST_SKIPPED; 6881 6882 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6883 6884 uint64_t feat_flags = dev_info.feature_flags; 6885 6886 if (op_mode == IN_PLACE) { 6887 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6888 printf("Device doesn't support in-place scatter-gather " 6889 "in both input and output mbufs.\n"); 6890 return TEST_SKIPPED; 6891 } 6892 6893 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6894 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6895 printf("Device doesn't support RAW data-path APIs.\n"); 6896 return TEST_SKIPPED; 6897 } 6898 } else { 6899 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6900 return TEST_SKIPPED; 6901 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6902 printf("Device doesn't support out-of-place scatter-gather " 6903 "in both input and output mbufs.\n"); 6904 return TEST_SKIPPED; 6905 } 6906 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6907 printf("Device doesn't support digest encrypted.\n"); 6908 return TEST_SKIPPED; 6909 } 6910 } 6911 6912 /* Create ZUC session */ 6913 retval = create_wireless_algo_auth_cipher_session( 6914 ts_params->valid_devs[0], 6915 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6916 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6917 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6918 : RTE_CRYPTO_AUTH_OP_GENERATE), 6919 RTE_CRYPTO_AUTH_ZUC_EIA3, 6920 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6921 tdata->key.data, tdata->key.len, 6922 tdata->key.data, tdata->key.len, 6923 tdata->auth_iv.len, tdata->digest.len, 6924 tdata->cipher_iv.len); 6925 6926 if (retval != 0) 6927 return retval; 6928 6929 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6930 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6931 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6932 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6933 6934 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6935 plaintext_pad_len, 15, 0); 6936 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6937 "Failed to allocate input buffer in mempool"); 6938 6939 if (op_mode == OUT_OF_PLACE) { 6940 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 6941 plaintext_pad_len, 15, 0); 6942 TEST_ASSERT_NOT_NULL(ut_params->obuf, 6943 "Failed to allocate output buffer in mempool"); 6944 } 6945 6946 if (verify) { 6947 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6948 tdata->ciphertext.data); 6949 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6950 ciphertext_len, buffer); 6951 debug_hexdump(stdout, "ciphertext:", ciphertext, 6952 ciphertext_len); 6953 } else { 6954 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6955 tdata->plaintext.data); 6956 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6957 plaintext_len, buffer); 6958 debug_hexdump(stdout, "plaintext:", plaintext, 6959 plaintext_len); 6960 } 6961 memset(buffer, 0, sizeof(buffer)); 6962 6963 /* Create ZUC operation */ 6964 retval = create_wireless_algo_auth_cipher_operation( 6965 tdata->digest.data, tdata->digest.len, 6966 tdata->cipher_iv.data, tdata->cipher_iv.len, 6967 tdata->auth_iv.data, tdata->auth_iv.len, 6968 (tdata->digest.offset_bytes == 0 ? 6969 (verify ? ciphertext_pad_len : plaintext_pad_len) 6970 : tdata->digest.offset_bytes), 6971 tdata->validCipherLenInBits.len, 6972 tdata->validCipherOffsetInBits.len, 6973 tdata->validAuthLenInBits.len, 6974 0, 6975 op_mode, 1, verify); 6976 6977 if (retval < 0) 6978 return retval; 6979 6980 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6981 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 6982 tdata->cipher_iv.len); 6983 if (retval != TEST_SUCCESS) 6984 return retval; 6985 } else 6986 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6987 ut_params->op); 6988 6989 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6990 6991 ut_params->obuf = (op_mode == IN_PLACE ? 6992 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6993 6994 if (verify) { 6995 if (ut_params->obuf) 6996 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 6997 plaintext_len, buffer); 6998 else 6999 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7000 plaintext_len, buffer); 7001 7002 debug_hexdump(stdout, "plaintext:", plaintext, 7003 (tdata->plaintext.len >> 3) - tdata->digest.len); 7004 debug_hexdump(stdout, "plaintext expected:", 7005 tdata->plaintext.data, 7006 (tdata->plaintext.len >> 3) - tdata->digest.len); 7007 } else { 7008 if (ut_params->obuf) 7009 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 7010 ciphertext_len, buffer); 7011 else 7012 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7013 ciphertext_len, buffer); 7014 7015 debug_hexdump(stdout, "ciphertext:", ciphertext, 7016 ciphertext_len); 7017 debug_hexdump(stdout, "ciphertext expected:", 7018 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 7019 7020 if (ut_params->obuf) 7021 digest = rte_pktmbuf_read(ut_params->obuf, 7022 (tdata->digest.offset_bytes == 0 ? 7023 plaintext_pad_len : tdata->digest.offset_bytes), 7024 tdata->digest.len, digest_buffer); 7025 else 7026 digest = rte_pktmbuf_read(ut_params->ibuf, 7027 (tdata->digest.offset_bytes == 0 ? 7028 plaintext_pad_len : tdata->digest.offset_bytes), 7029 tdata->digest.len, digest_buffer); 7030 7031 debug_hexdump(stdout, "digest:", digest, 7032 tdata->digest.len); 7033 debug_hexdump(stdout, "digest expected:", 7034 tdata->digest.data, tdata->digest.len); 7035 } 7036 7037 /* Validate obuf */ 7038 if (verify) { 7039 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7040 plaintext, 7041 tdata->plaintext.data, 7042 tdata->plaintext.len >> 3, 7043 "ZUC Plaintext data not as expected"); 7044 } else { 7045 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7046 ciphertext, 7047 tdata->ciphertext.data, 7048 tdata->validDataLenInBits.len, 7049 "ZUC Ciphertext data not as expected"); 7050 7051 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7052 digest, 7053 tdata->digest.data, 7054 tdata->digest.len, 7055 "ZUC Generated auth tag not as expected"); 7056 } 7057 return 0; 7058 } 7059 7060 static int 7061 test_kasumi_encryption_test_case_1(void) 7062 { 7063 return test_kasumi_encryption(&kasumi_test_case_1); 7064 } 7065 7066 static int 7067 test_kasumi_encryption_test_case_1_sgl(void) 7068 { 7069 return test_kasumi_encryption_sgl(&kasumi_test_case_1); 7070 } 7071 7072 static int 7073 test_kasumi_encryption_test_case_1_oop(void) 7074 { 7075 return test_kasumi_encryption_oop(&kasumi_test_case_1); 7076 } 7077 7078 static int 7079 test_kasumi_encryption_test_case_1_oop_sgl(void) 7080 { 7081 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1); 7082 } 7083 7084 static int 7085 test_kasumi_encryption_test_case_2(void) 7086 { 7087 return test_kasumi_encryption(&kasumi_test_case_2); 7088 } 7089 7090 static int 7091 test_kasumi_encryption_test_case_3(void) 7092 { 7093 return test_kasumi_encryption(&kasumi_test_case_3); 7094 } 7095 7096 static int 7097 test_kasumi_encryption_test_case_4(void) 7098 { 7099 return test_kasumi_encryption(&kasumi_test_case_4); 7100 } 7101 7102 static int 7103 test_kasumi_encryption_test_case_5(void) 7104 { 7105 return test_kasumi_encryption(&kasumi_test_case_5); 7106 } 7107 7108 static int 7109 test_kasumi_decryption_test_case_1(void) 7110 { 7111 return test_kasumi_decryption(&kasumi_test_case_1); 7112 } 7113 7114 static int 7115 test_kasumi_decryption_test_case_1_oop(void) 7116 { 7117 return test_kasumi_decryption_oop(&kasumi_test_case_1); 7118 } 7119 7120 static int 7121 test_kasumi_decryption_test_case_2(void) 7122 { 7123 return test_kasumi_decryption(&kasumi_test_case_2); 7124 } 7125 7126 static int 7127 test_kasumi_decryption_test_case_3(void) 7128 { 7129 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 7130 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7131 return TEST_SKIPPED; 7132 return test_kasumi_decryption(&kasumi_test_case_3); 7133 } 7134 7135 static int 7136 test_kasumi_decryption_test_case_4(void) 7137 { 7138 return test_kasumi_decryption(&kasumi_test_case_4); 7139 } 7140 7141 static int 7142 test_kasumi_decryption_test_case_5(void) 7143 { 7144 return test_kasumi_decryption(&kasumi_test_case_5); 7145 } 7146 static int 7147 test_snow3g_encryption_test_case_1(void) 7148 { 7149 return test_snow3g_encryption(&snow3g_test_case_1); 7150 } 7151 7152 static int 7153 test_snow3g_encryption_test_case_1_oop(void) 7154 { 7155 return test_snow3g_encryption_oop(&snow3g_test_case_1); 7156 } 7157 7158 static int 7159 test_snow3g_encryption_test_case_1_oop_sgl(void) 7160 { 7161 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 1, 1); 7162 } 7163 7164 static int 7165 test_snow3g_encryption_test_case_1_oop_lb_in_sgl_out(void) 7166 { 7167 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 0, 1); 7168 } 7169 7170 static int 7171 test_snow3g_encryption_test_case_1_oop_sgl_in_lb_out(void) 7172 { 7173 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 1, 0); 7174 } 7175 7176 static int 7177 test_snow3g_encryption_test_case_1_offset_oop(void) 7178 { 7179 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); 7180 } 7181 7182 static int 7183 test_snow3g_encryption_test_case_2(void) 7184 { 7185 return test_snow3g_encryption(&snow3g_test_case_2); 7186 } 7187 7188 static int 7189 test_snow3g_encryption_test_case_3(void) 7190 { 7191 return test_snow3g_encryption(&snow3g_test_case_3); 7192 } 7193 7194 static int 7195 test_snow3g_encryption_test_case_4(void) 7196 { 7197 return test_snow3g_encryption(&snow3g_test_case_4); 7198 } 7199 7200 static int 7201 test_snow3g_encryption_test_case_5(void) 7202 { 7203 return test_snow3g_encryption(&snow3g_test_case_5); 7204 } 7205 7206 static int 7207 test_snow3g_decryption_test_case_1(void) 7208 { 7209 return test_snow3g_decryption(&snow3g_test_case_1); 7210 } 7211 7212 static int 7213 test_snow3g_decryption_test_case_1_oop(void) 7214 { 7215 return test_snow3g_decryption_oop(&snow3g_test_case_1); 7216 } 7217 7218 static int 7219 test_snow3g_decryption_test_case_2(void) 7220 { 7221 return test_snow3g_decryption(&snow3g_test_case_2); 7222 } 7223 7224 static int 7225 test_snow3g_decryption_test_case_3(void) 7226 { 7227 return test_snow3g_decryption(&snow3g_test_case_3); 7228 } 7229 7230 static int 7231 test_snow3g_decryption_test_case_4(void) 7232 { 7233 return test_snow3g_decryption(&snow3g_test_case_4); 7234 } 7235 7236 static int 7237 test_snow3g_decryption_test_case_5(void) 7238 { 7239 return test_snow3g_decryption(&snow3g_test_case_5); 7240 } 7241 7242 /* 7243 * Function prepares snow3g_hash_test_data from snow3g_test_data. 7244 * Pattern digest from snow3g_test_data must be allocated as 7245 * 4 last bytes in plaintext. 7246 */ 7247 static void 7248 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern, 7249 struct snow3g_hash_test_data *output) 7250 { 7251 if ((pattern != NULL) && (output != NULL)) { 7252 output->key.len = pattern->key.len; 7253 7254 memcpy(output->key.data, 7255 pattern->key.data, pattern->key.len); 7256 7257 output->auth_iv.len = pattern->auth_iv.len; 7258 7259 memcpy(output->auth_iv.data, 7260 pattern->auth_iv.data, pattern->auth_iv.len); 7261 7262 output->plaintext.len = pattern->plaintext.len; 7263 7264 memcpy(output->plaintext.data, 7265 pattern->plaintext.data, pattern->plaintext.len >> 3); 7266 7267 output->digest.len = pattern->digest.len; 7268 7269 memcpy(output->digest.data, 7270 &pattern->plaintext.data[pattern->digest.offset_bytes], 7271 pattern->digest.len); 7272 7273 output->validAuthLenInBits.len = 7274 pattern->validAuthLenInBits.len; 7275 } 7276 } 7277 7278 /* 7279 * Test case verify computed cipher and digest from snow3g_test_case_7 data. 7280 */ 7281 static int 7282 test_snow3g_decryption_with_digest_test_case_1(void) 7283 { 7284 int ret; 7285 struct snow3g_hash_test_data snow3g_hash_data; 7286 struct rte_cryptodev_info dev_info; 7287 struct crypto_testsuite_params *ts_params = &testsuite_params; 7288 7289 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7290 uint64_t feat_flags = dev_info.feature_flags; 7291 7292 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7293 printf("Device doesn't support encrypted digest operations.\n"); 7294 return TEST_SKIPPED; 7295 } 7296 7297 /* 7298 * Function prepare data for hash verification test case. 7299 * Digest is allocated in 4 last bytes in plaintext, pattern. 7300 */ 7301 snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data); 7302 7303 ret = test_snow3g_decryption(&snow3g_test_case_7); 7304 if (ret != 0) 7305 return ret; 7306 7307 return test_snow3g_authentication_verify(&snow3g_hash_data); 7308 } 7309 7310 static int 7311 test_snow3g_cipher_auth_test_case_1(void) 7312 { 7313 return test_snow3g_cipher_auth(&snow3g_test_case_3); 7314 } 7315 7316 static int 7317 test_snow3g_auth_cipher_test_case_1(void) 7318 { 7319 return test_snow3g_auth_cipher( 7320 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0); 7321 } 7322 7323 static int 7324 test_snow3g_auth_cipher_test_case_2(void) 7325 { 7326 return test_snow3g_auth_cipher( 7327 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0); 7328 } 7329 7330 static int 7331 test_snow3g_auth_cipher_test_case_2_oop(void) 7332 { 7333 return test_snow3g_auth_cipher( 7334 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7335 } 7336 7337 static int 7338 test_snow3g_auth_cipher_part_digest_enc(void) 7339 { 7340 return test_snow3g_auth_cipher( 7341 &snow3g_auth_cipher_partial_digest_encryption, 7342 IN_PLACE, 0); 7343 } 7344 7345 static int 7346 test_snow3g_auth_cipher_part_digest_enc_oop(void) 7347 { 7348 return test_snow3g_auth_cipher( 7349 &snow3g_auth_cipher_partial_digest_encryption, 7350 OUT_OF_PLACE, 0); 7351 } 7352 7353 static int 7354 test_snow3g_auth_cipher_test_case_3_sgl(void) 7355 { 7356 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 7357 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7358 return TEST_SKIPPED; 7359 return test_snow3g_auth_cipher_sgl( 7360 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0); 7361 } 7362 7363 static int 7364 test_snow3g_auth_cipher_test_case_3_oop_sgl(void) 7365 { 7366 return test_snow3g_auth_cipher_sgl( 7367 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0); 7368 } 7369 7370 static int 7371 test_snow3g_auth_cipher_part_digest_enc_sgl(void) 7372 { 7373 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 7374 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7375 return TEST_SKIPPED; 7376 return test_snow3g_auth_cipher_sgl( 7377 &snow3g_auth_cipher_partial_digest_encryption, 7378 IN_PLACE, 0); 7379 } 7380 7381 static int 7382 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void) 7383 { 7384 return test_snow3g_auth_cipher_sgl( 7385 &snow3g_auth_cipher_partial_digest_encryption, 7386 OUT_OF_PLACE, 0); 7387 } 7388 7389 static int 7390 test_snow3g_auth_cipher_total_digest_enc_1(void) 7391 { 7392 return test_snow3g_auth_cipher( 7393 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 0); 7394 } 7395 7396 static int 7397 test_snow3g_auth_cipher_total_digest_enc_1_oop(void) 7398 { 7399 return test_snow3g_auth_cipher( 7400 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 0); 7401 } 7402 7403 static int 7404 test_snow3g_auth_cipher_total_digest_enc_1_sgl(void) 7405 { 7406 return test_snow3g_auth_cipher_sgl( 7407 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 0); 7408 } 7409 7410 static int 7411 test_snow3g_auth_cipher_total_digest_enc_1_oop_sgl(void) 7412 { 7413 return test_snow3g_auth_cipher_sgl( 7414 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 0); 7415 } 7416 7417 static int 7418 test_snow3g_auth_cipher_verify_test_case_1(void) 7419 { 7420 return test_snow3g_auth_cipher( 7421 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1); 7422 } 7423 7424 static int 7425 test_snow3g_auth_cipher_verify_test_case_2(void) 7426 { 7427 return test_snow3g_auth_cipher( 7428 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1); 7429 } 7430 7431 static int 7432 test_snow3g_auth_cipher_verify_test_case_2_oop(void) 7433 { 7434 return test_snow3g_auth_cipher( 7435 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7436 } 7437 7438 static int 7439 test_snow3g_auth_cipher_verify_part_digest_enc(void) 7440 { 7441 return test_snow3g_auth_cipher( 7442 &snow3g_auth_cipher_partial_digest_encryption, 7443 IN_PLACE, 1); 7444 } 7445 7446 static int 7447 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void) 7448 { 7449 return test_snow3g_auth_cipher( 7450 &snow3g_auth_cipher_partial_digest_encryption, 7451 OUT_OF_PLACE, 1); 7452 } 7453 7454 static int 7455 test_snow3g_auth_cipher_verify_test_case_3_sgl(void) 7456 { 7457 return test_snow3g_auth_cipher_sgl( 7458 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1); 7459 } 7460 7461 static int 7462 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void) 7463 { 7464 return test_snow3g_auth_cipher_sgl( 7465 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1); 7466 } 7467 7468 static int 7469 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void) 7470 { 7471 return test_snow3g_auth_cipher_sgl( 7472 &snow3g_auth_cipher_partial_digest_encryption, 7473 IN_PLACE, 1); 7474 } 7475 7476 static int 7477 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void) 7478 { 7479 return test_snow3g_auth_cipher_sgl( 7480 &snow3g_auth_cipher_partial_digest_encryption, 7481 OUT_OF_PLACE, 1); 7482 } 7483 7484 static int 7485 test_snow3g_auth_cipher_verify_total_digest_enc_1(void) 7486 { 7487 return test_snow3g_auth_cipher( 7488 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 1); 7489 } 7490 7491 static int 7492 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop(void) 7493 { 7494 return test_snow3g_auth_cipher( 7495 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 1); 7496 } 7497 7498 static int 7499 test_snow3g_auth_cipher_verify_total_digest_enc_1_sgl(void) 7500 { 7501 return test_snow3g_auth_cipher_sgl( 7502 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 1); 7503 } 7504 7505 static int 7506 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop_sgl(void) 7507 { 7508 return test_snow3g_auth_cipher_sgl( 7509 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 1); 7510 } 7511 7512 static int 7513 test_snow3g_auth_cipher_with_digest_test_case_1(void) 7514 { 7515 return test_snow3g_auth_cipher( 7516 &snow3g_test_case_7, IN_PLACE, 0); 7517 } 7518 7519 static int 7520 test_kasumi_auth_cipher_test_case_1(void) 7521 { 7522 return test_kasumi_auth_cipher( 7523 &kasumi_test_case_3, IN_PLACE, 0); 7524 } 7525 7526 static int 7527 test_kasumi_auth_cipher_test_case_2(void) 7528 { 7529 return test_kasumi_auth_cipher( 7530 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7531 } 7532 7533 static int 7534 test_kasumi_auth_cipher_test_case_2_oop(void) 7535 { 7536 return test_kasumi_auth_cipher( 7537 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7538 } 7539 7540 static int 7541 test_kasumi_auth_cipher_test_case_2_sgl(void) 7542 { 7543 return test_kasumi_auth_cipher_sgl( 7544 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7545 } 7546 7547 static int 7548 test_kasumi_auth_cipher_test_case_2_oop_sgl(void) 7549 { 7550 return test_kasumi_auth_cipher_sgl( 7551 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7552 } 7553 7554 static int 7555 test_kasumi_auth_cipher_verify_test_case_1(void) 7556 { 7557 return test_kasumi_auth_cipher( 7558 &kasumi_test_case_3, IN_PLACE, 1); 7559 } 7560 7561 static int 7562 test_kasumi_auth_cipher_verify_test_case_2(void) 7563 { 7564 return test_kasumi_auth_cipher( 7565 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7566 } 7567 7568 static int 7569 test_kasumi_auth_cipher_verify_test_case_2_oop(void) 7570 { 7571 return test_kasumi_auth_cipher( 7572 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7573 } 7574 7575 static int 7576 test_kasumi_auth_cipher_verify_test_case_2_sgl(void) 7577 { 7578 return test_kasumi_auth_cipher_sgl( 7579 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7580 } 7581 7582 static int 7583 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void) 7584 { 7585 return test_kasumi_auth_cipher_sgl( 7586 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7587 } 7588 7589 static int 7590 test_kasumi_cipher_auth_test_case_1(void) 7591 { 7592 return test_kasumi_cipher_auth(&kasumi_test_case_6); 7593 } 7594 7595 static int 7596 test_zuc_encryption_test_case_1(void) 7597 { 7598 return test_zuc_cipher(&zuc_test_case_cipher_193b, 7599 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7600 } 7601 7602 static int 7603 test_zuc_encryption_test_case_2(void) 7604 { 7605 return test_zuc_cipher(&zuc_test_case_cipher_800b, 7606 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7607 } 7608 7609 static int 7610 test_zuc_encryption_test_case_3(void) 7611 { 7612 return test_zuc_cipher(&zuc_test_case_cipher_1570b, 7613 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7614 } 7615 7616 static int 7617 test_zuc_encryption_test_case_4(void) 7618 { 7619 return test_zuc_cipher(&zuc_test_case_cipher_2798b, 7620 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7621 } 7622 7623 static int 7624 test_zuc_encryption_test_case_5(void) 7625 { 7626 return test_zuc_cipher(&zuc_test_case_cipher_4019b, 7627 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7628 } 7629 7630 static int 7631 test_zuc_encryption_test_case_6_sgl(void) 7632 { 7633 return test_zuc_cipher_sgl(&zuc_test_case_cipher_193b, 7634 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7635 } 7636 7637 static int 7638 test_zuc_decryption_test_case_1(void) 7639 { 7640 return test_zuc_cipher(&zuc_test_case_cipher_193b, 7641 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7642 } 7643 7644 static int 7645 test_zuc_decryption_test_case_2(void) 7646 { 7647 return test_zuc_cipher(&zuc_test_case_cipher_800b, 7648 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7649 } 7650 7651 static int 7652 test_zuc_decryption_test_case_3(void) 7653 { 7654 return test_zuc_cipher(&zuc_test_case_cipher_1570b, 7655 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7656 } 7657 7658 static int 7659 test_zuc_decryption_test_case_4(void) 7660 { 7661 return test_zuc_cipher(&zuc_test_case_cipher_2798b, 7662 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7663 } 7664 7665 static int 7666 test_zuc_decryption_test_case_5(void) 7667 { 7668 return test_zuc_cipher(&zuc_test_case_cipher_4019b, 7669 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7670 } 7671 7672 static int 7673 test_zuc_decryption_test_case_6_sgl(void) 7674 { 7675 return test_zuc_cipher_sgl(&zuc_test_case_cipher_193b, 7676 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7677 } 7678 7679 static int 7680 test_zuc_hash_generate_test_case_1(void) 7681 { 7682 return test_zuc_authentication(&zuc_test_case_auth_1b, 7683 RTE_CRYPTO_AUTH_OP_GENERATE); 7684 } 7685 7686 static int 7687 test_zuc_hash_generate_test_case_2(void) 7688 { 7689 return test_zuc_authentication(&zuc_test_case_auth_90b, 7690 RTE_CRYPTO_AUTH_OP_GENERATE); 7691 } 7692 7693 static int 7694 test_zuc_hash_generate_test_case_3(void) 7695 { 7696 return test_zuc_authentication(&zuc_test_case_auth_577b, 7697 RTE_CRYPTO_AUTH_OP_GENERATE); 7698 } 7699 7700 static int 7701 test_zuc_hash_generate_test_case_4(void) 7702 { 7703 return test_zuc_authentication(&zuc_test_case_auth_2079b, 7704 RTE_CRYPTO_AUTH_OP_GENERATE); 7705 } 7706 7707 static int 7708 test_zuc_hash_generate_test_case_5(void) 7709 { 7710 return test_zuc_authentication(&zuc_test_auth_5670b, 7711 RTE_CRYPTO_AUTH_OP_GENERATE); 7712 } 7713 7714 static int 7715 test_zuc_hash_generate_test_case_6(void) 7716 { 7717 return test_zuc_authentication(&zuc_test_case_auth_128b, 7718 RTE_CRYPTO_AUTH_OP_GENERATE); 7719 } 7720 7721 static int 7722 test_zuc_hash_generate_test_case_7(void) 7723 { 7724 return test_zuc_authentication(&zuc_test_case_auth_2080b, 7725 RTE_CRYPTO_AUTH_OP_GENERATE); 7726 } 7727 7728 static int 7729 test_zuc_hash_generate_test_case_8(void) 7730 { 7731 return test_zuc_authentication(&zuc_test_case_auth_584b, 7732 RTE_CRYPTO_AUTH_OP_GENERATE); 7733 } 7734 7735 static int 7736 test_zuc_hash_verify_test_case_1(void) 7737 { 7738 return test_zuc_authentication(&zuc_test_case_auth_1b, 7739 RTE_CRYPTO_AUTH_OP_VERIFY); 7740 } 7741 7742 static int 7743 test_zuc_hash_verify_test_case_2(void) 7744 { 7745 return test_zuc_authentication(&zuc_test_case_auth_90b, 7746 RTE_CRYPTO_AUTH_OP_VERIFY); 7747 } 7748 7749 static int 7750 test_zuc_hash_verify_test_case_3(void) 7751 { 7752 return test_zuc_authentication(&zuc_test_case_auth_577b, 7753 RTE_CRYPTO_AUTH_OP_VERIFY); 7754 } 7755 7756 static int 7757 test_zuc_hash_verify_test_case_4(void) 7758 { 7759 return test_zuc_authentication(&zuc_test_case_auth_2079b, 7760 RTE_CRYPTO_AUTH_OP_VERIFY); 7761 } 7762 7763 static int 7764 test_zuc_hash_verify_test_case_5(void) 7765 { 7766 return test_zuc_authentication(&zuc_test_auth_5670b, 7767 RTE_CRYPTO_AUTH_OP_VERIFY); 7768 } 7769 7770 static int 7771 test_zuc_hash_verify_test_case_6(void) 7772 { 7773 return test_zuc_authentication(&zuc_test_case_auth_128b, 7774 RTE_CRYPTO_AUTH_OP_VERIFY); 7775 } 7776 7777 static int 7778 test_zuc_hash_verify_test_case_7(void) 7779 { 7780 return test_zuc_authentication(&zuc_test_case_auth_2080b, 7781 RTE_CRYPTO_AUTH_OP_VERIFY); 7782 } 7783 7784 static int 7785 test_zuc_hash_verify_test_case_8(void) 7786 { 7787 return test_zuc_authentication(&zuc_test_case_auth_584b, 7788 RTE_CRYPTO_AUTH_OP_VERIFY); 7789 } 7790 7791 static int 7792 test_zuc_cipher_auth_test_case_1(void) 7793 { 7794 return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b); 7795 } 7796 7797 static int 7798 test_zuc_cipher_auth_test_case_2(void) 7799 { 7800 return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b); 7801 } 7802 7803 static int 7804 test_zuc_auth_cipher_test_case_1(void) 7805 { 7806 return test_zuc_auth_cipher( 7807 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7808 } 7809 7810 static int 7811 test_zuc_auth_cipher_test_case_1_oop(void) 7812 { 7813 return test_zuc_auth_cipher( 7814 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7815 } 7816 7817 static int 7818 test_zuc_auth_cipher_test_case_1_sgl(void) 7819 { 7820 return test_zuc_auth_cipher_sgl( 7821 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7822 } 7823 7824 static int 7825 test_zuc_auth_cipher_test_case_1_oop_sgl(void) 7826 { 7827 return test_zuc_auth_cipher_sgl( 7828 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7829 } 7830 7831 static int 7832 test_zuc_auth_cipher_test_case_2(void) 7833 { 7834 return test_zuc_auth_cipher( 7835 &zuc_auth_cipher_test_case_2, IN_PLACE, 0); 7836 } 7837 7838 static int 7839 test_zuc_auth_cipher_test_case_2_oop(void) 7840 { 7841 return test_zuc_auth_cipher( 7842 &zuc_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7843 } 7844 7845 static int 7846 test_zuc_auth_cipher_verify_test_case_1(void) 7847 { 7848 return test_zuc_auth_cipher( 7849 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7850 } 7851 7852 static int 7853 test_zuc_auth_cipher_verify_test_case_1_oop(void) 7854 { 7855 return test_zuc_auth_cipher( 7856 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7857 } 7858 7859 static int 7860 test_zuc_auth_cipher_verify_test_case_1_sgl(void) 7861 { 7862 return test_zuc_auth_cipher_sgl( 7863 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7864 } 7865 7866 static int 7867 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void) 7868 { 7869 return test_zuc_auth_cipher_sgl( 7870 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7871 } 7872 7873 static int 7874 test_zuc_auth_cipher_verify_test_case_2(void) 7875 { 7876 return test_zuc_auth_cipher( 7877 &zuc_auth_cipher_test_case_2, IN_PLACE, 1); 7878 } 7879 7880 static int 7881 test_zuc_auth_cipher_verify_test_case_2_oop(void) 7882 { 7883 return test_zuc_auth_cipher( 7884 &zuc_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7885 } 7886 7887 static int 7888 test_zuc256_encryption_test_case_1(void) 7889 { 7890 return test_zuc_cipher(&zuc256_test_case_cipher_1, 7891 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7892 } 7893 7894 static int 7895 test_zuc256_encryption_test_case_2(void) 7896 { 7897 return test_zuc_cipher(&zuc256_test_case_cipher_2, 7898 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7899 } 7900 7901 static int 7902 test_zuc256_decryption_test_case_1(void) 7903 { 7904 return test_zuc_cipher(&zuc256_test_case_cipher_1, 7905 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7906 } 7907 7908 static int 7909 test_zuc256_decryption_test_case_2(void) 7910 { 7911 return test_zuc_cipher(&zuc256_test_case_cipher_2, 7912 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7913 } 7914 7915 static int 7916 test_zuc256_hash_generate_4b_tag_test_case_1(void) 7917 { 7918 return test_zuc_authentication(&zuc256_test_case_auth_1, 7919 RTE_CRYPTO_AUTH_OP_GENERATE); 7920 } 7921 7922 static int 7923 test_zuc256_hash_generate_4b_tag_test_case_2(void) 7924 { 7925 return test_zuc_authentication(&zuc256_test_case_auth_2, 7926 RTE_CRYPTO_AUTH_OP_GENERATE); 7927 } 7928 7929 static int 7930 test_zuc256_hash_generate_4b_tag_test_case_3(void) 7931 { 7932 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b, 7933 RTE_CRYPTO_AUTH_OP_GENERATE); 7934 } 7935 7936 static int 7937 test_zuc256_hash_generate_8b_tag_test_case_1(void) 7938 { 7939 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b, 7940 RTE_CRYPTO_AUTH_OP_GENERATE); 7941 } 7942 7943 static int 7944 test_zuc256_hash_generate_16b_tag_test_case_1(void) 7945 { 7946 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b, 7947 RTE_CRYPTO_AUTH_OP_GENERATE); 7948 } 7949 7950 static int 7951 test_zuc256_hash_verify_4b_tag_test_case_1(void) 7952 { 7953 return test_zuc_authentication(&zuc256_test_case_auth_1, 7954 RTE_CRYPTO_AUTH_OP_VERIFY); 7955 } 7956 7957 static int 7958 test_zuc256_hash_verify_4b_tag_test_case_2(void) 7959 { 7960 return test_zuc_authentication(&zuc256_test_case_auth_2, 7961 RTE_CRYPTO_AUTH_OP_VERIFY); 7962 } 7963 7964 static int 7965 test_zuc256_hash_verify_4b_tag_test_case_3(void) 7966 { 7967 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b, 7968 RTE_CRYPTO_AUTH_OP_VERIFY); 7969 } 7970 7971 static int 7972 test_zuc256_hash_verify_8b_tag_test_case_1(void) 7973 { 7974 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b, 7975 RTE_CRYPTO_AUTH_OP_VERIFY); 7976 } 7977 7978 static int 7979 test_zuc256_hash_verify_16b_tag_test_case_1(void) 7980 { 7981 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b, 7982 RTE_CRYPTO_AUTH_OP_VERIFY); 7983 } 7984 7985 static int 7986 test_zuc256_cipher_auth_4b_tag_test_case_1(void) 7987 { 7988 return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_1); 7989 } 7990 7991 static int 7992 test_zuc256_cipher_auth_4b_tag_test_case_2(void) 7993 { 7994 return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_2); 7995 } 7996 7997 static int 7998 test_zuc256_cipher_auth_8b_tag_test_case_1(void) 7999 { 8000 return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_3); 8001 } 8002 8003 static int 8004 test_zuc256_cipher_auth_16b_tag_test_case_1(void) 8005 { 8006 return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_4); 8007 } 8008 8009 static int 8010 test_zuc256_auth_cipher_4b_tag_test_case_1(void) 8011 { 8012 return test_zuc_auth_cipher( 8013 &zuc256_auth_cipher_test_case_1, IN_PLACE, 0); 8014 } 8015 8016 static int 8017 test_zuc256_auth_cipher_4b_tag_test_case_2(void) 8018 { 8019 return test_zuc_auth_cipher( 8020 &zuc256_auth_cipher_test_case_2, IN_PLACE, 0); 8021 } 8022 8023 static int 8024 test_zuc256_auth_cipher_8b_tag_test_case_1(void) 8025 { 8026 return test_zuc_auth_cipher( 8027 &zuc256_auth_cipher_test_case_3, IN_PLACE, 0); 8028 } 8029 8030 static int 8031 test_zuc256_auth_cipher_16b_tag_test_case_1(void) 8032 { 8033 return test_zuc_auth_cipher( 8034 &zuc256_auth_cipher_test_case_4, IN_PLACE, 0); 8035 } 8036 8037 static int 8038 test_zuc256_auth_cipher_verify_4b_tag_test_case_1(void) 8039 { 8040 return test_zuc_auth_cipher( 8041 &zuc256_auth_cipher_test_case_1, IN_PLACE, 1); 8042 } 8043 8044 static int 8045 test_zuc256_auth_cipher_verify_4b_tag_test_case_2(void) 8046 { 8047 return test_zuc_auth_cipher( 8048 &zuc256_auth_cipher_test_case_2, IN_PLACE, 1); 8049 } 8050 8051 static int 8052 test_zuc256_auth_cipher_verify_8b_tag_test_case_1(void) 8053 { 8054 return test_zuc_auth_cipher( 8055 &zuc256_auth_cipher_test_case_3, IN_PLACE, 1); 8056 } 8057 8058 static int 8059 test_zuc256_auth_cipher_verify_16b_tag_test_case_1(void) 8060 { 8061 return test_zuc_auth_cipher( 8062 &zuc256_auth_cipher_test_case_4, IN_PLACE, 1); 8063 } 8064 8065 static int 8066 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata) 8067 { 8068 uint8_t dev_id = testsuite_params.valid_devs[0]; 8069 8070 struct rte_cryptodev_sym_capability_idx cap_idx; 8071 8072 /* Check if device supports particular cipher algorithm */ 8073 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8074 cap_idx.algo.cipher = tdata->cipher_algo; 8075 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 8076 return TEST_SKIPPED; 8077 8078 /* Check if device supports particular hash algorithm */ 8079 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8080 cap_idx.algo.auth = tdata->auth_algo; 8081 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 8082 return TEST_SKIPPED; 8083 8084 return 0; 8085 } 8086 8087 static int 8088 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata, 8089 uint8_t op_mode, uint8_t verify) 8090 { 8091 struct crypto_testsuite_params *ts_params = &testsuite_params; 8092 struct crypto_unittest_params *ut_params = &unittest_params; 8093 8094 int retval; 8095 8096 uint8_t *plaintext = NULL, *ciphertext = NULL; 8097 unsigned int plaintext_pad_len; 8098 unsigned int plaintext_len; 8099 unsigned int ciphertext_pad_len; 8100 unsigned int ciphertext_len; 8101 unsigned int digest_offset; 8102 8103 struct rte_cryptodev_info dev_info; 8104 struct rte_crypto_op *op; 8105 8106 /* Check if device supports particular algorithms separately */ 8107 if (test_mixed_check_if_unsupported(tdata)) 8108 return TEST_SKIPPED; 8109 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 8110 return TEST_SKIPPED; 8111 8112 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8113 return TEST_SKIPPED; 8114 8115 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8116 8117 uint64_t feat_flags = dev_info.feature_flags; 8118 8119 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 8120 printf("Device doesn't support digest encrypted.\n"); 8121 return TEST_SKIPPED; 8122 } 8123 8124 /* Create the session */ 8125 if (verify) 8126 retval = create_wireless_algo_cipher_auth_session( 8127 ts_params->valid_devs[0], 8128 RTE_CRYPTO_CIPHER_OP_DECRYPT, 8129 RTE_CRYPTO_AUTH_OP_VERIFY, 8130 tdata->auth_algo, 8131 tdata->cipher_algo, 8132 tdata->auth_key.data, tdata->auth_key.len, 8133 tdata->cipher_key.data, tdata->cipher_key.len, 8134 tdata->auth_iv.len, tdata->digest_enc.len, 8135 tdata->cipher_iv.len); 8136 else 8137 retval = create_wireless_algo_auth_cipher_session( 8138 ts_params->valid_devs[0], 8139 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8140 RTE_CRYPTO_AUTH_OP_GENERATE, 8141 tdata->auth_algo, 8142 tdata->cipher_algo, 8143 tdata->auth_key.data, tdata->auth_key.len, 8144 tdata->cipher_key.data, tdata->cipher_key.len, 8145 tdata->auth_iv.len, tdata->digest_enc.len, 8146 tdata->cipher_iv.len); 8147 if (retval != 0) 8148 return retval; 8149 8150 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8151 if (op_mode == OUT_OF_PLACE) 8152 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8153 8154 /* clear mbuf payload */ 8155 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8156 rte_pktmbuf_tailroom(ut_params->ibuf)); 8157 if (op_mode == OUT_OF_PLACE) { 8158 8159 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 8160 rte_pktmbuf_tailroom(ut_params->obuf)); 8161 } 8162 8163 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 8164 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 8165 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 8166 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 8167 8168 if (verify) { 8169 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8170 ciphertext_pad_len); 8171 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 8172 debug_hexdump(stdout, "ciphertext:", ciphertext, 8173 ciphertext_len); 8174 } else { 8175 /* make sure enough space to cover partial digest verify case */ 8176 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8177 ciphertext_pad_len); 8178 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 8179 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 8180 } 8181 8182 if (op_mode == OUT_OF_PLACE) 8183 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 8184 8185 /* Create the operation */ 8186 retval = create_wireless_algo_auth_cipher_operation( 8187 tdata->digest_enc.data, tdata->digest_enc.len, 8188 tdata->cipher_iv.data, tdata->cipher_iv.len, 8189 tdata->auth_iv.data, tdata->auth_iv.len, 8190 (tdata->digest_enc.offset == 0 ? 8191 plaintext_pad_len 8192 : tdata->digest_enc.offset), 8193 tdata->validCipherLen.len_bits, 8194 tdata->cipher.offset_bits, 8195 tdata->validAuthLen.len_bits, 8196 tdata->auth.offset_bits, 8197 op_mode, 0, verify); 8198 8199 if (retval < 0) 8200 return retval; 8201 8202 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 8203 8204 /* Check if the op failed because the device doesn't */ 8205 /* support this particular combination of algorithms */ 8206 if (op == NULL && ut_params->op->status == 8207 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 8208 printf("Device doesn't support this mixed combination. " 8209 "Test Skipped.\n"); 8210 return TEST_SKIPPED; 8211 } 8212 ut_params->op = op; 8213 8214 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 8215 8216 ut_params->obuf = (op_mode == IN_PLACE ? 8217 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 8218 8219 if (verify) { 8220 if (ut_params->obuf) 8221 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 8222 uint8_t *); 8223 else 8224 plaintext = ciphertext + 8225 (tdata->cipher.offset_bits >> 3); 8226 8227 debug_hexdump(stdout, "plaintext:", plaintext, 8228 tdata->plaintext.len_bits >> 3); 8229 debug_hexdump(stdout, "plaintext expected:", 8230 tdata->plaintext.data, 8231 tdata->plaintext.len_bits >> 3); 8232 } else { 8233 if (ut_params->obuf) 8234 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 8235 uint8_t *); 8236 else 8237 ciphertext = plaintext; 8238 8239 debug_hexdump(stdout, "ciphertext:", ciphertext, 8240 ciphertext_len); 8241 debug_hexdump(stdout, "ciphertext expected:", 8242 tdata->ciphertext.data, 8243 tdata->ciphertext.len_bits >> 3); 8244 8245 if (tdata->digest_enc.offset == 0) 8246 digest_offset = plaintext_pad_len; 8247 else 8248 digest_offset = tdata->digest_enc.offset; 8249 8250 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 8251 uint8_t *, digest_offset); 8252 8253 debug_hexdump(stdout, "digest:", ut_params->digest, 8254 tdata->digest_enc.len); 8255 debug_hexdump(stdout, "digest expected:", 8256 tdata->digest_enc.data, 8257 tdata->digest_enc.len); 8258 } 8259 8260 if (!verify) { 8261 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8262 ut_params->digest, 8263 tdata->digest_enc.data, 8264 tdata->digest_enc.len, 8265 "Generated auth tag not as expected"); 8266 } 8267 8268 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 8269 if (verify) { 8270 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 8271 plaintext, 8272 tdata->plaintext.data, 8273 tdata->plaintext.len_bits >> 3, 8274 "Plaintext data not as expected"); 8275 } else { 8276 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 8277 ciphertext, 8278 tdata->ciphertext.data, 8279 tdata->validDataLen.len_bits, 8280 "Ciphertext data not as expected"); 8281 } 8282 } 8283 8284 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8285 "crypto op processing failed"); 8286 8287 return 0; 8288 } 8289 8290 static int 8291 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata, 8292 uint8_t op_mode, uint8_t verify) 8293 { 8294 struct crypto_testsuite_params *ts_params = &testsuite_params; 8295 struct crypto_unittest_params *ut_params = &unittest_params; 8296 8297 int retval; 8298 8299 const uint8_t *plaintext = NULL; 8300 const uint8_t *ciphertext = NULL; 8301 const uint8_t *digest = NULL; 8302 unsigned int plaintext_pad_len; 8303 unsigned int plaintext_len; 8304 unsigned int ciphertext_pad_len; 8305 unsigned int ciphertext_len; 8306 uint8_t buffer[10000]; 8307 uint8_t digest_buffer[10000]; 8308 8309 struct rte_cryptodev_info dev_info; 8310 struct rte_crypto_op *op; 8311 8312 /* Check if device supports particular algorithms */ 8313 if (test_mixed_check_if_unsupported(tdata)) 8314 return TEST_SKIPPED; 8315 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 8316 return TEST_SKIPPED; 8317 8318 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8319 8320 uint64_t feat_flags = dev_info.feature_flags; 8321 8322 if (op_mode == IN_PLACE) { 8323 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 8324 printf("Device doesn't support in-place scatter-gather " 8325 "in both input and output mbufs.\n"); 8326 return TEST_SKIPPED; 8327 } 8328 } else { 8329 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 8330 printf("Device doesn't support out-of-place scatter-gather " 8331 "in both input and output mbufs.\n"); 8332 return TEST_SKIPPED; 8333 } 8334 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 8335 printf("Device doesn't support digest encrypted.\n"); 8336 return TEST_SKIPPED; 8337 } 8338 } 8339 8340 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8341 return TEST_SKIPPED; 8342 8343 /* Create the session */ 8344 if (verify) 8345 retval = create_wireless_algo_cipher_auth_session( 8346 ts_params->valid_devs[0], 8347 RTE_CRYPTO_CIPHER_OP_DECRYPT, 8348 RTE_CRYPTO_AUTH_OP_VERIFY, 8349 tdata->auth_algo, 8350 tdata->cipher_algo, 8351 tdata->auth_key.data, tdata->auth_key.len, 8352 tdata->cipher_key.data, tdata->cipher_key.len, 8353 tdata->auth_iv.len, tdata->digest_enc.len, 8354 tdata->cipher_iv.len); 8355 else 8356 retval = create_wireless_algo_auth_cipher_session( 8357 ts_params->valid_devs[0], 8358 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8359 RTE_CRYPTO_AUTH_OP_GENERATE, 8360 tdata->auth_algo, 8361 tdata->cipher_algo, 8362 tdata->auth_key.data, tdata->auth_key.len, 8363 tdata->cipher_key.data, tdata->cipher_key.len, 8364 tdata->auth_iv.len, tdata->digest_enc.len, 8365 tdata->cipher_iv.len); 8366 if (retval != 0) 8367 return retval; 8368 8369 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 8370 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 8371 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 8372 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 8373 8374 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 8375 ciphertext_pad_len, 15, 0); 8376 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 8377 "Failed to allocate input buffer in mempool"); 8378 8379 if (op_mode == OUT_OF_PLACE) { 8380 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 8381 plaintext_pad_len, 15, 0); 8382 TEST_ASSERT_NOT_NULL(ut_params->obuf, 8383 "Failed to allocate output buffer in mempool"); 8384 } 8385 8386 if (verify) { 8387 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 8388 tdata->ciphertext.data); 8389 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 8390 ciphertext_len, buffer); 8391 debug_hexdump(stdout, "ciphertext:", ciphertext, 8392 ciphertext_len); 8393 } else { 8394 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 8395 tdata->plaintext.data); 8396 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 8397 plaintext_len, buffer); 8398 debug_hexdump(stdout, "plaintext:", plaintext, 8399 plaintext_len); 8400 } 8401 memset(buffer, 0, sizeof(buffer)); 8402 8403 /* Create the operation */ 8404 retval = create_wireless_algo_auth_cipher_operation( 8405 tdata->digest_enc.data, tdata->digest_enc.len, 8406 tdata->cipher_iv.data, tdata->cipher_iv.len, 8407 tdata->auth_iv.data, tdata->auth_iv.len, 8408 (tdata->digest_enc.offset == 0 ? 8409 plaintext_pad_len 8410 : tdata->digest_enc.offset), 8411 tdata->validCipherLen.len_bits, 8412 tdata->cipher.offset_bits, 8413 tdata->validAuthLen.len_bits, 8414 tdata->auth.offset_bits, 8415 op_mode, 1, verify); 8416 8417 if (retval < 0) 8418 return retval; 8419 8420 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 8421 8422 /* Check if the op failed because the device doesn't */ 8423 /* support this particular combination of algorithms */ 8424 if (op == NULL && ut_params->op->status == 8425 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 8426 printf("Device doesn't support this mixed combination. " 8427 "Test Skipped.\n"); 8428 return TEST_SKIPPED; 8429 } 8430 ut_params->op = op; 8431 8432 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 8433 8434 ut_params->obuf = (op_mode == IN_PLACE ? 8435 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 8436 8437 if (verify) { 8438 if (ut_params->obuf) 8439 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 8440 plaintext_len, buffer); 8441 else 8442 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 8443 plaintext_len, buffer); 8444 8445 debug_hexdump(stdout, "plaintext:", plaintext, 8446 (tdata->plaintext.len_bits >> 3) - 8447 tdata->digest_enc.len); 8448 debug_hexdump(stdout, "plaintext expected:", 8449 tdata->plaintext.data, 8450 (tdata->plaintext.len_bits >> 3) - 8451 tdata->digest_enc.len); 8452 } else { 8453 if (ut_params->obuf) 8454 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 8455 ciphertext_len, buffer); 8456 else 8457 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 8458 ciphertext_len, buffer); 8459 8460 debug_hexdump(stdout, "ciphertext:", ciphertext, 8461 ciphertext_len); 8462 debug_hexdump(stdout, "ciphertext expected:", 8463 tdata->ciphertext.data, 8464 tdata->ciphertext.len_bits >> 3); 8465 8466 if (ut_params->obuf) 8467 digest = rte_pktmbuf_read(ut_params->obuf, 8468 (tdata->digest_enc.offset == 0 ? 8469 plaintext_pad_len : 8470 tdata->digest_enc.offset), 8471 tdata->digest_enc.len, digest_buffer); 8472 else 8473 digest = rte_pktmbuf_read(ut_params->ibuf, 8474 (tdata->digest_enc.offset == 0 ? 8475 plaintext_pad_len : 8476 tdata->digest_enc.offset), 8477 tdata->digest_enc.len, digest_buffer); 8478 8479 debug_hexdump(stdout, "digest:", digest, 8480 tdata->digest_enc.len); 8481 debug_hexdump(stdout, "digest expected:", 8482 tdata->digest_enc.data, tdata->digest_enc.len); 8483 } 8484 8485 if (!verify) { 8486 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8487 digest, 8488 tdata->digest_enc.data, 8489 tdata->digest_enc.len, 8490 "Generated auth tag not as expected"); 8491 } 8492 8493 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 8494 if (verify) { 8495 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 8496 plaintext, 8497 tdata->plaintext.data, 8498 tdata->plaintext.len_bits >> 3, 8499 "Plaintext data not as expected"); 8500 } else { 8501 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 8502 ciphertext, 8503 tdata->ciphertext.data, 8504 tdata->validDataLen.len_bits, 8505 "Ciphertext data not as expected"); 8506 } 8507 } 8508 8509 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8510 "crypto op processing failed"); 8511 8512 return 0; 8513 } 8514 8515 /** AUTH AES CMAC + CIPHER AES CTR */ 8516 8517 static int 8518 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 8519 { 8520 return test_mixed_auth_cipher( 8521 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8522 } 8523 8524 static int 8525 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 8526 { 8527 return test_mixed_auth_cipher( 8528 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8529 } 8530 8531 static int 8532 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 8533 { 8534 return test_mixed_auth_cipher_sgl( 8535 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8536 } 8537 8538 static int 8539 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 8540 { 8541 return test_mixed_auth_cipher_sgl( 8542 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8543 } 8544 8545 static int 8546 test_aes_cmac_aes_ctr_digest_enc_test_case_2(void) 8547 { 8548 return test_mixed_auth_cipher( 8549 &auth_aes_cmac_cipher_aes_ctr_test_case_2, IN_PLACE, 0); 8550 } 8551 8552 static int 8553 test_aes_cmac_aes_ctr_digest_enc_test_case_2_oop(void) 8554 { 8555 return test_mixed_auth_cipher( 8556 &auth_aes_cmac_cipher_aes_ctr_test_case_2, OUT_OF_PLACE, 0); 8557 } 8558 8559 static int 8560 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 8561 { 8562 return test_mixed_auth_cipher( 8563 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8564 } 8565 8566 static int 8567 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2(void) 8568 { 8569 return test_mixed_auth_cipher( 8570 &auth_aes_cmac_cipher_aes_ctr_test_case_2, IN_PLACE, 1); 8571 } 8572 8573 static int 8574 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 8575 { 8576 return test_mixed_auth_cipher( 8577 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8578 } 8579 8580 static int 8581 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 8582 { 8583 return test_mixed_auth_cipher_sgl( 8584 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8585 } 8586 8587 static int 8588 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 8589 { 8590 return test_mixed_auth_cipher_sgl( 8591 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8592 } 8593 8594 static int 8595 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2_oop(void) 8596 { 8597 return test_mixed_auth_cipher( 8598 &auth_aes_cmac_cipher_aes_ctr_test_case_2, OUT_OF_PLACE, 1); 8599 } 8600 8601 /** MIXED AUTH + CIPHER */ 8602 8603 static int 8604 test_auth_zuc_cipher_snow_test_case_1(void) 8605 { 8606 return test_mixed_auth_cipher( 8607 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 8608 } 8609 8610 static int 8611 test_verify_auth_zuc_cipher_snow_test_case_1(void) 8612 { 8613 return test_mixed_auth_cipher( 8614 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 8615 } 8616 8617 static int 8618 test_auth_zuc_cipher_snow_test_case_1_inplace(void) 8619 { 8620 return test_mixed_auth_cipher( 8621 &auth_zuc_cipher_snow_test_case_1, IN_PLACE, 0); 8622 } 8623 8624 static int 8625 test_verify_auth_zuc_cipher_snow_test_case_1_inplace(void) 8626 { 8627 return test_mixed_auth_cipher( 8628 &auth_zuc_cipher_snow_test_case_1, IN_PLACE, 1); 8629 } 8630 8631 8632 static int 8633 test_auth_aes_cmac_cipher_snow_test_case_1(void) 8634 { 8635 return test_mixed_auth_cipher( 8636 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 8637 } 8638 8639 static int 8640 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void) 8641 { 8642 return test_mixed_auth_cipher( 8643 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 8644 } 8645 8646 static int 8647 test_auth_aes_cmac_cipher_snow_test_case_1_inplace(void) 8648 { 8649 return test_mixed_auth_cipher( 8650 &auth_aes_cmac_cipher_snow_test_case_1, IN_PLACE, 0); 8651 } 8652 8653 static int 8654 test_verify_auth_aes_cmac_cipher_snow_test_case_1_inplace(void) 8655 { 8656 return test_mixed_auth_cipher( 8657 &auth_aes_cmac_cipher_snow_test_case_1, IN_PLACE, 1); 8658 } 8659 8660 static int 8661 test_auth_zuc_cipher_aes_ctr_test_case_1(void) 8662 { 8663 return test_mixed_auth_cipher( 8664 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8665 } 8666 8667 static int 8668 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void) 8669 { 8670 return test_mixed_auth_cipher( 8671 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8672 } 8673 8674 static int 8675 test_auth_zuc_cipher_aes_ctr_test_case_1_inplace(void) 8676 { 8677 return test_mixed_auth_cipher( 8678 &auth_zuc_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8679 } 8680 8681 static int 8682 test_verify_auth_zuc_cipher_aes_ctr_test_case_1_inplace(void) 8683 { 8684 return test_mixed_auth_cipher( 8685 &auth_zuc_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8686 } 8687 8688 static int 8689 test_auth_snow_cipher_aes_ctr_test_case_1(void) 8690 { 8691 return test_mixed_auth_cipher( 8692 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8693 } 8694 8695 static int 8696 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void) 8697 { 8698 return test_mixed_auth_cipher( 8699 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8700 } 8701 8702 static int 8703 test_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl(void) 8704 { 8705 return test_mixed_auth_cipher_sgl( 8706 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8707 } 8708 8709 static int 8710 test_auth_snow_cipher_aes_ctr_test_case_1_inplace(void) 8711 { 8712 return test_mixed_auth_cipher( 8713 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8714 } 8715 8716 static int 8717 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl(void) 8718 { 8719 return test_mixed_auth_cipher_sgl( 8720 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8721 } 8722 8723 static int 8724 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace(void) 8725 { 8726 return test_mixed_auth_cipher( 8727 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8728 } 8729 8730 static int 8731 test_auth_snow_cipher_zuc_test_case_1(void) 8732 { 8733 return test_mixed_auth_cipher( 8734 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 8735 } 8736 8737 static int 8738 test_verify_auth_snow_cipher_zuc_test_case_1(void) 8739 { 8740 return test_mixed_auth_cipher( 8741 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 8742 } 8743 8744 static int 8745 test_auth_snow_cipher_zuc_test_case_1_inplace(void) 8746 { 8747 return test_mixed_auth_cipher( 8748 &auth_snow_cipher_zuc_test_case_1, IN_PLACE, 0); 8749 } 8750 8751 static int 8752 test_verify_auth_snow_cipher_zuc_test_case_1_inplace(void) 8753 { 8754 return test_mixed_auth_cipher( 8755 &auth_snow_cipher_zuc_test_case_1, IN_PLACE, 1); 8756 } 8757 8758 static int 8759 test_auth_aes_cmac_cipher_zuc_test_case_1(void) 8760 { 8761 return test_mixed_auth_cipher( 8762 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 8763 } 8764 8765 static int 8766 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void) 8767 { 8768 return test_mixed_auth_cipher( 8769 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 8770 } 8771 static int 8772 test_auth_aes_cmac_cipher_zuc_test_case_1_inplace(void) 8773 { 8774 return test_mixed_auth_cipher( 8775 &auth_aes_cmac_cipher_zuc_test_case_1, IN_PLACE, 0); 8776 } 8777 8778 static int 8779 test_verify_auth_aes_cmac_cipher_zuc_test_case_1_inplace(void) 8780 { 8781 return test_mixed_auth_cipher( 8782 &auth_aes_cmac_cipher_zuc_test_case_1, IN_PLACE, 1); 8783 } 8784 8785 static int 8786 test_auth_null_cipher_snow_test_case_1(void) 8787 { 8788 return test_mixed_auth_cipher( 8789 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 8790 } 8791 8792 static int 8793 test_verify_auth_null_cipher_snow_test_case_1(void) 8794 { 8795 return test_mixed_auth_cipher( 8796 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 8797 } 8798 8799 static int 8800 test_auth_null_cipher_zuc_test_case_1(void) 8801 { 8802 return test_mixed_auth_cipher( 8803 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 8804 } 8805 8806 static int 8807 test_verify_auth_null_cipher_zuc_test_case_1(void) 8808 { 8809 return test_mixed_auth_cipher( 8810 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 8811 } 8812 8813 static int 8814 test_auth_snow_cipher_null_test_case_1(void) 8815 { 8816 return test_mixed_auth_cipher( 8817 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0); 8818 } 8819 8820 static int 8821 test_verify_auth_snow_cipher_null_test_case_1(void) 8822 { 8823 return test_mixed_auth_cipher( 8824 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1); 8825 } 8826 8827 static int 8828 test_auth_zuc_cipher_null_test_case_1(void) 8829 { 8830 return test_mixed_auth_cipher( 8831 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0); 8832 } 8833 8834 static int 8835 test_verify_auth_zuc_cipher_null_test_case_1(void) 8836 { 8837 return test_mixed_auth_cipher( 8838 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1); 8839 } 8840 8841 static int 8842 test_auth_null_cipher_aes_ctr_test_case_1(void) 8843 { 8844 return test_mixed_auth_cipher( 8845 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8846 } 8847 8848 static int 8849 test_verify_auth_null_cipher_aes_ctr_test_case_1(void) 8850 { 8851 return test_mixed_auth_cipher( 8852 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8853 } 8854 8855 static int 8856 test_auth_aes_cmac_cipher_null_test_case_1(void) 8857 { 8858 return test_mixed_auth_cipher( 8859 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0); 8860 } 8861 8862 static int 8863 test_verify_auth_aes_cmac_cipher_null_test_case_1(void) 8864 { 8865 return test_mixed_auth_cipher( 8866 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1); 8867 } 8868 8869 /* ***** AEAD algorithm Tests ***** */ 8870 8871 static int 8872 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo, 8873 enum rte_crypto_aead_operation op, 8874 const uint8_t *key, const uint8_t key_len, 8875 const uint16_t aad_len, const uint8_t auth_len, 8876 uint8_t iv_len) 8877 { 8878 uint8_t aead_key[key_len]; 8879 8880 struct crypto_testsuite_params *ts_params = &testsuite_params; 8881 struct crypto_unittest_params *ut_params = &unittest_params; 8882 8883 memcpy(aead_key, key, key_len); 8884 8885 /* Setup AEAD Parameters */ 8886 ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 8887 ut_params->aead_xform.next = NULL; 8888 ut_params->aead_xform.aead.algo = algo; 8889 ut_params->aead_xform.aead.op = op; 8890 ut_params->aead_xform.aead.key.data = aead_key; 8891 ut_params->aead_xform.aead.key.length = key_len; 8892 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 8893 ut_params->aead_xform.aead.iv.length = iv_len; 8894 ut_params->aead_xform.aead.digest_length = auth_len; 8895 ut_params->aead_xform.aead.aad_length = aad_len; 8896 8897 debug_hexdump(stdout, "key:", key, key_len); 8898 8899 /* Create Crypto session*/ 8900 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 8901 &ut_params->aead_xform, ts_params->session_mpool); 8902 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 8903 return TEST_SKIPPED; 8904 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 8905 return 0; 8906 } 8907 8908 static int 8909 create_aead_xform(struct rte_crypto_op *op, 8910 enum rte_crypto_aead_algorithm algo, 8911 enum rte_crypto_aead_operation aead_op, 8912 uint8_t *key, const uint8_t key_len, 8913 const uint8_t aad_len, const uint8_t auth_len, 8914 uint8_t iv_len) 8915 { 8916 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1), 8917 "failed to allocate space for crypto transform"); 8918 8919 struct rte_crypto_sym_op *sym_op = op->sym; 8920 8921 /* Setup AEAD Parameters */ 8922 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD; 8923 sym_op->xform->next = NULL; 8924 sym_op->xform->aead.algo = algo; 8925 sym_op->xform->aead.op = aead_op; 8926 sym_op->xform->aead.key.data = key; 8927 sym_op->xform->aead.key.length = key_len; 8928 sym_op->xform->aead.iv.offset = IV_OFFSET; 8929 sym_op->xform->aead.iv.length = iv_len; 8930 sym_op->xform->aead.digest_length = auth_len; 8931 sym_op->xform->aead.aad_length = aad_len; 8932 8933 debug_hexdump(stdout, "key:", key, key_len); 8934 8935 return 0; 8936 } 8937 8938 static int 8939 create_aead_operation(enum rte_crypto_aead_operation op, 8940 const struct aead_test_data *tdata) 8941 { 8942 struct crypto_testsuite_params *ts_params = &testsuite_params; 8943 struct crypto_unittest_params *ut_params = &unittest_params; 8944 8945 uint8_t *plaintext, *ciphertext; 8946 unsigned int aad_pad_len, plaintext_pad_len; 8947 8948 /* Generate Crypto op data structure */ 8949 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8950 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8951 TEST_ASSERT_NOT_NULL(ut_params->op, 8952 "Failed to allocate symmetric crypto operation struct"); 8953 8954 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 8955 8956 /* Append aad data */ 8957 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 8958 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16); 8959 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8960 aad_pad_len); 8961 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8962 "no room to append aad"); 8963 8964 sym_op->aead.aad.phys_addr = 8965 rte_pktmbuf_iova(ut_params->ibuf); 8966 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 8967 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len); 8968 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data + 18, 8969 tdata->aad.len); 8970 8971 /* Append IV at the end of the crypto operation*/ 8972 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8973 uint8_t *, IV_OFFSET); 8974 8975 /* Copy IV 1 byte after the IV pointer, according to the API */ 8976 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len); 8977 debug_hexdump(stdout, "iv:", iv_ptr + 1, 8978 tdata->iv.len); 8979 } else { 8980 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 8981 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8982 aad_pad_len); 8983 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8984 "no room to append aad"); 8985 8986 sym_op->aead.aad.phys_addr = 8987 rte_pktmbuf_iova(ut_params->ibuf); 8988 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len); 8989 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 8990 tdata->aad.len); 8991 8992 /* Append IV at the end of the crypto operation*/ 8993 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8994 uint8_t *, IV_OFFSET); 8995 8996 if (tdata->iv.len == 0) { 8997 rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH); 8998 debug_hexdump(stdout, "iv:", iv_ptr, 8999 AES_GCM_J0_LENGTH); 9000 } else { 9001 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 9002 debug_hexdump(stdout, "iv:", iv_ptr, 9003 tdata->iv.len); 9004 } 9005 } 9006 9007 /* Append plaintext/ciphertext */ 9008 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 9009 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 9010 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9011 plaintext_pad_len); 9012 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 9013 9014 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 9015 debug_hexdump(stdout, "plaintext:", plaintext, 9016 tdata->plaintext.len); 9017 9018 if (ut_params->obuf) { 9019 ciphertext = (uint8_t *)rte_pktmbuf_append( 9020 ut_params->obuf, 9021 plaintext_pad_len + aad_pad_len); 9022 TEST_ASSERT_NOT_NULL(ciphertext, 9023 "no room to append ciphertext"); 9024 9025 memset(ciphertext + aad_pad_len, 0, 9026 tdata->ciphertext.len); 9027 } 9028 } else { 9029 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); 9030 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9031 plaintext_pad_len); 9032 TEST_ASSERT_NOT_NULL(ciphertext, 9033 "no room to append ciphertext"); 9034 9035 memcpy(ciphertext, tdata->ciphertext.data, 9036 tdata->ciphertext.len); 9037 debug_hexdump(stdout, "ciphertext:", ciphertext, 9038 tdata->ciphertext.len); 9039 9040 if (ut_params->obuf) { 9041 plaintext = (uint8_t *)rte_pktmbuf_append( 9042 ut_params->obuf, 9043 plaintext_pad_len + aad_pad_len); 9044 TEST_ASSERT_NOT_NULL(plaintext, 9045 "no room to append plaintext"); 9046 9047 memset(plaintext + aad_pad_len, 0, 9048 tdata->plaintext.len); 9049 } 9050 } 9051 9052 /* Append digest data */ 9053 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 9054 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 9055 ut_params->obuf ? ut_params->obuf : 9056 ut_params->ibuf, 9057 tdata->auth_tag.len); 9058 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 9059 "no room to append digest"); 9060 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len); 9061 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 9062 ut_params->obuf ? ut_params->obuf : 9063 ut_params->ibuf, 9064 plaintext_pad_len + 9065 aad_pad_len); 9066 } else { 9067 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 9068 ut_params->ibuf, tdata->auth_tag.len); 9069 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 9070 "no room to append digest"); 9071 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 9072 ut_params->ibuf, 9073 plaintext_pad_len + aad_pad_len); 9074 9075 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 9076 tdata->auth_tag.len); 9077 debug_hexdump(stdout, "digest:", 9078 sym_op->aead.digest.data, 9079 tdata->auth_tag.len); 9080 } 9081 9082 sym_op->aead.data.length = tdata->plaintext.len; 9083 sym_op->aead.data.offset = aad_pad_len; 9084 9085 return 0; 9086 } 9087 9088 static int 9089 test_authenticated_encryption_helper(const struct aead_test_data *tdata, bool use_ext_mbuf) 9090 { 9091 struct crypto_testsuite_params *ts_params = &testsuite_params; 9092 struct crypto_unittest_params *ut_params = &unittest_params; 9093 9094 int retval; 9095 uint8_t *ciphertext, *auth_tag; 9096 uint16_t plaintext_pad_len; 9097 uint32_t i; 9098 struct rte_cryptodev_info dev_info; 9099 9100 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9101 uint64_t feat_flags = dev_info.feature_flags; 9102 9103 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9104 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9105 printf("Device doesn't support RAW data-path APIs.\n"); 9106 return TEST_SKIPPED; 9107 } 9108 9109 /* Verify the capabilities */ 9110 struct rte_cryptodev_sym_capability_idx cap_idx; 9111 const struct rte_cryptodev_symmetric_capability *capability; 9112 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9113 cap_idx.algo.aead = tdata->algo; 9114 capability = rte_cryptodev_sym_capability_get( 9115 ts_params->valid_devs[0], &cap_idx); 9116 if (capability == NULL) 9117 return TEST_SKIPPED; 9118 if (rte_cryptodev_sym_capability_check_aead( 9119 capability, tdata->key.len, tdata->auth_tag.len, 9120 tdata->aad.len, tdata->iv.len)) 9121 return TEST_SKIPPED; 9122 9123 /* Create AEAD session */ 9124 retval = create_aead_session(ts_params->valid_devs[0], 9125 tdata->algo, 9126 RTE_CRYPTO_AEAD_OP_ENCRYPT, 9127 tdata->key.data, tdata->key.len, 9128 tdata->aad.len, tdata->auth_tag.len, 9129 tdata->iv.len); 9130 if (retval != TEST_SUCCESS) 9131 return retval; 9132 9133 if (tdata->aad.len > MBUF_SIZE) { 9134 if (use_ext_mbuf) { 9135 ut_params->ibuf = ext_mbuf_create(ts_params->large_mbuf_pool, 9136 AEAD_TEXT_MAX_LENGTH, 9137 1 /* nb_segs */, 9138 NULL); 9139 } else { 9140 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 9141 } 9142 /* Populate full size of add data */ 9143 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 9144 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 9145 } else { 9146 if (use_ext_mbuf) { 9147 ut_params->ibuf = ext_mbuf_create(ts_params->mbuf_pool, 9148 AEAD_TEXT_MAX_LENGTH, 9149 1 /* nb_segs */, 9150 NULL); 9151 } else { 9152 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9153 } 9154 } 9155 9156 /* clear mbuf payload */ 9157 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9158 rte_pktmbuf_tailroom(ut_params->ibuf)); 9159 9160 /* Create AEAD operation */ 9161 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 9162 if (retval < 0) 9163 return retval; 9164 9165 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9166 9167 ut_params->op->sym->m_src = ut_params->ibuf; 9168 9169 /* Process crypto operation */ 9170 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9171 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 9172 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 9173 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 9174 0); 9175 if (retval != TEST_SUCCESS) 9176 return retval; 9177 } else 9178 TEST_ASSERT_NOT_NULL( 9179 process_crypto_request(ts_params->valid_devs[0], 9180 ut_params->op), "failed to process sym crypto op"); 9181 9182 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9183 "crypto op processing failed"); 9184 9185 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 9186 9187 if (ut_params->op->sym->m_dst) { 9188 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 9189 uint8_t *); 9190 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 9191 uint8_t *, plaintext_pad_len); 9192 } else { 9193 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 9194 uint8_t *, 9195 ut_params->op->sym->cipher.data.offset); 9196 auth_tag = ciphertext + plaintext_pad_len; 9197 } 9198 9199 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 9200 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 9201 9202 /* Validate obuf */ 9203 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9204 ciphertext, 9205 tdata->ciphertext.data, 9206 tdata->ciphertext.len, 9207 "Ciphertext data not as expected"); 9208 9209 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9210 auth_tag, 9211 tdata->auth_tag.data, 9212 tdata->auth_tag.len, 9213 "Generated auth tag not as expected"); 9214 9215 return 0; 9216 9217 } 9218 9219 static int 9220 test_authenticated_encryption(const struct aead_test_data *tdata) 9221 { 9222 return test_authenticated_encryption_helper(tdata, false); 9223 } 9224 9225 #ifdef RTE_LIB_SECURITY 9226 static int 9227 security_proto_supported(enum rte_security_session_action_type action, 9228 enum rte_security_session_protocol proto) 9229 { 9230 struct crypto_testsuite_params *ts_params = &testsuite_params; 9231 9232 const struct rte_security_capability *capabilities; 9233 const struct rte_security_capability *capability; 9234 uint16_t i = 0; 9235 9236 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 9237 9238 9239 capabilities = rte_security_capabilities_get(ctx); 9240 9241 if (capabilities == NULL) 9242 return -ENOTSUP; 9243 9244 while ((capability = &capabilities[i++])->action != 9245 RTE_SECURITY_ACTION_TYPE_NONE) { 9246 if (capability->action == action && 9247 capability->protocol == proto) 9248 return 0; 9249 } 9250 9251 return -ENOTSUP; 9252 } 9253 9254 /* Basic algorithm run function for async inplace mode. 9255 * Creates a session from input parameters and runs one operation 9256 * on input_vec. Checks the output of the crypto operation against 9257 * output_vec. 9258 */ 9259 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc, 9260 enum rte_crypto_auth_operation opa, 9261 const uint8_t *input_vec, unsigned int input_vec_len, 9262 const uint8_t *output_vec, 9263 unsigned int output_vec_len, 9264 enum rte_crypto_cipher_algorithm cipher_alg, 9265 const uint8_t *cipher_key, uint32_t cipher_key_len, 9266 enum rte_crypto_auth_algorithm auth_alg, 9267 const uint8_t *auth_key, uint32_t auth_key_len, 9268 uint8_t bearer, enum rte_security_pdcp_domain domain, 9269 uint8_t packet_direction, uint8_t sn_size, 9270 uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap) 9271 { 9272 struct crypto_testsuite_params *ts_params = &testsuite_params; 9273 struct crypto_unittest_params *ut_params = &unittest_params; 9274 uint8_t *plaintext; 9275 int ret = TEST_SUCCESS; 9276 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 9277 struct rte_cryptodev_info dev_info; 9278 uint64_t feat_flags; 9279 9280 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9281 feat_flags = dev_info.feature_flags; 9282 9283 /* Verify the capabilities */ 9284 struct rte_security_capability_idx sec_cap_idx; 9285 9286 sec_cap_idx.action = ut_params->type; 9287 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 9288 sec_cap_idx.pdcp.domain = domain; 9289 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 9290 return TEST_SKIPPED; 9291 9292 /* Generate test mbuf data */ 9293 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9294 9295 /* clear mbuf payload */ 9296 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9297 rte_pktmbuf_tailroom(ut_params->ibuf)); 9298 9299 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9300 input_vec_len); 9301 memcpy(plaintext, input_vec, input_vec_len); 9302 9303 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9304 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9305 printf("Device does not support RAW data-path APIs.\n"); 9306 return TEST_SKIPPED; 9307 } 9308 /* Out of place support */ 9309 if (oop) { 9310 /* 9311 * For out-op-place we need to alloc another mbuf 9312 */ 9313 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9314 rte_pktmbuf_append(ut_params->obuf, output_vec_len); 9315 } 9316 9317 /* Setup Cipher Parameters */ 9318 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9319 ut_params->cipher_xform.cipher.algo = cipher_alg; 9320 ut_params->cipher_xform.cipher.op = opc; 9321 ut_params->cipher_xform.cipher.key.data = cipher_key; 9322 ut_params->cipher_xform.cipher.key.length = cipher_key_len; 9323 ut_params->cipher_xform.cipher.iv.length = 9324 packet_direction ? 4 : 0; 9325 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 9326 9327 /* Setup HMAC Parameters if ICV header is required */ 9328 if (auth_alg != 0) { 9329 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9330 ut_params->auth_xform.next = NULL; 9331 ut_params->auth_xform.auth.algo = auth_alg; 9332 ut_params->auth_xform.auth.op = opa; 9333 ut_params->auth_xform.auth.key.data = auth_key; 9334 ut_params->auth_xform.auth.key.length = auth_key_len; 9335 9336 ut_params->cipher_xform.next = &ut_params->auth_xform; 9337 } else { 9338 ut_params->cipher_xform.next = NULL; 9339 } 9340 9341 struct rte_security_session_conf sess_conf = { 9342 .action_type = ut_params->type, 9343 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 9344 {.pdcp = { 9345 .bearer = bearer, 9346 .domain = domain, 9347 .pkt_dir = packet_direction, 9348 .sn_size = sn_size, 9349 .hfn = packet_direction ? 0 : hfn, 9350 /** 9351 * hfn can be set as pdcp_test_hfn[i] 9352 * if hfn_ovrd is not set. Here, PDCP 9353 * packet direction is just used to 9354 * run half of the cases with session 9355 * HFN and other half with per packet 9356 * HFN. 9357 */ 9358 .hfn_threshold = hfn_threshold, 9359 .hfn_ovrd = packet_direction ? 1 : 0, 9360 .sdap_enabled = sdap, 9361 } }, 9362 .crypto_xform = &ut_params->cipher_xform 9363 }; 9364 9365 /* Create security session */ 9366 ut_params->sec_session = rte_security_session_create(ctx, 9367 &sess_conf, ts_params->session_mpool); 9368 9369 if (!ut_params->sec_session) { 9370 printf("TestCase %s()-%d line %d failed %s: ", 9371 __func__, i, __LINE__, "Failed to allocate session"); 9372 ret = TEST_FAILED; 9373 goto on_err; 9374 } 9375 9376 /* Generate crypto op data structure */ 9377 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9378 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9379 if (!ut_params->op) { 9380 printf("TestCase %s()-%d line %d failed %s: ", 9381 __func__, i, __LINE__, 9382 "Failed to allocate symmetric crypto operation struct"); 9383 ret = TEST_FAILED; 9384 goto on_err; 9385 } 9386 9387 uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op, 9388 uint32_t *, IV_OFFSET); 9389 *per_pkt_hfn = packet_direction ? hfn : 0; 9390 9391 rte_security_attach_session(ut_params->op, ut_params->sec_session); 9392 9393 /* set crypto operation source mbuf */ 9394 ut_params->op->sym->m_src = ut_params->ibuf; 9395 if (oop) 9396 ut_params->op->sym->m_dst = ut_params->obuf; 9397 9398 /* Process crypto operation */ 9399 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 9400 /* filling lengths */ 9401 ut_params->op->sym->cipher.data.length = ut_params->op->sym->m_src->pkt_len; 9402 ut_params->op->sym->auth.data.length = ut_params->op->sym->m_src->pkt_len; 9403 9404 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 0); 9405 if (ret != TEST_SUCCESS) 9406 return ret; 9407 } else { 9408 ut_params->op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 9409 } 9410 if (ut_params->op == NULL) { 9411 printf("TestCase %s()-%d line %d failed %s: ", 9412 __func__, i, __LINE__, 9413 "failed to process sym crypto op"); 9414 ret = TEST_FAILED; 9415 goto on_err; 9416 } 9417 9418 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 9419 printf("TestCase %s()-%d line %d failed %s: ", 9420 __func__, i, __LINE__, "crypto op processing failed"); 9421 ret = TEST_FAILED; 9422 goto on_err; 9423 } 9424 9425 /* Validate obuf */ 9426 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 9427 uint8_t *); 9428 if (oop) { 9429 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 9430 uint8_t *); 9431 } 9432 9433 if (memcmp(ciphertext, output_vec, output_vec_len)) { 9434 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 9435 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len); 9436 rte_hexdump(stdout, "reference", output_vec, output_vec_len); 9437 ret = TEST_FAILED; 9438 goto on_err; 9439 } 9440 9441 on_err: 9442 rte_crypto_op_free(ut_params->op); 9443 ut_params->op = NULL; 9444 9445 if (ut_params->sec_session) 9446 rte_security_session_destroy(ctx, ut_params->sec_session); 9447 ut_params->sec_session = NULL; 9448 9449 rte_pktmbuf_free(ut_params->ibuf); 9450 ut_params->ibuf = NULL; 9451 if (oop) { 9452 rte_pktmbuf_free(ut_params->obuf); 9453 ut_params->obuf = NULL; 9454 } 9455 9456 return ret; 9457 } 9458 9459 static int 9460 test_pdcp_proto_SGL(int i, int oop, 9461 enum rte_crypto_cipher_operation opc, 9462 enum rte_crypto_auth_operation opa, 9463 uint8_t *input_vec, 9464 unsigned int input_vec_len, 9465 uint8_t *output_vec, 9466 unsigned int output_vec_len, 9467 uint32_t fragsz, 9468 uint32_t fragsz_oop) 9469 { 9470 struct crypto_testsuite_params *ts_params = &testsuite_params; 9471 struct crypto_unittest_params *ut_params = &unittest_params; 9472 uint8_t *plaintext; 9473 struct rte_mbuf *buf, *buf_oop = NULL; 9474 int ret = TEST_SUCCESS; 9475 int to_trn = 0; 9476 int to_trn_tbl[16]; 9477 int segs = 1; 9478 unsigned int trn_data = 0; 9479 struct rte_cryptodev_info dev_info; 9480 uint64_t feat_flags; 9481 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 9482 struct rte_mbuf *temp_mbuf; 9483 9484 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9485 feat_flags = dev_info.feature_flags; 9486 9487 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9488 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9489 printf("Device does not support RAW data-path APIs.\n"); 9490 return -ENOTSUP; 9491 } 9492 /* Verify the capabilities */ 9493 struct rte_security_capability_idx sec_cap_idx; 9494 9495 sec_cap_idx.action = ut_params->type; 9496 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 9497 sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain; 9498 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 9499 return TEST_SKIPPED; 9500 9501 if (fragsz > input_vec_len) 9502 fragsz = input_vec_len; 9503 9504 uint16_t plaintext_len = fragsz; 9505 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 9506 9507 if (fragsz_oop > output_vec_len) 9508 frag_size_oop = output_vec_len; 9509 9510 int ecx = 0; 9511 if (input_vec_len % fragsz != 0) { 9512 if (input_vec_len / fragsz + 1 > 16) 9513 return 1; 9514 } else if (input_vec_len / fragsz > 16) 9515 return 1; 9516 9517 /* Out of place support */ 9518 if (oop) { 9519 /* 9520 * For out-op-place we need to alloc another mbuf 9521 */ 9522 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9523 rte_pktmbuf_append(ut_params->obuf, frag_size_oop); 9524 buf_oop = ut_params->obuf; 9525 } 9526 9527 /* Generate test mbuf data */ 9528 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9529 9530 /* clear mbuf payload */ 9531 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9532 rte_pktmbuf_tailroom(ut_params->ibuf)); 9533 9534 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9535 plaintext_len); 9536 memcpy(plaintext, input_vec, plaintext_len); 9537 trn_data += plaintext_len; 9538 9539 buf = ut_params->ibuf; 9540 9541 /* 9542 * Loop until no more fragments 9543 */ 9544 9545 while (trn_data < input_vec_len) { 9546 ++segs; 9547 to_trn = (input_vec_len - trn_data < fragsz) ? 9548 (input_vec_len - trn_data) : fragsz; 9549 9550 to_trn_tbl[ecx++] = to_trn; 9551 9552 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9553 buf = buf->next; 9554 9555 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 9556 rte_pktmbuf_tailroom(buf)); 9557 9558 /* OOP */ 9559 if (oop && !fragsz_oop) { 9560 buf_oop->next = 9561 rte_pktmbuf_alloc(ts_params->mbuf_pool); 9562 buf_oop = buf_oop->next; 9563 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 9564 0, rte_pktmbuf_tailroom(buf_oop)); 9565 rte_pktmbuf_append(buf_oop, to_trn); 9566 } 9567 9568 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 9569 to_trn); 9570 9571 memcpy(plaintext, input_vec + trn_data, to_trn); 9572 trn_data += to_trn; 9573 } 9574 9575 ut_params->ibuf->nb_segs = segs; 9576 9577 segs = 1; 9578 if (fragsz_oop && oop) { 9579 to_trn = 0; 9580 ecx = 0; 9581 9582 trn_data = frag_size_oop; 9583 while (trn_data < output_vec_len) { 9584 ++segs; 9585 to_trn = 9586 (output_vec_len - trn_data < 9587 frag_size_oop) ? 9588 (output_vec_len - trn_data) : 9589 frag_size_oop; 9590 9591 to_trn_tbl[ecx++] = to_trn; 9592 9593 buf_oop->next = 9594 rte_pktmbuf_alloc(ts_params->mbuf_pool); 9595 buf_oop = buf_oop->next; 9596 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 9597 0, rte_pktmbuf_tailroom(buf_oop)); 9598 rte_pktmbuf_append(buf_oop, to_trn); 9599 9600 trn_data += to_trn; 9601 } 9602 ut_params->obuf->nb_segs = segs; 9603 } 9604 9605 /* Setup Cipher Parameters */ 9606 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9607 ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg; 9608 ut_params->cipher_xform.cipher.op = opc; 9609 ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i]; 9610 ut_params->cipher_xform.cipher.key.length = 9611 pdcp_test_params[i].cipher_key_len; 9612 ut_params->cipher_xform.cipher.iv.length = 0; 9613 9614 /* Setup HMAC Parameters if ICV header is required */ 9615 if (pdcp_test_params[i].auth_alg != 0) { 9616 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9617 ut_params->auth_xform.next = NULL; 9618 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg; 9619 ut_params->auth_xform.auth.op = opa; 9620 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i]; 9621 ut_params->auth_xform.auth.key.length = 9622 pdcp_test_params[i].auth_key_len; 9623 9624 ut_params->cipher_xform.next = &ut_params->auth_xform; 9625 } else { 9626 ut_params->cipher_xform.next = NULL; 9627 } 9628 9629 struct rte_security_session_conf sess_conf = { 9630 .action_type = ut_params->type, 9631 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 9632 {.pdcp = { 9633 .bearer = pdcp_test_bearer[i], 9634 .domain = pdcp_test_params[i].domain, 9635 .pkt_dir = pdcp_test_packet_direction[i], 9636 .sn_size = pdcp_test_data_sn_size[i], 9637 .hfn = pdcp_test_hfn[i], 9638 .hfn_threshold = pdcp_test_hfn_threshold[i], 9639 .hfn_ovrd = 0, 9640 } }, 9641 .crypto_xform = &ut_params->cipher_xform 9642 }; 9643 9644 /* Create security session */ 9645 ut_params->sec_session = rte_security_session_create(ctx, 9646 &sess_conf, ts_params->session_mpool); 9647 9648 if (!ut_params->sec_session) { 9649 printf("TestCase %s()-%d line %d failed %s: ", 9650 __func__, i, __LINE__, "Failed to allocate session"); 9651 ret = TEST_FAILED; 9652 goto on_err; 9653 } 9654 9655 /* Generate crypto op data structure */ 9656 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9657 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9658 if (!ut_params->op) { 9659 printf("TestCase %s()-%d line %d failed %s: ", 9660 __func__, i, __LINE__, 9661 "Failed to allocate symmetric crypto operation struct"); 9662 ret = TEST_FAILED; 9663 goto on_err; 9664 } 9665 9666 rte_security_attach_session(ut_params->op, ut_params->sec_session); 9667 9668 /* set crypto operation source mbuf */ 9669 ut_params->op->sym->m_src = ut_params->ibuf; 9670 if (oop) 9671 ut_params->op->sym->m_dst = ut_params->obuf; 9672 9673 /* Process crypto operation */ 9674 temp_mbuf = ut_params->op->sym->m_src; 9675 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 9676 /* filling lengths */ 9677 while (temp_mbuf) { 9678 ut_params->op->sym->cipher.data.length 9679 += temp_mbuf->pkt_len; 9680 ut_params->op->sym->auth.data.length 9681 += temp_mbuf->pkt_len; 9682 temp_mbuf = temp_mbuf->next; 9683 } 9684 9685 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 0); 9686 if (ret != TEST_SUCCESS) 9687 return ret; 9688 } else { 9689 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 9690 ut_params->op); 9691 } 9692 if (ut_params->op == NULL) { 9693 printf("TestCase %s()-%d line %d failed %s: ", 9694 __func__, i, __LINE__, 9695 "failed to process sym crypto op"); 9696 ret = TEST_FAILED; 9697 goto on_err; 9698 } 9699 9700 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 9701 printf("TestCase %s()-%d line %d failed %s: ", 9702 __func__, i, __LINE__, "crypto op processing failed"); 9703 ret = TEST_FAILED; 9704 goto on_err; 9705 } 9706 9707 /* Validate obuf */ 9708 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 9709 uint8_t *); 9710 if (oop) { 9711 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 9712 uint8_t *); 9713 } 9714 if (fragsz_oop) 9715 fragsz = frag_size_oop; 9716 if (memcmp(ciphertext, output_vec, fragsz)) { 9717 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 9718 rte_hexdump(stdout, "encrypted", ciphertext, fragsz); 9719 rte_hexdump(stdout, "reference", output_vec, fragsz); 9720 ret = TEST_FAILED; 9721 goto on_err; 9722 } 9723 9724 buf = ut_params->op->sym->m_src->next; 9725 if (oop) 9726 buf = ut_params->op->sym->m_dst->next; 9727 9728 unsigned int off = fragsz; 9729 9730 ecx = 0; 9731 while (buf) { 9732 ciphertext = rte_pktmbuf_mtod(buf, 9733 uint8_t *); 9734 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) { 9735 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 9736 rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]); 9737 rte_hexdump(stdout, "reference", output_vec + off, 9738 to_trn_tbl[ecx]); 9739 ret = TEST_FAILED; 9740 goto on_err; 9741 } 9742 off += to_trn_tbl[ecx++]; 9743 buf = buf->next; 9744 } 9745 on_err: 9746 rte_crypto_op_free(ut_params->op); 9747 ut_params->op = NULL; 9748 9749 if (ut_params->sec_session) 9750 rte_security_session_destroy(ctx, ut_params->sec_session); 9751 ut_params->sec_session = NULL; 9752 9753 rte_pktmbuf_free(ut_params->ibuf); 9754 ut_params->ibuf = NULL; 9755 if (oop) { 9756 rte_pktmbuf_free(ut_params->obuf); 9757 ut_params->obuf = NULL; 9758 } 9759 9760 return ret; 9761 } 9762 9763 int 9764 test_pdcp_proto_cplane_encap(int i) 9765 { 9766 return test_pdcp_proto( 9767 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 9768 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9769 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9770 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9771 pdcp_test_params[i].cipher_key_len, 9772 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9773 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9774 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9775 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9776 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9777 } 9778 9779 int 9780 test_pdcp_proto_uplane_encap(int i) 9781 { 9782 return test_pdcp_proto( 9783 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 9784 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9785 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 9786 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9787 pdcp_test_params[i].cipher_key_len, 9788 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9789 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9790 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9791 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9792 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9793 } 9794 9795 int 9796 test_pdcp_proto_uplane_encap_with_int(int i) 9797 { 9798 return test_pdcp_proto( 9799 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 9800 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9801 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9802 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9803 pdcp_test_params[i].cipher_key_len, 9804 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9805 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9806 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9807 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9808 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9809 } 9810 9811 int 9812 test_pdcp_proto_cplane_decap(int i) 9813 { 9814 return test_pdcp_proto( 9815 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 9816 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9817 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9818 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9819 pdcp_test_params[i].cipher_key_len, 9820 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9821 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9822 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9823 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9824 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9825 } 9826 9827 int 9828 test_pdcp_proto_uplane_decap(int i) 9829 { 9830 return test_pdcp_proto( 9831 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 9832 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 9833 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9834 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9835 pdcp_test_params[i].cipher_key_len, 9836 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9837 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9838 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9839 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9840 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9841 } 9842 9843 int 9844 test_pdcp_proto_uplane_decap_with_int(int i) 9845 { 9846 return test_pdcp_proto( 9847 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 9848 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9849 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9850 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9851 pdcp_test_params[i].cipher_key_len, 9852 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9853 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9854 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9855 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9856 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9857 } 9858 9859 static int 9860 test_PDCP_PROTO_SGL_in_place_32B(void) 9861 { 9862 /* i can be used for running any PDCP case 9863 * In this case it is uplane 12-bit AES-SNOW DL encap 9864 */ 9865 int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK; 9866 return test_pdcp_proto_SGL(i, IN_PLACE, 9867 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9868 RTE_CRYPTO_AUTH_OP_GENERATE, 9869 pdcp_test_data_in[i], 9870 pdcp_test_data_in_len[i], 9871 pdcp_test_data_out[i], 9872 pdcp_test_data_in_len[i]+4, 9873 32, 0); 9874 } 9875 static int 9876 test_PDCP_PROTO_SGL_oop_32B_128B(void) 9877 { 9878 /* i can be used for running any PDCP case 9879 * In this case it is uplane 18-bit NULL-NULL DL encap 9880 */ 9881 int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK; 9882 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9883 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9884 RTE_CRYPTO_AUTH_OP_GENERATE, 9885 pdcp_test_data_in[i], 9886 pdcp_test_data_in_len[i], 9887 pdcp_test_data_out[i], 9888 pdcp_test_data_in_len[i]+4, 9889 32, 128); 9890 } 9891 static int 9892 test_PDCP_PROTO_SGL_oop_32B_40B(void) 9893 { 9894 /* i can be used for running any PDCP case 9895 * In this case it is uplane 18-bit AES DL encap 9896 */ 9897 int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET 9898 + DOWNLINK; 9899 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9900 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9901 RTE_CRYPTO_AUTH_OP_GENERATE, 9902 pdcp_test_data_in[i], 9903 pdcp_test_data_in_len[i], 9904 pdcp_test_data_out[i], 9905 pdcp_test_data_in_len[i], 9906 32, 40); 9907 } 9908 static int 9909 test_PDCP_PROTO_SGL_oop_128B_32B(void) 9910 { 9911 /* i can be used for running any PDCP case 9912 * In this case it is cplane 12-bit AES-ZUC DL encap 9913 */ 9914 int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK; 9915 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9916 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9917 RTE_CRYPTO_AUTH_OP_GENERATE, 9918 pdcp_test_data_in[i], 9919 pdcp_test_data_in_len[i], 9920 pdcp_test_data_out[i], 9921 pdcp_test_data_in_len[i]+4, 9922 128, 32); 9923 } 9924 9925 static int 9926 test_PDCP_SDAP_PROTO_encap_all(void) 9927 { 9928 int i = 0, size = 0; 9929 int err, all_err = TEST_SUCCESS; 9930 const struct pdcp_sdap_test *cur_test; 9931 9932 size = RTE_DIM(list_pdcp_sdap_tests); 9933 9934 for (i = 0; i < size; i++) { 9935 cur_test = &list_pdcp_sdap_tests[i]; 9936 err = test_pdcp_proto( 9937 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9938 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9939 cur_test->in_len, cur_test->data_out, 9940 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9941 cur_test->param.cipher_alg, cur_test->cipher_key, 9942 cur_test->param.cipher_key_len, 9943 cur_test->param.auth_alg, 9944 cur_test->auth_key, cur_test->param.auth_key_len, 9945 cur_test->bearer, cur_test->param.domain, 9946 cur_test->packet_direction, cur_test->sn_size, 9947 cur_test->hfn, 9948 cur_test->hfn_threshold, SDAP_ENABLED); 9949 if (err) { 9950 printf("\t%d) %s: Encapsulation failed\n", 9951 cur_test->test_idx, 9952 cur_test->param.name); 9953 err = TEST_FAILED; 9954 } else { 9955 printf("\t%d) %s: Encap PASS\n", cur_test->test_idx, 9956 cur_test->param.name); 9957 err = TEST_SUCCESS; 9958 } 9959 all_err += err; 9960 } 9961 9962 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9963 9964 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9965 } 9966 9967 static int 9968 test_PDCP_PROTO_short_mac(void) 9969 { 9970 int i = 0, size = 0; 9971 int err, all_err = TEST_SUCCESS; 9972 const struct pdcp_short_mac_test *cur_test; 9973 9974 size = RTE_DIM(list_pdcp_smac_tests); 9975 9976 for (i = 0; i < size; i++) { 9977 cur_test = &list_pdcp_smac_tests[i]; 9978 err = test_pdcp_proto( 9979 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9980 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9981 cur_test->in_len, cur_test->data_out, 9982 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9983 RTE_CRYPTO_CIPHER_NULL, NULL, 9984 0, cur_test->param.auth_alg, 9985 cur_test->auth_key, cur_test->param.auth_key_len, 9986 0, cur_test->param.domain, 0, 0, 9987 0, 0, 0); 9988 if (err) { 9989 printf("\t%d) %s: Short MAC test failed\n", 9990 cur_test->test_idx, 9991 cur_test->param.name); 9992 err = TEST_FAILED; 9993 } else { 9994 printf("\t%d) %s: Short MAC test PASS\n", 9995 cur_test->test_idx, 9996 cur_test->param.name); 9997 rte_hexdump(stdout, "MAC I", 9998 cur_test->data_out + cur_test->in_len + 2, 9999 2); 10000 err = TEST_SUCCESS; 10001 } 10002 all_err += err; 10003 } 10004 10005 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 10006 10007 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 10008 10009 } 10010 10011 static int 10012 test_PDCP_SDAP_PROTO_decap_all(void) 10013 { 10014 int i = 0, size = 0; 10015 int err, all_err = TEST_SUCCESS; 10016 const struct pdcp_sdap_test *cur_test; 10017 10018 size = RTE_DIM(list_pdcp_sdap_tests); 10019 10020 for (i = 0; i < size; i++) { 10021 cur_test = &list_pdcp_sdap_tests[i]; 10022 err = test_pdcp_proto( 10023 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, 10024 RTE_CRYPTO_AUTH_OP_VERIFY, 10025 cur_test->data_out, 10026 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 10027 cur_test->data_in, cur_test->in_len, 10028 cur_test->param.cipher_alg, 10029 cur_test->cipher_key, cur_test->param.cipher_key_len, 10030 cur_test->param.auth_alg, cur_test->auth_key, 10031 cur_test->param.auth_key_len, cur_test->bearer, 10032 cur_test->param.domain, cur_test->packet_direction, 10033 cur_test->sn_size, cur_test->hfn, 10034 cur_test->hfn_threshold, SDAP_ENABLED); 10035 if (err) { 10036 printf("\t%d) %s: Decapsulation failed\n", 10037 cur_test->test_idx, 10038 cur_test->param.name); 10039 err = TEST_FAILED; 10040 } else { 10041 printf("\t%d) %s: Decap PASS\n", cur_test->test_idx, 10042 cur_test->param.name); 10043 err = TEST_SUCCESS; 10044 } 10045 all_err += err; 10046 } 10047 10048 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 10049 10050 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 10051 } 10052 10053 static int 10054 test_ipsec_proto_crypto_op_enq(struct crypto_testsuite_params *ts_params, 10055 struct crypto_unittest_params *ut_params, 10056 struct rte_security_ipsec_xform *ipsec_xform, 10057 const struct ipsec_test_data *td, 10058 const struct ipsec_test_flags *flags, 10059 int pkt_num) 10060 { 10061 uint8_t dev_id = ts_params->valid_devs[0]; 10062 enum rte_security_ipsec_sa_direction dir; 10063 int ret; 10064 10065 dir = ipsec_xform->direction; 10066 10067 /* Generate crypto op data structure */ 10068 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10069 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10070 if (!ut_params->op) { 10071 printf("Could not allocate crypto op"); 10072 return TEST_FAILED; 10073 } 10074 10075 /* Attach session to operation */ 10076 rte_security_attach_session(ut_params->op, ut_params->sec_session); 10077 10078 /* Set crypto operation mbufs */ 10079 ut_params->op->sym->m_src = ut_params->ibuf; 10080 ut_params->op->sym->m_dst = NULL; 10081 10082 /* Copy IV in crypto operation when IV generation is disabled */ 10083 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS && 10084 ipsec_xform->options.iv_gen_disable == 1) { 10085 uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op, 10086 uint8_t *, 10087 IV_OFFSET); 10088 int len; 10089 10090 if (td->aead) 10091 len = td->xform.aead.aead.iv.length; 10092 else if (td->aes_gmac) 10093 len = td->xform.chain.auth.auth.iv.length; 10094 else 10095 len = td->xform.chain.cipher.cipher.iv.length; 10096 10097 memcpy(iv, td->iv.data, len); 10098 } 10099 10100 /* Process crypto operation */ 10101 process_crypto_request(dev_id, ut_params->op); 10102 10103 ret = test_ipsec_status_check(td, ut_params->op, flags, dir, pkt_num); 10104 10105 rte_crypto_op_free(ut_params->op); 10106 ut_params->op = NULL; 10107 10108 return ret; 10109 } 10110 10111 static int 10112 test_ipsec_proto_mbuf_enq(struct crypto_testsuite_params *ts_params, 10113 struct crypto_unittest_params *ut_params, 10114 void *ctx) 10115 { 10116 uint64_t timeout, userdata; 10117 struct rte_ether_hdr *hdr; 10118 struct rte_mbuf *m; 10119 void **sec_sess; 10120 int ret; 10121 10122 RTE_SET_USED(ts_params); 10123 10124 hdr = (void *)rte_pktmbuf_prepend(ut_params->ibuf, sizeof(struct rte_ether_hdr)); 10125 hdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4); 10126 10127 ut_params->ibuf->l2_len = sizeof(struct rte_ether_hdr); 10128 ut_params->ibuf->port = 0; 10129 10130 sec_sess = &ut_params->sec_session; 10131 ret = rte_security_inb_pkt_rx_inject(ctx, &ut_params->ibuf, sec_sess, 1); 10132 10133 if (ret != 1) 10134 return TEST_FAILED; 10135 10136 ut_params->ibuf = NULL; 10137 10138 /* Add a timeout for 1 s */ 10139 timeout = rte_get_tsc_cycles() + rte_get_tsc_hz(); 10140 10141 do { 10142 /* Get packet from port 0, queue 0 */ 10143 ret = rte_eth_rx_burst(0, 0, &m, 1); 10144 } while ((ret == 0) && (rte_get_tsc_cycles() < timeout)); 10145 10146 if (ret == 0) { 10147 printf("Could not receive packets from ethdev\n"); 10148 return TEST_FAILED; 10149 } 10150 10151 if (m == NULL) { 10152 printf("Received mbuf is NULL\n"); 10153 return TEST_FAILED; 10154 } 10155 10156 ut_params->ibuf = m; 10157 10158 if (!(m->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD)) { 10159 printf("Received packet is not Rx security processed\n"); 10160 return TEST_FAILED; 10161 } 10162 10163 if (m->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED) { 10164 printf("Received packet has failed Rx security processing\n"); 10165 return TEST_FAILED; 10166 } 10167 10168 /* 10169 * 'ut_params' is set as userdata. Verify that the field is returned 10170 * correctly. 10171 */ 10172 userdata = *(uint64_t *)rte_security_dynfield(m); 10173 if (userdata != (uint64_t)ut_params) { 10174 printf("Userdata retrieved not matching expected\n"); 10175 return TEST_FAILED; 10176 } 10177 10178 /* Trim L2 header */ 10179 rte_pktmbuf_adj(m, sizeof(struct rte_ether_hdr)); 10180 10181 return TEST_SUCCESS; 10182 } 10183 10184 static int 10185 test_ipsec_proto_process(const struct ipsec_test_data td[], 10186 struct ipsec_test_data res_d[], 10187 int nb_td, 10188 bool silent, 10189 const struct ipsec_test_flags *flags) 10190 { 10191 uint16_t v6_src[8] = {0x2607, 0xf8b0, 0x400c, 0x0c03, 0x0000, 0x0000, 10192 0x0000, 0x001a}; 10193 uint16_t v6_dst[8] = {0x2001, 0x0470, 0xe5bf, 0xdead, 0x4957, 0x2174, 10194 0xe82c, 0x4887}; 10195 const struct rte_ipv4_hdr *ipv4 = 10196 (const struct rte_ipv4_hdr *)td[0].output_text.data; 10197 int nb_segs = flags->nb_segs_in_mbuf ? flags->nb_segs_in_mbuf : 1; 10198 struct crypto_testsuite_params *ts_params = &testsuite_params; 10199 struct crypto_unittest_params *ut_params = &unittest_params; 10200 struct rte_security_capability_idx sec_cap_idx; 10201 const struct rte_security_capability *sec_cap; 10202 struct rte_security_ipsec_xform ipsec_xform; 10203 uint8_t dev_id = ts_params->valid_devs[0]; 10204 enum rte_security_ipsec_sa_direction dir; 10205 struct ipsec_test_data *res_d_tmp = NULL; 10206 uint8_t input_text[IPSEC_TEXT_MAX_LEN]; 10207 int salt_len, i, ret = TEST_SUCCESS; 10208 void *ctx; 10209 uint32_t src, dst; 10210 uint32_t verify; 10211 10212 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 10213 gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 10214 10215 /* Use first test data to create session */ 10216 10217 /* Copy IPsec xform */ 10218 memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform)); 10219 10220 dir = ipsec_xform.direction; 10221 verify = flags->tunnel_hdr_verify; 10222 10223 memcpy(&src, &ipv4->src_addr, sizeof(ipv4->src_addr)); 10224 memcpy(&dst, &ipv4->dst_addr, sizeof(ipv4->dst_addr)); 10225 10226 if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) { 10227 if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR) 10228 src += 1; 10229 else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR) 10230 dst += 1; 10231 } 10232 10233 if (td->ipsec_xform.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) { 10234 if (td->ipsec_xform.tunnel.type == 10235 RTE_SECURITY_IPSEC_TUNNEL_IPV4) { 10236 memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, 10237 sizeof(src)); 10238 memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, 10239 sizeof(dst)); 10240 10241 if (flags->df == TEST_IPSEC_SET_DF_0_INNER_1) 10242 ipsec_xform.tunnel.ipv4.df = 0; 10243 10244 if (flags->df == TEST_IPSEC_SET_DF_1_INNER_0) 10245 ipsec_xform.tunnel.ipv4.df = 1; 10246 10247 if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1) 10248 ipsec_xform.tunnel.ipv4.dscp = 0; 10249 10250 if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0) 10251 ipsec_xform.tunnel.ipv4.dscp = 10252 TEST_IPSEC_DSCP_VAL; 10253 10254 } else { 10255 if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1) 10256 ipsec_xform.tunnel.ipv6.dscp = 0; 10257 10258 if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0) 10259 ipsec_xform.tunnel.ipv6.dscp = 10260 TEST_IPSEC_DSCP_VAL; 10261 10262 memcpy(&ipsec_xform.tunnel.ipv6.src_addr, &v6_src, 10263 sizeof(v6_src)); 10264 memcpy(&ipsec_xform.tunnel.ipv6.dst_addr, &v6_dst, 10265 sizeof(v6_dst)); 10266 } 10267 } 10268 10269 ctx = rte_cryptodev_get_sec_ctx(dev_id); 10270 10271 sec_cap_idx.action = ut_params->type; 10272 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC; 10273 sec_cap_idx.ipsec.proto = ipsec_xform.proto; 10274 sec_cap_idx.ipsec.mode = ipsec_xform.mode; 10275 sec_cap_idx.ipsec.direction = ipsec_xform.direction; 10276 10277 if (flags->udp_encap) 10278 ipsec_xform.options.udp_encap = 1; 10279 10280 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 10281 if (sec_cap == NULL) 10282 return TEST_SKIPPED; 10283 10284 /* Copy cipher session parameters */ 10285 if (td[0].aead) { 10286 memcpy(&ut_params->aead_xform, &td[0].xform.aead, 10287 sizeof(ut_params->aead_xform)); 10288 ut_params->aead_xform.aead.key.data = td[0].key.data; 10289 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 10290 10291 /* Verify crypto capabilities */ 10292 if (test_sec_crypto_caps_aead_verify(sec_cap, &ut_params->aead_xform) != 0) { 10293 if (!silent) 10294 RTE_LOG(INFO, USER1, 10295 "Crypto capabilities not supported\n"); 10296 return TEST_SKIPPED; 10297 } 10298 } else if (td[0].auth_only) { 10299 memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth, 10300 sizeof(ut_params->auth_xform)); 10301 ut_params->auth_xform.auth.key.data = td[0].auth_key.data; 10302 10303 if (test_sec_crypto_caps_auth_verify(sec_cap, &ut_params->auth_xform) != 0) { 10304 if (!silent) 10305 RTE_LOG(INFO, USER1, 10306 "Auth crypto capabilities not supported\n"); 10307 return TEST_SKIPPED; 10308 } 10309 } else { 10310 memcpy(&ut_params->cipher_xform, &td[0].xform.chain.cipher, 10311 sizeof(ut_params->cipher_xform)); 10312 memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth, 10313 sizeof(ut_params->auth_xform)); 10314 ut_params->cipher_xform.cipher.key.data = td[0].key.data; 10315 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 10316 ut_params->auth_xform.auth.key.data = td[0].auth_key.data; 10317 10318 /* Verify crypto capabilities */ 10319 10320 if (test_sec_crypto_caps_cipher_verify(sec_cap, &ut_params->cipher_xform) != 0) { 10321 if (!silent) 10322 RTE_LOG(INFO, USER1, 10323 "Cipher crypto capabilities not supported\n"); 10324 return TEST_SKIPPED; 10325 } 10326 10327 if (test_sec_crypto_caps_auth_verify(sec_cap, &ut_params->auth_xform) != 0) { 10328 if (!silent) 10329 RTE_LOG(INFO, USER1, 10330 "Auth crypto capabilities not supported\n"); 10331 return TEST_SKIPPED; 10332 } 10333 } 10334 10335 if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0) 10336 return TEST_SKIPPED; 10337 10338 struct rte_security_session_conf sess_conf = { 10339 .action_type = ut_params->type, 10340 .protocol = RTE_SECURITY_PROTOCOL_IPSEC, 10341 }; 10342 10343 if (td[0].aead || td[0].aes_gmac) { 10344 salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len); 10345 memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len); 10346 } 10347 10348 if (td[0].aead) { 10349 sess_conf.ipsec = ipsec_xform; 10350 sess_conf.crypto_xform = &ut_params->aead_xform; 10351 } else if (td[0].auth_only) { 10352 sess_conf.ipsec = ipsec_xform; 10353 sess_conf.crypto_xform = &ut_params->auth_xform; 10354 } else { 10355 sess_conf.ipsec = ipsec_xform; 10356 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) { 10357 sess_conf.crypto_xform = &ut_params->cipher_xform; 10358 ut_params->cipher_xform.next = &ut_params->auth_xform; 10359 } else { 10360 sess_conf.crypto_xform = &ut_params->auth_xform; 10361 ut_params->auth_xform.next = &ut_params->cipher_xform; 10362 } 10363 } 10364 10365 if (dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS && flags->rx_inject) 10366 sess_conf.userdata = ut_params; 10367 10368 /* Create security session */ 10369 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 10370 ts_params->session_mpool); 10371 10372 if (ut_params->sec_session == NULL) 10373 return TEST_SKIPPED; 10374 10375 for (i = 0; i < nb_td; i++) { 10376 if (flags->antireplay && 10377 (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)) { 10378 sess_conf.ipsec.esn.value = td[i].ipsec_xform.esn.value; 10379 ret = rte_security_session_update(ctx, 10380 ut_params->sec_session, &sess_conf); 10381 if (ret) { 10382 printf("Could not update sequence number in " 10383 "session\n"); 10384 return TEST_SKIPPED; 10385 } 10386 } 10387 10388 /* Copy test data before modification */ 10389 memcpy(input_text, td[i].input_text.data, td[i].input_text.len); 10390 if (test_ipsec_pkt_update(input_text, flags)) { 10391 ret = TEST_FAILED; 10392 goto mbuf_free; 10393 } 10394 10395 /* Setup source mbuf payload */ 10396 if (flags->use_ext_mbuf) { 10397 ut_params->ibuf = ext_mbuf_create(ts_params->mbuf_pool, 10398 td[i].input_text.len, nb_segs, input_text); 10399 } else { 10400 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 10401 td[i].input_text.len, nb_segs, 0); 10402 pktmbuf_write(ut_params->ibuf, 0, td[i].input_text.len, input_text); 10403 } 10404 10405 if (dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS && flags->rx_inject) 10406 ret = test_ipsec_proto_mbuf_enq(ts_params, ut_params, 10407 ctx); 10408 else 10409 ret = test_ipsec_proto_crypto_op_enq(ts_params, 10410 ut_params, 10411 &ipsec_xform, 10412 &td[i], flags, 10413 i + 1); 10414 10415 if (ret != TEST_SUCCESS) 10416 goto mbuf_free; 10417 10418 if (res_d != NULL) 10419 res_d_tmp = &res_d[i]; 10420 10421 ret = test_ipsec_post_process(ut_params->ibuf, &td[i], 10422 res_d_tmp, silent, flags); 10423 if (ret != TEST_SUCCESS) 10424 goto mbuf_free; 10425 10426 ret = test_ipsec_stats_verify(ctx, ut_params->sec_session, 10427 flags, dir); 10428 if (ret != TEST_SUCCESS) 10429 goto mbuf_free; 10430 10431 rte_pktmbuf_free(ut_params->ibuf); 10432 ut_params->ibuf = NULL; 10433 } 10434 10435 mbuf_free: 10436 if (flags->use_ext_mbuf) 10437 ext_mbuf_memzone_free(nb_segs); 10438 10439 rte_pktmbuf_free(ut_params->ibuf); 10440 ut_params->ibuf = NULL; 10441 10442 if (ut_params->sec_session) 10443 rte_security_session_destroy(ctx, ut_params->sec_session); 10444 ut_params->sec_session = NULL; 10445 10446 return ret; 10447 } 10448 10449 static int 10450 test_ipsec_proto_known_vec(const void *test_data) 10451 { 10452 struct ipsec_test_data td_outb; 10453 struct ipsec_test_flags flags; 10454 10455 memset(&flags, 0, sizeof(flags)); 10456 10457 memcpy(&td_outb, test_data, sizeof(td_outb)); 10458 10459 if (td_outb.aes_gmac || td_outb.aead || 10460 ((td_outb.ipsec_xform.proto != RTE_SECURITY_IPSEC_SA_PROTO_AH) && 10461 (td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL))) { 10462 /* Disable IV gen to be able to test with known vectors */ 10463 td_outb.ipsec_xform.options.iv_gen_disable = 1; 10464 } 10465 10466 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 10467 } 10468 10469 static int 10470 test_ipsec_proto_known_vec_ext_mbuf(const void *test_data) 10471 { 10472 struct ipsec_test_data td_outb; 10473 struct ipsec_test_flags flags; 10474 10475 memset(&flags, 0, sizeof(flags)); 10476 flags.use_ext_mbuf = true; 10477 10478 memcpy(&td_outb, test_data, sizeof(td_outb)); 10479 10480 if (td_outb.aes_gmac || td_outb.aead || 10481 ((td_outb.ipsec_xform.proto != RTE_SECURITY_IPSEC_SA_PROTO_AH) && 10482 (td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL))) { 10483 /* Disable IV gen to be able to test with known vectors */ 10484 td_outb.ipsec_xform.options.iv_gen_disable = 1; 10485 } 10486 10487 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 10488 } 10489 10490 static int 10491 test_ipsec_proto_known_vec_inb(const void *test_data) 10492 { 10493 const struct ipsec_test_data *td = test_data; 10494 struct ipsec_test_flags flags; 10495 struct ipsec_test_data td_inb; 10496 10497 memset(&flags, 0, sizeof(flags)); 10498 10499 if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) 10500 test_ipsec_td_in_from_out(td, &td_inb); 10501 else 10502 memcpy(&td_inb, td, sizeof(td_inb)); 10503 10504 return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags); 10505 } 10506 10507 static int 10508 test_ipsec_proto_known_vec_fragmented(const void *test_data) 10509 { 10510 struct ipsec_test_data td_outb; 10511 struct ipsec_test_flags flags; 10512 10513 memset(&flags, 0, sizeof(flags)); 10514 flags.fragment = true; 10515 10516 memcpy(&td_outb, test_data, sizeof(td_outb)); 10517 10518 /* Disable IV gen to be able to test with known vectors */ 10519 td_outb.ipsec_xform.options.iv_gen_disable = 1; 10520 10521 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 10522 } 10523 10524 static int 10525 test_ipsec_proto_known_vec_inb_rx_inject(const void *test_data) 10526 { 10527 const struct ipsec_test_data *td = test_data; 10528 struct ipsec_test_flags flags; 10529 struct ipsec_test_data td_inb; 10530 10531 memset(&flags, 0, sizeof(flags)); 10532 flags.rx_inject = true; 10533 10534 if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) 10535 test_ipsec_td_in_from_out(td, &td_inb); 10536 else 10537 memcpy(&td_inb, td, sizeof(td_inb)); 10538 10539 return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags); 10540 } 10541 10542 static int 10543 test_ipsec_proto_all(const struct ipsec_test_flags *flags) 10544 { 10545 struct ipsec_test_data td_outb[TEST_SEC_PKTS_MAX]; 10546 struct ipsec_test_data td_inb[TEST_SEC_PKTS_MAX]; 10547 unsigned int i, nb_pkts = 1, pass_cnt = 0; 10548 int ret; 10549 10550 if (flags->iv_gen || 10551 flags->sa_expiry_pkts_soft || 10552 flags->sa_expiry_pkts_hard) 10553 nb_pkts = TEST_SEC_PKTS_MAX; 10554 10555 for (i = 0; i < RTE_DIM(sec_alg_list); i++) { 10556 test_ipsec_td_prepare(sec_alg_list[i].param1, 10557 sec_alg_list[i].param2, 10558 flags, 10559 td_outb, 10560 nb_pkts); 10561 10562 if (!td_outb->aead) { 10563 enum rte_crypto_cipher_algorithm cipher_alg; 10564 enum rte_crypto_auth_algorithm auth_alg; 10565 10566 cipher_alg = td_outb->xform.chain.cipher.cipher.algo; 10567 auth_alg = td_outb->xform.chain.auth.auth.algo; 10568 10569 if (td_outb->aes_gmac && cipher_alg != RTE_CRYPTO_CIPHER_NULL) 10570 continue; 10571 10572 /* ICV is not applicable for NULL auth */ 10573 if (flags->icv_corrupt && 10574 auth_alg == RTE_CRYPTO_AUTH_NULL) 10575 continue; 10576 10577 /* IV is not applicable for NULL cipher */ 10578 if (flags->iv_gen && 10579 cipher_alg == RTE_CRYPTO_CIPHER_NULL) 10580 continue; 10581 } 10582 10583 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 10584 flags); 10585 if (ret == TEST_SKIPPED) 10586 continue; 10587 10588 if (ret == TEST_FAILED) 10589 return TEST_FAILED; 10590 10591 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags); 10592 10593 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 10594 flags); 10595 if (ret == TEST_SKIPPED) 10596 continue; 10597 10598 if (ret == TEST_FAILED) 10599 return TEST_FAILED; 10600 10601 if (flags->display_alg) 10602 test_sec_alg_display(sec_alg_list[i].param1, sec_alg_list[i].param2); 10603 10604 pass_cnt++; 10605 } 10606 10607 if (pass_cnt > 0) 10608 return TEST_SUCCESS; 10609 else 10610 return TEST_SKIPPED; 10611 } 10612 10613 static int 10614 test_ipsec_ah_proto_all(const struct ipsec_test_flags *flags) 10615 { 10616 struct ipsec_test_data td_outb[TEST_SEC_PKTS_MAX]; 10617 struct ipsec_test_data td_inb[TEST_SEC_PKTS_MAX]; 10618 unsigned int i, nb_pkts = 1, pass_cnt = 0; 10619 int ret; 10620 10621 for (i = 0; i < RTE_DIM(sec_auth_only_alg_list); i++) { 10622 test_ipsec_td_prepare(sec_auth_only_alg_list[i].param1, 10623 sec_auth_only_alg_list[i].param2, 10624 flags, 10625 td_outb, 10626 nb_pkts); 10627 10628 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 10629 flags); 10630 if (ret == TEST_SKIPPED) 10631 continue; 10632 10633 if (ret == TEST_FAILED) 10634 return TEST_FAILED; 10635 10636 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags); 10637 10638 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 10639 flags); 10640 if (ret == TEST_SKIPPED) 10641 continue; 10642 10643 if (ret == TEST_FAILED) 10644 return TEST_FAILED; 10645 10646 if (flags->display_alg) 10647 test_sec_alg_display(sec_auth_only_alg_list[i].param1, 10648 sec_auth_only_alg_list[i].param2); 10649 10650 pass_cnt++; 10651 } 10652 10653 if (pass_cnt > 0) 10654 return TEST_SUCCESS; 10655 else 10656 return TEST_SKIPPED; 10657 } 10658 10659 static int 10660 test_ipsec_proto_display_list(void) 10661 { 10662 struct ipsec_test_flags flags; 10663 10664 memset(&flags, 0, sizeof(flags)); 10665 10666 flags.display_alg = true; 10667 10668 return test_ipsec_proto_all(&flags); 10669 } 10670 10671 static int 10672 test_ipsec_proto_ah_tunnel_ipv4(void) 10673 { 10674 struct ipsec_test_flags flags; 10675 10676 memset(&flags, 0, sizeof(flags)); 10677 10678 flags.ah = true; 10679 flags.display_alg = true; 10680 10681 return test_ipsec_ah_proto_all(&flags); 10682 } 10683 10684 static int 10685 test_ipsec_proto_ah_transport_ipv4(void) 10686 { 10687 struct ipsec_test_flags flags; 10688 10689 memset(&flags, 0, sizeof(flags)); 10690 10691 flags.ah = true; 10692 flags.transport = true; 10693 10694 return test_ipsec_ah_proto_all(&flags); 10695 } 10696 10697 static int 10698 test_ipsec_proto_iv_gen(void) 10699 { 10700 struct ipsec_test_flags flags; 10701 10702 memset(&flags, 0, sizeof(flags)); 10703 10704 flags.iv_gen = true; 10705 10706 return test_ipsec_proto_all(&flags); 10707 } 10708 10709 static int 10710 test_ipsec_proto_sa_exp_pkts_soft(void) 10711 { 10712 struct ipsec_test_flags flags; 10713 10714 memset(&flags, 0, sizeof(flags)); 10715 10716 flags.sa_expiry_pkts_soft = true; 10717 10718 return test_ipsec_proto_all(&flags); 10719 } 10720 10721 static int 10722 test_ipsec_proto_sa_exp_pkts_hard(void) 10723 { 10724 struct ipsec_test_flags flags; 10725 10726 memset(&flags, 0, sizeof(flags)); 10727 10728 flags.sa_expiry_pkts_hard = true; 10729 10730 return test_ipsec_proto_all(&flags); 10731 } 10732 10733 static int 10734 test_ipsec_proto_err_icv_corrupt(void) 10735 { 10736 struct ipsec_test_flags flags; 10737 10738 memset(&flags, 0, sizeof(flags)); 10739 10740 flags.icv_corrupt = true; 10741 10742 return test_ipsec_proto_all(&flags); 10743 } 10744 10745 static int 10746 test_ipsec_proto_udp_encap_custom_ports(void) 10747 { 10748 struct ipsec_test_flags flags; 10749 10750 if (gbl_driver_id == rte_cryptodev_driver_id_get( 10751 RTE_STR(CRYPTODEV_NAME_CN10K_PMD))) 10752 return TEST_SKIPPED; 10753 10754 memset(&flags, 0, sizeof(flags)); 10755 10756 flags.udp_encap = true; 10757 flags.udp_encap_custom_ports = true; 10758 10759 return test_ipsec_proto_all(&flags); 10760 } 10761 10762 static int 10763 test_ipsec_proto_udp_encap(void) 10764 { 10765 struct ipsec_test_flags flags; 10766 10767 memset(&flags, 0, sizeof(flags)); 10768 10769 flags.udp_encap = true; 10770 10771 return test_ipsec_proto_all(&flags); 10772 } 10773 10774 static int 10775 test_ipsec_proto_tunnel_src_dst_addr_verify(void) 10776 { 10777 struct ipsec_test_flags flags; 10778 10779 memset(&flags, 0, sizeof(flags)); 10780 10781 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR; 10782 10783 return test_ipsec_proto_all(&flags); 10784 } 10785 10786 static int 10787 test_ipsec_proto_tunnel_dst_addr_verify(void) 10788 { 10789 struct ipsec_test_flags flags; 10790 10791 memset(&flags, 0, sizeof(flags)); 10792 10793 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR; 10794 10795 return test_ipsec_proto_all(&flags); 10796 } 10797 10798 static int 10799 test_ipsec_proto_udp_ports_verify(void) 10800 { 10801 struct ipsec_test_flags flags; 10802 10803 memset(&flags, 0, sizeof(flags)); 10804 10805 flags.udp_encap = true; 10806 flags.udp_ports_verify = true; 10807 10808 return test_ipsec_proto_all(&flags); 10809 } 10810 10811 static int 10812 test_ipsec_proto_inner_ip_csum(void) 10813 { 10814 struct ipsec_test_flags flags; 10815 10816 memset(&flags, 0, sizeof(flags)); 10817 10818 flags.ip_csum = true; 10819 10820 return test_ipsec_proto_all(&flags); 10821 } 10822 10823 static int 10824 test_ipsec_proto_inner_l4_csum(void) 10825 { 10826 struct ipsec_test_flags flags; 10827 10828 memset(&flags, 0, sizeof(flags)); 10829 10830 flags.l4_csum = true; 10831 10832 return test_ipsec_proto_all(&flags); 10833 } 10834 10835 static int 10836 test_ipsec_proto_tunnel_v4_in_v4(void) 10837 { 10838 struct ipsec_test_flags flags; 10839 10840 memset(&flags, 0, sizeof(flags)); 10841 10842 flags.ipv6 = false; 10843 flags.tunnel_ipv6 = false; 10844 10845 return test_ipsec_proto_all(&flags); 10846 } 10847 10848 static int 10849 test_ipsec_proto_tunnel_v6_in_v6(void) 10850 { 10851 struct ipsec_test_flags flags; 10852 10853 memset(&flags, 0, sizeof(flags)); 10854 10855 flags.ipv6 = true; 10856 flags.tunnel_ipv6 = true; 10857 10858 return test_ipsec_proto_all(&flags); 10859 } 10860 10861 static int 10862 test_ipsec_proto_tunnel_v4_in_v6(void) 10863 { 10864 struct ipsec_test_flags flags; 10865 10866 memset(&flags, 0, sizeof(flags)); 10867 10868 flags.ipv6 = false; 10869 flags.tunnel_ipv6 = true; 10870 10871 return test_ipsec_proto_all(&flags); 10872 } 10873 10874 static int 10875 test_ipsec_proto_tunnel_v6_in_v4(void) 10876 { 10877 struct ipsec_test_flags flags; 10878 10879 memset(&flags, 0, sizeof(flags)); 10880 10881 flags.ipv6 = true; 10882 flags.tunnel_ipv6 = false; 10883 10884 return test_ipsec_proto_all(&flags); 10885 } 10886 10887 static int 10888 test_ipsec_proto_transport_v4(void) 10889 { 10890 struct ipsec_test_flags flags; 10891 10892 memset(&flags, 0, sizeof(flags)); 10893 10894 flags.ipv6 = false; 10895 flags.transport = true; 10896 10897 return test_ipsec_proto_all(&flags); 10898 } 10899 10900 static int 10901 test_ipsec_proto_transport_l4_csum(void) 10902 { 10903 struct ipsec_test_flags flags = { 10904 .l4_csum = true, 10905 .transport = true, 10906 }; 10907 10908 return test_ipsec_proto_all(&flags); 10909 } 10910 10911 static int 10912 test_ipsec_proto_stats(void) 10913 { 10914 struct ipsec_test_flags flags; 10915 10916 memset(&flags, 0, sizeof(flags)); 10917 10918 flags.stats_success = true; 10919 10920 return test_ipsec_proto_all(&flags); 10921 } 10922 10923 static int 10924 test_ipsec_proto_pkt_fragment(void) 10925 { 10926 struct ipsec_test_flags flags; 10927 10928 memset(&flags, 0, sizeof(flags)); 10929 10930 flags.fragment = true; 10931 10932 return test_ipsec_proto_all(&flags); 10933 10934 } 10935 10936 static int 10937 test_ipsec_proto_copy_df_inner_0(void) 10938 { 10939 struct ipsec_test_flags flags; 10940 10941 memset(&flags, 0, sizeof(flags)); 10942 10943 flags.df = TEST_IPSEC_COPY_DF_INNER_0; 10944 10945 return test_ipsec_proto_all(&flags); 10946 } 10947 10948 static int 10949 test_ipsec_proto_copy_df_inner_1(void) 10950 { 10951 struct ipsec_test_flags flags; 10952 10953 memset(&flags, 0, sizeof(flags)); 10954 10955 flags.df = TEST_IPSEC_COPY_DF_INNER_1; 10956 10957 return test_ipsec_proto_all(&flags); 10958 } 10959 10960 static int 10961 test_ipsec_proto_set_df_0_inner_1(void) 10962 { 10963 struct ipsec_test_flags flags; 10964 10965 memset(&flags, 0, sizeof(flags)); 10966 10967 flags.df = TEST_IPSEC_SET_DF_0_INNER_1; 10968 10969 return test_ipsec_proto_all(&flags); 10970 } 10971 10972 static int 10973 test_ipsec_proto_set_df_1_inner_0(void) 10974 { 10975 struct ipsec_test_flags flags; 10976 10977 memset(&flags, 0, sizeof(flags)); 10978 10979 flags.df = TEST_IPSEC_SET_DF_1_INNER_0; 10980 10981 return test_ipsec_proto_all(&flags); 10982 } 10983 10984 static int 10985 test_ipsec_proto_ipv4_copy_dscp_inner_0(void) 10986 { 10987 struct ipsec_test_flags flags; 10988 10989 memset(&flags, 0, sizeof(flags)); 10990 10991 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0; 10992 10993 return test_ipsec_proto_all(&flags); 10994 } 10995 10996 static int 10997 test_ipsec_proto_ipv4_copy_dscp_inner_1(void) 10998 { 10999 struct ipsec_test_flags flags; 11000 11001 memset(&flags, 0, sizeof(flags)); 11002 11003 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1; 11004 11005 return test_ipsec_proto_all(&flags); 11006 } 11007 11008 static int 11009 test_ipsec_proto_ipv4_set_dscp_0_inner_1(void) 11010 { 11011 struct ipsec_test_flags flags; 11012 11013 if (gbl_driver_id == rte_cryptodev_driver_id_get( 11014 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 11015 return TEST_SKIPPED; 11016 11017 memset(&flags, 0, sizeof(flags)); 11018 11019 flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1; 11020 11021 return test_ipsec_proto_all(&flags); 11022 } 11023 11024 static int 11025 test_ipsec_proto_ipv4_set_dscp_1_inner_0(void) 11026 { 11027 struct ipsec_test_flags flags; 11028 11029 if (gbl_driver_id == rte_cryptodev_driver_id_get( 11030 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 11031 return TEST_SKIPPED; 11032 11033 memset(&flags, 0, sizeof(flags)); 11034 11035 flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0; 11036 11037 return test_ipsec_proto_all(&flags); 11038 } 11039 11040 static int 11041 test_ipsec_proto_ipv6_copy_dscp_inner_0(void) 11042 { 11043 struct ipsec_test_flags flags; 11044 11045 memset(&flags, 0, sizeof(flags)); 11046 11047 flags.ipv6 = true; 11048 flags.tunnel_ipv6 = true; 11049 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0; 11050 11051 return test_ipsec_proto_all(&flags); 11052 } 11053 11054 static int 11055 test_ipsec_proto_ipv6_copy_dscp_inner_1(void) 11056 { 11057 struct ipsec_test_flags flags; 11058 11059 memset(&flags, 0, sizeof(flags)); 11060 11061 flags.ipv6 = true; 11062 flags.tunnel_ipv6 = true; 11063 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1; 11064 11065 return test_ipsec_proto_all(&flags); 11066 } 11067 11068 static int 11069 test_ipsec_proto_ipv6_set_dscp_0_inner_1(void) 11070 { 11071 struct ipsec_test_flags flags; 11072 11073 if (gbl_driver_id == rte_cryptodev_driver_id_get( 11074 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 11075 return TEST_SKIPPED; 11076 11077 memset(&flags, 0, sizeof(flags)); 11078 11079 flags.ipv6 = true; 11080 flags.tunnel_ipv6 = true; 11081 flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1; 11082 11083 return test_ipsec_proto_all(&flags); 11084 } 11085 11086 static int 11087 test_ipsec_proto_ipv6_set_dscp_1_inner_0(void) 11088 { 11089 struct ipsec_test_flags flags; 11090 11091 if (gbl_driver_id == rte_cryptodev_driver_id_get( 11092 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 11093 return TEST_SKIPPED; 11094 11095 memset(&flags, 0, sizeof(flags)); 11096 11097 flags.ipv6 = true; 11098 flags.tunnel_ipv6 = true; 11099 flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0; 11100 11101 return test_ipsec_proto_all(&flags); 11102 } 11103 11104 static int 11105 test_ipsec_proto_sgl(void) 11106 { 11107 struct crypto_testsuite_params *ts_params = &testsuite_params; 11108 struct rte_cryptodev_info dev_info; 11109 11110 struct ipsec_test_flags flags = { 11111 .nb_segs_in_mbuf = 5 11112 }; 11113 11114 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11115 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 11116 printf("Device doesn't support in-place scatter-gather. " 11117 "Test Skipped.\n"); 11118 return TEST_SKIPPED; 11119 } 11120 11121 return test_ipsec_proto_all(&flags); 11122 } 11123 11124 static int 11125 test_ipsec_proto_sgl_ext_mbuf(void) 11126 { 11127 struct crypto_testsuite_params *ts_params = &testsuite_params; 11128 struct rte_cryptodev_info dev_info; 11129 11130 struct ipsec_test_flags flags = { 11131 .nb_segs_in_mbuf = 5, 11132 .use_ext_mbuf = 1 11133 }; 11134 11135 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11136 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 11137 printf("Device doesn't support in-place scatter-gather. " 11138 "Test Skipped.\n"); 11139 return TEST_SKIPPED; 11140 } 11141 11142 return test_ipsec_proto_all(&flags); 11143 } 11144 11145 static int 11146 test_ipsec_pkt_replay(const void *test_data, const uint64_t esn[], 11147 bool replayed_pkt[], uint32_t nb_pkts, bool esn_en, 11148 uint64_t winsz) 11149 { 11150 struct ipsec_test_data td_outb[TEST_SEC_PKTS_MAX]; 11151 struct ipsec_test_data td_inb[TEST_SEC_PKTS_MAX]; 11152 struct ipsec_test_flags flags; 11153 uint32_t i = 0, ret = 0; 11154 11155 if (nb_pkts == 0) 11156 return TEST_FAILED; 11157 11158 memset(&flags, 0, sizeof(flags)); 11159 flags.antireplay = true; 11160 11161 for (i = 0; i < nb_pkts; i++) { 11162 memcpy(&td_outb[i], test_data, sizeof(td_outb[i])); 11163 td_outb[i].ipsec_xform.options.iv_gen_disable = 1; 11164 td_outb[i].ipsec_xform.replay_win_sz = winsz; 11165 td_outb[i].ipsec_xform.options.esn = esn_en; 11166 } 11167 11168 for (i = 0; i < nb_pkts; i++) 11169 td_outb[i].ipsec_xform.esn.value = esn[i]; 11170 11171 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 11172 &flags); 11173 if (ret != TEST_SUCCESS) 11174 return ret; 11175 11176 test_ipsec_td_update(td_inb, td_outb, nb_pkts, &flags); 11177 11178 for (i = 0; i < nb_pkts; i++) { 11179 td_inb[i].ipsec_xform.options.esn = esn_en; 11180 /* Set antireplay flag for packets to be dropped */ 11181 td_inb[i].ar_packet = replayed_pkt[i]; 11182 } 11183 11184 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 11185 &flags); 11186 11187 return ret; 11188 } 11189 11190 static int 11191 test_ipsec_proto_pkt_antireplay(const void *test_data, uint64_t winsz) 11192 { 11193 11194 uint32_t nb_pkts = 5; 11195 bool replayed_pkt[5]; 11196 uint64_t esn[5]; 11197 11198 /* 1. Advance the TOP of the window to WS * 2 */ 11199 esn[0] = winsz * 2; 11200 /* 2. Test sequence number within the new window(WS + 1) */ 11201 esn[1] = winsz + 1; 11202 /* 3. Test sequence number less than the window BOTTOM */ 11203 esn[2] = winsz; 11204 /* 4. Test sequence number in the middle of the window */ 11205 esn[3] = winsz + (winsz / 2); 11206 /* 5. Test replay of the packet in the middle of the window */ 11207 esn[4] = winsz + (winsz / 2); 11208 11209 replayed_pkt[0] = false; 11210 replayed_pkt[1] = false; 11211 replayed_pkt[2] = true; 11212 replayed_pkt[3] = false; 11213 replayed_pkt[4] = true; 11214 11215 return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts, 11216 false, winsz); 11217 } 11218 11219 static int 11220 test_ipsec_proto_pkt_antireplay1024(const void *test_data) 11221 { 11222 return test_ipsec_proto_pkt_antireplay(test_data, 1024); 11223 } 11224 11225 static int 11226 test_ipsec_proto_pkt_antireplay2048(const void *test_data) 11227 { 11228 return test_ipsec_proto_pkt_antireplay(test_data, 2048); 11229 } 11230 11231 static int 11232 test_ipsec_proto_pkt_antireplay4096(const void *test_data) 11233 { 11234 return test_ipsec_proto_pkt_antireplay(test_data, 4096); 11235 } 11236 11237 static int 11238 test_ipsec_proto_pkt_esn_antireplay(const void *test_data, uint64_t winsz) 11239 { 11240 11241 uint32_t nb_pkts = 7; 11242 bool replayed_pkt[7]; 11243 uint64_t esn[7]; 11244 11245 /* Set the initial sequence number */ 11246 esn[0] = (uint64_t)(0xFFFFFFFF - winsz); 11247 /* 1. Advance the TOP of the window to (1<<32 + WS/2) */ 11248 esn[1] = (uint64_t)((1ULL << 32) + (winsz / 2)); 11249 /* 2. Test sequence number within new window (1<<32 + WS/2 + 1) */ 11250 esn[2] = (uint64_t)((1ULL << 32) - (winsz / 2) + 1); 11251 /* 3. Test with sequence number within window (1<<32 - 1) */ 11252 esn[3] = (uint64_t)((1ULL << 32) - 1); 11253 /* 4. Test with sequence number within window (1<<32 - 1) */ 11254 esn[4] = (uint64_t)(1ULL << 32); 11255 /* 5. Test with duplicate sequence number within 11256 * new window (1<<32 - 1) 11257 */ 11258 esn[5] = (uint64_t)((1ULL << 32) - 1); 11259 /* 6. Test with duplicate sequence number within new window (1<<32) */ 11260 esn[6] = (uint64_t)(1ULL << 32); 11261 11262 replayed_pkt[0] = false; 11263 replayed_pkt[1] = false; 11264 replayed_pkt[2] = false; 11265 replayed_pkt[3] = false; 11266 replayed_pkt[4] = false; 11267 replayed_pkt[5] = true; 11268 replayed_pkt[6] = true; 11269 11270 return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts, 11271 true, winsz); 11272 } 11273 11274 static int 11275 test_ipsec_proto_pkt_esn_antireplay1024(const void *test_data) 11276 { 11277 return test_ipsec_proto_pkt_esn_antireplay(test_data, 1024); 11278 } 11279 11280 static int 11281 test_ipsec_proto_pkt_esn_antireplay2048(const void *test_data) 11282 { 11283 return test_ipsec_proto_pkt_esn_antireplay(test_data, 2048); 11284 } 11285 11286 static int 11287 test_ipsec_proto_pkt_esn_antireplay4096(const void *test_data) 11288 { 11289 return test_ipsec_proto_pkt_esn_antireplay(test_data, 4096); 11290 } 11291 11292 static int 11293 test_PDCP_PROTO_all(void) 11294 { 11295 struct crypto_testsuite_params *ts_params = &testsuite_params; 11296 struct crypto_unittest_params *ut_params = &unittest_params; 11297 struct rte_cryptodev_info dev_info; 11298 int status; 11299 11300 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11301 uint64_t feat_flags = dev_info.feature_flags; 11302 11303 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 11304 return TEST_SKIPPED; 11305 11306 /* Set action type */ 11307 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 11308 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 11309 gbl_action_type; 11310 11311 if (security_proto_supported(ut_params->type, 11312 RTE_SECURITY_PROTOCOL_PDCP) < 0) 11313 return TEST_SKIPPED; 11314 11315 status = test_PDCP_PROTO_cplane_encap_all(); 11316 status += test_PDCP_PROTO_cplane_decap_all(); 11317 status += test_PDCP_PROTO_uplane_encap_all(); 11318 status += test_PDCP_PROTO_uplane_decap_all(); 11319 status += test_PDCP_PROTO_SGL_in_place_32B(); 11320 status += test_PDCP_PROTO_SGL_oop_32B_128B(); 11321 status += test_PDCP_PROTO_SGL_oop_32B_40B(); 11322 status += test_PDCP_PROTO_SGL_oop_128B_32B(); 11323 status += test_PDCP_SDAP_PROTO_encap_all(); 11324 status += test_PDCP_SDAP_PROTO_decap_all(); 11325 status += test_PDCP_PROTO_short_mac(); 11326 11327 if (status) 11328 return TEST_FAILED; 11329 else 11330 return TEST_SUCCESS; 11331 } 11332 11333 static int 11334 test_ipsec_proto_ipv4_ttl_decrement(void) 11335 { 11336 struct ipsec_test_flags flags = { 11337 .dec_ttl_or_hop_limit = true 11338 }; 11339 11340 return test_ipsec_proto_all(&flags); 11341 } 11342 11343 static int 11344 test_ipsec_proto_ipv6_hop_limit_decrement(void) 11345 { 11346 struct ipsec_test_flags flags = { 11347 .ipv6 = true, 11348 .dec_ttl_or_hop_limit = true 11349 }; 11350 11351 return test_ipsec_proto_all(&flags); 11352 } 11353 11354 static int 11355 test_docsis_proto_uplink(const void *data) 11356 { 11357 const struct docsis_test_data *d_td = data; 11358 struct crypto_testsuite_params *ts_params = &testsuite_params; 11359 struct crypto_unittest_params *ut_params = &unittest_params; 11360 uint8_t *plaintext = NULL; 11361 uint8_t *ciphertext = NULL; 11362 uint8_t *iv_ptr; 11363 int32_t cipher_len, crc_len; 11364 uint32_t crc_data_len; 11365 int ret = TEST_SUCCESS; 11366 11367 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 11368 11369 /* Verify the capabilities */ 11370 struct rte_security_capability_idx sec_cap_idx; 11371 const struct rte_security_capability *sec_cap; 11372 const struct rte_cryptodev_capabilities *crypto_cap; 11373 const struct rte_cryptodev_symmetric_capability *sym_cap; 11374 int j = 0; 11375 11376 /* Set action type */ 11377 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 11378 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 11379 gbl_action_type; 11380 11381 if (security_proto_supported(ut_params->type, 11382 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 11383 return TEST_SKIPPED; 11384 11385 sec_cap_idx.action = ut_params->type; 11386 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 11387 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK; 11388 11389 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 11390 if (sec_cap == NULL) 11391 return TEST_SKIPPED; 11392 11393 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 11394 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 11395 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 11396 crypto_cap->sym.xform_type == 11397 RTE_CRYPTO_SYM_XFORM_CIPHER && 11398 crypto_cap->sym.cipher.algo == 11399 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 11400 sym_cap = &crypto_cap->sym; 11401 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 11402 d_td->key.len, 11403 d_td->iv.len) == 0) 11404 break; 11405 } 11406 } 11407 11408 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 11409 return TEST_SKIPPED; 11410 11411 /* Setup source mbuf payload */ 11412 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11413 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11414 rte_pktmbuf_tailroom(ut_params->ibuf)); 11415 11416 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11417 d_td->ciphertext.len); 11418 11419 memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len); 11420 11421 /* Setup cipher session parameters */ 11422 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11423 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 11424 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 11425 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 11426 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 11427 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 11428 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 11429 ut_params->cipher_xform.next = NULL; 11430 11431 /* Setup DOCSIS session parameters */ 11432 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK; 11433 11434 struct rte_security_session_conf sess_conf = { 11435 .action_type = ut_params->type, 11436 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 11437 .docsis = ut_params->docsis_xform, 11438 .crypto_xform = &ut_params->cipher_xform, 11439 }; 11440 11441 /* Create security session */ 11442 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 11443 ts_params->session_mpool); 11444 11445 if (!ut_params->sec_session) { 11446 printf("Test function %s line %u: failed to allocate session\n", 11447 __func__, __LINE__); 11448 ret = TEST_FAILED; 11449 goto on_err; 11450 } 11451 11452 /* Generate crypto op data structure */ 11453 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11454 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11455 if (!ut_params->op) { 11456 printf("Test function %s line %u: failed to allocate symmetric " 11457 "crypto operation\n", __func__, __LINE__); 11458 ret = TEST_FAILED; 11459 goto on_err; 11460 } 11461 11462 /* Setup CRC operation parameters */ 11463 crc_len = d_td->ciphertext.no_crc == false ? 11464 (d_td->ciphertext.len - 11465 d_td->ciphertext.crc_offset - 11466 RTE_ETHER_CRC_LEN) : 11467 0; 11468 crc_len = crc_len > 0 ? crc_len : 0; 11469 crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN; 11470 ut_params->op->sym->auth.data.length = crc_len; 11471 ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset; 11472 11473 /* Setup cipher operation parameters */ 11474 cipher_len = d_td->ciphertext.no_cipher == false ? 11475 (d_td->ciphertext.len - 11476 d_td->ciphertext.cipher_offset) : 11477 0; 11478 cipher_len = cipher_len > 0 ? cipher_len : 0; 11479 ut_params->op->sym->cipher.data.length = cipher_len; 11480 ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset; 11481 11482 /* Setup cipher IV */ 11483 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 11484 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 11485 11486 /* Attach session to operation */ 11487 rte_security_attach_session(ut_params->op, ut_params->sec_session); 11488 11489 /* Set crypto operation mbufs */ 11490 ut_params->op->sym->m_src = ut_params->ibuf; 11491 ut_params->op->sym->m_dst = NULL; 11492 11493 /* Process crypto operation */ 11494 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 11495 NULL) { 11496 printf("Test function %s line %u: failed to process security " 11497 "crypto op\n", __func__, __LINE__); 11498 ret = TEST_FAILED; 11499 goto on_err; 11500 } 11501 11502 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 11503 printf("Test function %s line %u: failed to process crypto op\n", 11504 __func__, __LINE__); 11505 ret = TEST_FAILED; 11506 goto on_err; 11507 } 11508 11509 /* Validate plaintext */ 11510 plaintext = ciphertext; 11511 11512 if (memcmp(plaintext, d_td->plaintext.data, 11513 d_td->plaintext.len - crc_data_len)) { 11514 printf("Test function %s line %u: plaintext not as expected\n", 11515 __func__, __LINE__); 11516 rte_hexdump(stdout, "expected", d_td->plaintext.data, 11517 d_td->plaintext.len); 11518 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len); 11519 ret = TEST_FAILED; 11520 goto on_err; 11521 } 11522 11523 on_err: 11524 rte_crypto_op_free(ut_params->op); 11525 ut_params->op = NULL; 11526 11527 if (ut_params->sec_session) 11528 rte_security_session_destroy(ctx, ut_params->sec_session); 11529 ut_params->sec_session = NULL; 11530 11531 rte_pktmbuf_free(ut_params->ibuf); 11532 ut_params->ibuf = NULL; 11533 11534 return ret; 11535 } 11536 11537 static int 11538 test_docsis_proto_downlink(const void *data) 11539 { 11540 const struct docsis_test_data *d_td = data; 11541 struct crypto_testsuite_params *ts_params = &testsuite_params; 11542 struct crypto_unittest_params *ut_params = &unittest_params; 11543 uint8_t *plaintext = NULL; 11544 uint8_t *ciphertext = NULL; 11545 uint8_t *iv_ptr; 11546 int32_t cipher_len, crc_len; 11547 int ret = TEST_SUCCESS; 11548 11549 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 11550 11551 /* Verify the capabilities */ 11552 struct rte_security_capability_idx sec_cap_idx; 11553 const struct rte_security_capability *sec_cap; 11554 const struct rte_cryptodev_capabilities *crypto_cap; 11555 const struct rte_cryptodev_symmetric_capability *sym_cap; 11556 int j = 0; 11557 11558 /* Set action type */ 11559 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 11560 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 11561 gbl_action_type; 11562 11563 if (security_proto_supported(ut_params->type, 11564 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 11565 return TEST_SKIPPED; 11566 11567 sec_cap_idx.action = ut_params->type; 11568 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 11569 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 11570 11571 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 11572 if (sec_cap == NULL) 11573 return TEST_SKIPPED; 11574 11575 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 11576 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 11577 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 11578 crypto_cap->sym.xform_type == 11579 RTE_CRYPTO_SYM_XFORM_CIPHER && 11580 crypto_cap->sym.cipher.algo == 11581 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 11582 sym_cap = &crypto_cap->sym; 11583 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 11584 d_td->key.len, 11585 d_td->iv.len) == 0) 11586 break; 11587 } 11588 } 11589 11590 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 11591 return TEST_SKIPPED; 11592 11593 /* Setup source mbuf payload */ 11594 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11595 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11596 rte_pktmbuf_tailroom(ut_params->ibuf)); 11597 11598 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11599 d_td->plaintext.len); 11600 11601 memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len); 11602 11603 /* Setup cipher session parameters */ 11604 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11605 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 11606 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 11607 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 11608 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 11609 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 11610 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 11611 ut_params->cipher_xform.next = NULL; 11612 11613 /* Setup DOCSIS session parameters */ 11614 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 11615 11616 struct rte_security_session_conf sess_conf = { 11617 .action_type = ut_params->type, 11618 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 11619 .docsis = ut_params->docsis_xform, 11620 .crypto_xform = &ut_params->cipher_xform, 11621 }; 11622 11623 /* Create security session */ 11624 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 11625 ts_params->session_mpool); 11626 11627 if (!ut_params->sec_session) { 11628 printf("Test function %s line %u: failed to allocate session\n", 11629 __func__, __LINE__); 11630 ret = TEST_FAILED; 11631 goto on_err; 11632 } 11633 11634 /* Generate crypto op data structure */ 11635 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11636 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11637 if (!ut_params->op) { 11638 printf("Test function %s line %u: failed to allocate symmetric " 11639 "crypto operation\n", __func__, __LINE__); 11640 ret = TEST_FAILED; 11641 goto on_err; 11642 } 11643 11644 /* Setup CRC operation parameters */ 11645 crc_len = d_td->plaintext.no_crc == false ? 11646 (d_td->plaintext.len - 11647 d_td->plaintext.crc_offset - 11648 RTE_ETHER_CRC_LEN) : 11649 0; 11650 crc_len = crc_len > 0 ? crc_len : 0; 11651 ut_params->op->sym->auth.data.length = crc_len; 11652 ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset; 11653 11654 /* Setup cipher operation parameters */ 11655 cipher_len = d_td->plaintext.no_cipher == false ? 11656 (d_td->plaintext.len - 11657 d_td->plaintext.cipher_offset) : 11658 0; 11659 cipher_len = cipher_len > 0 ? cipher_len : 0; 11660 ut_params->op->sym->cipher.data.length = cipher_len; 11661 ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset; 11662 11663 /* Setup cipher IV */ 11664 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 11665 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 11666 11667 /* Attach session to operation */ 11668 rte_security_attach_session(ut_params->op, ut_params->sec_session); 11669 11670 /* Set crypto operation mbufs */ 11671 ut_params->op->sym->m_src = ut_params->ibuf; 11672 ut_params->op->sym->m_dst = NULL; 11673 11674 /* Process crypto operation */ 11675 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 11676 NULL) { 11677 printf("Test function %s line %u: failed to process crypto op\n", 11678 __func__, __LINE__); 11679 ret = TEST_FAILED; 11680 goto on_err; 11681 } 11682 11683 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 11684 printf("Test function %s line %u: crypto op processing failed\n", 11685 __func__, __LINE__); 11686 ret = TEST_FAILED; 11687 goto on_err; 11688 } 11689 11690 /* Validate ciphertext */ 11691 ciphertext = plaintext; 11692 11693 if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) { 11694 printf("Test function %s line %u: plaintext not as expected\n", 11695 __func__, __LINE__); 11696 rte_hexdump(stdout, "expected", d_td->ciphertext.data, 11697 d_td->ciphertext.len); 11698 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len); 11699 ret = TEST_FAILED; 11700 goto on_err; 11701 } 11702 11703 on_err: 11704 rte_crypto_op_free(ut_params->op); 11705 ut_params->op = NULL; 11706 11707 if (ut_params->sec_session) 11708 rte_security_session_destroy(ctx, ut_params->sec_session); 11709 ut_params->sec_session = NULL; 11710 11711 rte_pktmbuf_free(ut_params->ibuf); 11712 ut_params->ibuf = NULL; 11713 11714 return ret; 11715 } 11716 11717 static void 11718 test_tls_record_imp_nonce_update(const struct tls_record_test_data *td, 11719 struct rte_security_tls_record_xform *tls_record_xform) 11720 { 11721 unsigned int imp_nonce_len; 11722 uint8_t *imp_nonce; 11723 11724 switch (tls_record_xform->ver) { 11725 case RTE_SECURITY_VERSION_TLS_1_2: 11726 imp_nonce_len = RTE_SECURITY_TLS_1_2_IMP_NONCE_LEN; 11727 imp_nonce = tls_record_xform->tls_1_2.imp_nonce; 11728 break; 11729 case RTE_SECURITY_VERSION_DTLS_1_2: 11730 imp_nonce_len = RTE_SECURITY_DTLS_1_2_IMP_NONCE_LEN; 11731 imp_nonce = tls_record_xform->dtls_1_2.imp_nonce; 11732 break; 11733 case RTE_SECURITY_VERSION_TLS_1_3: 11734 imp_nonce_len = RTE_SECURITY_TLS_1_3_IMP_NONCE_LEN; 11735 imp_nonce = tls_record_xform->tls_1_3.imp_nonce; 11736 break; 11737 default: 11738 return; 11739 } 11740 11741 imp_nonce_len = RTE_MIN(imp_nonce_len, td[0].imp_nonce.len); 11742 memcpy(imp_nonce, td[0].imp_nonce.data, imp_nonce_len); 11743 } 11744 11745 static int 11746 test_tls_record_proto_process(const struct tls_record_test_data td[], 11747 struct tls_record_test_data res_d[], int nb_td, bool silent, 11748 const struct tls_record_test_flags *flags) 11749 { 11750 int nb_segs = flags->nb_segs_in_mbuf ? flags->nb_segs_in_mbuf : 1; 11751 struct crypto_testsuite_params *ts_params = &testsuite_params; 11752 struct crypto_unittest_params *ut_params = &unittest_params; 11753 struct rte_security_tls_record_xform tls_record_xform; 11754 struct rte_security_capability_idx sec_cap_idx; 11755 const struct rte_security_capability *sec_cap; 11756 struct tls_record_test_data *res_d_tmp = NULL; 11757 enum rte_security_tls_sess_type sess_type; 11758 uint8_t dev_id = ts_params->valid_devs[0]; 11759 struct rte_security_ctx *ctx; 11760 int i, ret = TEST_SUCCESS; 11761 11762 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 11763 gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 11764 11765 /* Use first test data to create session */ 11766 11767 /* Copy TLS record xform */ 11768 memcpy(&tls_record_xform, &td[0].tls_record_xform, sizeof(tls_record_xform)); 11769 11770 sess_type = tls_record_xform.type; 11771 11772 ctx = rte_cryptodev_get_sec_ctx(dev_id); 11773 11774 sec_cap_idx.action = ut_params->type; 11775 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_TLS_RECORD; 11776 sec_cap_idx.tls_record.type = tls_record_xform.type; 11777 sec_cap_idx.tls_record.ver = tls_record_xform.ver; 11778 11779 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 11780 if (sec_cap == NULL) 11781 return TEST_SKIPPED; 11782 11783 /* Copy cipher session parameters */ 11784 if (td[0].aead) { 11785 memcpy(&ut_params->aead_xform, &td[0].xform.aead, sizeof(ut_params->aead_xform)); 11786 ut_params->aead_xform.aead.key.data = td[0].key.data; 11787 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 11788 11789 /* Verify crypto capabilities */ 11790 if (test_sec_crypto_caps_aead_verify(sec_cap, &ut_params->aead_xform) != 0) { 11791 if (!silent) 11792 RTE_LOG(INFO, USER1, "Crypto capabilities not supported\n"); 11793 return TEST_SKIPPED; 11794 } 11795 } else { 11796 memcpy(&ut_params->cipher_xform, &td[0].xform.chain.cipher, 11797 sizeof(ut_params->cipher_xform)); 11798 memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth, 11799 sizeof(ut_params->auth_xform)); 11800 ut_params->cipher_xform.cipher.key.data = td[0].key.data; 11801 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 11802 ut_params->auth_xform.auth.key.data = td[0].auth_key.data; 11803 11804 /* Verify crypto capabilities */ 11805 11806 if (test_sec_crypto_caps_cipher_verify(sec_cap, &ut_params->cipher_xform) != 0) { 11807 if (!silent) 11808 RTE_LOG(INFO, USER1, "Cipher crypto capabilities not supported\n"); 11809 return TEST_SKIPPED; 11810 } 11811 11812 if (test_sec_crypto_caps_auth_verify(sec_cap, &ut_params->auth_xform) != 0) { 11813 if (!silent) 11814 RTE_LOG(INFO, USER1, "Auth crypto capabilities not supported\n"); 11815 return TEST_SKIPPED; 11816 } 11817 } 11818 11819 if (test_tls_record_sec_caps_verify(&tls_record_xform, sec_cap, silent) != 0) 11820 return TEST_SKIPPED; 11821 11822 struct rte_security_session_conf sess_conf = { 11823 .action_type = ut_params->type, 11824 .protocol = RTE_SECURITY_PROTOCOL_TLS_RECORD, 11825 }; 11826 11827 if (td[0].aead) 11828 test_tls_record_imp_nonce_update(&td[0], &tls_record_xform); 11829 11830 sess_conf.tls_record = tls_record_xform; 11831 11832 if (td[0].aead) { 11833 sess_conf.crypto_xform = &ut_params->aead_xform; 11834 } else { 11835 if (sess_type == RTE_SECURITY_TLS_SESS_TYPE_READ) { 11836 sess_conf.crypto_xform = &ut_params->cipher_xform; 11837 ut_params->cipher_xform.next = &ut_params->auth_xform; 11838 } else { 11839 sess_conf.crypto_xform = &ut_params->auth_xform; 11840 ut_params->auth_xform.next = &ut_params->cipher_xform; 11841 } 11842 } 11843 11844 /* Create security session */ 11845 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 11846 ts_params->session_mpool); 11847 if (ut_params->sec_session == NULL) 11848 return TEST_SKIPPED; 11849 11850 for (i = 0; i < nb_td; i++) { 11851 /* Setup source mbuf payload */ 11852 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, td[i].input_text.len, 11853 nb_segs, 0); 11854 pktmbuf_write(ut_params->ibuf, 0, td[i].input_text.len, td[i].input_text.data); 11855 11856 /* Generate crypto op data structure */ 11857 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11858 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11859 if (ut_params->op == NULL) { 11860 printf("Could not allocate crypto op"); 11861 ret = TEST_FAILED; 11862 goto crypto_op_free; 11863 } 11864 11865 /* Attach session to operation */ 11866 rte_security_attach_session(ut_params->op, ut_params->sec_session); 11867 11868 /* Set crypto operation mbufs */ 11869 ut_params->op->sym->m_src = ut_params->ibuf; 11870 ut_params->op->sym->m_dst = NULL; 11871 ut_params->op->param1.tls_record.content_type = td[i].app_type; 11872 11873 /* Copy IV in crypto operation when IV generation is disabled */ 11874 if (sess_type == RTE_SECURITY_TLS_SESS_TYPE_WRITE && 11875 tls_record_xform.options.iv_gen_disable == 1) { 11876 uint8_t *iv; 11877 int len; 11878 11879 iv = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET); 11880 if (td[i].aead) 11881 len = td[i].xform.aead.aead.iv.length - 4; 11882 else 11883 len = td[i].xform.chain.cipher.cipher.iv.length; 11884 memcpy(iv, td[i].iv.data, len); 11885 } 11886 11887 /* Process crypto operation */ 11888 process_crypto_request(dev_id, ut_params->op); 11889 11890 ret = test_tls_record_status_check(ut_params->op); 11891 if (ret != TEST_SUCCESS) 11892 goto crypto_op_free; 11893 11894 if (res_d != NULL) 11895 res_d_tmp = &res_d[i]; 11896 11897 ret = test_tls_record_post_process(ut_params->ibuf, &td[i], res_d_tmp, silent); 11898 if (ret != TEST_SUCCESS) 11899 goto crypto_op_free; 11900 11901 11902 rte_crypto_op_free(ut_params->op); 11903 ut_params->op = NULL; 11904 11905 rte_pktmbuf_free(ut_params->ibuf); 11906 ut_params->ibuf = NULL; 11907 } 11908 11909 crypto_op_free: 11910 rte_crypto_op_free(ut_params->op); 11911 ut_params->op = NULL; 11912 11913 rte_pktmbuf_free(ut_params->ibuf); 11914 ut_params->ibuf = NULL; 11915 11916 if (ut_params->sec_session) 11917 rte_security_session_destroy(ctx, ut_params->sec_session); 11918 ut_params->sec_session = NULL; 11919 11920 RTE_SET_USED(flags); 11921 11922 return ret; 11923 } 11924 11925 static int 11926 test_tls_record_proto_known_vec(const void *test_data) 11927 { 11928 struct tls_record_test_data td_write; 11929 struct tls_record_test_flags flags; 11930 11931 memset(&flags, 0, sizeof(flags)); 11932 11933 memcpy(&td_write, test_data, sizeof(td_write)); 11934 11935 /* Disable IV gen to be able to test with known vectors */ 11936 td_write.tls_record_xform.options.iv_gen_disable = 1; 11937 11938 return test_tls_record_proto_process(&td_write, NULL, 1, false, &flags); 11939 } 11940 11941 static int 11942 test_tls_record_proto_known_vec_read(const void *test_data) 11943 { 11944 const struct tls_record_test_data *td = test_data; 11945 struct tls_record_test_flags flags; 11946 struct tls_record_test_data td_inb; 11947 11948 memset(&flags, 0, sizeof(flags)); 11949 11950 if (td->tls_record_xform.type == RTE_SECURITY_TLS_SESS_TYPE_WRITE) 11951 test_tls_record_td_read_from_write(td, &td_inb); 11952 else 11953 memcpy(&td_inb, td, sizeof(td_inb)); 11954 11955 return test_tls_record_proto_process(&td_inb, NULL, 1, false, &flags); 11956 } 11957 11958 static int 11959 test_tls_record_proto_all(const struct tls_record_test_flags *flags) 11960 { 11961 struct tls_record_test_data td_outb[TEST_SEC_PKTS_MAX]; 11962 struct tls_record_test_data td_inb[TEST_SEC_PKTS_MAX]; 11963 unsigned int i, nb_pkts = 1, pass_cnt = 0; 11964 int ret; 11965 11966 for (i = 0; i < RTE_DIM(sec_alg_list); i++) { 11967 test_tls_record_td_prepare(sec_alg_list[i].param1, sec_alg_list[i].param2, flags, 11968 td_outb, nb_pkts); 11969 11970 ret = test_tls_record_proto_process(td_outb, td_inb, nb_pkts, true, flags); 11971 if (ret == TEST_SKIPPED) 11972 continue; 11973 11974 if (ret == TEST_FAILED) 11975 return TEST_FAILED; 11976 11977 test_tls_record_td_update(td_inb, td_outb, nb_pkts, flags); 11978 11979 ret = test_tls_record_proto_process(td_inb, NULL, nb_pkts, true, flags); 11980 if (ret == TEST_SKIPPED) 11981 continue; 11982 11983 if (ret == TEST_FAILED) 11984 return TEST_FAILED; 11985 11986 if (flags->display_alg) 11987 test_sec_alg_display(sec_alg_list[i].param1, sec_alg_list[i].param2); 11988 11989 pass_cnt++; 11990 } 11991 11992 if (pass_cnt > 0) 11993 return TEST_SUCCESS; 11994 else 11995 return TEST_SKIPPED; 11996 } 11997 11998 static int 11999 test_tls_record_proto_display_list(void) 12000 { 12001 struct tls_record_test_flags flags; 12002 12003 memset(&flags, 0, sizeof(flags)); 12004 12005 flags.display_alg = true; 12006 12007 return test_tls_record_proto_all(&flags); 12008 } 12009 12010 static int 12011 test_tls_record_proto_sgl(void) 12012 { 12013 struct tls_record_test_flags flags = { 12014 .nb_segs_in_mbuf = 5 12015 }; 12016 struct crypto_testsuite_params *ts_params = &testsuite_params; 12017 struct rte_cryptodev_info dev_info; 12018 12019 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12020 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 12021 printf("Device doesn't support in-place scatter-gather. Test Skipped.\n"); 12022 return TEST_SKIPPED; 12023 } 12024 12025 return test_tls_record_proto_all(&flags); 12026 } 12027 12028 #endif 12029 12030 static int 12031 test_AES_GCM_authenticated_encryption_test_case_1(void) 12032 { 12033 return test_authenticated_encryption(&gcm_test_case_1); 12034 } 12035 12036 static int 12037 test_AES_GCM_authenticated_encryption_test_case_2(void) 12038 { 12039 return test_authenticated_encryption(&gcm_test_case_2); 12040 } 12041 12042 static int 12043 test_AES_GCM_authenticated_encryption_test_case_3(void) 12044 { 12045 return test_authenticated_encryption(&gcm_test_case_3); 12046 } 12047 12048 static int 12049 test_AES_GCM_authenticated_encryption_test_case_3_ext_mbuf(void) 12050 { 12051 return test_authenticated_encryption_helper(&gcm_test_case_3, true); 12052 } 12053 12054 static int 12055 test_AES_GCM_authenticated_encryption_test_case_4(void) 12056 { 12057 return test_authenticated_encryption(&gcm_test_case_4); 12058 } 12059 12060 static int 12061 test_AES_GCM_authenticated_encryption_test_case_5(void) 12062 { 12063 return test_authenticated_encryption(&gcm_test_case_5); 12064 } 12065 12066 static int 12067 test_AES_GCM_authenticated_encryption_test_case_6(void) 12068 { 12069 return test_authenticated_encryption(&gcm_test_case_6); 12070 } 12071 12072 static int 12073 test_AES_GCM_authenticated_encryption_test_case_7(void) 12074 { 12075 return test_authenticated_encryption(&gcm_test_case_7); 12076 } 12077 12078 static int 12079 test_AES_GCM_authenticated_encryption_test_case_8(void) 12080 { 12081 return test_authenticated_encryption(&gcm_test_case_8); 12082 } 12083 12084 static int 12085 test_AES_GCM_J0_authenticated_encryption_test_case_1(void) 12086 { 12087 return test_authenticated_encryption(&gcm_J0_test_case_1); 12088 } 12089 12090 static int 12091 test_AES_GCM_auth_encryption_test_case_192_1(void) 12092 { 12093 return test_authenticated_encryption(&gcm_test_case_192_1); 12094 } 12095 12096 static int 12097 test_AES_GCM_auth_encryption_test_case_192_2(void) 12098 { 12099 return test_authenticated_encryption(&gcm_test_case_192_2); 12100 } 12101 12102 static int 12103 test_AES_GCM_auth_encryption_test_case_192_3(void) 12104 { 12105 return test_authenticated_encryption(&gcm_test_case_192_3); 12106 } 12107 12108 static int 12109 test_AES_GCM_auth_encryption_test_case_192_4(void) 12110 { 12111 return test_authenticated_encryption(&gcm_test_case_192_4); 12112 } 12113 12114 static int 12115 test_AES_GCM_auth_encryption_test_case_192_5(void) 12116 { 12117 return test_authenticated_encryption(&gcm_test_case_192_5); 12118 } 12119 12120 static int 12121 test_AES_GCM_auth_encryption_test_case_192_6(void) 12122 { 12123 return test_authenticated_encryption(&gcm_test_case_192_6); 12124 } 12125 12126 static int 12127 test_AES_GCM_auth_encryption_test_case_192_7(void) 12128 { 12129 return test_authenticated_encryption(&gcm_test_case_192_7); 12130 } 12131 12132 static int 12133 test_AES_GCM_auth_encryption_test_case_256_1(void) 12134 { 12135 return test_authenticated_encryption(&gcm_test_case_256_1); 12136 } 12137 12138 static int 12139 test_AES_GCM_auth_encryption_test_case_256_2(void) 12140 { 12141 return test_authenticated_encryption(&gcm_test_case_256_2); 12142 } 12143 12144 static int 12145 test_AES_GCM_auth_encryption_test_case_256_3(void) 12146 { 12147 return test_authenticated_encryption(&gcm_test_case_256_3); 12148 } 12149 12150 static int 12151 test_AES_GCM_auth_encryption_test_case_256_4(void) 12152 { 12153 return test_authenticated_encryption(&gcm_test_case_256_4); 12154 } 12155 12156 static int 12157 test_AES_GCM_auth_encryption_test_case_256_5(void) 12158 { 12159 return test_authenticated_encryption(&gcm_test_case_256_5); 12160 } 12161 12162 static int 12163 test_AES_GCM_auth_encryption_test_case_256_6(void) 12164 { 12165 return test_authenticated_encryption(&gcm_test_case_256_6); 12166 } 12167 12168 static int 12169 test_AES_GCM_auth_encryption_test_case_256_7(void) 12170 { 12171 return test_authenticated_encryption(&gcm_test_case_256_7); 12172 } 12173 12174 static int 12175 test_AES_GCM_auth_encryption_test_case_aad_1(void) 12176 { 12177 return test_authenticated_encryption(&gcm_test_case_aad_1); 12178 } 12179 12180 static int 12181 test_AES_GCM_auth_encryption_test_case_aad_2(void) 12182 { 12183 return test_authenticated_encryption(&gcm_test_case_aad_2); 12184 } 12185 12186 static int 12187 test_AES_GCM_auth_encryption_fail_iv_corrupt(void) 12188 { 12189 struct aead_test_data tdata; 12190 int res; 12191 12192 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12193 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12194 tdata.iv.data[0] += 1; 12195 res = test_authenticated_encryption(&tdata); 12196 if (res == TEST_SKIPPED) 12197 return res; 12198 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 12199 return TEST_SUCCESS; 12200 } 12201 12202 static int 12203 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void) 12204 { 12205 struct aead_test_data tdata; 12206 int res; 12207 12208 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12209 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12210 tdata.plaintext.data[0] += 1; 12211 res = test_authenticated_encryption(&tdata); 12212 if (res == TEST_SKIPPED) 12213 return res; 12214 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 12215 return TEST_SUCCESS; 12216 } 12217 12218 static int 12219 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void) 12220 { 12221 struct aead_test_data tdata; 12222 int res; 12223 12224 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12225 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12226 tdata.ciphertext.data[0] += 1; 12227 res = test_authenticated_encryption(&tdata); 12228 if (res == TEST_SKIPPED) 12229 return res; 12230 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 12231 return TEST_SUCCESS; 12232 } 12233 12234 static int 12235 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void) 12236 { 12237 struct aead_test_data tdata; 12238 int res; 12239 12240 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12241 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12242 tdata.aad.len += 1; 12243 res = test_authenticated_encryption(&tdata); 12244 if (res == TEST_SKIPPED) 12245 return res; 12246 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 12247 return TEST_SUCCESS; 12248 } 12249 12250 static int 12251 test_AES_GCM_auth_encryption_fail_aad_corrupt(void) 12252 { 12253 struct aead_test_data tdata; 12254 uint8_t aad[gcm_test_case_7.aad.len]; 12255 int res; 12256 12257 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12258 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12259 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 12260 aad[0] += 1; 12261 tdata.aad.data = aad; 12262 res = test_authenticated_encryption(&tdata); 12263 if (res == TEST_SKIPPED) 12264 return res; 12265 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 12266 return TEST_SUCCESS; 12267 } 12268 12269 static int 12270 test_AES_GCM_auth_encryption_fail_tag_corrupt(void) 12271 { 12272 struct aead_test_data tdata; 12273 int res; 12274 12275 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12276 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12277 tdata.auth_tag.data[0] += 1; 12278 res = test_authenticated_encryption(&tdata); 12279 if (res == TEST_SKIPPED) 12280 return res; 12281 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 12282 return TEST_SUCCESS; 12283 } 12284 12285 static int 12286 test_authenticated_decryption_helper(const struct aead_test_data *tdata, bool use_ext_mbuf) 12287 { 12288 struct crypto_testsuite_params *ts_params = &testsuite_params; 12289 struct crypto_unittest_params *ut_params = &unittest_params; 12290 12291 int retval; 12292 uint8_t *plaintext; 12293 uint32_t i; 12294 struct rte_cryptodev_info dev_info; 12295 12296 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12297 uint64_t feat_flags = dev_info.feature_flags; 12298 12299 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12300 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12301 printf("Device doesn't support RAW data-path APIs.\n"); 12302 return TEST_SKIPPED; 12303 } 12304 12305 /* Verify the capabilities */ 12306 struct rte_cryptodev_sym_capability_idx cap_idx; 12307 const struct rte_cryptodev_symmetric_capability *capability; 12308 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12309 cap_idx.algo.aead = tdata->algo; 12310 capability = rte_cryptodev_sym_capability_get( 12311 ts_params->valid_devs[0], &cap_idx); 12312 if (capability == NULL) 12313 return TEST_SKIPPED; 12314 if (rte_cryptodev_sym_capability_check_aead( 12315 capability, tdata->key.len, tdata->auth_tag.len, 12316 tdata->aad.len, tdata->iv.len)) 12317 return TEST_SKIPPED; 12318 12319 /* Create AEAD session */ 12320 retval = create_aead_session(ts_params->valid_devs[0], 12321 tdata->algo, 12322 RTE_CRYPTO_AEAD_OP_DECRYPT, 12323 tdata->key.data, tdata->key.len, 12324 tdata->aad.len, tdata->auth_tag.len, 12325 tdata->iv.len); 12326 if (retval != TEST_SUCCESS) 12327 return retval; 12328 12329 /* alloc mbuf and set payload */ 12330 if (tdata->aad.len > MBUF_SIZE) { 12331 if (use_ext_mbuf) { 12332 ut_params->ibuf = ext_mbuf_create(ts_params->large_mbuf_pool, 12333 AEAD_TEXT_MAX_LENGTH, 12334 1 /* nb_segs */, 12335 NULL); 12336 } else { 12337 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 12338 } 12339 /* Populate full size of add data */ 12340 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 12341 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 12342 } else { 12343 if (use_ext_mbuf) { 12344 ut_params->ibuf = ext_mbuf_create(ts_params->mbuf_pool, 12345 AEAD_TEXT_MAX_LENGTH, 12346 1 /* nb_segs */, 12347 NULL); 12348 } else { 12349 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12350 } 12351 } 12352 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12353 rte_pktmbuf_tailroom(ut_params->ibuf)); 12354 12355 /* Create AEAD operation */ 12356 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 12357 if (retval < 0) 12358 return retval; 12359 12360 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12361 12362 ut_params->op->sym->m_src = ut_params->ibuf; 12363 12364 /* Process crypto operation */ 12365 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12366 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 12367 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 12368 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 12369 0); 12370 if (retval != TEST_SUCCESS) 12371 return retval; 12372 } else 12373 TEST_ASSERT_NOT_NULL( 12374 process_crypto_request(ts_params->valid_devs[0], 12375 ut_params->op), "failed to process sym crypto op"); 12376 12377 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12378 "crypto op processing failed"); 12379 12380 if (ut_params->op->sym->m_dst) 12381 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 12382 uint8_t *); 12383 else 12384 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 12385 uint8_t *, 12386 ut_params->op->sym->cipher.data.offset); 12387 12388 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 12389 12390 /* Validate obuf */ 12391 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12392 plaintext, 12393 tdata->plaintext.data, 12394 tdata->plaintext.len, 12395 "Plaintext data not as expected"); 12396 12397 TEST_ASSERT_EQUAL(ut_params->op->status, 12398 RTE_CRYPTO_OP_STATUS_SUCCESS, 12399 "Authentication failed"); 12400 12401 return 0; 12402 } 12403 12404 static int 12405 test_authenticated_decryption(const struct aead_test_data *tdata) 12406 { 12407 return test_authenticated_decryption_helper(tdata, false); 12408 } 12409 12410 static int 12411 test_AES_GCM_authenticated_decryption_test_case_1(void) 12412 { 12413 return test_authenticated_decryption(&gcm_test_case_1); 12414 } 12415 12416 static int 12417 test_AES_GCM_authenticated_decryption_test_case_2(void) 12418 { 12419 return test_authenticated_decryption(&gcm_test_case_2); 12420 } 12421 12422 static int 12423 test_AES_GCM_authenticated_decryption_test_case_3(void) 12424 { 12425 return test_authenticated_decryption(&gcm_test_case_3); 12426 } 12427 12428 static int 12429 test_AES_GCM_authenticated_decryption_test_case_3_ext_mbuf(void) 12430 { 12431 return test_authenticated_decryption_helper(&gcm_test_case_3, true); 12432 } 12433 12434 static int 12435 test_AES_GCM_authenticated_decryption_test_case_4(void) 12436 { 12437 return test_authenticated_decryption(&gcm_test_case_4); 12438 } 12439 12440 static int 12441 test_AES_GCM_authenticated_decryption_test_case_5(void) 12442 { 12443 return test_authenticated_decryption(&gcm_test_case_5); 12444 } 12445 12446 static int 12447 test_AES_GCM_authenticated_decryption_test_case_6(void) 12448 { 12449 return test_authenticated_decryption(&gcm_test_case_6); 12450 } 12451 12452 static int 12453 test_AES_GCM_authenticated_decryption_test_case_7(void) 12454 { 12455 return test_authenticated_decryption(&gcm_test_case_7); 12456 } 12457 12458 static int 12459 test_AES_GCM_authenticated_decryption_test_case_8(void) 12460 { 12461 return test_authenticated_decryption(&gcm_test_case_8); 12462 } 12463 12464 static int 12465 test_AES_GCM_J0_authenticated_decryption_test_case_1(void) 12466 { 12467 return test_authenticated_decryption(&gcm_J0_test_case_1); 12468 } 12469 12470 static int 12471 test_AES_GCM_auth_decryption_test_case_192_1(void) 12472 { 12473 return test_authenticated_decryption(&gcm_test_case_192_1); 12474 } 12475 12476 static int 12477 test_AES_GCM_auth_decryption_test_case_192_2(void) 12478 { 12479 return test_authenticated_decryption(&gcm_test_case_192_2); 12480 } 12481 12482 static int 12483 test_AES_GCM_auth_decryption_test_case_192_3(void) 12484 { 12485 return test_authenticated_decryption(&gcm_test_case_192_3); 12486 } 12487 12488 static int 12489 test_AES_GCM_auth_decryption_test_case_192_4(void) 12490 { 12491 return test_authenticated_decryption(&gcm_test_case_192_4); 12492 } 12493 12494 static int 12495 test_AES_GCM_auth_decryption_test_case_192_5(void) 12496 { 12497 return test_authenticated_decryption(&gcm_test_case_192_5); 12498 } 12499 12500 static int 12501 test_AES_GCM_auth_decryption_test_case_192_6(void) 12502 { 12503 return test_authenticated_decryption(&gcm_test_case_192_6); 12504 } 12505 12506 static int 12507 test_AES_GCM_auth_decryption_test_case_192_7(void) 12508 { 12509 return test_authenticated_decryption(&gcm_test_case_192_7); 12510 } 12511 12512 static int 12513 test_AES_GCM_auth_decryption_test_case_256_1(void) 12514 { 12515 return test_authenticated_decryption(&gcm_test_case_256_1); 12516 } 12517 12518 static int 12519 test_AES_GCM_auth_decryption_test_case_256_2(void) 12520 { 12521 return test_authenticated_decryption(&gcm_test_case_256_2); 12522 } 12523 12524 static int 12525 test_AES_GCM_auth_decryption_test_case_256_3(void) 12526 { 12527 return test_authenticated_decryption(&gcm_test_case_256_3); 12528 } 12529 12530 static int 12531 test_AES_GCM_auth_decryption_test_case_256_4(void) 12532 { 12533 return test_authenticated_decryption(&gcm_test_case_256_4); 12534 } 12535 12536 static int 12537 test_AES_GCM_auth_decryption_test_case_256_5(void) 12538 { 12539 return test_authenticated_decryption(&gcm_test_case_256_5); 12540 } 12541 12542 static int 12543 test_AES_GCM_auth_decryption_test_case_256_6(void) 12544 { 12545 return test_authenticated_decryption(&gcm_test_case_256_6); 12546 } 12547 12548 static int 12549 test_AES_GCM_auth_decryption_test_case_256_7(void) 12550 { 12551 return test_authenticated_decryption(&gcm_test_case_256_7); 12552 } 12553 12554 static int 12555 test_AES_GCM_auth_decryption_test_case_256_8(void) 12556 { 12557 return test_authenticated_decryption(&gcm_test_case_256_8); 12558 } 12559 12560 static int 12561 test_AES_GCM_auth_encryption_test_case_256_8(void) 12562 { 12563 return test_authenticated_encryption(&gcm_test_case_256_8); 12564 } 12565 12566 static int 12567 test_AES_GCM_auth_decryption_test_case_aad_1(void) 12568 { 12569 return test_authenticated_decryption(&gcm_test_case_aad_1); 12570 } 12571 12572 static int 12573 test_AES_GCM_auth_decryption_test_case_aad_2(void) 12574 { 12575 return test_authenticated_decryption(&gcm_test_case_aad_2); 12576 } 12577 12578 static int 12579 test_AES_GCM_auth_decryption_fail_iv_corrupt(void) 12580 { 12581 struct aead_test_data tdata; 12582 int res; 12583 12584 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12585 tdata.iv.data[0] += 1; 12586 res = test_authenticated_decryption(&tdata); 12587 if (res == TEST_SKIPPED) 12588 return res; 12589 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12590 return TEST_SUCCESS; 12591 } 12592 12593 static int 12594 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void) 12595 { 12596 struct aead_test_data tdata; 12597 int res; 12598 12599 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12600 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12601 tdata.plaintext.data[0] += 1; 12602 res = test_authenticated_decryption(&tdata); 12603 if (res == TEST_SKIPPED) 12604 return res; 12605 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12606 return TEST_SUCCESS; 12607 } 12608 12609 static int 12610 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void) 12611 { 12612 struct aead_test_data tdata; 12613 int res; 12614 12615 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12616 tdata.ciphertext.data[0] += 1; 12617 res = test_authenticated_decryption(&tdata); 12618 if (res == TEST_SKIPPED) 12619 return res; 12620 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12621 return TEST_SUCCESS; 12622 } 12623 12624 static int 12625 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void) 12626 { 12627 struct aead_test_data tdata; 12628 int res; 12629 12630 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12631 tdata.aad.len += 1; 12632 res = test_authenticated_decryption(&tdata); 12633 if (res == TEST_SKIPPED) 12634 return res; 12635 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12636 return TEST_SUCCESS; 12637 } 12638 12639 static int 12640 test_AES_GCM_auth_decryption_fail_aad_corrupt(void) 12641 { 12642 struct aead_test_data tdata; 12643 uint8_t aad[gcm_test_case_7.aad.len]; 12644 int res; 12645 12646 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12647 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 12648 aad[0] += 1; 12649 tdata.aad.data = aad; 12650 res = test_authenticated_decryption(&tdata); 12651 if (res == TEST_SKIPPED) 12652 return res; 12653 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12654 return TEST_SUCCESS; 12655 } 12656 12657 static int 12658 test_AES_GCM_auth_decryption_fail_tag_corrupt(void) 12659 { 12660 struct aead_test_data tdata; 12661 int res; 12662 12663 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12664 tdata.auth_tag.data[0] += 1; 12665 res = test_authenticated_decryption(&tdata); 12666 if (res == TEST_SKIPPED) 12667 return res; 12668 TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed"); 12669 return TEST_SUCCESS; 12670 } 12671 12672 static int 12673 test_authenticated_encryption_oop(const struct aead_test_data *tdata) 12674 { 12675 struct crypto_testsuite_params *ts_params = &testsuite_params; 12676 struct crypto_unittest_params *ut_params = &unittest_params; 12677 12678 int retval; 12679 uint8_t *ciphertext, *auth_tag; 12680 uint16_t plaintext_pad_len; 12681 struct rte_cryptodev_info dev_info; 12682 12683 /* Verify the capabilities */ 12684 struct rte_cryptodev_sym_capability_idx cap_idx; 12685 const struct rte_cryptodev_symmetric_capability *capability; 12686 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12687 cap_idx.algo.aead = tdata->algo; 12688 capability = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], &cap_idx); 12689 if (capability == NULL) 12690 return TEST_SKIPPED; 12691 if (rte_cryptodev_sym_capability_check_aead( 12692 capability, tdata->key.len, tdata->auth_tag.len, 12693 tdata->aad.len, tdata->iv.len)) 12694 return TEST_SKIPPED; 12695 12696 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12697 uint64_t feat_flags = dev_info.feature_flags; 12698 12699 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12700 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) 12701 return TEST_SKIPPED; 12702 12703 /* not supported with CPU crypto */ 12704 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12705 return TEST_SKIPPED; 12706 12707 /* Create AEAD session */ 12708 retval = create_aead_session(ts_params->valid_devs[0], 12709 tdata->algo, 12710 RTE_CRYPTO_AEAD_OP_ENCRYPT, 12711 tdata->key.data, tdata->key.len, 12712 tdata->aad.len, tdata->auth_tag.len, 12713 tdata->iv.len); 12714 if (retval < 0) 12715 return retval; 12716 12717 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12718 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12719 12720 /* clear mbuf payload */ 12721 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12722 rte_pktmbuf_tailroom(ut_params->ibuf)); 12723 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 12724 rte_pktmbuf_tailroom(ut_params->obuf)); 12725 12726 /* Create AEAD operation */ 12727 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 12728 if (retval < 0) 12729 return retval; 12730 12731 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12732 12733 ut_params->op->sym->m_src = ut_params->ibuf; 12734 ut_params->op->sym->m_dst = ut_params->obuf; 12735 12736 /* Process crypto operation */ 12737 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 12738 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 12739 0); 12740 if (retval != TEST_SUCCESS) 12741 return retval; 12742 } else 12743 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 12744 ut_params->op), "failed to process sym crypto op"); 12745 12746 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12747 "crypto op processing failed"); 12748 12749 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12750 12751 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 12752 ut_params->op->sym->cipher.data.offset); 12753 auth_tag = ciphertext + plaintext_pad_len; 12754 12755 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 12756 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 12757 12758 /* Validate obuf */ 12759 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12760 ciphertext, 12761 tdata->ciphertext.data, 12762 tdata->ciphertext.len, 12763 "Ciphertext data not as expected"); 12764 12765 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12766 auth_tag, 12767 tdata->auth_tag.data, 12768 tdata->auth_tag.len, 12769 "Generated auth tag not as expected"); 12770 12771 return 0; 12772 12773 } 12774 12775 static int 12776 test_AES_GCM_authenticated_encryption_oop_test_case_1(void) 12777 { 12778 return test_authenticated_encryption_oop(&gcm_test_case_5); 12779 } 12780 12781 static int 12782 test_authenticated_decryption_oop(const struct aead_test_data *tdata) 12783 { 12784 struct crypto_testsuite_params *ts_params = &testsuite_params; 12785 struct crypto_unittest_params *ut_params = &unittest_params; 12786 12787 int retval; 12788 uint8_t *plaintext; 12789 struct rte_cryptodev_info dev_info; 12790 12791 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12792 uint64_t feat_flags = dev_info.feature_flags; 12793 12794 /* Verify the capabilities */ 12795 struct rte_cryptodev_sym_capability_idx cap_idx; 12796 const struct rte_cryptodev_symmetric_capability *capability; 12797 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12798 cap_idx.algo.aead = tdata->algo; 12799 capability = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], &cap_idx); 12800 12801 if (capability == NULL) 12802 return TEST_SKIPPED; 12803 12804 if (rte_cryptodev_sym_capability_check_aead(capability, tdata->key.len, 12805 tdata->auth_tag.len, tdata->aad.len, tdata->iv.len)) 12806 return TEST_SKIPPED; 12807 12808 /* not supported with CPU crypto and raw data-path APIs*/ 12809 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO || 12810 global_api_test_type == CRYPTODEV_RAW_API_TEST) 12811 return TEST_SKIPPED; 12812 12813 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12814 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12815 printf("Device does not support RAW data-path APIs.\n"); 12816 return TEST_SKIPPED; 12817 } 12818 12819 /* Create AEAD session */ 12820 retval = create_aead_session(ts_params->valid_devs[0], 12821 tdata->algo, 12822 RTE_CRYPTO_AEAD_OP_DECRYPT, 12823 tdata->key.data, tdata->key.len, 12824 tdata->aad.len, tdata->auth_tag.len, 12825 tdata->iv.len); 12826 if (retval < 0) 12827 return retval; 12828 12829 /* alloc mbuf and set payload */ 12830 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12831 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12832 12833 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12834 rte_pktmbuf_tailroom(ut_params->ibuf)); 12835 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 12836 rte_pktmbuf_tailroom(ut_params->obuf)); 12837 12838 /* Create AEAD operation */ 12839 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 12840 if (retval < 0) 12841 return retval; 12842 12843 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12844 12845 ut_params->op->sym->m_src = ut_params->ibuf; 12846 ut_params->op->sym->m_dst = ut_params->obuf; 12847 12848 /* Process crypto operation */ 12849 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 12850 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 12851 0); 12852 if (retval != TEST_SUCCESS) 12853 return retval; 12854 } else 12855 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 12856 ut_params->op), "failed to process sym crypto op"); 12857 12858 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12859 "crypto op processing failed"); 12860 12861 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 12862 ut_params->op->sym->cipher.data.offset); 12863 12864 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 12865 12866 /* Validate obuf */ 12867 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12868 plaintext, 12869 tdata->plaintext.data, 12870 tdata->plaintext.len, 12871 "Plaintext data not as expected"); 12872 12873 TEST_ASSERT_EQUAL(ut_params->op->status, 12874 RTE_CRYPTO_OP_STATUS_SUCCESS, 12875 "Authentication failed"); 12876 return 0; 12877 } 12878 12879 static int 12880 test_AES_GCM_authenticated_decryption_oop_test_case_1(void) 12881 { 12882 return test_authenticated_decryption_oop(&gcm_test_case_5); 12883 } 12884 12885 static int 12886 test_authenticated_encryption_sessionless( 12887 const struct aead_test_data *tdata) 12888 { 12889 struct crypto_testsuite_params *ts_params = &testsuite_params; 12890 struct crypto_unittest_params *ut_params = &unittest_params; 12891 12892 int retval; 12893 uint8_t *ciphertext, *auth_tag; 12894 uint16_t plaintext_pad_len; 12895 uint8_t key[tdata->key.len + 1]; 12896 struct rte_cryptodev_info dev_info; 12897 12898 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12899 uint64_t feat_flags = dev_info.feature_flags; 12900 12901 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 12902 printf("Device doesn't support Sessionless ops.\n"); 12903 return TEST_SKIPPED; 12904 } 12905 12906 /* not supported with CPU crypto */ 12907 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12908 return TEST_SKIPPED; 12909 12910 /* Verify the capabilities */ 12911 struct rte_cryptodev_sym_capability_idx cap_idx; 12912 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12913 cap_idx.algo.aead = tdata->algo; 12914 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12915 &cap_idx) == NULL) 12916 return TEST_SKIPPED; 12917 12918 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12919 12920 /* clear mbuf payload */ 12921 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12922 rte_pktmbuf_tailroom(ut_params->ibuf)); 12923 12924 /* Create AEAD operation */ 12925 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 12926 if (retval < 0) 12927 return retval; 12928 12929 /* Create GCM xform */ 12930 memcpy(key, tdata->key.data, tdata->key.len); 12931 retval = create_aead_xform(ut_params->op, 12932 tdata->algo, 12933 RTE_CRYPTO_AEAD_OP_ENCRYPT, 12934 key, tdata->key.len, 12935 tdata->aad.len, tdata->auth_tag.len, 12936 tdata->iv.len); 12937 if (retval < 0) 12938 return retval; 12939 12940 ut_params->op->sym->m_src = ut_params->ibuf; 12941 12942 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 12943 RTE_CRYPTO_OP_SESSIONLESS, 12944 "crypto op session type not sessionless"); 12945 12946 /* Process crypto operation */ 12947 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 12948 ut_params->op), "failed to process sym crypto op"); 12949 12950 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 12951 12952 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12953 "crypto op status not success"); 12954 12955 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12956 12957 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 12958 ut_params->op->sym->cipher.data.offset); 12959 auth_tag = ciphertext + plaintext_pad_len; 12960 12961 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 12962 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 12963 12964 /* Validate obuf */ 12965 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12966 ciphertext, 12967 tdata->ciphertext.data, 12968 tdata->ciphertext.len, 12969 "Ciphertext data not as expected"); 12970 12971 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12972 auth_tag, 12973 tdata->auth_tag.data, 12974 tdata->auth_tag.len, 12975 "Generated auth tag not as expected"); 12976 12977 return 0; 12978 12979 } 12980 12981 static int 12982 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void) 12983 { 12984 return test_authenticated_encryption_sessionless( 12985 &gcm_test_case_5); 12986 } 12987 12988 static int 12989 test_authenticated_decryption_sessionless( 12990 const struct aead_test_data *tdata) 12991 { 12992 struct crypto_testsuite_params *ts_params = &testsuite_params; 12993 struct crypto_unittest_params *ut_params = &unittest_params; 12994 12995 int retval; 12996 uint8_t *plaintext; 12997 uint8_t key[tdata->key.len + 1]; 12998 struct rte_cryptodev_info dev_info; 12999 13000 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13001 uint64_t feat_flags = dev_info.feature_flags; 13002 13003 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 13004 printf("Device doesn't support Sessionless ops.\n"); 13005 return TEST_SKIPPED; 13006 } 13007 13008 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13009 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13010 printf("Device doesn't support RAW data-path APIs.\n"); 13011 return TEST_SKIPPED; 13012 } 13013 13014 /* not supported with CPU crypto */ 13015 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13016 return TEST_SKIPPED; 13017 13018 /* Verify the capabilities */ 13019 struct rte_cryptodev_sym_capability_idx cap_idx; 13020 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 13021 cap_idx.algo.aead = tdata->algo; 13022 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13023 &cap_idx) == NULL) 13024 return TEST_SKIPPED; 13025 13026 /* alloc mbuf and set payload */ 13027 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13028 13029 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13030 rte_pktmbuf_tailroom(ut_params->ibuf)); 13031 13032 /* Create AEAD operation */ 13033 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 13034 if (retval < 0) 13035 return retval; 13036 13037 /* Create AEAD xform */ 13038 memcpy(key, tdata->key.data, tdata->key.len); 13039 retval = create_aead_xform(ut_params->op, 13040 tdata->algo, 13041 RTE_CRYPTO_AEAD_OP_DECRYPT, 13042 key, tdata->key.len, 13043 tdata->aad.len, tdata->auth_tag.len, 13044 tdata->iv.len); 13045 if (retval < 0) 13046 return retval; 13047 13048 ut_params->op->sym->m_src = ut_params->ibuf; 13049 13050 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 13051 RTE_CRYPTO_OP_SESSIONLESS, 13052 "crypto op session type not sessionless"); 13053 13054 /* Process crypto operation */ 13055 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 13056 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 13057 0); 13058 if (retval != TEST_SUCCESS) 13059 return retval; 13060 } else 13061 TEST_ASSERT_NOT_NULL(process_crypto_request( 13062 ts_params->valid_devs[0], ut_params->op), 13063 "failed to process sym crypto op"); 13064 13065 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 13066 13067 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13068 "crypto op status not success"); 13069 13070 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 13071 ut_params->op->sym->cipher.data.offset); 13072 13073 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 13074 13075 /* Validate obuf */ 13076 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13077 plaintext, 13078 tdata->plaintext.data, 13079 tdata->plaintext.len, 13080 "Plaintext data not as expected"); 13081 13082 TEST_ASSERT_EQUAL(ut_params->op->status, 13083 RTE_CRYPTO_OP_STATUS_SUCCESS, 13084 "Authentication failed"); 13085 return 0; 13086 } 13087 13088 static int 13089 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void) 13090 { 13091 return test_authenticated_decryption_sessionless( 13092 &gcm_test_case_5); 13093 } 13094 13095 static int 13096 test_AES_CCM_authenticated_encryption_test_case_128_1(void) 13097 { 13098 return test_authenticated_encryption(&ccm_test_case_128_1); 13099 } 13100 13101 static int 13102 test_AES_CCM_authenticated_encryption_test_case_128_2(void) 13103 { 13104 return test_authenticated_encryption(&ccm_test_case_128_2); 13105 } 13106 13107 static int 13108 test_AES_CCM_authenticated_encryption_test_case_128_3(void) 13109 { 13110 return test_authenticated_encryption(&ccm_test_case_128_3); 13111 } 13112 13113 static int 13114 test_AES_CCM_authenticated_decryption_test_case_128_1(void) 13115 { 13116 return test_authenticated_decryption(&ccm_test_case_128_1); 13117 } 13118 13119 static int 13120 test_AES_CCM_authenticated_decryption_test_case_128_2(void) 13121 { 13122 return test_authenticated_decryption(&ccm_test_case_128_2); 13123 } 13124 13125 static int 13126 test_AES_CCM_authenticated_decryption_test_case_128_3(void) 13127 { 13128 return test_authenticated_decryption(&ccm_test_case_128_3); 13129 } 13130 13131 static int 13132 test_AES_CCM_authenticated_encryption_test_case_192_1(void) 13133 { 13134 return test_authenticated_encryption(&ccm_test_case_192_1); 13135 } 13136 13137 static int 13138 test_AES_CCM_authenticated_encryption_test_case_192_2(void) 13139 { 13140 return test_authenticated_encryption(&ccm_test_case_192_2); 13141 } 13142 13143 static int 13144 test_AES_CCM_authenticated_encryption_test_case_192_3(void) 13145 { 13146 return test_authenticated_encryption(&ccm_test_case_192_3); 13147 } 13148 13149 static int 13150 test_AES_CCM_authenticated_decryption_test_case_192_1(void) 13151 { 13152 return test_authenticated_decryption(&ccm_test_case_192_1); 13153 } 13154 13155 static int 13156 test_AES_CCM_authenticated_decryption_test_case_192_2(void) 13157 { 13158 return test_authenticated_decryption(&ccm_test_case_192_2); 13159 } 13160 13161 static int 13162 test_AES_CCM_authenticated_decryption_test_case_192_3(void) 13163 { 13164 return test_authenticated_decryption(&ccm_test_case_192_3); 13165 } 13166 13167 static int 13168 test_AES_CCM_authenticated_encryption_test_case_256_1(void) 13169 { 13170 return test_authenticated_encryption(&ccm_test_case_256_1); 13171 } 13172 13173 static int 13174 test_AES_CCM_authenticated_encryption_test_case_256_2(void) 13175 { 13176 return test_authenticated_encryption(&ccm_test_case_256_2); 13177 } 13178 13179 static int 13180 test_AES_CCM_authenticated_encryption_test_case_256_3(void) 13181 { 13182 return test_authenticated_encryption(&ccm_test_case_256_3); 13183 } 13184 13185 static int 13186 test_AES_CCM_authenticated_decryption_test_case_256_1(void) 13187 { 13188 return test_authenticated_decryption(&ccm_test_case_256_1); 13189 } 13190 13191 static int 13192 test_AES_CCM_authenticated_decryption_test_case_256_2(void) 13193 { 13194 return test_authenticated_decryption(&ccm_test_case_256_2); 13195 } 13196 13197 static int 13198 test_AES_CCM_authenticated_decryption_test_case_256_3(void) 13199 { 13200 return test_authenticated_decryption(&ccm_test_case_256_3); 13201 } 13202 13203 static int 13204 test_stats(void) 13205 { 13206 struct crypto_testsuite_params *ts_params = &testsuite_params; 13207 struct rte_cryptodev_stats stats; 13208 13209 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13210 return TEST_SKIPPED; 13211 13212 /* Verify the capabilities */ 13213 struct rte_cryptodev_sym_capability_idx cap_idx; 13214 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13215 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 13216 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13217 &cap_idx) == NULL) 13218 return TEST_SKIPPED; 13219 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13220 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 13221 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13222 &cap_idx) == NULL) 13223 return TEST_SKIPPED; 13224 13225 if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 13226 == -ENOTSUP) 13227 return TEST_SKIPPED; 13228 13229 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 13230 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 13231 &stats) == -ENODEV), 13232 "rte_cryptodev_stats_get invalid dev failed"); 13233 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 13234 "rte_cryptodev_stats_get invalid Param failed"); 13235 13236 /* Test expected values */ 13237 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 13238 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 13239 &stats), 13240 "rte_cryptodev_stats_get failed"); 13241 TEST_ASSERT((stats.enqueued_count == 1), 13242 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 13243 TEST_ASSERT((stats.dequeued_count == 1), 13244 "rte_cryptodev_stats_get returned unexpected dequeued stat"); 13245 TEST_ASSERT((stats.enqueue_err_count == 0), 13246 "rte_cryptodev_stats_get returned unexpected enqueued error count stat"); 13247 TEST_ASSERT((stats.dequeue_err_count == 0), 13248 "rte_cryptodev_stats_get returned unexpected dequeued error count stat"); 13249 13250 /* invalid device but should ignore and not reset device stats*/ 13251 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 13252 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 13253 &stats), 13254 "rte_cryptodev_stats_get failed"); 13255 TEST_ASSERT((stats.enqueued_count == 1), 13256 "rte_cryptodev_stats_get returned unexpected enqueued stat after invalid reset"); 13257 13258 /* check that a valid reset clears stats */ 13259 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 13260 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 13261 &stats), 13262 "rte_cryptodev_stats_get failed"); 13263 TEST_ASSERT((stats.enqueued_count == 0), 13264 "rte_cryptodev_stats_get returned unexpected enqueued stat after valid reset"); 13265 TEST_ASSERT((stats.dequeued_count == 0), 13266 "rte_cryptodev_stats_get returned unexpected dequeued stat after valid reset"); 13267 13268 return TEST_SUCCESS; 13269 } 13270 13271 static int 13272 test_device_reconfigure(void) 13273 { 13274 struct crypto_testsuite_params *ts_params = &testsuite_params; 13275 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 13276 struct rte_cryptodev_qp_conf qp_conf = { 13277 .nb_descriptors = MAX_NUM_OPS_INFLIGHT, 13278 .mp_session = ts_params->session_mpool 13279 }; 13280 uint16_t qp_id, dev_id, num_devs = 0; 13281 13282 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 13283 "Need at least %d devices for test", 1); 13284 13285 dev_id = ts_params->valid_devs[0]; 13286 13287 /* Stop the device in case it's started so it can be configured */ 13288 rte_cryptodev_stop(dev_id); 13289 13290 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 13291 "Failed test for rte_cryptodev_configure: " 13292 "dev_num %u", dev_id); 13293 13294 /* Reconfigure with same configure params */ 13295 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 13296 "Failed test for rte_cryptodev_configure: " 13297 "dev_num %u", dev_id); 13298 13299 /* Reconfigure with just one queue pair */ 13300 ts_params->conf.nb_queue_pairs = 1; 13301 13302 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 13303 &ts_params->conf), 13304 "Failed to configure cryptodev: dev_id %u, qp_id %u", 13305 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 13306 13307 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 13308 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 13309 ts_params->valid_devs[0], qp_id, &qp_conf, 13310 rte_cryptodev_socket_id( 13311 ts_params->valid_devs[0])), 13312 "Failed test for " 13313 "rte_cryptodev_queue_pair_setup: num_inflights " 13314 "%u on qp %u on cryptodev %u", 13315 qp_conf.nb_descriptors, qp_id, 13316 ts_params->valid_devs[0]); 13317 } 13318 13319 /* Reconfigure with max number of queue pairs */ 13320 ts_params->conf.nb_queue_pairs = orig_nb_qps; 13321 13322 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 13323 &ts_params->conf), 13324 "Failed to configure cryptodev: dev_id %u, qp_id %u", 13325 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 13326 13327 qp_conf.mp_session = ts_params->session_mpool; 13328 13329 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 13330 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 13331 ts_params->valid_devs[0], qp_id, &qp_conf, 13332 rte_cryptodev_socket_id( 13333 ts_params->valid_devs[0])), 13334 "Failed test for " 13335 "rte_cryptodev_queue_pair_setup: num_inflights " 13336 "%u on qp %u on cryptodev %u", 13337 qp_conf.nb_descriptors, qp_id, 13338 ts_params->valid_devs[0]); 13339 } 13340 13341 /* Start the device */ 13342 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 13343 "Failed to start cryptodev %u", 13344 ts_params->valid_devs[0]); 13345 13346 /* Test expected values */ 13347 return test_AES_CBC_HMAC_SHA1_encrypt_digest(); 13348 } 13349 13350 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 13351 struct crypto_unittest_params *ut_params, 13352 enum rte_crypto_auth_operation op, 13353 const struct HMAC_MD5_vector *test_case) 13354 { 13355 uint8_t key[64]; 13356 13357 memcpy(key, test_case->key.data, test_case->key.len); 13358 13359 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13360 ut_params->auth_xform.next = NULL; 13361 ut_params->auth_xform.auth.op = op; 13362 13363 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 13364 13365 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 13366 ut_params->auth_xform.auth.key.length = test_case->key.len; 13367 ut_params->auth_xform.auth.key.data = key; 13368 13369 ut_params->sess = rte_cryptodev_sym_session_create( 13370 ts_params->valid_devs[0], &ut_params->auth_xform, 13371 ts_params->session_mpool); 13372 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 13373 return TEST_SKIPPED; 13374 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13375 13376 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13377 13378 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13379 rte_pktmbuf_tailroom(ut_params->ibuf)); 13380 13381 return 0; 13382 } 13383 13384 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 13385 const struct HMAC_MD5_vector *test_case, 13386 uint8_t **plaintext) 13387 { 13388 uint16_t plaintext_pad_len; 13389 13390 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 13391 13392 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 13393 16); 13394 13395 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13396 plaintext_pad_len); 13397 memcpy(*plaintext, test_case->plaintext.data, 13398 test_case->plaintext.len); 13399 13400 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 13401 ut_params->ibuf, MD5_DIGEST_LEN); 13402 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13403 "no room to append digest"); 13404 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 13405 ut_params->ibuf, plaintext_pad_len); 13406 13407 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 13408 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 13409 test_case->auth_tag.len); 13410 } 13411 13412 sym_op->auth.data.offset = 0; 13413 sym_op->auth.data.length = test_case->plaintext.len; 13414 13415 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13416 ut_params->op->sym->m_src = ut_params->ibuf; 13417 13418 return 0; 13419 } 13420 13421 static int 13422 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 13423 { 13424 uint16_t plaintext_pad_len; 13425 uint8_t *plaintext, *auth_tag; 13426 int ret; 13427 13428 struct crypto_testsuite_params *ts_params = &testsuite_params; 13429 struct crypto_unittest_params *ut_params = &unittest_params; 13430 struct rte_cryptodev_info dev_info; 13431 13432 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13433 uint64_t feat_flags = dev_info.feature_flags; 13434 13435 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13436 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13437 printf("Device doesn't support RAW data-path APIs.\n"); 13438 return TEST_SKIPPED; 13439 } 13440 13441 /* Verify the capabilities */ 13442 struct rte_cryptodev_sym_capability_idx cap_idx; 13443 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13444 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 13445 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13446 &cap_idx) == NULL) 13447 return TEST_SKIPPED; 13448 13449 if (MD5_HMAC_create_session(ts_params, ut_params, 13450 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 13451 return TEST_FAILED; 13452 13453 /* Generate Crypto op data structure */ 13454 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13455 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13456 TEST_ASSERT_NOT_NULL(ut_params->op, 13457 "Failed to allocate symmetric crypto operation struct"); 13458 13459 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 13460 16); 13461 13462 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 13463 return TEST_FAILED; 13464 13465 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13466 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13467 ut_params->op); 13468 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 13469 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 0); 13470 if (ret != TEST_SUCCESS) 13471 return ret; 13472 } else 13473 TEST_ASSERT_NOT_NULL( 13474 process_crypto_request(ts_params->valid_devs[0], 13475 ut_params->op), 13476 "failed to process sym crypto op"); 13477 13478 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13479 "crypto op processing failed"); 13480 13481 if (ut_params->op->sym->m_dst) { 13482 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 13483 uint8_t *, plaintext_pad_len); 13484 } else { 13485 auth_tag = plaintext + plaintext_pad_len; 13486 } 13487 13488 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13489 auth_tag, 13490 test_case->auth_tag.data, 13491 test_case->auth_tag.len, 13492 "HMAC_MD5 generated tag not as expected"); 13493 13494 return TEST_SUCCESS; 13495 } 13496 13497 static int 13498 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 13499 { 13500 uint8_t *plaintext; 13501 int ret; 13502 13503 struct crypto_testsuite_params *ts_params = &testsuite_params; 13504 struct crypto_unittest_params *ut_params = &unittest_params; 13505 struct rte_cryptodev_info dev_info; 13506 13507 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13508 uint64_t feat_flags = dev_info.feature_flags; 13509 13510 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13511 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13512 printf("Device doesn't support RAW data-path APIs.\n"); 13513 return TEST_SKIPPED; 13514 } 13515 13516 /* Verify the capabilities */ 13517 struct rte_cryptodev_sym_capability_idx cap_idx; 13518 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13519 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 13520 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13521 &cap_idx) == NULL) 13522 return TEST_SKIPPED; 13523 13524 if (MD5_HMAC_create_session(ts_params, ut_params, 13525 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 13526 return TEST_FAILED; 13527 } 13528 13529 /* Generate Crypto op data structure */ 13530 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13531 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13532 TEST_ASSERT_NOT_NULL(ut_params->op, 13533 "Failed to allocate symmetric crypto operation struct"); 13534 13535 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 13536 return TEST_FAILED; 13537 13538 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13539 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13540 ut_params->op); 13541 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 13542 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 0); 13543 if (ret != TEST_SUCCESS) 13544 return ret; 13545 } else 13546 TEST_ASSERT_NOT_NULL( 13547 process_crypto_request(ts_params->valid_devs[0], 13548 ut_params->op), 13549 "failed to process sym crypto op"); 13550 13551 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13552 "HMAC_MD5 crypto op processing failed"); 13553 13554 return TEST_SUCCESS; 13555 } 13556 13557 static int 13558 test_MD5_HMAC_generate_case_1(void) 13559 { 13560 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 13561 } 13562 13563 static int 13564 test_MD5_HMAC_verify_case_1(void) 13565 { 13566 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 13567 } 13568 13569 static int 13570 test_MD5_HMAC_generate_case_2(void) 13571 { 13572 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 13573 } 13574 13575 static int 13576 test_MD5_HMAC_verify_case_2(void) 13577 { 13578 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 13579 } 13580 13581 static int 13582 test_multi_session(void) 13583 { 13584 struct crypto_testsuite_params *ts_params = &testsuite_params; 13585 struct crypto_unittest_params *ut_params = &unittest_params; 13586 struct rte_cryptodev_info dev_info; 13587 int i, nb_sess, ret = TEST_SUCCESS; 13588 void **sessions; 13589 13590 /* Verify the capabilities */ 13591 struct rte_cryptodev_sym_capability_idx cap_idx; 13592 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13593 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 13594 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13595 &cap_idx) == NULL) 13596 return TEST_SKIPPED; 13597 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13598 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 13599 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13600 &cap_idx) == NULL) 13601 return TEST_SKIPPED; 13602 13603 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 13604 aes_cbc_key, hmac_sha512_key); 13605 13606 13607 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13608 13609 sessions = rte_malloc(NULL, 13610 sizeof(void *) * 13611 (MAX_NB_SESSIONS + 1), 0); 13612 13613 /* Create multiple crypto sessions*/ 13614 for (i = 0; i < MAX_NB_SESSIONS; i++) { 13615 sessions[i] = rte_cryptodev_sym_session_create( 13616 ts_params->valid_devs[0], &ut_params->auth_xform, 13617 ts_params->session_mpool); 13618 if (sessions[i] == NULL && rte_errno == ENOTSUP) { 13619 nb_sess = i; 13620 ret = TEST_SKIPPED; 13621 break; 13622 } 13623 13624 TEST_ASSERT_NOT_NULL(sessions[i], 13625 "Session creation failed at session number %u", 13626 i); 13627 13628 /* Attempt to send a request on each session */ 13629 ret = test_AES_CBC_HMAC_SHA512_decrypt_perform( 13630 sessions[i], 13631 ut_params, 13632 ts_params, 13633 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 13634 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 13635 aes_cbc_iv); 13636 13637 /* free crypto operation structure */ 13638 rte_crypto_op_free(ut_params->op); 13639 13640 /* 13641 * free mbuf - both obuf and ibuf are usually the same, 13642 * so check if they point at the same address is necessary, 13643 * to avoid freeing the mbuf twice. 13644 */ 13645 if (ut_params->obuf) { 13646 rte_pktmbuf_free(ut_params->obuf); 13647 if (ut_params->ibuf == ut_params->obuf) 13648 ut_params->ibuf = 0; 13649 ut_params->obuf = 0; 13650 } 13651 if (ut_params->ibuf) { 13652 rte_pktmbuf_free(ut_params->ibuf); 13653 ut_params->ibuf = 0; 13654 } 13655 13656 if (ret != TEST_SUCCESS) { 13657 i++; 13658 break; 13659 } 13660 } 13661 13662 nb_sess = i; 13663 13664 for (i = 0; i < nb_sess; i++) { 13665 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 13666 sessions[i]); 13667 } 13668 13669 rte_free(sessions); 13670 13671 if (ret != TEST_SKIPPED) 13672 TEST_ASSERT_SUCCESS(ret, "Failed to perform decrypt on request number %u.", i - 1); 13673 13674 return ret; 13675 } 13676 13677 struct multi_session_params { 13678 struct crypto_unittest_params ut_params; 13679 uint8_t *cipher_key; 13680 uint8_t *hmac_key; 13681 const uint8_t *cipher; 13682 const uint8_t *digest; 13683 uint8_t *iv; 13684 }; 13685 13686 #define MB_SESSION_NUMBER 3 13687 13688 static int 13689 test_multi_session_random_usage(void) 13690 { 13691 struct crypto_testsuite_params *ts_params = &testsuite_params; 13692 struct rte_cryptodev_info dev_info; 13693 int index = 0, ret = TEST_SUCCESS; 13694 uint32_t nb_sess, i, j; 13695 void **sessions; 13696 struct multi_session_params ut_paramz[] = { 13697 13698 { 13699 .cipher_key = ms_aes_cbc_key0, 13700 .hmac_key = ms_hmac_key0, 13701 .cipher = ms_aes_cbc_cipher0, 13702 .digest = ms_hmac_digest0, 13703 .iv = ms_aes_cbc_iv0 13704 }, 13705 { 13706 .cipher_key = ms_aes_cbc_key1, 13707 .hmac_key = ms_hmac_key1, 13708 .cipher = ms_aes_cbc_cipher1, 13709 .digest = ms_hmac_digest1, 13710 .iv = ms_aes_cbc_iv1 13711 }, 13712 { 13713 .cipher_key = ms_aes_cbc_key2, 13714 .hmac_key = ms_hmac_key2, 13715 .cipher = ms_aes_cbc_cipher2, 13716 .digest = ms_hmac_digest2, 13717 .iv = ms_aes_cbc_iv2 13718 }, 13719 13720 }; 13721 13722 /* Verify the capabilities */ 13723 struct rte_cryptodev_sym_capability_idx cap_idx; 13724 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13725 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 13726 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13727 &cap_idx) == NULL) 13728 return TEST_SKIPPED; 13729 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13730 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 13731 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13732 &cap_idx) == NULL) 13733 return TEST_SKIPPED; 13734 13735 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13736 13737 sessions = rte_malloc(NULL, (sizeof(void *) 13738 * MAX_NB_SESSIONS) + 1, 0); 13739 13740 for (i = 0; i < MB_SESSION_NUMBER; i++) { 13741 13742 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params, 13743 sizeof(struct crypto_unittest_params)); 13744 13745 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 13746 &ut_paramz[i].ut_params, 13747 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 13748 13749 /* Create multiple crypto sessions*/ 13750 sessions[i] = rte_cryptodev_sym_session_create( 13751 ts_params->valid_devs[0], 13752 &ut_paramz[i].ut_params.auth_xform, 13753 ts_params->session_mpool); 13754 if (sessions[i] == NULL && rte_errno == ENOTSUP) { 13755 nb_sess = i; 13756 ret = TEST_SKIPPED; 13757 goto session_clear; 13758 } 13759 13760 TEST_ASSERT_NOT_NULL(sessions[i], 13761 "Session creation failed at session number %u", 13762 i); 13763 } 13764 13765 nb_sess = i; 13766 13767 srand(time(NULL)); 13768 for (i = 0; i < 40000; i++) { 13769 13770 j = rand() % MB_SESSION_NUMBER; 13771 13772 ret = test_AES_CBC_HMAC_SHA512_decrypt_perform( 13773 sessions[j], 13774 &ut_paramz[j].ut_params, 13775 ts_params, ut_paramz[j].cipher, 13776 ut_paramz[j].digest, 13777 ut_paramz[j].iv); 13778 13779 rte_crypto_op_free(ut_paramz[j].ut_params.op); 13780 13781 /* 13782 * free mbuf - both obuf and ibuf are usually the same, 13783 * so check if they point at the same address is necessary, 13784 * to avoid freeing the mbuf twice. 13785 */ 13786 if (ut_paramz[j].ut_params.obuf) { 13787 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 13788 if (ut_paramz[j].ut_params.ibuf 13789 == ut_paramz[j].ut_params.obuf) 13790 ut_paramz[j].ut_params.ibuf = 0; 13791 ut_paramz[j].ut_params.obuf = 0; 13792 } 13793 if (ut_paramz[j].ut_params.ibuf) { 13794 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 13795 ut_paramz[j].ut_params.ibuf = 0; 13796 } 13797 13798 if (ret != TEST_SKIPPED) { 13799 index = i; 13800 break; 13801 } 13802 } 13803 13804 session_clear: 13805 for (i = 0; i < nb_sess; i++) { 13806 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 13807 sessions[i]); 13808 } 13809 13810 rte_free(sessions); 13811 13812 if (ret != TEST_SKIPPED) 13813 TEST_ASSERT_SUCCESS(ret, "Failed to perform decrypt on request number %u.", index); 13814 13815 return TEST_SUCCESS; 13816 } 13817 13818 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab, 13819 0xab, 0xab, 0xab, 0xab, 13820 0xab, 0xab, 0xab, 0xab, 13821 0xab, 0xab, 0xab, 0xab}; 13822 13823 static int 13824 test_null_invalid_operation(void) 13825 { 13826 struct crypto_testsuite_params *ts_params = &testsuite_params; 13827 struct crypto_unittest_params *ut_params = &unittest_params; 13828 13829 /* This test is for NULL PMD only */ 13830 if (gbl_driver_id != rte_cryptodev_driver_id_get( 13831 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 13832 return TEST_SKIPPED; 13833 13834 /* Setup Cipher Parameters */ 13835 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13836 ut_params->cipher_xform.next = NULL; 13837 13838 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 13839 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 13840 13841 /* Create Crypto session*/ 13842 ut_params->sess = rte_cryptodev_sym_session_create( 13843 ts_params->valid_devs[0], &ut_params->cipher_xform, 13844 ts_params->session_mpool); 13845 TEST_ASSERT(ut_params->sess == NULL, 13846 "Session creation succeeded unexpectedly"); 13847 13848 /* Setup HMAC Parameters */ 13849 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13850 ut_params->auth_xform.next = NULL; 13851 13852 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 13853 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 13854 13855 /* Create Crypto session*/ 13856 ut_params->sess = rte_cryptodev_sym_session_create( 13857 ts_params->valid_devs[0], &ut_params->auth_xform, 13858 ts_params->session_mpool); 13859 TEST_ASSERT(ut_params->sess == NULL, 13860 "Session creation succeeded unexpectedly"); 13861 13862 return TEST_SUCCESS; 13863 } 13864 13865 13866 #define NULL_BURST_LENGTH (32) 13867 13868 static int 13869 test_null_burst_operation(void) 13870 { 13871 struct crypto_testsuite_params *ts_params = &testsuite_params; 13872 struct crypto_unittest_params *ut_params = &unittest_params; 13873 13874 unsigned i, burst_len = NULL_BURST_LENGTH; 13875 13876 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 13877 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 13878 13879 /* This test is for NULL PMD only */ 13880 if (gbl_driver_id != rte_cryptodev_driver_id_get( 13881 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 13882 return TEST_SKIPPED; 13883 13884 /* Setup Cipher Parameters */ 13885 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13886 ut_params->cipher_xform.next = &ut_params->auth_xform; 13887 13888 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 13889 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 13890 13891 /* Setup HMAC Parameters */ 13892 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13893 ut_params->auth_xform.next = NULL; 13894 13895 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 13896 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 13897 13898 /* Create Crypto session*/ 13899 ut_params->sess = rte_cryptodev_sym_session_create( 13900 ts_params->valid_devs[0], 13901 &ut_params->auth_xform, 13902 ts_params->session_mpool); 13903 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 13904 return TEST_SKIPPED; 13905 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13906 13907 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 13908 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 13909 burst_len, "failed to generate burst of crypto ops"); 13910 13911 /* Generate an operation for each mbuf in burst */ 13912 for (i = 0; i < burst_len; i++) { 13913 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13914 13915 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 13916 13917 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 13918 sizeof(unsigned)); 13919 *data = i; 13920 13921 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 13922 13923 burst[i]->sym->m_src = m; 13924 } 13925 13926 /* Process crypto operation */ 13927 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 13928 0, burst, burst_len), 13929 burst_len, 13930 "Error enqueuing burst"); 13931 13932 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 13933 0, burst_dequeued, burst_len), 13934 burst_len, 13935 "Error dequeuing burst"); 13936 13937 13938 for (i = 0; i < burst_len; i++) { 13939 TEST_ASSERT_EQUAL( 13940 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 13941 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 13942 uint32_t *), 13943 "data not as expected"); 13944 13945 rte_pktmbuf_free(burst[i]->sym->m_src); 13946 rte_crypto_op_free(burst[i]); 13947 } 13948 13949 return TEST_SUCCESS; 13950 } 13951 13952 static uint16_t 13953 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 13954 uint16_t nb_ops, void *user_param) 13955 { 13956 RTE_SET_USED(dev_id); 13957 RTE_SET_USED(qp_id); 13958 RTE_SET_USED(ops); 13959 RTE_SET_USED(user_param); 13960 13961 printf("crypto enqueue callback called\n"); 13962 return nb_ops; 13963 } 13964 13965 static uint16_t 13966 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 13967 uint16_t nb_ops, void *user_param) 13968 { 13969 RTE_SET_USED(dev_id); 13970 RTE_SET_USED(qp_id); 13971 RTE_SET_USED(ops); 13972 RTE_SET_USED(user_param); 13973 13974 printf("crypto dequeue callback called\n"); 13975 return nb_ops; 13976 } 13977 13978 /* 13979 * Thread using enqueue/dequeue callback with RCU. 13980 */ 13981 static int 13982 test_enqdeq_callback_thread(void *arg) 13983 { 13984 RTE_SET_USED(arg); 13985 /* DP thread calls rte_cryptodev_enqueue_burst()/ 13986 * rte_cryptodev_dequeue_burst() and invokes callback. 13987 */ 13988 test_null_burst_operation(); 13989 return 0; 13990 } 13991 13992 static int 13993 test_enq_callback_setup(void) 13994 { 13995 struct crypto_testsuite_params *ts_params = &testsuite_params; 13996 struct rte_cryptodev_info dev_info; 13997 struct rte_cryptodev_qp_conf qp_conf = { 13998 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 13999 }; 14000 14001 struct rte_cryptodev_cb *cb; 14002 uint16_t qp_id = 0; 14003 14004 /* Stop the device in case it's started so it can be configured */ 14005 rte_cryptodev_stop(ts_params->valid_devs[0]); 14006 14007 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14008 14009 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 14010 &ts_params->conf), 14011 "Failed to configure cryptodev %u", 14012 ts_params->valid_devs[0]); 14013 14014 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 14015 qp_conf.mp_session = ts_params->session_mpool; 14016 14017 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 14018 ts_params->valid_devs[0], qp_id, &qp_conf, 14019 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 14020 "Failed test for " 14021 "rte_cryptodev_queue_pair_setup: num_inflights " 14022 "%u on qp %u on cryptodev %u", 14023 qp_conf.nb_descriptors, qp_id, 14024 ts_params->valid_devs[0]); 14025 14026 /* Test with invalid crypto device */ 14027 cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS, 14028 qp_id, test_enq_callback, NULL); 14029 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 14030 "cryptodev %u did not fail", 14031 qp_id, RTE_CRYPTO_MAX_DEVS); 14032 14033 /* Test with invalid queue pair */ 14034 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 14035 dev_info.max_nb_queue_pairs + 1, 14036 test_enq_callback, NULL); 14037 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 14038 "cryptodev %u did not fail", 14039 dev_info.max_nb_queue_pairs + 1, 14040 ts_params->valid_devs[0]); 14041 14042 /* Test with NULL callback */ 14043 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 14044 qp_id, NULL, NULL); 14045 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 14046 "cryptodev %u did not fail", 14047 qp_id, ts_params->valid_devs[0]); 14048 14049 /* Test with valid configuration */ 14050 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 14051 qp_id, test_enq_callback, NULL); 14052 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 14053 "qp %u on cryptodev %u", 14054 qp_id, ts_params->valid_devs[0]); 14055 14056 rte_cryptodev_start(ts_params->valid_devs[0]); 14057 14058 /* Launch a thread */ 14059 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 14060 rte_get_next_lcore(-1, 1, 0)); 14061 14062 /* Wait until reader exited. */ 14063 rte_eal_mp_wait_lcore(); 14064 14065 /* Test with invalid crypto device */ 14066 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 14067 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 14068 "Expected call to fail as crypto device is invalid"); 14069 14070 /* Test with invalid queue pair */ 14071 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 14072 ts_params->valid_devs[0], 14073 dev_info.max_nb_queue_pairs + 1, cb), 14074 "Expected call to fail as queue pair is invalid"); 14075 14076 /* Test with NULL callback */ 14077 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 14078 ts_params->valid_devs[0], qp_id, NULL), 14079 "Expected call to fail as callback is NULL"); 14080 14081 /* Test with valid configuration */ 14082 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback( 14083 ts_params->valid_devs[0], qp_id, cb), 14084 "Failed test to remove callback on " 14085 "qp %u on cryptodev %u", 14086 qp_id, ts_params->valid_devs[0]); 14087 14088 return TEST_SUCCESS; 14089 } 14090 14091 static int 14092 test_deq_callback_setup(void) 14093 { 14094 struct crypto_testsuite_params *ts_params = &testsuite_params; 14095 struct rte_cryptodev_info dev_info; 14096 struct rte_cryptodev_qp_conf qp_conf = { 14097 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 14098 }; 14099 14100 struct rte_cryptodev_cb *cb; 14101 uint16_t qp_id = 0; 14102 14103 /* Stop the device in case it's started so it can be configured */ 14104 rte_cryptodev_stop(ts_params->valid_devs[0]); 14105 14106 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14107 14108 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 14109 &ts_params->conf), 14110 "Failed to configure cryptodev %u", 14111 ts_params->valid_devs[0]); 14112 14113 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 14114 qp_conf.mp_session = ts_params->session_mpool; 14115 14116 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 14117 ts_params->valid_devs[0], qp_id, &qp_conf, 14118 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 14119 "Failed test for " 14120 "rte_cryptodev_queue_pair_setup: num_inflights " 14121 "%u on qp %u on cryptodev %u", 14122 qp_conf.nb_descriptors, qp_id, 14123 ts_params->valid_devs[0]); 14124 14125 /* Test with invalid crypto device */ 14126 cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS, 14127 qp_id, test_deq_callback, NULL); 14128 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 14129 "cryptodev %u did not fail", 14130 qp_id, RTE_CRYPTO_MAX_DEVS); 14131 14132 /* Test with invalid queue pair */ 14133 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 14134 dev_info.max_nb_queue_pairs + 1, 14135 test_deq_callback, NULL); 14136 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 14137 "cryptodev %u did not fail", 14138 dev_info.max_nb_queue_pairs + 1, 14139 ts_params->valid_devs[0]); 14140 14141 /* Test with NULL callback */ 14142 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 14143 qp_id, NULL, NULL); 14144 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 14145 "cryptodev %u did not fail", 14146 qp_id, ts_params->valid_devs[0]); 14147 14148 /* Test with valid configuration */ 14149 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 14150 qp_id, test_deq_callback, NULL); 14151 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 14152 "qp %u on cryptodev %u", 14153 qp_id, ts_params->valid_devs[0]); 14154 14155 rte_cryptodev_start(ts_params->valid_devs[0]); 14156 14157 /* Launch a thread */ 14158 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 14159 rte_get_next_lcore(-1, 1, 0)); 14160 14161 /* Wait until reader exited. */ 14162 rte_eal_mp_wait_lcore(); 14163 14164 /* Test with invalid crypto device */ 14165 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 14166 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 14167 "Expected call to fail as crypto device is invalid"); 14168 14169 /* Test with invalid queue pair */ 14170 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 14171 ts_params->valid_devs[0], 14172 dev_info.max_nb_queue_pairs + 1, cb), 14173 "Expected call to fail as queue pair is invalid"); 14174 14175 /* Test with NULL callback */ 14176 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 14177 ts_params->valid_devs[0], qp_id, NULL), 14178 "Expected call to fail as callback is NULL"); 14179 14180 /* Test with valid configuration */ 14181 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback( 14182 ts_params->valid_devs[0], qp_id, cb), 14183 "Failed test to remove callback on " 14184 "qp %u on cryptodev %u", 14185 qp_id, ts_params->valid_devs[0]); 14186 14187 return TEST_SUCCESS; 14188 } 14189 14190 static void 14191 generate_gmac_large_plaintext(uint8_t *data) 14192 { 14193 uint16_t i; 14194 14195 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 14196 memcpy(&data[i], &data[0], 32); 14197 } 14198 14199 static int 14200 create_gmac_operation(enum rte_crypto_auth_operation op, 14201 const struct gmac_test_data *tdata) 14202 { 14203 struct crypto_testsuite_params *ts_params = &testsuite_params; 14204 struct crypto_unittest_params *ut_params = &unittest_params; 14205 struct rte_crypto_sym_op *sym_op; 14206 14207 uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 14208 14209 /* Generate Crypto op data structure */ 14210 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 14211 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 14212 TEST_ASSERT_NOT_NULL(ut_params->op, 14213 "Failed to allocate symmetric crypto operation struct"); 14214 14215 sym_op = ut_params->op->sym; 14216 14217 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 14218 ut_params->ibuf, tdata->gmac_tag.len); 14219 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 14220 "no room to append digest"); 14221 14222 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 14223 ut_params->ibuf, plaintext_pad_len); 14224 14225 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 14226 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 14227 tdata->gmac_tag.len); 14228 debug_hexdump(stdout, "digest:", 14229 sym_op->auth.digest.data, 14230 tdata->gmac_tag.len); 14231 } 14232 14233 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 14234 uint8_t *, IV_OFFSET); 14235 14236 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 14237 14238 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 14239 14240 sym_op->cipher.data.length = 0; 14241 sym_op->cipher.data.offset = 0; 14242 14243 sym_op->auth.data.offset = 0; 14244 sym_op->auth.data.length = tdata->plaintext.len; 14245 14246 return 0; 14247 } 14248 14249 static int 14250 create_gmac_operation_sgl(enum rte_crypto_auth_operation op, 14251 const struct gmac_test_data *tdata, 14252 void *digest_mem, uint64_t digest_phys) 14253 { 14254 struct crypto_testsuite_params *ts_params = &testsuite_params; 14255 struct crypto_unittest_params *ut_params = &unittest_params; 14256 struct rte_crypto_sym_op *sym_op; 14257 14258 /* Generate Crypto op data structure */ 14259 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 14260 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 14261 TEST_ASSERT_NOT_NULL(ut_params->op, 14262 "Failed to allocate symmetric crypto operation struct"); 14263 14264 sym_op = ut_params->op->sym; 14265 14266 sym_op->auth.digest.data = digest_mem; 14267 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 14268 "no room to append digest"); 14269 14270 sym_op->auth.digest.phys_addr = digest_phys; 14271 14272 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 14273 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 14274 tdata->gmac_tag.len); 14275 debug_hexdump(stdout, "digest:", 14276 sym_op->auth.digest.data, 14277 tdata->gmac_tag.len); 14278 } 14279 14280 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 14281 uint8_t *, IV_OFFSET); 14282 14283 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 14284 14285 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 14286 14287 sym_op->cipher.data.length = 0; 14288 sym_op->cipher.data.offset = 0; 14289 14290 sym_op->auth.data.offset = 0; 14291 sym_op->auth.data.length = tdata->plaintext.len; 14292 14293 return 0; 14294 } 14295 14296 static int create_gmac_session(uint8_t dev_id, 14297 const struct gmac_test_data *tdata, 14298 enum rte_crypto_auth_operation auth_op) 14299 { 14300 uint8_t auth_key[tdata->key.len]; 14301 14302 struct crypto_testsuite_params *ts_params = &testsuite_params; 14303 struct crypto_unittest_params *ut_params = &unittest_params; 14304 14305 memcpy(auth_key, tdata->key.data, tdata->key.len); 14306 14307 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14308 ut_params->auth_xform.next = NULL; 14309 14310 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 14311 ut_params->auth_xform.auth.op = auth_op; 14312 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 14313 ut_params->auth_xform.auth.key.length = tdata->key.len; 14314 ut_params->auth_xform.auth.key.data = auth_key; 14315 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 14316 ut_params->auth_xform.auth.iv.length = tdata->iv.len; 14317 14318 14319 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 14320 &ut_params->auth_xform, ts_params->session_mpool); 14321 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 14322 return TEST_SKIPPED; 14323 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 14324 14325 return 0; 14326 } 14327 14328 static int 14329 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 14330 { 14331 struct crypto_testsuite_params *ts_params = &testsuite_params; 14332 struct crypto_unittest_params *ut_params = &unittest_params; 14333 struct rte_cryptodev_info dev_info; 14334 14335 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14336 uint64_t feat_flags = dev_info.feature_flags; 14337 14338 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14339 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14340 printf("Device doesn't support RAW data-path APIs.\n"); 14341 return TEST_SKIPPED; 14342 } 14343 14344 int retval; 14345 14346 uint8_t *auth_tag, *plaintext; 14347 uint16_t plaintext_pad_len; 14348 14349 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 14350 "No GMAC length in the source data"); 14351 14352 /* Verify the capabilities */ 14353 struct rte_cryptodev_sym_capability_idx cap_idx; 14354 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14355 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 14356 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14357 &cap_idx) == NULL) 14358 return TEST_SKIPPED; 14359 14360 retval = create_gmac_session(ts_params->valid_devs[0], 14361 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 14362 14363 if (retval == TEST_SKIPPED) 14364 return TEST_SKIPPED; 14365 if (retval < 0) 14366 return retval; 14367 14368 if (tdata->plaintext.len > MBUF_SIZE) 14369 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 14370 else 14371 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14372 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14373 "Failed to allocate input buffer in mempool"); 14374 14375 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14376 rte_pktmbuf_tailroom(ut_params->ibuf)); 14377 14378 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 14379 /* 14380 * Runtime generate the large plain text instead of use hard code 14381 * plain text vector. It is done to avoid create huge source file 14382 * with the test vector. 14383 */ 14384 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 14385 generate_gmac_large_plaintext(tdata->plaintext.data); 14386 14387 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14388 plaintext_pad_len); 14389 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14390 14391 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 14392 debug_hexdump(stdout, "plaintext:", plaintext, 14393 tdata->plaintext.len); 14394 14395 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 14396 tdata); 14397 14398 if (retval < 0) 14399 return retval; 14400 14401 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14402 14403 ut_params->op->sym->m_src = ut_params->ibuf; 14404 14405 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14406 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14407 ut_params->op); 14408 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 14409 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 14410 0); 14411 if (retval != TEST_SUCCESS) 14412 return retval; 14413 } else 14414 TEST_ASSERT_NOT_NULL( 14415 process_crypto_request(ts_params->valid_devs[0], 14416 ut_params->op), "failed to process sym crypto op"); 14417 14418 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14419 "crypto op processing failed"); 14420 14421 if (ut_params->op->sym->m_dst) { 14422 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 14423 uint8_t *, plaintext_pad_len); 14424 } else { 14425 auth_tag = plaintext + plaintext_pad_len; 14426 } 14427 14428 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 14429 14430 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14431 auth_tag, 14432 tdata->gmac_tag.data, 14433 tdata->gmac_tag.len, 14434 "GMAC Generated auth tag not as expected"); 14435 14436 return 0; 14437 } 14438 14439 static int 14440 test_AES_GMAC_authentication_test_case_1(void) 14441 { 14442 return test_AES_GMAC_authentication(&gmac_test_case_1); 14443 } 14444 14445 static int 14446 test_AES_GMAC_authentication_test_case_2(void) 14447 { 14448 return test_AES_GMAC_authentication(&gmac_test_case_2); 14449 } 14450 14451 static int 14452 test_AES_GMAC_authentication_test_case_3(void) 14453 { 14454 return test_AES_GMAC_authentication(&gmac_test_case_3); 14455 } 14456 14457 static int 14458 test_AES_GMAC_authentication_test_case_4(void) 14459 { 14460 return test_AES_GMAC_authentication(&gmac_test_case_4); 14461 } 14462 14463 static int 14464 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 14465 { 14466 struct crypto_testsuite_params *ts_params = &testsuite_params; 14467 struct crypto_unittest_params *ut_params = &unittest_params; 14468 int retval; 14469 uint32_t plaintext_pad_len; 14470 uint8_t *plaintext; 14471 struct rte_cryptodev_info dev_info; 14472 14473 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14474 uint64_t feat_flags = dev_info.feature_flags; 14475 14476 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14477 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14478 printf("Device doesn't support RAW data-path APIs.\n"); 14479 return TEST_SKIPPED; 14480 } 14481 14482 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 14483 "No GMAC length in the source data"); 14484 14485 /* Verify the capabilities */ 14486 struct rte_cryptodev_sym_capability_idx cap_idx; 14487 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14488 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 14489 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14490 &cap_idx) == NULL) 14491 return TEST_SKIPPED; 14492 14493 retval = create_gmac_session(ts_params->valid_devs[0], 14494 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 14495 14496 if (retval == TEST_SKIPPED) 14497 return TEST_SKIPPED; 14498 if (retval < 0) 14499 return retval; 14500 14501 if (tdata->plaintext.len > MBUF_SIZE) 14502 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 14503 else 14504 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14505 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14506 "Failed to allocate input buffer in mempool"); 14507 14508 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14509 rte_pktmbuf_tailroom(ut_params->ibuf)); 14510 14511 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 14512 14513 /* 14514 * Runtime generate the large plain text instead of use hard code 14515 * plain text vector. It is done to avoid create huge source file 14516 * with the test vector. 14517 */ 14518 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 14519 generate_gmac_large_plaintext(tdata->plaintext.data); 14520 14521 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14522 plaintext_pad_len); 14523 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14524 14525 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 14526 debug_hexdump(stdout, "plaintext:", plaintext, 14527 tdata->plaintext.len); 14528 14529 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 14530 tdata); 14531 14532 if (retval < 0) 14533 return retval; 14534 14535 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14536 14537 ut_params->op->sym->m_src = ut_params->ibuf; 14538 14539 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14540 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14541 ut_params->op); 14542 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 14543 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 14544 0); 14545 if (retval != TEST_SUCCESS) 14546 return retval; 14547 } else 14548 TEST_ASSERT_NOT_NULL( 14549 process_crypto_request(ts_params->valid_devs[0], 14550 ut_params->op), "failed to process sym crypto op"); 14551 14552 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14553 "crypto op processing failed"); 14554 14555 return 0; 14556 14557 } 14558 14559 static int 14560 test_AES_GMAC_authentication_verify_test_case_1(void) 14561 { 14562 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 14563 } 14564 14565 static int 14566 test_AES_GMAC_authentication_verify_test_case_2(void) 14567 { 14568 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 14569 } 14570 14571 static int 14572 test_AES_GMAC_authentication_verify_test_case_3(void) 14573 { 14574 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 14575 } 14576 14577 static int 14578 test_AES_GMAC_authentication_verify_test_case_4(void) 14579 { 14580 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 14581 } 14582 14583 static int 14584 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata, 14585 uint32_t fragsz) 14586 { 14587 struct crypto_testsuite_params *ts_params = &testsuite_params; 14588 struct crypto_unittest_params *ut_params = &unittest_params; 14589 struct rte_cryptodev_info dev_info; 14590 uint64_t feature_flags; 14591 unsigned int trn_data = 0; 14592 void *digest_mem = NULL; 14593 uint32_t segs = 1; 14594 unsigned int to_trn = 0; 14595 struct rte_mbuf *buf = NULL; 14596 uint8_t *auth_tag, *plaintext; 14597 int retval; 14598 14599 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 14600 "No GMAC length in the source data"); 14601 14602 /* Verify the capabilities */ 14603 struct rte_cryptodev_sym_capability_idx cap_idx; 14604 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14605 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 14606 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14607 &cap_idx) == NULL) 14608 return TEST_SKIPPED; 14609 14610 /* Check for any input SGL support */ 14611 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14612 feature_flags = dev_info.feature_flags; 14613 14614 if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) || 14615 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) || 14616 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))) 14617 return TEST_SKIPPED; 14618 14619 if (fragsz > tdata->plaintext.len) 14620 fragsz = tdata->plaintext.len; 14621 14622 uint16_t plaintext_len = fragsz; 14623 14624 retval = create_gmac_session(ts_params->valid_devs[0], 14625 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 14626 14627 if (retval == TEST_SKIPPED) 14628 return TEST_SKIPPED; 14629 if (retval < 0) 14630 return retval; 14631 14632 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14633 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14634 "Failed to allocate input buffer in mempool"); 14635 14636 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14637 rte_pktmbuf_tailroom(ut_params->ibuf)); 14638 14639 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14640 plaintext_len); 14641 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14642 14643 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 14644 14645 trn_data += plaintext_len; 14646 14647 buf = ut_params->ibuf; 14648 14649 /* 14650 * Loop until no more fragments 14651 */ 14652 14653 while (trn_data < tdata->plaintext.len) { 14654 ++segs; 14655 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 14656 (tdata->plaintext.len - trn_data) : fragsz; 14657 14658 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14659 buf = buf->next; 14660 14661 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 14662 rte_pktmbuf_tailroom(buf)); 14663 14664 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 14665 to_trn); 14666 14667 memcpy(plaintext, tdata->plaintext.data + trn_data, 14668 to_trn); 14669 trn_data += to_trn; 14670 if (trn_data == tdata->plaintext.len) 14671 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 14672 tdata->gmac_tag.len); 14673 } 14674 ut_params->ibuf->nb_segs = segs; 14675 14676 /* 14677 * Place digest at the end of the last buffer 14678 */ 14679 uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn; 14680 14681 if (!digest_mem) { 14682 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14683 + tdata->gmac_tag.len); 14684 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 14685 tdata->plaintext.len); 14686 } 14687 14688 retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE, 14689 tdata, digest_mem, digest_phys); 14690 14691 if (retval < 0) 14692 return retval; 14693 14694 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14695 14696 ut_params->op->sym->m_src = ut_params->ibuf; 14697 14698 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14699 return TEST_SKIPPED; 14700 14701 TEST_ASSERT_NOT_NULL( 14702 process_crypto_request(ts_params->valid_devs[0], 14703 ut_params->op), "failed to process sym crypto op"); 14704 14705 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14706 "crypto op processing failed"); 14707 14708 auth_tag = digest_mem; 14709 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 14710 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14711 auth_tag, 14712 tdata->gmac_tag.data, 14713 tdata->gmac_tag.len, 14714 "GMAC Generated auth tag not as expected"); 14715 14716 return 0; 14717 } 14718 14719 /* Segment size not multiple of block size (16B) */ 14720 static int 14721 test_AES_GMAC_authentication_SGL_40B(void) 14722 { 14723 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40); 14724 } 14725 14726 static int 14727 test_AES_GMAC_authentication_SGL_80B(void) 14728 { 14729 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80); 14730 } 14731 14732 static int 14733 test_AES_GMAC_authentication_SGL_2048B(void) 14734 { 14735 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048); 14736 } 14737 14738 /* Segment size not multiple of block size (16B) */ 14739 static int 14740 test_AES_GMAC_authentication_SGL_2047B(void) 14741 { 14742 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047); 14743 } 14744 14745 struct test_crypto_vector { 14746 enum rte_crypto_cipher_algorithm crypto_algo; 14747 unsigned int cipher_offset; 14748 unsigned int cipher_len; 14749 14750 struct { 14751 uint8_t data[64]; 14752 unsigned int len; 14753 } cipher_key; 14754 14755 struct { 14756 uint8_t data[64]; 14757 unsigned int len; 14758 } iv; 14759 14760 struct { 14761 const uint8_t *data; 14762 unsigned int len; 14763 } plaintext; 14764 14765 struct { 14766 const uint8_t *data; 14767 unsigned int len; 14768 } ciphertext; 14769 14770 enum rte_crypto_auth_algorithm auth_algo; 14771 unsigned int auth_offset; 14772 14773 struct { 14774 uint8_t data[128]; 14775 unsigned int len; 14776 } auth_key; 14777 14778 struct { 14779 const uint8_t *data; 14780 unsigned int len; 14781 } aad; 14782 14783 struct { 14784 uint8_t data[128]; 14785 unsigned int len; 14786 } digest; 14787 }; 14788 14789 static const struct test_crypto_vector 14790 hmac_sha1_test_crypto_vector = { 14791 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 14792 .plaintext = { 14793 .data = plaintext_hash, 14794 .len = 512 14795 }, 14796 .auth_key = { 14797 .data = { 14798 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 14799 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 14800 0xDE, 0xF4, 0xDE, 0xAD 14801 }, 14802 .len = 20 14803 }, 14804 .digest = { 14805 .data = { 14806 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 14807 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 14808 0x3F, 0x91, 0x64, 0x59 14809 }, 14810 .len = 20 14811 } 14812 }; 14813 14814 static const struct test_crypto_vector 14815 aes128_gmac_test_vector = { 14816 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 14817 .plaintext = { 14818 .data = plaintext_hash, 14819 .len = 512 14820 }, 14821 .iv = { 14822 .data = { 14823 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 14824 0x08, 0x09, 0x0A, 0x0B 14825 }, 14826 .len = 12 14827 }, 14828 .auth_key = { 14829 .data = { 14830 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 14831 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 14832 }, 14833 .len = 16 14834 }, 14835 .digest = { 14836 .data = { 14837 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 14838 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 14839 }, 14840 .len = 16 14841 } 14842 }; 14843 14844 static const struct test_crypto_vector 14845 aes128cbc_hmac_sha1_test_vector = { 14846 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 14847 .cipher_offset = 0, 14848 .cipher_len = 512, 14849 .cipher_key = { 14850 .data = { 14851 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 14852 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 14853 }, 14854 .len = 16 14855 }, 14856 .iv = { 14857 .data = { 14858 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 14859 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 14860 }, 14861 .len = 16 14862 }, 14863 .plaintext = { 14864 .data = plaintext_hash, 14865 .len = 512 14866 }, 14867 .ciphertext = { 14868 .data = ciphertext512_aes128cbc, 14869 .len = 512 14870 }, 14871 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 14872 .auth_offset = 0, 14873 .auth_key = { 14874 .data = { 14875 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 14876 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 14877 0xDE, 0xF4, 0xDE, 0xAD 14878 }, 14879 .len = 20 14880 }, 14881 .digest = { 14882 .data = { 14883 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 14884 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 14885 0x18, 0x8C, 0x1D, 0x32 14886 }, 14887 .len = 20 14888 } 14889 }; 14890 14891 static const struct test_crypto_vector 14892 aes128cbc_hmac_sha1_aad_test_vector = { 14893 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 14894 .cipher_offset = 8, 14895 .cipher_len = 496, 14896 .cipher_key = { 14897 .data = { 14898 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 14899 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 14900 }, 14901 .len = 16 14902 }, 14903 .iv = { 14904 .data = { 14905 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 14906 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 14907 }, 14908 .len = 16 14909 }, 14910 .plaintext = { 14911 .data = plaintext_hash, 14912 .len = 512 14913 }, 14914 .ciphertext = { 14915 .data = ciphertext512_aes128cbc_aad, 14916 .len = 512 14917 }, 14918 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 14919 .auth_offset = 0, 14920 .auth_key = { 14921 .data = { 14922 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 14923 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 14924 0xDE, 0xF4, 0xDE, 0xAD 14925 }, 14926 .len = 20 14927 }, 14928 .digest = { 14929 .data = { 14930 0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F, 14931 0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B, 14932 0x62, 0x0F, 0xFB, 0x10 14933 }, 14934 .len = 20 14935 } 14936 }; 14937 14938 static void 14939 data_corruption(uint8_t *data) 14940 { 14941 data[0] += 1; 14942 } 14943 14944 static void 14945 tag_corruption(uint8_t *data, unsigned int tag_offset) 14946 { 14947 data[tag_offset] += 1; 14948 } 14949 14950 static int 14951 create_auth_session(struct crypto_unittest_params *ut_params, 14952 uint8_t dev_id, 14953 const struct test_crypto_vector *reference, 14954 enum rte_crypto_auth_operation auth_op) 14955 { 14956 struct crypto_testsuite_params *ts_params = &testsuite_params; 14957 uint8_t auth_key[reference->auth_key.len + 1]; 14958 14959 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 14960 14961 /* Setup Authentication Parameters */ 14962 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14963 ut_params->auth_xform.auth.op = auth_op; 14964 ut_params->auth_xform.next = NULL; 14965 ut_params->auth_xform.auth.algo = reference->auth_algo; 14966 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 14967 ut_params->auth_xform.auth.key.data = auth_key; 14968 ut_params->auth_xform.auth.digest_length = reference->digest.len; 14969 14970 /* Create Crypto session*/ 14971 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 14972 &ut_params->auth_xform, 14973 ts_params->session_mpool); 14974 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 14975 return TEST_SKIPPED; 14976 14977 return 0; 14978 } 14979 14980 static int 14981 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 14982 uint8_t dev_id, 14983 const struct test_crypto_vector *reference, 14984 enum rte_crypto_auth_operation auth_op, 14985 enum rte_crypto_cipher_operation cipher_op) 14986 { 14987 struct crypto_testsuite_params *ts_params = &testsuite_params; 14988 uint8_t cipher_key[reference->cipher_key.len + 1]; 14989 uint8_t auth_key[reference->auth_key.len + 1]; 14990 14991 memcpy(cipher_key, reference->cipher_key.data, 14992 reference->cipher_key.len); 14993 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 14994 14995 /* Setup Authentication Parameters */ 14996 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14997 ut_params->auth_xform.auth.op = auth_op; 14998 ut_params->auth_xform.auth.algo = reference->auth_algo; 14999 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 15000 ut_params->auth_xform.auth.key.data = auth_key; 15001 ut_params->auth_xform.auth.digest_length = reference->digest.len; 15002 15003 if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) { 15004 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 15005 ut_params->auth_xform.auth.iv.length = reference->iv.len; 15006 } else { 15007 ut_params->auth_xform.next = &ut_params->cipher_xform; 15008 15009 /* Setup Cipher Parameters */ 15010 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15011 ut_params->cipher_xform.next = NULL; 15012 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 15013 ut_params->cipher_xform.cipher.op = cipher_op; 15014 ut_params->cipher_xform.cipher.key.data = cipher_key; 15015 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 15016 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 15017 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 15018 } 15019 15020 /* Create Crypto session*/ 15021 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 15022 &ut_params->auth_xform, 15023 ts_params->session_mpool); 15024 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 15025 return TEST_SKIPPED; 15026 15027 return 0; 15028 } 15029 15030 static int 15031 create_auth_operation(struct crypto_testsuite_params *ts_params, 15032 struct crypto_unittest_params *ut_params, 15033 const struct test_crypto_vector *reference, 15034 unsigned int auth_generate) 15035 { 15036 /* Generate Crypto op data structure */ 15037 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 15038 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 15039 TEST_ASSERT_NOT_NULL(ut_params->op, 15040 "Failed to allocate pktmbuf offload"); 15041 15042 /* Set crypto operation data parameters */ 15043 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 15044 15045 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 15046 15047 /* set crypto operation source mbuf */ 15048 sym_op->m_src = ut_params->ibuf; 15049 15050 /* digest */ 15051 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 15052 ut_params->ibuf, reference->digest.len); 15053 15054 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 15055 "no room to append auth tag"); 15056 15057 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 15058 ut_params->ibuf, reference->plaintext.len); 15059 15060 if (auth_generate) 15061 memset(sym_op->auth.digest.data, 0, reference->digest.len); 15062 else 15063 memcpy(sym_op->auth.digest.data, 15064 reference->digest.data, 15065 reference->digest.len); 15066 15067 debug_hexdump(stdout, "digest:", 15068 sym_op->auth.digest.data, 15069 reference->digest.len); 15070 15071 sym_op->auth.data.length = reference->plaintext.len; 15072 sym_op->auth.data.offset = 0; 15073 15074 return 0; 15075 } 15076 15077 static int 15078 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 15079 struct crypto_unittest_params *ut_params, 15080 const struct test_crypto_vector *reference, 15081 unsigned int auth_generate) 15082 { 15083 /* Generate Crypto op data structure */ 15084 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 15085 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 15086 TEST_ASSERT_NOT_NULL(ut_params->op, 15087 "Failed to allocate pktmbuf offload"); 15088 15089 /* Set crypto operation data parameters */ 15090 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 15091 15092 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 15093 15094 /* set crypto operation source mbuf */ 15095 sym_op->m_src = ut_params->ibuf; 15096 15097 /* digest */ 15098 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 15099 ut_params->ibuf, reference->digest.len); 15100 15101 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 15102 "no room to append auth tag"); 15103 15104 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 15105 ut_params->ibuf, reference->ciphertext.len); 15106 15107 if (auth_generate) 15108 memset(sym_op->auth.digest.data, 0, reference->digest.len); 15109 else 15110 memcpy(sym_op->auth.digest.data, 15111 reference->digest.data, 15112 reference->digest.len); 15113 15114 debug_hexdump(stdout, "digest:", 15115 sym_op->auth.digest.data, 15116 reference->digest.len); 15117 15118 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 15119 reference->iv.data, reference->iv.len); 15120 15121 sym_op->cipher.data.length = 0; 15122 sym_op->cipher.data.offset = 0; 15123 15124 sym_op->auth.data.length = reference->plaintext.len; 15125 sym_op->auth.data.offset = 0; 15126 15127 return 0; 15128 } 15129 15130 static int 15131 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 15132 struct crypto_unittest_params *ut_params, 15133 const struct test_crypto_vector *reference, 15134 unsigned int auth_generate) 15135 { 15136 /* Generate Crypto op data structure */ 15137 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 15138 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 15139 TEST_ASSERT_NOT_NULL(ut_params->op, 15140 "Failed to allocate pktmbuf offload"); 15141 15142 /* Set crypto operation data parameters */ 15143 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 15144 15145 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 15146 15147 /* set crypto operation source mbuf */ 15148 sym_op->m_src = ut_params->ibuf; 15149 15150 /* digest */ 15151 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 15152 ut_params->ibuf, reference->digest.len); 15153 15154 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 15155 "no room to append auth tag"); 15156 15157 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 15158 ut_params->ibuf, reference->ciphertext.len); 15159 15160 if (auth_generate) 15161 memset(sym_op->auth.digest.data, 0, reference->digest.len); 15162 else 15163 memcpy(sym_op->auth.digest.data, 15164 reference->digest.data, 15165 reference->digest.len); 15166 15167 debug_hexdump(stdout, "digest:", 15168 sym_op->auth.digest.data, 15169 reference->digest.len); 15170 15171 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 15172 reference->iv.data, reference->iv.len); 15173 15174 sym_op->cipher.data.length = reference->cipher_len; 15175 sym_op->cipher.data.offset = reference->cipher_offset; 15176 15177 sym_op->auth.data.length = reference->plaintext.len; 15178 sym_op->auth.data.offset = reference->auth_offset; 15179 15180 return 0; 15181 } 15182 15183 static int 15184 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 15185 struct crypto_unittest_params *ut_params, 15186 const struct test_crypto_vector *reference) 15187 { 15188 return create_auth_operation(ts_params, ut_params, reference, 0); 15189 } 15190 15191 static int 15192 create_auth_verify_GMAC_operation( 15193 struct crypto_testsuite_params *ts_params, 15194 struct crypto_unittest_params *ut_params, 15195 const struct test_crypto_vector *reference) 15196 { 15197 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 15198 } 15199 15200 static int 15201 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params, 15202 struct crypto_unittest_params *ut_params, 15203 const struct test_crypto_vector *reference) 15204 { 15205 return create_cipher_auth_operation(ts_params, ut_params, reference, 0); 15206 } 15207 15208 static int 15209 test_authentication_verify_fail_when_data_corruption( 15210 struct crypto_testsuite_params *ts_params, 15211 struct crypto_unittest_params *ut_params, 15212 const struct test_crypto_vector *reference, 15213 unsigned int data_corrupted) 15214 { 15215 int retval; 15216 15217 uint8_t *plaintext; 15218 struct rte_cryptodev_info dev_info; 15219 15220 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15221 uint64_t feat_flags = dev_info.feature_flags; 15222 15223 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15224 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15225 printf("Device doesn't support RAW data-path APIs.\n"); 15226 return TEST_SKIPPED; 15227 } 15228 15229 /* Verify the capabilities */ 15230 struct rte_cryptodev_sym_capability_idx cap_idx; 15231 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15232 cap_idx.algo.auth = reference->auth_algo; 15233 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15234 &cap_idx) == NULL) 15235 return TEST_SKIPPED; 15236 15237 15238 /* Create session */ 15239 retval = create_auth_session(ut_params, 15240 ts_params->valid_devs[0], 15241 reference, 15242 RTE_CRYPTO_AUTH_OP_VERIFY); 15243 15244 if (retval == TEST_SKIPPED) 15245 return TEST_SKIPPED; 15246 if (retval < 0) 15247 return retval; 15248 15249 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15250 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 15251 "Failed to allocate input buffer in mempool"); 15252 15253 /* clear mbuf payload */ 15254 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15255 rte_pktmbuf_tailroom(ut_params->ibuf)); 15256 15257 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15258 reference->plaintext.len); 15259 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 15260 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 15261 15262 debug_hexdump(stdout, "plaintext:", plaintext, 15263 reference->plaintext.len); 15264 15265 /* Create operation */ 15266 retval = create_auth_verify_operation(ts_params, ut_params, reference); 15267 15268 if (retval < 0) 15269 return retval; 15270 15271 if (data_corrupted) 15272 data_corruption(plaintext); 15273 else 15274 tag_corruption(plaintext, reference->plaintext.len); 15275 15276 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 15277 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 15278 ut_params->op); 15279 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 15280 RTE_CRYPTO_OP_STATUS_SUCCESS, 15281 "authentication not failed"); 15282 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15283 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 15284 0); 15285 if (retval != TEST_SUCCESS) 15286 return retval; 15287 } else { 15288 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 15289 ut_params->op); 15290 } 15291 if (ut_params->op == NULL) 15292 return 0; 15293 else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) 15294 return 0; 15295 15296 return -1; 15297 } 15298 15299 static int 15300 test_authentication_verify_GMAC_fail_when_corruption( 15301 struct crypto_testsuite_params *ts_params, 15302 struct crypto_unittest_params *ut_params, 15303 const struct test_crypto_vector *reference, 15304 unsigned int data_corrupted) 15305 { 15306 int retval; 15307 uint8_t *plaintext; 15308 struct rte_cryptodev_info dev_info; 15309 15310 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15311 uint64_t feat_flags = dev_info.feature_flags; 15312 15313 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15314 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15315 printf("Device doesn't support RAW data-path APIs.\n"); 15316 return TEST_SKIPPED; 15317 } 15318 15319 /* Verify the capabilities */ 15320 struct rte_cryptodev_sym_capability_idx cap_idx; 15321 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15322 cap_idx.algo.auth = reference->auth_algo; 15323 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15324 &cap_idx) == NULL) 15325 return TEST_SKIPPED; 15326 15327 /* Create session */ 15328 retval = create_auth_cipher_session(ut_params, 15329 ts_params->valid_devs[0], 15330 reference, 15331 RTE_CRYPTO_AUTH_OP_VERIFY, 15332 RTE_CRYPTO_CIPHER_OP_DECRYPT); 15333 if (retval == TEST_SKIPPED) 15334 return TEST_SKIPPED; 15335 if (retval < 0) 15336 return retval; 15337 15338 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15339 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 15340 "Failed to allocate input buffer in mempool"); 15341 15342 /* clear mbuf payload */ 15343 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15344 rte_pktmbuf_tailroom(ut_params->ibuf)); 15345 15346 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15347 reference->plaintext.len); 15348 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 15349 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 15350 15351 debug_hexdump(stdout, "plaintext:", plaintext, 15352 reference->plaintext.len); 15353 15354 /* Create operation */ 15355 retval = create_auth_verify_GMAC_operation(ts_params, 15356 ut_params, 15357 reference); 15358 15359 if (retval < 0) 15360 return retval; 15361 15362 if (data_corrupted) 15363 data_corruption(plaintext); 15364 else 15365 tag_corruption(plaintext, reference->aad.len); 15366 15367 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 15368 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 15369 ut_params->op); 15370 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 15371 RTE_CRYPTO_OP_STATUS_SUCCESS, 15372 "authentication not failed"); 15373 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15374 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 15375 0); 15376 if (retval != TEST_SUCCESS) 15377 return retval; 15378 } else { 15379 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 15380 ut_params->op); 15381 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 15382 } 15383 15384 return 0; 15385 } 15386 15387 static int 15388 test_authenticated_decryption_fail_when_corruption( 15389 struct crypto_testsuite_params *ts_params, 15390 struct crypto_unittest_params *ut_params, 15391 const struct test_crypto_vector *reference, 15392 unsigned int data_corrupted) 15393 { 15394 int retval; 15395 15396 uint8_t *ciphertext; 15397 struct rte_cryptodev_info dev_info; 15398 15399 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15400 uint64_t feat_flags = dev_info.feature_flags; 15401 15402 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15403 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15404 printf("Device doesn't support RAW data-path APIs.\n"); 15405 return TEST_SKIPPED; 15406 } 15407 15408 /* Verify the capabilities */ 15409 struct rte_cryptodev_sym_capability_idx cap_idx; 15410 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15411 cap_idx.algo.auth = reference->auth_algo; 15412 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15413 &cap_idx) == NULL) 15414 return TEST_SKIPPED; 15415 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15416 cap_idx.algo.cipher = reference->crypto_algo; 15417 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15418 &cap_idx) == NULL) 15419 return TEST_SKIPPED; 15420 15421 /* Create session */ 15422 retval = create_auth_cipher_session(ut_params, 15423 ts_params->valid_devs[0], 15424 reference, 15425 RTE_CRYPTO_AUTH_OP_VERIFY, 15426 RTE_CRYPTO_CIPHER_OP_DECRYPT); 15427 if (retval == TEST_SKIPPED) 15428 return TEST_SKIPPED; 15429 if (retval < 0) 15430 return retval; 15431 15432 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15433 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 15434 "Failed to allocate input buffer in mempool"); 15435 15436 /* clear mbuf payload */ 15437 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15438 rte_pktmbuf_tailroom(ut_params->ibuf)); 15439 15440 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15441 reference->ciphertext.len); 15442 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 15443 memcpy(ciphertext, reference->ciphertext.data, 15444 reference->ciphertext.len); 15445 15446 /* Create operation */ 15447 retval = create_cipher_auth_verify_operation(ts_params, 15448 ut_params, 15449 reference); 15450 15451 if (retval < 0) 15452 return retval; 15453 15454 if (data_corrupted) 15455 data_corruption(ciphertext); 15456 else 15457 tag_corruption(ciphertext, reference->ciphertext.len); 15458 15459 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 15460 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 15461 ut_params->op); 15462 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 15463 RTE_CRYPTO_OP_STATUS_SUCCESS, 15464 "authentication not failed"); 15465 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15466 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 15467 0); 15468 if (retval != TEST_SUCCESS) 15469 return retval; 15470 } else { 15471 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 15472 ut_params->op); 15473 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 15474 } 15475 15476 return 0; 15477 } 15478 15479 static int 15480 test_authenticated_encrypt_with_esn( 15481 struct crypto_testsuite_params *ts_params, 15482 struct crypto_unittest_params *ut_params, 15483 const struct test_crypto_vector *reference) 15484 { 15485 int retval; 15486 15487 uint8_t *authciphertext, *plaintext, *auth_tag; 15488 uint16_t plaintext_pad_len; 15489 uint8_t cipher_key[reference->cipher_key.len + 1]; 15490 uint8_t auth_key[reference->auth_key.len + 1]; 15491 struct rte_cryptodev_info dev_info; 15492 15493 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15494 uint64_t feat_flags = dev_info.feature_flags; 15495 15496 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15497 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15498 printf("Device doesn't support RAW data-path APIs.\n"); 15499 return TEST_SKIPPED; 15500 } 15501 15502 /* Verify the capabilities */ 15503 struct rte_cryptodev_sym_capability_idx cap_idx; 15504 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15505 cap_idx.algo.auth = reference->auth_algo; 15506 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15507 &cap_idx) == NULL) 15508 return TEST_SKIPPED; 15509 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15510 cap_idx.algo.cipher = reference->crypto_algo; 15511 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15512 &cap_idx) == NULL) 15513 return TEST_SKIPPED; 15514 15515 /* Create session */ 15516 memcpy(cipher_key, reference->cipher_key.data, 15517 reference->cipher_key.len); 15518 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 15519 15520 /* Setup Cipher Parameters */ 15521 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15522 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 15523 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 15524 ut_params->cipher_xform.cipher.key.data = cipher_key; 15525 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 15526 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 15527 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 15528 15529 ut_params->cipher_xform.next = &ut_params->auth_xform; 15530 15531 /* Setup Authentication Parameters */ 15532 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15533 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 15534 ut_params->auth_xform.auth.algo = reference->auth_algo; 15535 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 15536 ut_params->auth_xform.auth.key.data = auth_key; 15537 ut_params->auth_xform.auth.digest_length = reference->digest.len; 15538 ut_params->auth_xform.next = NULL; 15539 15540 /* Create Crypto session*/ 15541 ut_params->sess = rte_cryptodev_sym_session_create( 15542 ts_params->valid_devs[0], &ut_params->cipher_xform, 15543 ts_params->session_mpool); 15544 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 15545 return TEST_SKIPPED; 15546 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 15547 15548 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15549 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 15550 "Failed to allocate input buffer in mempool"); 15551 15552 /* clear mbuf payload */ 15553 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15554 rte_pktmbuf_tailroom(ut_params->ibuf)); 15555 15556 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15557 reference->plaintext.len); 15558 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 15559 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 15560 15561 /* Create operation */ 15562 retval = create_cipher_auth_operation(ts_params, 15563 ut_params, 15564 reference, 0); 15565 15566 if (retval < 0) 15567 return retval; 15568 15569 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 15570 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 15571 ut_params->op); 15572 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15573 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 15574 0); 15575 if (retval != TEST_SUCCESS) 15576 return retval; 15577 } else 15578 ut_params->op = process_crypto_request( 15579 ts_params->valid_devs[0], ut_params->op); 15580 15581 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 15582 15583 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 15584 "crypto op processing failed"); 15585 15586 plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16); 15587 15588 authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 15589 ut_params->op->sym->auth.data.offset); 15590 auth_tag = authciphertext + plaintext_pad_len; 15591 debug_hexdump(stdout, "ciphertext:", authciphertext, 15592 reference->ciphertext.len); 15593 debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len); 15594 15595 /* Validate obuf */ 15596 TEST_ASSERT_BUFFERS_ARE_EQUAL( 15597 authciphertext, 15598 reference->ciphertext.data, 15599 reference->ciphertext.len, 15600 "Ciphertext data not as expected"); 15601 15602 TEST_ASSERT_BUFFERS_ARE_EQUAL( 15603 auth_tag, 15604 reference->digest.data, 15605 reference->digest.len, 15606 "Generated digest not as expected"); 15607 15608 return TEST_SUCCESS; 15609 15610 } 15611 15612 static int 15613 test_authenticated_decrypt_with_esn( 15614 struct crypto_testsuite_params *ts_params, 15615 struct crypto_unittest_params *ut_params, 15616 const struct test_crypto_vector *reference) 15617 { 15618 int retval; 15619 15620 uint8_t *ciphertext; 15621 uint8_t cipher_key[reference->cipher_key.len + 1]; 15622 uint8_t auth_key[reference->auth_key.len + 1]; 15623 struct rte_cryptodev_info dev_info; 15624 15625 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15626 uint64_t feat_flags = dev_info.feature_flags; 15627 15628 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15629 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15630 printf("Device doesn't support RAW data-path APIs.\n"); 15631 return TEST_SKIPPED; 15632 } 15633 15634 /* Verify the capabilities */ 15635 struct rte_cryptodev_sym_capability_idx cap_idx; 15636 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15637 cap_idx.algo.auth = reference->auth_algo; 15638 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15639 &cap_idx) == NULL) 15640 return TEST_SKIPPED; 15641 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15642 cap_idx.algo.cipher = reference->crypto_algo; 15643 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15644 &cap_idx) == NULL) 15645 return TEST_SKIPPED; 15646 15647 /* Create session */ 15648 memcpy(cipher_key, reference->cipher_key.data, 15649 reference->cipher_key.len); 15650 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 15651 15652 /* Setup Authentication Parameters */ 15653 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15654 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 15655 ut_params->auth_xform.auth.algo = reference->auth_algo; 15656 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 15657 ut_params->auth_xform.auth.key.data = auth_key; 15658 ut_params->auth_xform.auth.digest_length = reference->digest.len; 15659 ut_params->auth_xform.next = &ut_params->cipher_xform; 15660 15661 /* Setup Cipher Parameters */ 15662 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15663 ut_params->cipher_xform.next = NULL; 15664 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 15665 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 15666 ut_params->cipher_xform.cipher.key.data = cipher_key; 15667 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 15668 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 15669 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 15670 15671 /* Create Crypto session*/ 15672 ut_params->sess = rte_cryptodev_sym_session_create( 15673 ts_params->valid_devs[0], &ut_params->auth_xform, 15674 ts_params->session_mpool); 15675 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 15676 return TEST_SKIPPED; 15677 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 15678 15679 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15680 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 15681 "Failed to allocate input buffer in mempool"); 15682 15683 /* clear mbuf payload */ 15684 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15685 rte_pktmbuf_tailroom(ut_params->ibuf)); 15686 15687 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15688 reference->ciphertext.len); 15689 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 15690 memcpy(ciphertext, reference->ciphertext.data, 15691 reference->ciphertext.len); 15692 15693 /* Create operation */ 15694 retval = create_cipher_auth_verify_operation(ts_params, 15695 ut_params, 15696 reference); 15697 15698 if (retval < 0) 15699 return retval; 15700 15701 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 15702 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 15703 ut_params->op); 15704 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15705 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 15706 0); 15707 if (retval != TEST_SUCCESS) 15708 return retval; 15709 } else 15710 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 15711 ut_params->op); 15712 15713 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 15714 TEST_ASSERT_EQUAL(ut_params->op->status, 15715 RTE_CRYPTO_OP_STATUS_SUCCESS, 15716 "crypto op processing passed"); 15717 15718 ut_params->obuf = ut_params->op->sym->m_src; 15719 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 15720 15721 return 0; 15722 } 15723 15724 static int 15725 create_aead_operation_SGL(enum rte_crypto_aead_operation op, 15726 const struct aead_test_data *tdata, 15727 void *digest_mem, uint64_t digest_phys) 15728 { 15729 struct crypto_testsuite_params *ts_params = &testsuite_params; 15730 struct crypto_unittest_params *ut_params = &unittest_params; 15731 15732 const unsigned int auth_tag_len = tdata->auth_tag.len; 15733 const unsigned int iv_len = tdata->iv.len; 15734 unsigned int aad_len = tdata->aad.len; 15735 unsigned int aad_len_pad = 0; 15736 15737 /* Generate Crypto op data structure */ 15738 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 15739 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 15740 TEST_ASSERT_NOT_NULL(ut_params->op, 15741 "Failed to allocate symmetric crypto operation struct"); 15742 15743 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 15744 15745 sym_op->aead.digest.data = digest_mem; 15746 15747 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 15748 "no room to append digest"); 15749 15750 sym_op->aead.digest.phys_addr = digest_phys; 15751 15752 if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) { 15753 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 15754 auth_tag_len); 15755 debug_hexdump(stdout, "digest:", 15756 sym_op->aead.digest.data, 15757 auth_tag_len); 15758 } 15759 15760 /* Append aad data */ 15761 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 15762 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 15763 uint8_t *, IV_OFFSET); 15764 15765 /* Copy IV 1 byte after the IV pointer, according to the API */ 15766 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len); 15767 15768 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16); 15769 15770 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 15771 ut_params->ibuf, aad_len); 15772 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 15773 "no room to prepend aad"); 15774 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 15775 ut_params->ibuf); 15776 15777 memset(sym_op->aead.aad.data, 0, aad_len); 15778 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 15779 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 15780 15781 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 15782 debug_hexdump(stdout, "aad:", 15783 sym_op->aead.aad.data, aad_len); 15784 } else { 15785 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 15786 uint8_t *, IV_OFFSET); 15787 15788 rte_memcpy(iv_ptr, tdata->iv.data, iv_len); 15789 15790 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16); 15791 15792 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 15793 ut_params->ibuf, aad_len_pad); 15794 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 15795 "no room to prepend aad"); 15796 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 15797 ut_params->ibuf); 15798 15799 memset(sym_op->aead.aad.data, 0, aad_len); 15800 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 15801 15802 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 15803 debug_hexdump(stdout, "aad:", 15804 sym_op->aead.aad.data, aad_len); 15805 } 15806 15807 sym_op->aead.data.length = tdata->plaintext.len; 15808 sym_op->aead.data.offset = aad_len_pad; 15809 15810 return 0; 15811 } 15812 15813 #define SGL_MAX_NO 16 15814 15815 static int 15816 test_authenticated_encryption_SGL(const struct aead_test_data *tdata, 15817 const int oop, uint32_t fragsz, uint32_t fragsz_oop) 15818 { 15819 struct crypto_testsuite_params *ts_params = &testsuite_params; 15820 struct crypto_unittest_params *ut_params = &unittest_params; 15821 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL; 15822 int retval; 15823 int to_trn = 0; 15824 int to_trn_tbl[SGL_MAX_NO]; 15825 int segs = 1; 15826 unsigned int trn_data = 0; 15827 uint8_t *plaintext, *ciphertext, *auth_tag; 15828 struct rte_cryptodev_info dev_info; 15829 15830 /* Verify the capabilities */ 15831 struct rte_cryptodev_sym_capability_idx cap_idx; 15832 const struct rte_cryptodev_symmetric_capability *capability; 15833 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 15834 cap_idx.algo.aead = tdata->algo; 15835 capability = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], &cap_idx); 15836 if (capability == NULL) 15837 return TEST_SKIPPED; 15838 if (rte_cryptodev_sym_capability_check_aead(capability, tdata->key.len, 15839 tdata->auth_tag.len, tdata->aad.len, tdata->iv.len)) 15840 return TEST_SKIPPED; 15841 15842 /* 15843 * SGL not supported on AESNI_MB PMD CPU crypto, 15844 * OOP not supported on AESNI_GCM CPU crypto 15845 */ 15846 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO && 15847 (gbl_driver_id == rte_cryptodev_driver_id_get( 15848 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) || oop)) 15849 return TEST_SKIPPED; 15850 15851 /* Detailed check for the particular SGL support flag */ 15852 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15853 if (!oop) { 15854 unsigned int sgl_in = fragsz < tdata->plaintext.len; 15855 if (sgl_in && (!(dev_info.feature_flags & 15856 RTE_CRYPTODEV_FF_IN_PLACE_SGL))) 15857 return TEST_SKIPPED; 15858 15859 uint64_t feat_flags = dev_info.feature_flags; 15860 15861 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15862 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15863 printf("Device doesn't support RAW data-path APIs.\n"); 15864 return TEST_SKIPPED; 15865 } 15866 } else { 15867 unsigned int sgl_in = fragsz < tdata->plaintext.len; 15868 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) < 15869 tdata->plaintext.len; 15870 /* Raw data path API does not support OOP */ 15871 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 15872 return TEST_SKIPPED; 15873 if (sgl_in && !sgl_out) { 15874 if (!(dev_info.feature_flags & 15875 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) 15876 return TEST_SKIPPED; 15877 } else if (!sgl_in && sgl_out) { 15878 if (!(dev_info.feature_flags & 15879 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 15880 return TEST_SKIPPED; 15881 } else if (sgl_in && sgl_out) { 15882 if (!(dev_info.feature_flags & 15883 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 15884 return TEST_SKIPPED; 15885 } 15886 } 15887 15888 if (fragsz > tdata->plaintext.len) 15889 fragsz = tdata->plaintext.len; 15890 15891 uint16_t plaintext_len = fragsz; 15892 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 15893 15894 if (fragsz_oop > tdata->plaintext.len) 15895 frag_size_oop = tdata->plaintext.len; 15896 15897 int ecx = 0; 15898 void *digest_mem = NULL; 15899 15900 uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 15901 15902 if (tdata->plaintext.len % fragsz != 0) { 15903 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO) 15904 return 1; 15905 } else { 15906 if (tdata->plaintext.len / fragsz > SGL_MAX_NO) 15907 return 1; 15908 } 15909 15910 /* 15911 * For out-op-place we need to alloc another mbuf 15912 */ 15913 if (oop) { 15914 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15915 rte_pktmbuf_append(ut_params->obuf, 15916 frag_size_oop + prepend_len); 15917 buf_oop = ut_params->obuf; 15918 } 15919 15920 /* Create AEAD session */ 15921 retval = create_aead_session(ts_params->valid_devs[0], 15922 tdata->algo, 15923 RTE_CRYPTO_AEAD_OP_ENCRYPT, 15924 tdata->key.data, tdata->key.len, 15925 tdata->aad.len, tdata->auth_tag.len, 15926 tdata->iv.len); 15927 if (retval < 0) 15928 return retval; 15929 15930 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15931 15932 /* clear mbuf payload */ 15933 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15934 rte_pktmbuf_tailroom(ut_params->ibuf)); 15935 15936 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15937 plaintext_len); 15938 15939 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 15940 15941 trn_data += plaintext_len; 15942 15943 buf = ut_params->ibuf; 15944 15945 /* 15946 * Loop until no more fragments 15947 */ 15948 15949 while (trn_data < tdata->plaintext.len) { 15950 ++segs; 15951 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 15952 (tdata->plaintext.len - trn_data) : fragsz; 15953 15954 to_trn_tbl[ecx++] = to_trn; 15955 15956 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15957 buf = buf->next; 15958 15959 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 15960 rte_pktmbuf_tailroom(buf)); 15961 15962 /* OOP */ 15963 if (oop && !fragsz_oop) { 15964 buf_last_oop = buf_oop->next = 15965 rte_pktmbuf_alloc(ts_params->mbuf_pool); 15966 buf_oop = buf_oop->next; 15967 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 15968 0, rte_pktmbuf_tailroom(buf_oop)); 15969 rte_pktmbuf_append(buf_oop, to_trn); 15970 } 15971 15972 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 15973 to_trn); 15974 15975 memcpy(plaintext, tdata->plaintext.data + trn_data, 15976 to_trn); 15977 trn_data += to_trn; 15978 if (trn_data == tdata->plaintext.len) { 15979 if (oop) { 15980 if (!fragsz_oop) 15981 digest_mem = rte_pktmbuf_append(buf_oop, 15982 tdata->auth_tag.len); 15983 } else 15984 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 15985 tdata->auth_tag.len); 15986 } 15987 } 15988 15989 uint64_t digest_phys = 0; 15990 15991 ut_params->ibuf->nb_segs = segs; 15992 15993 segs = 1; 15994 if (fragsz_oop && oop) { 15995 to_trn = 0; 15996 ecx = 0; 15997 15998 if (frag_size_oop == tdata->plaintext.len) { 15999 digest_mem = rte_pktmbuf_append(ut_params->obuf, 16000 tdata->auth_tag.len); 16001 16002 digest_phys = rte_pktmbuf_iova_offset( 16003 ut_params->obuf, 16004 tdata->plaintext.len + prepend_len); 16005 } 16006 16007 trn_data = frag_size_oop; 16008 while (trn_data < tdata->plaintext.len) { 16009 ++segs; 16010 to_trn = 16011 (tdata->plaintext.len - trn_data < 16012 frag_size_oop) ? 16013 (tdata->plaintext.len - trn_data) : 16014 frag_size_oop; 16015 16016 to_trn_tbl[ecx++] = to_trn; 16017 16018 buf_last_oop = buf_oop->next = 16019 rte_pktmbuf_alloc(ts_params->mbuf_pool); 16020 buf_oop = buf_oop->next; 16021 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 16022 0, rte_pktmbuf_tailroom(buf_oop)); 16023 rte_pktmbuf_append(buf_oop, to_trn); 16024 16025 trn_data += to_trn; 16026 16027 if (trn_data == tdata->plaintext.len) { 16028 digest_mem = rte_pktmbuf_append(buf_oop, 16029 tdata->auth_tag.len); 16030 } 16031 } 16032 16033 ut_params->obuf->nb_segs = segs; 16034 } 16035 16036 /* 16037 * Place digest at the end of the last buffer 16038 */ 16039 if (!digest_phys) 16040 digest_phys = rte_pktmbuf_iova(buf) + to_trn; 16041 if (oop && buf_last_oop) 16042 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn; 16043 16044 if (!digest_mem && !oop) { 16045 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 16046 + tdata->auth_tag.len); 16047 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 16048 tdata->plaintext.len); 16049 } 16050 16051 /* Create AEAD operation */ 16052 retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT, 16053 tdata, digest_mem, digest_phys); 16054 16055 if (retval < 0) 16056 return retval; 16057 16058 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 16059 16060 ut_params->op->sym->m_src = ut_params->ibuf; 16061 if (oop) 16062 ut_params->op->sym->m_dst = ut_params->obuf; 16063 16064 /* Process crypto operation */ 16065 if (oop == IN_PLACE && 16066 gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 16067 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 16068 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 16069 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 16070 0); 16071 if (retval != TEST_SUCCESS) 16072 return retval; 16073 } else 16074 TEST_ASSERT_NOT_NULL( 16075 process_crypto_request(ts_params->valid_devs[0], 16076 ut_params->op), "failed to process sym crypto op"); 16077 16078 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 16079 "crypto op processing failed"); 16080 16081 16082 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 16083 uint8_t *, prepend_len); 16084 if (oop) { 16085 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 16086 uint8_t *, prepend_len); 16087 } 16088 16089 if (fragsz_oop) 16090 fragsz = fragsz_oop; 16091 16092 TEST_ASSERT_BUFFERS_ARE_EQUAL( 16093 ciphertext, 16094 tdata->ciphertext.data, 16095 fragsz, 16096 "Ciphertext data not as expected"); 16097 16098 buf = ut_params->op->sym->m_src->next; 16099 if (oop) 16100 buf = ut_params->op->sym->m_dst->next; 16101 16102 unsigned int off = fragsz; 16103 16104 ecx = 0; 16105 while (buf) { 16106 ciphertext = rte_pktmbuf_mtod(buf, 16107 uint8_t *); 16108 16109 TEST_ASSERT_BUFFERS_ARE_EQUAL( 16110 ciphertext, 16111 tdata->ciphertext.data + off, 16112 to_trn_tbl[ecx], 16113 "Ciphertext data not as expected"); 16114 16115 off += to_trn_tbl[ecx++]; 16116 buf = buf->next; 16117 } 16118 16119 auth_tag = digest_mem; 16120 TEST_ASSERT_BUFFERS_ARE_EQUAL( 16121 auth_tag, 16122 tdata->auth_tag.data, 16123 tdata->auth_tag.len, 16124 "Generated auth tag not as expected"); 16125 16126 return 0; 16127 } 16128 16129 static int 16130 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) 16131 { 16132 return test_authenticated_encryption_SGL( 16133 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400); 16134 } 16135 16136 static int 16137 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void) 16138 { 16139 return test_authenticated_encryption_SGL( 16140 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000); 16141 } 16142 16143 static int 16144 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void) 16145 { 16146 return test_authenticated_encryption_SGL( 16147 &gcm_test_case_8, OUT_OF_PLACE, 400, 16148 gcm_test_case_8.plaintext.len); 16149 } 16150 16151 static int 16152 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void) 16153 { 16154 /* This test is not for OPENSSL PMD */ 16155 if (gbl_driver_id == rte_cryptodev_driver_id_get( 16156 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) 16157 return TEST_SKIPPED; 16158 16159 return test_authenticated_encryption_SGL( 16160 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0); 16161 } 16162 16163 static int 16164 test_authentication_verify_fail_when_data_corrupted( 16165 struct crypto_testsuite_params *ts_params, 16166 struct crypto_unittest_params *ut_params, 16167 const struct test_crypto_vector *reference) 16168 { 16169 return test_authentication_verify_fail_when_data_corruption( 16170 ts_params, ut_params, reference, 1); 16171 } 16172 16173 static int 16174 test_authentication_verify_fail_when_tag_corrupted( 16175 struct crypto_testsuite_params *ts_params, 16176 struct crypto_unittest_params *ut_params, 16177 const struct test_crypto_vector *reference) 16178 { 16179 return test_authentication_verify_fail_when_data_corruption( 16180 ts_params, ut_params, reference, 0); 16181 } 16182 16183 static int 16184 test_authentication_verify_GMAC_fail_when_data_corrupted( 16185 struct crypto_testsuite_params *ts_params, 16186 struct crypto_unittest_params *ut_params, 16187 const struct test_crypto_vector *reference) 16188 { 16189 return test_authentication_verify_GMAC_fail_when_corruption( 16190 ts_params, ut_params, reference, 1); 16191 } 16192 16193 static int 16194 test_authentication_verify_GMAC_fail_when_tag_corrupted( 16195 struct crypto_testsuite_params *ts_params, 16196 struct crypto_unittest_params *ut_params, 16197 const struct test_crypto_vector *reference) 16198 { 16199 return test_authentication_verify_GMAC_fail_when_corruption( 16200 ts_params, ut_params, reference, 0); 16201 } 16202 16203 static int 16204 test_authenticated_decryption_fail_when_data_corrupted( 16205 struct crypto_testsuite_params *ts_params, 16206 struct crypto_unittest_params *ut_params, 16207 const struct test_crypto_vector *reference) 16208 { 16209 return test_authenticated_decryption_fail_when_corruption( 16210 ts_params, ut_params, reference, 1); 16211 } 16212 16213 static int 16214 test_authenticated_decryption_fail_when_tag_corrupted( 16215 struct crypto_testsuite_params *ts_params, 16216 struct crypto_unittest_params *ut_params, 16217 const struct test_crypto_vector *reference) 16218 { 16219 return test_authenticated_decryption_fail_when_corruption( 16220 ts_params, ut_params, reference, 0); 16221 } 16222 16223 static int 16224 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 16225 { 16226 return test_authentication_verify_fail_when_data_corrupted( 16227 &testsuite_params, &unittest_params, 16228 &hmac_sha1_test_crypto_vector); 16229 } 16230 16231 static int 16232 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 16233 { 16234 return test_authentication_verify_fail_when_tag_corrupted( 16235 &testsuite_params, &unittest_params, 16236 &hmac_sha1_test_crypto_vector); 16237 } 16238 16239 static int 16240 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 16241 { 16242 return test_authentication_verify_GMAC_fail_when_data_corrupted( 16243 &testsuite_params, &unittest_params, 16244 &aes128_gmac_test_vector); 16245 } 16246 16247 static int 16248 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 16249 { 16250 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 16251 &testsuite_params, &unittest_params, 16252 &aes128_gmac_test_vector); 16253 } 16254 16255 static int 16256 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 16257 { 16258 return test_authenticated_decryption_fail_when_data_corrupted( 16259 &testsuite_params, 16260 &unittest_params, 16261 &aes128cbc_hmac_sha1_test_vector); 16262 } 16263 16264 static int 16265 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 16266 { 16267 return test_authenticated_decryption_fail_when_tag_corrupted( 16268 &testsuite_params, 16269 &unittest_params, 16270 &aes128cbc_hmac_sha1_test_vector); 16271 } 16272 16273 static int 16274 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void) 16275 { 16276 return test_authenticated_encrypt_with_esn( 16277 &testsuite_params, 16278 &unittest_params, 16279 &aes128cbc_hmac_sha1_aad_test_vector); 16280 } 16281 16282 static int 16283 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void) 16284 { 16285 return test_authenticated_decrypt_with_esn( 16286 &testsuite_params, 16287 &unittest_params, 16288 &aes128cbc_hmac_sha1_aad_test_vector); 16289 } 16290 16291 static int 16292 test_chacha20_poly1305_encrypt_test_case_rfc8439(void) 16293 { 16294 return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439); 16295 } 16296 16297 static int 16298 test_chacha20_poly1305_decrypt_test_case_rfc8439(void) 16299 { 16300 return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439); 16301 } 16302 16303 static int 16304 test_chacha20_poly1305_encrypt_SGL_out_of_place(void) 16305 { 16306 return test_authenticated_encryption_SGL( 16307 &chacha20_poly1305_case_2, OUT_OF_PLACE, 32, 16308 chacha20_poly1305_case_2.plaintext.len); 16309 } 16310 16311 #ifdef RTE_CRYPTO_SCHEDULER 16312 16313 /* global AESNI worker IDs for the scheduler test */ 16314 uint8_t aesni_ids[2]; 16315 16316 static int 16317 scheduler_testsuite_setup(void) 16318 { 16319 uint32_t i = 0; 16320 int32_t nb_devs, ret; 16321 char vdev_args[VDEV_ARGS_SIZE] = {""}; 16322 char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core," 16323 "ordering=enable,name=cryptodev_test_scheduler,corelist="}; 16324 uint16_t worker_core_count = 0; 16325 uint16_t socket_id = 0; 16326 16327 if (gbl_driver_id == rte_cryptodev_driver_id_get( 16328 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) { 16329 16330 /* Identify the Worker Cores 16331 * Use 2 worker cores for the device args 16332 */ 16333 RTE_LCORE_FOREACH_WORKER(i) { 16334 if (worker_core_count > 1) 16335 break; 16336 snprintf(vdev_args, sizeof(vdev_args), 16337 "%s%d", temp_str, i); 16338 strcpy(temp_str, vdev_args); 16339 strlcat(temp_str, ";", sizeof(temp_str)); 16340 worker_core_count++; 16341 socket_id = rte_lcore_to_socket_id(i); 16342 } 16343 if (worker_core_count != 2) { 16344 RTE_LOG(ERR, USER1, 16345 "Cryptodev scheduler test require at least " 16346 "two worker cores to run. " 16347 "Please use the correct coremask.\n"); 16348 return TEST_FAILED; 16349 } 16350 strcpy(temp_str, vdev_args); 16351 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", 16352 temp_str, socket_id); 16353 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args); 16354 nb_devs = rte_cryptodev_device_count_by_driver( 16355 rte_cryptodev_driver_id_get( 16356 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))); 16357 if (nb_devs < 1) { 16358 ret = rte_vdev_init( 16359 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD), 16360 vdev_args); 16361 TEST_ASSERT(ret == 0, 16362 "Failed to create instance %u of pmd : %s", 16363 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 16364 } 16365 } 16366 return testsuite_setup(); 16367 } 16368 16369 static int 16370 test_scheduler_attach_worker_op(void) 16371 { 16372 struct crypto_testsuite_params *ts_params = &testsuite_params; 16373 uint8_t sched_id = ts_params->valid_devs[0]; 16374 uint32_t i, nb_devs_attached = 0; 16375 int ret; 16376 char vdev_name[32]; 16377 unsigned int count = rte_cryptodev_count(); 16378 16379 /* create 2 AESNI_MB vdevs on top of existing devices */ 16380 for (i = count; i < count + 2; i++) { 16381 snprintf(vdev_name, sizeof(vdev_name), "%s_%u", 16382 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), 16383 i); 16384 ret = rte_vdev_init(vdev_name, NULL); 16385 16386 TEST_ASSERT(ret == 0, 16387 "Failed to create instance %u of" 16388 " pmd : %s", 16389 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 16390 16391 if (ret < 0) { 16392 RTE_LOG(ERR, USER1, 16393 "Failed to create 2 AESNI MB PMDs.\n"); 16394 return TEST_SKIPPED; 16395 } 16396 } 16397 16398 /* attach 2 AESNI_MB cdevs */ 16399 for (i = count; i < count + 2; i++) { 16400 struct rte_cryptodev_info info; 16401 unsigned int session_size; 16402 16403 rte_cryptodev_info_get(i, &info); 16404 if (info.driver_id != rte_cryptodev_driver_id_get( 16405 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) 16406 continue; 16407 16408 session_size = rte_cryptodev_sym_get_private_session_size(i); 16409 /* 16410 * Create the session mempool again, since now there are new devices 16411 * to use the mempool. 16412 */ 16413 if (ts_params->session_mpool) { 16414 rte_mempool_free(ts_params->session_mpool); 16415 ts_params->session_mpool = NULL; 16416 } 16417 16418 if (info.sym.max_nb_sessions != 0 && 16419 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 16420 RTE_LOG(ERR, USER1, 16421 "Device does not support " 16422 "at least %u sessions\n", 16423 MAX_NB_SESSIONS); 16424 return TEST_FAILED; 16425 } 16426 /* 16427 * Create mempool with maximum number of sessions, 16428 * to include the session headers 16429 */ 16430 if (ts_params->session_mpool == NULL) { 16431 ts_params->session_mpool = 16432 rte_cryptodev_sym_session_pool_create( 16433 "test_sess_mp", 16434 MAX_NB_SESSIONS, session_size, 16435 0, 0, SOCKET_ID_ANY); 16436 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 16437 "session mempool allocation failed"); 16438 } 16439 16440 ts_params->qp_conf.mp_session = ts_params->session_mpool; 16441 16442 ret = rte_cryptodev_scheduler_worker_attach(sched_id, 16443 (uint8_t)i); 16444 16445 TEST_ASSERT(ret == 0, 16446 "Failed to attach device %u of pmd : %s", i, 16447 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 16448 16449 aesni_ids[nb_devs_attached] = (uint8_t)i; 16450 16451 nb_devs_attached++; 16452 } 16453 16454 return 0; 16455 } 16456 16457 static int 16458 test_scheduler_detach_worker_op(void) 16459 { 16460 struct crypto_testsuite_params *ts_params = &testsuite_params; 16461 uint8_t sched_id = ts_params->valid_devs[0]; 16462 uint32_t i; 16463 int ret; 16464 16465 for (i = 0; i < 2; i++) { 16466 ret = rte_cryptodev_scheduler_worker_detach(sched_id, 16467 aesni_ids[i]); 16468 TEST_ASSERT(ret == 0, 16469 "Failed to detach device %u", aesni_ids[i]); 16470 } 16471 16472 return 0; 16473 } 16474 16475 static int 16476 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode) 16477 { 16478 struct crypto_testsuite_params *ts_params = &testsuite_params; 16479 uint8_t sched_id = ts_params->valid_devs[0]; 16480 /* set mode */ 16481 return rte_cryptodev_scheduler_mode_set(sched_id, 16482 scheduler_mode); 16483 } 16484 16485 static int 16486 test_scheduler_mode_roundrobin_op(void) 16487 { 16488 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) == 16489 0, "Failed to set roundrobin mode"); 16490 return 0; 16491 16492 } 16493 16494 static int 16495 test_scheduler_mode_multicore_op(void) 16496 { 16497 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) == 16498 0, "Failed to set multicore mode"); 16499 16500 return 0; 16501 } 16502 16503 static int 16504 test_scheduler_mode_failover_op(void) 16505 { 16506 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) == 16507 0, "Failed to set failover mode"); 16508 16509 return 0; 16510 } 16511 16512 static int 16513 test_scheduler_mode_pkt_size_distr_op(void) 16514 { 16515 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) == 16516 0, "Failed to set pktsize mode"); 16517 16518 return 0; 16519 } 16520 16521 static int 16522 scheduler_multicore_testsuite_setup(void) 16523 { 16524 if (test_scheduler_attach_worker_op() < 0) 16525 return TEST_SKIPPED; 16526 if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0) 16527 return TEST_SKIPPED; 16528 return 0; 16529 } 16530 16531 static int 16532 scheduler_roundrobin_testsuite_setup(void) 16533 { 16534 if (test_scheduler_attach_worker_op() < 0) 16535 return TEST_SKIPPED; 16536 if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0) 16537 return TEST_SKIPPED; 16538 return 0; 16539 } 16540 16541 static int 16542 scheduler_failover_testsuite_setup(void) 16543 { 16544 if (test_scheduler_attach_worker_op() < 0) 16545 return TEST_SKIPPED; 16546 if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0) 16547 return TEST_SKIPPED; 16548 return 0; 16549 } 16550 16551 static int 16552 scheduler_pkt_size_distr_testsuite_setup(void) 16553 { 16554 if (test_scheduler_attach_worker_op() < 0) 16555 return TEST_SKIPPED; 16556 if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0) 16557 return TEST_SKIPPED; 16558 return 0; 16559 } 16560 16561 static void 16562 scheduler_mode_testsuite_teardown(void) 16563 { 16564 test_scheduler_detach_worker_op(); 16565 } 16566 16567 #endif /* RTE_CRYPTO_SCHEDULER */ 16568 16569 static struct unit_test_suite end_testsuite = { 16570 .suite_name = NULL, 16571 .setup = NULL, 16572 .teardown = NULL, 16573 .unit_test_suites = NULL 16574 }; 16575 16576 #ifdef RTE_LIB_SECURITY 16577 static struct unit_test_suite ipsec_proto_testsuite = { 16578 .suite_name = "IPsec Proto Unit Test Suite", 16579 .setup = ipsec_proto_testsuite_setup, 16580 .unit_test_cases = { 16581 TEST_CASE_NAMED_WITH_DATA( 16582 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 16583 ut_setup_security, ut_teardown, 16584 test_ipsec_proto_known_vec, &pkt_aes_128_gcm), 16585 TEST_CASE_NAMED_WITH_DATA( 16586 "Outbound known vector ext_mbuf mode (ESP tunnel mode IPv4 AES-GCM 128)", 16587 ut_setup_security, ut_teardown, 16588 test_ipsec_proto_known_vec_ext_mbuf, &pkt_aes_128_gcm), 16589 TEST_CASE_NAMED_WITH_DATA( 16590 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 16591 ut_setup_security, ut_teardown, 16592 test_ipsec_proto_known_vec, &pkt_aes_192_gcm), 16593 TEST_CASE_NAMED_WITH_DATA( 16594 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 16595 ut_setup_security, ut_teardown, 16596 test_ipsec_proto_known_vec, &pkt_aes_256_gcm), 16597 TEST_CASE_NAMED_WITH_DATA( 16598 "Outbound known vector (ESP tunnel mode IPv4 AES-CCM 256)", 16599 ut_setup_security, ut_teardown, 16600 test_ipsec_proto_known_vec, &pkt_aes_256_ccm), 16601 TEST_CASE_NAMED_WITH_DATA( 16602 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC MD5 [12B ICV])", 16603 ut_setup_security, ut_teardown, 16604 test_ipsec_proto_known_vec, 16605 &pkt_aes_128_cbc_md5), 16606 TEST_CASE_NAMED_WITH_DATA( 16607 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])", 16608 ut_setup_security, ut_teardown, 16609 test_ipsec_proto_known_vec, 16610 &pkt_aes_128_cbc_hmac_sha256), 16611 TEST_CASE_NAMED_WITH_DATA( 16612 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])", 16613 ut_setup_security, ut_teardown, 16614 test_ipsec_proto_known_vec, 16615 &pkt_aes_128_cbc_hmac_sha384), 16616 TEST_CASE_NAMED_WITH_DATA( 16617 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])", 16618 ut_setup_security, ut_teardown, 16619 test_ipsec_proto_known_vec, 16620 &pkt_aes_128_cbc_hmac_sha512), 16621 TEST_CASE_NAMED_WITH_DATA( 16622 "Outbound known vector (ESP tunnel mode IPv6 AES-GCM 128)", 16623 ut_setup_security, ut_teardown, 16624 test_ipsec_proto_known_vec, &pkt_aes_256_gcm_v6), 16625 TEST_CASE_NAMED_WITH_DATA( 16626 "Outbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])", 16627 ut_setup_security, ut_teardown, 16628 test_ipsec_proto_known_vec, 16629 &pkt_aes_128_cbc_hmac_sha256_v6), 16630 TEST_CASE_NAMED_WITH_DATA( 16631 "Outbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])", 16632 ut_setup_security, ut_teardown, 16633 test_ipsec_proto_known_vec, 16634 &pkt_null_aes_xcbc), 16635 TEST_CASE_NAMED_WITH_DATA( 16636 "Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA256 [16B ICV])", 16637 ut_setup_security, ut_teardown, 16638 test_ipsec_proto_known_vec, 16639 &pkt_des_cbc_hmac_sha256), 16640 TEST_CASE_NAMED_WITH_DATA( 16641 "Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA384 [24B ICV])", 16642 ut_setup_security, ut_teardown, 16643 test_ipsec_proto_known_vec, 16644 &pkt_des_cbc_hmac_sha384), 16645 TEST_CASE_NAMED_WITH_DATA( 16646 "Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA512 [32B ICV])", 16647 ut_setup_security, ut_teardown, 16648 test_ipsec_proto_known_vec, 16649 &pkt_des_cbc_hmac_sha512), 16650 TEST_CASE_NAMED_WITH_DATA( 16651 "Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA256 [16B ICV])", 16652 ut_setup_security, ut_teardown, 16653 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha256), 16654 TEST_CASE_NAMED_WITH_DATA( 16655 "Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA384 [24B ICV])", 16656 ut_setup_security, ut_teardown, 16657 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha384), 16658 TEST_CASE_NAMED_WITH_DATA( 16659 "Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA512 [32B ICV])", 16660 ut_setup_security, ut_teardown, 16661 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha512), 16662 TEST_CASE_NAMED_WITH_DATA( 16663 "Outbound known vector (ESP tunnel mode IPv6 DES-CBC HMAC-SHA256 [16B ICV])", 16664 ut_setup_security, ut_teardown, 16665 test_ipsec_proto_known_vec, 16666 &pkt_des_cbc_hmac_sha256_v6), 16667 TEST_CASE_NAMED_WITH_DATA( 16668 "Outbound known vector (ESP tunnel mode IPv6 3DES-CBC HMAC-SHA256 [16B ICV])", 16669 ut_setup_security, ut_teardown, 16670 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha256_v6), 16671 TEST_CASE_NAMED_WITH_DATA( 16672 "Outbound known vector (AH tunnel mode IPv4 HMAC-SHA256)", 16673 ut_setup_security, ut_teardown, 16674 test_ipsec_proto_known_vec, 16675 &pkt_ah_tunnel_sha256), 16676 TEST_CASE_NAMED_WITH_DATA( 16677 "Outbound known vector (AH transport mode IPv4 HMAC-SHA256)", 16678 ut_setup_security, ut_teardown, 16679 test_ipsec_proto_known_vec, 16680 &pkt_ah_transport_sha256), 16681 TEST_CASE_NAMED_WITH_DATA( 16682 "Outbound known vector (AH transport mode IPv4 AES-GMAC 128)", 16683 ut_setup_security, ut_teardown, 16684 test_ipsec_proto_known_vec, 16685 &pkt_ah_ipv4_aes_gmac_128), 16686 TEST_CASE_NAMED_WITH_DATA( 16687 "Outbound fragmented packet", 16688 ut_setup_security, ut_teardown, 16689 test_ipsec_proto_known_vec_fragmented, 16690 &pkt_aes_128_gcm_frag), 16691 TEST_CASE_NAMED_WITH_DATA( 16692 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 16693 ut_setup_security, ut_teardown, 16694 test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm), 16695 TEST_CASE_NAMED_WITH_DATA( 16696 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 16697 ut_setup_security, ut_teardown, 16698 test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm), 16699 TEST_CASE_NAMED_WITH_DATA( 16700 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 16701 ut_setup_security, ut_teardown, 16702 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm), 16703 TEST_CASE_NAMED_WITH_DATA( 16704 "Inbound known vector (ESP tunnel mode IPv4 AES-CCM 256)", 16705 ut_setup_security, ut_teardown, 16706 test_ipsec_proto_known_vec_inb, &pkt_aes_256_ccm), 16707 TEST_CASE_NAMED_WITH_DATA( 16708 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)", 16709 ut_setup_security, ut_teardown, 16710 test_ipsec_proto_known_vec_inb, &pkt_aes_128_cbc_null), 16711 TEST_CASE_NAMED_WITH_DATA( 16712 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC MD5 [12B ICV])", 16713 ut_setup_security, ut_teardown, 16714 test_ipsec_proto_known_vec_inb, 16715 &pkt_aes_128_cbc_md5), 16716 TEST_CASE_NAMED_WITH_DATA( 16717 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])", 16718 ut_setup_security, ut_teardown, 16719 test_ipsec_proto_known_vec_inb, 16720 &pkt_aes_128_cbc_hmac_sha256), 16721 TEST_CASE_NAMED_WITH_DATA( 16722 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])", 16723 ut_setup_security, ut_teardown, 16724 test_ipsec_proto_known_vec_inb, 16725 &pkt_aes_128_cbc_hmac_sha384), 16726 TEST_CASE_NAMED_WITH_DATA( 16727 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])", 16728 ut_setup_security, ut_teardown, 16729 test_ipsec_proto_known_vec_inb, 16730 &pkt_aes_128_cbc_hmac_sha512), 16731 TEST_CASE_NAMED_WITH_DATA( 16732 "Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)", 16733 ut_setup_security, ut_teardown, 16734 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm_v6), 16735 TEST_CASE_NAMED_WITH_DATA( 16736 "Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])", 16737 ut_setup_security, ut_teardown, 16738 test_ipsec_proto_known_vec_inb, 16739 &pkt_aes_128_cbc_hmac_sha256_v6), 16740 TEST_CASE_NAMED_WITH_DATA( 16741 "Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])", 16742 ut_setup_security, ut_teardown, 16743 test_ipsec_proto_known_vec_inb, 16744 &pkt_null_aes_xcbc), 16745 TEST_CASE_NAMED_WITH_DATA( 16746 "Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA256 [16B ICV])", 16747 ut_setup_security, ut_teardown, 16748 test_ipsec_proto_known_vec_inb, 16749 &pkt_des_cbc_hmac_sha256), 16750 TEST_CASE_NAMED_WITH_DATA( 16751 "Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA384 [24B ICV])", 16752 ut_setup_security, ut_teardown, 16753 test_ipsec_proto_known_vec_inb, 16754 &pkt_des_cbc_hmac_sha384), 16755 TEST_CASE_NAMED_WITH_DATA( 16756 "Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA512 [32B ICV])", 16757 ut_setup_security, ut_teardown, 16758 test_ipsec_proto_known_vec_inb, 16759 &pkt_des_cbc_hmac_sha512), 16760 TEST_CASE_NAMED_WITH_DATA( 16761 "Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA256 [16B ICV])", 16762 ut_setup_security, ut_teardown, 16763 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha256), 16764 TEST_CASE_NAMED_WITH_DATA( 16765 "Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA384 [24B ICV])", 16766 ut_setup_security, ut_teardown, 16767 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha384), 16768 TEST_CASE_NAMED_WITH_DATA( 16769 "Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA512 [32B ICV])", 16770 ut_setup_security, ut_teardown, 16771 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha512), 16772 TEST_CASE_NAMED_WITH_DATA( 16773 "Inbound known vector (ESP tunnel mode IPv6 DES-CBC HMAC-SHA256 [16B ICV])", 16774 ut_setup_security, ut_teardown, 16775 test_ipsec_proto_known_vec_inb, 16776 &pkt_des_cbc_hmac_sha256_v6), 16777 TEST_CASE_NAMED_WITH_DATA( 16778 "Inbound known vector (ESP tunnel mode IPv6 3DES-CBC HMAC-SHA256 [16B ICV])", 16779 ut_setup_security, ut_teardown, 16780 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha256_v6), 16781 TEST_CASE_NAMED_WITH_DATA( 16782 "Inbound known vector (AH tunnel mode IPv4 HMAC-SHA256)", 16783 ut_setup_security, ut_teardown, 16784 test_ipsec_proto_known_vec_inb, 16785 &pkt_ah_tunnel_sha256), 16786 TEST_CASE_NAMED_WITH_DATA( 16787 "Inbound known vector (AH transport mode IPv4 HMAC-SHA256)", 16788 ut_setup_security, ut_teardown, 16789 test_ipsec_proto_known_vec_inb, 16790 &pkt_ah_transport_sha256), 16791 TEST_CASE_NAMED_WITH_DATA( 16792 "Inbound known vector (AH transport mode IPv4 AES-GMAC 128)", 16793 ut_setup_security, ut_teardown, 16794 test_ipsec_proto_known_vec_inb, 16795 &pkt_ah_ipv4_aes_gmac_128), 16796 TEST_CASE_NAMED_ST( 16797 "Combined test alg list", 16798 ut_setup_security, ut_teardown, 16799 test_ipsec_proto_display_list), 16800 TEST_CASE_NAMED_ST( 16801 "Combined test alg list (AH)", 16802 ut_setup_security, ut_teardown, 16803 test_ipsec_proto_ah_tunnel_ipv4), 16804 TEST_CASE_NAMED_ST( 16805 "IV generation", 16806 ut_setup_security, ut_teardown, 16807 test_ipsec_proto_iv_gen), 16808 TEST_CASE_NAMED_ST( 16809 "UDP encapsulation", 16810 ut_setup_security, ut_teardown, 16811 test_ipsec_proto_udp_encap), 16812 TEST_CASE_NAMED_ST( 16813 "UDP encapsulation with custom ports", 16814 ut_setup_security, ut_teardown, 16815 test_ipsec_proto_udp_encap_custom_ports), 16816 TEST_CASE_NAMED_ST( 16817 "UDP encapsulation ports verification test", 16818 ut_setup_security, ut_teardown, 16819 test_ipsec_proto_udp_ports_verify), 16820 TEST_CASE_NAMED_ST( 16821 "SA expiry packets soft", 16822 ut_setup_security, ut_teardown, 16823 test_ipsec_proto_sa_exp_pkts_soft), 16824 TEST_CASE_NAMED_ST( 16825 "SA expiry packets hard", 16826 ut_setup_security, ut_teardown, 16827 test_ipsec_proto_sa_exp_pkts_hard), 16828 TEST_CASE_NAMED_ST( 16829 "Negative test: ICV corruption", 16830 ut_setup_security, ut_teardown, 16831 test_ipsec_proto_err_icv_corrupt), 16832 TEST_CASE_NAMED_ST( 16833 "Tunnel dst addr verification", 16834 ut_setup_security, ut_teardown, 16835 test_ipsec_proto_tunnel_dst_addr_verify), 16836 TEST_CASE_NAMED_ST( 16837 "Tunnel src and dst addr verification", 16838 ut_setup_security, ut_teardown, 16839 test_ipsec_proto_tunnel_src_dst_addr_verify), 16840 TEST_CASE_NAMED_ST( 16841 "Inner IP checksum", 16842 ut_setup_security, ut_teardown, 16843 test_ipsec_proto_inner_ip_csum), 16844 TEST_CASE_NAMED_ST( 16845 "Inner L4 checksum", 16846 ut_setup_security, ut_teardown, 16847 test_ipsec_proto_inner_l4_csum), 16848 TEST_CASE_NAMED_ST( 16849 "Tunnel IPv4 in IPv4", 16850 ut_setup_security, ut_teardown, 16851 test_ipsec_proto_tunnel_v4_in_v4), 16852 TEST_CASE_NAMED_ST( 16853 "Tunnel IPv6 in IPv6", 16854 ut_setup_security, ut_teardown, 16855 test_ipsec_proto_tunnel_v6_in_v6), 16856 TEST_CASE_NAMED_ST( 16857 "Tunnel IPv4 in IPv6", 16858 ut_setup_security, ut_teardown, 16859 test_ipsec_proto_tunnel_v4_in_v6), 16860 TEST_CASE_NAMED_ST( 16861 "Tunnel IPv6 in IPv4", 16862 ut_setup_security, ut_teardown, 16863 test_ipsec_proto_tunnel_v6_in_v4), 16864 TEST_CASE_NAMED_ST( 16865 "Transport IPv4", 16866 ut_setup_security, ut_teardown, 16867 test_ipsec_proto_transport_v4), 16868 TEST_CASE_NAMED_ST( 16869 "AH transport IPv4", 16870 ut_setup_security, ut_teardown, 16871 test_ipsec_proto_ah_transport_ipv4), 16872 TEST_CASE_NAMED_ST( 16873 "Transport l4 checksum", 16874 ut_setup_security, ut_teardown, 16875 test_ipsec_proto_transport_l4_csum), 16876 TEST_CASE_NAMED_ST( 16877 "Statistics: success", 16878 ut_setup_security, ut_teardown, 16879 test_ipsec_proto_stats), 16880 TEST_CASE_NAMED_ST( 16881 "Fragmented packet", 16882 ut_setup_security, ut_teardown, 16883 test_ipsec_proto_pkt_fragment), 16884 TEST_CASE_NAMED_ST( 16885 "Tunnel header copy DF (inner 0)", 16886 ut_setup_security, ut_teardown, 16887 test_ipsec_proto_copy_df_inner_0), 16888 TEST_CASE_NAMED_ST( 16889 "Tunnel header copy DF (inner 1)", 16890 ut_setup_security, ut_teardown, 16891 test_ipsec_proto_copy_df_inner_1), 16892 TEST_CASE_NAMED_ST( 16893 "Tunnel header set DF 0 (inner 1)", 16894 ut_setup_security, ut_teardown, 16895 test_ipsec_proto_set_df_0_inner_1), 16896 TEST_CASE_NAMED_ST( 16897 "Tunnel header set DF 1 (inner 0)", 16898 ut_setup_security, ut_teardown, 16899 test_ipsec_proto_set_df_1_inner_0), 16900 TEST_CASE_NAMED_ST( 16901 "Tunnel header IPv4 copy DSCP (inner 0)", 16902 ut_setup_security, ut_teardown, 16903 test_ipsec_proto_ipv4_copy_dscp_inner_0), 16904 TEST_CASE_NAMED_ST( 16905 "Tunnel header IPv4 copy DSCP (inner 1)", 16906 ut_setup_security, ut_teardown, 16907 test_ipsec_proto_ipv4_copy_dscp_inner_1), 16908 TEST_CASE_NAMED_ST( 16909 "Tunnel header IPv4 set DSCP 0 (inner 1)", 16910 ut_setup_security, ut_teardown, 16911 test_ipsec_proto_ipv4_set_dscp_0_inner_1), 16912 TEST_CASE_NAMED_ST( 16913 "Tunnel header IPv4 set DSCP 1 (inner 0)", 16914 ut_setup_security, ut_teardown, 16915 test_ipsec_proto_ipv4_set_dscp_1_inner_0), 16916 TEST_CASE_NAMED_ST( 16917 "Tunnel header IPv6 copy DSCP (inner 0)", 16918 ut_setup_security, ut_teardown, 16919 test_ipsec_proto_ipv6_copy_dscp_inner_0), 16920 TEST_CASE_NAMED_ST( 16921 "Tunnel header IPv6 copy DSCP (inner 1)", 16922 ut_setup_security, ut_teardown, 16923 test_ipsec_proto_ipv6_copy_dscp_inner_1), 16924 TEST_CASE_NAMED_ST( 16925 "Tunnel header IPv6 set DSCP 0 (inner 1)", 16926 ut_setup_security, ut_teardown, 16927 test_ipsec_proto_ipv6_set_dscp_0_inner_1), 16928 TEST_CASE_NAMED_ST( 16929 "Tunnel header IPv6 set DSCP 1 (inner 0)", 16930 ut_setup_security, ut_teardown, 16931 test_ipsec_proto_ipv6_set_dscp_1_inner_0), 16932 TEST_CASE_NAMED_WITH_DATA( 16933 "Antireplay with window size 1024", 16934 ut_setup_security, ut_teardown, 16935 test_ipsec_proto_pkt_antireplay1024, &pkt_aes_128_gcm), 16936 TEST_CASE_NAMED_WITH_DATA( 16937 "Antireplay with window size 2048", 16938 ut_setup_security, ut_teardown, 16939 test_ipsec_proto_pkt_antireplay2048, &pkt_aes_128_gcm), 16940 TEST_CASE_NAMED_WITH_DATA( 16941 "Antireplay with window size 4096", 16942 ut_setup_security, ut_teardown, 16943 test_ipsec_proto_pkt_antireplay4096, &pkt_aes_128_gcm), 16944 TEST_CASE_NAMED_WITH_DATA( 16945 "ESN and Antireplay with window size 1024", 16946 ut_setup_security, ut_teardown, 16947 test_ipsec_proto_pkt_esn_antireplay1024, 16948 &pkt_aes_128_gcm), 16949 TEST_CASE_NAMED_WITH_DATA( 16950 "ESN and Antireplay with window size 2048", 16951 ut_setup_security, ut_teardown, 16952 test_ipsec_proto_pkt_esn_antireplay2048, 16953 &pkt_aes_128_gcm), 16954 TEST_CASE_NAMED_WITH_DATA( 16955 "ESN and Antireplay with window size 4096", 16956 ut_setup_security, ut_teardown, 16957 test_ipsec_proto_pkt_esn_antireplay4096, 16958 &pkt_aes_128_gcm), 16959 TEST_CASE_NAMED_ST( 16960 "Tunnel header IPv4 decrement inner TTL", 16961 ut_setup_security, ut_teardown, 16962 test_ipsec_proto_ipv4_ttl_decrement), 16963 TEST_CASE_NAMED_ST( 16964 "Tunnel header IPv6 decrement inner hop limit", 16965 ut_setup_security, ut_teardown, 16966 test_ipsec_proto_ipv6_hop_limit_decrement), 16967 TEST_CASE_NAMED_ST( 16968 "Multi-segmented mode", 16969 ut_setup_security, ut_teardown, 16970 test_ipsec_proto_sgl), 16971 TEST_CASE_NAMED_ST( 16972 "Multi-segmented external mbuf mode", 16973 ut_setup_security, ut_teardown, 16974 test_ipsec_proto_sgl_ext_mbuf), 16975 TEST_CASE_NAMED_WITH_DATA( 16976 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128) Rx inject", 16977 ut_setup_security_rx_inject, ut_teardown_rx_inject, 16978 test_ipsec_proto_known_vec_inb_rx_inject, &pkt_aes_128_gcm), 16979 TEST_CASES_END() /**< NULL terminate unit test array */ 16980 } 16981 }; 16982 16983 static struct unit_test_suite pdcp_proto_testsuite = { 16984 .suite_name = "PDCP Proto Unit Test Suite", 16985 .setup = pdcp_proto_testsuite_setup, 16986 .unit_test_cases = { 16987 TEST_CASE_ST(ut_setup_security, ut_teardown, 16988 test_PDCP_PROTO_all), 16989 TEST_CASES_END() /**< NULL terminate unit test array */ 16990 } 16991 }; 16992 16993 static struct unit_test_suite tls12_record_proto_testsuite = { 16994 .suite_name = "TLS 1.2 Record Protocol Unit Test Suite", 16995 .setup = tls_record_proto_testsuite_setup, 16996 .unit_test_cases = { 16997 TEST_CASE_NAMED_WITH_DATA( 16998 "Write record known vector AES-GCM-128 (vector 1)", 16999 ut_setup_security, ut_teardown, 17000 test_tls_record_proto_known_vec, &tls_test_data_aes_128_gcm_v1), 17001 TEST_CASE_NAMED_WITH_DATA( 17002 "Write record known vector AES-GCM-128 (vector 2)", 17003 ut_setup_security, ut_teardown, 17004 test_tls_record_proto_known_vec, &tls_test_data_aes_128_gcm_v2), 17005 TEST_CASE_NAMED_WITH_DATA( 17006 "Write record known vector AES-GCM-256", 17007 ut_setup_security, ut_teardown, 17008 test_tls_record_proto_known_vec, &tls_test_data_aes_256_gcm), 17009 TEST_CASE_NAMED_WITH_DATA( 17010 "Write record known vector AES-CBC-128-SHA1", 17011 ut_setup_security, ut_teardown, 17012 test_tls_record_proto_known_vec, &tls_test_data_aes_128_cbc_sha1_hmac), 17013 TEST_CASE_NAMED_WITH_DATA( 17014 "Write record known vector AES-128-CBC-SHA256", 17015 ut_setup_security, ut_teardown, 17016 test_tls_record_proto_known_vec, &tls_test_data_aes_128_cbc_sha256_hmac), 17017 TEST_CASE_NAMED_WITH_DATA( 17018 "Write record known vector AES-256-CBC-SHA1", 17019 ut_setup_security, ut_teardown, 17020 test_tls_record_proto_known_vec, &tls_test_data_aes_256_cbc_sha1_hmac), 17021 TEST_CASE_NAMED_WITH_DATA( 17022 "Write record known vector AES-256-CBC-SHA256", 17023 ut_setup_security, ut_teardown, 17024 test_tls_record_proto_known_vec, &tls_test_data_aes_256_cbc_sha256_hmac), 17025 TEST_CASE_NAMED_WITH_DATA( 17026 "Write record known vector 3DES-CBC-SHA1-HMAC", 17027 ut_setup_security, ut_teardown, 17028 test_tls_record_proto_known_vec, &tls_test_data_3des_cbc_sha1_hmac), 17029 TEST_CASE_NAMED_WITH_DATA( 17030 "Write record known vector NULL-SHA1-HMAC", 17031 ut_setup_security, ut_teardown, 17032 test_tls_record_proto_known_vec, &tls_test_data_null_cipher_sha1_hmac), 17033 TEST_CASE_NAMED_WITH_DATA( 17034 "Write record known vector CHACHA20-POLY1305", 17035 ut_setup_security, ut_teardown, 17036 test_tls_record_proto_known_vec, &tls_test_data_chacha20_poly1305), 17037 17038 TEST_CASE_NAMED_WITH_DATA( 17039 "Read record known vector AES-GCM-128 (vector 1)", 17040 ut_setup_security, ut_teardown, 17041 test_tls_record_proto_known_vec_read, &tls_test_data_aes_128_gcm_v1), 17042 TEST_CASE_NAMED_WITH_DATA( 17043 "Read record known vector AES-GCM-128 (vector 2)", 17044 ut_setup_security, ut_teardown, 17045 test_tls_record_proto_known_vec_read, &tls_test_data_aes_128_gcm_v2), 17046 TEST_CASE_NAMED_WITH_DATA( 17047 "Read record known vector AES-GCM-256", 17048 ut_setup_security, ut_teardown, 17049 test_tls_record_proto_known_vec_read, &tls_test_data_aes_256_gcm), 17050 TEST_CASE_NAMED_WITH_DATA( 17051 "Read record known vector AES-128-CBC-SHA1", 17052 ut_setup_security, ut_teardown, 17053 test_tls_record_proto_known_vec_read, &tls_test_data_aes_128_cbc_sha1_hmac), 17054 TEST_CASE_NAMED_WITH_DATA( 17055 "Read record known vector AES-128-CBC-SHA256", 17056 ut_setup_security, ut_teardown, 17057 test_tls_record_proto_known_vec_read, 17058 &tls_test_data_aes_128_cbc_sha256_hmac), 17059 TEST_CASE_NAMED_WITH_DATA( 17060 "Read record known vector AES-256-CBC-SHA1", 17061 ut_setup_security, ut_teardown, 17062 test_tls_record_proto_known_vec_read, &tls_test_data_aes_256_cbc_sha1_hmac), 17063 TEST_CASE_NAMED_WITH_DATA( 17064 "Read record known vector AES-256-CBC-SHA256", 17065 ut_setup_security, ut_teardown, 17066 test_tls_record_proto_known_vec_read, 17067 &tls_test_data_aes_256_cbc_sha256_hmac), 17068 TEST_CASE_NAMED_WITH_DATA( 17069 "Read record known vector 3DES-CBC-SHA1-HMAC", 17070 ut_setup_security, ut_teardown, 17071 test_tls_record_proto_known_vec_read, &tls_test_data_3des_cbc_sha1_hmac), 17072 TEST_CASE_NAMED_WITH_DATA( 17073 "Read record known vector NULL-SHA1-HMAC", 17074 ut_setup_security, ut_teardown, 17075 test_tls_record_proto_known_vec_read, &tls_test_data_null_cipher_sha1_hmac), 17076 TEST_CASE_NAMED_WITH_DATA( 17077 "Read record known vector CHACHA20-POLY1305", 17078 ut_setup_security, ut_teardown, 17079 test_tls_record_proto_known_vec_read, &tls_test_data_chacha20_poly1305), 17080 17081 TEST_CASE_NAMED_ST( 17082 "Combined test alg list", 17083 ut_setup_security, ut_teardown, 17084 test_tls_record_proto_display_list), 17085 TEST_CASE_NAMED_ST( 17086 "Multi-segmented mode", 17087 ut_setup_security, ut_teardown, 17088 test_tls_record_proto_sgl), 17089 TEST_CASES_END() /**< NULL terminate unit test array */ 17090 } 17091 }; 17092 17093 static struct unit_test_suite dtls12_record_proto_testsuite = { 17094 .suite_name = "DTLS 1.2 Record Protocol Unit Test Suite", 17095 .setup = tls_record_proto_testsuite_setup, 17096 .unit_test_cases = { 17097 TEST_CASE_NAMED_WITH_DATA( 17098 "Write record known vector AES-GCM-128", 17099 ut_setup_security, ut_teardown, 17100 test_tls_record_proto_known_vec, &dtls_test_data_aes_128_gcm), 17101 TEST_CASE_NAMED_WITH_DATA( 17102 "Write record known vector AES-GCM-256", 17103 ut_setup_security, ut_teardown, 17104 test_tls_record_proto_known_vec, &dtls_test_data_aes_256_gcm), 17105 TEST_CASE_NAMED_WITH_DATA( 17106 "Write record known vector AES-128-CBC-SHA1", 17107 ut_setup_security, ut_teardown, 17108 test_tls_record_proto_known_vec, 17109 &dtls_test_data_aes_128_cbc_sha1_hmac), 17110 TEST_CASE_NAMED_WITH_DATA( 17111 "Write record known vector AES-128-CBC-SHA256", 17112 ut_setup_security, ut_teardown, 17113 test_tls_record_proto_known_vec, 17114 &dtls_test_data_aes_128_cbc_sha256_hmac), 17115 TEST_CASE_NAMED_WITH_DATA( 17116 "Write record known vector AES-256-CBC-SHA1", 17117 ut_setup_security, ut_teardown, 17118 test_tls_record_proto_known_vec, 17119 &dtls_test_data_aes_256_cbc_sha1_hmac), 17120 TEST_CASE_NAMED_WITH_DATA( 17121 "Write record known vector AES-256-CBC-SHA256", 17122 ut_setup_security, ut_teardown, 17123 test_tls_record_proto_known_vec, 17124 &dtls_test_data_aes_256_cbc_sha256_hmac), 17125 TEST_CASE_NAMED_WITH_DATA( 17126 "Write record known vector 3DES-CBC-SHA1-HMAC", 17127 ut_setup_security, ut_teardown, 17128 test_tls_record_proto_known_vec, 17129 &dtls_test_data_3des_cbc_sha1_hmac), 17130 TEST_CASE_NAMED_WITH_DATA( 17131 "Write record known vector NULL-SHA1-HMAC", 17132 ut_setup_security, ut_teardown, 17133 test_tls_record_proto_known_vec, 17134 &dtls_test_data_null_cipher_sha1_hmac), 17135 TEST_CASE_NAMED_WITH_DATA( 17136 "Write record known vector CHACHA20-POLY1305", 17137 ut_setup_security, ut_teardown, 17138 test_tls_record_proto_known_vec, &dtls_test_data_chacha20_poly1305), 17139 TEST_CASE_NAMED_WITH_DATA( 17140 "Read record known vector AES-GCM-128", 17141 ut_setup_security, ut_teardown, 17142 test_tls_record_proto_known_vec_read, &dtls_test_data_aes_128_gcm), 17143 TEST_CASE_NAMED_WITH_DATA( 17144 "Read record known vector AES-GCM-256", 17145 ut_setup_security, ut_teardown, 17146 test_tls_record_proto_known_vec_read, &dtls_test_data_aes_256_gcm), 17147 TEST_CASE_NAMED_WITH_DATA( 17148 "Read record known vector AES-128-CBC-SHA1", 17149 ut_setup_security, ut_teardown, 17150 test_tls_record_proto_known_vec_read, 17151 &dtls_test_data_aes_128_cbc_sha1_hmac), 17152 TEST_CASE_NAMED_WITH_DATA( 17153 "Read record known vector AES-128-CBC-SHA256", 17154 ut_setup_security, ut_teardown, 17155 test_tls_record_proto_known_vec_read, 17156 &dtls_test_data_aes_128_cbc_sha256_hmac), 17157 TEST_CASE_NAMED_WITH_DATA( 17158 "Read record known vector AES-256-CBC-SHA1", 17159 ut_setup_security, ut_teardown, 17160 test_tls_record_proto_known_vec_read, 17161 &dtls_test_data_aes_256_cbc_sha1_hmac), 17162 TEST_CASE_NAMED_WITH_DATA( 17163 "Read record known vector AES-256-CBC-SHA256", 17164 ut_setup_security, ut_teardown, 17165 test_tls_record_proto_known_vec_read, 17166 &dtls_test_data_aes_256_cbc_sha256_hmac), 17167 TEST_CASE_NAMED_WITH_DATA( 17168 "Read record known vector 3DES-CBC-SHA1-HMAC", 17169 ut_setup_security, ut_teardown, 17170 test_tls_record_proto_known_vec_read, 17171 &dtls_test_data_3des_cbc_sha1_hmac), 17172 TEST_CASE_NAMED_WITH_DATA( 17173 "Read record known vector NULL-SHA1-HMAC", 17174 ut_setup_security, ut_teardown, 17175 test_tls_record_proto_known_vec_read, 17176 &dtls_test_data_null_cipher_sha1_hmac), 17177 TEST_CASE_NAMED_WITH_DATA( 17178 "Read record known vector CHACHA20-POLY1305", 17179 ut_setup_security, ut_teardown, 17180 test_tls_record_proto_known_vec_read, &dtls_test_data_chacha20_poly1305), 17181 17182 TEST_CASE_NAMED_ST( 17183 "Combined test alg list", 17184 ut_setup_security, ut_teardown, 17185 test_tls_record_proto_display_list), 17186 TEST_CASE_NAMED_ST( 17187 "Multi-segmented mode", 17188 ut_setup_security, ut_teardown, 17189 test_tls_record_proto_sgl), 17190 TEST_CASES_END() /**< NULL terminate unit test array */ 17191 } 17192 }; 17193 17194 #define ADD_UPLINK_TESTCASE(data) \ 17195 TEST_CASE_NAMED_WITH_DATA(data.test_descr_uplink, ut_setup_security, \ 17196 ut_teardown, test_docsis_proto_uplink, (const void *) &data), \ 17197 17198 #define ADD_DOWNLINK_TESTCASE(data) \ 17199 TEST_CASE_NAMED_WITH_DATA(data.test_descr_downlink, ut_setup_security, \ 17200 ut_teardown, test_docsis_proto_downlink, (const void *) &data), \ 17201 17202 static struct unit_test_suite docsis_proto_testsuite = { 17203 .suite_name = "DOCSIS Proto Unit Test Suite", 17204 .setup = docsis_proto_testsuite_setup, 17205 .unit_test_cases = { 17206 /* Uplink */ 17207 ADD_UPLINK_TESTCASE(docsis_test_case_1) 17208 ADD_UPLINK_TESTCASE(docsis_test_case_2) 17209 ADD_UPLINK_TESTCASE(docsis_test_case_3) 17210 ADD_UPLINK_TESTCASE(docsis_test_case_4) 17211 ADD_UPLINK_TESTCASE(docsis_test_case_5) 17212 ADD_UPLINK_TESTCASE(docsis_test_case_6) 17213 ADD_UPLINK_TESTCASE(docsis_test_case_7) 17214 ADD_UPLINK_TESTCASE(docsis_test_case_8) 17215 ADD_UPLINK_TESTCASE(docsis_test_case_9) 17216 ADD_UPLINK_TESTCASE(docsis_test_case_10) 17217 ADD_UPLINK_TESTCASE(docsis_test_case_11) 17218 ADD_UPLINK_TESTCASE(docsis_test_case_12) 17219 ADD_UPLINK_TESTCASE(docsis_test_case_13) 17220 ADD_UPLINK_TESTCASE(docsis_test_case_14) 17221 ADD_UPLINK_TESTCASE(docsis_test_case_15) 17222 ADD_UPLINK_TESTCASE(docsis_test_case_16) 17223 ADD_UPLINK_TESTCASE(docsis_test_case_17) 17224 ADD_UPLINK_TESTCASE(docsis_test_case_18) 17225 ADD_UPLINK_TESTCASE(docsis_test_case_19) 17226 ADD_UPLINK_TESTCASE(docsis_test_case_20) 17227 ADD_UPLINK_TESTCASE(docsis_test_case_21) 17228 ADD_UPLINK_TESTCASE(docsis_test_case_22) 17229 ADD_UPLINK_TESTCASE(docsis_test_case_23) 17230 ADD_UPLINK_TESTCASE(docsis_test_case_24) 17231 ADD_UPLINK_TESTCASE(docsis_test_case_25) 17232 ADD_UPLINK_TESTCASE(docsis_test_case_26) 17233 /* Downlink */ 17234 ADD_DOWNLINK_TESTCASE(docsis_test_case_1) 17235 ADD_DOWNLINK_TESTCASE(docsis_test_case_2) 17236 ADD_DOWNLINK_TESTCASE(docsis_test_case_3) 17237 ADD_DOWNLINK_TESTCASE(docsis_test_case_4) 17238 ADD_DOWNLINK_TESTCASE(docsis_test_case_5) 17239 ADD_DOWNLINK_TESTCASE(docsis_test_case_6) 17240 ADD_DOWNLINK_TESTCASE(docsis_test_case_7) 17241 ADD_DOWNLINK_TESTCASE(docsis_test_case_8) 17242 ADD_DOWNLINK_TESTCASE(docsis_test_case_9) 17243 ADD_DOWNLINK_TESTCASE(docsis_test_case_10) 17244 ADD_DOWNLINK_TESTCASE(docsis_test_case_11) 17245 ADD_DOWNLINK_TESTCASE(docsis_test_case_12) 17246 ADD_DOWNLINK_TESTCASE(docsis_test_case_13) 17247 ADD_DOWNLINK_TESTCASE(docsis_test_case_14) 17248 ADD_DOWNLINK_TESTCASE(docsis_test_case_15) 17249 ADD_DOWNLINK_TESTCASE(docsis_test_case_16) 17250 ADD_DOWNLINK_TESTCASE(docsis_test_case_17) 17251 ADD_DOWNLINK_TESTCASE(docsis_test_case_18) 17252 ADD_DOWNLINK_TESTCASE(docsis_test_case_19) 17253 ADD_DOWNLINK_TESTCASE(docsis_test_case_20) 17254 ADD_DOWNLINK_TESTCASE(docsis_test_case_21) 17255 ADD_DOWNLINK_TESTCASE(docsis_test_case_22) 17256 ADD_DOWNLINK_TESTCASE(docsis_test_case_23) 17257 ADD_DOWNLINK_TESTCASE(docsis_test_case_24) 17258 ADD_DOWNLINK_TESTCASE(docsis_test_case_25) 17259 ADD_DOWNLINK_TESTCASE(docsis_test_case_26) 17260 TEST_CASES_END() /**< NULL terminate unit test array */ 17261 } 17262 }; 17263 #endif 17264 17265 static struct unit_test_suite cryptodev_gen_testsuite = { 17266 .suite_name = "Crypto General Unit Test Suite", 17267 .setup = crypto_gen_testsuite_setup, 17268 .unit_test_cases = { 17269 TEST_CASE_ST(ut_setup, ut_teardown, 17270 test_device_reconfigure), 17271 TEST_CASE_ST(ut_setup, ut_teardown, 17272 test_device_configure_invalid_dev_id), 17273 TEST_CASE_ST(ut_setup, ut_teardown, 17274 test_queue_pair_descriptor_setup), 17275 TEST_CASE_ST(ut_setup, ut_teardown, 17276 test_device_configure_invalid_queue_pair_ids), 17277 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 17278 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup), 17279 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup), 17280 TEST_CASES_END() /**< NULL terminate unit test array */ 17281 } 17282 }; 17283 17284 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = { 17285 .suite_name = "Negative HMAC SHA1 Unit Test Suite", 17286 .setup = negative_hmac_sha1_testsuite_setup, 17287 .unit_test_cases = { 17288 /** Negative tests */ 17289 TEST_CASE_ST(ut_setup, ut_teardown, 17290 authentication_verify_HMAC_SHA1_fail_data_corrupt), 17291 TEST_CASE_ST(ut_setup, ut_teardown, 17292 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 17293 TEST_CASE_ST(ut_setup, ut_teardown, 17294 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 17295 TEST_CASE_ST(ut_setup, ut_teardown, 17296 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 17297 17298 TEST_CASES_END() /**< NULL terminate unit test array */ 17299 } 17300 }; 17301 17302 static struct unit_test_suite cryptodev_multi_session_testsuite = { 17303 .suite_name = "Multi Session Unit Test Suite", 17304 .setup = multi_session_testsuite_setup, 17305 .unit_test_cases = { 17306 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 17307 TEST_CASE_ST(ut_setup, ut_teardown, 17308 test_multi_session_random_usage), 17309 17310 TEST_CASES_END() /**< NULL terminate unit test array */ 17311 } 17312 }; 17313 17314 static struct unit_test_suite cryptodev_null_testsuite = { 17315 .suite_name = "NULL Test Suite", 17316 .setup = null_testsuite_setup, 17317 .unit_test_cases = { 17318 TEST_CASE_ST(ut_setup, ut_teardown, 17319 test_null_invalid_operation), 17320 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation), 17321 TEST_CASES_END() 17322 } 17323 }; 17324 17325 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite = { 17326 .suite_name = "AES CCM Authenticated Test Suite", 17327 .setup = aes_ccm_auth_testsuite_setup, 17328 .unit_test_cases = { 17329 /** AES CCM Authenticated Encryption 128 bits key*/ 17330 TEST_CASE_ST(ut_setup, ut_teardown, 17331 test_AES_CCM_authenticated_encryption_test_case_128_1), 17332 TEST_CASE_ST(ut_setup, ut_teardown, 17333 test_AES_CCM_authenticated_encryption_test_case_128_2), 17334 TEST_CASE_ST(ut_setup, ut_teardown, 17335 test_AES_CCM_authenticated_encryption_test_case_128_3), 17336 17337 /** AES CCM Authenticated Decryption 128 bits key*/ 17338 TEST_CASE_ST(ut_setup, ut_teardown, 17339 test_AES_CCM_authenticated_decryption_test_case_128_1), 17340 TEST_CASE_ST(ut_setup, ut_teardown, 17341 test_AES_CCM_authenticated_decryption_test_case_128_2), 17342 TEST_CASE_ST(ut_setup, ut_teardown, 17343 test_AES_CCM_authenticated_decryption_test_case_128_3), 17344 17345 /** AES CCM Authenticated Encryption 192 bits key */ 17346 TEST_CASE_ST(ut_setup, ut_teardown, 17347 test_AES_CCM_authenticated_encryption_test_case_192_1), 17348 TEST_CASE_ST(ut_setup, ut_teardown, 17349 test_AES_CCM_authenticated_encryption_test_case_192_2), 17350 TEST_CASE_ST(ut_setup, ut_teardown, 17351 test_AES_CCM_authenticated_encryption_test_case_192_3), 17352 17353 /** AES CCM Authenticated Decryption 192 bits key*/ 17354 TEST_CASE_ST(ut_setup, ut_teardown, 17355 test_AES_CCM_authenticated_decryption_test_case_192_1), 17356 TEST_CASE_ST(ut_setup, ut_teardown, 17357 test_AES_CCM_authenticated_decryption_test_case_192_2), 17358 TEST_CASE_ST(ut_setup, ut_teardown, 17359 test_AES_CCM_authenticated_decryption_test_case_192_3), 17360 17361 /** AES CCM Authenticated Encryption 256 bits key */ 17362 TEST_CASE_ST(ut_setup, ut_teardown, 17363 test_AES_CCM_authenticated_encryption_test_case_256_1), 17364 TEST_CASE_ST(ut_setup, ut_teardown, 17365 test_AES_CCM_authenticated_encryption_test_case_256_2), 17366 TEST_CASE_ST(ut_setup, ut_teardown, 17367 test_AES_CCM_authenticated_encryption_test_case_256_3), 17368 17369 /** AES CCM Authenticated Decryption 256 bits key*/ 17370 TEST_CASE_ST(ut_setup, ut_teardown, 17371 test_AES_CCM_authenticated_decryption_test_case_256_1), 17372 TEST_CASE_ST(ut_setup, ut_teardown, 17373 test_AES_CCM_authenticated_decryption_test_case_256_2), 17374 TEST_CASE_ST(ut_setup, ut_teardown, 17375 test_AES_CCM_authenticated_decryption_test_case_256_3), 17376 TEST_CASES_END() 17377 } 17378 }; 17379 17380 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite = { 17381 .suite_name = "AES GCM Authenticated Test Suite", 17382 .setup = aes_gcm_auth_testsuite_setup, 17383 .unit_test_cases = { 17384 /** AES GCM Authenticated Encryption */ 17385 TEST_CASE_ST(ut_setup, ut_teardown, 17386 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 17387 TEST_CASE_ST(ut_setup, ut_teardown, 17388 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 17389 TEST_CASE_ST(ut_setup, ut_teardown, 17390 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 17391 TEST_CASE_ST(ut_setup, ut_teardown, 17392 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 17393 TEST_CASE_ST(ut_setup, ut_teardown, 17394 test_AES_GCM_authenticated_encryption_test_case_1), 17395 TEST_CASE_ST(ut_setup, ut_teardown, 17396 test_AES_GCM_authenticated_encryption_test_case_2), 17397 TEST_CASE_ST(ut_setup, ut_teardown, 17398 test_AES_GCM_authenticated_encryption_test_case_3), 17399 TEST_CASE_ST(ut_setup, ut_teardown, 17400 test_AES_GCM_authenticated_encryption_test_case_4), 17401 TEST_CASE_ST(ut_setup, ut_teardown, 17402 test_AES_GCM_authenticated_encryption_test_case_5), 17403 TEST_CASE_ST(ut_setup, ut_teardown, 17404 test_AES_GCM_authenticated_encryption_test_case_6), 17405 TEST_CASE_ST(ut_setup, ut_teardown, 17406 test_AES_GCM_authenticated_encryption_test_case_7), 17407 TEST_CASE_ST(ut_setup, ut_teardown, 17408 test_AES_GCM_authenticated_encryption_test_case_8), 17409 TEST_CASE_ST(ut_setup, ut_teardown, 17410 test_AES_GCM_J0_authenticated_encryption_test_case_1), 17411 17412 /** AES GCM Authenticated Decryption */ 17413 TEST_CASE_ST(ut_setup, ut_teardown, 17414 test_AES_GCM_authenticated_decryption_test_case_1), 17415 TEST_CASE_ST(ut_setup, ut_teardown, 17416 test_AES_GCM_authenticated_decryption_test_case_2), 17417 TEST_CASE_ST(ut_setup, ut_teardown, 17418 test_AES_GCM_authenticated_decryption_test_case_3), 17419 TEST_CASE_ST(ut_setup, ut_teardown, 17420 test_AES_GCM_authenticated_decryption_test_case_4), 17421 TEST_CASE_ST(ut_setup, ut_teardown, 17422 test_AES_GCM_authenticated_decryption_test_case_5), 17423 TEST_CASE_ST(ut_setup, ut_teardown, 17424 test_AES_GCM_authenticated_decryption_test_case_6), 17425 TEST_CASE_ST(ut_setup, ut_teardown, 17426 test_AES_GCM_authenticated_decryption_test_case_7), 17427 TEST_CASE_ST(ut_setup, ut_teardown, 17428 test_AES_GCM_authenticated_decryption_test_case_8), 17429 TEST_CASE_ST(ut_setup, ut_teardown, 17430 test_AES_GCM_J0_authenticated_decryption_test_case_1), 17431 17432 /** AES GCM Authenticated Encryption 192 bits key */ 17433 TEST_CASE_ST(ut_setup, ut_teardown, 17434 test_AES_GCM_auth_encryption_test_case_192_1), 17435 TEST_CASE_ST(ut_setup, ut_teardown, 17436 test_AES_GCM_auth_encryption_test_case_192_2), 17437 TEST_CASE_ST(ut_setup, ut_teardown, 17438 test_AES_GCM_auth_encryption_test_case_192_3), 17439 TEST_CASE_ST(ut_setup, ut_teardown, 17440 test_AES_GCM_auth_encryption_test_case_192_4), 17441 TEST_CASE_ST(ut_setup, ut_teardown, 17442 test_AES_GCM_auth_encryption_test_case_192_5), 17443 TEST_CASE_ST(ut_setup, ut_teardown, 17444 test_AES_GCM_auth_encryption_test_case_192_6), 17445 TEST_CASE_ST(ut_setup, ut_teardown, 17446 test_AES_GCM_auth_encryption_test_case_192_7), 17447 17448 /** AES GCM Authenticated Decryption 192 bits key */ 17449 TEST_CASE_ST(ut_setup, ut_teardown, 17450 test_AES_GCM_auth_decryption_test_case_192_1), 17451 TEST_CASE_ST(ut_setup, ut_teardown, 17452 test_AES_GCM_auth_decryption_test_case_192_2), 17453 TEST_CASE_ST(ut_setup, ut_teardown, 17454 test_AES_GCM_auth_decryption_test_case_192_3), 17455 TEST_CASE_ST(ut_setup, ut_teardown, 17456 test_AES_GCM_auth_decryption_test_case_192_4), 17457 TEST_CASE_ST(ut_setup, ut_teardown, 17458 test_AES_GCM_auth_decryption_test_case_192_5), 17459 TEST_CASE_ST(ut_setup, ut_teardown, 17460 test_AES_GCM_auth_decryption_test_case_192_6), 17461 TEST_CASE_ST(ut_setup, ut_teardown, 17462 test_AES_GCM_auth_decryption_test_case_192_7), 17463 17464 /** AES GCM Authenticated Encryption 256 bits key */ 17465 TEST_CASE_ST(ut_setup, ut_teardown, 17466 test_AES_GCM_auth_encryption_test_case_256_1), 17467 TEST_CASE_ST(ut_setup, ut_teardown, 17468 test_AES_GCM_auth_encryption_test_case_256_2), 17469 TEST_CASE_ST(ut_setup, ut_teardown, 17470 test_AES_GCM_auth_encryption_test_case_256_3), 17471 TEST_CASE_ST(ut_setup, ut_teardown, 17472 test_AES_GCM_auth_encryption_test_case_256_4), 17473 TEST_CASE_ST(ut_setup, ut_teardown, 17474 test_AES_GCM_auth_encryption_test_case_256_5), 17475 TEST_CASE_ST(ut_setup, ut_teardown, 17476 test_AES_GCM_auth_encryption_test_case_256_6), 17477 TEST_CASE_ST(ut_setup, ut_teardown, 17478 test_AES_GCM_auth_encryption_test_case_256_7), 17479 TEST_CASE_ST(ut_setup, ut_teardown, 17480 test_AES_GCM_auth_encryption_test_case_256_8), 17481 17482 /** AES GCM Authenticated Decryption 256 bits key */ 17483 TEST_CASE_ST(ut_setup, ut_teardown, 17484 test_AES_GCM_auth_decryption_test_case_256_1), 17485 TEST_CASE_ST(ut_setup, ut_teardown, 17486 test_AES_GCM_auth_decryption_test_case_256_2), 17487 TEST_CASE_ST(ut_setup, ut_teardown, 17488 test_AES_GCM_auth_decryption_test_case_256_3), 17489 TEST_CASE_ST(ut_setup, ut_teardown, 17490 test_AES_GCM_auth_decryption_test_case_256_4), 17491 TEST_CASE_ST(ut_setup, ut_teardown, 17492 test_AES_GCM_auth_decryption_test_case_256_5), 17493 TEST_CASE_ST(ut_setup, ut_teardown, 17494 test_AES_GCM_auth_decryption_test_case_256_6), 17495 TEST_CASE_ST(ut_setup, ut_teardown, 17496 test_AES_GCM_auth_decryption_test_case_256_7), 17497 TEST_CASE_ST(ut_setup, ut_teardown, 17498 test_AES_GCM_auth_decryption_test_case_256_8), 17499 17500 /** AES GCM Authenticated Encryption big aad size */ 17501 TEST_CASE_ST(ut_setup, ut_teardown, 17502 test_AES_GCM_auth_encryption_test_case_aad_1), 17503 TEST_CASE_ST(ut_setup, ut_teardown, 17504 test_AES_GCM_auth_encryption_test_case_aad_2), 17505 17506 /** AES GCM Authenticated Decryption big aad size */ 17507 TEST_CASE_ST(ut_setup, ut_teardown, 17508 test_AES_GCM_auth_decryption_test_case_aad_1), 17509 TEST_CASE_ST(ut_setup, ut_teardown, 17510 test_AES_GCM_auth_decryption_test_case_aad_2), 17511 17512 /** Out of place tests */ 17513 TEST_CASE_ST(ut_setup, ut_teardown, 17514 test_AES_GCM_authenticated_encryption_oop_test_case_1), 17515 TEST_CASE_ST(ut_setup, ut_teardown, 17516 test_AES_GCM_authenticated_decryption_oop_test_case_1), 17517 17518 /** Session-less tests */ 17519 TEST_CASE_ST(ut_setup, ut_teardown, 17520 test_AES_GCM_authenticated_encryption_sessionless_test_case_1), 17521 TEST_CASE_ST(ut_setup, ut_teardown, 17522 test_AES_GCM_authenticated_decryption_sessionless_test_case_1), 17523 17524 /** AES GCM external mbuf tests */ 17525 TEST_CASE_ST(ut_setup, ut_teardown, 17526 test_AES_GCM_authenticated_encryption_test_case_3_ext_mbuf), 17527 TEST_CASE_ST(ut_setup, ut_teardown, 17528 test_AES_GCM_authenticated_decryption_test_case_3_ext_mbuf), 17529 17530 TEST_CASES_END() 17531 } 17532 }; 17533 17534 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite = { 17535 .suite_name = "AES GMAC Authentication Test Suite", 17536 .setup = aes_gmac_auth_testsuite_setup, 17537 .unit_test_cases = { 17538 TEST_CASE_ST(ut_setup, ut_teardown, 17539 test_AES_GMAC_authentication_test_case_1), 17540 TEST_CASE_ST(ut_setup, ut_teardown, 17541 test_AES_GMAC_authentication_verify_test_case_1), 17542 TEST_CASE_ST(ut_setup, ut_teardown, 17543 test_AES_GMAC_authentication_test_case_2), 17544 TEST_CASE_ST(ut_setup, ut_teardown, 17545 test_AES_GMAC_authentication_verify_test_case_2), 17546 TEST_CASE_ST(ut_setup, ut_teardown, 17547 test_AES_GMAC_authentication_test_case_3), 17548 TEST_CASE_ST(ut_setup, ut_teardown, 17549 test_AES_GMAC_authentication_verify_test_case_3), 17550 TEST_CASE_ST(ut_setup, ut_teardown, 17551 test_AES_GMAC_authentication_test_case_4), 17552 TEST_CASE_ST(ut_setup, ut_teardown, 17553 test_AES_GMAC_authentication_verify_test_case_4), 17554 TEST_CASE_ST(ut_setup, ut_teardown, 17555 test_AES_GMAC_authentication_SGL_40B), 17556 TEST_CASE_ST(ut_setup, ut_teardown, 17557 test_AES_GMAC_authentication_SGL_80B), 17558 TEST_CASE_ST(ut_setup, ut_teardown, 17559 test_AES_GMAC_authentication_SGL_2048B), 17560 TEST_CASE_ST(ut_setup, ut_teardown, 17561 test_AES_GMAC_authentication_SGL_2047B), 17562 17563 TEST_CASES_END() 17564 } 17565 }; 17566 17567 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite = { 17568 .suite_name = "Chacha20-Poly1305 Test Suite", 17569 .setup = chacha20_poly1305_testsuite_setup, 17570 .unit_test_cases = { 17571 TEST_CASE_ST(ut_setup, ut_teardown, 17572 test_chacha20_poly1305_encrypt_test_case_rfc8439), 17573 TEST_CASE_ST(ut_setup, ut_teardown, 17574 test_chacha20_poly1305_decrypt_test_case_rfc8439), 17575 TEST_CASE_ST(ut_setup, ut_teardown, 17576 test_chacha20_poly1305_encrypt_SGL_out_of_place), 17577 TEST_CASES_END() 17578 } 17579 }; 17580 17581 static struct unit_test_suite cryptodev_snow3g_testsuite = { 17582 .suite_name = "SNOW 3G Test Suite", 17583 .setup = snow3g_testsuite_setup, 17584 .unit_test_cases = { 17585 /** SNOW 3G encrypt only (UEA2) */ 17586 TEST_CASE_ST(ut_setup, ut_teardown, 17587 test_snow3g_encryption_test_case_1), 17588 TEST_CASE_ST(ut_setup, ut_teardown, 17589 test_snow3g_encryption_test_case_2), 17590 TEST_CASE_ST(ut_setup, ut_teardown, 17591 test_snow3g_encryption_test_case_3), 17592 TEST_CASE_ST(ut_setup, ut_teardown, 17593 test_snow3g_encryption_test_case_4), 17594 TEST_CASE_ST(ut_setup, ut_teardown, 17595 test_snow3g_encryption_test_case_5), 17596 17597 TEST_CASE_ST(ut_setup, ut_teardown, 17598 test_snow3g_encryption_test_case_1_oop), 17599 TEST_CASE_ST(ut_setup, ut_teardown, 17600 test_snow3g_encryption_test_case_1_oop_sgl), 17601 TEST_CASE_ST(ut_setup, ut_teardown, 17602 test_snow3g_encryption_test_case_1_oop_lb_in_sgl_out), 17603 TEST_CASE_ST(ut_setup, ut_teardown, 17604 test_snow3g_encryption_test_case_1_oop_sgl_in_lb_out), 17605 TEST_CASE_ST(ut_setup, ut_teardown, 17606 test_snow3g_encryption_test_case_1_offset_oop), 17607 TEST_CASE_ST(ut_setup, ut_teardown, 17608 test_snow3g_decryption_test_case_1_oop), 17609 17610 /** SNOW 3G generate auth, then encrypt (UEA2) */ 17611 TEST_CASE_ST(ut_setup, ut_teardown, 17612 test_snow3g_auth_cipher_test_case_1), 17613 TEST_CASE_ST(ut_setup, ut_teardown, 17614 test_snow3g_auth_cipher_test_case_2), 17615 TEST_CASE_ST(ut_setup, ut_teardown, 17616 test_snow3g_auth_cipher_test_case_2_oop), 17617 TEST_CASE_ST(ut_setup, ut_teardown, 17618 test_snow3g_auth_cipher_part_digest_enc), 17619 TEST_CASE_ST(ut_setup, ut_teardown, 17620 test_snow3g_auth_cipher_part_digest_enc_oop), 17621 TEST_CASE_ST(ut_setup, ut_teardown, 17622 test_snow3g_auth_cipher_test_case_3_sgl), 17623 TEST_CASE_ST(ut_setup, ut_teardown, 17624 test_snow3g_auth_cipher_test_case_3_oop_sgl), 17625 TEST_CASE_ST(ut_setup, ut_teardown, 17626 test_snow3g_auth_cipher_part_digest_enc_sgl), 17627 TEST_CASE_ST(ut_setup, ut_teardown, 17628 test_snow3g_auth_cipher_part_digest_enc_oop_sgl), 17629 TEST_CASE_ST(ut_setup, ut_teardown, 17630 test_snow3g_auth_cipher_total_digest_enc_1), 17631 TEST_CASE_ST(ut_setup, ut_teardown, 17632 test_snow3g_auth_cipher_total_digest_enc_1_oop), 17633 TEST_CASE_ST(ut_setup, ut_teardown, 17634 test_snow3g_auth_cipher_total_digest_enc_1_sgl), 17635 TEST_CASE_ST(ut_setup, ut_teardown, 17636 test_snow3g_auth_cipher_total_digest_enc_1_oop_sgl), 17637 17638 /** SNOW 3G decrypt (UEA2), then verify auth */ 17639 TEST_CASE_ST(ut_setup, ut_teardown, 17640 test_snow3g_auth_cipher_verify_test_case_1), 17641 TEST_CASE_ST(ut_setup, ut_teardown, 17642 test_snow3g_auth_cipher_verify_test_case_2), 17643 TEST_CASE_ST(ut_setup, ut_teardown, 17644 test_snow3g_auth_cipher_verify_test_case_2_oop), 17645 TEST_CASE_ST(ut_setup, ut_teardown, 17646 test_snow3g_auth_cipher_verify_part_digest_enc), 17647 TEST_CASE_ST(ut_setup, ut_teardown, 17648 test_snow3g_auth_cipher_verify_part_digest_enc_oop), 17649 TEST_CASE_ST(ut_setup, ut_teardown, 17650 test_snow3g_auth_cipher_verify_test_case_3_sgl), 17651 TEST_CASE_ST(ut_setup, ut_teardown, 17652 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl), 17653 TEST_CASE_ST(ut_setup, ut_teardown, 17654 test_snow3g_auth_cipher_verify_part_digest_enc_sgl), 17655 TEST_CASE_ST(ut_setup, ut_teardown, 17656 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl), 17657 TEST_CASE_ST(ut_setup, ut_teardown, 17658 test_snow3g_auth_cipher_verify_total_digest_enc_1), 17659 TEST_CASE_ST(ut_setup, ut_teardown, 17660 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop), 17661 TEST_CASE_ST(ut_setup, ut_teardown, 17662 test_snow3g_auth_cipher_verify_total_digest_enc_1_sgl), 17663 TEST_CASE_ST(ut_setup, ut_teardown, 17664 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop_sgl), 17665 17666 /** SNOW 3G decrypt only (UEA2) */ 17667 TEST_CASE_ST(ut_setup, ut_teardown, 17668 test_snow3g_decryption_test_case_1), 17669 TEST_CASE_ST(ut_setup, ut_teardown, 17670 test_snow3g_decryption_test_case_2), 17671 TEST_CASE_ST(ut_setup, ut_teardown, 17672 test_snow3g_decryption_test_case_3), 17673 TEST_CASE_ST(ut_setup, ut_teardown, 17674 test_snow3g_decryption_test_case_4), 17675 TEST_CASE_ST(ut_setup, ut_teardown, 17676 test_snow3g_decryption_test_case_5), 17677 TEST_CASE_ST(ut_setup, ut_teardown, 17678 test_snow3g_decryption_with_digest_test_case_1), 17679 TEST_CASE_ST(ut_setup, ut_teardown, 17680 test_snow3g_hash_generate_test_case_1), 17681 TEST_CASE_ST(ut_setup, ut_teardown, 17682 test_snow3g_hash_generate_test_case_2), 17683 TEST_CASE_ST(ut_setup, ut_teardown, 17684 test_snow3g_hash_generate_test_case_3), 17685 17686 /* Tests with buffers which length is not byte-aligned */ 17687 TEST_CASE_ST(ut_setup, ut_teardown, 17688 test_snow3g_hash_generate_test_case_4), 17689 TEST_CASE_ST(ut_setup, ut_teardown, 17690 test_snow3g_hash_generate_test_case_5), 17691 TEST_CASE_ST(ut_setup, ut_teardown, 17692 test_snow3g_hash_generate_test_case_6), 17693 TEST_CASE_ST(ut_setup, ut_teardown, 17694 test_snow3g_hash_verify_test_case_1), 17695 TEST_CASE_ST(ut_setup, ut_teardown, 17696 test_snow3g_hash_verify_test_case_2), 17697 TEST_CASE_ST(ut_setup, ut_teardown, 17698 test_snow3g_hash_verify_test_case_3), 17699 17700 /* Tests with buffers which length is not byte-aligned */ 17701 TEST_CASE_ST(ut_setup, ut_teardown, 17702 test_snow3g_hash_verify_test_case_4), 17703 TEST_CASE_ST(ut_setup, ut_teardown, 17704 test_snow3g_hash_verify_test_case_5), 17705 TEST_CASE_ST(ut_setup, ut_teardown, 17706 test_snow3g_hash_verify_test_case_6), 17707 TEST_CASE_ST(ut_setup, ut_teardown, 17708 test_snow3g_cipher_auth_test_case_1), 17709 TEST_CASE_ST(ut_setup, ut_teardown, 17710 test_snow3g_auth_cipher_with_digest_test_case_1), 17711 TEST_CASES_END() 17712 } 17713 }; 17714 17715 static struct unit_test_suite cryptodev_zuc_testsuite = { 17716 .suite_name = "ZUC Test Suite", 17717 .setup = zuc_testsuite_setup, 17718 .unit_test_cases = { 17719 /** ZUC encrypt only (EEA3) */ 17720 TEST_CASE_ST(ut_setup, ut_teardown, 17721 test_zuc_encryption_test_case_1), 17722 TEST_CASE_ST(ut_setup, ut_teardown, 17723 test_zuc_encryption_test_case_2), 17724 TEST_CASE_ST(ut_setup, ut_teardown, 17725 test_zuc_encryption_test_case_3), 17726 TEST_CASE_ST(ut_setup, ut_teardown, 17727 test_zuc_encryption_test_case_4), 17728 TEST_CASE_ST(ut_setup, ut_teardown, 17729 test_zuc_encryption_test_case_5), 17730 TEST_CASE_ST(ut_setup, ut_teardown, 17731 test_zuc_encryption_test_case_6_sgl), 17732 17733 /** ZUC decrypt only (EEA3) */ 17734 TEST_CASE_ST(ut_setup, ut_teardown, 17735 test_zuc_decryption_test_case_1), 17736 TEST_CASE_ST(ut_setup, ut_teardown, 17737 test_zuc_decryption_test_case_2), 17738 TEST_CASE_ST(ut_setup, ut_teardown, 17739 test_zuc_decryption_test_case_3), 17740 TEST_CASE_ST(ut_setup, ut_teardown, 17741 test_zuc_decryption_test_case_4), 17742 TEST_CASE_ST(ut_setup, ut_teardown, 17743 test_zuc_decryption_test_case_5), 17744 TEST_CASE_ST(ut_setup, ut_teardown, 17745 test_zuc_decryption_test_case_6_sgl), 17746 17747 /** ZUC authenticate (EIA3) */ 17748 TEST_CASE_ST(ut_setup, ut_teardown, 17749 test_zuc_hash_generate_test_case_1), 17750 TEST_CASE_ST(ut_setup, ut_teardown, 17751 test_zuc_hash_generate_test_case_2), 17752 TEST_CASE_ST(ut_setup, ut_teardown, 17753 test_zuc_hash_generate_test_case_3), 17754 TEST_CASE_ST(ut_setup, ut_teardown, 17755 test_zuc_hash_generate_test_case_4), 17756 TEST_CASE_ST(ut_setup, ut_teardown, 17757 test_zuc_hash_generate_test_case_5), 17758 TEST_CASE_ST(ut_setup, ut_teardown, 17759 test_zuc_hash_generate_test_case_6), 17760 TEST_CASE_ST(ut_setup, ut_teardown, 17761 test_zuc_hash_generate_test_case_7), 17762 TEST_CASE_ST(ut_setup, ut_teardown, 17763 test_zuc_hash_generate_test_case_8), 17764 17765 /** ZUC verify (EIA3) */ 17766 TEST_CASE_ST(ut_setup, ut_teardown, 17767 test_zuc_hash_verify_test_case_1), 17768 TEST_CASE_ST(ut_setup, ut_teardown, 17769 test_zuc_hash_verify_test_case_2), 17770 TEST_CASE_ST(ut_setup, ut_teardown, 17771 test_zuc_hash_verify_test_case_3), 17772 TEST_CASE_ST(ut_setup, ut_teardown, 17773 test_zuc_hash_verify_test_case_4), 17774 TEST_CASE_ST(ut_setup, ut_teardown, 17775 test_zuc_hash_verify_test_case_5), 17776 TEST_CASE_ST(ut_setup, ut_teardown, 17777 test_zuc_hash_verify_test_case_6), 17778 TEST_CASE_ST(ut_setup, ut_teardown, 17779 test_zuc_hash_verify_test_case_7), 17780 TEST_CASE_ST(ut_setup, ut_teardown, 17781 test_zuc_hash_verify_test_case_8), 17782 17783 /** ZUC alg-chain (EEA3/EIA3) */ 17784 TEST_CASE_ST(ut_setup, ut_teardown, 17785 test_zuc_cipher_auth_test_case_1), 17786 TEST_CASE_ST(ut_setup, ut_teardown, 17787 test_zuc_cipher_auth_test_case_2), 17788 17789 /** ZUC generate auth, then encrypt (EEA3) */ 17790 TEST_CASE_ST(ut_setup, ut_teardown, 17791 test_zuc_auth_cipher_test_case_1), 17792 TEST_CASE_ST(ut_setup, ut_teardown, 17793 test_zuc_auth_cipher_test_case_1_oop), 17794 TEST_CASE_ST(ut_setup, ut_teardown, 17795 test_zuc_auth_cipher_test_case_1_sgl), 17796 TEST_CASE_ST(ut_setup, ut_teardown, 17797 test_zuc_auth_cipher_test_case_1_oop_sgl), 17798 TEST_CASE_ST(ut_setup, ut_teardown, 17799 test_zuc_auth_cipher_test_case_2), 17800 TEST_CASE_ST(ut_setup, ut_teardown, 17801 test_zuc_auth_cipher_test_case_2_oop), 17802 17803 /** ZUC decrypt (EEA3), then verify auth */ 17804 TEST_CASE_ST(ut_setup, ut_teardown, 17805 test_zuc_auth_cipher_verify_test_case_1), 17806 TEST_CASE_ST(ut_setup, ut_teardown, 17807 test_zuc_auth_cipher_verify_test_case_1_oop), 17808 TEST_CASE_ST(ut_setup, ut_teardown, 17809 test_zuc_auth_cipher_verify_test_case_1_sgl), 17810 TEST_CASE_ST(ut_setup, ut_teardown, 17811 test_zuc_auth_cipher_verify_test_case_1_oop_sgl), 17812 TEST_CASE_ST(ut_setup, ut_teardown, 17813 test_zuc_auth_cipher_verify_test_case_2), 17814 TEST_CASE_ST(ut_setup, ut_teardown, 17815 test_zuc_auth_cipher_verify_test_case_2_oop), 17816 17817 /** ZUC-256 encrypt only **/ 17818 TEST_CASE_ST(ut_setup, ut_teardown, 17819 test_zuc256_encryption_test_case_1), 17820 TEST_CASE_ST(ut_setup, ut_teardown, 17821 test_zuc256_encryption_test_case_2), 17822 17823 /** ZUC-256 decrypt only **/ 17824 TEST_CASE_ST(ut_setup, ut_teardown, 17825 test_zuc256_decryption_test_case_1), 17826 TEST_CASE_ST(ut_setup, ut_teardown, 17827 test_zuc256_decryption_test_case_2), 17828 17829 /** ZUC-256 authentication only **/ 17830 TEST_CASE_ST(ut_setup, ut_teardown, 17831 test_zuc256_hash_generate_4b_tag_test_case_1), 17832 TEST_CASE_ST(ut_setup, ut_teardown, 17833 test_zuc256_hash_generate_4b_tag_test_case_2), 17834 TEST_CASE_ST(ut_setup, ut_teardown, 17835 test_zuc256_hash_generate_4b_tag_test_case_3), 17836 TEST_CASE_ST(ut_setup, ut_teardown, 17837 test_zuc256_hash_generate_8b_tag_test_case_1), 17838 TEST_CASE_ST(ut_setup, ut_teardown, 17839 test_zuc256_hash_generate_16b_tag_test_case_1), 17840 17841 /** ZUC-256 authentication verify only **/ 17842 TEST_CASE_ST(ut_setup, ut_teardown, 17843 test_zuc256_hash_verify_4b_tag_test_case_1), 17844 TEST_CASE_ST(ut_setup, ut_teardown, 17845 test_zuc256_hash_verify_4b_tag_test_case_2), 17846 TEST_CASE_ST(ut_setup, ut_teardown, 17847 test_zuc256_hash_verify_4b_tag_test_case_3), 17848 TEST_CASE_ST(ut_setup, ut_teardown, 17849 test_zuc256_hash_verify_8b_tag_test_case_1), 17850 TEST_CASE_ST(ut_setup, ut_teardown, 17851 test_zuc256_hash_verify_16b_tag_test_case_1), 17852 17853 /** ZUC-256 encrypt and authenticate **/ 17854 TEST_CASE_ST(ut_setup, ut_teardown, 17855 test_zuc256_cipher_auth_4b_tag_test_case_1), 17856 TEST_CASE_ST(ut_setup, ut_teardown, 17857 test_zuc256_cipher_auth_4b_tag_test_case_2), 17858 TEST_CASE_ST(ut_setup, ut_teardown, 17859 test_zuc256_cipher_auth_8b_tag_test_case_1), 17860 TEST_CASE_ST(ut_setup, ut_teardown, 17861 test_zuc256_cipher_auth_16b_tag_test_case_1), 17862 17863 /** ZUC-256 generate auth, then encrypt */ 17864 TEST_CASE_ST(ut_setup, ut_teardown, 17865 test_zuc256_auth_cipher_4b_tag_test_case_1), 17866 TEST_CASE_ST(ut_setup, ut_teardown, 17867 test_zuc256_auth_cipher_4b_tag_test_case_2), 17868 TEST_CASE_ST(ut_setup, ut_teardown, 17869 test_zuc256_auth_cipher_8b_tag_test_case_1), 17870 TEST_CASE_ST(ut_setup, ut_teardown, 17871 test_zuc256_auth_cipher_16b_tag_test_case_1), 17872 17873 /** ZUC-256 decrypt, then verify auth */ 17874 TEST_CASE_ST(ut_setup, ut_teardown, 17875 test_zuc256_auth_cipher_verify_4b_tag_test_case_1), 17876 TEST_CASE_ST(ut_setup, ut_teardown, 17877 test_zuc256_auth_cipher_verify_4b_tag_test_case_2), 17878 TEST_CASE_ST(ut_setup, ut_teardown, 17879 test_zuc256_auth_cipher_verify_8b_tag_test_case_1), 17880 TEST_CASE_ST(ut_setup, ut_teardown, 17881 test_zuc256_auth_cipher_verify_16b_tag_test_case_1), 17882 17883 TEST_CASES_END() 17884 } 17885 }; 17886 17887 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite = { 17888 .suite_name = "HMAC_MD5 Authentication Test Suite", 17889 .setup = hmac_md5_auth_testsuite_setup, 17890 .unit_test_cases = { 17891 TEST_CASE_ST(ut_setup, ut_teardown, 17892 test_MD5_HMAC_generate_case_1), 17893 TEST_CASE_ST(ut_setup, ut_teardown, 17894 test_MD5_HMAC_verify_case_1), 17895 TEST_CASE_ST(ut_setup, ut_teardown, 17896 test_MD5_HMAC_generate_case_2), 17897 TEST_CASE_ST(ut_setup, ut_teardown, 17898 test_MD5_HMAC_verify_case_2), 17899 TEST_CASES_END() 17900 } 17901 }; 17902 17903 static struct unit_test_suite cryptodev_kasumi_testsuite = { 17904 .suite_name = "Kasumi Test Suite", 17905 .setup = kasumi_testsuite_setup, 17906 .unit_test_cases = { 17907 /** KASUMI hash only (UIA1) */ 17908 TEST_CASE_ST(ut_setup, ut_teardown, 17909 test_kasumi_hash_generate_test_case_1), 17910 TEST_CASE_ST(ut_setup, ut_teardown, 17911 test_kasumi_hash_generate_test_case_2), 17912 TEST_CASE_ST(ut_setup, ut_teardown, 17913 test_kasumi_hash_generate_test_case_3), 17914 TEST_CASE_ST(ut_setup, ut_teardown, 17915 test_kasumi_hash_generate_test_case_4), 17916 TEST_CASE_ST(ut_setup, ut_teardown, 17917 test_kasumi_hash_generate_test_case_5), 17918 TEST_CASE_ST(ut_setup, ut_teardown, 17919 test_kasumi_hash_generate_test_case_6), 17920 17921 TEST_CASE_ST(ut_setup, ut_teardown, 17922 test_kasumi_hash_verify_test_case_1), 17923 TEST_CASE_ST(ut_setup, ut_teardown, 17924 test_kasumi_hash_verify_test_case_2), 17925 TEST_CASE_ST(ut_setup, ut_teardown, 17926 test_kasumi_hash_verify_test_case_3), 17927 TEST_CASE_ST(ut_setup, ut_teardown, 17928 test_kasumi_hash_verify_test_case_4), 17929 TEST_CASE_ST(ut_setup, ut_teardown, 17930 test_kasumi_hash_verify_test_case_5), 17931 17932 /** KASUMI encrypt only (UEA1) */ 17933 TEST_CASE_ST(ut_setup, ut_teardown, 17934 test_kasumi_encryption_test_case_1), 17935 TEST_CASE_ST(ut_setup, ut_teardown, 17936 test_kasumi_encryption_test_case_1_sgl), 17937 TEST_CASE_ST(ut_setup, ut_teardown, 17938 test_kasumi_encryption_test_case_1_oop), 17939 TEST_CASE_ST(ut_setup, ut_teardown, 17940 test_kasumi_encryption_test_case_1_oop_sgl), 17941 TEST_CASE_ST(ut_setup, ut_teardown, 17942 test_kasumi_encryption_test_case_2), 17943 TEST_CASE_ST(ut_setup, ut_teardown, 17944 test_kasumi_encryption_test_case_3), 17945 TEST_CASE_ST(ut_setup, ut_teardown, 17946 test_kasumi_encryption_test_case_4), 17947 TEST_CASE_ST(ut_setup, ut_teardown, 17948 test_kasumi_encryption_test_case_5), 17949 17950 /** KASUMI decrypt only (UEA1) */ 17951 TEST_CASE_ST(ut_setup, ut_teardown, 17952 test_kasumi_decryption_test_case_1), 17953 TEST_CASE_ST(ut_setup, ut_teardown, 17954 test_kasumi_decryption_test_case_2), 17955 TEST_CASE_ST(ut_setup, ut_teardown, 17956 test_kasumi_decryption_test_case_3), 17957 TEST_CASE_ST(ut_setup, ut_teardown, 17958 test_kasumi_decryption_test_case_4), 17959 TEST_CASE_ST(ut_setup, ut_teardown, 17960 test_kasumi_decryption_test_case_5), 17961 TEST_CASE_ST(ut_setup, ut_teardown, 17962 test_kasumi_decryption_test_case_1_oop), 17963 TEST_CASE_ST(ut_setup, ut_teardown, 17964 test_kasumi_cipher_auth_test_case_1), 17965 17966 /** KASUMI generate auth, then encrypt (F8) */ 17967 TEST_CASE_ST(ut_setup, ut_teardown, 17968 test_kasumi_auth_cipher_test_case_1), 17969 TEST_CASE_ST(ut_setup, ut_teardown, 17970 test_kasumi_auth_cipher_test_case_2), 17971 TEST_CASE_ST(ut_setup, ut_teardown, 17972 test_kasumi_auth_cipher_test_case_2_oop), 17973 TEST_CASE_ST(ut_setup, ut_teardown, 17974 test_kasumi_auth_cipher_test_case_2_sgl), 17975 TEST_CASE_ST(ut_setup, ut_teardown, 17976 test_kasumi_auth_cipher_test_case_2_oop_sgl), 17977 17978 /** KASUMI decrypt (F8), then verify auth */ 17979 TEST_CASE_ST(ut_setup, ut_teardown, 17980 test_kasumi_auth_cipher_verify_test_case_1), 17981 TEST_CASE_ST(ut_setup, ut_teardown, 17982 test_kasumi_auth_cipher_verify_test_case_2), 17983 TEST_CASE_ST(ut_setup, ut_teardown, 17984 test_kasumi_auth_cipher_verify_test_case_2_oop), 17985 TEST_CASE_ST(ut_setup, ut_teardown, 17986 test_kasumi_auth_cipher_verify_test_case_2_sgl), 17987 TEST_CASE_ST(ut_setup, ut_teardown, 17988 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl), 17989 17990 TEST_CASES_END() 17991 } 17992 }; 17993 17994 static struct unit_test_suite cryptodev_esn_testsuite = { 17995 .suite_name = "ESN Test Suite", 17996 .setup = esn_testsuite_setup, 17997 .unit_test_cases = { 17998 TEST_CASE_ST(ut_setup, ut_teardown, 17999 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 18000 TEST_CASE_ST(ut_setup, ut_teardown, 18001 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 18002 TEST_CASES_END() 18003 } 18004 }; 18005 18006 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite = { 18007 .suite_name = "Negative AES GCM Test Suite", 18008 .setup = negative_aes_gcm_testsuite_setup, 18009 .unit_test_cases = { 18010 TEST_CASE_ST(ut_setup, ut_teardown, 18011 test_AES_GCM_auth_encryption_fail_iv_corrupt), 18012 TEST_CASE_ST(ut_setup, ut_teardown, 18013 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 18014 TEST_CASE_ST(ut_setup, ut_teardown, 18015 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 18016 TEST_CASE_ST(ut_setup, ut_teardown, 18017 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 18018 TEST_CASE_ST(ut_setup, ut_teardown, 18019 test_AES_GCM_auth_encryption_fail_aad_corrupt), 18020 TEST_CASE_ST(ut_setup, ut_teardown, 18021 test_AES_GCM_auth_encryption_fail_tag_corrupt), 18022 TEST_CASE_ST(ut_setup, ut_teardown, 18023 test_AES_GCM_auth_decryption_fail_iv_corrupt), 18024 TEST_CASE_ST(ut_setup, ut_teardown, 18025 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 18026 TEST_CASE_ST(ut_setup, ut_teardown, 18027 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 18028 TEST_CASE_ST(ut_setup, ut_teardown, 18029 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 18030 TEST_CASE_ST(ut_setup, ut_teardown, 18031 test_AES_GCM_auth_decryption_fail_aad_corrupt), 18032 TEST_CASE_ST(ut_setup, ut_teardown, 18033 test_AES_GCM_auth_decryption_fail_tag_corrupt), 18034 18035 TEST_CASES_END() 18036 } 18037 }; 18038 18039 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite = { 18040 .suite_name = "Negative AES GMAC Test Suite", 18041 .setup = negative_aes_gmac_testsuite_setup, 18042 .unit_test_cases = { 18043 TEST_CASE_ST(ut_setup, ut_teardown, 18044 authentication_verify_AES128_GMAC_fail_data_corrupt), 18045 TEST_CASE_ST(ut_setup, ut_teardown, 18046 authentication_verify_AES128_GMAC_fail_tag_corrupt), 18047 18048 TEST_CASES_END() 18049 } 18050 }; 18051 18052 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite = { 18053 .suite_name = "Mixed CIPHER + HASH algorithms Test Suite", 18054 .setup = mixed_cipher_hash_testsuite_setup, 18055 .unit_test_cases = { 18056 /** AUTH AES CMAC + CIPHER AES CTR */ 18057 TEST_CASE_ST(ut_setup, ut_teardown, 18058 test_aes_cmac_aes_ctr_digest_enc_test_case_1), 18059 TEST_CASE_ST(ut_setup, ut_teardown, 18060 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 18061 TEST_CASE_ST(ut_setup, ut_teardown, 18062 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 18063 TEST_CASE_ST(ut_setup, ut_teardown, 18064 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 18065 TEST_CASE_ST(ut_setup, ut_teardown, 18066 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1), 18067 TEST_CASE_ST(ut_setup, ut_teardown, 18068 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 18069 TEST_CASE_ST(ut_setup, ut_teardown, 18070 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 18071 TEST_CASE_ST(ut_setup, ut_teardown, 18072 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 18073 TEST_CASE_ST(ut_setup, ut_teardown, 18074 test_aes_cmac_aes_ctr_digest_enc_test_case_2), 18075 TEST_CASE_ST(ut_setup, ut_teardown, 18076 test_aes_cmac_aes_ctr_digest_enc_test_case_2_oop), 18077 TEST_CASE_ST(ut_setup, ut_teardown, 18078 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2), 18079 TEST_CASE_ST(ut_setup, ut_teardown, 18080 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2_oop), 18081 18082 /** AUTH ZUC + CIPHER SNOW3G */ 18083 TEST_CASE_ST(ut_setup, ut_teardown, 18084 test_auth_zuc_cipher_snow_test_case_1), 18085 TEST_CASE_ST(ut_setup, ut_teardown, 18086 test_verify_auth_zuc_cipher_snow_test_case_1), 18087 TEST_CASE_ST(ut_setup, ut_teardown, 18088 test_auth_zuc_cipher_snow_test_case_1_inplace), 18089 TEST_CASE_ST(ut_setup, ut_teardown, 18090 test_verify_auth_zuc_cipher_snow_test_case_1_inplace), 18091 /** AUTH AES CMAC + CIPHER SNOW3G */ 18092 TEST_CASE_ST(ut_setup, ut_teardown, 18093 test_auth_aes_cmac_cipher_snow_test_case_1), 18094 TEST_CASE_ST(ut_setup, ut_teardown, 18095 test_verify_auth_aes_cmac_cipher_snow_test_case_1), 18096 TEST_CASE_ST(ut_setup, ut_teardown, 18097 test_auth_aes_cmac_cipher_snow_test_case_1_inplace), 18098 TEST_CASE_ST(ut_setup, ut_teardown, 18099 test_verify_auth_aes_cmac_cipher_snow_test_case_1_inplace), 18100 /** AUTH ZUC + CIPHER AES CTR */ 18101 TEST_CASE_ST(ut_setup, ut_teardown, 18102 test_auth_zuc_cipher_aes_ctr_test_case_1), 18103 TEST_CASE_ST(ut_setup, ut_teardown, 18104 test_verify_auth_zuc_cipher_aes_ctr_test_case_1), 18105 TEST_CASE_ST(ut_setup, ut_teardown, 18106 test_auth_zuc_cipher_aes_ctr_test_case_1_inplace), 18107 TEST_CASE_ST(ut_setup, ut_teardown, 18108 test_verify_auth_zuc_cipher_aes_ctr_test_case_1_inplace), 18109 /** AUTH SNOW3G + CIPHER AES CTR */ 18110 TEST_CASE_ST(ut_setup, ut_teardown, 18111 test_auth_snow_cipher_aes_ctr_test_case_1), 18112 TEST_CASE_ST(ut_setup, ut_teardown, 18113 test_verify_auth_snow_cipher_aes_ctr_test_case_1), 18114 TEST_CASE_ST(ut_setup, ut_teardown, 18115 test_auth_snow_cipher_aes_ctr_test_case_1_inplace), 18116 TEST_CASE_ST(ut_setup, ut_teardown, 18117 test_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl), 18118 TEST_CASE_ST(ut_setup, ut_teardown, 18119 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace), 18120 TEST_CASE_ST(ut_setup, ut_teardown, 18121 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl), 18122 /** AUTH SNOW3G + CIPHER ZUC */ 18123 TEST_CASE_ST(ut_setup, ut_teardown, 18124 test_auth_snow_cipher_zuc_test_case_1), 18125 TEST_CASE_ST(ut_setup, ut_teardown, 18126 test_verify_auth_snow_cipher_zuc_test_case_1), 18127 TEST_CASE_ST(ut_setup, ut_teardown, 18128 test_auth_snow_cipher_zuc_test_case_1_inplace), 18129 TEST_CASE_ST(ut_setup, ut_teardown, 18130 test_verify_auth_snow_cipher_zuc_test_case_1_inplace), 18131 /** AUTH AES CMAC + CIPHER ZUC */ 18132 TEST_CASE_ST(ut_setup, ut_teardown, 18133 test_auth_aes_cmac_cipher_zuc_test_case_1), 18134 TEST_CASE_ST(ut_setup, ut_teardown, 18135 test_verify_auth_aes_cmac_cipher_zuc_test_case_1), 18136 TEST_CASE_ST(ut_setup, ut_teardown, 18137 test_auth_aes_cmac_cipher_zuc_test_case_1_inplace), 18138 TEST_CASE_ST(ut_setup, ut_teardown, 18139 test_verify_auth_aes_cmac_cipher_zuc_test_case_1_inplace), 18140 18141 /** AUTH NULL + CIPHER SNOW3G */ 18142 TEST_CASE_ST(ut_setup, ut_teardown, 18143 test_auth_null_cipher_snow_test_case_1), 18144 TEST_CASE_ST(ut_setup, ut_teardown, 18145 test_verify_auth_null_cipher_snow_test_case_1), 18146 /** AUTH NULL + CIPHER ZUC */ 18147 TEST_CASE_ST(ut_setup, ut_teardown, 18148 test_auth_null_cipher_zuc_test_case_1), 18149 TEST_CASE_ST(ut_setup, ut_teardown, 18150 test_verify_auth_null_cipher_zuc_test_case_1), 18151 /** AUTH SNOW3G + CIPHER NULL */ 18152 TEST_CASE_ST(ut_setup, ut_teardown, 18153 test_auth_snow_cipher_null_test_case_1), 18154 TEST_CASE_ST(ut_setup, ut_teardown, 18155 test_verify_auth_snow_cipher_null_test_case_1), 18156 /** AUTH ZUC + CIPHER NULL */ 18157 TEST_CASE_ST(ut_setup, ut_teardown, 18158 test_auth_zuc_cipher_null_test_case_1), 18159 TEST_CASE_ST(ut_setup, ut_teardown, 18160 test_verify_auth_zuc_cipher_null_test_case_1), 18161 /** AUTH NULL + CIPHER AES CTR */ 18162 TEST_CASE_ST(ut_setup, ut_teardown, 18163 test_auth_null_cipher_aes_ctr_test_case_1), 18164 TEST_CASE_ST(ut_setup, ut_teardown, 18165 test_verify_auth_null_cipher_aes_ctr_test_case_1), 18166 /** AUTH AES CMAC + CIPHER NULL */ 18167 TEST_CASE_ST(ut_setup, ut_teardown, 18168 test_auth_aes_cmac_cipher_null_test_case_1), 18169 TEST_CASE_ST(ut_setup, ut_teardown, 18170 test_verify_auth_aes_cmac_cipher_null_test_case_1), 18171 TEST_CASES_END() 18172 } 18173 }; 18174 18175 static int 18176 run_cryptodev_testsuite(const char *pmd_name) 18177 { 18178 uint8_t ret, j, i = 0, blk_start_idx = 0; 18179 const enum blockcipher_test_type blk_suites[] = { 18180 BLKCIPHER_AES_CHAIN_TYPE, 18181 BLKCIPHER_AES_CIPHERONLY_TYPE, 18182 BLKCIPHER_AES_DOCSIS_TYPE, 18183 BLKCIPHER_3DES_CHAIN_TYPE, 18184 BLKCIPHER_3DES_CIPHERONLY_TYPE, 18185 BLKCIPHER_DES_CIPHERONLY_TYPE, 18186 BLKCIPHER_DES_DOCSIS_TYPE, 18187 BLKCIPHER_SM4_CHAIN_TYPE, 18188 BLKCIPHER_SM4_CIPHERONLY_TYPE, 18189 BLKCIPHER_AUTHONLY_TYPE}; 18190 struct unit_test_suite *static_suites[] = { 18191 &cryptodev_multi_session_testsuite, 18192 &cryptodev_null_testsuite, 18193 &cryptodev_aes_ccm_auth_testsuite, 18194 &cryptodev_aes_gcm_auth_testsuite, 18195 &cryptodev_aes_gmac_auth_testsuite, 18196 &cryptodev_snow3g_testsuite, 18197 &cryptodev_chacha20_poly1305_testsuite, 18198 &cryptodev_zuc_testsuite, 18199 &cryptodev_hmac_md5_auth_testsuite, 18200 &cryptodev_kasumi_testsuite, 18201 &cryptodev_esn_testsuite, 18202 &cryptodev_negative_aes_gcm_testsuite, 18203 &cryptodev_negative_aes_gmac_testsuite, 18204 &cryptodev_mixed_cipher_hash_testsuite, 18205 &cryptodev_negative_hmac_sha1_testsuite, 18206 &cryptodev_gen_testsuite, 18207 #ifdef RTE_LIB_SECURITY 18208 &ipsec_proto_testsuite, 18209 &pdcp_proto_testsuite, 18210 &docsis_proto_testsuite, 18211 &tls12_record_proto_testsuite, 18212 &dtls12_record_proto_testsuite, 18213 #endif 18214 &end_testsuite 18215 }; 18216 static struct unit_test_suite ts = { 18217 .suite_name = "Cryptodev Unit Test Suite", 18218 .setup = testsuite_setup, 18219 .teardown = testsuite_teardown, 18220 .unit_test_cases = {TEST_CASES_END()} 18221 }; 18222 18223 gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name); 18224 18225 if (gbl_driver_id == -1) { 18226 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name); 18227 return TEST_SKIPPED; 18228 } 18229 18230 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 18231 (RTE_DIM(blk_suites) + RTE_DIM(static_suites))); 18232 18233 ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites)); 18234 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 18235 ret = unit_test_suite_runner(&ts); 18236 18237 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites)); 18238 free(ts.unit_test_suites); 18239 return ret; 18240 } 18241 18242 static int 18243 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name) 18244 { 18245 struct rte_cryptodev_info dev_info; 18246 uint8_t i, nb_devs; 18247 int driver_id; 18248 18249 driver_id = rte_cryptodev_driver_id_get(pmd_name); 18250 if (driver_id == -1) { 18251 RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name); 18252 return TEST_SKIPPED; 18253 } 18254 18255 nb_devs = rte_cryptodev_count(); 18256 if (nb_devs < 1) { 18257 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 18258 return TEST_SKIPPED; 18259 } 18260 18261 for (i = 0; i < nb_devs; i++) { 18262 rte_cryptodev_info_get(i, &dev_info); 18263 if (dev_info.driver_id == driver_id) { 18264 if (!(dev_info.feature_flags & flag)) { 18265 RTE_LOG(INFO, USER1, "%s not supported\n", 18266 flag_name); 18267 return TEST_SKIPPED; 18268 } 18269 return 0; /* found */ 18270 } 18271 } 18272 18273 RTE_LOG(INFO, USER1, "%s not supported\n", flag_name); 18274 return TEST_SKIPPED; 18275 } 18276 18277 static int 18278 test_cryptodev_qat(void) 18279 { 18280 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 18281 } 18282 18283 static int 18284 test_cryptodev_uadk(void) 18285 { 18286 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_UADK_PMD)); 18287 } 18288 18289 static int 18290 test_cryptodev_virtio(void) 18291 { 18292 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)); 18293 } 18294 18295 static int 18296 test_cryptodev_aesni_mb(void) 18297 { 18298 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 18299 } 18300 18301 static int 18302 test_cryptodev_cpu_aesni_mb(void) 18303 { 18304 int32_t rc; 18305 enum rte_security_session_action_type at = gbl_action_type; 18306 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 18307 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 18308 gbl_action_type = at; 18309 return rc; 18310 } 18311 18312 static int 18313 test_cryptodev_chacha_poly_mb(void) 18314 { 18315 int32_t rc; 18316 enum rte_security_session_action_type at = gbl_action_type; 18317 rc = run_cryptodev_testsuite( 18318 RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD)); 18319 gbl_action_type = at; 18320 return rc; 18321 } 18322 18323 static int 18324 test_cryptodev_openssl(void) 18325 { 18326 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 18327 } 18328 18329 static int 18330 test_cryptodev_aesni_gcm(void) 18331 { 18332 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 18333 } 18334 18335 static int 18336 test_cryptodev_cpu_aesni_gcm(void) 18337 { 18338 int32_t rc; 18339 enum rte_security_session_action_type at = gbl_action_type; 18340 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 18341 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 18342 gbl_action_type = at; 18343 return rc; 18344 } 18345 18346 static int 18347 test_cryptodev_mlx5(void) 18348 { 18349 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD)); 18350 } 18351 18352 static int 18353 test_cryptodev_null(void) 18354 { 18355 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 18356 } 18357 18358 static int 18359 test_cryptodev_sw_snow3g(void) 18360 { 18361 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 18362 } 18363 18364 static int 18365 test_cryptodev_sw_kasumi(void) 18366 { 18367 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 18368 } 18369 18370 static int 18371 test_cryptodev_sw_zuc(void) 18372 { 18373 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 18374 } 18375 18376 static int 18377 test_cryptodev_armv8(void) 18378 { 18379 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 18380 } 18381 18382 static int 18383 test_cryptodev_mrvl(void) 18384 { 18385 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 18386 } 18387 18388 #ifdef RTE_CRYPTO_SCHEDULER 18389 18390 static int 18391 test_cryptodev_scheduler(void) 18392 { 18393 uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0; 18394 const enum blockcipher_test_type blk_suites[] = { 18395 BLKCIPHER_AES_CHAIN_TYPE, 18396 BLKCIPHER_AES_CIPHERONLY_TYPE, 18397 BLKCIPHER_AUTHONLY_TYPE 18398 }; 18399 static struct unit_test_suite scheduler_multicore = { 18400 .suite_name = "Scheduler Multicore Unit Test Suite", 18401 .setup = scheduler_multicore_testsuite_setup, 18402 .teardown = scheduler_mode_testsuite_teardown, 18403 .unit_test_cases = {TEST_CASES_END()} 18404 }; 18405 static struct unit_test_suite scheduler_round_robin = { 18406 .suite_name = "Scheduler Round Robin Unit Test Suite", 18407 .setup = scheduler_roundrobin_testsuite_setup, 18408 .teardown = scheduler_mode_testsuite_teardown, 18409 .unit_test_cases = {TEST_CASES_END()} 18410 }; 18411 static struct unit_test_suite scheduler_failover = { 18412 .suite_name = "Scheduler Failover Unit Test Suite", 18413 .setup = scheduler_failover_testsuite_setup, 18414 .teardown = scheduler_mode_testsuite_teardown, 18415 .unit_test_cases = {TEST_CASES_END()} 18416 }; 18417 static struct unit_test_suite scheduler_pkt_size_distr = { 18418 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite", 18419 .setup = scheduler_pkt_size_distr_testsuite_setup, 18420 .teardown = scheduler_mode_testsuite_teardown, 18421 .unit_test_cases = {TEST_CASES_END()} 18422 }; 18423 struct unit_test_suite *sched_mode_suites[] = { 18424 &scheduler_multicore, 18425 &scheduler_round_robin, 18426 &scheduler_failover, 18427 &scheduler_pkt_size_distr 18428 }; 18429 static struct unit_test_suite scheduler_config = { 18430 .suite_name = "Crypto Device Scheduler Config Unit Test Suite", 18431 .unit_test_cases = { 18432 TEST_CASE(test_scheduler_attach_worker_op), 18433 TEST_CASE(test_scheduler_mode_multicore_op), 18434 TEST_CASE(test_scheduler_mode_roundrobin_op), 18435 TEST_CASE(test_scheduler_mode_failover_op), 18436 TEST_CASE(test_scheduler_mode_pkt_size_distr_op), 18437 TEST_CASE(test_scheduler_detach_worker_op), 18438 18439 TEST_CASES_END() /**< NULL terminate array */ 18440 } 18441 }; 18442 struct unit_test_suite *static_suites[] = { 18443 &scheduler_config, 18444 &end_testsuite 18445 }; 18446 struct unit_test_suite *sched_mode_static_suites[] = { 18447 #ifdef RTE_LIB_SECURITY 18448 &docsis_proto_testsuite, 18449 #endif 18450 &end_testsuite 18451 }; 18452 static struct unit_test_suite ts = { 18453 .suite_name = "Scheduler Unit Test Suite", 18454 .setup = scheduler_testsuite_setup, 18455 .teardown = testsuite_teardown, 18456 .unit_test_cases = {TEST_CASES_END()} 18457 }; 18458 18459 gbl_driver_id = rte_cryptodev_driver_id_get( 18460 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 18461 18462 if (gbl_driver_id == -1) { 18463 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n"); 18464 return TEST_SKIPPED; 18465 } 18466 18467 if (rte_cryptodev_driver_id_get( 18468 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) { 18469 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 18470 return TEST_SKIPPED; 18471 } 18472 18473 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 18474 uint8_t blk_i = 0; 18475 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof 18476 (struct unit_test_suite *) * 18477 (RTE_DIM(blk_suites) + 18478 RTE_DIM(sched_mode_static_suites) + 1)); 18479 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]), 18480 blk_suites, RTE_DIM(blk_suites)); 18481 ADD_STATIC_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]), 18482 sched_mode_static_suites, 18483 RTE_DIM(sched_mode_static_suites)); 18484 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite; 18485 } 18486 18487 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 18488 (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites))); 18489 ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites, 18490 RTE_DIM(sched_mode_suites)); 18491 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 18492 ret = unit_test_suite_runner(&ts); 18493 18494 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 18495 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, 18496 (*sched_mode_suites[sched_i]), 18497 RTE_DIM(blk_suites)); 18498 free(sched_mode_suites[sched_i]->unit_test_suites); 18499 } 18500 free(ts.unit_test_suites); 18501 return ret; 18502 } 18503 18504 REGISTER_DRIVER_TEST(cryptodev_scheduler_autotest, test_cryptodev_scheduler); 18505 18506 #endif 18507 18508 static int 18509 test_cryptodev_dpaa2_sec(void) 18510 { 18511 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 18512 } 18513 18514 static int 18515 test_cryptodev_dpaa_sec(void) 18516 { 18517 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 18518 } 18519 18520 static int 18521 test_cryptodev_ccp(void) 18522 { 18523 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 18524 } 18525 18526 static int 18527 test_cryptodev_octeontx(void) 18528 { 18529 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)); 18530 } 18531 18532 static int 18533 test_cryptodev_caam_jr(void) 18534 { 18535 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)); 18536 } 18537 18538 static int 18539 test_cryptodev_nitrox(void) 18540 { 18541 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD)); 18542 } 18543 18544 static int 18545 test_cryptodev_bcmfs(void) 18546 { 18547 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD)); 18548 } 18549 18550 static int 18551 run_cryptodev_raw_testsuite(const char *pmd_name) 18552 { 18553 int ret; 18554 18555 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, "RAW API"); 18556 if (ret) 18557 return ret; 18558 18559 global_api_test_type = CRYPTODEV_RAW_API_TEST; 18560 ret = run_cryptodev_testsuite(pmd_name); 18561 global_api_test_type = CRYPTODEV_API_TEST; 18562 18563 return ret; 18564 } 18565 18566 static int 18567 test_cryptodev_qat_raw_api(void) 18568 { 18569 return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 18570 } 18571 18572 static int 18573 test_cryptodev_cn9k(void) 18574 { 18575 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD)); 18576 } 18577 18578 static int 18579 test_cryptodev_cn10k(void) 18580 { 18581 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD)); 18582 } 18583 18584 static int 18585 test_cryptodev_cn10k_raw_api(void) 18586 { 18587 return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD)); 18588 } 18589 18590 static int 18591 test_cryptodev_dpaa2_sec_raw_api(void) 18592 { 18593 return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 18594 } 18595 18596 static int 18597 test_cryptodev_dpaa_sec_raw_api(void) 18598 { 18599 return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 18600 } 18601 18602 REGISTER_DRIVER_TEST(cryptodev_cn10k_raw_api_autotest, 18603 test_cryptodev_cn10k_raw_api); 18604 REGISTER_DRIVER_TEST(cryptodev_dpaa2_sec_raw_api_autotest, 18605 test_cryptodev_dpaa2_sec_raw_api); 18606 REGISTER_DRIVER_TEST(cryptodev_dpaa_sec_raw_api_autotest, 18607 test_cryptodev_dpaa_sec_raw_api); 18608 REGISTER_DRIVER_TEST(cryptodev_qat_raw_api_autotest, 18609 test_cryptodev_qat_raw_api); 18610 REGISTER_DRIVER_TEST(cryptodev_qat_autotest, test_cryptodev_qat); 18611 REGISTER_DRIVER_TEST(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 18612 REGISTER_DRIVER_TEST(cryptodev_cpu_aesni_mb_autotest, 18613 test_cryptodev_cpu_aesni_mb); 18614 REGISTER_DRIVER_TEST(cryptodev_chacha_poly_mb_autotest, 18615 test_cryptodev_chacha_poly_mb); 18616 REGISTER_DRIVER_TEST(cryptodev_openssl_autotest, test_cryptodev_openssl); 18617 REGISTER_DRIVER_TEST(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 18618 REGISTER_DRIVER_TEST(cryptodev_cpu_aesni_gcm_autotest, 18619 test_cryptodev_cpu_aesni_gcm); 18620 REGISTER_DRIVER_TEST(cryptodev_mlx5_autotest, test_cryptodev_mlx5); 18621 REGISTER_DRIVER_TEST(cryptodev_null_autotest, test_cryptodev_null); 18622 REGISTER_DRIVER_TEST(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 18623 REGISTER_DRIVER_TEST(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 18624 REGISTER_DRIVER_TEST(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 18625 REGISTER_DRIVER_TEST(cryptodev_sw_armv8_autotest, test_cryptodev_armv8); 18626 REGISTER_DRIVER_TEST(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl); 18627 REGISTER_DRIVER_TEST(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec); 18628 REGISTER_DRIVER_TEST(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec); 18629 REGISTER_DRIVER_TEST(cryptodev_ccp_autotest, test_cryptodev_ccp); 18630 REGISTER_DRIVER_TEST(cryptodev_uadk_autotest, test_cryptodev_uadk); 18631 REGISTER_DRIVER_TEST(cryptodev_virtio_autotest, test_cryptodev_virtio); 18632 REGISTER_DRIVER_TEST(cryptodev_octeontx_autotest, test_cryptodev_octeontx); 18633 REGISTER_DRIVER_TEST(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr); 18634 REGISTER_DRIVER_TEST(cryptodev_nitrox_autotest, test_cryptodev_nitrox); 18635 REGISTER_DRIVER_TEST(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs); 18636 REGISTER_DRIVER_TEST(cryptodev_cn9k_autotest, test_cryptodev_cn9k); 18637 REGISTER_DRIVER_TEST(cryptodev_cn10k_autotest, test_cryptodev_cn10k); 18638