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_ip.h> 21 #include <rte_string_fns.h> 22 #include <rte_tcp.h> 23 #include <rte_udp.h> 24 25 #ifdef RTE_CRYPTO_SCHEDULER 26 #include <rte_cryptodev_scheduler.h> 27 #include <rte_cryptodev_scheduler_operations.h> 28 #endif 29 30 #include <rte_lcore.h> 31 32 #include "test.h" 33 #include "test_cryptodev.h" 34 35 #include "test_cryptodev_blockcipher.h" 36 #include "test_cryptodev_aes_test_vectors.h" 37 #include "test_cryptodev_des_test_vectors.h" 38 #include "test_cryptodev_hash_test_vectors.h" 39 #include "test_cryptodev_kasumi_test_vectors.h" 40 #include "test_cryptodev_kasumi_hash_test_vectors.h" 41 #include "test_cryptodev_snow3g_test_vectors.h" 42 #include "test_cryptodev_snow3g_hash_test_vectors.h" 43 #include "test_cryptodev_zuc_test_vectors.h" 44 #include "test_cryptodev_aead_test_vectors.h" 45 #include "test_cryptodev_hmac_test_vectors.h" 46 #include "test_cryptodev_mixed_test_vectors.h" 47 #ifdef RTE_LIB_SECURITY 48 #include "test_cryptodev_security_ipsec.h" 49 #include "test_cryptodev_security_ipsec_test_vectors.h" 50 #include "test_cryptodev_security_pdcp_test_vectors.h" 51 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h" 52 #include "test_cryptodev_security_pdcp_test_func.h" 53 #include "test_cryptodev_security_docsis_test_vectors.h" 54 55 #define SDAP_DISABLED 0 56 #define SDAP_ENABLED 1 57 #endif 58 59 #define VDEV_ARGS_SIZE 100 60 #define MAX_NB_SESSIONS 4 61 62 #define MAX_DRV_SERVICE_CTX_SIZE 256 63 64 #define MAX_RAW_DEQUEUE_COUNT 65535 65 66 #define IN_PLACE 0 67 #define OUT_OF_PLACE 1 68 69 static int gbl_driver_id; 70 71 static enum rte_security_session_action_type gbl_action_type = 72 RTE_SECURITY_ACTION_TYPE_NONE; 73 74 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST; 75 76 struct crypto_unittest_params { 77 struct rte_crypto_sym_xform cipher_xform; 78 struct rte_crypto_sym_xform auth_xform; 79 struct rte_crypto_sym_xform aead_xform; 80 #ifdef RTE_LIB_SECURITY 81 struct rte_security_docsis_xform docsis_xform; 82 #endif 83 84 union { 85 void *sess; 86 #ifdef RTE_LIB_SECURITY 87 void *sec_session; 88 #endif 89 }; 90 #ifdef RTE_LIB_SECURITY 91 enum rte_security_session_action_type type; 92 #endif 93 struct rte_crypto_op *op; 94 95 struct rte_mbuf *obuf, *ibuf; 96 97 uint8_t *digest; 98 }; 99 100 #define ALIGN_POW2_ROUNDUP(num, align) \ 101 (((num) + (align) - 1) & ~((align) - 1)) 102 103 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts) \ 104 for (j = 0; j < num_child_ts; index++, j++) \ 105 parent_ts.unit_test_suites[index] = child_ts[j] 106 107 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types) \ 108 for (j = 0; j < num_blk_types; index++, j++) \ 109 parent_ts.unit_test_suites[index] = \ 110 build_blockcipher_test_suite(blk_types[j]) 111 112 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types) \ 113 for (j = index; j < index + num_blk_types; j++) \ 114 free_blockcipher_test_suite(parent_ts.unit_test_suites[j]) 115 116 /* 117 * Forward declarations. 118 */ 119 static int 120 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 121 struct crypto_unittest_params *ut_params, uint8_t *cipher_key, 122 uint8_t *hmac_key); 123 124 static int 125 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess, 126 struct crypto_unittest_params *ut_params, 127 struct crypto_testsuite_params *ts_param, 128 const uint8_t *cipher, 129 const uint8_t *digest, 130 const uint8_t *iv); 131 132 static int 133 security_proto_supported(enum rte_security_session_action_type action, 134 enum rte_security_session_protocol proto); 135 136 static int 137 dev_configure_and_start(uint64_t ff_disable); 138 139 static struct rte_mbuf * 140 setup_test_string(struct rte_mempool *mpool, 141 const char *string, size_t len, uint8_t blocksize) 142 { 143 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool); 144 size_t t_len = len - (blocksize ? (len % blocksize) : 0); 145 146 if (m) { 147 char *dst; 148 149 memset(m->buf_addr, 0, m->buf_len); 150 dst = rte_pktmbuf_append(m, t_len); 151 if (!dst) { 152 rte_pktmbuf_free(m); 153 return NULL; 154 } 155 if (string != NULL) 156 rte_memcpy(dst, string, t_len); 157 else 158 memset(dst, 0, t_len); 159 } 160 161 return m; 162 } 163 164 /* Get number of bytes in X bits (rounding up) */ 165 static uint32_t 166 ceil_byte_length(uint32_t num_bits) 167 { 168 if (num_bits % 8) 169 return ((num_bits >> 3) + 1); 170 else 171 return (num_bits >> 3); 172 } 173 174 static void 175 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused, 176 uint8_t is_op_success) 177 { 178 struct rte_crypto_op *op = user_data; 179 op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS : 180 RTE_CRYPTO_OP_STATUS_ERROR; 181 } 182 183 static struct crypto_testsuite_params testsuite_params = { NULL }; 184 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params; 185 static struct crypto_unittest_params unittest_params; 186 187 void 188 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id, 189 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth, 190 uint8_t len_in_bits, uint8_t cipher_iv_len) 191 { 192 struct rte_crypto_sym_op *sop = op->sym; 193 struct rte_crypto_op *ret_op = NULL; 194 struct rte_crypto_vec data_vec[UINT8_MAX], dest_data_vec[UINT8_MAX]; 195 struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv; 196 union rte_crypto_sym_ofs ofs; 197 struct rte_crypto_sym_vec vec; 198 struct rte_crypto_sgl sgl, dest_sgl; 199 uint32_t max_len; 200 union rte_cryptodev_session_ctx sess; 201 uint64_t auth_end_iova; 202 uint32_t count = 0; 203 struct rte_crypto_raw_dp_ctx *ctx; 204 uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0, 205 auth_len = 0; 206 int32_t n; 207 uint32_t n_success; 208 int ctx_service_size; 209 int32_t status = 0; 210 int enqueue_status, dequeue_status; 211 struct crypto_unittest_params *ut_params = &unittest_params; 212 int is_sgl = sop->m_src->nb_segs > 1; 213 int is_oop = 0; 214 215 ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id); 216 if (ctx_service_size < 0) { 217 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 218 return; 219 } 220 221 ctx = malloc(ctx_service_size); 222 if (!ctx) { 223 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 224 return; 225 } 226 227 /* Both are enums, setting crypto_sess will suit any session type */ 228 sess.crypto_sess = op->sym->session; 229 230 if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx, 231 op->sess_type, sess, 0) < 0) { 232 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 233 goto exit; 234 } 235 236 cipher_iv.iova = 0; 237 cipher_iv.va = NULL; 238 aad_auth_iv.iova = 0; 239 aad_auth_iv.va = NULL; 240 digest.iova = 0; 241 digest.va = NULL; 242 sgl.vec = data_vec; 243 vec.num = 1; 244 vec.src_sgl = &sgl; 245 vec.iv = &cipher_iv; 246 vec.digest = &digest; 247 vec.aad = &aad_auth_iv; 248 vec.status = &status; 249 250 ofs.raw = 0; 251 252 if ((sop->m_dst != NULL) && (sop->m_dst != sop->m_src)) 253 is_oop = 1; 254 255 if (is_cipher && is_auth) { 256 cipher_offset = sop->cipher.data.offset; 257 cipher_len = sop->cipher.data.length; 258 auth_offset = sop->auth.data.offset; 259 auth_len = sop->auth.data.length; 260 max_len = RTE_MAX(cipher_offset + cipher_len, 261 auth_offset + auth_len); 262 if (len_in_bits) { 263 max_len = max_len >> 3; 264 cipher_offset = cipher_offset >> 3; 265 auth_offset = auth_offset >> 3; 266 cipher_len = cipher_len >> 3; 267 auth_len = auth_len >> 3; 268 } 269 ofs.ofs.cipher.head = cipher_offset; 270 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 271 ofs.ofs.auth.head = auth_offset; 272 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 273 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 274 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 275 aad_auth_iv.va = rte_crypto_op_ctod_offset( 276 op, void *, IV_OFFSET + cipher_iv_len); 277 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 278 cipher_iv_len); 279 digest.va = (void *)sop->auth.digest.data; 280 digest.iova = sop->auth.digest.phys_addr; 281 282 if (is_sgl) { 283 uint32_t remaining_off = auth_offset + auth_len; 284 struct rte_mbuf *sgl_buf = sop->m_src; 285 if (is_oop) 286 sgl_buf = sop->m_dst; 287 288 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf) 289 && sgl_buf->next != NULL) { 290 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 291 sgl_buf = sgl_buf->next; 292 } 293 294 auth_end_iova = (uint64_t)rte_pktmbuf_iova_offset( 295 sgl_buf, remaining_off); 296 } else { 297 auth_end_iova = rte_pktmbuf_iova(op->sym->m_src) + 298 auth_offset + auth_len; 299 } 300 /* Then check if digest-encrypted conditions are met */ 301 if ((auth_offset + auth_len < cipher_offset + cipher_len) && 302 (digest.iova == auth_end_iova) && is_sgl) 303 max_len = RTE_MAX(max_len, 304 auth_offset + auth_len + 305 ut_params->auth_xform.auth.digest_length); 306 307 } else if (is_cipher) { 308 cipher_offset = sop->cipher.data.offset; 309 cipher_len = sop->cipher.data.length; 310 max_len = cipher_len + cipher_offset; 311 if (len_in_bits) { 312 max_len = max_len >> 3; 313 cipher_offset = cipher_offset >> 3; 314 cipher_len = cipher_len >> 3; 315 } 316 ofs.ofs.cipher.head = cipher_offset; 317 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 318 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 319 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 320 321 } else if (is_auth) { 322 auth_offset = sop->auth.data.offset; 323 auth_len = sop->auth.data.length; 324 max_len = auth_len + auth_offset; 325 if (len_in_bits) { 326 max_len = max_len >> 3; 327 auth_offset = auth_offset >> 3; 328 auth_len = auth_len >> 3; 329 } 330 ofs.ofs.auth.head = auth_offset; 331 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 332 aad_auth_iv.va = rte_crypto_op_ctod_offset( 333 op, void *, IV_OFFSET + cipher_iv_len); 334 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 335 cipher_iv_len); 336 digest.va = (void *)sop->auth.digest.data; 337 digest.iova = sop->auth.digest.phys_addr; 338 339 } else { /* aead */ 340 cipher_offset = sop->aead.data.offset; 341 cipher_len = sop->aead.data.length; 342 max_len = cipher_len + cipher_offset; 343 if (len_in_bits) { 344 max_len = max_len >> 3; 345 cipher_offset = cipher_offset >> 3; 346 cipher_len = cipher_len >> 3; 347 } 348 ofs.ofs.cipher.head = cipher_offset; 349 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 350 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 351 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 352 aad_auth_iv.va = (void *)sop->aead.aad.data; 353 aad_auth_iv.iova = sop->aead.aad.phys_addr; 354 digest.va = (void *)sop->aead.digest.data; 355 digest.iova = sop->aead.digest.phys_addr; 356 } 357 358 n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len, 359 data_vec, RTE_DIM(data_vec)); 360 if (n < 0 || n > sop->m_src->nb_segs) { 361 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 362 goto exit; 363 } 364 365 sgl.num = n; 366 /* Out of place */ 367 if (is_oop) { 368 dest_sgl.vec = dest_data_vec; 369 vec.dest_sgl = &dest_sgl; 370 n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len, 371 dest_data_vec, RTE_DIM(dest_data_vec)); 372 if (n < 0 || n > sop->m_dst->nb_segs) { 373 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 374 goto exit; 375 } 376 dest_sgl.num = n; 377 } else 378 vec.dest_sgl = NULL; 379 380 if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op, 381 &enqueue_status) < 1) { 382 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 383 goto exit; 384 } 385 386 if (enqueue_status == 0) { 387 status = rte_cryptodev_raw_enqueue_done(ctx, 1); 388 if (status < 0) { 389 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 390 goto exit; 391 } 392 } else if (enqueue_status < 0) { 393 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 394 goto exit; 395 } 396 397 n = n_success = 0; 398 while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) { 399 n = rte_cryptodev_raw_dequeue_burst(ctx, 400 NULL, 1, post_process_raw_dp_op, 401 (void **)&ret_op, 0, &n_success, 402 &dequeue_status); 403 if (dequeue_status < 0) { 404 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 405 goto exit; 406 } 407 if (n == 0) 408 rte_pause(); 409 } 410 411 if (n == 1 && dequeue_status == 0) { 412 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) { 413 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 414 goto exit; 415 } 416 } 417 418 op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op || 419 ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR || 420 n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR : 421 RTE_CRYPTO_OP_STATUS_SUCCESS; 422 423 exit: 424 free(ctx); 425 } 426 427 static void 428 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op) 429 { 430 int32_t n, st; 431 struct rte_crypto_sym_op *sop; 432 union rte_crypto_sym_ofs ofs; 433 struct rte_crypto_sgl sgl; 434 struct rte_crypto_sym_vec symvec; 435 struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr; 436 struct rte_crypto_vec vec[UINT8_MAX]; 437 438 sop = op->sym; 439 440 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset, 441 sop->aead.data.length, vec, RTE_DIM(vec)); 442 443 if (n < 0 || n != sop->m_src->nb_segs) { 444 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 445 return; 446 } 447 448 sgl.vec = vec; 449 sgl.num = n; 450 symvec.src_sgl = &sgl; 451 symvec.iv = &iv_ptr; 452 symvec.digest = &digest_ptr; 453 symvec.aad = &aad_ptr; 454 symvec.status = &st; 455 symvec.num = 1; 456 457 /* for CPU crypto the IOVA address is not required */ 458 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 459 digest_ptr.va = (void *)sop->aead.digest.data; 460 aad_ptr.va = (void *)sop->aead.aad.data; 461 462 ofs.raw = 0; 463 464 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 465 &symvec); 466 467 if (n != 1) 468 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 469 else 470 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 471 } 472 473 static void 474 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op) 475 { 476 int32_t n, st; 477 struct rte_crypto_sym_op *sop; 478 union rte_crypto_sym_ofs ofs; 479 struct rte_crypto_sgl sgl; 480 struct rte_crypto_sym_vec symvec; 481 struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr; 482 struct rte_crypto_vec vec[UINT8_MAX]; 483 484 sop = op->sym; 485 486 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset, 487 sop->auth.data.length, vec, RTE_DIM(vec)); 488 489 if (n < 0 || n != sop->m_src->nb_segs) { 490 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 491 return; 492 } 493 494 sgl.vec = vec; 495 sgl.num = n; 496 symvec.src_sgl = &sgl; 497 symvec.iv = &iv_ptr; 498 symvec.digest = &digest_ptr; 499 symvec.status = &st; 500 symvec.num = 1; 501 502 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 503 digest_ptr.va = (void *)sop->auth.digest.data; 504 505 ofs.raw = 0; 506 ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset; 507 ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) - 508 (sop->cipher.data.offset + sop->cipher.data.length); 509 510 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 511 &symvec); 512 513 if (n != 1) 514 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 515 else 516 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 517 } 518 519 static struct rte_crypto_op * 520 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op) 521 { 522 523 RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO); 524 525 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 526 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n"); 527 return NULL; 528 } 529 530 op = NULL; 531 532 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 533 rte_pause(); 534 535 if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 536 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status); 537 return NULL; 538 } 539 540 return op; 541 } 542 543 static int 544 testsuite_setup(void) 545 { 546 struct crypto_testsuite_params *ts_params = &testsuite_params; 547 struct rte_cryptodev_info info; 548 uint32_t i = 0, nb_devs, dev_id; 549 uint16_t qp_id; 550 551 memset(ts_params, 0, sizeof(*ts_params)); 552 553 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 554 if (ts_params->mbuf_pool == NULL) { 555 /* Not already created so create */ 556 ts_params->mbuf_pool = rte_pktmbuf_pool_create( 557 "CRYPTO_MBUFPOOL", 558 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE, 559 rte_socket_id()); 560 if (ts_params->mbuf_pool == NULL) { 561 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n"); 562 return TEST_FAILED; 563 } 564 } 565 566 ts_params->large_mbuf_pool = rte_mempool_lookup( 567 "CRYPTO_LARGE_MBUFPOOL"); 568 if (ts_params->large_mbuf_pool == NULL) { 569 /* Not already created so create */ 570 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create( 571 "CRYPTO_LARGE_MBUFPOOL", 572 1, 0, 0, UINT16_MAX, 573 rte_socket_id()); 574 if (ts_params->large_mbuf_pool == NULL) { 575 RTE_LOG(ERR, USER1, 576 "Can't create CRYPTO_LARGE_MBUFPOOL\n"); 577 return TEST_FAILED; 578 } 579 } 580 581 ts_params->op_mpool = rte_crypto_op_pool_create( 582 "MBUF_CRYPTO_SYM_OP_POOL", 583 RTE_CRYPTO_OP_TYPE_SYMMETRIC, 584 NUM_MBUFS, MBUF_CACHE_SIZE, 585 DEFAULT_NUM_XFORMS * 586 sizeof(struct rte_crypto_sym_xform) + 587 MAXIMUM_IV_LENGTH, 588 rte_socket_id()); 589 if (ts_params->op_mpool == NULL) { 590 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n"); 591 return TEST_FAILED; 592 } 593 594 nb_devs = rte_cryptodev_count(); 595 if (nb_devs < 1) { 596 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 597 return TEST_SKIPPED; 598 } 599 600 if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) { 601 RTE_LOG(WARNING, USER1, "No %s devices found?\n", 602 rte_cryptodev_driver_name_get(gbl_driver_id)); 603 return TEST_SKIPPED; 604 } 605 606 /* Create list of valid crypto devs */ 607 for (i = 0; i < nb_devs; i++) { 608 rte_cryptodev_info_get(i, &info); 609 if (info.driver_id == gbl_driver_id) 610 ts_params->valid_devs[ts_params->valid_dev_count++] = i; 611 } 612 613 if (ts_params->valid_dev_count < 1) 614 return TEST_FAILED; 615 616 /* Set up all the qps on the first of the valid devices found */ 617 618 dev_id = ts_params->valid_devs[0]; 619 620 rte_cryptodev_info_get(dev_id, &info); 621 622 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; 623 ts_params->conf.socket_id = SOCKET_ID_ANY; 624 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY; 625 626 unsigned int session_size = 627 rte_cryptodev_sym_get_private_session_size(dev_id); 628 629 #ifdef RTE_LIB_SECURITY 630 unsigned int security_session_size = rte_security_session_get_size( 631 rte_cryptodev_get_sec_ctx(dev_id)); 632 633 if (session_size < security_session_size) 634 session_size = security_session_size; 635 #endif 636 /* 637 * Create mempool with maximum number of sessions. 638 */ 639 if (info.sym.max_nb_sessions != 0 && 640 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 641 RTE_LOG(ERR, USER1, "Device does not support " 642 "at least %u sessions\n", 643 MAX_NB_SESSIONS); 644 return TEST_FAILED; 645 } 646 647 ts_params->session_mpool = rte_cryptodev_sym_session_pool_create( 648 "test_sess_mp", MAX_NB_SESSIONS, session_size, 0, 0, 649 SOCKET_ID_ANY); 650 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 651 "session mempool allocation failed"); 652 653 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, 654 &ts_params->conf), 655 "Failed to configure cryptodev %u with %u qps", 656 dev_id, ts_params->conf.nb_queue_pairs); 657 658 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 659 ts_params->qp_conf.mp_session = ts_params->session_mpool; 660 661 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 662 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 663 dev_id, qp_id, &ts_params->qp_conf, 664 rte_cryptodev_socket_id(dev_id)), 665 "Failed to setup queue pair %u on cryptodev %u", 666 qp_id, dev_id); 667 } 668 669 return TEST_SUCCESS; 670 } 671 672 static void 673 testsuite_teardown(void) 674 { 675 struct crypto_testsuite_params *ts_params = &testsuite_params; 676 int res; 677 678 if (ts_params->mbuf_pool != NULL) { 679 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 680 rte_mempool_avail_count(ts_params->mbuf_pool)); 681 } 682 683 if (ts_params->op_mpool != NULL) { 684 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", 685 rte_mempool_avail_count(ts_params->op_mpool)); 686 } 687 688 if (ts_params->session_mpool != NULL) { 689 rte_mempool_free(ts_params->session_mpool); 690 ts_params->session_mpool = NULL; 691 } 692 693 res = rte_cryptodev_close(ts_params->valid_devs[0]); 694 if (res) 695 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res); 696 } 697 698 static int 699 check_capabilities_supported(enum rte_crypto_sym_xform_type type, 700 const int *algs, uint16_t num_algs) 701 { 702 uint8_t dev_id = testsuite_params.valid_devs[0]; 703 bool some_alg_supported = FALSE; 704 uint16_t i; 705 706 for (i = 0; i < num_algs && !some_alg_supported; i++) { 707 struct rte_cryptodev_sym_capability_idx alg = { 708 type, {algs[i]} 709 }; 710 if (rte_cryptodev_sym_capability_get(dev_id, 711 &alg) != NULL) 712 some_alg_supported = TRUE; 713 } 714 if (!some_alg_supported) 715 return TEST_SKIPPED; 716 717 return 0; 718 } 719 720 int 721 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers, 722 uint16_t num_ciphers) 723 { 724 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER, 725 (const int *) ciphers, num_ciphers); 726 } 727 728 int 729 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths, 730 uint16_t num_auths) 731 { 732 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH, 733 (const int *) auths, num_auths); 734 } 735 736 int 737 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads, 738 uint16_t num_aeads) 739 { 740 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD, 741 (const int *) aeads, num_aeads); 742 } 743 744 static int 745 null_testsuite_setup(void) 746 { 747 struct crypto_testsuite_params *ts_params = &testsuite_params; 748 uint8_t dev_id = ts_params->valid_devs[0]; 749 struct rte_cryptodev_info dev_info; 750 const enum rte_crypto_cipher_algorithm ciphers[] = { 751 RTE_CRYPTO_CIPHER_NULL 752 }; 753 const enum rte_crypto_auth_algorithm auths[] = { 754 RTE_CRYPTO_AUTH_NULL 755 }; 756 757 rte_cryptodev_info_get(dev_id, &dev_info); 758 759 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 760 RTE_LOG(INFO, USER1, "Feature flag requirements for NULL " 761 "testsuite not met\n"); 762 return TEST_SKIPPED; 763 } 764 765 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 766 && check_auth_capabilities_supported(auths, 767 RTE_DIM(auths)) != 0) { 768 RTE_LOG(INFO, USER1, "Capability requirements for NULL " 769 "testsuite not met\n"); 770 return TEST_SKIPPED; 771 } 772 773 return 0; 774 } 775 776 static int 777 crypto_gen_testsuite_setup(void) 778 { 779 struct crypto_testsuite_params *ts_params = &testsuite_params; 780 uint8_t dev_id = ts_params->valid_devs[0]; 781 struct rte_cryptodev_info dev_info; 782 783 rte_cryptodev_info_get(dev_id, &dev_info); 784 785 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 786 RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen " 787 "testsuite not met\n"); 788 return TEST_SKIPPED; 789 } 790 791 return 0; 792 } 793 794 #ifdef RTE_LIB_SECURITY 795 static int 796 ipsec_proto_testsuite_setup(void) 797 { 798 struct crypto_testsuite_params *ts_params = &testsuite_params; 799 struct crypto_unittest_params *ut_params = &unittest_params; 800 struct rte_cryptodev_info dev_info; 801 int ret = 0; 802 803 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 804 805 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) { 806 RTE_LOG(INFO, USER1, "Feature flag requirements for IPsec Proto " 807 "testsuite not met\n"); 808 return TEST_SKIPPED; 809 } 810 811 /* Reconfigure to enable security */ 812 ret = dev_configure_and_start(0); 813 if (ret != TEST_SUCCESS) 814 return ret; 815 816 /* Set action type */ 817 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 818 819 if (security_proto_supported( 820 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 821 RTE_SECURITY_PROTOCOL_IPSEC) < 0) { 822 RTE_LOG(INFO, USER1, "Capability requirements for IPsec Proto " 823 "test not met\n"); 824 ret = TEST_SKIPPED; 825 } 826 827 test_ipsec_alg_list_populate(); 828 test_ipsec_ah_alg_list_populate(); 829 830 /* 831 * Stop the device. Device would be started again by individual test 832 * case setup routine. 833 */ 834 rte_cryptodev_stop(ts_params->valid_devs[0]); 835 836 return ret; 837 } 838 839 static int 840 pdcp_proto_testsuite_setup(void) 841 { 842 struct crypto_testsuite_params *ts_params = &testsuite_params; 843 uint8_t dev_id = ts_params->valid_devs[0]; 844 struct rte_cryptodev_info dev_info; 845 const enum rte_crypto_cipher_algorithm ciphers[] = { 846 RTE_CRYPTO_CIPHER_NULL, 847 RTE_CRYPTO_CIPHER_AES_CTR, 848 RTE_CRYPTO_CIPHER_ZUC_EEA3, 849 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 850 }; 851 const enum rte_crypto_auth_algorithm auths[] = { 852 RTE_CRYPTO_AUTH_NULL, 853 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 854 RTE_CRYPTO_AUTH_AES_CMAC, 855 RTE_CRYPTO_AUTH_ZUC_EIA3 856 }; 857 858 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_auth_key)); 859 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_bearer)); 860 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_crypto_key)); 861 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_in)); 862 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_in_len)); 863 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_out)); 864 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_sn_size)); 865 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_hfn)); 866 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_hfn_threshold)); 867 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_packet_direction)); 868 869 rte_cryptodev_info_get(dev_id, &dev_info); 870 871 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 872 !(dev_info.feature_flags & 873 RTE_CRYPTODEV_FF_SECURITY)) { 874 RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto " 875 "testsuite not met\n"); 876 return TEST_SKIPPED; 877 } 878 879 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 880 && check_auth_capabilities_supported(auths, 881 RTE_DIM(auths)) != 0) { 882 RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto " 883 "testsuite not met\n"); 884 return TEST_SKIPPED; 885 } 886 887 return 0; 888 } 889 890 static int 891 docsis_proto_testsuite_setup(void) 892 { 893 struct crypto_testsuite_params *ts_params = &testsuite_params; 894 uint8_t dev_id = ts_params->valid_devs[0]; 895 struct rte_cryptodev_info dev_info; 896 const enum rte_crypto_cipher_algorithm ciphers[] = { 897 RTE_CRYPTO_CIPHER_AES_DOCSISBPI 898 }; 899 900 rte_cryptodev_info_get(dev_id, &dev_info); 901 902 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 903 !(dev_info.feature_flags & 904 RTE_CRYPTODEV_FF_SECURITY)) { 905 RTE_LOG(INFO, USER1, "Feature flag requirements for DOCSIS " 906 "Proto testsuite not met\n"); 907 return TEST_SKIPPED; 908 } 909 910 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { 911 RTE_LOG(INFO, USER1, "Capability requirements for DOCSIS Proto " 912 "testsuite not met\n"); 913 return TEST_SKIPPED; 914 } 915 916 return 0; 917 } 918 #endif 919 920 static int 921 aes_ccm_auth_testsuite_setup(void) 922 { 923 struct crypto_testsuite_params *ts_params = &testsuite_params; 924 uint8_t dev_id = ts_params->valid_devs[0]; 925 struct rte_cryptodev_info dev_info; 926 const enum rte_crypto_aead_algorithm aeads[] = { 927 RTE_CRYPTO_AEAD_AES_CCM 928 }; 929 930 rte_cryptodev_info_get(dev_id, &dev_info); 931 932 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 933 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 934 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 935 RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM " 936 "testsuite not met\n"); 937 return TEST_SKIPPED; 938 } 939 940 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 941 RTE_LOG(INFO, USER1, "Capability requirements for AES CCM " 942 "testsuite not met\n"); 943 return TEST_SKIPPED; 944 } 945 946 return 0; 947 } 948 949 static int 950 aes_gcm_auth_testsuite_setup(void) 951 { 952 struct crypto_testsuite_params *ts_params = &testsuite_params; 953 uint8_t dev_id = ts_params->valid_devs[0]; 954 struct rte_cryptodev_info dev_info; 955 const enum rte_crypto_aead_algorithm aeads[] = { 956 RTE_CRYPTO_AEAD_AES_GCM 957 }; 958 959 rte_cryptodev_info_get(dev_id, &dev_info); 960 961 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 962 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM " 963 "testsuite not met\n"); 964 return TEST_SKIPPED; 965 } 966 967 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 968 RTE_LOG(INFO, USER1, "Capability requirements for AES GCM " 969 "testsuite not met\n"); 970 return TEST_SKIPPED; 971 } 972 973 return 0; 974 } 975 976 static int 977 aes_gmac_auth_testsuite_setup(void) 978 { 979 struct crypto_testsuite_params *ts_params = &testsuite_params; 980 uint8_t dev_id = ts_params->valid_devs[0]; 981 struct rte_cryptodev_info dev_info; 982 const enum rte_crypto_auth_algorithm auths[] = { 983 RTE_CRYPTO_AUTH_AES_GMAC 984 }; 985 986 rte_cryptodev_info_get(dev_id, &dev_info); 987 988 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 989 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 990 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 991 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC " 992 "testsuite not met\n"); 993 return TEST_SKIPPED; 994 } 995 996 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 997 RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC " 998 "testsuite not met\n"); 999 return TEST_SKIPPED; 1000 } 1001 1002 return 0; 1003 } 1004 1005 static int 1006 chacha20_poly1305_testsuite_setup(void) 1007 { 1008 struct crypto_testsuite_params *ts_params = &testsuite_params; 1009 uint8_t dev_id = ts_params->valid_devs[0]; 1010 struct rte_cryptodev_info dev_info; 1011 const enum rte_crypto_aead_algorithm aeads[] = { 1012 RTE_CRYPTO_AEAD_CHACHA20_POLY1305 1013 }; 1014 1015 rte_cryptodev_info_get(dev_id, &dev_info); 1016 1017 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1018 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1019 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1020 RTE_LOG(INFO, USER1, "Feature flag requirements for " 1021 "Chacha20-Poly1305 testsuite not met\n"); 1022 return TEST_SKIPPED; 1023 } 1024 1025 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1026 RTE_LOG(INFO, USER1, "Capability requirements for " 1027 "Chacha20-Poly1305 testsuite not met\n"); 1028 return TEST_SKIPPED; 1029 } 1030 1031 return 0; 1032 } 1033 1034 static int 1035 snow3g_testsuite_setup(void) 1036 { 1037 struct crypto_testsuite_params *ts_params = &testsuite_params; 1038 uint8_t dev_id = ts_params->valid_devs[0]; 1039 struct rte_cryptodev_info dev_info; 1040 const enum rte_crypto_cipher_algorithm ciphers[] = { 1041 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1042 1043 }; 1044 const enum rte_crypto_auth_algorithm auths[] = { 1045 RTE_CRYPTO_AUTH_SNOW3G_UIA2 1046 }; 1047 1048 rte_cryptodev_info_get(dev_id, &dev_info); 1049 1050 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1051 RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G " 1052 "testsuite not met\n"); 1053 return TEST_SKIPPED; 1054 } 1055 1056 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1057 && check_auth_capabilities_supported(auths, 1058 RTE_DIM(auths)) != 0) { 1059 RTE_LOG(INFO, USER1, "Capability requirements for Snow3G " 1060 "testsuite not met\n"); 1061 return TEST_SKIPPED; 1062 } 1063 1064 return 0; 1065 } 1066 1067 static int 1068 zuc_testsuite_setup(void) 1069 { 1070 struct crypto_testsuite_params *ts_params = &testsuite_params; 1071 uint8_t dev_id = ts_params->valid_devs[0]; 1072 struct rte_cryptodev_info dev_info; 1073 const enum rte_crypto_cipher_algorithm ciphers[] = { 1074 RTE_CRYPTO_CIPHER_ZUC_EEA3 1075 }; 1076 const enum rte_crypto_auth_algorithm auths[] = { 1077 RTE_CRYPTO_AUTH_ZUC_EIA3 1078 }; 1079 1080 rte_cryptodev_info_get(dev_id, &dev_info); 1081 1082 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1083 RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC " 1084 "testsuite not met\n"); 1085 return TEST_SKIPPED; 1086 } 1087 1088 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1089 && check_auth_capabilities_supported(auths, 1090 RTE_DIM(auths)) != 0) { 1091 RTE_LOG(INFO, USER1, "Capability requirements for ZUC " 1092 "testsuite not met\n"); 1093 return TEST_SKIPPED; 1094 } 1095 1096 return 0; 1097 } 1098 1099 static int 1100 hmac_md5_auth_testsuite_setup(void) 1101 { 1102 struct crypto_testsuite_params *ts_params = &testsuite_params; 1103 uint8_t dev_id = ts_params->valid_devs[0]; 1104 struct rte_cryptodev_info dev_info; 1105 const enum rte_crypto_auth_algorithm auths[] = { 1106 RTE_CRYPTO_AUTH_MD5_HMAC 1107 }; 1108 1109 rte_cryptodev_info_get(dev_id, &dev_info); 1110 1111 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1112 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1113 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1114 RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 " 1115 "Auth testsuite not met\n"); 1116 return TEST_SKIPPED; 1117 } 1118 1119 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1120 RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 " 1121 "testsuite not met\n"); 1122 return TEST_SKIPPED; 1123 } 1124 1125 return 0; 1126 } 1127 1128 static int 1129 kasumi_testsuite_setup(void) 1130 { 1131 struct crypto_testsuite_params *ts_params = &testsuite_params; 1132 uint8_t dev_id = ts_params->valid_devs[0]; 1133 struct rte_cryptodev_info dev_info; 1134 const enum rte_crypto_cipher_algorithm ciphers[] = { 1135 RTE_CRYPTO_CIPHER_KASUMI_F8 1136 }; 1137 const enum rte_crypto_auth_algorithm auths[] = { 1138 RTE_CRYPTO_AUTH_KASUMI_F9 1139 }; 1140 1141 rte_cryptodev_info_get(dev_id, &dev_info); 1142 1143 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1144 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1145 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1146 RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi " 1147 "testsuite not met\n"); 1148 return TEST_SKIPPED; 1149 } 1150 1151 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1152 && check_auth_capabilities_supported(auths, 1153 RTE_DIM(auths)) != 0) { 1154 RTE_LOG(INFO, USER1, "Capability requirements for Kasumi " 1155 "testsuite not met\n"); 1156 return TEST_SKIPPED; 1157 } 1158 1159 return 0; 1160 } 1161 1162 static int 1163 negative_aes_gcm_testsuite_setup(void) 1164 { 1165 struct crypto_testsuite_params *ts_params = &testsuite_params; 1166 uint8_t dev_id = ts_params->valid_devs[0]; 1167 struct rte_cryptodev_info dev_info; 1168 const enum rte_crypto_aead_algorithm aeads[] = { 1169 RTE_CRYPTO_AEAD_AES_GCM 1170 }; 1171 1172 rte_cryptodev_info_get(dev_id, &dev_info); 1173 1174 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1175 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1176 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1177 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1178 "AES GCM testsuite not met\n"); 1179 return TEST_SKIPPED; 1180 } 1181 1182 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1183 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1184 "AES GCM testsuite not met\n"); 1185 return TEST_SKIPPED; 1186 } 1187 1188 return 0; 1189 } 1190 1191 static int 1192 negative_aes_gmac_testsuite_setup(void) 1193 { 1194 struct crypto_testsuite_params *ts_params = &testsuite_params; 1195 uint8_t dev_id = ts_params->valid_devs[0]; 1196 struct rte_cryptodev_info dev_info; 1197 const enum rte_crypto_auth_algorithm auths[] = { 1198 RTE_CRYPTO_AUTH_AES_GMAC 1199 }; 1200 1201 rte_cryptodev_info_get(dev_id, &dev_info); 1202 1203 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1204 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1205 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1206 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1207 "AES GMAC testsuite not met\n"); 1208 return TEST_SKIPPED; 1209 } 1210 1211 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1212 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1213 "AES GMAC testsuite not met\n"); 1214 return TEST_SKIPPED; 1215 } 1216 1217 return 0; 1218 } 1219 1220 static int 1221 mixed_cipher_hash_testsuite_setup(void) 1222 { 1223 struct crypto_testsuite_params *ts_params = &testsuite_params; 1224 uint8_t dev_id = ts_params->valid_devs[0]; 1225 struct rte_cryptodev_info dev_info; 1226 uint64_t feat_flags; 1227 const enum rte_crypto_cipher_algorithm ciphers[] = { 1228 RTE_CRYPTO_CIPHER_NULL, 1229 RTE_CRYPTO_CIPHER_AES_CTR, 1230 RTE_CRYPTO_CIPHER_ZUC_EEA3, 1231 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1232 }; 1233 const enum rte_crypto_auth_algorithm auths[] = { 1234 RTE_CRYPTO_AUTH_NULL, 1235 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 1236 RTE_CRYPTO_AUTH_AES_CMAC, 1237 RTE_CRYPTO_AUTH_ZUC_EIA3 1238 }; 1239 1240 rte_cryptodev_info_get(dev_id, &dev_info); 1241 feat_flags = dev_info.feature_flags; 1242 1243 if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1244 (global_api_test_type == CRYPTODEV_RAW_API_TEST)) { 1245 RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed " 1246 "Cipher Hash testsuite not met\n"); 1247 return TEST_SKIPPED; 1248 } 1249 1250 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1251 && check_auth_capabilities_supported(auths, 1252 RTE_DIM(auths)) != 0) { 1253 RTE_LOG(INFO, USER1, "Capability requirements for Mixed " 1254 "Cipher Hash testsuite not met\n"); 1255 return TEST_SKIPPED; 1256 } 1257 1258 return 0; 1259 } 1260 1261 static int 1262 esn_testsuite_setup(void) 1263 { 1264 struct crypto_testsuite_params *ts_params = &testsuite_params; 1265 uint8_t dev_id = ts_params->valid_devs[0]; 1266 struct rte_cryptodev_info dev_info; 1267 const enum rte_crypto_cipher_algorithm ciphers[] = { 1268 RTE_CRYPTO_CIPHER_AES_CBC 1269 }; 1270 const enum rte_crypto_auth_algorithm auths[] = { 1271 RTE_CRYPTO_AUTH_SHA1_HMAC 1272 }; 1273 1274 rte_cryptodev_info_get(dev_id, &dev_info); 1275 1276 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1277 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1278 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1279 RTE_LOG(INFO, USER1, "Feature flag requirements for ESN " 1280 "testsuite not met\n"); 1281 return TEST_SKIPPED; 1282 } 1283 1284 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1285 && check_auth_capabilities_supported(auths, 1286 RTE_DIM(auths)) != 0) { 1287 RTE_LOG(INFO, USER1, "Capability requirements for ESN " 1288 "testsuite not met\n"); 1289 return TEST_SKIPPED; 1290 } 1291 1292 return 0; 1293 } 1294 1295 static int 1296 multi_session_testsuite_setup(void) 1297 { 1298 struct crypto_testsuite_params *ts_params = &testsuite_params; 1299 uint8_t dev_id = ts_params->valid_devs[0]; 1300 struct rte_cryptodev_info dev_info; 1301 const enum rte_crypto_cipher_algorithm ciphers[] = { 1302 RTE_CRYPTO_CIPHER_AES_CBC 1303 }; 1304 const enum rte_crypto_auth_algorithm auths[] = { 1305 RTE_CRYPTO_AUTH_SHA512_HMAC 1306 }; 1307 1308 rte_cryptodev_info_get(dev_id, &dev_info); 1309 1310 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1311 RTE_LOG(INFO, USER1, "Feature flag requirements for Multi " 1312 "Session testsuite not met\n"); 1313 return TEST_SKIPPED; 1314 } 1315 1316 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1317 && check_auth_capabilities_supported(auths, 1318 RTE_DIM(auths)) != 0) { 1319 RTE_LOG(INFO, USER1, "Capability requirements for Multi " 1320 "Session testsuite not met\n"); 1321 return TEST_SKIPPED; 1322 } 1323 1324 return 0; 1325 } 1326 1327 static int 1328 negative_hmac_sha1_testsuite_setup(void) 1329 { 1330 struct crypto_testsuite_params *ts_params = &testsuite_params; 1331 uint8_t dev_id = ts_params->valid_devs[0]; 1332 struct rte_cryptodev_info dev_info; 1333 const enum rte_crypto_cipher_algorithm ciphers[] = { 1334 RTE_CRYPTO_CIPHER_AES_CBC 1335 }; 1336 const enum rte_crypto_auth_algorithm auths[] = { 1337 RTE_CRYPTO_AUTH_SHA1_HMAC 1338 }; 1339 1340 rte_cryptodev_info_get(dev_id, &dev_info); 1341 1342 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1343 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1344 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1345 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1346 "HMAC SHA1 testsuite not met\n"); 1347 return TEST_SKIPPED; 1348 } 1349 1350 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1351 && check_auth_capabilities_supported(auths, 1352 RTE_DIM(auths)) != 0) { 1353 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1354 "HMAC SHA1 testsuite not met\n"); 1355 return TEST_SKIPPED; 1356 } 1357 1358 return 0; 1359 } 1360 1361 static int 1362 dev_configure_and_start(uint64_t ff_disable) 1363 { 1364 struct crypto_testsuite_params *ts_params = &testsuite_params; 1365 struct crypto_unittest_params *ut_params = &unittest_params; 1366 1367 uint16_t qp_id; 1368 1369 /* Clear unit test parameters before running test */ 1370 memset(ut_params, 0, sizeof(*ut_params)); 1371 1372 /* Reconfigure device to default parameters */ 1373 ts_params->conf.socket_id = SOCKET_ID_ANY; 1374 ts_params->conf.ff_disable = ff_disable; 1375 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 1376 ts_params->qp_conf.mp_session = ts_params->session_mpool; 1377 1378 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1379 &ts_params->conf), 1380 "Failed to configure cryptodev %u", 1381 ts_params->valid_devs[0]); 1382 1383 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { 1384 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1385 ts_params->valid_devs[0], qp_id, 1386 &ts_params->qp_conf, 1387 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1388 "Failed to setup queue pair %u on cryptodev %u", 1389 qp_id, ts_params->valid_devs[0]); 1390 } 1391 1392 1393 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 1394 1395 /* Start the device */ 1396 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 1397 "Failed to start cryptodev %u", 1398 ts_params->valid_devs[0]); 1399 1400 return TEST_SUCCESS; 1401 } 1402 1403 int 1404 ut_setup(void) 1405 { 1406 /* Configure and start the device with security feature disabled */ 1407 return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY); 1408 } 1409 1410 static int 1411 ut_setup_security(void) 1412 { 1413 /* Configure and start the device with no features disabled */ 1414 return dev_configure_and_start(0); 1415 } 1416 1417 void 1418 ut_teardown(void) 1419 { 1420 struct crypto_testsuite_params *ts_params = &testsuite_params; 1421 struct crypto_unittest_params *ut_params = &unittest_params; 1422 1423 /* free crypto session structure */ 1424 #ifdef RTE_LIB_SECURITY 1425 if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) { 1426 if (ut_params->sec_session) { 1427 rte_security_session_destroy(rte_cryptodev_get_sec_ctx 1428 (ts_params->valid_devs[0]), 1429 ut_params->sec_session); 1430 ut_params->sec_session = NULL; 1431 } 1432 } else 1433 #endif 1434 { 1435 if (ut_params->sess) { 1436 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 1437 ut_params->sess); 1438 ut_params->sess = NULL; 1439 } 1440 } 1441 1442 /* free crypto operation structure */ 1443 rte_crypto_op_free(ut_params->op); 1444 1445 /* 1446 * free mbuf - both obuf and ibuf are usually the same, 1447 * so check if they point at the same address is necessary, 1448 * to avoid freeing the mbuf twice. 1449 */ 1450 if (ut_params->obuf) { 1451 rte_pktmbuf_free(ut_params->obuf); 1452 if (ut_params->ibuf == ut_params->obuf) 1453 ut_params->ibuf = 0; 1454 ut_params->obuf = 0; 1455 } 1456 if (ut_params->ibuf) { 1457 rte_pktmbuf_free(ut_params->ibuf); 1458 ut_params->ibuf = 0; 1459 } 1460 1461 if (ts_params->mbuf_pool != NULL) 1462 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 1463 rte_mempool_avail_count(ts_params->mbuf_pool)); 1464 1465 /* Stop the device */ 1466 rte_cryptodev_stop(ts_params->valid_devs[0]); 1467 } 1468 1469 static int 1470 test_device_configure_invalid_dev_id(void) 1471 { 1472 struct crypto_testsuite_params *ts_params = &testsuite_params; 1473 uint16_t dev_id, num_devs = 0; 1474 1475 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 1476 "Need at least %d devices for test", 1); 1477 1478 /* valid dev_id values */ 1479 dev_id = ts_params->valid_devs[0]; 1480 1481 /* Stop the device in case it's started so it can be configured */ 1482 rte_cryptodev_stop(dev_id); 1483 1484 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 1485 "Failed test for rte_cryptodev_configure: " 1486 "invalid dev_num %u", dev_id); 1487 1488 /* invalid dev_id values */ 1489 dev_id = num_devs; 1490 1491 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1492 "Failed test for rte_cryptodev_configure: " 1493 "invalid dev_num %u", dev_id); 1494 1495 dev_id = 0xff; 1496 1497 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1498 "Failed test for rte_cryptodev_configure:" 1499 "invalid dev_num %u", dev_id); 1500 1501 return TEST_SUCCESS; 1502 } 1503 1504 static int 1505 test_device_configure_invalid_queue_pair_ids(void) 1506 { 1507 struct crypto_testsuite_params *ts_params = &testsuite_params; 1508 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 1509 1510 /* Stop the device in case it's started so it can be configured */ 1511 rte_cryptodev_stop(ts_params->valid_devs[0]); 1512 1513 /* valid - max value queue pairs */ 1514 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1515 1516 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1517 &ts_params->conf), 1518 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1519 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 1520 1521 /* valid - one queue pairs */ 1522 ts_params->conf.nb_queue_pairs = 1; 1523 1524 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1525 &ts_params->conf), 1526 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1527 ts_params->valid_devs[0], 1528 ts_params->conf.nb_queue_pairs); 1529 1530 1531 /* invalid - zero queue pairs */ 1532 ts_params->conf.nb_queue_pairs = 0; 1533 1534 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1535 &ts_params->conf), 1536 "Failed test for rte_cryptodev_configure, dev_id %u," 1537 " invalid qps: %u", 1538 ts_params->valid_devs[0], 1539 ts_params->conf.nb_queue_pairs); 1540 1541 1542 /* invalid - max value supported by field queue pairs */ 1543 ts_params->conf.nb_queue_pairs = UINT16_MAX; 1544 1545 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1546 &ts_params->conf), 1547 "Failed test for rte_cryptodev_configure, dev_id %u," 1548 " invalid qps: %u", 1549 ts_params->valid_devs[0], 1550 ts_params->conf.nb_queue_pairs); 1551 1552 1553 /* invalid - max value + 1 queue pairs */ 1554 ts_params->conf.nb_queue_pairs = orig_nb_qps + 1; 1555 1556 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1557 &ts_params->conf), 1558 "Failed test for rte_cryptodev_configure, dev_id %u," 1559 " invalid qps: %u", 1560 ts_params->valid_devs[0], 1561 ts_params->conf.nb_queue_pairs); 1562 1563 /* revert to original testsuite value */ 1564 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1565 1566 return TEST_SUCCESS; 1567 } 1568 1569 static int 1570 test_queue_pair_descriptor_setup(void) 1571 { 1572 struct crypto_testsuite_params *ts_params = &testsuite_params; 1573 struct rte_cryptodev_qp_conf qp_conf = { 1574 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 1575 }; 1576 uint16_t qp_id; 1577 1578 /* Stop the device in case it's started so it can be configured */ 1579 rte_cryptodev_stop(ts_params->valid_devs[0]); 1580 1581 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1582 &ts_params->conf), 1583 "Failed to configure cryptodev %u", 1584 ts_params->valid_devs[0]); 1585 1586 /* 1587 * Test various ring sizes on this device. memzones can't be 1588 * freed so are re-used if ring is released and re-created. 1589 */ 1590 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/ 1591 qp_conf.mp_session = ts_params->session_mpool; 1592 1593 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1594 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1595 ts_params->valid_devs[0], qp_id, &qp_conf, 1596 rte_cryptodev_socket_id( 1597 ts_params->valid_devs[0])), 1598 "Failed test for " 1599 "rte_cryptodev_queue_pair_setup: num_inflights " 1600 "%u on qp %u on cryptodev %u", 1601 qp_conf.nb_descriptors, qp_id, 1602 ts_params->valid_devs[0]); 1603 } 1604 1605 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2); 1606 1607 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1608 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1609 ts_params->valid_devs[0], qp_id, &qp_conf, 1610 rte_cryptodev_socket_id( 1611 ts_params->valid_devs[0])), 1612 "Failed test for" 1613 " rte_cryptodev_queue_pair_setup: num_inflights" 1614 " %u on qp %u on cryptodev %u", 1615 qp_conf.nb_descriptors, qp_id, 1616 ts_params->valid_devs[0]); 1617 } 1618 1619 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */ 1620 1621 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1622 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1623 ts_params->valid_devs[0], qp_id, &qp_conf, 1624 rte_cryptodev_socket_id( 1625 ts_params->valid_devs[0])), 1626 "Failed test for " 1627 "rte_cryptodev_queue_pair_setup: num_inflights" 1628 " %u on qp %u on cryptodev %u", 1629 qp_conf.nb_descriptors, qp_id, 1630 ts_params->valid_devs[0]); 1631 } 1632 1633 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 1634 1635 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1636 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1637 ts_params->valid_devs[0], qp_id, &qp_conf, 1638 rte_cryptodev_socket_id( 1639 ts_params->valid_devs[0])), 1640 "Failed test for" 1641 " rte_cryptodev_queue_pair_setup:" 1642 "num_inflights %u on qp %u on cryptodev %u", 1643 qp_conf.nb_descriptors, qp_id, 1644 ts_params->valid_devs[0]); 1645 } 1646 1647 /* test invalid queue pair id */ 1648 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */ 1649 1650 qp_id = ts_params->conf.nb_queue_pairs; /*invalid */ 1651 1652 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1653 ts_params->valid_devs[0], 1654 qp_id, &qp_conf, 1655 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1656 "Failed test for rte_cryptodev_queue_pair_setup:" 1657 "invalid qp %u on cryptodev %u", 1658 qp_id, ts_params->valid_devs[0]); 1659 1660 qp_id = 0xffff; /*invalid*/ 1661 1662 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1663 ts_params->valid_devs[0], 1664 qp_id, &qp_conf, 1665 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1666 "Failed test for rte_cryptodev_queue_pair_setup:" 1667 "invalid qp %u on cryptodev %u", 1668 qp_id, ts_params->valid_devs[0]); 1669 1670 return TEST_SUCCESS; 1671 } 1672 1673 /* ***** Plaintext data for tests ***** */ 1674 1675 const char catch_22_quote_1[] = 1676 "There was only one catch and that was Catch-22, which " 1677 "specified that a concern for one's safety in the face of " 1678 "dangers that were real and immediate was the process of a " 1679 "rational mind. Orr was crazy and could be grounded. All he " 1680 "had to do was ask; and as soon as he did, he would no longer " 1681 "be crazy and would have to fly more missions. Orr would be " 1682 "crazy to fly more missions and sane if he didn't, but if he " 1683 "was sane he had to fly them. If he flew them he was crazy " 1684 "and didn't have to; but if he didn't want to he was sane and " 1685 "had to. Yossarian was moved very deeply by the absolute " 1686 "simplicity of this clause of Catch-22 and let out a " 1687 "respectful whistle. \"That's some catch, that Catch-22\", he " 1688 "observed. \"It's the best there is,\" Doc Daneeka agreed."; 1689 1690 const char catch_22_quote[] = 1691 "What a lousy earth! He wondered how many people were " 1692 "destitute that same night even in his own prosperous country, " 1693 "how many homes were shanties, how many husbands were drunk " 1694 "and wives socked, and how many children were bullied, abused, " 1695 "or abandoned. How many families hungered for food they could " 1696 "not afford to buy? How many hearts were broken? How many " 1697 "suicides would take place that same night, how many people " 1698 "would go insane? How many cockroaches and landlords would " 1699 "triumph? How many winners were losers, successes failures, " 1700 "and rich men poor men? How many wise guys were stupid? How " 1701 "many happy endings were unhappy endings? How many honest men " 1702 "were liars, brave men cowards, loyal men traitors, how many " 1703 "sainted men were corrupt, how many people in positions of " 1704 "trust had sold their souls to bodyguards, how many had never " 1705 "had souls? How many straight-and-narrow paths were crooked " 1706 "paths? How many best families were worst families and how " 1707 "many good people were bad people? When you added them all up " 1708 "and then subtracted, you might be left with only the children, " 1709 "and perhaps with Albert Einstein and an old violinist or " 1710 "sculptor somewhere."; 1711 1712 #define QUOTE_480_BYTES (480) 1713 #define QUOTE_512_BYTES (512) 1714 #define QUOTE_768_BYTES (768) 1715 #define QUOTE_1024_BYTES (1024) 1716 1717 1718 1719 /* ***** SHA1 Hash Tests ***** */ 1720 1721 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1) 1722 1723 static uint8_t hmac_sha1_key[] = { 1724 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 1725 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 1726 0xDE, 0xF4, 0xDE, 0xAD }; 1727 1728 /* ***** SHA224 Hash Tests ***** */ 1729 1730 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224) 1731 1732 1733 /* ***** AES-CBC Cipher Tests ***** */ 1734 1735 #define CIPHER_KEY_LENGTH_AES_CBC (16) 1736 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC) 1737 1738 static uint8_t aes_cbc_key[] = { 1739 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 1740 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A }; 1741 1742 static uint8_t aes_cbc_iv[] = { 1743 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 1744 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; 1745 1746 1747 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */ 1748 1749 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = { 1750 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, 1751 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, 1752 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, 1753 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, 1754 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E, 1755 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08, 1756 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0, 1757 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01, 1758 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57, 1759 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE, 1760 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9, 1761 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9, 1762 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D, 1763 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3, 1764 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46, 1765 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3, 1766 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80, 1767 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92, 1768 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5, 1769 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5, 1770 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2, 1771 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5, 1772 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1773 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76, 1774 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4, 1775 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62, 1776 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4, 1777 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4, 1778 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54, 1779 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61, 1780 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91, 1781 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A, 1782 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF, 1783 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F, 1784 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28, 1785 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E, 1786 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7, 1787 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76, 1788 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6, 1789 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03, 1790 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C, 1791 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2, 1792 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6, 1793 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96, 1794 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6, 1795 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA, 1796 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87, 1797 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55, 1798 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B, 1799 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98, 1800 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53, 1801 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A, 1802 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26, 1803 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36, 1804 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36, 1805 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D, 1806 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E, 1807 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E, 1808 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A, 1809 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6, 1810 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4, 1811 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7, 1812 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1, 1813 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C 1814 }; 1815 1816 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = { 1817 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60, 1818 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1819 0x18, 0x8c, 0x1d, 0x32 1820 }; 1821 1822 1823 /* Multisession Vector context Test */ 1824 /*Begin Session 0 */ 1825 static uint8_t ms_aes_cbc_key0[] = { 1826 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1827 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1828 }; 1829 1830 static uint8_t ms_aes_cbc_iv0[] = { 1831 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1832 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1833 }; 1834 1835 static const uint8_t ms_aes_cbc_cipher0[] = { 1836 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38, 1837 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC, 1838 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB, 1839 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9, 1840 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D, 1841 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4, 1842 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34, 1843 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F, 1844 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99, 1845 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED, 1846 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D, 1847 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24, 1848 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71, 1849 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72, 1850 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E, 1851 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD, 1852 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18, 1853 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6, 1854 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29, 1855 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C, 1856 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96, 1857 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26, 1858 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55, 1859 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46, 1860 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B, 1861 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4, 1862 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7, 1863 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5, 1864 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0, 1865 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E, 1866 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D, 1867 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44, 1868 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76, 1869 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3, 1870 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83, 1871 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85, 1872 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45, 1873 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25, 1874 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A, 1875 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1, 1876 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA, 1877 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3, 1878 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4, 1879 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60, 1880 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A, 1881 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A, 1882 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9, 1883 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55, 1884 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13, 1885 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B, 1886 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1, 1887 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0, 1888 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3, 1889 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23, 1890 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B, 1891 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07, 1892 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB, 1893 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1, 1894 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F, 1895 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F, 1896 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84, 1897 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B, 1898 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17, 1899 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF 1900 }; 1901 1902 1903 static uint8_t ms_hmac_key0[] = { 1904 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1905 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1906 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1907 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1908 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1909 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1910 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1911 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1912 }; 1913 1914 static const uint8_t ms_hmac_digest0[] = { 1915 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51, 1916 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F, 1917 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C, 1918 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4, 1919 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56, 1920 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4, 1921 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23, 1922 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90 1923 }; 1924 1925 /* End Session 0 */ 1926 /* Begin session 1 */ 1927 1928 static uint8_t ms_aes_cbc_key1[] = { 1929 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1930 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1931 }; 1932 1933 static uint8_t ms_aes_cbc_iv1[] = { 1934 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1935 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1936 }; 1937 1938 static const uint8_t ms_aes_cbc_cipher1[] = { 1939 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71, 1940 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23, 1941 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09, 1942 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A, 1943 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C, 1944 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F, 1945 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9, 1946 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66, 1947 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43, 1948 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB, 1949 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23, 1950 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29, 1951 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26, 1952 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F, 1953 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68, 1954 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77, 1955 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8, 1956 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97, 1957 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3, 1958 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90, 1959 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5, 1960 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E, 1961 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45, 1962 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B, 1963 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5, 1964 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D, 1965 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E, 1966 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD, 1967 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE, 1968 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1, 1969 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F, 1970 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25, 1971 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1, 1972 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3, 1973 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE, 1974 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6, 1975 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52, 1976 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA, 1977 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63, 1978 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E, 1979 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA, 1980 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB, 1981 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71, 1982 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF, 1983 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A, 1984 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95, 1985 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73, 1986 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49, 1987 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB, 1988 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B, 1989 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC, 1990 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED, 1991 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02, 1992 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4, 1993 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF, 1994 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82, 1995 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D, 1996 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6, 1997 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9, 1998 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35, 1999 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0, 2000 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53, 2001 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5, 2002 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3 2003 2004 }; 2005 2006 static uint8_t ms_hmac_key1[] = { 2007 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2008 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2009 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2010 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2011 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2012 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2013 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2014 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2015 }; 2016 2017 static const uint8_t ms_hmac_digest1[] = { 2018 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69, 2019 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50, 2020 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20, 2021 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD, 2022 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9, 2023 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4, 2024 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA, 2025 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F 2026 }; 2027 /* End Session 1 */ 2028 /* Begin Session 2 */ 2029 static uint8_t ms_aes_cbc_key2[] = { 2030 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2031 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2032 }; 2033 2034 static uint8_t ms_aes_cbc_iv2[] = { 2035 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2036 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2037 }; 2038 2039 static const uint8_t ms_aes_cbc_cipher2[] = { 2040 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91, 2041 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97, 2042 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8, 2043 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5, 2044 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98, 2045 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69, 2046 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09, 2047 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF, 2048 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44, 2049 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B, 2050 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9, 2051 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34, 2052 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99, 2053 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF, 2054 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC, 2055 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26, 2056 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3, 2057 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF, 2058 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3, 2059 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3, 2060 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA, 2061 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13, 2062 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38, 2063 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71, 2064 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC, 2065 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1, 2066 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E, 2067 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22, 2068 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62, 2069 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72, 2070 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6, 2071 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6, 2072 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44, 2073 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24, 2074 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5, 2075 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E, 2076 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17, 2077 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9, 2078 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D, 2079 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D, 2080 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22, 2081 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9, 2082 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49, 2083 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E, 2084 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B, 2085 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2, 2086 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95, 2087 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07, 2088 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3, 2089 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A, 2090 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57, 2091 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84, 2092 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61, 2093 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF, 2094 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17, 2095 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A, 2096 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1, 2097 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53, 2098 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7, 2099 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2, 2100 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A, 2101 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8, 2102 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70, 2103 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92 2104 }; 2105 2106 static uint8_t ms_hmac_key2[] = { 2107 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2108 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2109 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2110 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2111 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2112 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2113 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2114 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2115 }; 2116 2117 static const uint8_t ms_hmac_digest2[] = { 2118 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF, 2119 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6, 2120 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77, 2121 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27, 2122 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82, 2123 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24, 2124 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E, 2125 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59 2126 }; 2127 2128 /* End Session 2 */ 2129 2130 2131 static int 2132 test_AES_CBC_HMAC_SHA1_encrypt_digest(void) 2133 { 2134 struct crypto_testsuite_params *ts_params = &testsuite_params; 2135 struct crypto_unittest_params *ut_params = &unittest_params; 2136 /* Verify the capabilities */ 2137 struct rte_cryptodev_sym_capability_idx cap_idx; 2138 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2139 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 2140 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2141 &cap_idx) == NULL) 2142 return TEST_SKIPPED; 2143 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2144 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 2145 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2146 &cap_idx) == NULL) 2147 return TEST_SKIPPED; 2148 2149 /* Generate test mbuf data and space for digest */ 2150 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2151 catch_22_quote, QUOTE_512_BYTES, 0); 2152 2153 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2154 DIGEST_BYTE_LENGTH_SHA1); 2155 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2156 2157 /* Setup Cipher Parameters */ 2158 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2159 ut_params->cipher_xform.next = &ut_params->auth_xform; 2160 2161 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2162 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 2163 ut_params->cipher_xform.cipher.key.data = aes_cbc_key; 2164 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2165 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2166 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2167 2168 /* Setup HMAC Parameters */ 2169 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2170 2171 ut_params->auth_xform.next = NULL; 2172 2173 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 2174 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 2175 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; 2176 ut_params->auth_xform.auth.key.data = hmac_sha1_key; 2177 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; 2178 2179 rte_errno = 0; 2180 ut_params->sess = rte_cryptodev_sym_session_create( 2181 ts_params->valid_devs[0], &ut_params->cipher_xform, 2182 ts_params->session_mpool); 2183 if (rte_errno == ENOTSUP) 2184 return TEST_SKIPPED; 2185 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2186 2187 /* Generate crypto op data structure */ 2188 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2189 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2190 TEST_ASSERT_NOT_NULL(ut_params->op, 2191 "Failed to allocate symmetric crypto operation struct"); 2192 2193 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2194 2195 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2196 2197 /* set crypto operation source mbuf */ 2198 sym_op->m_src = ut_params->ibuf; 2199 2200 /* Set crypto operation authentication parameters */ 2201 sym_op->auth.digest.data = ut_params->digest; 2202 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2203 ut_params->ibuf, QUOTE_512_BYTES); 2204 2205 sym_op->auth.data.offset = 0; 2206 sym_op->auth.data.length = QUOTE_512_BYTES; 2207 2208 /* Copy IV at the end of the crypto operation */ 2209 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2210 aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC); 2211 2212 /* Set crypto operation cipher parameters */ 2213 sym_op->cipher.data.offset = 0; 2214 sym_op->cipher.data.length = QUOTE_512_BYTES; 2215 2216 /* Process crypto operation */ 2217 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2218 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2219 ut_params->op); 2220 else 2221 TEST_ASSERT_NOT_NULL( 2222 process_crypto_request(ts_params->valid_devs[0], 2223 ut_params->op), 2224 "failed to process sym crypto op"); 2225 2226 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2227 "crypto op processing failed"); 2228 2229 /* Validate obuf */ 2230 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 2231 uint8_t *); 2232 2233 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, 2234 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 2235 QUOTE_512_BYTES, 2236 "ciphertext data not as expected"); 2237 2238 uint8_t *digest = ciphertext + QUOTE_512_BYTES; 2239 2240 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, 2241 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, 2242 gbl_driver_id == rte_cryptodev_driver_id_get( 2243 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ? 2244 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : 2245 DIGEST_BYTE_LENGTH_SHA1, 2246 "Generated digest data not as expected"); 2247 2248 return TEST_SUCCESS; 2249 } 2250 2251 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ 2252 2253 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) 2254 2255 static uint8_t hmac_sha512_key[] = { 2256 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 2257 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2258 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2259 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60, 2260 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1, 2261 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2262 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76, 2263 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 }; 2264 2265 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = { 2266 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8, 2267 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48, 2268 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8, 2269 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70, 2270 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8, 2271 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E, 2272 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D, 2273 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A }; 2274 2275 2276 2277 static int 2278 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2279 struct crypto_unittest_params *ut_params, 2280 uint8_t *cipher_key, 2281 uint8_t *hmac_key); 2282 2283 static int 2284 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess, 2285 struct crypto_unittest_params *ut_params, 2286 struct crypto_testsuite_params *ts_params, 2287 const uint8_t *cipher, 2288 const uint8_t *digest, 2289 const uint8_t *iv); 2290 2291 2292 static int 2293 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2294 struct crypto_unittest_params *ut_params, 2295 uint8_t *cipher_key, 2296 uint8_t *hmac_key) 2297 { 2298 2299 /* Setup Cipher Parameters */ 2300 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2301 ut_params->cipher_xform.next = NULL; 2302 2303 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2304 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 2305 ut_params->cipher_xform.cipher.key.data = cipher_key; 2306 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2307 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2308 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2309 2310 /* Setup HMAC Parameters */ 2311 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2312 ut_params->auth_xform.next = &ut_params->cipher_xform; 2313 2314 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 2315 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC; 2316 ut_params->auth_xform.auth.key.data = hmac_key; 2317 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512; 2318 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512; 2319 2320 return TEST_SUCCESS; 2321 } 2322 2323 2324 static int 2325 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess, 2326 struct crypto_unittest_params *ut_params, 2327 struct crypto_testsuite_params *ts_params, 2328 const uint8_t *cipher, 2329 const uint8_t *digest, 2330 const uint8_t *iv) 2331 { 2332 /* Generate test mbuf data and digest */ 2333 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2334 (const char *) 2335 cipher, 2336 QUOTE_512_BYTES, 0); 2337 2338 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2339 DIGEST_BYTE_LENGTH_SHA512); 2340 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2341 2342 rte_memcpy(ut_params->digest, 2343 digest, 2344 DIGEST_BYTE_LENGTH_SHA512); 2345 2346 /* Generate Crypto op data structure */ 2347 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2348 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2349 TEST_ASSERT_NOT_NULL(ut_params->op, 2350 "Failed to allocate symmetric crypto operation struct"); 2351 2352 rte_crypto_op_attach_sym_session(ut_params->op, sess); 2353 2354 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2355 2356 /* set crypto operation source mbuf */ 2357 sym_op->m_src = ut_params->ibuf; 2358 2359 sym_op->auth.digest.data = ut_params->digest; 2360 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2361 ut_params->ibuf, QUOTE_512_BYTES); 2362 2363 sym_op->auth.data.offset = 0; 2364 sym_op->auth.data.length = QUOTE_512_BYTES; 2365 2366 /* Copy IV at the end of the crypto operation */ 2367 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2368 iv, CIPHER_IV_LENGTH_AES_CBC); 2369 2370 sym_op->cipher.data.offset = 0; 2371 sym_op->cipher.data.length = QUOTE_512_BYTES; 2372 2373 /* Process crypto operation */ 2374 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2375 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2376 ut_params->op); 2377 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2378 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2379 ut_params->op, 1, 1, 0, 0); 2380 else 2381 TEST_ASSERT_NOT_NULL( 2382 process_crypto_request(ts_params->valid_devs[0], 2383 ut_params->op), 2384 "failed to process sym crypto op"); 2385 2386 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2387 "crypto op processing failed"); 2388 2389 ut_params->obuf = ut_params->op->sym->m_src; 2390 2391 /* Validate obuf */ 2392 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2393 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 2394 catch_22_quote, 2395 QUOTE_512_BYTES, 2396 "Plaintext data not as expected"); 2397 2398 /* Validate obuf */ 2399 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2400 "Digest verification failed"); 2401 2402 return TEST_SUCCESS; 2403 } 2404 2405 /* ***** SNOW 3G Tests ***** */ 2406 static int 2407 create_wireless_algo_hash_session(uint8_t dev_id, 2408 const uint8_t *key, const uint8_t key_len, 2409 const uint8_t iv_len, const uint8_t auth_len, 2410 enum rte_crypto_auth_operation op, 2411 enum rte_crypto_auth_algorithm algo) 2412 { 2413 uint8_t hash_key[key_len]; 2414 2415 struct crypto_testsuite_params *ts_params = &testsuite_params; 2416 struct crypto_unittest_params *ut_params = &unittest_params; 2417 2418 memcpy(hash_key, key, key_len); 2419 2420 debug_hexdump(stdout, "key:", key, key_len); 2421 2422 /* Setup Authentication Parameters */ 2423 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2424 ut_params->auth_xform.next = NULL; 2425 2426 ut_params->auth_xform.auth.op = op; 2427 ut_params->auth_xform.auth.algo = algo; 2428 ut_params->auth_xform.auth.key.length = key_len; 2429 ut_params->auth_xform.auth.key.data = hash_key; 2430 ut_params->auth_xform.auth.digest_length = auth_len; 2431 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 2432 ut_params->auth_xform.auth.iv.length = iv_len; 2433 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2434 &ut_params->auth_xform, ts_params->session_mpool); 2435 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2436 return TEST_SKIPPED; 2437 2438 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2439 return 0; 2440 } 2441 2442 static int 2443 create_wireless_algo_cipher_session(uint8_t dev_id, 2444 enum rte_crypto_cipher_operation op, 2445 enum rte_crypto_cipher_algorithm algo, 2446 const uint8_t *key, const uint8_t key_len, 2447 uint8_t iv_len) 2448 { 2449 uint8_t cipher_key[key_len]; 2450 struct crypto_testsuite_params *ts_params = &testsuite_params; 2451 struct crypto_unittest_params *ut_params = &unittest_params; 2452 2453 memcpy(cipher_key, key, key_len); 2454 2455 /* Setup Cipher Parameters */ 2456 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2457 ut_params->cipher_xform.next = NULL; 2458 2459 ut_params->cipher_xform.cipher.algo = algo; 2460 ut_params->cipher_xform.cipher.op = op; 2461 ut_params->cipher_xform.cipher.key.data = cipher_key; 2462 ut_params->cipher_xform.cipher.key.length = key_len; 2463 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2464 ut_params->cipher_xform.cipher.iv.length = iv_len; 2465 2466 debug_hexdump(stdout, "key:", key, key_len); 2467 2468 /* Create Crypto session */ 2469 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2470 &ut_params->cipher_xform, ts_params->session_mpool); 2471 2472 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2473 return TEST_SKIPPED; 2474 2475 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2476 return 0; 2477 } 2478 2479 static int 2480 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len, 2481 unsigned int cipher_len, 2482 unsigned int cipher_offset) 2483 { 2484 struct crypto_testsuite_params *ts_params = &testsuite_params; 2485 struct crypto_unittest_params *ut_params = &unittest_params; 2486 2487 /* Generate Crypto op data structure */ 2488 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2489 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2490 TEST_ASSERT_NOT_NULL(ut_params->op, 2491 "Failed to allocate pktmbuf offload"); 2492 2493 /* Set crypto operation data parameters */ 2494 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2495 2496 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2497 2498 /* set crypto operation source mbuf */ 2499 sym_op->m_src = ut_params->ibuf; 2500 2501 /* iv */ 2502 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2503 iv, iv_len); 2504 sym_op->cipher.data.length = cipher_len; 2505 sym_op->cipher.data.offset = cipher_offset; 2506 return 0; 2507 } 2508 2509 static int 2510 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len, 2511 unsigned int cipher_len, 2512 unsigned int cipher_offset) 2513 { 2514 struct crypto_testsuite_params *ts_params = &testsuite_params; 2515 struct crypto_unittest_params *ut_params = &unittest_params; 2516 2517 /* Generate Crypto op data structure */ 2518 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2519 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2520 TEST_ASSERT_NOT_NULL(ut_params->op, 2521 "Failed to allocate pktmbuf offload"); 2522 2523 /* Set crypto operation data parameters */ 2524 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2525 2526 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2527 2528 /* set crypto operation source mbuf */ 2529 sym_op->m_src = ut_params->ibuf; 2530 sym_op->m_dst = ut_params->obuf; 2531 2532 /* iv */ 2533 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2534 iv, iv_len); 2535 sym_op->cipher.data.length = cipher_len; 2536 sym_op->cipher.data.offset = cipher_offset; 2537 return 0; 2538 } 2539 2540 static int 2541 create_wireless_algo_cipher_auth_session(uint8_t dev_id, 2542 enum rte_crypto_cipher_operation cipher_op, 2543 enum rte_crypto_auth_operation auth_op, 2544 enum rte_crypto_auth_algorithm auth_algo, 2545 enum rte_crypto_cipher_algorithm cipher_algo, 2546 const uint8_t *key, uint8_t key_len, 2547 uint8_t auth_iv_len, uint8_t auth_len, 2548 uint8_t cipher_iv_len) 2549 2550 { 2551 uint8_t cipher_auth_key[key_len]; 2552 2553 struct crypto_testsuite_params *ts_params = &testsuite_params; 2554 struct crypto_unittest_params *ut_params = &unittest_params; 2555 2556 memcpy(cipher_auth_key, key, key_len); 2557 2558 /* Setup Authentication Parameters */ 2559 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2560 ut_params->auth_xform.next = NULL; 2561 2562 ut_params->auth_xform.auth.op = auth_op; 2563 ut_params->auth_xform.auth.algo = auth_algo; 2564 ut_params->auth_xform.auth.key.length = key_len; 2565 /* Hash key = cipher key */ 2566 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2567 ut_params->auth_xform.auth.digest_length = auth_len; 2568 /* Auth IV will be after cipher IV */ 2569 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2570 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2571 2572 /* Setup Cipher Parameters */ 2573 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2574 ut_params->cipher_xform.next = &ut_params->auth_xform; 2575 2576 ut_params->cipher_xform.cipher.algo = cipher_algo; 2577 ut_params->cipher_xform.cipher.op = cipher_op; 2578 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2579 ut_params->cipher_xform.cipher.key.length = key_len; 2580 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2581 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2582 2583 debug_hexdump(stdout, "key:", key, key_len); 2584 2585 /* Create Crypto session*/ 2586 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2587 &ut_params->cipher_xform, ts_params->session_mpool); 2588 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2589 return TEST_SKIPPED; 2590 2591 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2592 return 0; 2593 } 2594 2595 static int 2596 create_wireless_cipher_auth_session(uint8_t dev_id, 2597 enum rte_crypto_cipher_operation cipher_op, 2598 enum rte_crypto_auth_operation auth_op, 2599 enum rte_crypto_auth_algorithm auth_algo, 2600 enum rte_crypto_cipher_algorithm cipher_algo, 2601 const struct wireless_test_data *tdata) 2602 { 2603 const uint8_t key_len = tdata->key.len; 2604 uint8_t cipher_auth_key[key_len]; 2605 2606 struct crypto_testsuite_params *ts_params = &testsuite_params; 2607 struct crypto_unittest_params *ut_params = &unittest_params; 2608 const uint8_t *key = tdata->key.data; 2609 const uint8_t auth_len = tdata->digest.len; 2610 uint8_t cipher_iv_len = tdata->cipher_iv.len; 2611 uint8_t auth_iv_len = tdata->auth_iv.len; 2612 2613 memcpy(cipher_auth_key, key, key_len); 2614 2615 /* Setup Authentication Parameters */ 2616 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2617 ut_params->auth_xform.next = NULL; 2618 2619 ut_params->auth_xform.auth.op = auth_op; 2620 ut_params->auth_xform.auth.algo = auth_algo; 2621 ut_params->auth_xform.auth.key.length = key_len; 2622 /* Hash key = cipher key */ 2623 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2624 ut_params->auth_xform.auth.digest_length = auth_len; 2625 /* Auth IV will be after cipher IV */ 2626 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2627 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2628 2629 /* Setup Cipher Parameters */ 2630 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2631 ut_params->cipher_xform.next = &ut_params->auth_xform; 2632 2633 ut_params->cipher_xform.cipher.algo = cipher_algo; 2634 ut_params->cipher_xform.cipher.op = cipher_op; 2635 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2636 ut_params->cipher_xform.cipher.key.length = key_len; 2637 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2638 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2639 2640 2641 debug_hexdump(stdout, "key:", key, key_len); 2642 2643 /* Create Crypto session*/ 2644 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2645 &ut_params->cipher_xform, ts_params->session_mpool); 2646 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2647 return TEST_SKIPPED; 2648 2649 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2650 return 0; 2651 } 2652 2653 static int 2654 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id, 2655 const struct wireless_test_data *tdata) 2656 { 2657 return create_wireless_cipher_auth_session(dev_id, 2658 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2659 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3, 2660 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata); 2661 } 2662 2663 static int 2664 create_wireless_algo_auth_cipher_session(uint8_t dev_id, 2665 enum rte_crypto_cipher_operation cipher_op, 2666 enum rte_crypto_auth_operation auth_op, 2667 enum rte_crypto_auth_algorithm auth_algo, 2668 enum rte_crypto_cipher_algorithm cipher_algo, 2669 const uint8_t *key, const uint8_t key_len, 2670 uint8_t auth_iv_len, uint8_t auth_len, 2671 uint8_t cipher_iv_len) 2672 { 2673 uint8_t auth_cipher_key[key_len]; 2674 struct crypto_testsuite_params *ts_params = &testsuite_params; 2675 struct crypto_unittest_params *ut_params = &unittest_params; 2676 2677 memcpy(auth_cipher_key, key, key_len); 2678 2679 /* Setup Authentication Parameters */ 2680 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2681 ut_params->auth_xform.auth.op = auth_op; 2682 ut_params->auth_xform.next = &ut_params->cipher_xform; 2683 ut_params->auth_xform.auth.algo = auth_algo; 2684 ut_params->auth_xform.auth.key.length = key_len; 2685 ut_params->auth_xform.auth.key.data = auth_cipher_key; 2686 ut_params->auth_xform.auth.digest_length = auth_len; 2687 /* Auth IV will be after cipher IV */ 2688 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2689 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2690 2691 /* Setup Cipher Parameters */ 2692 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2693 ut_params->cipher_xform.next = NULL; 2694 ut_params->cipher_xform.cipher.algo = cipher_algo; 2695 ut_params->cipher_xform.cipher.op = cipher_op; 2696 ut_params->cipher_xform.cipher.key.data = auth_cipher_key; 2697 ut_params->cipher_xform.cipher.key.length = key_len; 2698 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2699 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2700 2701 debug_hexdump(stdout, "key:", key, key_len); 2702 2703 /* Create Crypto session*/ 2704 if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 2705 ut_params->auth_xform.next = NULL; 2706 ut_params->cipher_xform.next = &ut_params->auth_xform; 2707 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2708 &ut_params->cipher_xform, ts_params->session_mpool); 2709 } else 2710 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2711 &ut_params->auth_xform, ts_params->session_mpool); 2712 2713 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2714 return TEST_SKIPPED; 2715 2716 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2717 2718 return 0; 2719 } 2720 2721 static int 2722 create_wireless_algo_hash_operation(const uint8_t *auth_tag, 2723 unsigned int auth_tag_len, 2724 const uint8_t *iv, unsigned int iv_len, 2725 unsigned int data_pad_len, 2726 enum rte_crypto_auth_operation op, 2727 unsigned int auth_len, unsigned int auth_offset) 2728 { 2729 struct crypto_testsuite_params *ts_params = &testsuite_params; 2730 2731 struct crypto_unittest_params *ut_params = &unittest_params; 2732 2733 /* Generate Crypto op data structure */ 2734 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2735 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2736 TEST_ASSERT_NOT_NULL(ut_params->op, 2737 "Failed to allocate pktmbuf offload"); 2738 2739 /* Set crypto operation data parameters */ 2740 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2741 2742 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2743 2744 /* set crypto operation source mbuf */ 2745 sym_op->m_src = ut_params->ibuf; 2746 2747 /* iv */ 2748 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2749 iv, iv_len); 2750 /* digest */ 2751 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2752 ut_params->ibuf, auth_tag_len); 2753 2754 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2755 "no room to append auth tag"); 2756 ut_params->digest = sym_op->auth.digest.data; 2757 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2758 ut_params->ibuf, data_pad_len); 2759 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2760 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2761 else 2762 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2763 2764 debug_hexdump(stdout, "digest:", 2765 sym_op->auth.digest.data, 2766 auth_tag_len); 2767 2768 sym_op->auth.data.length = auth_len; 2769 sym_op->auth.data.offset = auth_offset; 2770 2771 return 0; 2772 } 2773 2774 static int 2775 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata, 2776 enum rte_crypto_auth_operation op) 2777 { 2778 struct crypto_testsuite_params *ts_params = &testsuite_params; 2779 struct crypto_unittest_params *ut_params = &unittest_params; 2780 2781 const uint8_t *auth_tag = tdata->digest.data; 2782 const unsigned int auth_tag_len = tdata->digest.len; 2783 unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len); 2784 unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2785 2786 const uint8_t *cipher_iv = tdata->cipher_iv.data; 2787 const uint8_t cipher_iv_len = tdata->cipher_iv.len; 2788 const uint8_t *auth_iv = tdata->auth_iv.data; 2789 const uint8_t auth_iv_len = tdata->auth_iv.len; 2790 const unsigned int cipher_len = tdata->validCipherLenInBits.len; 2791 const unsigned int auth_len = tdata->validAuthLenInBits.len; 2792 2793 /* Generate Crypto op data structure */ 2794 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2795 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2796 TEST_ASSERT_NOT_NULL(ut_params->op, 2797 "Failed to allocate pktmbuf offload"); 2798 /* Set crypto operation data parameters */ 2799 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2800 2801 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2802 2803 /* set crypto operation source mbuf */ 2804 sym_op->m_src = ut_params->ibuf; 2805 2806 /* digest */ 2807 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2808 ut_params->ibuf, auth_tag_len); 2809 2810 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2811 "no room to append auth tag"); 2812 ut_params->digest = sym_op->auth.digest.data; 2813 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2814 ut_params->ibuf, data_pad_len); 2815 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2816 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2817 else 2818 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2819 2820 debug_hexdump(stdout, "digest:", 2821 sym_op->auth.digest.data, 2822 auth_tag_len); 2823 2824 /* Copy cipher and auth IVs at the end of the crypto operation */ 2825 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2826 IV_OFFSET); 2827 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2828 iv_ptr += cipher_iv_len; 2829 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2830 2831 sym_op->cipher.data.length = cipher_len; 2832 sym_op->cipher.data.offset = 0; 2833 sym_op->auth.data.length = auth_len; 2834 sym_op->auth.data.offset = 0; 2835 2836 return 0; 2837 } 2838 2839 static int 2840 create_zuc_cipher_hash_generate_operation( 2841 const struct wireless_test_data *tdata) 2842 { 2843 return create_wireless_cipher_hash_operation(tdata, 2844 RTE_CRYPTO_AUTH_OP_GENERATE); 2845 } 2846 2847 static int 2848 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag, 2849 const unsigned auth_tag_len, 2850 const uint8_t *auth_iv, uint8_t auth_iv_len, 2851 unsigned data_pad_len, 2852 enum rte_crypto_auth_operation op, 2853 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2854 const unsigned cipher_len, const unsigned cipher_offset, 2855 const unsigned auth_len, const unsigned auth_offset) 2856 { 2857 struct crypto_testsuite_params *ts_params = &testsuite_params; 2858 struct crypto_unittest_params *ut_params = &unittest_params; 2859 2860 enum rte_crypto_cipher_algorithm cipher_algo = 2861 ut_params->cipher_xform.cipher.algo; 2862 enum rte_crypto_auth_algorithm auth_algo = 2863 ut_params->auth_xform.auth.algo; 2864 2865 /* Generate Crypto op data structure */ 2866 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2867 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2868 TEST_ASSERT_NOT_NULL(ut_params->op, 2869 "Failed to allocate pktmbuf offload"); 2870 /* Set crypto operation data parameters */ 2871 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2872 2873 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2874 2875 /* set crypto operation source mbuf */ 2876 sym_op->m_src = ut_params->ibuf; 2877 2878 /* digest */ 2879 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2880 ut_params->ibuf, auth_tag_len); 2881 2882 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2883 "no room to append auth tag"); 2884 ut_params->digest = sym_op->auth.digest.data; 2885 2886 if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) { 2887 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2888 ut_params->ibuf, data_pad_len); 2889 } else { 2890 struct rte_mbuf *m = ut_params->ibuf; 2891 unsigned int offset = data_pad_len; 2892 2893 while (offset > m->data_len && m->next != NULL) { 2894 offset -= m->data_len; 2895 m = m->next; 2896 } 2897 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2898 m, offset); 2899 } 2900 2901 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2902 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2903 else 2904 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2905 2906 debug_hexdump(stdout, "digest:", 2907 sym_op->auth.digest.data, 2908 auth_tag_len); 2909 2910 /* Copy cipher and auth IVs at the end of the crypto operation */ 2911 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2912 IV_OFFSET); 2913 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2914 iv_ptr += cipher_iv_len; 2915 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2916 2917 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 2918 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 2919 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 2920 sym_op->cipher.data.length = cipher_len; 2921 sym_op->cipher.data.offset = cipher_offset; 2922 } else { 2923 sym_op->cipher.data.length = cipher_len >> 3; 2924 sym_op->cipher.data.offset = cipher_offset >> 3; 2925 } 2926 2927 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 2928 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 2929 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 2930 sym_op->auth.data.length = auth_len; 2931 sym_op->auth.data.offset = auth_offset; 2932 } else { 2933 sym_op->auth.data.length = auth_len >> 3; 2934 sym_op->auth.data.offset = auth_offset >> 3; 2935 } 2936 2937 return 0; 2938 } 2939 2940 static int 2941 create_wireless_algo_auth_cipher_operation( 2942 const uint8_t *auth_tag, unsigned int auth_tag_len, 2943 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2944 const uint8_t *auth_iv, uint8_t auth_iv_len, 2945 unsigned int data_pad_len, 2946 unsigned int cipher_len, unsigned int cipher_offset, 2947 unsigned int auth_len, unsigned int auth_offset, 2948 uint8_t op_mode, uint8_t do_sgl, uint8_t verify) 2949 { 2950 struct crypto_testsuite_params *ts_params = &testsuite_params; 2951 struct crypto_unittest_params *ut_params = &unittest_params; 2952 2953 enum rte_crypto_cipher_algorithm cipher_algo = 2954 ut_params->cipher_xform.cipher.algo; 2955 enum rte_crypto_auth_algorithm auth_algo = 2956 ut_params->auth_xform.auth.algo; 2957 2958 /* Generate Crypto op data structure */ 2959 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2960 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2961 TEST_ASSERT_NOT_NULL(ut_params->op, 2962 "Failed to allocate pktmbuf offload"); 2963 2964 /* Set crypto operation data parameters */ 2965 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2966 2967 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2968 2969 /* set crypto operation mbufs */ 2970 sym_op->m_src = ut_params->ibuf; 2971 if (op_mode == OUT_OF_PLACE) 2972 sym_op->m_dst = ut_params->obuf; 2973 2974 /* digest */ 2975 if (!do_sgl) { 2976 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset( 2977 (op_mode == IN_PLACE ? 2978 ut_params->ibuf : ut_params->obuf), 2979 uint8_t *, data_pad_len); 2980 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2981 (op_mode == IN_PLACE ? 2982 ut_params->ibuf : ut_params->obuf), 2983 data_pad_len); 2984 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2985 } else { 2986 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3); 2987 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ? 2988 sym_op->m_src : sym_op->m_dst); 2989 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) { 2990 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 2991 sgl_buf = sgl_buf->next; 2992 } 2993 2994 /* The last segment should be large enough to hold full digest */ 2995 if (sgl_buf->data_len < auth_tag_len) { 2996 rte_pktmbuf_free(sgl_buf->next); 2997 sgl_buf->next = NULL; 2998 TEST_ASSERT_NOT_NULL(rte_pktmbuf_append(sgl_buf, 2999 auth_tag_len - sgl_buf->data_len), 3000 "No room to append auth tag"); 3001 } 3002 3003 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf, 3004 uint8_t *, remaining_off); 3005 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf, 3006 remaining_off); 3007 memset(sym_op->auth.digest.data, 0, remaining_off); 3008 while (sgl_buf->next != NULL) { 3009 memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *), 3010 0, rte_pktmbuf_data_len(sgl_buf)); 3011 sgl_buf = sgl_buf->next; 3012 } 3013 } 3014 3015 /* Copy digest for the verification */ 3016 if (verify) 3017 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3018 3019 /* Copy cipher and auth IVs at the end of the crypto operation */ 3020 uint8_t *iv_ptr = rte_crypto_op_ctod_offset( 3021 ut_params->op, uint8_t *, IV_OFFSET); 3022 3023 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 3024 iv_ptr += cipher_iv_len; 3025 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 3026 3027 /* Only copy over the offset data needed from src to dst in OOP, 3028 * if the auth and cipher offsets are not aligned 3029 */ 3030 if (op_mode == OUT_OF_PLACE) { 3031 if (cipher_offset > auth_offset) 3032 rte_memcpy( 3033 rte_pktmbuf_mtod_offset( 3034 sym_op->m_dst, 3035 uint8_t *, auth_offset >> 3), 3036 rte_pktmbuf_mtod_offset( 3037 sym_op->m_src, 3038 uint8_t *, auth_offset >> 3), 3039 ((cipher_offset >> 3) - (auth_offset >> 3))); 3040 } 3041 3042 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 3043 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 3044 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 3045 sym_op->cipher.data.length = cipher_len; 3046 sym_op->cipher.data.offset = cipher_offset; 3047 } else { 3048 sym_op->cipher.data.length = cipher_len >> 3; 3049 sym_op->cipher.data.offset = cipher_offset >> 3; 3050 } 3051 3052 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 3053 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 3054 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 3055 sym_op->auth.data.length = auth_len; 3056 sym_op->auth.data.offset = auth_offset; 3057 } else { 3058 sym_op->auth.data.length = auth_len >> 3; 3059 sym_op->auth.data.offset = auth_offset >> 3; 3060 } 3061 3062 return 0; 3063 } 3064 3065 static int 3066 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) 3067 { 3068 struct crypto_testsuite_params *ts_params = &testsuite_params; 3069 struct crypto_unittest_params *ut_params = &unittest_params; 3070 3071 int retval; 3072 unsigned plaintext_pad_len; 3073 unsigned plaintext_len; 3074 uint8_t *plaintext; 3075 struct rte_cryptodev_info dev_info; 3076 3077 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3078 uint64_t feat_flags = dev_info.feature_flags; 3079 3080 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3081 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3082 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3083 return TEST_SKIPPED; 3084 } 3085 3086 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3087 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3088 printf("Device doesn't support RAW data-path APIs.\n"); 3089 return TEST_SKIPPED; 3090 } 3091 3092 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3093 return TEST_SKIPPED; 3094 3095 /* Verify the capabilities */ 3096 struct rte_cryptodev_sym_capability_idx cap_idx; 3097 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3098 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3099 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3100 &cap_idx) == NULL) 3101 return TEST_SKIPPED; 3102 3103 /* Create SNOW 3G session */ 3104 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3105 tdata->key.data, tdata->key.len, 3106 tdata->auth_iv.len, tdata->digest.len, 3107 RTE_CRYPTO_AUTH_OP_GENERATE, 3108 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3109 if (retval < 0) 3110 return retval; 3111 3112 /* alloc mbuf and set payload */ 3113 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3114 3115 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3116 rte_pktmbuf_tailroom(ut_params->ibuf)); 3117 3118 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3119 /* Append data which is padded to a multiple of */ 3120 /* the algorithms block size */ 3121 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3122 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3123 plaintext_pad_len); 3124 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3125 3126 /* Create SNOW 3G operation */ 3127 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3128 tdata->auth_iv.data, tdata->auth_iv.len, 3129 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3130 tdata->validAuthLenInBits.len, 3131 0); 3132 if (retval < 0) 3133 return retval; 3134 3135 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3136 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3137 ut_params->op, 0, 1, 1, 0); 3138 else 3139 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3140 ut_params->op); 3141 ut_params->obuf = ut_params->op->sym->m_src; 3142 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3143 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3144 + plaintext_pad_len; 3145 3146 /* Validate obuf */ 3147 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3148 ut_params->digest, 3149 tdata->digest.data, 3150 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 3151 "SNOW 3G Generated auth tag not as expected"); 3152 3153 return 0; 3154 } 3155 3156 static int 3157 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) 3158 { 3159 struct crypto_testsuite_params *ts_params = &testsuite_params; 3160 struct crypto_unittest_params *ut_params = &unittest_params; 3161 3162 int retval; 3163 unsigned plaintext_pad_len; 3164 unsigned plaintext_len; 3165 uint8_t *plaintext; 3166 struct rte_cryptodev_info dev_info; 3167 3168 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3169 uint64_t feat_flags = dev_info.feature_flags; 3170 3171 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3172 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3173 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3174 return TEST_SKIPPED; 3175 } 3176 3177 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3178 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3179 printf("Device doesn't support RAW data-path APIs.\n"); 3180 return TEST_SKIPPED; 3181 } 3182 3183 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3184 return TEST_SKIPPED; 3185 3186 /* Verify the capabilities */ 3187 struct rte_cryptodev_sym_capability_idx cap_idx; 3188 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3189 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3190 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3191 &cap_idx) == NULL) 3192 return TEST_SKIPPED; 3193 3194 /* Create SNOW 3G session */ 3195 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3196 tdata->key.data, tdata->key.len, 3197 tdata->auth_iv.len, tdata->digest.len, 3198 RTE_CRYPTO_AUTH_OP_VERIFY, 3199 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3200 if (retval < 0) 3201 return retval; 3202 /* alloc mbuf and set payload */ 3203 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3204 3205 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3206 rte_pktmbuf_tailroom(ut_params->ibuf)); 3207 3208 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3209 /* Append data which is padded to a multiple of */ 3210 /* the algorithms block size */ 3211 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3212 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3213 plaintext_pad_len); 3214 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3215 3216 /* Create SNOW 3G operation */ 3217 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3218 tdata->digest.len, 3219 tdata->auth_iv.data, tdata->auth_iv.len, 3220 plaintext_pad_len, 3221 RTE_CRYPTO_AUTH_OP_VERIFY, 3222 tdata->validAuthLenInBits.len, 3223 0); 3224 if (retval < 0) 3225 return retval; 3226 3227 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3228 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3229 ut_params->op, 0, 1, 1, 0); 3230 else 3231 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3232 ut_params->op); 3233 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3234 ut_params->obuf = ut_params->op->sym->m_src; 3235 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3236 + plaintext_pad_len; 3237 3238 /* Validate obuf */ 3239 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3240 return 0; 3241 else 3242 return -1; 3243 3244 return 0; 3245 } 3246 3247 static int 3248 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata) 3249 { 3250 struct crypto_testsuite_params *ts_params = &testsuite_params; 3251 struct crypto_unittest_params *ut_params = &unittest_params; 3252 3253 int retval; 3254 unsigned plaintext_pad_len; 3255 unsigned plaintext_len; 3256 uint8_t *plaintext; 3257 struct rte_cryptodev_info dev_info; 3258 3259 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3260 uint64_t feat_flags = dev_info.feature_flags; 3261 3262 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3263 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3264 printf("Device doesn't support RAW data-path APIs.\n"); 3265 return TEST_SKIPPED; 3266 } 3267 3268 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3269 return TEST_SKIPPED; 3270 3271 /* Verify the capabilities */ 3272 struct rte_cryptodev_sym_capability_idx cap_idx; 3273 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3274 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3275 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3276 &cap_idx) == NULL) 3277 return TEST_SKIPPED; 3278 3279 /* Create KASUMI session */ 3280 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3281 tdata->key.data, tdata->key.len, 3282 0, tdata->digest.len, 3283 RTE_CRYPTO_AUTH_OP_GENERATE, 3284 RTE_CRYPTO_AUTH_KASUMI_F9); 3285 if (retval < 0) 3286 return retval; 3287 3288 /* alloc mbuf and set payload */ 3289 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3290 3291 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3292 rte_pktmbuf_tailroom(ut_params->ibuf)); 3293 3294 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3295 /* Append data which is padded to a multiple of */ 3296 /* the algorithms block size */ 3297 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3298 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3299 plaintext_pad_len); 3300 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3301 3302 /* Create KASUMI operation */ 3303 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3304 NULL, 0, 3305 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3306 tdata->plaintext.len, 3307 0); 3308 if (retval < 0) 3309 return retval; 3310 3311 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3312 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 3313 ut_params->op); 3314 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3315 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3316 ut_params->op, 0, 1, 1, 0); 3317 else 3318 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3319 ut_params->op); 3320 3321 ut_params->obuf = ut_params->op->sym->m_src; 3322 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3323 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3324 + plaintext_pad_len; 3325 3326 /* Validate obuf */ 3327 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3328 ut_params->digest, 3329 tdata->digest.data, 3330 DIGEST_BYTE_LENGTH_KASUMI_F9, 3331 "KASUMI Generated auth tag not as expected"); 3332 3333 return 0; 3334 } 3335 3336 static int 3337 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata) 3338 { 3339 struct crypto_testsuite_params *ts_params = &testsuite_params; 3340 struct crypto_unittest_params *ut_params = &unittest_params; 3341 3342 int retval; 3343 unsigned plaintext_pad_len; 3344 unsigned plaintext_len; 3345 uint8_t *plaintext; 3346 struct rte_cryptodev_info dev_info; 3347 3348 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3349 uint64_t feat_flags = dev_info.feature_flags; 3350 3351 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3352 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3353 printf("Device doesn't support RAW data-path APIs.\n"); 3354 return TEST_SKIPPED; 3355 } 3356 3357 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3358 return TEST_SKIPPED; 3359 3360 /* Verify the capabilities */ 3361 struct rte_cryptodev_sym_capability_idx cap_idx; 3362 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3363 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3364 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3365 &cap_idx) == NULL) 3366 return TEST_SKIPPED; 3367 3368 /* Create KASUMI session */ 3369 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3370 tdata->key.data, tdata->key.len, 3371 0, tdata->digest.len, 3372 RTE_CRYPTO_AUTH_OP_VERIFY, 3373 RTE_CRYPTO_AUTH_KASUMI_F9); 3374 if (retval < 0) 3375 return retval; 3376 /* alloc mbuf and set payload */ 3377 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3378 3379 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3380 rte_pktmbuf_tailroom(ut_params->ibuf)); 3381 3382 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3383 /* Append data which is padded to a multiple */ 3384 /* of the algorithms block size */ 3385 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3386 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3387 plaintext_pad_len); 3388 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3389 3390 /* Create KASUMI operation */ 3391 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3392 tdata->digest.len, 3393 NULL, 0, 3394 plaintext_pad_len, 3395 RTE_CRYPTO_AUTH_OP_VERIFY, 3396 tdata->plaintext.len, 3397 0); 3398 if (retval < 0) 3399 return retval; 3400 3401 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3402 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3403 ut_params->op, 0, 1, 1, 0); 3404 else 3405 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3406 ut_params->op); 3407 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3408 ut_params->obuf = ut_params->op->sym->m_src; 3409 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3410 + plaintext_pad_len; 3411 3412 /* Validate obuf */ 3413 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3414 return 0; 3415 else 3416 return -1; 3417 3418 return 0; 3419 } 3420 3421 static int 3422 test_snow3g_hash_generate_test_case_1(void) 3423 { 3424 return test_snow3g_authentication(&snow3g_hash_test_case_1); 3425 } 3426 3427 static int 3428 test_snow3g_hash_generate_test_case_2(void) 3429 { 3430 return test_snow3g_authentication(&snow3g_hash_test_case_2); 3431 } 3432 3433 static int 3434 test_snow3g_hash_generate_test_case_3(void) 3435 { 3436 return test_snow3g_authentication(&snow3g_hash_test_case_3); 3437 } 3438 3439 static int 3440 test_snow3g_hash_generate_test_case_4(void) 3441 { 3442 return test_snow3g_authentication(&snow3g_hash_test_case_4); 3443 } 3444 3445 static int 3446 test_snow3g_hash_generate_test_case_5(void) 3447 { 3448 return test_snow3g_authentication(&snow3g_hash_test_case_5); 3449 } 3450 3451 static int 3452 test_snow3g_hash_generate_test_case_6(void) 3453 { 3454 return test_snow3g_authentication(&snow3g_hash_test_case_6); 3455 } 3456 3457 static int 3458 test_snow3g_hash_verify_test_case_1(void) 3459 { 3460 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1); 3461 3462 } 3463 3464 static int 3465 test_snow3g_hash_verify_test_case_2(void) 3466 { 3467 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2); 3468 } 3469 3470 static int 3471 test_snow3g_hash_verify_test_case_3(void) 3472 { 3473 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3); 3474 } 3475 3476 static int 3477 test_snow3g_hash_verify_test_case_4(void) 3478 { 3479 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4); 3480 } 3481 3482 static int 3483 test_snow3g_hash_verify_test_case_5(void) 3484 { 3485 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5); 3486 } 3487 3488 static int 3489 test_snow3g_hash_verify_test_case_6(void) 3490 { 3491 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6); 3492 } 3493 3494 static int 3495 test_kasumi_hash_generate_test_case_1(void) 3496 { 3497 return test_kasumi_authentication(&kasumi_hash_test_case_1); 3498 } 3499 3500 static int 3501 test_kasumi_hash_generate_test_case_2(void) 3502 { 3503 return test_kasumi_authentication(&kasumi_hash_test_case_2); 3504 } 3505 3506 static int 3507 test_kasumi_hash_generate_test_case_3(void) 3508 { 3509 return test_kasumi_authentication(&kasumi_hash_test_case_3); 3510 } 3511 3512 static int 3513 test_kasumi_hash_generate_test_case_4(void) 3514 { 3515 return test_kasumi_authentication(&kasumi_hash_test_case_4); 3516 } 3517 3518 static int 3519 test_kasumi_hash_generate_test_case_5(void) 3520 { 3521 return test_kasumi_authentication(&kasumi_hash_test_case_5); 3522 } 3523 3524 static int 3525 test_kasumi_hash_generate_test_case_6(void) 3526 { 3527 return test_kasumi_authentication(&kasumi_hash_test_case_6); 3528 } 3529 3530 static int 3531 test_kasumi_hash_verify_test_case_1(void) 3532 { 3533 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1); 3534 } 3535 3536 static int 3537 test_kasumi_hash_verify_test_case_2(void) 3538 { 3539 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2); 3540 } 3541 3542 static int 3543 test_kasumi_hash_verify_test_case_3(void) 3544 { 3545 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3); 3546 } 3547 3548 static int 3549 test_kasumi_hash_verify_test_case_4(void) 3550 { 3551 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4); 3552 } 3553 3554 static int 3555 test_kasumi_hash_verify_test_case_5(void) 3556 { 3557 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5); 3558 } 3559 3560 static int 3561 test_kasumi_encryption(const struct kasumi_test_data *tdata) 3562 { 3563 struct crypto_testsuite_params *ts_params = &testsuite_params; 3564 struct crypto_unittest_params *ut_params = &unittest_params; 3565 3566 int retval; 3567 uint8_t *plaintext, *ciphertext; 3568 unsigned plaintext_pad_len; 3569 unsigned plaintext_len; 3570 struct rte_cryptodev_info dev_info; 3571 3572 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3573 uint64_t feat_flags = dev_info.feature_flags; 3574 3575 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3576 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3577 printf("Device doesn't support RAW data-path APIs.\n"); 3578 return TEST_SKIPPED; 3579 } 3580 3581 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3582 return TEST_SKIPPED; 3583 3584 /* Verify the capabilities */ 3585 struct rte_cryptodev_sym_capability_idx cap_idx; 3586 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3587 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3588 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3589 &cap_idx) == NULL) 3590 return TEST_SKIPPED; 3591 3592 /* Create KASUMI session */ 3593 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3594 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3595 RTE_CRYPTO_CIPHER_KASUMI_F8, 3596 tdata->key.data, tdata->key.len, 3597 tdata->cipher_iv.len); 3598 if (retval < 0) 3599 return retval; 3600 3601 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3602 3603 /* Clear mbuf payload */ 3604 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3605 rte_pktmbuf_tailroom(ut_params->ibuf)); 3606 3607 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3608 /* Append data which is padded to a multiple */ 3609 /* of the algorithms block size */ 3610 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3611 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3612 plaintext_pad_len); 3613 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3614 3615 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3616 3617 /* Create KASUMI operation */ 3618 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3619 tdata->cipher_iv.len, 3620 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3621 tdata->validCipherOffsetInBits.len); 3622 if (retval < 0) 3623 return retval; 3624 3625 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3626 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3627 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3628 else 3629 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3630 ut_params->op); 3631 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3632 3633 ut_params->obuf = ut_params->op->sym->m_dst; 3634 if (ut_params->obuf) 3635 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3636 else 3637 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3638 3639 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3640 3641 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3642 (tdata->validCipherOffsetInBits.len >> 3); 3643 /* Validate obuf */ 3644 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3645 ciphertext, 3646 reference_ciphertext, 3647 tdata->validCipherLenInBits.len, 3648 "KASUMI Ciphertext data not as expected"); 3649 return 0; 3650 } 3651 3652 static int 3653 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata) 3654 { 3655 struct crypto_testsuite_params *ts_params = &testsuite_params; 3656 struct crypto_unittest_params *ut_params = &unittest_params; 3657 3658 int retval; 3659 3660 unsigned int plaintext_pad_len; 3661 unsigned int plaintext_len; 3662 3663 uint8_t buffer[10000]; 3664 const uint8_t *ciphertext; 3665 3666 struct rte_cryptodev_info dev_info; 3667 3668 /* Verify the capabilities */ 3669 struct rte_cryptodev_sym_capability_idx cap_idx; 3670 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3671 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3672 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3673 &cap_idx) == NULL) 3674 return TEST_SKIPPED; 3675 3676 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3677 3678 uint64_t feat_flags = dev_info.feature_flags; 3679 3680 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 3681 printf("Device doesn't support in-place scatter-gather. " 3682 "Test Skipped.\n"); 3683 return TEST_SKIPPED; 3684 } 3685 3686 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3687 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3688 printf("Device doesn't support RAW data-path APIs.\n"); 3689 return TEST_SKIPPED; 3690 } 3691 3692 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3693 return TEST_SKIPPED; 3694 3695 /* Create KASUMI session */ 3696 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3697 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3698 RTE_CRYPTO_CIPHER_KASUMI_F8, 3699 tdata->key.data, tdata->key.len, 3700 tdata->cipher_iv.len); 3701 if (retval < 0) 3702 return retval; 3703 3704 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3705 3706 3707 /* Append data which is padded to a multiple */ 3708 /* of the algorithms block size */ 3709 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3710 3711 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3712 plaintext_pad_len, 10, 0); 3713 3714 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3715 3716 /* Create KASUMI operation */ 3717 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3718 tdata->cipher_iv.len, 3719 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3720 tdata->validCipherOffsetInBits.len); 3721 if (retval < 0) 3722 return retval; 3723 3724 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3725 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3726 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3727 else 3728 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3729 ut_params->op); 3730 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3731 3732 ut_params->obuf = ut_params->op->sym->m_dst; 3733 3734 if (ut_params->obuf) 3735 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3736 plaintext_len, buffer); 3737 else 3738 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3739 tdata->validCipherOffsetInBits.len >> 3, 3740 plaintext_len, buffer); 3741 3742 /* Validate obuf */ 3743 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3744 3745 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3746 (tdata->validCipherOffsetInBits.len >> 3); 3747 /* Validate obuf */ 3748 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3749 ciphertext, 3750 reference_ciphertext, 3751 tdata->validCipherLenInBits.len, 3752 "KASUMI Ciphertext data not as expected"); 3753 return 0; 3754 } 3755 3756 static int 3757 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata) 3758 { 3759 struct crypto_testsuite_params *ts_params = &testsuite_params; 3760 struct crypto_unittest_params *ut_params = &unittest_params; 3761 3762 int retval; 3763 uint8_t *plaintext, *ciphertext; 3764 unsigned plaintext_pad_len; 3765 unsigned plaintext_len; 3766 3767 /* Verify the capabilities */ 3768 struct rte_cryptodev_sym_capability_idx cap_idx; 3769 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3770 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3771 /* Data-path service does not support OOP */ 3772 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3773 &cap_idx) == NULL) 3774 return TEST_SKIPPED; 3775 3776 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3777 return TEST_SKIPPED; 3778 3779 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3780 return TEST_SKIPPED; 3781 3782 /* Create KASUMI session */ 3783 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3784 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3785 RTE_CRYPTO_CIPHER_KASUMI_F8, 3786 tdata->key.data, tdata->key.len, 3787 tdata->cipher_iv.len); 3788 if (retval < 0) 3789 return retval; 3790 3791 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3792 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3793 3794 /* Clear mbuf payload */ 3795 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3796 rte_pktmbuf_tailroom(ut_params->ibuf)); 3797 3798 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3799 /* Append data which is padded to a multiple */ 3800 /* of the algorithms block size */ 3801 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3802 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3803 plaintext_pad_len); 3804 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3805 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3806 3807 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3808 3809 /* Create KASUMI operation */ 3810 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3811 tdata->cipher_iv.len, 3812 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3813 tdata->validCipherOffsetInBits.len); 3814 if (retval < 0) 3815 return retval; 3816 3817 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3818 ut_params->op); 3819 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3820 3821 ut_params->obuf = ut_params->op->sym->m_dst; 3822 if (ut_params->obuf) 3823 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3824 else 3825 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3826 3827 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3828 3829 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3830 (tdata->validCipherOffsetInBits.len >> 3); 3831 /* Validate obuf */ 3832 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3833 ciphertext, 3834 reference_ciphertext, 3835 tdata->validCipherLenInBits.len, 3836 "KASUMI Ciphertext data not as expected"); 3837 return 0; 3838 } 3839 3840 static int 3841 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata) 3842 { 3843 struct crypto_testsuite_params *ts_params = &testsuite_params; 3844 struct crypto_unittest_params *ut_params = &unittest_params; 3845 3846 int retval; 3847 unsigned int plaintext_pad_len; 3848 unsigned int plaintext_len; 3849 3850 const uint8_t *ciphertext; 3851 uint8_t buffer[2048]; 3852 3853 struct rte_cryptodev_info dev_info; 3854 3855 /* Verify the capabilities */ 3856 struct rte_cryptodev_sym_capability_idx cap_idx; 3857 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3858 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3859 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3860 &cap_idx) == NULL) 3861 return TEST_SKIPPED; 3862 3863 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3864 return TEST_SKIPPED; 3865 3866 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3867 return TEST_SKIPPED; 3868 3869 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3870 3871 uint64_t feat_flags = dev_info.feature_flags; 3872 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 3873 printf("Device doesn't support out-of-place scatter-gather " 3874 "in both input and output mbufs. " 3875 "Test Skipped.\n"); 3876 return TEST_SKIPPED; 3877 } 3878 3879 /* Create KASUMI session */ 3880 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3881 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3882 RTE_CRYPTO_CIPHER_KASUMI_F8, 3883 tdata->key.data, tdata->key.len, 3884 tdata->cipher_iv.len); 3885 if (retval < 0) 3886 return retval; 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 3893 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3894 plaintext_pad_len, 10, 0); 3895 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 3896 plaintext_pad_len, 3, 0); 3897 3898 /* Append data which is padded to a multiple */ 3899 /* of the algorithms block size */ 3900 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3901 3902 /* Create KASUMI operation */ 3903 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3904 tdata->cipher_iv.len, 3905 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3906 tdata->validCipherOffsetInBits.len); 3907 if (retval < 0) 3908 return retval; 3909 3910 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3911 ut_params->op); 3912 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3913 3914 ut_params->obuf = ut_params->op->sym->m_dst; 3915 if (ut_params->obuf) 3916 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3917 plaintext_pad_len, buffer); 3918 else 3919 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3920 tdata->validCipherOffsetInBits.len >> 3, 3921 plaintext_pad_len, buffer); 3922 3923 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3924 (tdata->validCipherOffsetInBits.len >> 3); 3925 /* Validate obuf */ 3926 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3927 ciphertext, 3928 reference_ciphertext, 3929 tdata->validCipherLenInBits.len, 3930 "KASUMI Ciphertext data not as expected"); 3931 return 0; 3932 } 3933 3934 3935 static int 3936 test_kasumi_decryption_oop(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 uint8_t *ciphertext, *plaintext; 3943 unsigned ciphertext_pad_len; 3944 unsigned ciphertext_len; 3945 3946 /* Verify the capabilities */ 3947 struct rte_cryptodev_sym_capability_idx cap_idx; 3948 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3949 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3950 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3951 &cap_idx) == NULL) 3952 return TEST_SKIPPED; 3953 3954 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3955 return TEST_SKIPPED; 3956 3957 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3958 return TEST_SKIPPED; 3959 3960 /* Create KASUMI session */ 3961 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3962 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3963 RTE_CRYPTO_CIPHER_KASUMI_F8, 3964 tdata->key.data, tdata->key.len, 3965 tdata->cipher_iv.len); 3966 if (retval < 0) 3967 return retval; 3968 3969 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3970 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3971 3972 /* Clear mbuf payload */ 3973 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3974 rte_pktmbuf_tailroom(ut_params->ibuf)); 3975 3976 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 3977 /* Append data which is padded to a multiple */ 3978 /* of the algorithms block size */ 3979 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 3980 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3981 ciphertext_pad_len); 3982 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 3983 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 3984 3985 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 3986 3987 /* Create KASUMI operation */ 3988 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3989 tdata->cipher_iv.len, 3990 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3991 tdata->validCipherOffsetInBits.len); 3992 if (retval < 0) 3993 return retval; 3994 3995 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3996 ut_params->op); 3997 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3998 3999 ut_params->obuf = ut_params->op->sym->m_dst; 4000 if (ut_params->obuf) 4001 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4002 else 4003 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4004 4005 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4006 4007 const uint8_t *reference_plaintext = tdata->plaintext.data + 4008 (tdata->validCipherOffsetInBits.len >> 3); 4009 /* Validate obuf */ 4010 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4011 plaintext, 4012 reference_plaintext, 4013 tdata->validCipherLenInBits.len, 4014 "KASUMI Plaintext data not as expected"); 4015 return 0; 4016 } 4017 4018 static int 4019 test_kasumi_decryption(const struct kasumi_test_data *tdata) 4020 { 4021 struct crypto_testsuite_params *ts_params = &testsuite_params; 4022 struct crypto_unittest_params *ut_params = &unittest_params; 4023 4024 int retval; 4025 uint8_t *ciphertext, *plaintext; 4026 unsigned ciphertext_pad_len; 4027 unsigned ciphertext_len; 4028 struct rte_cryptodev_info dev_info; 4029 4030 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4031 uint64_t feat_flags = dev_info.feature_flags; 4032 4033 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4034 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4035 printf("Device doesn't support RAW data-path APIs.\n"); 4036 return TEST_SKIPPED; 4037 } 4038 4039 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4040 return TEST_SKIPPED; 4041 4042 /* Verify the capabilities */ 4043 struct rte_cryptodev_sym_capability_idx cap_idx; 4044 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4045 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4046 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4047 &cap_idx) == NULL) 4048 return TEST_SKIPPED; 4049 4050 /* Create KASUMI session */ 4051 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4052 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4053 RTE_CRYPTO_CIPHER_KASUMI_F8, 4054 tdata->key.data, tdata->key.len, 4055 tdata->cipher_iv.len); 4056 if (retval < 0) 4057 return retval; 4058 4059 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4060 4061 /* Clear mbuf payload */ 4062 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4063 rte_pktmbuf_tailroom(ut_params->ibuf)); 4064 4065 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4066 /* Append data which is padded to a multiple */ 4067 /* of the algorithms block size */ 4068 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4069 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4070 ciphertext_pad_len); 4071 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4072 4073 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4074 4075 /* Create KASUMI operation */ 4076 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4077 tdata->cipher_iv.len, 4078 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4079 tdata->validCipherOffsetInBits.len); 4080 if (retval < 0) 4081 return retval; 4082 4083 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4084 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4085 ut_params->op, 1, 0, 1, 0); 4086 else 4087 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4088 ut_params->op); 4089 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4090 4091 ut_params->obuf = ut_params->op->sym->m_dst; 4092 if (ut_params->obuf) 4093 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4094 else 4095 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4096 4097 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4098 4099 const uint8_t *reference_plaintext = tdata->plaintext.data + 4100 (tdata->validCipherOffsetInBits.len >> 3); 4101 /* Validate obuf */ 4102 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4103 plaintext, 4104 reference_plaintext, 4105 tdata->validCipherLenInBits.len, 4106 "KASUMI Plaintext data not as expected"); 4107 return 0; 4108 } 4109 4110 static int 4111 test_snow3g_encryption(const struct snow3g_test_data *tdata) 4112 { 4113 struct crypto_testsuite_params *ts_params = &testsuite_params; 4114 struct crypto_unittest_params *ut_params = &unittest_params; 4115 4116 int retval; 4117 uint8_t *plaintext, *ciphertext; 4118 unsigned plaintext_pad_len; 4119 unsigned plaintext_len; 4120 struct rte_cryptodev_info dev_info; 4121 4122 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4123 uint64_t feat_flags = dev_info.feature_flags; 4124 4125 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4126 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4127 printf("Device doesn't support RAW data-path APIs.\n"); 4128 return TEST_SKIPPED; 4129 } 4130 4131 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4132 return TEST_SKIPPED; 4133 4134 /* Verify the capabilities */ 4135 struct rte_cryptodev_sym_capability_idx cap_idx; 4136 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4137 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4138 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4139 &cap_idx) == NULL) 4140 return TEST_SKIPPED; 4141 4142 /* Create SNOW 3G session */ 4143 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4144 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4145 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4146 tdata->key.data, tdata->key.len, 4147 tdata->cipher_iv.len); 4148 if (retval < 0) 4149 return retval; 4150 4151 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4152 4153 /* Clear mbuf payload */ 4154 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4155 rte_pktmbuf_tailroom(ut_params->ibuf)); 4156 4157 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4158 /* Append data which is padded to a multiple of */ 4159 /* the algorithms block size */ 4160 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4161 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4162 plaintext_pad_len); 4163 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4164 4165 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4166 4167 /* Create SNOW 3G operation */ 4168 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4169 tdata->cipher_iv.len, 4170 tdata->validCipherLenInBits.len, 4171 0); 4172 if (retval < 0) 4173 return retval; 4174 4175 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4176 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4177 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4178 else 4179 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4180 ut_params->op); 4181 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4182 4183 ut_params->obuf = ut_params->op->sym->m_dst; 4184 if (ut_params->obuf) 4185 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4186 else 4187 ciphertext = plaintext; 4188 4189 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4190 4191 /* Validate obuf */ 4192 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4193 ciphertext, 4194 tdata->ciphertext.data, 4195 tdata->validDataLenInBits.len, 4196 "SNOW 3G Ciphertext data not as expected"); 4197 return 0; 4198 } 4199 4200 4201 static int 4202 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) 4203 { 4204 struct crypto_testsuite_params *ts_params = &testsuite_params; 4205 struct crypto_unittest_params *ut_params = &unittest_params; 4206 uint8_t *plaintext, *ciphertext; 4207 4208 int retval; 4209 unsigned plaintext_pad_len; 4210 unsigned plaintext_len; 4211 struct rte_cryptodev_info dev_info; 4212 4213 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4214 uint64_t feat_flags = dev_info.feature_flags; 4215 4216 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4217 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4218 printf("Device does not support RAW data-path APIs.\n"); 4219 return -ENOTSUP; 4220 } 4221 4222 /* Verify the capabilities */ 4223 struct rte_cryptodev_sym_capability_idx cap_idx; 4224 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4225 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4226 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4227 &cap_idx) == NULL) 4228 return TEST_SKIPPED; 4229 4230 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4231 return TEST_SKIPPED; 4232 4233 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4234 return TEST_SKIPPED; 4235 4236 /* Create SNOW 3G session */ 4237 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4238 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4239 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4240 tdata->key.data, tdata->key.len, 4241 tdata->cipher_iv.len); 4242 if (retval < 0) 4243 return retval; 4244 4245 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4246 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4247 4248 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4249 "Failed to allocate input buffer in mempool"); 4250 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4251 "Failed to allocate output buffer in mempool"); 4252 4253 /* Clear mbuf payload */ 4254 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4255 rte_pktmbuf_tailroom(ut_params->ibuf)); 4256 4257 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4258 /* Append data which is padded to a multiple of */ 4259 /* the algorithms block size */ 4260 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4261 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4262 plaintext_pad_len); 4263 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4264 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4265 4266 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4267 4268 /* Create SNOW 3G operation */ 4269 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4270 tdata->cipher_iv.len, 4271 tdata->validCipherLenInBits.len, 4272 0); 4273 if (retval < 0) 4274 return retval; 4275 4276 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4277 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4278 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4279 else 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 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4287 else 4288 ciphertext = plaintext; 4289 4290 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4291 4292 /* Validate obuf */ 4293 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4294 ciphertext, 4295 tdata->ciphertext.data, 4296 tdata->validDataLenInBits.len, 4297 "SNOW 3G Ciphertext data not as expected"); 4298 return 0; 4299 } 4300 4301 static int 4302 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata, 4303 uint8_t sgl_in, uint8_t sgl_out) 4304 { 4305 struct crypto_testsuite_params *ts_params = &testsuite_params; 4306 struct crypto_unittest_params *ut_params = &unittest_params; 4307 4308 int retval; 4309 unsigned int plaintext_pad_len; 4310 unsigned int plaintext_len; 4311 uint8_t buffer[10000]; 4312 const uint8_t *ciphertext; 4313 4314 struct rte_cryptodev_info dev_info; 4315 4316 /* Verify the capabilities */ 4317 struct rte_cryptodev_sym_capability_idx cap_idx; 4318 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4319 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4320 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4321 &cap_idx) == NULL) 4322 return TEST_SKIPPED; 4323 4324 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4325 return TEST_SKIPPED; 4326 4327 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4328 return TEST_SKIPPED; 4329 4330 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4331 4332 uint64_t feat_flags = dev_info.feature_flags; 4333 4334 if (((sgl_in && sgl_out) && !(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 4335 || ((!sgl_in && sgl_out) && 4336 !(feat_flags & RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 4337 || ((sgl_in && !sgl_out) && 4338 !(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))) { 4339 printf("Device doesn't support out-of-place scatter gather type. " 4340 "Test Skipped.\n"); 4341 return TEST_SKIPPED; 4342 } 4343 4344 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4345 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4346 printf("Device does not support RAW data-path APIs.\n"); 4347 return -ENOTSUP; 4348 } 4349 4350 /* Create SNOW 3G session */ 4351 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4352 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4353 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4354 tdata->key.data, tdata->key.len, 4355 tdata->cipher_iv.len); 4356 if (retval < 0) 4357 return retval; 4358 4359 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4360 /* Append data which is padded to a multiple of */ 4361 /* the algorithms block size */ 4362 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4363 4364 if (sgl_in) 4365 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4366 plaintext_pad_len, 10, 0); 4367 else { 4368 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4369 rte_pktmbuf_append(ut_params->ibuf, plaintext_pad_len); 4370 } 4371 4372 if (sgl_out) 4373 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4374 plaintext_pad_len, 3, 0); 4375 else { 4376 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4377 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4378 } 4379 4380 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4381 "Failed to allocate input buffer in mempool"); 4382 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4383 "Failed to allocate output buffer in mempool"); 4384 4385 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 4386 4387 /* Create SNOW 3G operation */ 4388 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4389 tdata->cipher_iv.len, 4390 tdata->validCipherLenInBits.len, 4391 0); 4392 if (retval < 0) 4393 return retval; 4394 4395 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4396 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4397 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4398 else 4399 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4400 ut_params->op); 4401 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4402 4403 ut_params->obuf = ut_params->op->sym->m_dst; 4404 if (ut_params->obuf) 4405 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4406 plaintext_len, buffer); 4407 else 4408 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4409 plaintext_len, buffer); 4410 4411 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4412 4413 /* Validate obuf */ 4414 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4415 ciphertext, 4416 tdata->ciphertext.data, 4417 tdata->validDataLenInBits.len, 4418 "SNOW 3G Ciphertext data not as expected"); 4419 4420 return 0; 4421 } 4422 4423 /* Shift right a buffer by "offset" bits, "offset" < 8 */ 4424 static void 4425 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) 4426 { 4427 uint8_t curr_byte, prev_byte; 4428 uint32_t length_in_bytes = ceil_byte_length(length + offset); 4429 uint8_t lower_byte_mask = (1 << offset) - 1; 4430 unsigned i; 4431 4432 prev_byte = buffer[0]; 4433 buffer[0] >>= offset; 4434 4435 for (i = 1; i < length_in_bytes; i++) { 4436 curr_byte = buffer[i]; 4437 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | 4438 (curr_byte >> offset); 4439 prev_byte = curr_byte; 4440 } 4441 } 4442 4443 static int 4444 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) 4445 { 4446 struct crypto_testsuite_params *ts_params = &testsuite_params; 4447 struct crypto_unittest_params *ut_params = &unittest_params; 4448 uint8_t *plaintext, *ciphertext; 4449 int retval; 4450 uint32_t plaintext_len; 4451 uint32_t plaintext_pad_len; 4452 uint8_t extra_offset = 4; 4453 uint8_t *expected_ciphertext_shifted; 4454 struct rte_cryptodev_info dev_info; 4455 4456 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4457 uint64_t feat_flags = dev_info.feature_flags; 4458 4459 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4460 ((tdata->validDataLenInBits.len % 8) != 0)) { 4461 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4462 return TEST_SKIPPED; 4463 } 4464 4465 /* Verify the capabilities */ 4466 struct rte_cryptodev_sym_capability_idx cap_idx; 4467 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4468 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4469 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4470 &cap_idx) == NULL) 4471 return TEST_SKIPPED; 4472 4473 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4474 return TEST_SKIPPED; 4475 4476 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4477 return TEST_SKIPPED; 4478 4479 /* Create SNOW 3G session */ 4480 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4481 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4482 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4483 tdata->key.data, tdata->key.len, 4484 tdata->cipher_iv.len); 4485 if (retval < 0) 4486 return retval; 4487 4488 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4489 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4490 4491 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4492 "Failed to allocate input buffer in mempool"); 4493 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4494 "Failed to allocate output buffer in mempool"); 4495 4496 /* Clear mbuf payload */ 4497 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4498 rte_pktmbuf_tailroom(ut_params->ibuf)); 4499 4500 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset); 4501 /* 4502 * Append data which is padded to a 4503 * multiple of the algorithms block size 4504 */ 4505 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4506 4507 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, 4508 plaintext_pad_len); 4509 4510 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4511 4512 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); 4513 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); 4514 4515 #ifdef RTE_APP_TEST_DEBUG 4516 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); 4517 #endif 4518 /* Create SNOW 3G operation */ 4519 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4520 tdata->cipher_iv.len, 4521 tdata->validCipherLenInBits.len, 4522 extra_offset); 4523 if (retval < 0) 4524 return retval; 4525 4526 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4527 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4528 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4529 else 4530 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4531 ut_params->op); 4532 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4533 4534 ut_params->obuf = ut_params->op->sym->m_dst; 4535 if (ut_params->obuf) 4536 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4537 else 4538 ciphertext = plaintext; 4539 4540 #ifdef RTE_APP_TEST_DEBUG 4541 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4542 #endif 4543 4544 expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8); 4545 4546 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, 4547 "failed to reserve memory for ciphertext shifted\n"); 4548 4549 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, 4550 ceil_byte_length(tdata->ciphertext.len)); 4551 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, 4552 extra_offset); 4553 /* Validate obuf */ 4554 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4555 ciphertext, 4556 expected_ciphertext_shifted, 4557 tdata->validDataLenInBits.len, 4558 extra_offset, 4559 "SNOW 3G Ciphertext data not as expected"); 4560 return 0; 4561 } 4562 4563 static int test_snow3g_decryption(const struct snow3g_test_data *tdata) 4564 { 4565 struct crypto_testsuite_params *ts_params = &testsuite_params; 4566 struct crypto_unittest_params *ut_params = &unittest_params; 4567 4568 int retval; 4569 4570 uint8_t *plaintext, *ciphertext; 4571 unsigned ciphertext_pad_len; 4572 unsigned ciphertext_len; 4573 struct rte_cryptodev_info dev_info; 4574 4575 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4576 uint64_t feat_flags = dev_info.feature_flags; 4577 4578 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4579 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4580 printf("Device doesn't support RAW data-path APIs.\n"); 4581 return TEST_SKIPPED; 4582 } 4583 4584 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4585 return TEST_SKIPPED; 4586 4587 /* Verify the capabilities */ 4588 struct rte_cryptodev_sym_capability_idx cap_idx; 4589 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4590 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4591 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4592 &cap_idx) == NULL) 4593 return TEST_SKIPPED; 4594 4595 /* Create SNOW 3G session */ 4596 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4597 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4598 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4599 tdata->key.data, tdata->key.len, 4600 tdata->cipher_iv.len); 4601 if (retval < 0) 4602 return retval; 4603 4604 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4605 4606 /* Clear mbuf payload */ 4607 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4608 rte_pktmbuf_tailroom(ut_params->ibuf)); 4609 4610 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4611 /* Append data which is padded to a multiple of */ 4612 /* the algorithms block size */ 4613 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4614 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4615 ciphertext_pad_len); 4616 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4617 4618 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4619 4620 /* Create SNOW 3G operation */ 4621 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4622 tdata->cipher_iv.len, 4623 tdata->validCipherLenInBits.len, 4624 tdata->cipher.offset_bits); 4625 if (retval < 0) 4626 return retval; 4627 4628 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4629 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4630 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4631 else 4632 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4633 ut_params->op); 4634 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4635 ut_params->obuf = ut_params->op->sym->m_dst; 4636 if (ut_params->obuf) 4637 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4638 else 4639 plaintext = ciphertext; 4640 4641 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4642 4643 /* Validate obuf */ 4644 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4645 tdata->plaintext.data, 4646 tdata->validDataLenInBits.len, 4647 "SNOW 3G Plaintext data not as expected"); 4648 return 0; 4649 } 4650 4651 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) 4652 { 4653 struct crypto_testsuite_params *ts_params = &testsuite_params; 4654 struct crypto_unittest_params *ut_params = &unittest_params; 4655 4656 int retval; 4657 4658 uint8_t *plaintext, *ciphertext; 4659 unsigned ciphertext_pad_len; 4660 unsigned ciphertext_len; 4661 struct rte_cryptodev_info dev_info; 4662 4663 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4664 uint64_t feat_flags = dev_info.feature_flags; 4665 4666 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4667 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4668 printf("Device does not support RAW data-path APIs.\n"); 4669 return -ENOTSUP; 4670 } 4671 /* Verify the capabilities */ 4672 struct rte_cryptodev_sym_capability_idx cap_idx; 4673 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4674 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4675 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4676 &cap_idx) == NULL) 4677 return TEST_SKIPPED; 4678 4679 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4680 return TEST_SKIPPED; 4681 4682 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4683 return TEST_SKIPPED; 4684 4685 /* Create SNOW 3G session */ 4686 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4687 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4688 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4689 tdata->key.data, tdata->key.len, 4690 tdata->cipher_iv.len); 4691 if (retval < 0) 4692 return retval; 4693 4694 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4695 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4696 4697 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4698 "Failed to allocate input buffer"); 4699 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4700 "Failed to allocate output buffer"); 4701 4702 /* Clear mbuf payload */ 4703 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4704 rte_pktmbuf_tailroom(ut_params->ibuf)); 4705 4706 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4707 rte_pktmbuf_tailroom(ut_params->obuf)); 4708 4709 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4710 /* Append data which is padded to a multiple of */ 4711 /* the algorithms block size */ 4712 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4713 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4714 ciphertext_pad_len); 4715 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4716 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4717 4718 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4719 4720 /* Create SNOW 3G operation */ 4721 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4722 tdata->cipher_iv.len, 4723 tdata->validCipherLenInBits.len, 4724 0); 4725 if (retval < 0) 4726 return retval; 4727 4728 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4729 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4730 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4731 else 4732 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4733 ut_params->op); 4734 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4735 ut_params->obuf = ut_params->op->sym->m_dst; 4736 if (ut_params->obuf) 4737 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4738 else 4739 plaintext = ciphertext; 4740 4741 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4742 4743 /* Validate obuf */ 4744 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4745 tdata->plaintext.data, 4746 tdata->validDataLenInBits.len, 4747 "SNOW 3G Plaintext data not as expected"); 4748 return 0; 4749 } 4750 4751 static int 4752 test_zuc_cipher_auth(const struct wireless_test_data *tdata) 4753 { 4754 struct crypto_testsuite_params *ts_params = &testsuite_params; 4755 struct crypto_unittest_params *ut_params = &unittest_params; 4756 4757 int retval; 4758 4759 uint8_t *plaintext, *ciphertext; 4760 unsigned int plaintext_pad_len; 4761 unsigned int plaintext_len; 4762 4763 struct rte_cryptodev_info dev_info; 4764 struct rte_cryptodev_sym_capability_idx cap_idx; 4765 4766 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4767 uint64_t feat_flags = dev_info.feature_flags; 4768 4769 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4770 ((tdata->validAuthLenInBits.len % 8 != 0) || 4771 (tdata->validDataLenInBits.len % 8 != 0))) { 4772 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4773 return TEST_SKIPPED; 4774 } 4775 4776 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4777 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4778 printf("Device doesn't support RAW data-path APIs.\n"); 4779 return TEST_SKIPPED; 4780 } 4781 4782 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4783 return TEST_SKIPPED; 4784 4785 /* Check if device supports ZUC EEA3 */ 4786 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4787 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 4788 4789 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4790 &cap_idx) == NULL) 4791 return TEST_SKIPPED; 4792 4793 /* Check if device supports ZUC EIA3 */ 4794 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4795 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 4796 4797 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4798 &cap_idx) == NULL) 4799 return TEST_SKIPPED; 4800 4801 /* Create ZUC session */ 4802 retval = create_zuc_cipher_auth_encrypt_generate_session( 4803 ts_params->valid_devs[0], 4804 tdata); 4805 if (retval != 0) 4806 return retval; 4807 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4808 4809 /* clear mbuf payload */ 4810 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4811 rte_pktmbuf_tailroom(ut_params->ibuf)); 4812 4813 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4814 /* Append data which is padded to a multiple of */ 4815 /* the algorithms block size */ 4816 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4817 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4818 plaintext_pad_len); 4819 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4820 4821 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4822 4823 /* Create ZUC operation */ 4824 retval = create_zuc_cipher_hash_generate_operation(tdata); 4825 if (retval < 0) 4826 return retval; 4827 4828 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4829 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4830 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4831 else 4832 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4833 ut_params->op); 4834 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4835 ut_params->obuf = ut_params->op->sym->m_src; 4836 if (ut_params->obuf) 4837 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4838 else 4839 ciphertext = plaintext; 4840 4841 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4842 /* Validate obuf */ 4843 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4844 ciphertext, 4845 tdata->ciphertext.data, 4846 tdata->validDataLenInBits.len, 4847 "ZUC Ciphertext data not as expected"); 4848 4849 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4850 + plaintext_pad_len; 4851 4852 /* Validate obuf */ 4853 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4854 ut_params->digest, 4855 tdata->digest.data, 4856 tdata->digest.len, 4857 "ZUC Generated auth tag not as expected"); 4858 return 0; 4859 } 4860 4861 static int 4862 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) 4863 { 4864 struct crypto_testsuite_params *ts_params = &testsuite_params; 4865 struct crypto_unittest_params *ut_params = &unittest_params; 4866 4867 int retval; 4868 4869 uint8_t *plaintext, *ciphertext; 4870 unsigned plaintext_pad_len; 4871 unsigned plaintext_len; 4872 struct rte_cryptodev_info dev_info; 4873 4874 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4875 uint64_t feat_flags = dev_info.feature_flags; 4876 4877 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4878 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4879 printf("Device doesn't support RAW data-path APIs.\n"); 4880 return TEST_SKIPPED; 4881 } 4882 4883 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4884 return TEST_SKIPPED; 4885 4886 /* Verify the capabilities */ 4887 struct rte_cryptodev_sym_capability_idx cap_idx; 4888 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4889 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4890 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4891 &cap_idx) == NULL) 4892 return TEST_SKIPPED; 4893 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4894 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4895 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4896 &cap_idx) == NULL) 4897 return TEST_SKIPPED; 4898 4899 /* Create SNOW 3G session */ 4900 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0], 4901 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4902 RTE_CRYPTO_AUTH_OP_GENERATE, 4903 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4904 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4905 tdata->key.data, tdata->key.len, 4906 tdata->auth_iv.len, tdata->digest.len, 4907 tdata->cipher_iv.len); 4908 if (retval != 0) 4909 return retval; 4910 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4911 4912 /* clear mbuf payload */ 4913 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4914 rte_pktmbuf_tailroom(ut_params->ibuf)); 4915 4916 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4917 /* Append data which is padded to a multiple of */ 4918 /* the algorithms block size */ 4919 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4920 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4921 plaintext_pad_len); 4922 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4923 4924 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4925 4926 /* Create SNOW 3G operation */ 4927 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 4928 tdata->digest.len, tdata->auth_iv.data, 4929 tdata->auth_iv.len, 4930 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 4931 tdata->cipher_iv.data, tdata->cipher_iv.len, 4932 tdata->validCipherLenInBits.len, 4933 0, 4934 tdata->validAuthLenInBits.len, 4935 0 4936 ); 4937 if (retval < 0) 4938 return retval; 4939 4940 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4941 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4942 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4943 else 4944 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4945 ut_params->op); 4946 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4947 ut_params->obuf = ut_params->op->sym->m_src; 4948 if (ut_params->obuf) 4949 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4950 else 4951 ciphertext = plaintext; 4952 4953 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4954 /* Validate obuf */ 4955 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4956 ciphertext, 4957 tdata->ciphertext.data, 4958 tdata->validDataLenInBits.len, 4959 "SNOW 3G Ciphertext data not as expected"); 4960 4961 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4962 + plaintext_pad_len; 4963 4964 /* Validate obuf */ 4965 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4966 ut_params->digest, 4967 tdata->digest.data, 4968 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4969 "SNOW 3G Generated auth tag not as expected"); 4970 return 0; 4971 } 4972 4973 static int 4974 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata, 4975 uint8_t op_mode, uint8_t verify) 4976 { 4977 struct crypto_testsuite_params *ts_params = &testsuite_params; 4978 struct crypto_unittest_params *ut_params = &unittest_params; 4979 4980 int retval; 4981 4982 uint8_t *plaintext = NULL, *ciphertext = NULL; 4983 unsigned int plaintext_pad_len; 4984 unsigned int plaintext_len; 4985 unsigned int ciphertext_pad_len; 4986 unsigned int ciphertext_len; 4987 4988 struct rte_cryptodev_info dev_info; 4989 4990 /* Verify the capabilities */ 4991 struct rte_cryptodev_sym_capability_idx cap_idx; 4992 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4993 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4994 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4995 &cap_idx) == NULL) 4996 return TEST_SKIPPED; 4997 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4998 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4999 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5000 &cap_idx) == NULL) 5001 return TEST_SKIPPED; 5002 5003 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5004 return TEST_SKIPPED; 5005 5006 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5007 5008 uint64_t feat_flags = dev_info.feature_flags; 5009 5010 if (op_mode == OUT_OF_PLACE) { 5011 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5012 printf("Device doesn't support digest encrypted.\n"); 5013 return TEST_SKIPPED; 5014 } 5015 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5016 return TEST_SKIPPED; 5017 } 5018 5019 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5020 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5021 printf("Device doesn't support RAW data-path APIs.\n"); 5022 return TEST_SKIPPED; 5023 } 5024 5025 /* Create SNOW 3G session */ 5026 retval = create_wireless_algo_auth_cipher_session( 5027 ts_params->valid_devs[0], 5028 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5029 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5030 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5031 : RTE_CRYPTO_AUTH_OP_GENERATE), 5032 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5033 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5034 tdata->key.data, tdata->key.len, 5035 tdata->auth_iv.len, tdata->digest.len, 5036 tdata->cipher_iv.len); 5037 if (retval != 0) 5038 return retval; 5039 5040 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5041 if (op_mode == OUT_OF_PLACE) 5042 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5043 5044 /* clear mbuf payload */ 5045 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5046 rte_pktmbuf_tailroom(ut_params->ibuf)); 5047 if (op_mode == OUT_OF_PLACE) 5048 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5049 rte_pktmbuf_tailroom(ut_params->obuf)); 5050 5051 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5052 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5053 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5054 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5055 5056 if (verify) { 5057 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5058 ciphertext_pad_len); 5059 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5060 if (op_mode == OUT_OF_PLACE) 5061 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5062 debug_hexdump(stdout, "ciphertext:", ciphertext, 5063 ciphertext_len); 5064 } else { 5065 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5066 plaintext_pad_len); 5067 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5068 if (op_mode == OUT_OF_PLACE) 5069 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5070 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5071 } 5072 5073 /* Create SNOW 3G operation */ 5074 retval = create_wireless_algo_auth_cipher_operation( 5075 tdata->digest.data, tdata->digest.len, 5076 tdata->cipher_iv.data, tdata->cipher_iv.len, 5077 tdata->auth_iv.data, tdata->auth_iv.len, 5078 (tdata->digest.offset_bytes == 0 ? 5079 (verify ? ciphertext_pad_len : plaintext_pad_len) 5080 : tdata->digest.offset_bytes), 5081 tdata->validCipherLenInBits.len, 5082 tdata->cipher.offset_bits, 5083 tdata->validAuthLenInBits.len, 5084 tdata->auth.offset_bits, 5085 op_mode, 0, verify); 5086 5087 if (retval < 0) 5088 return retval; 5089 5090 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5091 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5092 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5093 else 5094 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5095 ut_params->op); 5096 5097 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5098 5099 ut_params->obuf = (op_mode == IN_PLACE ? 5100 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5101 5102 if (verify) { 5103 if (ut_params->obuf) 5104 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5105 uint8_t *); 5106 else 5107 plaintext = ciphertext + 5108 (tdata->cipher.offset_bits >> 3); 5109 5110 debug_hexdump(stdout, "plaintext:", plaintext, 5111 (tdata->plaintext.len >> 3) - tdata->digest.len); 5112 debug_hexdump(stdout, "plaintext expected:", 5113 tdata->plaintext.data, 5114 (tdata->plaintext.len >> 3) - tdata->digest.len); 5115 } else { 5116 if (ut_params->obuf) 5117 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5118 uint8_t *); 5119 else 5120 ciphertext = plaintext; 5121 5122 debug_hexdump(stdout, "ciphertext:", ciphertext, 5123 ciphertext_len); 5124 debug_hexdump(stdout, "ciphertext expected:", 5125 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5126 5127 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5128 + (tdata->digest.offset_bytes == 0 ? 5129 plaintext_pad_len : tdata->digest.offset_bytes); 5130 5131 debug_hexdump(stdout, "digest:", ut_params->digest, 5132 tdata->digest.len); 5133 debug_hexdump(stdout, "digest expected:", tdata->digest.data, 5134 tdata->digest.len); 5135 } 5136 5137 /* Validate obuf */ 5138 if (verify) { 5139 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5140 plaintext, 5141 tdata->plaintext.data, 5142 (tdata->plaintext.len - tdata->cipher.offset_bits - 5143 (tdata->digest.len << 3)), 5144 tdata->cipher.offset_bits, 5145 "SNOW 3G Plaintext data not as expected"); 5146 } else { 5147 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5148 ciphertext, 5149 tdata->ciphertext.data, 5150 (tdata->validDataLenInBits.len - 5151 tdata->cipher.offset_bits), 5152 tdata->cipher.offset_bits, 5153 "SNOW 3G Ciphertext data not as expected"); 5154 5155 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5156 ut_params->digest, 5157 tdata->digest.data, 5158 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5159 "SNOW 3G Generated auth tag not as expected"); 5160 } 5161 return 0; 5162 } 5163 5164 static int 5165 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata, 5166 uint8_t op_mode, uint8_t verify) 5167 { 5168 struct crypto_testsuite_params *ts_params = &testsuite_params; 5169 struct crypto_unittest_params *ut_params = &unittest_params; 5170 5171 int retval; 5172 5173 const uint8_t *plaintext = NULL; 5174 const uint8_t *ciphertext = NULL; 5175 const uint8_t *digest = NULL; 5176 unsigned int plaintext_pad_len; 5177 unsigned int plaintext_len; 5178 unsigned int ciphertext_pad_len; 5179 unsigned int ciphertext_len; 5180 uint8_t buffer[10000]; 5181 uint8_t digest_buffer[10000]; 5182 5183 struct rte_cryptodev_info dev_info; 5184 5185 /* Verify the capabilities */ 5186 struct rte_cryptodev_sym_capability_idx cap_idx; 5187 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5188 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5189 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5190 &cap_idx) == NULL) 5191 return TEST_SKIPPED; 5192 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5193 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5194 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5195 &cap_idx) == NULL) 5196 return TEST_SKIPPED; 5197 5198 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5199 return TEST_SKIPPED; 5200 5201 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5202 5203 uint64_t feat_flags = dev_info.feature_flags; 5204 5205 if (op_mode == IN_PLACE) { 5206 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5207 printf("Device doesn't support in-place scatter-gather " 5208 "in both input and output mbufs.\n"); 5209 return TEST_SKIPPED; 5210 } 5211 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5212 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5213 printf("Device doesn't support RAW data-path APIs.\n"); 5214 return TEST_SKIPPED; 5215 } 5216 } else { 5217 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5218 return TEST_SKIPPED; 5219 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5220 printf("Device doesn't support out-of-place scatter-gather " 5221 "in both input and output mbufs.\n"); 5222 return TEST_SKIPPED; 5223 } 5224 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5225 printf("Device doesn't support digest encrypted.\n"); 5226 return TEST_SKIPPED; 5227 } 5228 } 5229 5230 /* Create SNOW 3G session */ 5231 retval = create_wireless_algo_auth_cipher_session( 5232 ts_params->valid_devs[0], 5233 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5234 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5235 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5236 : RTE_CRYPTO_AUTH_OP_GENERATE), 5237 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5238 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5239 tdata->key.data, tdata->key.len, 5240 tdata->auth_iv.len, tdata->digest.len, 5241 tdata->cipher_iv.len); 5242 5243 if (retval != 0) 5244 return retval; 5245 5246 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5247 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5248 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5249 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5250 5251 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5252 plaintext_pad_len, 15, 0); 5253 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5254 "Failed to allocate input buffer in mempool"); 5255 5256 if (op_mode == OUT_OF_PLACE) { 5257 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5258 plaintext_pad_len, 15, 0); 5259 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5260 "Failed to allocate output buffer in mempool"); 5261 } 5262 5263 if (verify) { 5264 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5265 tdata->ciphertext.data); 5266 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5267 ciphertext_len, buffer); 5268 debug_hexdump(stdout, "ciphertext:", ciphertext, 5269 ciphertext_len); 5270 } else { 5271 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5272 tdata->plaintext.data); 5273 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5274 plaintext_len, buffer); 5275 debug_hexdump(stdout, "plaintext:", plaintext, 5276 plaintext_len); 5277 } 5278 memset(buffer, 0, sizeof(buffer)); 5279 5280 /* Create SNOW 3G operation */ 5281 retval = create_wireless_algo_auth_cipher_operation( 5282 tdata->digest.data, tdata->digest.len, 5283 tdata->cipher_iv.data, tdata->cipher_iv.len, 5284 tdata->auth_iv.data, tdata->auth_iv.len, 5285 (tdata->digest.offset_bytes == 0 ? 5286 (verify ? ciphertext_pad_len : plaintext_pad_len) 5287 : tdata->digest.offset_bytes), 5288 tdata->validCipherLenInBits.len, 5289 tdata->cipher.offset_bits, 5290 tdata->validAuthLenInBits.len, 5291 tdata->auth.offset_bits, 5292 op_mode, 1, verify); 5293 5294 if (retval < 0) 5295 return retval; 5296 5297 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5298 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5299 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5300 else 5301 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5302 ut_params->op); 5303 5304 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5305 5306 ut_params->obuf = (op_mode == IN_PLACE ? 5307 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5308 5309 if (verify) { 5310 if (ut_params->obuf) 5311 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5312 plaintext_len, buffer); 5313 else 5314 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5315 plaintext_len, buffer); 5316 5317 debug_hexdump(stdout, "plaintext:", plaintext, 5318 (tdata->plaintext.len >> 3) - tdata->digest.len); 5319 debug_hexdump(stdout, "plaintext expected:", 5320 tdata->plaintext.data, 5321 (tdata->plaintext.len >> 3) - tdata->digest.len); 5322 } else { 5323 if (ut_params->obuf) 5324 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5325 ciphertext_len, buffer); 5326 else 5327 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5328 ciphertext_len, buffer); 5329 5330 debug_hexdump(stdout, "ciphertext:", ciphertext, 5331 ciphertext_len); 5332 debug_hexdump(stdout, "ciphertext expected:", 5333 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5334 5335 if (ut_params->obuf) 5336 digest = rte_pktmbuf_read(ut_params->obuf, 5337 (tdata->digest.offset_bytes == 0 ? 5338 plaintext_pad_len : tdata->digest.offset_bytes), 5339 tdata->digest.len, digest_buffer); 5340 else 5341 digest = rte_pktmbuf_read(ut_params->ibuf, 5342 (tdata->digest.offset_bytes == 0 ? 5343 plaintext_pad_len : tdata->digest.offset_bytes), 5344 tdata->digest.len, digest_buffer); 5345 5346 debug_hexdump(stdout, "digest:", digest, 5347 tdata->digest.len); 5348 debug_hexdump(stdout, "digest expected:", 5349 tdata->digest.data, tdata->digest.len); 5350 } 5351 5352 /* Validate obuf */ 5353 if (verify) { 5354 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5355 plaintext, 5356 tdata->plaintext.data, 5357 (tdata->plaintext.len - tdata->cipher.offset_bits - 5358 (tdata->digest.len << 3)), 5359 tdata->cipher.offset_bits, 5360 "SNOW 3G Plaintext data not as expected"); 5361 } else { 5362 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5363 ciphertext, 5364 tdata->ciphertext.data, 5365 (tdata->validDataLenInBits.len - 5366 tdata->cipher.offset_bits), 5367 tdata->cipher.offset_bits, 5368 "SNOW 3G Ciphertext data not as expected"); 5369 5370 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5371 digest, 5372 tdata->digest.data, 5373 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5374 "SNOW 3G Generated auth tag not as expected"); 5375 } 5376 return 0; 5377 } 5378 5379 static int 5380 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata, 5381 uint8_t op_mode, uint8_t verify) 5382 { 5383 struct crypto_testsuite_params *ts_params = &testsuite_params; 5384 struct crypto_unittest_params *ut_params = &unittest_params; 5385 5386 int retval; 5387 5388 uint8_t *plaintext = NULL, *ciphertext = NULL; 5389 unsigned int plaintext_pad_len; 5390 unsigned int plaintext_len; 5391 unsigned int ciphertext_pad_len; 5392 unsigned int ciphertext_len; 5393 5394 struct rte_cryptodev_info dev_info; 5395 5396 /* Verify the capabilities */ 5397 struct rte_cryptodev_sym_capability_idx cap_idx; 5398 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5399 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5400 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5401 &cap_idx) == NULL) 5402 return TEST_SKIPPED; 5403 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5404 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5405 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5406 &cap_idx) == NULL) 5407 return TEST_SKIPPED; 5408 5409 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5410 5411 uint64_t feat_flags = dev_info.feature_flags; 5412 5413 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5414 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5415 printf("Device doesn't support RAW data-path APIs.\n"); 5416 return TEST_SKIPPED; 5417 } 5418 5419 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5420 return TEST_SKIPPED; 5421 5422 if (op_mode == OUT_OF_PLACE) { 5423 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5424 return TEST_SKIPPED; 5425 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5426 printf("Device doesn't support digest encrypted.\n"); 5427 return TEST_SKIPPED; 5428 } 5429 } 5430 5431 /* Create KASUMI session */ 5432 retval = create_wireless_algo_auth_cipher_session( 5433 ts_params->valid_devs[0], 5434 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5435 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5436 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5437 : RTE_CRYPTO_AUTH_OP_GENERATE), 5438 RTE_CRYPTO_AUTH_KASUMI_F9, 5439 RTE_CRYPTO_CIPHER_KASUMI_F8, 5440 tdata->key.data, tdata->key.len, 5441 0, tdata->digest.len, 5442 tdata->cipher_iv.len); 5443 5444 if (retval != 0) 5445 return retval; 5446 5447 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5448 if (op_mode == OUT_OF_PLACE) 5449 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5450 5451 /* clear mbuf payload */ 5452 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5453 rte_pktmbuf_tailroom(ut_params->ibuf)); 5454 if (op_mode == OUT_OF_PLACE) 5455 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5456 rte_pktmbuf_tailroom(ut_params->obuf)); 5457 5458 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5459 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5460 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5461 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5462 5463 if (verify) { 5464 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5465 ciphertext_pad_len); 5466 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5467 if (op_mode == OUT_OF_PLACE) 5468 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5469 debug_hexdump(stdout, "ciphertext:", ciphertext, 5470 ciphertext_len); 5471 } else { 5472 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5473 plaintext_pad_len); 5474 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5475 if (op_mode == OUT_OF_PLACE) 5476 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5477 debug_hexdump(stdout, "plaintext:", plaintext, 5478 plaintext_len); 5479 } 5480 5481 /* Create KASUMI operation */ 5482 retval = create_wireless_algo_auth_cipher_operation( 5483 tdata->digest.data, tdata->digest.len, 5484 tdata->cipher_iv.data, tdata->cipher_iv.len, 5485 NULL, 0, 5486 (tdata->digest.offset_bytes == 0 ? 5487 (verify ? ciphertext_pad_len : plaintext_pad_len) 5488 : tdata->digest.offset_bytes), 5489 tdata->validCipherLenInBits.len, 5490 tdata->validCipherOffsetInBits.len, 5491 tdata->validAuthLenInBits.len, 5492 0, 5493 op_mode, 0, verify); 5494 5495 if (retval < 0) 5496 return retval; 5497 5498 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5499 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5500 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5501 else 5502 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5503 ut_params->op); 5504 5505 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5506 5507 ut_params->obuf = (op_mode == IN_PLACE ? 5508 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5509 5510 5511 if (verify) { 5512 if (ut_params->obuf) 5513 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5514 uint8_t *); 5515 else 5516 plaintext = ciphertext; 5517 5518 debug_hexdump(stdout, "plaintext:", plaintext, 5519 (tdata->plaintext.len >> 3) - tdata->digest.len); 5520 debug_hexdump(stdout, "plaintext expected:", 5521 tdata->plaintext.data, 5522 (tdata->plaintext.len >> 3) - tdata->digest.len); 5523 } else { 5524 if (ut_params->obuf) 5525 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5526 uint8_t *); 5527 else 5528 ciphertext = plaintext; 5529 5530 debug_hexdump(stdout, "ciphertext:", ciphertext, 5531 ciphertext_len); 5532 debug_hexdump(stdout, "ciphertext expected:", 5533 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5534 5535 ut_params->digest = rte_pktmbuf_mtod( 5536 ut_params->obuf, uint8_t *) + 5537 (tdata->digest.offset_bytes == 0 ? 5538 plaintext_pad_len : tdata->digest.offset_bytes); 5539 5540 debug_hexdump(stdout, "digest:", ut_params->digest, 5541 tdata->digest.len); 5542 debug_hexdump(stdout, "digest expected:", 5543 tdata->digest.data, tdata->digest.len); 5544 } 5545 5546 /* Validate obuf */ 5547 if (verify) { 5548 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5549 plaintext, 5550 tdata->plaintext.data, 5551 tdata->plaintext.len >> 3, 5552 "KASUMI Plaintext data not as expected"); 5553 } else { 5554 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5555 ciphertext, 5556 tdata->ciphertext.data, 5557 tdata->ciphertext.len >> 3, 5558 "KASUMI Ciphertext data not as expected"); 5559 5560 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5561 ut_params->digest, 5562 tdata->digest.data, 5563 DIGEST_BYTE_LENGTH_KASUMI_F9, 5564 "KASUMI Generated auth tag not as expected"); 5565 } 5566 return 0; 5567 } 5568 5569 static int 5570 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata, 5571 uint8_t op_mode, uint8_t verify) 5572 { 5573 struct crypto_testsuite_params *ts_params = &testsuite_params; 5574 struct crypto_unittest_params *ut_params = &unittest_params; 5575 5576 int retval; 5577 5578 const uint8_t *plaintext = NULL; 5579 const uint8_t *ciphertext = NULL; 5580 const uint8_t *digest = NULL; 5581 unsigned int plaintext_pad_len; 5582 unsigned int plaintext_len; 5583 unsigned int ciphertext_pad_len; 5584 unsigned int ciphertext_len; 5585 uint8_t buffer[10000]; 5586 uint8_t digest_buffer[10000]; 5587 5588 struct rte_cryptodev_info dev_info; 5589 5590 /* Verify the capabilities */ 5591 struct rte_cryptodev_sym_capability_idx cap_idx; 5592 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5593 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5594 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5595 &cap_idx) == NULL) 5596 return TEST_SKIPPED; 5597 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5598 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5599 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5600 &cap_idx) == NULL) 5601 return TEST_SKIPPED; 5602 5603 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5604 return TEST_SKIPPED; 5605 5606 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5607 5608 uint64_t feat_flags = dev_info.feature_flags; 5609 5610 if (op_mode == IN_PLACE) { 5611 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5612 printf("Device doesn't support in-place scatter-gather " 5613 "in both input and output mbufs.\n"); 5614 return TEST_SKIPPED; 5615 } 5616 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5617 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5618 printf("Device doesn't support RAW data-path APIs.\n"); 5619 return TEST_SKIPPED; 5620 } 5621 } else { 5622 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5623 return TEST_SKIPPED; 5624 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5625 printf("Device doesn't support out-of-place scatter-gather " 5626 "in both input and output mbufs.\n"); 5627 return TEST_SKIPPED; 5628 } 5629 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5630 printf("Device doesn't support digest encrypted.\n"); 5631 return TEST_SKIPPED; 5632 } 5633 } 5634 5635 /* Create KASUMI session */ 5636 retval = create_wireless_algo_auth_cipher_session( 5637 ts_params->valid_devs[0], 5638 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5639 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5640 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5641 : RTE_CRYPTO_AUTH_OP_GENERATE), 5642 RTE_CRYPTO_AUTH_KASUMI_F9, 5643 RTE_CRYPTO_CIPHER_KASUMI_F8, 5644 tdata->key.data, tdata->key.len, 5645 0, tdata->digest.len, 5646 tdata->cipher_iv.len); 5647 5648 if (retval != 0) 5649 return retval; 5650 5651 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5652 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5653 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5654 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5655 5656 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5657 plaintext_pad_len, 15, 0); 5658 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5659 "Failed to allocate input buffer in mempool"); 5660 5661 if (op_mode == OUT_OF_PLACE) { 5662 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5663 plaintext_pad_len, 15, 0); 5664 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5665 "Failed to allocate output buffer in mempool"); 5666 } 5667 5668 if (verify) { 5669 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5670 tdata->ciphertext.data); 5671 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5672 ciphertext_len, buffer); 5673 debug_hexdump(stdout, "ciphertext:", ciphertext, 5674 ciphertext_len); 5675 } else { 5676 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5677 tdata->plaintext.data); 5678 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5679 plaintext_len, buffer); 5680 debug_hexdump(stdout, "plaintext:", plaintext, 5681 plaintext_len); 5682 } 5683 memset(buffer, 0, sizeof(buffer)); 5684 5685 /* Create KASUMI operation */ 5686 retval = create_wireless_algo_auth_cipher_operation( 5687 tdata->digest.data, tdata->digest.len, 5688 tdata->cipher_iv.data, tdata->cipher_iv.len, 5689 NULL, 0, 5690 (tdata->digest.offset_bytes == 0 ? 5691 (verify ? ciphertext_pad_len : plaintext_pad_len) 5692 : tdata->digest.offset_bytes), 5693 tdata->validCipherLenInBits.len, 5694 tdata->validCipherOffsetInBits.len, 5695 tdata->validAuthLenInBits.len, 5696 0, 5697 op_mode, 1, verify); 5698 5699 if (retval < 0) 5700 return retval; 5701 5702 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5703 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5704 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5705 else 5706 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5707 ut_params->op); 5708 5709 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5710 5711 ut_params->obuf = (op_mode == IN_PLACE ? 5712 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5713 5714 if (verify) { 5715 if (ut_params->obuf) 5716 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5717 plaintext_len, buffer); 5718 else 5719 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5720 plaintext_len, buffer); 5721 5722 debug_hexdump(stdout, "plaintext:", plaintext, 5723 (tdata->plaintext.len >> 3) - tdata->digest.len); 5724 debug_hexdump(stdout, "plaintext expected:", 5725 tdata->plaintext.data, 5726 (tdata->plaintext.len >> 3) - tdata->digest.len); 5727 } else { 5728 if (ut_params->obuf) 5729 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5730 ciphertext_len, buffer); 5731 else 5732 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5733 ciphertext_len, buffer); 5734 5735 debug_hexdump(stdout, "ciphertext:", ciphertext, 5736 ciphertext_len); 5737 debug_hexdump(stdout, "ciphertext expected:", 5738 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5739 5740 if (ut_params->obuf) 5741 digest = rte_pktmbuf_read(ut_params->obuf, 5742 (tdata->digest.offset_bytes == 0 ? 5743 plaintext_pad_len : tdata->digest.offset_bytes), 5744 tdata->digest.len, digest_buffer); 5745 else 5746 digest = rte_pktmbuf_read(ut_params->ibuf, 5747 (tdata->digest.offset_bytes == 0 ? 5748 plaintext_pad_len : tdata->digest.offset_bytes), 5749 tdata->digest.len, digest_buffer); 5750 5751 debug_hexdump(stdout, "digest:", digest, 5752 tdata->digest.len); 5753 debug_hexdump(stdout, "digest expected:", 5754 tdata->digest.data, tdata->digest.len); 5755 } 5756 5757 /* Validate obuf */ 5758 if (verify) { 5759 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5760 plaintext, 5761 tdata->plaintext.data, 5762 tdata->plaintext.len >> 3, 5763 "KASUMI Plaintext data not as expected"); 5764 } else { 5765 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5766 ciphertext, 5767 tdata->ciphertext.data, 5768 tdata->validDataLenInBits.len, 5769 "KASUMI Ciphertext data not as expected"); 5770 5771 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5772 digest, 5773 tdata->digest.data, 5774 DIGEST_BYTE_LENGTH_KASUMI_F9, 5775 "KASUMI Generated auth tag not as expected"); 5776 } 5777 return 0; 5778 } 5779 5780 static int 5781 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata) 5782 { 5783 struct crypto_testsuite_params *ts_params = &testsuite_params; 5784 struct crypto_unittest_params *ut_params = &unittest_params; 5785 5786 int retval; 5787 5788 uint8_t *plaintext, *ciphertext; 5789 unsigned plaintext_pad_len; 5790 unsigned plaintext_len; 5791 struct rte_cryptodev_info dev_info; 5792 5793 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5794 uint64_t feat_flags = dev_info.feature_flags; 5795 5796 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5797 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5798 printf("Device doesn't support RAW data-path APIs.\n"); 5799 return TEST_SKIPPED; 5800 } 5801 5802 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5803 return TEST_SKIPPED; 5804 5805 /* Verify the capabilities */ 5806 struct rte_cryptodev_sym_capability_idx cap_idx; 5807 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5808 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5809 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5810 &cap_idx) == NULL) 5811 return TEST_SKIPPED; 5812 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5813 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5814 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5815 &cap_idx) == NULL) 5816 return TEST_SKIPPED; 5817 5818 /* Create KASUMI session */ 5819 retval = create_wireless_algo_cipher_auth_session( 5820 ts_params->valid_devs[0], 5821 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5822 RTE_CRYPTO_AUTH_OP_GENERATE, 5823 RTE_CRYPTO_AUTH_KASUMI_F9, 5824 RTE_CRYPTO_CIPHER_KASUMI_F8, 5825 tdata->key.data, tdata->key.len, 5826 0, tdata->digest.len, 5827 tdata->cipher_iv.len); 5828 if (retval != 0) 5829 return retval; 5830 5831 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5832 5833 /* clear mbuf payload */ 5834 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5835 rte_pktmbuf_tailroom(ut_params->ibuf)); 5836 5837 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5838 /* Append data which is padded to a multiple of */ 5839 /* the algorithms block size */ 5840 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5841 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5842 plaintext_pad_len); 5843 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5844 5845 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5846 5847 /* Create KASUMI operation */ 5848 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 5849 tdata->digest.len, NULL, 0, 5850 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5851 tdata->cipher_iv.data, tdata->cipher_iv.len, 5852 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 5853 tdata->validCipherOffsetInBits.len, 5854 tdata->validAuthLenInBits.len, 5855 0 5856 ); 5857 if (retval < 0) 5858 return retval; 5859 5860 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5861 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5862 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5863 else 5864 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5865 ut_params->op); 5866 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5867 5868 if (ut_params->op->sym->m_dst) 5869 ut_params->obuf = ut_params->op->sym->m_dst; 5870 else 5871 ut_params->obuf = ut_params->op->sym->m_src; 5872 5873 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 5874 tdata->validCipherOffsetInBits.len >> 3); 5875 5876 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5877 + plaintext_pad_len; 5878 5879 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 5880 (tdata->validCipherOffsetInBits.len >> 3); 5881 /* Validate obuf */ 5882 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5883 ciphertext, 5884 reference_ciphertext, 5885 tdata->validCipherLenInBits.len, 5886 "KASUMI Ciphertext data not as expected"); 5887 5888 /* Validate obuf */ 5889 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5890 ut_params->digest, 5891 tdata->digest.data, 5892 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5893 "KASUMI Generated auth tag not as expected"); 5894 return 0; 5895 } 5896 5897 static int 5898 check_cipher_capability(const struct crypto_testsuite_params *ts_params, 5899 const enum rte_crypto_cipher_algorithm cipher_algo, 5900 const uint16_t key_size, const uint16_t iv_size) 5901 { 5902 struct rte_cryptodev_sym_capability_idx cap_idx; 5903 const struct rte_cryptodev_symmetric_capability *cap; 5904 5905 /* Check if device supports the algorithm */ 5906 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5907 cap_idx.algo.cipher = cipher_algo; 5908 5909 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5910 &cap_idx); 5911 5912 if (cap == NULL) 5913 return -1; 5914 5915 /* Check if device supports key size and IV size */ 5916 if (rte_cryptodev_sym_capability_check_cipher(cap, key_size, 5917 iv_size) < 0) { 5918 return -1; 5919 } 5920 5921 return 0; 5922 } 5923 5924 static int 5925 check_auth_capability(const struct crypto_testsuite_params *ts_params, 5926 const enum rte_crypto_auth_algorithm auth_algo, 5927 const uint16_t key_size, const uint16_t iv_size, 5928 const uint16_t tag_size) 5929 { 5930 struct rte_cryptodev_sym_capability_idx cap_idx; 5931 const struct rte_cryptodev_symmetric_capability *cap; 5932 5933 /* Check if device supports the algorithm */ 5934 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5935 cap_idx.algo.auth = auth_algo; 5936 5937 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5938 &cap_idx); 5939 5940 if (cap == NULL) 5941 return -1; 5942 5943 /* Check if device supports key size and IV size */ 5944 if (rte_cryptodev_sym_capability_check_auth(cap, key_size, 5945 tag_size, iv_size) < 0) { 5946 return -1; 5947 } 5948 5949 return 0; 5950 } 5951 5952 static int 5953 test_zuc_cipher(const struct wireless_test_data *tdata, 5954 enum rte_crypto_cipher_operation direction) 5955 { 5956 struct crypto_testsuite_params *ts_params = &testsuite_params; 5957 struct crypto_unittest_params *ut_params = &unittest_params; 5958 5959 int retval; 5960 uint8_t *plaintext = NULL; 5961 uint8_t *ciphertext = NULL; 5962 unsigned int plaintext_pad_len, ciphertext_pad_len; 5963 unsigned int plaintext_len = 0; 5964 unsigned int ciphertext_len = 0; 5965 struct rte_cryptodev_info dev_info; 5966 5967 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5968 uint64_t feat_flags = dev_info.feature_flags; 5969 5970 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5971 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5972 printf("Device doesn't support RAW data-path APIs.\n"); 5973 return TEST_SKIPPED; 5974 } 5975 5976 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5977 return TEST_SKIPPED; 5978 5979 /* Check if device supports ZUC EEA3 */ 5980 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 5981 tdata->key.len, tdata->cipher_iv.len) < 0) 5982 return TEST_SKIPPED; 5983 5984 /* Create ZUC session */ 5985 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 5986 direction, 5987 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5988 tdata->key.data, tdata->key.len, 5989 tdata->cipher_iv.len); 5990 if (retval != 0) 5991 return retval; 5992 5993 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5994 5995 /* Clear mbuf payload */ 5996 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5997 rte_pktmbuf_tailroom(ut_params->ibuf)); 5998 5999 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6000 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6001 /* Append data which is padded to a multiple */ 6002 /* of the algorithms block size */ 6003 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6004 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6005 plaintext_pad_len); 6006 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6007 6008 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6009 } else { 6010 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6011 /* Append data which is padded to a multiple */ 6012 /* of the algorithms block size */ 6013 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 6014 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6015 ciphertext_pad_len); 6016 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6017 6018 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 6019 } 6020 6021 /* Create ZUC operation */ 6022 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6023 tdata->cipher_iv.len, 6024 tdata->plaintext.len, 6025 tdata->validCipherOffsetInBits.len); 6026 if (retval < 0) 6027 return retval; 6028 6029 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6030 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6031 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 6032 else 6033 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6034 ut_params->op); 6035 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6036 6037 ut_params->obuf = ut_params->op->sym->m_dst; 6038 6039 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6040 if (ut_params->obuf) 6041 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 6042 else 6043 ciphertext = plaintext; 6044 6045 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6046 6047 /* Validate obuf */ 6048 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6049 ciphertext, 6050 tdata->ciphertext.data, 6051 tdata->validCipherLenInBits.len, 6052 "ZUC Ciphertext data not as expected"); 6053 } else { 6054 if (ut_params->obuf) 6055 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 6056 else 6057 plaintext = ciphertext; 6058 6059 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 6060 6061 const uint8_t *reference_plaintext = tdata->plaintext.data + 6062 (tdata->validCipherOffsetInBits.len >> 3); 6063 6064 /* Validate obuf */ 6065 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6066 plaintext, 6067 reference_plaintext, 6068 tdata->validCipherLenInBits.len, 6069 "ZUC Plaintext data not as expected"); 6070 } 6071 6072 return 0; 6073 } 6074 6075 static int 6076 test_zuc_cipher_sgl(const struct wireless_test_data *tdata, 6077 enum rte_crypto_cipher_operation direction) 6078 { 6079 struct crypto_testsuite_params *ts_params = &testsuite_params; 6080 struct crypto_unittest_params *ut_params = &unittest_params; 6081 6082 int retval; 6083 6084 unsigned int plaintext_pad_len, ciphertext_pad_len; 6085 unsigned int plaintext_len = 0; 6086 unsigned int ciphertext_len = 0; 6087 const uint8_t *ciphertext, *plaintext; 6088 uint8_t buffer[2048]; 6089 struct rte_cryptodev_info dev_info; 6090 6091 /* Check if device supports ZUC EEA3 */ 6092 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6093 tdata->key.len, tdata->cipher_iv.len) < 0) 6094 return TEST_SKIPPED; 6095 6096 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6097 return TEST_SKIPPED; 6098 6099 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6100 6101 uint64_t feat_flags = dev_info.feature_flags; 6102 6103 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6104 printf("Device doesn't support in-place scatter-gather. " 6105 "Test Skipped.\n"); 6106 return TEST_SKIPPED; 6107 } 6108 6109 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6110 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6111 printf("Device doesn't support RAW data-path APIs.\n"); 6112 return TEST_SKIPPED; 6113 } 6114 6115 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6116 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6117 6118 /* Append data which is padded to a multiple */ 6119 /* of the algorithms block size */ 6120 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6121 6122 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6123 plaintext_pad_len, 10, 0); 6124 6125 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6126 tdata->plaintext.data); 6127 } else { 6128 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6129 6130 /* Append data which is padded to a multiple */ 6131 /* of the algorithms block size */ 6132 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 6133 6134 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6135 ciphertext_pad_len, 10, 0); 6136 6137 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6138 tdata->ciphertext.data); 6139 6140 } 6141 6142 /* Create ZUC session */ 6143 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 6144 direction, 6145 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6146 tdata->key.data, tdata->key.len, 6147 tdata->cipher_iv.len); 6148 if (retval < 0) 6149 return retval; 6150 6151 /* Clear mbuf payload */ 6152 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) 6153 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 6154 else 6155 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, tdata->ciphertext.data); 6156 6157 /* Create ZUC operation */ 6158 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6159 tdata->cipher_iv.len, tdata->plaintext.len, 6160 tdata->validCipherOffsetInBits.len); 6161 if (retval < 0) 6162 return retval; 6163 6164 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6165 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6166 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 6167 else 6168 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6169 ut_params->op); 6170 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6171 6172 ut_params->obuf = ut_params->op->sym->m_dst; 6173 6174 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6175 if (ut_params->obuf) 6176 ciphertext = rte_pktmbuf_read(ut_params->obuf, 6177 0, plaintext_len, buffer); 6178 else 6179 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 6180 0, plaintext_len, buffer); 6181 6182 /* Validate obuf */ 6183 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6184 6185 /* Validate obuf */ 6186 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6187 ciphertext, 6188 tdata->ciphertext.data, 6189 tdata->validCipherLenInBits.len, 6190 "ZUC Ciphertext data not as expected"); 6191 } else { 6192 if (ut_params->obuf) 6193 plaintext = rte_pktmbuf_read(ut_params->obuf, 6194 0, ciphertext_len, buffer); 6195 else 6196 plaintext = rte_pktmbuf_read(ut_params->ibuf, 6197 0, ciphertext_len, buffer); 6198 6199 /* Validate obuf */ 6200 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 6201 6202 /* Validate obuf */ 6203 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6204 plaintext, 6205 tdata->plaintext.data, 6206 tdata->validCipherLenInBits.len, 6207 "ZUC Plaintext data not as expected"); 6208 } 6209 6210 return 0; 6211 } 6212 6213 static int 6214 test_zuc_authentication(const struct wireless_test_data *tdata, 6215 enum rte_crypto_auth_operation auth_op) 6216 { 6217 struct crypto_testsuite_params *ts_params = &testsuite_params; 6218 struct crypto_unittest_params *ut_params = &unittest_params; 6219 6220 int retval; 6221 unsigned plaintext_pad_len; 6222 unsigned plaintext_len; 6223 uint8_t *plaintext; 6224 6225 struct rte_cryptodev_info dev_info; 6226 6227 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6228 uint64_t feat_flags = dev_info.feature_flags; 6229 6230 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 6231 (tdata->validAuthLenInBits.len % 8 != 0)) { 6232 printf("Device doesn't support NON-Byte Aligned Data.\n"); 6233 return TEST_SKIPPED; 6234 } 6235 6236 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6237 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6238 printf("Device doesn't support RAW data-path APIs.\n"); 6239 return TEST_SKIPPED; 6240 } 6241 6242 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6243 return TEST_SKIPPED; 6244 6245 /* Check if device supports ZUC EIA3 */ 6246 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6247 tdata->key.len, tdata->auth_iv.len, 6248 tdata->digest.len) < 0) 6249 return TEST_SKIPPED; 6250 6251 /* Create ZUC session */ 6252 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 6253 tdata->key.data, tdata->key.len, 6254 tdata->auth_iv.len, tdata->digest.len, 6255 auth_op, RTE_CRYPTO_AUTH_ZUC_EIA3); 6256 if (retval != 0) 6257 return retval; 6258 6259 /* alloc mbuf and set payload */ 6260 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6261 6262 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6263 rte_pktmbuf_tailroom(ut_params->ibuf)); 6264 6265 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6266 /* Append data which is padded to a multiple of */ 6267 /* the algorithms block size */ 6268 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6269 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6270 plaintext_pad_len); 6271 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6272 6273 /* Create ZUC operation */ 6274 retval = create_wireless_algo_hash_operation(tdata->digest.data, 6275 tdata->digest.len, 6276 tdata->auth_iv.data, tdata->auth_iv.len, 6277 plaintext_pad_len, 6278 auth_op, tdata->validAuthLenInBits.len, 0); 6279 if (retval < 0) 6280 return retval; 6281 6282 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6283 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6284 ut_params->op, 0, 1, 1, 0); 6285 else 6286 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6287 ut_params->op); 6288 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6289 ut_params->obuf = ut_params->op->sym->m_src; 6290 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 6291 + plaintext_pad_len; 6292 6293 if (auth_op != RTE_CRYPTO_AUTH_OP_VERIFY) { 6294 /* Validate obuf */ 6295 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6296 ut_params->digest, 6297 tdata->digest.data, 6298 tdata->digest.len, 6299 "ZUC Generated auth tag not as expected"); 6300 return 0; 6301 } 6302 6303 /* Validate obuf */ 6304 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 6305 return 0; 6306 else 6307 return -1; 6308 6309 return 0; 6310 } 6311 6312 static int 6313 test_zuc_auth_cipher(const struct wireless_test_data *tdata, 6314 uint8_t op_mode, uint8_t verify) 6315 { 6316 struct crypto_testsuite_params *ts_params = &testsuite_params; 6317 struct crypto_unittest_params *ut_params = &unittest_params; 6318 6319 int retval; 6320 6321 uint8_t *plaintext = NULL, *ciphertext = NULL; 6322 unsigned int plaintext_pad_len; 6323 unsigned int plaintext_len; 6324 unsigned int ciphertext_pad_len; 6325 unsigned int ciphertext_len; 6326 6327 struct rte_cryptodev_info dev_info; 6328 6329 /* Check if device supports ZUC EEA3 */ 6330 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6331 tdata->key.len, tdata->cipher_iv.len) < 0) 6332 return TEST_SKIPPED; 6333 6334 /* Check if device supports ZUC EIA3 */ 6335 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6336 tdata->key.len, tdata->auth_iv.len, 6337 tdata->digest.len) < 0) 6338 return TEST_SKIPPED; 6339 6340 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6341 6342 uint64_t feat_flags = dev_info.feature_flags; 6343 6344 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6345 printf("Device doesn't support digest encrypted.\n"); 6346 return TEST_SKIPPED; 6347 } 6348 if (op_mode == IN_PLACE) { 6349 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6350 printf("Device doesn't support in-place scatter-gather " 6351 "in both input and output mbufs.\n"); 6352 return TEST_SKIPPED; 6353 } 6354 6355 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6356 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6357 printf("Device doesn't support RAW data-path APIs.\n"); 6358 return TEST_SKIPPED; 6359 } 6360 } else { 6361 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6362 return TEST_SKIPPED; 6363 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6364 printf("Device doesn't support out-of-place scatter-gather " 6365 "in both input and output mbufs.\n"); 6366 return TEST_SKIPPED; 6367 } 6368 } 6369 6370 /* Create ZUC session */ 6371 retval = create_wireless_algo_auth_cipher_session( 6372 ts_params->valid_devs[0], 6373 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6374 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6375 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6376 : RTE_CRYPTO_AUTH_OP_GENERATE), 6377 RTE_CRYPTO_AUTH_ZUC_EIA3, 6378 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6379 tdata->key.data, tdata->key.len, 6380 tdata->auth_iv.len, tdata->digest.len, 6381 tdata->cipher_iv.len); 6382 6383 if (retval != 0) 6384 return retval; 6385 6386 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6387 if (op_mode == OUT_OF_PLACE) 6388 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6389 6390 /* clear mbuf payload */ 6391 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6392 rte_pktmbuf_tailroom(ut_params->ibuf)); 6393 if (op_mode == OUT_OF_PLACE) 6394 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 6395 rte_pktmbuf_tailroom(ut_params->obuf)); 6396 6397 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6398 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6399 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6400 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6401 6402 if (verify) { 6403 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6404 ciphertext_pad_len); 6405 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6406 debug_hexdump(stdout, "ciphertext:", ciphertext, 6407 ciphertext_len); 6408 } else { 6409 /* make sure enough space to cover partial digest verify case */ 6410 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6411 ciphertext_pad_len); 6412 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6413 debug_hexdump(stdout, "plaintext:", plaintext, 6414 plaintext_len); 6415 } 6416 6417 if (op_mode == OUT_OF_PLACE) 6418 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 6419 6420 /* Create ZUC operation */ 6421 retval = create_wireless_algo_auth_cipher_operation( 6422 tdata->digest.data, tdata->digest.len, 6423 tdata->cipher_iv.data, tdata->cipher_iv.len, 6424 tdata->auth_iv.data, tdata->auth_iv.len, 6425 (tdata->digest.offset_bytes == 0 ? 6426 (verify ? ciphertext_pad_len : plaintext_pad_len) 6427 : tdata->digest.offset_bytes), 6428 tdata->validCipherLenInBits.len, 6429 tdata->validCipherOffsetInBits.len, 6430 tdata->validAuthLenInBits.len, 6431 0, 6432 op_mode, 0, verify); 6433 6434 if (retval < 0) 6435 return retval; 6436 6437 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6438 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6439 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 6440 else 6441 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6442 ut_params->op); 6443 6444 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6445 6446 ut_params->obuf = (op_mode == IN_PLACE ? 6447 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6448 6449 6450 if (verify) { 6451 if (ut_params->obuf) 6452 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 6453 uint8_t *); 6454 else 6455 plaintext = ciphertext; 6456 6457 debug_hexdump(stdout, "plaintext:", plaintext, 6458 (tdata->plaintext.len >> 3) - tdata->digest.len); 6459 debug_hexdump(stdout, "plaintext expected:", 6460 tdata->plaintext.data, 6461 (tdata->plaintext.len >> 3) - tdata->digest.len); 6462 } else { 6463 if (ut_params->obuf) 6464 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 6465 uint8_t *); 6466 else 6467 ciphertext = plaintext; 6468 6469 debug_hexdump(stdout, "ciphertext:", ciphertext, 6470 ciphertext_len); 6471 debug_hexdump(stdout, "ciphertext expected:", 6472 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6473 6474 ut_params->digest = rte_pktmbuf_mtod( 6475 ut_params->obuf, uint8_t *) + 6476 (tdata->digest.offset_bytes == 0 ? 6477 plaintext_pad_len : tdata->digest.offset_bytes); 6478 6479 debug_hexdump(stdout, "digest:", ut_params->digest, 6480 tdata->digest.len); 6481 debug_hexdump(stdout, "digest expected:", 6482 tdata->digest.data, tdata->digest.len); 6483 } 6484 6485 /* Validate obuf */ 6486 if (verify) { 6487 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6488 plaintext, 6489 tdata->plaintext.data, 6490 tdata->plaintext.len >> 3, 6491 "ZUC Plaintext data not as expected"); 6492 } else { 6493 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6494 ciphertext, 6495 tdata->ciphertext.data, 6496 tdata->ciphertext.len >> 3, 6497 "ZUC Ciphertext data not as expected"); 6498 6499 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6500 ut_params->digest, 6501 tdata->digest.data, 6502 tdata->digest.len, 6503 "ZUC Generated auth tag not as expected"); 6504 } 6505 return 0; 6506 } 6507 6508 static int 6509 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata, 6510 uint8_t op_mode, uint8_t verify) 6511 { 6512 struct crypto_testsuite_params *ts_params = &testsuite_params; 6513 struct crypto_unittest_params *ut_params = &unittest_params; 6514 6515 int retval; 6516 6517 const uint8_t *plaintext = NULL; 6518 const uint8_t *ciphertext = NULL; 6519 const uint8_t *digest = NULL; 6520 unsigned int plaintext_pad_len; 6521 unsigned int plaintext_len; 6522 unsigned int ciphertext_pad_len; 6523 unsigned int ciphertext_len; 6524 uint8_t buffer[10000]; 6525 uint8_t digest_buffer[10000]; 6526 6527 struct rte_cryptodev_info dev_info; 6528 6529 /* Check if device supports ZUC EEA3 */ 6530 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6531 tdata->key.len, tdata->cipher_iv.len) < 0) 6532 return TEST_SKIPPED; 6533 6534 /* Check if device supports ZUC EIA3 */ 6535 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6536 tdata->key.len, tdata->auth_iv.len, 6537 tdata->digest.len) < 0) 6538 return TEST_SKIPPED; 6539 6540 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6541 6542 uint64_t feat_flags = dev_info.feature_flags; 6543 6544 if (op_mode == IN_PLACE) { 6545 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6546 printf("Device doesn't support in-place scatter-gather " 6547 "in both input and output mbufs.\n"); 6548 return TEST_SKIPPED; 6549 } 6550 6551 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6552 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6553 printf("Device doesn't support RAW data-path APIs.\n"); 6554 return TEST_SKIPPED; 6555 } 6556 } else { 6557 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6558 return TEST_SKIPPED; 6559 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6560 printf("Device doesn't support out-of-place scatter-gather " 6561 "in both input and output mbufs.\n"); 6562 return TEST_SKIPPED; 6563 } 6564 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6565 printf("Device doesn't support digest encrypted.\n"); 6566 return TEST_SKIPPED; 6567 } 6568 } 6569 6570 /* Create ZUC session */ 6571 retval = create_wireless_algo_auth_cipher_session( 6572 ts_params->valid_devs[0], 6573 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6574 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6575 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6576 : RTE_CRYPTO_AUTH_OP_GENERATE), 6577 RTE_CRYPTO_AUTH_ZUC_EIA3, 6578 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6579 tdata->key.data, tdata->key.len, 6580 tdata->auth_iv.len, tdata->digest.len, 6581 tdata->cipher_iv.len); 6582 6583 if (retval != 0) 6584 return retval; 6585 6586 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6587 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6588 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6589 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6590 6591 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6592 plaintext_pad_len, 15, 0); 6593 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6594 "Failed to allocate input buffer in mempool"); 6595 6596 if (op_mode == OUT_OF_PLACE) { 6597 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 6598 plaintext_pad_len, 15, 0); 6599 TEST_ASSERT_NOT_NULL(ut_params->obuf, 6600 "Failed to allocate output buffer in mempool"); 6601 } 6602 6603 if (verify) { 6604 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6605 tdata->ciphertext.data); 6606 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6607 ciphertext_len, buffer); 6608 debug_hexdump(stdout, "ciphertext:", ciphertext, 6609 ciphertext_len); 6610 } else { 6611 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6612 tdata->plaintext.data); 6613 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6614 plaintext_len, buffer); 6615 debug_hexdump(stdout, "plaintext:", plaintext, 6616 plaintext_len); 6617 } 6618 memset(buffer, 0, sizeof(buffer)); 6619 6620 /* Create ZUC operation */ 6621 retval = create_wireless_algo_auth_cipher_operation( 6622 tdata->digest.data, tdata->digest.len, 6623 tdata->cipher_iv.data, tdata->cipher_iv.len, 6624 tdata->auth_iv.data, tdata->auth_iv.len, 6625 (tdata->digest.offset_bytes == 0 ? 6626 (verify ? ciphertext_pad_len : plaintext_pad_len) 6627 : tdata->digest.offset_bytes), 6628 tdata->validCipherLenInBits.len, 6629 tdata->validCipherOffsetInBits.len, 6630 tdata->validAuthLenInBits.len, 6631 0, 6632 op_mode, 1, verify); 6633 6634 if (retval < 0) 6635 return retval; 6636 6637 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6638 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6639 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 6640 else 6641 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6642 ut_params->op); 6643 6644 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6645 6646 ut_params->obuf = (op_mode == IN_PLACE ? 6647 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6648 6649 if (verify) { 6650 if (ut_params->obuf) 6651 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 6652 plaintext_len, buffer); 6653 else 6654 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6655 plaintext_len, buffer); 6656 6657 debug_hexdump(stdout, "plaintext:", plaintext, 6658 (tdata->plaintext.len >> 3) - tdata->digest.len); 6659 debug_hexdump(stdout, "plaintext expected:", 6660 tdata->plaintext.data, 6661 (tdata->plaintext.len >> 3) - tdata->digest.len); 6662 } else { 6663 if (ut_params->obuf) 6664 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 6665 ciphertext_len, buffer); 6666 else 6667 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6668 ciphertext_len, buffer); 6669 6670 debug_hexdump(stdout, "ciphertext:", ciphertext, 6671 ciphertext_len); 6672 debug_hexdump(stdout, "ciphertext expected:", 6673 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6674 6675 if (ut_params->obuf) 6676 digest = rte_pktmbuf_read(ut_params->obuf, 6677 (tdata->digest.offset_bytes == 0 ? 6678 plaintext_pad_len : tdata->digest.offset_bytes), 6679 tdata->digest.len, digest_buffer); 6680 else 6681 digest = rte_pktmbuf_read(ut_params->ibuf, 6682 (tdata->digest.offset_bytes == 0 ? 6683 plaintext_pad_len : tdata->digest.offset_bytes), 6684 tdata->digest.len, digest_buffer); 6685 6686 debug_hexdump(stdout, "digest:", digest, 6687 tdata->digest.len); 6688 debug_hexdump(stdout, "digest expected:", 6689 tdata->digest.data, tdata->digest.len); 6690 } 6691 6692 /* Validate obuf */ 6693 if (verify) { 6694 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6695 plaintext, 6696 tdata->plaintext.data, 6697 tdata->plaintext.len >> 3, 6698 "ZUC Plaintext data not as expected"); 6699 } else { 6700 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6701 ciphertext, 6702 tdata->ciphertext.data, 6703 tdata->validDataLenInBits.len, 6704 "ZUC Ciphertext data not as expected"); 6705 6706 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6707 digest, 6708 tdata->digest.data, 6709 tdata->digest.len, 6710 "ZUC Generated auth tag not as expected"); 6711 } 6712 return 0; 6713 } 6714 6715 static int 6716 test_kasumi_encryption_test_case_1(void) 6717 { 6718 return test_kasumi_encryption(&kasumi_test_case_1); 6719 } 6720 6721 static int 6722 test_kasumi_encryption_test_case_1_sgl(void) 6723 { 6724 return test_kasumi_encryption_sgl(&kasumi_test_case_1); 6725 } 6726 6727 static int 6728 test_kasumi_encryption_test_case_1_oop(void) 6729 { 6730 return test_kasumi_encryption_oop(&kasumi_test_case_1); 6731 } 6732 6733 static int 6734 test_kasumi_encryption_test_case_1_oop_sgl(void) 6735 { 6736 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1); 6737 } 6738 6739 static int 6740 test_kasumi_encryption_test_case_2(void) 6741 { 6742 return test_kasumi_encryption(&kasumi_test_case_2); 6743 } 6744 6745 static int 6746 test_kasumi_encryption_test_case_3(void) 6747 { 6748 return test_kasumi_encryption(&kasumi_test_case_3); 6749 } 6750 6751 static int 6752 test_kasumi_encryption_test_case_4(void) 6753 { 6754 return test_kasumi_encryption(&kasumi_test_case_4); 6755 } 6756 6757 static int 6758 test_kasumi_encryption_test_case_5(void) 6759 { 6760 return test_kasumi_encryption(&kasumi_test_case_5); 6761 } 6762 6763 static int 6764 test_kasumi_decryption_test_case_1(void) 6765 { 6766 return test_kasumi_decryption(&kasumi_test_case_1); 6767 } 6768 6769 static int 6770 test_kasumi_decryption_test_case_1_oop(void) 6771 { 6772 return test_kasumi_decryption_oop(&kasumi_test_case_1); 6773 } 6774 6775 static int 6776 test_kasumi_decryption_test_case_2(void) 6777 { 6778 return test_kasumi_decryption(&kasumi_test_case_2); 6779 } 6780 6781 static int 6782 test_kasumi_decryption_test_case_3(void) 6783 { 6784 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6785 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6786 return TEST_SKIPPED; 6787 return test_kasumi_decryption(&kasumi_test_case_3); 6788 } 6789 6790 static int 6791 test_kasumi_decryption_test_case_4(void) 6792 { 6793 return test_kasumi_decryption(&kasumi_test_case_4); 6794 } 6795 6796 static int 6797 test_kasumi_decryption_test_case_5(void) 6798 { 6799 return test_kasumi_decryption(&kasumi_test_case_5); 6800 } 6801 static int 6802 test_snow3g_encryption_test_case_1(void) 6803 { 6804 return test_snow3g_encryption(&snow3g_test_case_1); 6805 } 6806 6807 static int 6808 test_snow3g_encryption_test_case_1_oop(void) 6809 { 6810 return test_snow3g_encryption_oop(&snow3g_test_case_1); 6811 } 6812 6813 static int 6814 test_snow3g_encryption_test_case_1_oop_sgl(void) 6815 { 6816 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 1, 1); 6817 } 6818 6819 static int 6820 test_snow3g_encryption_test_case_1_oop_lb_in_sgl_out(void) 6821 { 6822 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 0, 1); 6823 } 6824 6825 static int 6826 test_snow3g_encryption_test_case_1_oop_sgl_in_lb_out(void) 6827 { 6828 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 1, 0); 6829 } 6830 6831 static int 6832 test_snow3g_encryption_test_case_1_offset_oop(void) 6833 { 6834 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); 6835 } 6836 6837 static int 6838 test_snow3g_encryption_test_case_2(void) 6839 { 6840 return test_snow3g_encryption(&snow3g_test_case_2); 6841 } 6842 6843 static int 6844 test_snow3g_encryption_test_case_3(void) 6845 { 6846 return test_snow3g_encryption(&snow3g_test_case_3); 6847 } 6848 6849 static int 6850 test_snow3g_encryption_test_case_4(void) 6851 { 6852 return test_snow3g_encryption(&snow3g_test_case_4); 6853 } 6854 6855 static int 6856 test_snow3g_encryption_test_case_5(void) 6857 { 6858 return test_snow3g_encryption(&snow3g_test_case_5); 6859 } 6860 6861 static int 6862 test_snow3g_decryption_test_case_1(void) 6863 { 6864 return test_snow3g_decryption(&snow3g_test_case_1); 6865 } 6866 6867 static int 6868 test_snow3g_decryption_test_case_1_oop(void) 6869 { 6870 return test_snow3g_decryption_oop(&snow3g_test_case_1); 6871 } 6872 6873 static int 6874 test_snow3g_decryption_test_case_2(void) 6875 { 6876 return test_snow3g_decryption(&snow3g_test_case_2); 6877 } 6878 6879 static int 6880 test_snow3g_decryption_test_case_3(void) 6881 { 6882 return test_snow3g_decryption(&snow3g_test_case_3); 6883 } 6884 6885 static int 6886 test_snow3g_decryption_test_case_4(void) 6887 { 6888 return test_snow3g_decryption(&snow3g_test_case_4); 6889 } 6890 6891 static int 6892 test_snow3g_decryption_test_case_5(void) 6893 { 6894 return test_snow3g_decryption(&snow3g_test_case_5); 6895 } 6896 6897 /* 6898 * Function prepares snow3g_hash_test_data from snow3g_test_data. 6899 * Pattern digest from snow3g_test_data must be allocated as 6900 * 4 last bytes in plaintext. 6901 */ 6902 static void 6903 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern, 6904 struct snow3g_hash_test_data *output) 6905 { 6906 if ((pattern != NULL) && (output != NULL)) { 6907 output->key.len = pattern->key.len; 6908 6909 memcpy(output->key.data, 6910 pattern->key.data, pattern->key.len); 6911 6912 output->auth_iv.len = pattern->auth_iv.len; 6913 6914 memcpy(output->auth_iv.data, 6915 pattern->auth_iv.data, pattern->auth_iv.len); 6916 6917 output->plaintext.len = pattern->plaintext.len; 6918 6919 memcpy(output->plaintext.data, 6920 pattern->plaintext.data, pattern->plaintext.len >> 3); 6921 6922 output->digest.len = pattern->digest.len; 6923 6924 memcpy(output->digest.data, 6925 &pattern->plaintext.data[pattern->digest.offset_bytes], 6926 pattern->digest.len); 6927 6928 output->validAuthLenInBits.len = 6929 pattern->validAuthLenInBits.len; 6930 } 6931 } 6932 6933 /* 6934 * Test case verify computed cipher and digest from snow3g_test_case_7 data. 6935 */ 6936 static int 6937 test_snow3g_decryption_with_digest_test_case_1(void) 6938 { 6939 struct snow3g_hash_test_data snow3g_hash_data; 6940 struct rte_cryptodev_info dev_info; 6941 struct crypto_testsuite_params *ts_params = &testsuite_params; 6942 6943 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6944 uint64_t feat_flags = dev_info.feature_flags; 6945 6946 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6947 printf("Device doesn't support encrypted digest operations.\n"); 6948 return TEST_SKIPPED; 6949 } 6950 6951 /* 6952 * Function prepare data for hash verification test case. 6953 * Digest is allocated in 4 last bytes in plaintext, pattern. 6954 */ 6955 snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data); 6956 6957 if (test_snow3g_decryption(&snow3g_test_case_7)) 6958 return TEST_FAILED; 6959 6960 return test_snow3g_authentication_verify(&snow3g_hash_data); 6961 } 6962 6963 static int 6964 test_snow3g_cipher_auth_test_case_1(void) 6965 { 6966 return test_snow3g_cipher_auth(&snow3g_test_case_3); 6967 } 6968 6969 static int 6970 test_snow3g_auth_cipher_test_case_1(void) 6971 { 6972 return test_snow3g_auth_cipher( 6973 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0); 6974 } 6975 6976 static int 6977 test_snow3g_auth_cipher_test_case_2(void) 6978 { 6979 return test_snow3g_auth_cipher( 6980 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0); 6981 } 6982 6983 static int 6984 test_snow3g_auth_cipher_test_case_2_oop(void) 6985 { 6986 return test_snow3g_auth_cipher( 6987 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6988 } 6989 6990 static int 6991 test_snow3g_auth_cipher_part_digest_enc(void) 6992 { 6993 return test_snow3g_auth_cipher( 6994 &snow3g_auth_cipher_partial_digest_encryption, 6995 IN_PLACE, 0); 6996 } 6997 6998 static int 6999 test_snow3g_auth_cipher_part_digest_enc_oop(void) 7000 { 7001 return test_snow3g_auth_cipher( 7002 &snow3g_auth_cipher_partial_digest_encryption, 7003 OUT_OF_PLACE, 0); 7004 } 7005 7006 static int 7007 test_snow3g_auth_cipher_test_case_3_sgl(void) 7008 { 7009 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 7010 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7011 return TEST_SKIPPED; 7012 return test_snow3g_auth_cipher_sgl( 7013 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0); 7014 } 7015 7016 static int 7017 test_snow3g_auth_cipher_test_case_3_oop_sgl(void) 7018 { 7019 return test_snow3g_auth_cipher_sgl( 7020 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0); 7021 } 7022 7023 static int 7024 test_snow3g_auth_cipher_part_digest_enc_sgl(void) 7025 { 7026 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 7027 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7028 return TEST_SKIPPED; 7029 return test_snow3g_auth_cipher_sgl( 7030 &snow3g_auth_cipher_partial_digest_encryption, 7031 IN_PLACE, 0); 7032 } 7033 7034 static int 7035 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void) 7036 { 7037 return test_snow3g_auth_cipher_sgl( 7038 &snow3g_auth_cipher_partial_digest_encryption, 7039 OUT_OF_PLACE, 0); 7040 } 7041 7042 static int 7043 test_snow3g_auth_cipher_total_digest_enc_1(void) 7044 { 7045 return test_snow3g_auth_cipher( 7046 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 0); 7047 } 7048 7049 static int 7050 test_snow3g_auth_cipher_total_digest_enc_1_oop(void) 7051 { 7052 return test_snow3g_auth_cipher( 7053 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 0); 7054 } 7055 7056 static int 7057 test_snow3g_auth_cipher_total_digest_enc_1_sgl(void) 7058 { 7059 return test_snow3g_auth_cipher_sgl( 7060 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 0); 7061 } 7062 7063 static int 7064 test_snow3g_auth_cipher_total_digest_enc_1_oop_sgl(void) 7065 { 7066 return test_snow3g_auth_cipher_sgl( 7067 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 0); 7068 } 7069 7070 static int 7071 test_snow3g_auth_cipher_verify_test_case_1(void) 7072 { 7073 return test_snow3g_auth_cipher( 7074 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1); 7075 } 7076 7077 static int 7078 test_snow3g_auth_cipher_verify_test_case_2(void) 7079 { 7080 return test_snow3g_auth_cipher( 7081 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1); 7082 } 7083 7084 static int 7085 test_snow3g_auth_cipher_verify_test_case_2_oop(void) 7086 { 7087 return test_snow3g_auth_cipher( 7088 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7089 } 7090 7091 static int 7092 test_snow3g_auth_cipher_verify_part_digest_enc(void) 7093 { 7094 return test_snow3g_auth_cipher( 7095 &snow3g_auth_cipher_partial_digest_encryption, 7096 IN_PLACE, 1); 7097 } 7098 7099 static int 7100 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void) 7101 { 7102 return test_snow3g_auth_cipher( 7103 &snow3g_auth_cipher_partial_digest_encryption, 7104 OUT_OF_PLACE, 1); 7105 } 7106 7107 static int 7108 test_snow3g_auth_cipher_verify_test_case_3_sgl(void) 7109 { 7110 return test_snow3g_auth_cipher_sgl( 7111 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1); 7112 } 7113 7114 static int 7115 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void) 7116 { 7117 return test_snow3g_auth_cipher_sgl( 7118 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1); 7119 } 7120 7121 static int 7122 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void) 7123 { 7124 return test_snow3g_auth_cipher_sgl( 7125 &snow3g_auth_cipher_partial_digest_encryption, 7126 IN_PLACE, 1); 7127 } 7128 7129 static int 7130 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void) 7131 { 7132 return test_snow3g_auth_cipher_sgl( 7133 &snow3g_auth_cipher_partial_digest_encryption, 7134 OUT_OF_PLACE, 1); 7135 } 7136 7137 static int 7138 test_snow3g_auth_cipher_verify_total_digest_enc_1(void) 7139 { 7140 return test_snow3g_auth_cipher( 7141 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 1); 7142 } 7143 7144 static int 7145 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop(void) 7146 { 7147 return test_snow3g_auth_cipher( 7148 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 1); 7149 } 7150 7151 static int 7152 test_snow3g_auth_cipher_verify_total_digest_enc_1_sgl(void) 7153 { 7154 return test_snow3g_auth_cipher_sgl( 7155 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 1); 7156 } 7157 7158 static int 7159 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop_sgl(void) 7160 { 7161 return test_snow3g_auth_cipher_sgl( 7162 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 1); 7163 } 7164 7165 static int 7166 test_snow3g_auth_cipher_with_digest_test_case_1(void) 7167 { 7168 return test_snow3g_auth_cipher( 7169 &snow3g_test_case_7, IN_PLACE, 0); 7170 } 7171 7172 static int 7173 test_kasumi_auth_cipher_test_case_1(void) 7174 { 7175 return test_kasumi_auth_cipher( 7176 &kasumi_test_case_3, IN_PLACE, 0); 7177 } 7178 7179 static int 7180 test_kasumi_auth_cipher_test_case_2(void) 7181 { 7182 return test_kasumi_auth_cipher( 7183 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7184 } 7185 7186 static int 7187 test_kasumi_auth_cipher_test_case_2_oop(void) 7188 { 7189 return test_kasumi_auth_cipher( 7190 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7191 } 7192 7193 static int 7194 test_kasumi_auth_cipher_test_case_2_sgl(void) 7195 { 7196 return test_kasumi_auth_cipher_sgl( 7197 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7198 } 7199 7200 static int 7201 test_kasumi_auth_cipher_test_case_2_oop_sgl(void) 7202 { 7203 return test_kasumi_auth_cipher_sgl( 7204 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7205 } 7206 7207 static int 7208 test_kasumi_auth_cipher_verify_test_case_1(void) 7209 { 7210 return test_kasumi_auth_cipher( 7211 &kasumi_test_case_3, IN_PLACE, 1); 7212 } 7213 7214 static int 7215 test_kasumi_auth_cipher_verify_test_case_2(void) 7216 { 7217 return test_kasumi_auth_cipher( 7218 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7219 } 7220 7221 static int 7222 test_kasumi_auth_cipher_verify_test_case_2_oop(void) 7223 { 7224 return test_kasumi_auth_cipher( 7225 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7226 } 7227 7228 static int 7229 test_kasumi_auth_cipher_verify_test_case_2_sgl(void) 7230 { 7231 return test_kasumi_auth_cipher_sgl( 7232 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7233 } 7234 7235 static int 7236 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void) 7237 { 7238 return test_kasumi_auth_cipher_sgl( 7239 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7240 } 7241 7242 static int 7243 test_kasumi_cipher_auth_test_case_1(void) 7244 { 7245 return test_kasumi_cipher_auth(&kasumi_test_case_6); 7246 } 7247 7248 static int 7249 test_zuc_encryption_test_case_1(void) 7250 { 7251 return test_zuc_cipher(&zuc_test_case_cipher_193b, 7252 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7253 } 7254 7255 static int 7256 test_zuc_encryption_test_case_2(void) 7257 { 7258 return test_zuc_cipher(&zuc_test_case_cipher_800b, 7259 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7260 } 7261 7262 static int 7263 test_zuc_encryption_test_case_3(void) 7264 { 7265 return test_zuc_cipher(&zuc_test_case_cipher_1570b, 7266 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7267 } 7268 7269 static int 7270 test_zuc_encryption_test_case_4(void) 7271 { 7272 return test_zuc_cipher(&zuc_test_case_cipher_2798b, 7273 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7274 } 7275 7276 static int 7277 test_zuc_encryption_test_case_5(void) 7278 { 7279 return test_zuc_cipher(&zuc_test_case_cipher_4019b, 7280 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7281 } 7282 7283 static int 7284 test_zuc_encryption_test_case_6_sgl(void) 7285 { 7286 return test_zuc_cipher_sgl(&zuc_test_case_cipher_193b, 7287 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7288 } 7289 7290 static int 7291 test_zuc_decryption_test_case_1(void) 7292 { 7293 return test_zuc_cipher(&zuc_test_case_cipher_193b, 7294 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7295 } 7296 7297 static int 7298 test_zuc_decryption_test_case_2(void) 7299 { 7300 return test_zuc_cipher(&zuc_test_case_cipher_800b, 7301 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7302 } 7303 7304 static int 7305 test_zuc_decryption_test_case_3(void) 7306 { 7307 return test_zuc_cipher(&zuc_test_case_cipher_1570b, 7308 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7309 } 7310 7311 static int 7312 test_zuc_decryption_test_case_4(void) 7313 { 7314 return test_zuc_cipher(&zuc_test_case_cipher_2798b, 7315 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7316 } 7317 7318 static int 7319 test_zuc_decryption_test_case_5(void) 7320 { 7321 return test_zuc_cipher(&zuc_test_case_cipher_4019b, 7322 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7323 } 7324 7325 static int 7326 test_zuc_decryption_test_case_6_sgl(void) 7327 { 7328 return test_zuc_cipher_sgl(&zuc_test_case_cipher_193b, 7329 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7330 } 7331 7332 static int 7333 test_zuc_hash_generate_test_case_1(void) 7334 { 7335 return test_zuc_authentication(&zuc_test_case_auth_1b, 7336 RTE_CRYPTO_AUTH_OP_GENERATE); 7337 } 7338 7339 static int 7340 test_zuc_hash_generate_test_case_2(void) 7341 { 7342 return test_zuc_authentication(&zuc_test_case_auth_90b, 7343 RTE_CRYPTO_AUTH_OP_GENERATE); 7344 } 7345 7346 static int 7347 test_zuc_hash_generate_test_case_3(void) 7348 { 7349 return test_zuc_authentication(&zuc_test_case_auth_577b, 7350 RTE_CRYPTO_AUTH_OP_GENERATE); 7351 } 7352 7353 static int 7354 test_zuc_hash_generate_test_case_4(void) 7355 { 7356 return test_zuc_authentication(&zuc_test_case_auth_2079b, 7357 RTE_CRYPTO_AUTH_OP_GENERATE); 7358 } 7359 7360 static int 7361 test_zuc_hash_generate_test_case_5(void) 7362 { 7363 return test_zuc_authentication(&zuc_test_auth_5670b, 7364 RTE_CRYPTO_AUTH_OP_GENERATE); 7365 } 7366 7367 static int 7368 test_zuc_hash_generate_test_case_6(void) 7369 { 7370 return test_zuc_authentication(&zuc_test_case_auth_128b, 7371 RTE_CRYPTO_AUTH_OP_GENERATE); 7372 } 7373 7374 static int 7375 test_zuc_hash_generate_test_case_7(void) 7376 { 7377 return test_zuc_authentication(&zuc_test_case_auth_2080b, 7378 RTE_CRYPTO_AUTH_OP_GENERATE); 7379 } 7380 7381 static int 7382 test_zuc_hash_generate_test_case_8(void) 7383 { 7384 return test_zuc_authentication(&zuc_test_case_auth_584b, 7385 RTE_CRYPTO_AUTH_OP_GENERATE); 7386 } 7387 7388 static int 7389 test_zuc_hash_verify_test_case_1(void) 7390 { 7391 return test_zuc_authentication(&zuc_test_case_auth_1b, 7392 RTE_CRYPTO_AUTH_OP_VERIFY); 7393 } 7394 7395 static int 7396 test_zuc_hash_verify_test_case_2(void) 7397 { 7398 return test_zuc_authentication(&zuc_test_case_auth_90b, 7399 RTE_CRYPTO_AUTH_OP_VERIFY); 7400 } 7401 7402 static int 7403 test_zuc_hash_verify_test_case_3(void) 7404 { 7405 return test_zuc_authentication(&zuc_test_case_auth_577b, 7406 RTE_CRYPTO_AUTH_OP_VERIFY); 7407 } 7408 7409 static int 7410 test_zuc_hash_verify_test_case_4(void) 7411 { 7412 return test_zuc_authentication(&zuc_test_case_auth_2079b, 7413 RTE_CRYPTO_AUTH_OP_VERIFY); 7414 } 7415 7416 static int 7417 test_zuc_hash_verify_test_case_5(void) 7418 { 7419 return test_zuc_authentication(&zuc_test_auth_5670b, 7420 RTE_CRYPTO_AUTH_OP_VERIFY); 7421 } 7422 7423 static int 7424 test_zuc_hash_verify_test_case_6(void) 7425 { 7426 return test_zuc_authentication(&zuc_test_case_auth_128b, 7427 RTE_CRYPTO_AUTH_OP_VERIFY); 7428 } 7429 7430 static int 7431 test_zuc_hash_verify_test_case_7(void) 7432 { 7433 return test_zuc_authentication(&zuc_test_case_auth_2080b, 7434 RTE_CRYPTO_AUTH_OP_VERIFY); 7435 } 7436 7437 static int 7438 test_zuc_hash_verify_test_case_8(void) 7439 { 7440 return test_zuc_authentication(&zuc_test_case_auth_584b, 7441 RTE_CRYPTO_AUTH_OP_VERIFY); 7442 } 7443 7444 static int 7445 test_zuc_cipher_auth_test_case_1(void) 7446 { 7447 return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b); 7448 } 7449 7450 static int 7451 test_zuc_cipher_auth_test_case_2(void) 7452 { 7453 return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b); 7454 } 7455 7456 static int 7457 test_zuc_auth_cipher_test_case_1(void) 7458 { 7459 return test_zuc_auth_cipher( 7460 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7461 } 7462 7463 static int 7464 test_zuc_auth_cipher_test_case_1_oop(void) 7465 { 7466 return test_zuc_auth_cipher( 7467 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7468 } 7469 7470 static int 7471 test_zuc_auth_cipher_test_case_1_sgl(void) 7472 { 7473 return test_zuc_auth_cipher_sgl( 7474 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7475 } 7476 7477 static int 7478 test_zuc_auth_cipher_test_case_1_oop_sgl(void) 7479 { 7480 return test_zuc_auth_cipher_sgl( 7481 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7482 } 7483 7484 static int 7485 test_zuc_auth_cipher_test_case_2(void) 7486 { 7487 return test_zuc_auth_cipher( 7488 &zuc_auth_cipher_test_case_2, IN_PLACE, 0); 7489 } 7490 7491 static int 7492 test_zuc_auth_cipher_test_case_2_oop(void) 7493 { 7494 return test_zuc_auth_cipher( 7495 &zuc_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7496 } 7497 7498 static int 7499 test_zuc_auth_cipher_verify_test_case_1(void) 7500 { 7501 return test_zuc_auth_cipher( 7502 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7503 } 7504 7505 static int 7506 test_zuc_auth_cipher_verify_test_case_1_oop(void) 7507 { 7508 return test_zuc_auth_cipher( 7509 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7510 } 7511 7512 static int 7513 test_zuc_auth_cipher_verify_test_case_1_sgl(void) 7514 { 7515 return test_zuc_auth_cipher_sgl( 7516 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7517 } 7518 7519 static int 7520 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void) 7521 { 7522 return test_zuc_auth_cipher_sgl( 7523 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7524 } 7525 7526 static int 7527 test_zuc_auth_cipher_verify_test_case_2(void) 7528 { 7529 return test_zuc_auth_cipher( 7530 &zuc_auth_cipher_test_case_2, IN_PLACE, 1); 7531 } 7532 7533 static int 7534 test_zuc_auth_cipher_verify_test_case_2_oop(void) 7535 { 7536 return test_zuc_auth_cipher( 7537 &zuc_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7538 } 7539 7540 static int 7541 test_zuc256_encryption_test_case_1(void) 7542 { 7543 return test_zuc_cipher(&zuc256_test_case_cipher_1, 7544 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7545 } 7546 7547 static int 7548 test_zuc256_encryption_test_case_2(void) 7549 { 7550 return test_zuc_cipher(&zuc256_test_case_cipher_2, 7551 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7552 } 7553 7554 static int 7555 test_zuc256_decryption_test_case_1(void) 7556 { 7557 return test_zuc_cipher(&zuc256_test_case_cipher_1, 7558 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7559 } 7560 7561 static int 7562 test_zuc256_decryption_test_case_2(void) 7563 { 7564 return test_zuc_cipher(&zuc256_test_case_cipher_2, 7565 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7566 } 7567 7568 static int 7569 test_zuc256_hash_generate_4b_tag_test_case_1(void) 7570 { 7571 return test_zuc_authentication(&zuc256_test_case_auth_1, 7572 RTE_CRYPTO_AUTH_OP_GENERATE); 7573 } 7574 7575 static int 7576 test_zuc256_hash_generate_4b_tag_test_case_2(void) 7577 { 7578 return test_zuc_authentication(&zuc256_test_case_auth_2, 7579 RTE_CRYPTO_AUTH_OP_GENERATE); 7580 } 7581 7582 static int 7583 test_zuc256_hash_generate_4b_tag_test_case_3(void) 7584 { 7585 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b, 7586 RTE_CRYPTO_AUTH_OP_GENERATE); 7587 } 7588 7589 static int 7590 test_zuc256_hash_generate_8b_tag_test_case_1(void) 7591 { 7592 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b, 7593 RTE_CRYPTO_AUTH_OP_GENERATE); 7594 } 7595 7596 static int 7597 test_zuc256_hash_generate_16b_tag_test_case_1(void) 7598 { 7599 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b, 7600 RTE_CRYPTO_AUTH_OP_GENERATE); 7601 } 7602 7603 static int 7604 test_zuc256_hash_verify_4b_tag_test_case_1(void) 7605 { 7606 return test_zuc_authentication(&zuc256_test_case_auth_1, 7607 RTE_CRYPTO_AUTH_OP_VERIFY); 7608 } 7609 7610 static int 7611 test_zuc256_hash_verify_4b_tag_test_case_2(void) 7612 { 7613 return test_zuc_authentication(&zuc256_test_case_auth_2, 7614 RTE_CRYPTO_AUTH_OP_VERIFY); 7615 } 7616 7617 static int 7618 test_zuc256_hash_verify_4b_tag_test_case_3(void) 7619 { 7620 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b, 7621 RTE_CRYPTO_AUTH_OP_VERIFY); 7622 } 7623 7624 static int 7625 test_zuc256_hash_verify_8b_tag_test_case_1(void) 7626 { 7627 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b, 7628 RTE_CRYPTO_AUTH_OP_VERIFY); 7629 } 7630 7631 static int 7632 test_zuc256_hash_verify_16b_tag_test_case_1(void) 7633 { 7634 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b, 7635 RTE_CRYPTO_AUTH_OP_VERIFY); 7636 } 7637 7638 static int 7639 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata) 7640 { 7641 uint8_t dev_id = testsuite_params.valid_devs[0]; 7642 7643 struct rte_cryptodev_sym_capability_idx cap_idx; 7644 7645 /* Check if device supports particular cipher algorithm */ 7646 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 7647 cap_idx.algo.cipher = tdata->cipher_algo; 7648 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 7649 return TEST_SKIPPED; 7650 7651 /* Check if device supports particular hash algorithm */ 7652 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 7653 cap_idx.algo.auth = tdata->auth_algo; 7654 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 7655 return TEST_SKIPPED; 7656 7657 return 0; 7658 } 7659 7660 static int 7661 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata, 7662 uint8_t op_mode, uint8_t verify) 7663 { 7664 struct crypto_testsuite_params *ts_params = &testsuite_params; 7665 struct crypto_unittest_params *ut_params = &unittest_params; 7666 7667 int retval; 7668 7669 uint8_t *plaintext = NULL, *ciphertext = NULL; 7670 unsigned int plaintext_pad_len; 7671 unsigned int plaintext_len; 7672 unsigned int ciphertext_pad_len; 7673 unsigned int ciphertext_len; 7674 7675 struct rte_cryptodev_info dev_info; 7676 struct rte_crypto_op *op; 7677 7678 /* Check if device supports particular algorithms separately */ 7679 if (test_mixed_check_if_unsupported(tdata)) 7680 return TEST_SKIPPED; 7681 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7682 return TEST_SKIPPED; 7683 7684 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7685 7686 uint64_t feat_flags = dev_info.feature_flags; 7687 7688 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7689 printf("Device doesn't support digest encrypted.\n"); 7690 return TEST_SKIPPED; 7691 } 7692 7693 /* Create the session */ 7694 if (verify) 7695 retval = create_wireless_algo_cipher_auth_session( 7696 ts_params->valid_devs[0], 7697 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7698 RTE_CRYPTO_AUTH_OP_VERIFY, 7699 tdata->auth_algo, 7700 tdata->cipher_algo, 7701 tdata->auth_key.data, tdata->auth_key.len, 7702 tdata->auth_iv.len, tdata->digest_enc.len, 7703 tdata->cipher_iv.len); 7704 else 7705 retval = create_wireless_algo_auth_cipher_session( 7706 ts_params->valid_devs[0], 7707 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7708 RTE_CRYPTO_AUTH_OP_GENERATE, 7709 tdata->auth_algo, 7710 tdata->cipher_algo, 7711 tdata->auth_key.data, tdata->auth_key.len, 7712 tdata->auth_iv.len, tdata->digest_enc.len, 7713 tdata->cipher_iv.len); 7714 if (retval != 0) 7715 return retval; 7716 7717 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7718 if (op_mode == OUT_OF_PLACE) 7719 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7720 7721 /* clear mbuf payload */ 7722 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7723 rte_pktmbuf_tailroom(ut_params->ibuf)); 7724 if (op_mode == OUT_OF_PLACE) { 7725 7726 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 7727 rte_pktmbuf_tailroom(ut_params->obuf)); 7728 } 7729 7730 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 7731 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 7732 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 7733 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 7734 7735 if (verify) { 7736 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7737 ciphertext_pad_len); 7738 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 7739 debug_hexdump(stdout, "ciphertext:", ciphertext, 7740 ciphertext_len); 7741 } else { 7742 /* make sure enough space to cover partial digest verify case */ 7743 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7744 ciphertext_pad_len); 7745 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 7746 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 7747 } 7748 7749 if (op_mode == OUT_OF_PLACE) 7750 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 7751 7752 /* Create the operation */ 7753 retval = create_wireless_algo_auth_cipher_operation( 7754 tdata->digest_enc.data, tdata->digest_enc.len, 7755 tdata->cipher_iv.data, tdata->cipher_iv.len, 7756 tdata->auth_iv.data, tdata->auth_iv.len, 7757 (tdata->digest_enc.offset == 0 ? 7758 plaintext_pad_len 7759 : tdata->digest_enc.offset), 7760 tdata->validCipherLen.len_bits, 7761 tdata->cipher.offset_bits, 7762 tdata->validAuthLen.len_bits, 7763 tdata->auth.offset_bits, 7764 op_mode, 0, verify); 7765 7766 if (retval < 0) 7767 return retval; 7768 7769 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 7770 7771 /* Check if the op failed because the device doesn't */ 7772 /* support this particular combination of algorithms */ 7773 if (op == NULL && ut_params->op->status == 7774 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 7775 printf("Device doesn't support this mixed combination. " 7776 "Test Skipped.\n"); 7777 return TEST_SKIPPED; 7778 } 7779 ut_params->op = op; 7780 7781 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 7782 7783 ut_params->obuf = (op_mode == IN_PLACE ? 7784 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 7785 7786 if (verify) { 7787 if (ut_params->obuf) 7788 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 7789 uint8_t *); 7790 else 7791 plaintext = ciphertext + 7792 (tdata->cipher.offset_bits >> 3); 7793 7794 debug_hexdump(stdout, "plaintext:", plaintext, 7795 tdata->plaintext.len_bits >> 3); 7796 debug_hexdump(stdout, "plaintext expected:", 7797 tdata->plaintext.data, 7798 tdata->plaintext.len_bits >> 3); 7799 } else { 7800 if (ut_params->obuf) 7801 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 7802 uint8_t *); 7803 else 7804 ciphertext = plaintext; 7805 7806 debug_hexdump(stdout, "ciphertext:", ciphertext, 7807 ciphertext_len); 7808 debug_hexdump(stdout, "ciphertext expected:", 7809 tdata->ciphertext.data, 7810 tdata->ciphertext.len_bits >> 3); 7811 7812 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 7813 + (tdata->digest_enc.offset == 0 ? 7814 plaintext_pad_len : tdata->digest_enc.offset); 7815 7816 debug_hexdump(stdout, "digest:", ut_params->digest, 7817 tdata->digest_enc.len); 7818 debug_hexdump(stdout, "digest expected:", 7819 tdata->digest_enc.data, 7820 tdata->digest_enc.len); 7821 } 7822 7823 if (!verify) { 7824 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7825 ut_params->digest, 7826 tdata->digest_enc.data, 7827 tdata->digest_enc.len, 7828 "Generated auth tag not as expected"); 7829 } 7830 7831 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 7832 if (verify) { 7833 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7834 plaintext, 7835 tdata->plaintext.data, 7836 tdata->plaintext.len_bits >> 3, 7837 "Plaintext data not as expected"); 7838 } else { 7839 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7840 ciphertext, 7841 tdata->ciphertext.data, 7842 tdata->validDataLen.len_bits, 7843 "Ciphertext data not as expected"); 7844 } 7845 } 7846 7847 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7848 "crypto op processing failed"); 7849 7850 return 0; 7851 } 7852 7853 static int 7854 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata, 7855 uint8_t op_mode, uint8_t verify) 7856 { 7857 struct crypto_testsuite_params *ts_params = &testsuite_params; 7858 struct crypto_unittest_params *ut_params = &unittest_params; 7859 7860 int retval; 7861 7862 const uint8_t *plaintext = NULL; 7863 const uint8_t *ciphertext = NULL; 7864 const uint8_t *digest = NULL; 7865 unsigned int plaintext_pad_len; 7866 unsigned int plaintext_len; 7867 unsigned int ciphertext_pad_len; 7868 unsigned int ciphertext_len; 7869 uint8_t buffer[10000]; 7870 uint8_t digest_buffer[10000]; 7871 7872 struct rte_cryptodev_info dev_info; 7873 struct rte_crypto_op *op; 7874 7875 /* Check if device supports particular algorithms */ 7876 if (test_mixed_check_if_unsupported(tdata)) 7877 return TEST_SKIPPED; 7878 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7879 return TEST_SKIPPED; 7880 7881 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7882 7883 uint64_t feat_flags = dev_info.feature_flags; 7884 7885 if (op_mode == IN_PLACE) { 7886 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 7887 printf("Device doesn't support in-place scatter-gather " 7888 "in both input and output mbufs.\n"); 7889 return TEST_SKIPPED; 7890 } 7891 } else { 7892 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 7893 printf("Device doesn't support out-of-place scatter-gather " 7894 "in both input and output mbufs.\n"); 7895 return TEST_SKIPPED; 7896 } 7897 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7898 printf("Device doesn't support digest encrypted.\n"); 7899 return TEST_SKIPPED; 7900 } 7901 } 7902 7903 /* Create the session */ 7904 if (verify) 7905 retval = create_wireless_algo_cipher_auth_session( 7906 ts_params->valid_devs[0], 7907 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7908 RTE_CRYPTO_AUTH_OP_VERIFY, 7909 tdata->auth_algo, 7910 tdata->cipher_algo, 7911 tdata->auth_key.data, tdata->auth_key.len, 7912 tdata->auth_iv.len, tdata->digest_enc.len, 7913 tdata->cipher_iv.len); 7914 else 7915 retval = create_wireless_algo_auth_cipher_session( 7916 ts_params->valid_devs[0], 7917 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7918 RTE_CRYPTO_AUTH_OP_GENERATE, 7919 tdata->auth_algo, 7920 tdata->cipher_algo, 7921 tdata->auth_key.data, tdata->auth_key.len, 7922 tdata->auth_iv.len, tdata->digest_enc.len, 7923 tdata->cipher_iv.len); 7924 if (retval != 0) 7925 return retval; 7926 7927 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 7928 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 7929 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 7930 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 7931 7932 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 7933 ciphertext_pad_len, 15, 0); 7934 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 7935 "Failed to allocate input buffer in mempool"); 7936 7937 if (op_mode == OUT_OF_PLACE) { 7938 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 7939 plaintext_pad_len, 15, 0); 7940 TEST_ASSERT_NOT_NULL(ut_params->obuf, 7941 "Failed to allocate output buffer in mempool"); 7942 } 7943 7944 if (verify) { 7945 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 7946 tdata->ciphertext.data); 7947 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7948 ciphertext_len, buffer); 7949 debug_hexdump(stdout, "ciphertext:", ciphertext, 7950 ciphertext_len); 7951 } else { 7952 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 7953 tdata->plaintext.data); 7954 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7955 plaintext_len, buffer); 7956 debug_hexdump(stdout, "plaintext:", plaintext, 7957 plaintext_len); 7958 } 7959 memset(buffer, 0, sizeof(buffer)); 7960 7961 /* Create the operation */ 7962 retval = create_wireless_algo_auth_cipher_operation( 7963 tdata->digest_enc.data, tdata->digest_enc.len, 7964 tdata->cipher_iv.data, tdata->cipher_iv.len, 7965 tdata->auth_iv.data, tdata->auth_iv.len, 7966 (tdata->digest_enc.offset == 0 ? 7967 plaintext_pad_len 7968 : tdata->digest_enc.offset), 7969 tdata->validCipherLen.len_bits, 7970 tdata->cipher.offset_bits, 7971 tdata->validAuthLen.len_bits, 7972 tdata->auth.offset_bits, 7973 op_mode, 1, verify); 7974 7975 if (retval < 0) 7976 return retval; 7977 7978 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 7979 7980 /* Check if the op failed because the device doesn't */ 7981 /* support this particular combination of algorithms */ 7982 if (op == NULL && ut_params->op->status == 7983 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 7984 printf("Device doesn't support this mixed combination. " 7985 "Test Skipped.\n"); 7986 return TEST_SKIPPED; 7987 } 7988 ut_params->op = op; 7989 7990 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 7991 7992 ut_params->obuf = (op_mode == IN_PLACE ? 7993 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 7994 7995 if (verify) { 7996 if (ut_params->obuf) 7997 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 7998 plaintext_len, buffer); 7999 else 8000 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 8001 plaintext_len, buffer); 8002 8003 debug_hexdump(stdout, "plaintext:", plaintext, 8004 (tdata->plaintext.len_bits >> 3) - 8005 tdata->digest_enc.len); 8006 debug_hexdump(stdout, "plaintext expected:", 8007 tdata->plaintext.data, 8008 (tdata->plaintext.len_bits >> 3) - 8009 tdata->digest_enc.len); 8010 } else { 8011 if (ut_params->obuf) 8012 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 8013 ciphertext_len, buffer); 8014 else 8015 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 8016 ciphertext_len, buffer); 8017 8018 debug_hexdump(stdout, "ciphertext:", ciphertext, 8019 ciphertext_len); 8020 debug_hexdump(stdout, "ciphertext expected:", 8021 tdata->ciphertext.data, 8022 tdata->ciphertext.len_bits >> 3); 8023 8024 if (ut_params->obuf) 8025 digest = rte_pktmbuf_read(ut_params->obuf, 8026 (tdata->digest_enc.offset == 0 ? 8027 plaintext_pad_len : 8028 tdata->digest_enc.offset), 8029 tdata->digest_enc.len, digest_buffer); 8030 else 8031 digest = rte_pktmbuf_read(ut_params->ibuf, 8032 (tdata->digest_enc.offset == 0 ? 8033 plaintext_pad_len : 8034 tdata->digest_enc.offset), 8035 tdata->digest_enc.len, digest_buffer); 8036 8037 debug_hexdump(stdout, "digest:", digest, 8038 tdata->digest_enc.len); 8039 debug_hexdump(stdout, "digest expected:", 8040 tdata->digest_enc.data, tdata->digest_enc.len); 8041 } 8042 8043 if (!verify) { 8044 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8045 digest, 8046 tdata->digest_enc.data, 8047 tdata->digest_enc.len, 8048 "Generated auth tag not as expected"); 8049 } 8050 8051 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 8052 if (verify) { 8053 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 8054 plaintext, 8055 tdata->plaintext.data, 8056 tdata->plaintext.len_bits >> 3, 8057 "Plaintext data not as expected"); 8058 } else { 8059 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 8060 ciphertext, 8061 tdata->ciphertext.data, 8062 tdata->validDataLen.len_bits, 8063 "Ciphertext data not as expected"); 8064 } 8065 } 8066 8067 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8068 "crypto op processing failed"); 8069 8070 return 0; 8071 } 8072 8073 /** AUTH AES CMAC + CIPHER AES CTR */ 8074 8075 static int 8076 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 8077 { 8078 return test_mixed_auth_cipher( 8079 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8080 } 8081 8082 static int 8083 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 8084 { 8085 return test_mixed_auth_cipher( 8086 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8087 } 8088 8089 static int 8090 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 8091 { 8092 return test_mixed_auth_cipher_sgl( 8093 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8094 } 8095 8096 static int 8097 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 8098 { 8099 return test_mixed_auth_cipher_sgl( 8100 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8101 } 8102 8103 static int 8104 test_aes_cmac_aes_ctr_digest_enc_test_case_2(void) 8105 { 8106 return test_mixed_auth_cipher( 8107 &auth_aes_cmac_cipher_aes_ctr_test_case_2, IN_PLACE, 0); 8108 } 8109 8110 static int 8111 test_aes_cmac_aes_ctr_digest_enc_test_case_2_oop(void) 8112 { 8113 return test_mixed_auth_cipher( 8114 &auth_aes_cmac_cipher_aes_ctr_test_case_2, OUT_OF_PLACE, 0); 8115 } 8116 8117 static int 8118 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 8119 { 8120 return test_mixed_auth_cipher( 8121 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8122 } 8123 8124 static int 8125 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2(void) 8126 { 8127 return test_mixed_auth_cipher( 8128 &auth_aes_cmac_cipher_aes_ctr_test_case_2, IN_PLACE, 1); 8129 } 8130 8131 static int 8132 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 8133 { 8134 return test_mixed_auth_cipher( 8135 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8136 } 8137 8138 static int 8139 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 8140 { 8141 return test_mixed_auth_cipher_sgl( 8142 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8143 } 8144 8145 static int 8146 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 8147 { 8148 return test_mixed_auth_cipher_sgl( 8149 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8150 } 8151 8152 static int 8153 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2_oop(void) 8154 { 8155 return test_mixed_auth_cipher( 8156 &auth_aes_cmac_cipher_aes_ctr_test_case_2, OUT_OF_PLACE, 1); 8157 } 8158 8159 /** MIXED AUTH + CIPHER */ 8160 8161 static int 8162 test_auth_zuc_cipher_snow_test_case_1(void) 8163 { 8164 return test_mixed_auth_cipher( 8165 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 8166 } 8167 8168 static int 8169 test_verify_auth_zuc_cipher_snow_test_case_1(void) 8170 { 8171 return test_mixed_auth_cipher( 8172 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 8173 } 8174 8175 static int 8176 test_auth_zuc_cipher_snow_test_case_1_inplace(void) 8177 { 8178 return test_mixed_auth_cipher( 8179 &auth_zuc_cipher_snow_test_case_1, IN_PLACE, 0); 8180 } 8181 8182 static int 8183 test_verify_auth_zuc_cipher_snow_test_case_1_inplace(void) 8184 { 8185 return test_mixed_auth_cipher( 8186 &auth_zuc_cipher_snow_test_case_1, IN_PLACE, 1); 8187 } 8188 8189 8190 static int 8191 test_auth_aes_cmac_cipher_snow_test_case_1(void) 8192 { 8193 return test_mixed_auth_cipher( 8194 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 8195 } 8196 8197 static int 8198 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void) 8199 { 8200 return test_mixed_auth_cipher( 8201 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 8202 } 8203 8204 static int 8205 test_auth_aes_cmac_cipher_snow_test_case_1_inplace(void) 8206 { 8207 return test_mixed_auth_cipher( 8208 &auth_aes_cmac_cipher_snow_test_case_1, IN_PLACE, 0); 8209 } 8210 8211 static int 8212 test_verify_auth_aes_cmac_cipher_snow_test_case_1_inplace(void) 8213 { 8214 return test_mixed_auth_cipher( 8215 &auth_aes_cmac_cipher_snow_test_case_1, IN_PLACE, 1); 8216 } 8217 8218 static int 8219 test_auth_zuc_cipher_aes_ctr_test_case_1(void) 8220 { 8221 return test_mixed_auth_cipher( 8222 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8223 } 8224 8225 static int 8226 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void) 8227 { 8228 return test_mixed_auth_cipher( 8229 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8230 } 8231 8232 static int 8233 test_auth_zuc_cipher_aes_ctr_test_case_1_inplace(void) 8234 { 8235 return test_mixed_auth_cipher( 8236 &auth_zuc_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8237 } 8238 8239 static int 8240 test_verify_auth_zuc_cipher_aes_ctr_test_case_1_inplace(void) 8241 { 8242 return test_mixed_auth_cipher( 8243 &auth_zuc_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8244 } 8245 8246 static int 8247 test_auth_snow_cipher_aes_ctr_test_case_1(void) 8248 { 8249 return test_mixed_auth_cipher( 8250 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8251 } 8252 8253 static int 8254 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void) 8255 { 8256 return test_mixed_auth_cipher( 8257 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8258 } 8259 8260 static int 8261 test_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl(void) 8262 { 8263 return test_mixed_auth_cipher_sgl( 8264 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8265 } 8266 8267 static int 8268 test_auth_snow_cipher_aes_ctr_test_case_1_inplace(void) 8269 { 8270 return test_mixed_auth_cipher( 8271 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8272 } 8273 8274 static int 8275 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl(void) 8276 { 8277 return test_mixed_auth_cipher_sgl( 8278 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8279 } 8280 8281 static int 8282 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace(void) 8283 { 8284 return test_mixed_auth_cipher( 8285 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8286 } 8287 8288 static int 8289 test_auth_snow_cipher_zuc_test_case_1(void) 8290 { 8291 return test_mixed_auth_cipher( 8292 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 8293 } 8294 8295 static int 8296 test_verify_auth_snow_cipher_zuc_test_case_1(void) 8297 { 8298 return test_mixed_auth_cipher( 8299 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 8300 } 8301 8302 static int 8303 test_auth_snow_cipher_zuc_test_case_1_inplace(void) 8304 { 8305 return test_mixed_auth_cipher( 8306 &auth_snow_cipher_zuc_test_case_1, IN_PLACE, 0); 8307 } 8308 8309 static int 8310 test_verify_auth_snow_cipher_zuc_test_case_1_inplace(void) 8311 { 8312 return test_mixed_auth_cipher( 8313 &auth_snow_cipher_zuc_test_case_1, IN_PLACE, 1); 8314 } 8315 8316 static int 8317 test_auth_aes_cmac_cipher_zuc_test_case_1(void) 8318 { 8319 return test_mixed_auth_cipher( 8320 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 8321 } 8322 8323 static int 8324 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void) 8325 { 8326 return test_mixed_auth_cipher( 8327 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 8328 } 8329 static int 8330 test_auth_aes_cmac_cipher_zuc_test_case_1_inplace(void) 8331 { 8332 return test_mixed_auth_cipher( 8333 &auth_aes_cmac_cipher_zuc_test_case_1, IN_PLACE, 0); 8334 } 8335 8336 static int 8337 test_verify_auth_aes_cmac_cipher_zuc_test_case_1_inplace(void) 8338 { 8339 return test_mixed_auth_cipher( 8340 &auth_aes_cmac_cipher_zuc_test_case_1, IN_PLACE, 1); 8341 } 8342 8343 static int 8344 test_auth_null_cipher_snow_test_case_1(void) 8345 { 8346 return test_mixed_auth_cipher( 8347 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 8348 } 8349 8350 static int 8351 test_verify_auth_null_cipher_snow_test_case_1(void) 8352 { 8353 return test_mixed_auth_cipher( 8354 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 8355 } 8356 8357 static int 8358 test_auth_null_cipher_zuc_test_case_1(void) 8359 { 8360 return test_mixed_auth_cipher( 8361 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 8362 } 8363 8364 static int 8365 test_verify_auth_null_cipher_zuc_test_case_1(void) 8366 { 8367 return test_mixed_auth_cipher( 8368 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 8369 } 8370 8371 static int 8372 test_auth_snow_cipher_null_test_case_1(void) 8373 { 8374 return test_mixed_auth_cipher( 8375 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0); 8376 } 8377 8378 static int 8379 test_verify_auth_snow_cipher_null_test_case_1(void) 8380 { 8381 return test_mixed_auth_cipher( 8382 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1); 8383 } 8384 8385 static int 8386 test_auth_zuc_cipher_null_test_case_1(void) 8387 { 8388 return test_mixed_auth_cipher( 8389 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0); 8390 } 8391 8392 static int 8393 test_verify_auth_zuc_cipher_null_test_case_1(void) 8394 { 8395 return test_mixed_auth_cipher( 8396 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1); 8397 } 8398 8399 static int 8400 test_auth_null_cipher_aes_ctr_test_case_1(void) 8401 { 8402 return test_mixed_auth_cipher( 8403 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8404 } 8405 8406 static int 8407 test_verify_auth_null_cipher_aes_ctr_test_case_1(void) 8408 { 8409 return test_mixed_auth_cipher( 8410 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8411 } 8412 8413 static int 8414 test_auth_aes_cmac_cipher_null_test_case_1(void) 8415 { 8416 return test_mixed_auth_cipher( 8417 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0); 8418 } 8419 8420 static int 8421 test_verify_auth_aes_cmac_cipher_null_test_case_1(void) 8422 { 8423 return test_mixed_auth_cipher( 8424 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1); 8425 } 8426 8427 /* ***** AEAD algorithm Tests ***** */ 8428 8429 static int 8430 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo, 8431 enum rte_crypto_aead_operation op, 8432 const uint8_t *key, const uint8_t key_len, 8433 const uint16_t aad_len, const uint8_t auth_len, 8434 uint8_t iv_len) 8435 { 8436 uint8_t aead_key[key_len]; 8437 8438 struct crypto_testsuite_params *ts_params = &testsuite_params; 8439 struct crypto_unittest_params *ut_params = &unittest_params; 8440 8441 memcpy(aead_key, key, key_len); 8442 8443 /* Setup AEAD Parameters */ 8444 ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 8445 ut_params->aead_xform.next = NULL; 8446 ut_params->aead_xform.aead.algo = algo; 8447 ut_params->aead_xform.aead.op = op; 8448 ut_params->aead_xform.aead.key.data = aead_key; 8449 ut_params->aead_xform.aead.key.length = key_len; 8450 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 8451 ut_params->aead_xform.aead.iv.length = iv_len; 8452 ut_params->aead_xform.aead.digest_length = auth_len; 8453 ut_params->aead_xform.aead.aad_length = aad_len; 8454 8455 debug_hexdump(stdout, "key:", key, key_len); 8456 8457 /* Create Crypto session*/ 8458 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 8459 &ut_params->aead_xform, ts_params->session_mpool); 8460 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 8461 return TEST_SKIPPED; 8462 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 8463 return 0; 8464 } 8465 8466 static int 8467 create_aead_xform(struct rte_crypto_op *op, 8468 enum rte_crypto_aead_algorithm algo, 8469 enum rte_crypto_aead_operation aead_op, 8470 uint8_t *key, const uint8_t key_len, 8471 const uint8_t aad_len, const uint8_t auth_len, 8472 uint8_t iv_len) 8473 { 8474 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1), 8475 "failed to allocate space for crypto transform"); 8476 8477 struct rte_crypto_sym_op *sym_op = op->sym; 8478 8479 /* Setup AEAD Parameters */ 8480 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD; 8481 sym_op->xform->next = NULL; 8482 sym_op->xform->aead.algo = algo; 8483 sym_op->xform->aead.op = aead_op; 8484 sym_op->xform->aead.key.data = key; 8485 sym_op->xform->aead.key.length = key_len; 8486 sym_op->xform->aead.iv.offset = IV_OFFSET; 8487 sym_op->xform->aead.iv.length = iv_len; 8488 sym_op->xform->aead.digest_length = auth_len; 8489 sym_op->xform->aead.aad_length = aad_len; 8490 8491 debug_hexdump(stdout, "key:", key, key_len); 8492 8493 return 0; 8494 } 8495 8496 static int 8497 create_aead_operation(enum rte_crypto_aead_operation op, 8498 const struct aead_test_data *tdata) 8499 { 8500 struct crypto_testsuite_params *ts_params = &testsuite_params; 8501 struct crypto_unittest_params *ut_params = &unittest_params; 8502 8503 uint8_t *plaintext, *ciphertext; 8504 unsigned int aad_pad_len, plaintext_pad_len; 8505 8506 /* Generate Crypto op data structure */ 8507 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8508 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8509 TEST_ASSERT_NOT_NULL(ut_params->op, 8510 "Failed to allocate symmetric crypto operation struct"); 8511 8512 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 8513 8514 /* Append aad data */ 8515 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 8516 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16); 8517 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8518 aad_pad_len); 8519 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8520 "no room to append aad"); 8521 8522 sym_op->aead.aad.phys_addr = 8523 rte_pktmbuf_iova(ut_params->ibuf); 8524 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 8525 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len); 8526 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data + 18, 8527 tdata->aad.len); 8528 8529 /* Append IV at the end of the crypto operation*/ 8530 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8531 uint8_t *, IV_OFFSET); 8532 8533 /* Copy IV 1 byte after the IV pointer, according to the API */ 8534 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len); 8535 debug_hexdump(stdout, "iv:", iv_ptr + 1, 8536 tdata->iv.len); 8537 } else { 8538 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 8539 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8540 aad_pad_len); 8541 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8542 "no room to append aad"); 8543 8544 sym_op->aead.aad.phys_addr = 8545 rte_pktmbuf_iova(ut_params->ibuf); 8546 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len); 8547 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 8548 tdata->aad.len); 8549 8550 /* Append IV at the end of the crypto operation*/ 8551 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8552 uint8_t *, IV_OFFSET); 8553 8554 if (tdata->iv.len == 0) { 8555 rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH); 8556 debug_hexdump(stdout, "iv:", iv_ptr, 8557 AES_GCM_J0_LENGTH); 8558 } else { 8559 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 8560 debug_hexdump(stdout, "iv:", iv_ptr, 8561 tdata->iv.len); 8562 } 8563 } 8564 8565 /* Append plaintext/ciphertext */ 8566 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 8567 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 8568 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8569 plaintext_pad_len); 8570 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 8571 8572 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 8573 debug_hexdump(stdout, "plaintext:", plaintext, 8574 tdata->plaintext.len); 8575 8576 if (ut_params->obuf) { 8577 ciphertext = (uint8_t *)rte_pktmbuf_append( 8578 ut_params->obuf, 8579 plaintext_pad_len + aad_pad_len); 8580 TEST_ASSERT_NOT_NULL(ciphertext, 8581 "no room to append ciphertext"); 8582 8583 memset(ciphertext + aad_pad_len, 0, 8584 tdata->ciphertext.len); 8585 } 8586 } else { 8587 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); 8588 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8589 plaintext_pad_len); 8590 TEST_ASSERT_NOT_NULL(ciphertext, 8591 "no room to append ciphertext"); 8592 8593 memcpy(ciphertext, tdata->ciphertext.data, 8594 tdata->ciphertext.len); 8595 debug_hexdump(stdout, "ciphertext:", ciphertext, 8596 tdata->ciphertext.len); 8597 8598 if (ut_params->obuf) { 8599 plaintext = (uint8_t *)rte_pktmbuf_append( 8600 ut_params->obuf, 8601 plaintext_pad_len + aad_pad_len); 8602 TEST_ASSERT_NOT_NULL(plaintext, 8603 "no room to append plaintext"); 8604 8605 memset(plaintext + aad_pad_len, 0, 8606 tdata->plaintext.len); 8607 } 8608 } 8609 8610 /* Append digest data */ 8611 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 8612 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 8613 ut_params->obuf ? ut_params->obuf : 8614 ut_params->ibuf, 8615 tdata->auth_tag.len); 8616 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 8617 "no room to append digest"); 8618 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len); 8619 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 8620 ut_params->obuf ? ut_params->obuf : 8621 ut_params->ibuf, 8622 plaintext_pad_len + 8623 aad_pad_len); 8624 } else { 8625 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 8626 ut_params->ibuf, tdata->auth_tag.len); 8627 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 8628 "no room to append digest"); 8629 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 8630 ut_params->ibuf, 8631 plaintext_pad_len + aad_pad_len); 8632 8633 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 8634 tdata->auth_tag.len); 8635 debug_hexdump(stdout, "digest:", 8636 sym_op->aead.digest.data, 8637 tdata->auth_tag.len); 8638 } 8639 8640 sym_op->aead.data.length = tdata->plaintext.len; 8641 sym_op->aead.data.offset = aad_pad_len; 8642 8643 return 0; 8644 } 8645 8646 static int 8647 test_authenticated_encryption(const struct aead_test_data *tdata) 8648 { 8649 struct crypto_testsuite_params *ts_params = &testsuite_params; 8650 struct crypto_unittest_params *ut_params = &unittest_params; 8651 8652 int retval; 8653 uint8_t *ciphertext, *auth_tag; 8654 uint16_t plaintext_pad_len; 8655 uint32_t i; 8656 struct rte_cryptodev_info dev_info; 8657 8658 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8659 uint64_t feat_flags = dev_info.feature_flags; 8660 8661 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 8662 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 8663 printf("Device doesn't support RAW data-path APIs.\n"); 8664 return TEST_SKIPPED; 8665 } 8666 8667 /* Verify the capabilities */ 8668 struct rte_cryptodev_sym_capability_idx cap_idx; 8669 const struct rte_cryptodev_symmetric_capability *capability; 8670 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 8671 cap_idx.algo.aead = tdata->algo; 8672 capability = rte_cryptodev_sym_capability_get( 8673 ts_params->valid_devs[0], &cap_idx); 8674 if (capability == NULL) 8675 return TEST_SKIPPED; 8676 if (rte_cryptodev_sym_capability_check_aead( 8677 capability, tdata->key.len, tdata->auth_tag.len, 8678 tdata->aad.len, tdata->iv.len)) 8679 return TEST_SKIPPED; 8680 8681 /* Create AEAD session */ 8682 retval = create_aead_session(ts_params->valid_devs[0], 8683 tdata->algo, 8684 RTE_CRYPTO_AEAD_OP_ENCRYPT, 8685 tdata->key.data, tdata->key.len, 8686 tdata->aad.len, tdata->auth_tag.len, 8687 tdata->iv.len); 8688 if (retval < 0) 8689 return retval; 8690 8691 if (tdata->aad.len > MBUF_SIZE) { 8692 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 8693 /* Populate full size of add data */ 8694 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 8695 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 8696 } else 8697 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8698 8699 /* clear mbuf payload */ 8700 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8701 rte_pktmbuf_tailroom(ut_params->ibuf)); 8702 8703 /* Create AEAD operation */ 8704 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 8705 if (retval < 0) 8706 return retval; 8707 8708 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 8709 8710 ut_params->op->sym->m_src = ut_params->ibuf; 8711 8712 /* Process crypto operation */ 8713 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8714 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 8715 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 8716 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 8717 ut_params->op, 0, 0, 0, 0); 8718 else 8719 TEST_ASSERT_NOT_NULL( 8720 process_crypto_request(ts_params->valid_devs[0], 8721 ut_params->op), "failed to process sym crypto op"); 8722 8723 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8724 "crypto op processing failed"); 8725 8726 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 8727 8728 if (ut_params->op->sym->m_dst) { 8729 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8730 uint8_t *); 8731 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 8732 uint8_t *, plaintext_pad_len); 8733 } else { 8734 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 8735 uint8_t *, 8736 ut_params->op->sym->cipher.data.offset); 8737 auth_tag = ciphertext + plaintext_pad_len; 8738 } 8739 8740 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 8741 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 8742 8743 /* Validate obuf */ 8744 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8745 ciphertext, 8746 tdata->ciphertext.data, 8747 tdata->ciphertext.len, 8748 "Ciphertext data not as expected"); 8749 8750 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8751 auth_tag, 8752 tdata->auth_tag.data, 8753 tdata->auth_tag.len, 8754 "Generated auth tag not as expected"); 8755 8756 return 0; 8757 8758 } 8759 8760 #ifdef RTE_LIB_SECURITY 8761 static int 8762 security_proto_supported(enum rte_security_session_action_type action, 8763 enum rte_security_session_protocol proto) 8764 { 8765 struct crypto_testsuite_params *ts_params = &testsuite_params; 8766 8767 const struct rte_security_capability *capabilities; 8768 const struct rte_security_capability *capability; 8769 uint16_t i = 0; 8770 8771 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8772 rte_cryptodev_get_sec_ctx( 8773 ts_params->valid_devs[0]); 8774 8775 8776 capabilities = rte_security_capabilities_get(ctx); 8777 8778 if (capabilities == NULL) 8779 return -ENOTSUP; 8780 8781 while ((capability = &capabilities[i++])->action != 8782 RTE_SECURITY_ACTION_TYPE_NONE) { 8783 if (capability->action == action && 8784 capability->protocol == proto) 8785 return 0; 8786 } 8787 8788 return -ENOTSUP; 8789 } 8790 8791 /* Basic algorithm run function for async inplace mode. 8792 * Creates a session from input parameters and runs one operation 8793 * on input_vec. Checks the output of the crypto operation against 8794 * output_vec. 8795 */ 8796 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc, 8797 enum rte_crypto_auth_operation opa, 8798 const uint8_t *input_vec, unsigned int input_vec_len, 8799 const uint8_t *output_vec, 8800 unsigned int output_vec_len, 8801 enum rte_crypto_cipher_algorithm cipher_alg, 8802 const uint8_t *cipher_key, uint32_t cipher_key_len, 8803 enum rte_crypto_auth_algorithm auth_alg, 8804 const uint8_t *auth_key, uint32_t auth_key_len, 8805 uint8_t bearer, enum rte_security_pdcp_domain domain, 8806 uint8_t packet_direction, uint8_t sn_size, 8807 uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap) 8808 { 8809 struct crypto_testsuite_params *ts_params = &testsuite_params; 8810 struct crypto_unittest_params *ut_params = &unittest_params; 8811 uint8_t *plaintext; 8812 int ret = TEST_SUCCESS; 8813 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8814 rte_cryptodev_get_sec_ctx( 8815 ts_params->valid_devs[0]); 8816 struct rte_cryptodev_info dev_info; 8817 uint64_t feat_flags; 8818 8819 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8820 feat_flags = dev_info.feature_flags; 8821 8822 /* Verify the capabilities */ 8823 struct rte_security_capability_idx sec_cap_idx; 8824 8825 sec_cap_idx.action = ut_params->type; 8826 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 8827 sec_cap_idx.pdcp.domain = domain; 8828 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 8829 return TEST_SKIPPED; 8830 8831 /* Generate test mbuf data */ 8832 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8833 8834 /* clear mbuf payload */ 8835 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8836 rte_pktmbuf_tailroom(ut_params->ibuf)); 8837 8838 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8839 input_vec_len); 8840 memcpy(plaintext, input_vec, input_vec_len); 8841 8842 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 8843 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 8844 printf("Device does not support RAW data-path APIs.\n"); 8845 return TEST_SKIPPED; 8846 } 8847 /* Out of place support */ 8848 if (oop) { 8849 /* 8850 * For out-op-place we need to alloc another mbuf 8851 */ 8852 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8853 rte_pktmbuf_append(ut_params->obuf, output_vec_len); 8854 } 8855 8856 /* Setup Cipher Parameters */ 8857 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8858 ut_params->cipher_xform.cipher.algo = cipher_alg; 8859 ut_params->cipher_xform.cipher.op = opc; 8860 ut_params->cipher_xform.cipher.key.data = cipher_key; 8861 ut_params->cipher_xform.cipher.key.length = cipher_key_len; 8862 ut_params->cipher_xform.cipher.iv.length = 8863 packet_direction ? 4 : 0; 8864 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 8865 8866 /* Setup HMAC Parameters if ICV header is required */ 8867 if (auth_alg != 0) { 8868 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8869 ut_params->auth_xform.next = NULL; 8870 ut_params->auth_xform.auth.algo = auth_alg; 8871 ut_params->auth_xform.auth.op = opa; 8872 ut_params->auth_xform.auth.key.data = auth_key; 8873 ut_params->auth_xform.auth.key.length = auth_key_len; 8874 8875 ut_params->cipher_xform.next = &ut_params->auth_xform; 8876 } else { 8877 ut_params->cipher_xform.next = NULL; 8878 } 8879 8880 struct rte_security_session_conf sess_conf = { 8881 .action_type = ut_params->type, 8882 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 8883 {.pdcp = { 8884 .bearer = bearer, 8885 .domain = domain, 8886 .pkt_dir = packet_direction, 8887 .sn_size = sn_size, 8888 .hfn = packet_direction ? 0 : hfn, 8889 /** 8890 * hfn can be set as pdcp_test_hfn[i] 8891 * if hfn_ovrd is not set. Here, PDCP 8892 * packet direction is just used to 8893 * run half of the cases with session 8894 * HFN and other half with per packet 8895 * HFN. 8896 */ 8897 .hfn_threshold = hfn_threshold, 8898 .hfn_ovrd = packet_direction ? 1 : 0, 8899 .sdap_enabled = sdap, 8900 } }, 8901 .crypto_xform = &ut_params->cipher_xform 8902 }; 8903 8904 /* Create security session */ 8905 ut_params->sec_session = rte_security_session_create(ctx, 8906 &sess_conf, ts_params->session_mpool); 8907 8908 if (!ut_params->sec_session) { 8909 printf("TestCase %s()-%d line %d failed %s: ", 8910 __func__, i, __LINE__, "Failed to allocate session"); 8911 ret = TEST_FAILED; 8912 goto on_err; 8913 } 8914 8915 /* Generate crypto op data structure */ 8916 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8917 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8918 if (!ut_params->op) { 8919 printf("TestCase %s()-%d line %d failed %s: ", 8920 __func__, i, __LINE__, 8921 "Failed to allocate symmetric crypto operation struct"); 8922 ret = TEST_FAILED; 8923 goto on_err; 8924 } 8925 8926 uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op, 8927 uint32_t *, IV_OFFSET); 8928 *per_pkt_hfn = packet_direction ? hfn : 0; 8929 8930 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8931 8932 /* set crypto operation source mbuf */ 8933 ut_params->op->sym->m_src = ut_params->ibuf; 8934 if (oop) 8935 ut_params->op->sym->m_dst = ut_params->obuf; 8936 8937 /* Process crypto operation */ 8938 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 8939 /* filling lengths */ 8940 ut_params->op->sym->cipher.data.length = ut_params->op->sym->m_src->pkt_len; 8941 ut_params->op->sym->auth.data.length = ut_params->op->sym->m_src->pkt_len; 8942 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 8943 ut_params->op, 1, 1, 0, 0); 8944 } else { 8945 ut_params->op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 8946 } 8947 if (ut_params->op == NULL) { 8948 printf("TestCase %s()-%d line %d failed %s: ", 8949 __func__, i, __LINE__, 8950 "failed to process sym crypto op"); 8951 ret = TEST_FAILED; 8952 goto on_err; 8953 } 8954 8955 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8956 printf("TestCase %s()-%d line %d failed %s: ", 8957 __func__, i, __LINE__, "crypto op processing failed"); 8958 ret = TEST_FAILED; 8959 goto on_err; 8960 } 8961 8962 /* Validate obuf */ 8963 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 8964 uint8_t *); 8965 if (oop) { 8966 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8967 uint8_t *); 8968 } 8969 8970 if (memcmp(ciphertext, output_vec, output_vec_len)) { 8971 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8972 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len); 8973 rte_hexdump(stdout, "reference", output_vec, output_vec_len); 8974 ret = TEST_FAILED; 8975 goto on_err; 8976 } 8977 8978 on_err: 8979 rte_crypto_op_free(ut_params->op); 8980 ut_params->op = NULL; 8981 8982 if (ut_params->sec_session) 8983 rte_security_session_destroy(ctx, ut_params->sec_session); 8984 ut_params->sec_session = NULL; 8985 8986 rte_pktmbuf_free(ut_params->ibuf); 8987 ut_params->ibuf = NULL; 8988 if (oop) { 8989 rte_pktmbuf_free(ut_params->obuf); 8990 ut_params->obuf = NULL; 8991 } 8992 8993 return ret; 8994 } 8995 8996 static int 8997 test_pdcp_proto_SGL(int i, int oop, 8998 enum rte_crypto_cipher_operation opc, 8999 enum rte_crypto_auth_operation opa, 9000 uint8_t *input_vec, 9001 unsigned int input_vec_len, 9002 uint8_t *output_vec, 9003 unsigned int output_vec_len, 9004 uint32_t fragsz, 9005 uint32_t fragsz_oop) 9006 { 9007 struct crypto_testsuite_params *ts_params = &testsuite_params; 9008 struct crypto_unittest_params *ut_params = &unittest_params; 9009 uint8_t *plaintext; 9010 struct rte_mbuf *buf, *buf_oop = NULL; 9011 int ret = TEST_SUCCESS; 9012 int to_trn = 0; 9013 int to_trn_tbl[16]; 9014 int segs = 1; 9015 unsigned int trn_data = 0; 9016 struct rte_cryptodev_info dev_info; 9017 uint64_t feat_flags; 9018 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 9019 rte_cryptodev_get_sec_ctx( 9020 ts_params->valid_devs[0]); 9021 struct rte_mbuf *temp_mbuf; 9022 9023 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9024 feat_flags = dev_info.feature_flags; 9025 9026 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9027 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9028 printf("Device does not support RAW data-path APIs.\n"); 9029 return -ENOTSUP; 9030 } 9031 /* Verify the capabilities */ 9032 struct rte_security_capability_idx sec_cap_idx; 9033 9034 sec_cap_idx.action = ut_params->type; 9035 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 9036 sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain; 9037 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 9038 return TEST_SKIPPED; 9039 9040 if (fragsz > input_vec_len) 9041 fragsz = input_vec_len; 9042 9043 uint16_t plaintext_len = fragsz; 9044 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 9045 9046 if (fragsz_oop > output_vec_len) 9047 frag_size_oop = output_vec_len; 9048 9049 int ecx = 0; 9050 if (input_vec_len % fragsz != 0) { 9051 if (input_vec_len / fragsz + 1 > 16) 9052 return 1; 9053 } else if (input_vec_len / fragsz > 16) 9054 return 1; 9055 9056 /* Out of place support */ 9057 if (oop) { 9058 /* 9059 * For out-op-place we need to alloc another mbuf 9060 */ 9061 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9062 rte_pktmbuf_append(ut_params->obuf, frag_size_oop); 9063 buf_oop = ut_params->obuf; 9064 } 9065 9066 /* Generate test mbuf data */ 9067 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9068 9069 /* clear mbuf payload */ 9070 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9071 rte_pktmbuf_tailroom(ut_params->ibuf)); 9072 9073 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9074 plaintext_len); 9075 memcpy(plaintext, input_vec, plaintext_len); 9076 trn_data += plaintext_len; 9077 9078 buf = ut_params->ibuf; 9079 9080 /* 9081 * Loop until no more fragments 9082 */ 9083 9084 while (trn_data < input_vec_len) { 9085 ++segs; 9086 to_trn = (input_vec_len - trn_data < fragsz) ? 9087 (input_vec_len - trn_data) : fragsz; 9088 9089 to_trn_tbl[ecx++] = to_trn; 9090 9091 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9092 buf = buf->next; 9093 9094 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 9095 rte_pktmbuf_tailroom(buf)); 9096 9097 /* OOP */ 9098 if (oop && !fragsz_oop) { 9099 buf_oop->next = 9100 rte_pktmbuf_alloc(ts_params->mbuf_pool); 9101 buf_oop = buf_oop->next; 9102 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 9103 0, rte_pktmbuf_tailroom(buf_oop)); 9104 rte_pktmbuf_append(buf_oop, to_trn); 9105 } 9106 9107 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 9108 to_trn); 9109 9110 memcpy(plaintext, input_vec + trn_data, to_trn); 9111 trn_data += to_trn; 9112 } 9113 9114 ut_params->ibuf->nb_segs = segs; 9115 9116 segs = 1; 9117 if (fragsz_oop && oop) { 9118 to_trn = 0; 9119 ecx = 0; 9120 9121 trn_data = frag_size_oop; 9122 while (trn_data < output_vec_len) { 9123 ++segs; 9124 to_trn = 9125 (output_vec_len - trn_data < 9126 frag_size_oop) ? 9127 (output_vec_len - trn_data) : 9128 frag_size_oop; 9129 9130 to_trn_tbl[ecx++] = to_trn; 9131 9132 buf_oop->next = 9133 rte_pktmbuf_alloc(ts_params->mbuf_pool); 9134 buf_oop = buf_oop->next; 9135 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 9136 0, rte_pktmbuf_tailroom(buf_oop)); 9137 rte_pktmbuf_append(buf_oop, to_trn); 9138 9139 trn_data += to_trn; 9140 } 9141 ut_params->obuf->nb_segs = segs; 9142 } 9143 9144 /* Setup Cipher Parameters */ 9145 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9146 ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg; 9147 ut_params->cipher_xform.cipher.op = opc; 9148 ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i]; 9149 ut_params->cipher_xform.cipher.key.length = 9150 pdcp_test_params[i].cipher_key_len; 9151 ut_params->cipher_xform.cipher.iv.length = 0; 9152 9153 /* Setup HMAC Parameters if ICV header is required */ 9154 if (pdcp_test_params[i].auth_alg != 0) { 9155 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9156 ut_params->auth_xform.next = NULL; 9157 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg; 9158 ut_params->auth_xform.auth.op = opa; 9159 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i]; 9160 ut_params->auth_xform.auth.key.length = 9161 pdcp_test_params[i].auth_key_len; 9162 9163 ut_params->cipher_xform.next = &ut_params->auth_xform; 9164 } else { 9165 ut_params->cipher_xform.next = NULL; 9166 } 9167 9168 struct rte_security_session_conf sess_conf = { 9169 .action_type = ut_params->type, 9170 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 9171 {.pdcp = { 9172 .bearer = pdcp_test_bearer[i], 9173 .domain = pdcp_test_params[i].domain, 9174 .pkt_dir = pdcp_test_packet_direction[i], 9175 .sn_size = pdcp_test_data_sn_size[i], 9176 .hfn = pdcp_test_hfn[i], 9177 .hfn_threshold = pdcp_test_hfn_threshold[i], 9178 .hfn_ovrd = 0, 9179 } }, 9180 .crypto_xform = &ut_params->cipher_xform 9181 }; 9182 9183 /* Create security session */ 9184 ut_params->sec_session = rte_security_session_create(ctx, 9185 &sess_conf, ts_params->session_mpool); 9186 9187 if (!ut_params->sec_session) { 9188 printf("TestCase %s()-%d line %d failed %s: ", 9189 __func__, i, __LINE__, "Failed to allocate session"); 9190 ret = TEST_FAILED; 9191 goto on_err; 9192 } 9193 9194 /* Generate crypto op data structure */ 9195 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9196 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9197 if (!ut_params->op) { 9198 printf("TestCase %s()-%d line %d failed %s: ", 9199 __func__, i, __LINE__, 9200 "Failed to allocate symmetric crypto operation struct"); 9201 ret = TEST_FAILED; 9202 goto on_err; 9203 } 9204 9205 rte_security_attach_session(ut_params->op, ut_params->sec_session); 9206 9207 /* set crypto operation source mbuf */ 9208 ut_params->op->sym->m_src = ut_params->ibuf; 9209 if (oop) 9210 ut_params->op->sym->m_dst = ut_params->obuf; 9211 9212 /* Process crypto operation */ 9213 temp_mbuf = ut_params->op->sym->m_src; 9214 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 9215 /* filling lengths */ 9216 while (temp_mbuf) { 9217 ut_params->op->sym->cipher.data.length 9218 += temp_mbuf->pkt_len; 9219 ut_params->op->sym->auth.data.length 9220 += temp_mbuf->pkt_len; 9221 temp_mbuf = temp_mbuf->next; 9222 } 9223 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 9224 ut_params->op, 1, 1, 0, 0); 9225 } else { 9226 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 9227 ut_params->op); 9228 } 9229 if (ut_params->op == NULL) { 9230 printf("TestCase %s()-%d line %d failed %s: ", 9231 __func__, i, __LINE__, 9232 "failed to process sym crypto op"); 9233 ret = TEST_FAILED; 9234 goto on_err; 9235 } 9236 9237 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 9238 printf("TestCase %s()-%d line %d failed %s: ", 9239 __func__, i, __LINE__, "crypto op processing failed"); 9240 ret = TEST_FAILED; 9241 goto on_err; 9242 } 9243 9244 /* Validate obuf */ 9245 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 9246 uint8_t *); 9247 if (oop) { 9248 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 9249 uint8_t *); 9250 } 9251 if (fragsz_oop) 9252 fragsz = frag_size_oop; 9253 if (memcmp(ciphertext, output_vec, fragsz)) { 9254 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 9255 rte_hexdump(stdout, "encrypted", ciphertext, fragsz); 9256 rte_hexdump(stdout, "reference", output_vec, fragsz); 9257 ret = TEST_FAILED; 9258 goto on_err; 9259 } 9260 9261 buf = ut_params->op->sym->m_src->next; 9262 if (oop) 9263 buf = ut_params->op->sym->m_dst->next; 9264 9265 unsigned int off = fragsz; 9266 9267 ecx = 0; 9268 while (buf) { 9269 ciphertext = rte_pktmbuf_mtod(buf, 9270 uint8_t *); 9271 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) { 9272 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 9273 rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]); 9274 rte_hexdump(stdout, "reference", output_vec + off, 9275 to_trn_tbl[ecx]); 9276 ret = TEST_FAILED; 9277 goto on_err; 9278 } 9279 off += to_trn_tbl[ecx++]; 9280 buf = buf->next; 9281 } 9282 on_err: 9283 rte_crypto_op_free(ut_params->op); 9284 ut_params->op = NULL; 9285 9286 if (ut_params->sec_session) 9287 rte_security_session_destroy(ctx, ut_params->sec_session); 9288 ut_params->sec_session = NULL; 9289 9290 rte_pktmbuf_free(ut_params->ibuf); 9291 ut_params->ibuf = NULL; 9292 if (oop) { 9293 rte_pktmbuf_free(ut_params->obuf); 9294 ut_params->obuf = NULL; 9295 } 9296 9297 return ret; 9298 } 9299 9300 int 9301 test_pdcp_proto_cplane_encap(int i) 9302 { 9303 return test_pdcp_proto( 9304 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 9305 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9306 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9307 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9308 pdcp_test_params[i].cipher_key_len, 9309 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9310 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9311 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9312 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9313 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9314 } 9315 9316 int 9317 test_pdcp_proto_uplane_encap(int i) 9318 { 9319 return test_pdcp_proto( 9320 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 9321 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9322 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 9323 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9324 pdcp_test_params[i].cipher_key_len, 9325 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9326 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9327 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9328 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9329 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9330 } 9331 9332 int 9333 test_pdcp_proto_uplane_encap_with_int(int i) 9334 { 9335 return test_pdcp_proto( 9336 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 9337 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9338 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9339 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9340 pdcp_test_params[i].cipher_key_len, 9341 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9342 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9343 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9344 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9345 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9346 } 9347 9348 int 9349 test_pdcp_proto_cplane_decap(int i) 9350 { 9351 return test_pdcp_proto( 9352 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 9353 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9354 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9355 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9356 pdcp_test_params[i].cipher_key_len, 9357 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9358 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9359 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9360 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9361 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9362 } 9363 9364 int 9365 test_pdcp_proto_uplane_decap(int i) 9366 { 9367 return test_pdcp_proto( 9368 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 9369 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 9370 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9371 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9372 pdcp_test_params[i].cipher_key_len, 9373 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9374 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9375 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9376 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9377 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9378 } 9379 9380 int 9381 test_pdcp_proto_uplane_decap_with_int(int i) 9382 { 9383 return test_pdcp_proto( 9384 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 9385 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9386 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9387 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9388 pdcp_test_params[i].cipher_key_len, 9389 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9390 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9391 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9392 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9393 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9394 } 9395 9396 static int 9397 test_PDCP_PROTO_SGL_in_place_32B(void) 9398 { 9399 /* i can be used for running any PDCP case 9400 * In this case it is uplane 12-bit AES-SNOW DL encap 9401 */ 9402 int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK; 9403 return test_pdcp_proto_SGL(i, IN_PLACE, 9404 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9405 RTE_CRYPTO_AUTH_OP_GENERATE, 9406 pdcp_test_data_in[i], 9407 pdcp_test_data_in_len[i], 9408 pdcp_test_data_out[i], 9409 pdcp_test_data_in_len[i]+4, 9410 32, 0); 9411 } 9412 static int 9413 test_PDCP_PROTO_SGL_oop_32B_128B(void) 9414 { 9415 /* i can be used for running any PDCP case 9416 * In this case it is uplane 18-bit NULL-NULL DL encap 9417 */ 9418 int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK; 9419 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9420 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9421 RTE_CRYPTO_AUTH_OP_GENERATE, 9422 pdcp_test_data_in[i], 9423 pdcp_test_data_in_len[i], 9424 pdcp_test_data_out[i], 9425 pdcp_test_data_in_len[i]+4, 9426 32, 128); 9427 } 9428 static int 9429 test_PDCP_PROTO_SGL_oop_32B_40B(void) 9430 { 9431 /* i can be used for running any PDCP case 9432 * In this case it is uplane 18-bit AES DL encap 9433 */ 9434 int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET 9435 + DOWNLINK; 9436 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9437 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9438 RTE_CRYPTO_AUTH_OP_GENERATE, 9439 pdcp_test_data_in[i], 9440 pdcp_test_data_in_len[i], 9441 pdcp_test_data_out[i], 9442 pdcp_test_data_in_len[i], 9443 32, 40); 9444 } 9445 static int 9446 test_PDCP_PROTO_SGL_oop_128B_32B(void) 9447 { 9448 /* i can be used for running any PDCP case 9449 * In this case it is cplane 12-bit AES-ZUC DL encap 9450 */ 9451 int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK; 9452 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9453 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9454 RTE_CRYPTO_AUTH_OP_GENERATE, 9455 pdcp_test_data_in[i], 9456 pdcp_test_data_in_len[i], 9457 pdcp_test_data_out[i], 9458 pdcp_test_data_in_len[i]+4, 9459 128, 32); 9460 } 9461 9462 static int 9463 test_PDCP_SDAP_PROTO_encap_all(void) 9464 { 9465 int i = 0, size = 0; 9466 int err, all_err = TEST_SUCCESS; 9467 const struct pdcp_sdap_test *cur_test; 9468 9469 size = RTE_DIM(list_pdcp_sdap_tests); 9470 9471 for (i = 0; i < size; i++) { 9472 cur_test = &list_pdcp_sdap_tests[i]; 9473 err = test_pdcp_proto( 9474 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9475 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9476 cur_test->in_len, cur_test->data_out, 9477 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9478 cur_test->param.cipher_alg, cur_test->cipher_key, 9479 cur_test->param.cipher_key_len, 9480 cur_test->param.auth_alg, 9481 cur_test->auth_key, cur_test->param.auth_key_len, 9482 cur_test->bearer, cur_test->param.domain, 9483 cur_test->packet_direction, cur_test->sn_size, 9484 cur_test->hfn, 9485 cur_test->hfn_threshold, SDAP_ENABLED); 9486 if (err) { 9487 printf("\t%d) %s: Encapsulation failed\n", 9488 cur_test->test_idx, 9489 cur_test->param.name); 9490 err = TEST_FAILED; 9491 } else { 9492 printf("\t%d) %s: Encap PASS\n", cur_test->test_idx, 9493 cur_test->param.name); 9494 err = TEST_SUCCESS; 9495 } 9496 all_err += err; 9497 } 9498 9499 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9500 9501 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9502 } 9503 9504 static int 9505 test_PDCP_PROTO_short_mac(void) 9506 { 9507 int i = 0, size = 0; 9508 int err, all_err = TEST_SUCCESS; 9509 const struct pdcp_short_mac_test *cur_test; 9510 9511 size = RTE_DIM(list_pdcp_smac_tests); 9512 9513 for (i = 0; i < size; i++) { 9514 cur_test = &list_pdcp_smac_tests[i]; 9515 err = test_pdcp_proto( 9516 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9517 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9518 cur_test->in_len, cur_test->data_out, 9519 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9520 RTE_CRYPTO_CIPHER_NULL, NULL, 9521 0, cur_test->param.auth_alg, 9522 cur_test->auth_key, cur_test->param.auth_key_len, 9523 0, cur_test->param.domain, 0, 0, 9524 0, 0, 0); 9525 if (err) { 9526 printf("\t%d) %s: Short MAC test failed\n", 9527 cur_test->test_idx, 9528 cur_test->param.name); 9529 err = TEST_FAILED; 9530 } else { 9531 printf("\t%d) %s: Short MAC test PASS\n", 9532 cur_test->test_idx, 9533 cur_test->param.name); 9534 rte_hexdump(stdout, "MAC I", 9535 cur_test->data_out + cur_test->in_len + 2, 9536 2); 9537 err = TEST_SUCCESS; 9538 } 9539 all_err += err; 9540 } 9541 9542 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9543 9544 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9545 9546 } 9547 9548 static int 9549 test_PDCP_SDAP_PROTO_decap_all(void) 9550 { 9551 int i = 0, size = 0; 9552 int err, all_err = TEST_SUCCESS; 9553 const struct pdcp_sdap_test *cur_test; 9554 9555 size = RTE_DIM(list_pdcp_sdap_tests); 9556 9557 for (i = 0; i < size; i++) { 9558 cur_test = &list_pdcp_sdap_tests[i]; 9559 err = test_pdcp_proto( 9560 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, 9561 RTE_CRYPTO_AUTH_OP_VERIFY, 9562 cur_test->data_out, 9563 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9564 cur_test->data_in, cur_test->in_len, 9565 cur_test->param.cipher_alg, 9566 cur_test->cipher_key, cur_test->param.cipher_key_len, 9567 cur_test->param.auth_alg, cur_test->auth_key, 9568 cur_test->param.auth_key_len, cur_test->bearer, 9569 cur_test->param.domain, cur_test->packet_direction, 9570 cur_test->sn_size, cur_test->hfn, 9571 cur_test->hfn_threshold, SDAP_ENABLED); 9572 if (err) { 9573 printf("\t%d) %s: Decapsulation failed\n", 9574 cur_test->test_idx, 9575 cur_test->param.name); 9576 err = TEST_FAILED; 9577 } else { 9578 printf("\t%d) %s: Decap PASS\n", cur_test->test_idx, 9579 cur_test->param.name); 9580 err = TEST_SUCCESS; 9581 } 9582 all_err += err; 9583 } 9584 9585 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9586 9587 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9588 } 9589 9590 static int 9591 test_ipsec_proto_process(const struct ipsec_test_data td[], 9592 struct ipsec_test_data res_d[], 9593 int nb_td, 9594 bool silent, 9595 const struct ipsec_test_flags *flags) 9596 { 9597 uint16_t v6_src[8] = {0x2607, 0xf8b0, 0x400c, 0x0c03, 0x0000, 0x0000, 9598 0x0000, 0x001a}; 9599 uint16_t v6_dst[8] = {0x2001, 0x0470, 0xe5bf, 0xdead, 0x4957, 0x2174, 9600 0xe82c, 0x4887}; 9601 const struct rte_ipv4_hdr *ipv4 = 9602 (const struct rte_ipv4_hdr *)td[0].output_text.data; 9603 int nb_segs = flags->nb_segs_in_mbuf ? flags->nb_segs_in_mbuf : 1; 9604 struct crypto_testsuite_params *ts_params = &testsuite_params; 9605 struct crypto_unittest_params *ut_params = &unittest_params; 9606 struct rte_security_capability_idx sec_cap_idx; 9607 const struct rte_security_capability *sec_cap; 9608 struct rte_security_ipsec_xform ipsec_xform; 9609 uint8_t dev_id = ts_params->valid_devs[0]; 9610 enum rte_security_ipsec_sa_direction dir; 9611 struct ipsec_test_data *res_d_tmp = NULL; 9612 uint8_t input_text[IPSEC_TEXT_MAX_LEN]; 9613 int salt_len, i, ret = TEST_SUCCESS; 9614 struct rte_security_ctx *ctx; 9615 uint32_t src, dst; 9616 uint32_t verify; 9617 9618 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 9619 gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 9620 9621 /* Use first test data to create session */ 9622 9623 /* Copy IPsec xform */ 9624 memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform)); 9625 9626 dir = ipsec_xform.direction; 9627 verify = flags->tunnel_hdr_verify; 9628 9629 memcpy(&src, &ipv4->src_addr, sizeof(ipv4->src_addr)); 9630 memcpy(&dst, &ipv4->dst_addr, sizeof(ipv4->dst_addr)); 9631 9632 if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) { 9633 if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR) 9634 src += 1; 9635 else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR) 9636 dst += 1; 9637 } 9638 9639 if (td->ipsec_xform.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) { 9640 if (td->ipsec_xform.tunnel.type == 9641 RTE_SECURITY_IPSEC_TUNNEL_IPV4) { 9642 memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, 9643 sizeof(src)); 9644 memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, 9645 sizeof(dst)); 9646 9647 if (flags->df == TEST_IPSEC_SET_DF_0_INNER_1) 9648 ipsec_xform.tunnel.ipv4.df = 0; 9649 9650 if (flags->df == TEST_IPSEC_SET_DF_1_INNER_0) 9651 ipsec_xform.tunnel.ipv4.df = 1; 9652 9653 if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1) 9654 ipsec_xform.tunnel.ipv4.dscp = 0; 9655 9656 if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0) 9657 ipsec_xform.tunnel.ipv4.dscp = 9658 TEST_IPSEC_DSCP_VAL; 9659 9660 } else { 9661 if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1) 9662 ipsec_xform.tunnel.ipv6.dscp = 0; 9663 9664 if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0) 9665 ipsec_xform.tunnel.ipv6.dscp = 9666 TEST_IPSEC_DSCP_VAL; 9667 9668 memcpy(&ipsec_xform.tunnel.ipv6.src_addr, &v6_src, 9669 sizeof(v6_src)); 9670 memcpy(&ipsec_xform.tunnel.ipv6.dst_addr, &v6_dst, 9671 sizeof(v6_dst)); 9672 } 9673 } 9674 9675 ctx = rte_cryptodev_get_sec_ctx(dev_id); 9676 9677 sec_cap_idx.action = ut_params->type; 9678 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC; 9679 sec_cap_idx.ipsec.proto = ipsec_xform.proto; 9680 sec_cap_idx.ipsec.mode = ipsec_xform.mode; 9681 sec_cap_idx.ipsec.direction = ipsec_xform.direction; 9682 9683 if (flags->udp_encap) 9684 ipsec_xform.options.udp_encap = 1; 9685 9686 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 9687 if (sec_cap == NULL) 9688 return TEST_SKIPPED; 9689 9690 /* Copy cipher session parameters */ 9691 if (td[0].aead) { 9692 memcpy(&ut_params->aead_xform, &td[0].xform.aead, 9693 sizeof(ut_params->aead_xform)); 9694 ut_params->aead_xform.aead.key.data = td[0].key.data; 9695 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 9696 9697 /* Verify crypto capabilities */ 9698 if (test_ipsec_crypto_caps_aead_verify( 9699 sec_cap, 9700 &ut_params->aead_xform) != 0) { 9701 if (!silent) 9702 RTE_LOG(INFO, USER1, 9703 "Crypto capabilities not supported\n"); 9704 return TEST_SKIPPED; 9705 } 9706 } else if (td[0].auth_only) { 9707 memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth, 9708 sizeof(ut_params->auth_xform)); 9709 ut_params->auth_xform.auth.key.data = td[0].auth_key.data; 9710 9711 if (test_ipsec_crypto_caps_auth_verify( 9712 sec_cap, 9713 &ut_params->auth_xform) != 0) { 9714 if (!silent) 9715 RTE_LOG(INFO, USER1, 9716 "Auth crypto capabilities not supported\n"); 9717 return TEST_SKIPPED; 9718 } 9719 } else { 9720 memcpy(&ut_params->cipher_xform, &td[0].xform.chain.cipher, 9721 sizeof(ut_params->cipher_xform)); 9722 memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth, 9723 sizeof(ut_params->auth_xform)); 9724 ut_params->cipher_xform.cipher.key.data = td[0].key.data; 9725 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 9726 ut_params->auth_xform.auth.key.data = td[0].auth_key.data; 9727 9728 /* Verify crypto capabilities */ 9729 9730 if (test_ipsec_crypto_caps_cipher_verify( 9731 sec_cap, 9732 &ut_params->cipher_xform) != 0) { 9733 if (!silent) 9734 RTE_LOG(INFO, USER1, 9735 "Cipher crypto capabilities not supported\n"); 9736 return TEST_SKIPPED; 9737 } 9738 9739 if (test_ipsec_crypto_caps_auth_verify( 9740 sec_cap, 9741 &ut_params->auth_xform) != 0) { 9742 if (!silent) 9743 RTE_LOG(INFO, USER1, 9744 "Auth crypto capabilities not supported\n"); 9745 return TEST_SKIPPED; 9746 } 9747 } 9748 9749 if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0) 9750 return TEST_SKIPPED; 9751 9752 struct rte_security_session_conf sess_conf = { 9753 .action_type = ut_params->type, 9754 .protocol = RTE_SECURITY_PROTOCOL_IPSEC, 9755 }; 9756 9757 if (td[0].aead || td[0].aes_gmac) { 9758 salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len); 9759 memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len); 9760 } 9761 9762 if (td[0].aead) { 9763 sess_conf.ipsec = ipsec_xform; 9764 sess_conf.crypto_xform = &ut_params->aead_xform; 9765 } else if (td[0].auth_only) { 9766 sess_conf.ipsec = ipsec_xform; 9767 sess_conf.crypto_xform = &ut_params->auth_xform; 9768 } else { 9769 sess_conf.ipsec = ipsec_xform; 9770 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) { 9771 sess_conf.crypto_xform = &ut_params->cipher_xform; 9772 ut_params->cipher_xform.next = &ut_params->auth_xform; 9773 } else { 9774 sess_conf.crypto_xform = &ut_params->auth_xform; 9775 ut_params->auth_xform.next = &ut_params->cipher_xform; 9776 } 9777 } 9778 9779 /* Create security session */ 9780 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 9781 ts_params->session_mpool); 9782 9783 if (ut_params->sec_session == NULL) 9784 return TEST_SKIPPED; 9785 9786 for (i = 0; i < nb_td; i++) { 9787 if (flags->antireplay && 9788 (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)) { 9789 sess_conf.ipsec.esn.value = td[i].ipsec_xform.esn.value; 9790 ret = rte_security_session_update(ctx, 9791 ut_params->sec_session, &sess_conf); 9792 if (ret) { 9793 printf("Could not update sequence number in " 9794 "session\n"); 9795 return TEST_SKIPPED; 9796 } 9797 } 9798 9799 /* Copy test data before modification */ 9800 memcpy(input_text, td[i].input_text.data, td[i].input_text.len); 9801 if (test_ipsec_pkt_update(input_text, flags)) 9802 return TEST_FAILED; 9803 9804 /* Setup source mbuf payload */ 9805 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, td[i].input_text.len, 9806 nb_segs, 0); 9807 pktmbuf_write(ut_params->ibuf, 0, td[i].input_text.len, input_text); 9808 9809 /* Generate crypto op data structure */ 9810 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9811 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9812 if (!ut_params->op) { 9813 printf("TestCase %s line %d: %s\n", 9814 __func__, __LINE__, 9815 "failed to allocate crypto op"); 9816 ret = TEST_FAILED; 9817 goto crypto_op_free; 9818 } 9819 9820 /* Attach session to operation */ 9821 rte_security_attach_session(ut_params->op, 9822 ut_params->sec_session); 9823 9824 /* Set crypto operation mbufs */ 9825 ut_params->op->sym->m_src = ut_params->ibuf; 9826 ut_params->op->sym->m_dst = NULL; 9827 9828 /* Copy IV in crypto operation when IV generation is disabled */ 9829 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS && 9830 ipsec_xform.options.iv_gen_disable == 1) { 9831 uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op, 9832 uint8_t *, 9833 IV_OFFSET); 9834 int len; 9835 9836 if (td[i].aead) 9837 len = td[i].xform.aead.aead.iv.length; 9838 else if (td[i].aes_gmac) 9839 len = td[i].xform.chain.auth.auth.iv.length; 9840 else 9841 len = td[i].xform.chain.cipher.cipher.iv.length; 9842 9843 memcpy(iv, td[i].iv.data, len); 9844 } 9845 9846 /* Process crypto operation */ 9847 process_crypto_request(dev_id, ut_params->op); 9848 9849 ret = test_ipsec_status_check(&td[i], ut_params->op, flags, dir, 9850 i + 1); 9851 if (ret != TEST_SUCCESS) 9852 goto crypto_op_free; 9853 9854 if (res_d != NULL) 9855 res_d_tmp = &res_d[i]; 9856 9857 ret = test_ipsec_post_process(ut_params->ibuf, &td[i], 9858 res_d_tmp, silent, flags); 9859 if (ret != TEST_SUCCESS) 9860 goto crypto_op_free; 9861 9862 ret = test_ipsec_stats_verify(ctx, ut_params->sec_session, 9863 flags, dir); 9864 if (ret != TEST_SUCCESS) 9865 goto crypto_op_free; 9866 9867 rte_crypto_op_free(ut_params->op); 9868 ut_params->op = NULL; 9869 9870 rte_pktmbuf_free(ut_params->ibuf); 9871 ut_params->ibuf = NULL; 9872 } 9873 9874 crypto_op_free: 9875 rte_crypto_op_free(ut_params->op); 9876 ut_params->op = NULL; 9877 9878 rte_pktmbuf_free(ut_params->ibuf); 9879 ut_params->ibuf = NULL; 9880 9881 if (ut_params->sec_session) 9882 rte_security_session_destroy(ctx, ut_params->sec_session); 9883 ut_params->sec_session = NULL; 9884 9885 return ret; 9886 } 9887 9888 static int 9889 test_ipsec_proto_known_vec(const void *test_data) 9890 { 9891 struct ipsec_test_data td_outb; 9892 struct ipsec_test_flags flags; 9893 9894 memset(&flags, 0, sizeof(flags)); 9895 9896 memcpy(&td_outb, test_data, sizeof(td_outb)); 9897 9898 if (td_outb.aes_gmac || td_outb.aead || 9899 ((td_outb.ipsec_xform.proto != RTE_SECURITY_IPSEC_SA_PROTO_AH) && 9900 (td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL))) { 9901 /* Disable IV gen to be able to test with known vectors */ 9902 td_outb.ipsec_xform.options.iv_gen_disable = 1; 9903 } 9904 9905 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 9906 } 9907 9908 static int 9909 test_ipsec_proto_known_vec_inb(const void *test_data) 9910 { 9911 const struct ipsec_test_data *td = test_data; 9912 struct ipsec_test_flags flags; 9913 struct ipsec_test_data td_inb; 9914 9915 memset(&flags, 0, sizeof(flags)); 9916 9917 if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) 9918 test_ipsec_td_in_from_out(td, &td_inb); 9919 else 9920 memcpy(&td_inb, td, sizeof(td_inb)); 9921 9922 return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags); 9923 } 9924 9925 static int 9926 test_ipsec_proto_known_vec_fragmented(const void *test_data) 9927 { 9928 struct ipsec_test_data td_outb; 9929 struct ipsec_test_flags flags; 9930 9931 memset(&flags, 0, sizeof(flags)); 9932 flags.fragment = true; 9933 9934 memcpy(&td_outb, test_data, sizeof(td_outb)); 9935 9936 /* Disable IV gen to be able to test with known vectors */ 9937 td_outb.ipsec_xform.options.iv_gen_disable = 1; 9938 9939 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 9940 } 9941 9942 static int 9943 test_ipsec_proto_all(const struct ipsec_test_flags *flags) 9944 { 9945 struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX]; 9946 struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX]; 9947 unsigned int i, nb_pkts = 1, pass_cnt = 0; 9948 int ret; 9949 9950 if (flags->iv_gen || 9951 flags->sa_expiry_pkts_soft || 9952 flags->sa_expiry_pkts_hard) 9953 nb_pkts = IPSEC_TEST_PACKETS_MAX; 9954 9955 for (i = 0; i < RTE_DIM(alg_list); i++) { 9956 test_ipsec_td_prepare(alg_list[i].param1, 9957 alg_list[i].param2, 9958 flags, 9959 td_outb, 9960 nb_pkts); 9961 9962 if (!td_outb->aead) { 9963 enum rte_crypto_cipher_algorithm cipher_alg; 9964 enum rte_crypto_auth_algorithm auth_alg; 9965 9966 cipher_alg = td_outb->xform.chain.cipher.cipher.algo; 9967 auth_alg = td_outb->xform.chain.auth.auth.algo; 9968 9969 if (td_outb->aes_gmac && cipher_alg != RTE_CRYPTO_CIPHER_NULL) 9970 continue; 9971 9972 /* ICV is not applicable for NULL auth */ 9973 if (flags->icv_corrupt && 9974 auth_alg == RTE_CRYPTO_AUTH_NULL) 9975 continue; 9976 9977 /* IV is not applicable for NULL cipher */ 9978 if (flags->iv_gen && 9979 cipher_alg == RTE_CRYPTO_CIPHER_NULL) 9980 continue; 9981 } 9982 9983 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 9984 flags); 9985 if (ret == TEST_SKIPPED) 9986 continue; 9987 9988 if (ret == TEST_FAILED) 9989 return TEST_FAILED; 9990 9991 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags); 9992 9993 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 9994 flags); 9995 if (ret == TEST_SKIPPED) 9996 continue; 9997 9998 if (ret == TEST_FAILED) 9999 return TEST_FAILED; 10000 10001 if (flags->display_alg) 10002 test_ipsec_display_alg(alg_list[i].param1, 10003 alg_list[i].param2); 10004 10005 pass_cnt++; 10006 } 10007 10008 if (pass_cnt > 0) 10009 return TEST_SUCCESS; 10010 else 10011 return TEST_SKIPPED; 10012 } 10013 10014 static int 10015 test_ipsec_ah_proto_all(const struct ipsec_test_flags *flags) 10016 { 10017 struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX]; 10018 struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX]; 10019 unsigned int i, nb_pkts = 1, pass_cnt = 0; 10020 int ret; 10021 10022 for (i = 0; i < RTE_DIM(ah_alg_list); i++) { 10023 test_ipsec_td_prepare(ah_alg_list[i].param1, 10024 ah_alg_list[i].param2, 10025 flags, 10026 td_outb, 10027 nb_pkts); 10028 10029 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 10030 flags); 10031 if (ret == TEST_SKIPPED) 10032 continue; 10033 10034 if (ret == TEST_FAILED) 10035 return TEST_FAILED; 10036 10037 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags); 10038 10039 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 10040 flags); 10041 if (ret == TEST_SKIPPED) 10042 continue; 10043 10044 if (ret == TEST_FAILED) 10045 return TEST_FAILED; 10046 10047 if (flags->display_alg) 10048 test_ipsec_display_alg(ah_alg_list[i].param1, 10049 ah_alg_list[i].param2); 10050 10051 pass_cnt++; 10052 } 10053 10054 if (pass_cnt > 0) 10055 return TEST_SUCCESS; 10056 else 10057 return TEST_SKIPPED; 10058 } 10059 10060 static int 10061 test_ipsec_proto_display_list(const void *data __rte_unused) 10062 { 10063 struct ipsec_test_flags flags; 10064 10065 memset(&flags, 0, sizeof(flags)); 10066 10067 flags.display_alg = true; 10068 10069 return test_ipsec_proto_all(&flags); 10070 } 10071 10072 static int 10073 test_ipsec_proto_ah_tunnel_ipv4(const void *data __rte_unused) 10074 { 10075 struct ipsec_test_flags flags; 10076 10077 memset(&flags, 0, sizeof(flags)); 10078 10079 flags.ah = true; 10080 flags.display_alg = true; 10081 10082 return test_ipsec_ah_proto_all(&flags); 10083 } 10084 10085 static int 10086 test_ipsec_proto_ah_transport_ipv4(const void *data __rte_unused) 10087 { 10088 struct ipsec_test_flags flags; 10089 10090 memset(&flags, 0, sizeof(flags)); 10091 10092 flags.ah = true; 10093 flags.transport = true; 10094 10095 return test_ipsec_ah_proto_all(&flags); 10096 } 10097 10098 static int 10099 test_ipsec_proto_iv_gen(const void *data __rte_unused) 10100 { 10101 struct ipsec_test_flags flags; 10102 10103 memset(&flags, 0, sizeof(flags)); 10104 10105 flags.iv_gen = true; 10106 10107 return test_ipsec_proto_all(&flags); 10108 } 10109 10110 static int 10111 test_ipsec_proto_sa_exp_pkts_soft(const void *data __rte_unused) 10112 { 10113 struct ipsec_test_flags flags; 10114 10115 memset(&flags, 0, sizeof(flags)); 10116 10117 flags.sa_expiry_pkts_soft = true; 10118 10119 return test_ipsec_proto_all(&flags); 10120 } 10121 10122 static int 10123 test_ipsec_proto_sa_exp_pkts_hard(const void *data __rte_unused) 10124 { 10125 struct ipsec_test_flags flags; 10126 10127 memset(&flags, 0, sizeof(flags)); 10128 10129 flags.sa_expiry_pkts_hard = true; 10130 10131 return test_ipsec_proto_all(&flags); 10132 } 10133 10134 static int 10135 test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused) 10136 { 10137 struct ipsec_test_flags flags; 10138 10139 memset(&flags, 0, sizeof(flags)); 10140 10141 flags.icv_corrupt = true; 10142 10143 return test_ipsec_proto_all(&flags); 10144 } 10145 10146 static int 10147 test_ipsec_proto_udp_encap_custom_ports(const void *data __rte_unused) 10148 { 10149 struct ipsec_test_flags flags; 10150 10151 if (gbl_driver_id == rte_cryptodev_driver_id_get( 10152 RTE_STR(CRYPTODEV_NAME_CN10K_PMD))) 10153 return TEST_SKIPPED; 10154 10155 memset(&flags, 0, sizeof(flags)); 10156 10157 flags.udp_encap = true; 10158 flags.udp_encap_custom_ports = true; 10159 10160 return test_ipsec_proto_all(&flags); 10161 } 10162 10163 static int 10164 test_ipsec_proto_udp_encap(const void *data __rte_unused) 10165 { 10166 struct ipsec_test_flags flags; 10167 10168 memset(&flags, 0, sizeof(flags)); 10169 10170 flags.udp_encap = true; 10171 10172 return test_ipsec_proto_all(&flags); 10173 } 10174 10175 static int 10176 test_ipsec_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused) 10177 { 10178 struct ipsec_test_flags flags; 10179 10180 memset(&flags, 0, sizeof(flags)); 10181 10182 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR; 10183 10184 return test_ipsec_proto_all(&flags); 10185 } 10186 10187 static int 10188 test_ipsec_proto_tunnel_dst_addr_verify(const void *data __rte_unused) 10189 { 10190 struct ipsec_test_flags flags; 10191 10192 memset(&flags, 0, sizeof(flags)); 10193 10194 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR; 10195 10196 return test_ipsec_proto_all(&flags); 10197 } 10198 10199 static int 10200 test_ipsec_proto_udp_ports_verify(const void *data __rte_unused) 10201 { 10202 struct ipsec_test_flags flags; 10203 10204 memset(&flags, 0, sizeof(flags)); 10205 10206 flags.udp_encap = true; 10207 flags.udp_ports_verify = true; 10208 10209 return test_ipsec_proto_all(&flags); 10210 } 10211 10212 static int 10213 test_ipsec_proto_inner_ip_csum(const void *data __rte_unused) 10214 { 10215 struct ipsec_test_flags flags; 10216 10217 memset(&flags, 0, sizeof(flags)); 10218 10219 flags.ip_csum = true; 10220 10221 return test_ipsec_proto_all(&flags); 10222 } 10223 10224 static int 10225 test_ipsec_proto_inner_l4_csum(const void *data __rte_unused) 10226 { 10227 struct ipsec_test_flags flags; 10228 10229 memset(&flags, 0, sizeof(flags)); 10230 10231 flags.l4_csum = true; 10232 10233 return test_ipsec_proto_all(&flags); 10234 } 10235 10236 static int 10237 test_ipsec_proto_tunnel_v4_in_v4(const void *data __rte_unused) 10238 { 10239 struct ipsec_test_flags flags; 10240 10241 memset(&flags, 0, sizeof(flags)); 10242 10243 flags.ipv6 = false; 10244 flags.tunnel_ipv6 = false; 10245 10246 return test_ipsec_proto_all(&flags); 10247 } 10248 10249 static int 10250 test_ipsec_proto_tunnel_v6_in_v6(const void *data __rte_unused) 10251 { 10252 struct ipsec_test_flags flags; 10253 10254 memset(&flags, 0, sizeof(flags)); 10255 10256 flags.ipv6 = true; 10257 flags.tunnel_ipv6 = true; 10258 10259 return test_ipsec_proto_all(&flags); 10260 } 10261 10262 static int 10263 test_ipsec_proto_tunnel_v4_in_v6(const void *data __rte_unused) 10264 { 10265 struct ipsec_test_flags flags; 10266 10267 memset(&flags, 0, sizeof(flags)); 10268 10269 flags.ipv6 = false; 10270 flags.tunnel_ipv6 = true; 10271 10272 return test_ipsec_proto_all(&flags); 10273 } 10274 10275 static int 10276 test_ipsec_proto_tunnel_v6_in_v4(const void *data __rte_unused) 10277 { 10278 struct ipsec_test_flags flags; 10279 10280 memset(&flags, 0, sizeof(flags)); 10281 10282 flags.ipv6 = true; 10283 flags.tunnel_ipv6 = false; 10284 10285 return test_ipsec_proto_all(&flags); 10286 } 10287 10288 static int 10289 test_ipsec_proto_transport_v4(const void *data __rte_unused) 10290 { 10291 struct ipsec_test_flags flags; 10292 10293 memset(&flags, 0, sizeof(flags)); 10294 10295 flags.ipv6 = false; 10296 flags.transport = true; 10297 10298 return test_ipsec_proto_all(&flags); 10299 } 10300 10301 static int 10302 test_ipsec_proto_transport_l4_csum(const void *data __rte_unused) 10303 { 10304 struct ipsec_test_flags flags = { 10305 .l4_csum = true, 10306 .transport = true, 10307 }; 10308 10309 return test_ipsec_proto_all(&flags); 10310 } 10311 10312 static int 10313 test_ipsec_proto_stats(const void *data __rte_unused) 10314 { 10315 struct ipsec_test_flags flags; 10316 10317 memset(&flags, 0, sizeof(flags)); 10318 10319 flags.stats_success = true; 10320 10321 return test_ipsec_proto_all(&flags); 10322 } 10323 10324 static int 10325 test_ipsec_proto_pkt_fragment(const void *data __rte_unused) 10326 { 10327 struct ipsec_test_flags flags; 10328 10329 memset(&flags, 0, sizeof(flags)); 10330 10331 flags.fragment = true; 10332 10333 return test_ipsec_proto_all(&flags); 10334 10335 } 10336 10337 static int 10338 test_ipsec_proto_copy_df_inner_0(const void *data __rte_unused) 10339 { 10340 struct ipsec_test_flags flags; 10341 10342 memset(&flags, 0, sizeof(flags)); 10343 10344 flags.df = TEST_IPSEC_COPY_DF_INNER_0; 10345 10346 return test_ipsec_proto_all(&flags); 10347 } 10348 10349 static int 10350 test_ipsec_proto_copy_df_inner_1(const void *data __rte_unused) 10351 { 10352 struct ipsec_test_flags flags; 10353 10354 memset(&flags, 0, sizeof(flags)); 10355 10356 flags.df = TEST_IPSEC_COPY_DF_INNER_1; 10357 10358 return test_ipsec_proto_all(&flags); 10359 } 10360 10361 static int 10362 test_ipsec_proto_set_df_0_inner_1(const void *data __rte_unused) 10363 { 10364 struct ipsec_test_flags flags; 10365 10366 memset(&flags, 0, sizeof(flags)); 10367 10368 flags.df = TEST_IPSEC_SET_DF_0_INNER_1; 10369 10370 return test_ipsec_proto_all(&flags); 10371 } 10372 10373 static int 10374 test_ipsec_proto_set_df_1_inner_0(const void *data __rte_unused) 10375 { 10376 struct ipsec_test_flags flags; 10377 10378 memset(&flags, 0, sizeof(flags)); 10379 10380 flags.df = TEST_IPSEC_SET_DF_1_INNER_0; 10381 10382 return test_ipsec_proto_all(&flags); 10383 } 10384 10385 static int 10386 test_ipsec_proto_ipv4_copy_dscp_inner_0(const void *data __rte_unused) 10387 { 10388 struct ipsec_test_flags flags; 10389 10390 memset(&flags, 0, sizeof(flags)); 10391 10392 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0; 10393 10394 return test_ipsec_proto_all(&flags); 10395 } 10396 10397 static int 10398 test_ipsec_proto_ipv4_copy_dscp_inner_1(const void *data __rte_unused) 10399 { 10400 struct ipsec_test_flags flags; 10401 10402 memset(&flags, 0, sizeof(flags)); 10403 10404 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1; 10405 10406 return test_ipsec_proto_all(&flags); 10407 } 10408 10409 static int 10410 test_ipsec_proto_ipv4_set_dscp_0_inner_1(const void *data __rte_unused) 10411 { 10412 struct ipsec_test_flags flags; 10413 10414 if (gbl_driver_id == rte_cryptodev_driver_id_get( 10415 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 10416 return TEST_SKIPPED; 10417 10418 memset(&flags, 0, sizeof(flags)); 10419 10420 flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1; 10421 10422 return test_ipsec_proto_all(&flags); 10423 } 10424 10425 static int 10426 test_ipsec_proto_ipv4_set_dscp_1_inner_0(const void *data __rte_unused) 10427 { 10428 struct ipsec_test_flags flags; 10429 10430 if (gbl_driver_id == rte_cryptodev_driver_id_get( 10431 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 10432 return TEST_SKIPPED; 10433 10434 memset(&flags, 0, sizeof(flags)); 10435 10436 flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0; 10437 10438 return test_ipsec_proto_all(&flags); 10439 } 10440 10441 static int 10442 test_ipsec_proto_ipv6_copy_dscp_inner_0(const void *data __rte_unused) 10443 { 10444 struct ipsec_test_flags flags; 10445 10446 memset(&flags, 0, sizeof(flags)); 10447 10448 flags.ipv6 = true; 10449 flags.tunnel_ipv6 = true; 10450 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0; 10451 10452 return test_ipsec_proto_all(&flags); 10453 } 10454 10455 static int 10456 test_ipsec_proto_ipv6_copy_dscp_inner_1(const void *data __rte_unused) 10457 { 10458 struct ipsec_test_flags flags; 10459 10460 memset(&flags, 0, sizeof(flags)); 10461 10462 flags.ipv6 = true; 10463 flags.tunnel_ipv6 = true; 10464 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1; 10465 10466 return test_ipsec_proto_all(&flags); 10467 } 10468 10469 static int 10470 test_ipsec_proto_ipv6_set_dscp_0_inner_1(const void *data __rte_unused) 10471 { 10472 struct ipsec_test_flags flags; 10473 10474 if (gbl_driver_id == rte_cryptodev_driver_id_get( 10475 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 10476 return TEST_SKIPPED; 10477 10478 memset(&flags, 0, sizeof(flags)); 10479 10480 flags.ipv6 = true; 10481 flags.tunnel_ipv6 = true; 10482 flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1; 10483 10484 return test_ipsec_proto_all(&flags); 10485 } 10486 10487 static int 10488 test_ipsec_proto_ipv6_set_dscp_1_inner_0(const void *data __rte_unused) 10489 { 10490 struct ipsec_test_flags flags; 10491 10492 if (gbl_driver_id == rte_cryptodev_driver_id_get( 10493 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 10494 return TEST_SKIPPED; 10495 10496 memset(&flags, 0, sizeof(flags)); 10497 10498 flags.ipv6 = true; 10499 flags.tunnel_ipv6 = true; 10500 flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0; 10501 10502 return test_ipsec_proto_all(&flags); 10503 } 10504 10505 static int 10506 test_ipsec_proto_sgl(const void *data __rte_unused) 10507 { 10508 struct crypto_testsuite_params *ts_params = &testsuite_params; 10509 struct rte_cryptodev_info dev_info; 10510 10511 struct ipsec_test_flags flags = { 10512 .nb_segs_in_mbuf = 5 10513 }; 10514 10515 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10516 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 10517 printf("Device doesn't support in-place scatter-gather. " 10518 "Test Skipped.\n"); 10519 return TEST_SKIPPED; 10520 } 10521 10522 return test_ipsec_proto_all(&flags); 10523 } 10524 10525 static int 10526 test_ipsec_pkt_replay(const void *test_data, const uint64_t esn[], 10527 bool replayed_pkt[], uint32_t nb_pkts, bool esn_en, 10528 uint64_t winsz) 10529 { 10530 struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX]; 10531 struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX]; 10532 struct ipsec_test_flags flags; 10533 uint32_t i = 0, ret = 0; 10534 10535 if (nb_pkts == 0) 10536 return TEST_FAILED; 10537 10538 memset(&flags, 0, sizeof(flags)); 10539 flags.antireplay = true; 10540 10541 for (i = 0; i < nb_pkts; i++) { 10542 memcpy(&td_outb[i], test_data, sizeof(td_outb[i])); 10543 td_outb[i].ipsec_xform.options.iv_gen_disable = 1; 10544 td_outb[i].ipsec_xform.replay_win_sz = winsz; 10545 td_outb[i].ipsec_xform.options.esn = esn_en; 10546 } 10547 10548 for (i = 0; i < nb_pkts; i++) 10549 td_outb[i].ipsec_xform.esn.value = esn[i]; 10550 10551 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 10552 &flags); 10553 if (ret != TEST_SUCCESS) 10554 return ret; 10555 10556 test_ipsec_td_update(td_inb, td_outb, nb_pkts, &flags); 10557 10558 for (i = 0; i < nb_pkts; i++) { 10559 td_inb[i].ipsec_xform.options.esn = esn_en; 10560 /* Set antireplay flag for packets to be dropped */ 10561 td_inb[i].ar_packet = replayed_pkt[i]; 10562 } 10563 10564 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 10565 &flags); 10566 10567 return ret; 10568 } 10569 10570 static int 10571 test_ipsec_proto_pkt_antireplay(const void *test_data, uint64_t winsz) 10572 { 10573 10574 uint32_t nb_pkts = 5; 10575 bool replayed_pkt[5]; 10576 uint64_t esn[5]; 10577 10578 /* 1. Advance the TOP of the window to WS * 2 */ 10579 esn[0] = winsz * 2; 10580 /* 2. Test sequence number within the new window(WS + 1) */ 10581 esn[1] = winsz + 1; 10582 /* 3. Test sequence number less than the window BOTTOM */ 10583 esn[2] = winsz; 10584 /* 4. Test sequence number in the middle of the window */ 10585 esn[3] = winsz + (winsz / 2); 10586 /* 5. Test replay of the packet in the middle of the window */ 10587 esn[4] = winsz + (winsz / 2); 10588 10589 replayed_pkt[0] = false; 10590 replayed_pkt[1] = false; 10591 replayed_pkt[2] = true; 10592 replayed_pkt[3] = false; 10593 replayed_pkt[4] = true; 10594 10595 return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts, 10596 false, winsz); 10597 } 10598 10599 static int 10600 test_ipsec_proto_pkt_antireplay1024(const void *test_data) 10601 { 10602 return test_ipsec_proto_pkt_antireplay(test_data, 1024); 10603 } 10604 10605 static int 10606 test_ipsec_proto_pkt_antireplay2048(const void *test_data) 10607 { 10608 return test_ipsec_proto_pkt_antireplay(test_data, 2048); 10609 } 10610 10611 static int 10612 test_ipsec_proto_pkt_antireplay4096(const void *test_data) 10613 { 10614 return test_ipsec_proto_pkt_antireplay(test_data, 4096); 10615 } 10616 10617 static int 10618 test_ipsec_proto_pkt_esn_antireplay(const void *test_data, uint64_t winsz) 10619 { 10620 10621 uint32_t nb_pkts = 7; 10622 bool replayed_pkt[7]; 10623 uint64_t esn[7]; 10624 10625 /* Set the initial sequence number */ 10626 esn[0] = (uint64_t)(0xFFFFFFFF - winsz); 10627 /* 1. Advance the TOP of the window to (1<<32 + WS/2) */ 10628 esn[1] = (uint64_t)((1ULL << 32) + (winsz / 2)); 10629 /* 2. Test sequence number within new window (1<<32 + WS/2 + 1) */ 10630 esn[2] = (uint64_t)((1ULL << 32) - (winsz / 2) + 1); 10631 /* 3. Test with sequence number within window (1<<32 - 1) */ 10632 esn[3] = (uint64_t)((1ULL << 32) - 1); 10633 /* 4. Test with sequence number within window (1<<32 - 1) */ 10634 esn[4] = (uint64_t)(1ULL << 32); 10635 /* 5. Test with duplicate sequence number within 10636 * new window (1<<32 - 1) 10637 */ 10638 esn[5] = (uint64_t)((1ULL << 32) - 1); 10639 /* 6. Test with duplicate sequence number within new window (1<<32) */ 10640 esn[6] = (uint64_t)(1ULL << 32); 10641 10642 replayed_pkt[0] = false; 10643 replayed_pkt[1] = false; 10644 replayed_pkt[2] = false; 10645 replayed_pkt[3] = false; 10646 replayed_pkt[4] = false; 10647 replayed_pkt[5] = true; 10648 replayed_pkt[6] = true; 10649 10650 return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts, 10651 true, winsz); 10652 } 10653 10654 static int 10655 test_ipsec_proto_pkt_esn_antireplay1024(const void *test_data) 10656 { 10657 return test_ipsec_proto_pkt_esn_antireplay(test_data, 1024); 10658 } 10659 10660 static int 10661 test_ipsec_proto_pkt_esn_antireplay2048(const void *test_data) 10662 { 10663 return test_ipsec_proto_pkt_esn_antireplay(test_data, 2048); 10664 } 10665 10666 static int 10667 test_ipsec_proto_pkt_esn_antireplay4096(const void *test_data) 10668 { 10669 return test_ipsec_proto_pkt_esn_antireplay(test_data, 4096); 10670 } 10671 10672 static int 10673 test_PDCP_PROTO_all(void) 10674 { 10675 struct crypto_testsuite_params *ts_params = &testsuite_params; 10676 struct crypto_unittest_params *ut_params = &unittest_params; 10677 struct rte_cryptodev_info dev_info; 10678 int status; 10679 10680 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10681 uint64_t feat_flags = dev_info.feature_flags; 10682 10683 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 10684 return TEST_SKIPPED; 10685 10686 /* Set action type */ 10687 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 10688 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 10689 gbl_action_type; 10690 10691 if (security_proto_supported(ut_params->type, 10692 RTE_SECURITY_PROTOCOL_PDCP) < 0) 10693 return TEST_SKIPPED; 10694 10695 status = test_PDCP_PROTO_cplane_encap_all(); 10696 status += test_PDCP_PROTO_cplane_decap_all(); 10697 status += test_PDCP_PROTO_uplane_encap_all(); 10698 status += test_PDCP_PROTO_uplane_decap_all(); 10699 status += test_PDCP_PROTO_SGL_in_place_32B(); 10700 status += test_PDCP_PROTO_SGL_oop_32B_128B(); 10701 status += test_PDCP_PROTO_SGL_oop_32B_40B(); 10702 status += test_PDCP_PROTO_SGL_oop_128B_32B(); 10703 status += test_PDCP_SDAP_PROTO_encap_all(); 10704 status += test_PDCP_SDAP_PROTO_decap_all(); 10705 status += test_PDCP_PROTO_short_mac(); 10706 10707 if (status) 10708 return TEST_FAILED; 10709 else 10710 return TEST_SUCCESS; 10711 } 10712 10713 static int 10714 test_ipsec_proto_ipv4_ttl_decrement(const void *data __rte_unused) 10715 { 10716 struct ipsec_test_flags flags = { 10717 .dec_ttl_or_hop_limit = true 10718 }; 10719 10720 return test_ipsec_proto_all(&flags); 10721 } 10722 10723 static int 10724 test_ipsec_proto_ipv6_hop_limit_decrement(const void *data __rte_unused) 10725 { 10726 struct ipsec_test_flags flags = { 10727 .ipv6 = true, 10728 .dec_ttl_or_hop_limit = true 10729 }; 10730 10731 return test_ipsec_proto_all(&flags); 10732 } 10733 10734 static int 10735 test_docsis_proto_uplink(const void *data) 10736 { 10737 const struct docsis_test_data *d_td = data; 10738 struct crypto_testsuite_params *ts_params = &testsuite_params; 10739 struct crypto_unittest_params *ut_params = &unittest_params; 10740 uint8_t *plaintext = NULL; 10741 uint8_t *ciphertext = NULL; 10742 uint8_t *iv_ptr; 10743 int32_t cipher_len, crc_len; 10744 uint32_t crc_data_len; 10745 int ret = TEST_SUCCESS; 10746 10747 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 10748 rte_cryptodev_get_sec_ctx( 10749 ts_params->valid_devs[0]); 10750 10751 /* Verify the capabilities */ 10752 struct rte_security_capability_idx sec_cap_idx; 10753 const struct rte_security_capability *sec_cap; 10754 const struct rte_cryptodev_capabilities *crypto_cap; 10755 const struct rte_cryptodev_symmetric_capability *sym_cap; 10756 int j = 0; 10757 10758 /* Set action type */ 10759 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 10760 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 10761 gbl_action_type; 10762 10763 if (security_proto_supported(ut_params->type, 10764 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 10765 return TEST_SKIPPED; 10766 10767 sec_cap_idx.action = ut_params->type; 10768 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 10769 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK; 10770 10771 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 10772 if (sec_cap == NULL) 10773 return TEST_SKIPPED; 10774 10775 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 10776 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 10777 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 10778 crypto_cap->sym.xform_type == 10779 RTE_CRYPTO_SYM_XFORM_CIPHER && 10780 crypto_cap->sym.cipher.algo == 10781 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 10782 sym_cap = &crypto_cap->sym; 10783 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 10784 d_td->key.len, 10785 d_td->iv.len) == 0) 10786 break; 10787 } 10788 } 10789 10790 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 10791 return TEST_SKIPPED; 10792 10793 /* Setup source mbuf payload */ 10794 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10795 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10796 rte_pktmbuf_tailroom(ut_params->ibuf)); 10797 10798 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10799 d_td->ciphertext.len); 10800 10801 memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len); 10802 10803 /* Setup cipher session parameters */ 10804 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10805 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 10806 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 10807 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 10808 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 10809 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 10810 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 10811 ut_params->cipher_xform.next = NULL; 10812 10813 /* Setup DOCSIS session parameters */ 10814 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK; 10815 10816 struct rte_security_session_conf sess_conf = { 10817 .action_type = ut_params->type, 10818 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 10819 .docsis = ut_params->docsis_xform, 10820 .crypto_xform = &ut_params->cipher_xform, 10821 }; 10822 10823 /* Create security session */ 10824 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 10825 ts_params->session_mpool); 10826 10827 if (!ut_params->sec_session) { 10828 printf("Test function %s line %u: failed to allocate session\n", 10829 __func__, __LINE__); 10830 ret = TEST_FAILED; 10831 goto on_err; 10832 } 10833 10834 /* Generate crypto op data structure */ 10835 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10836 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10837 if (!ut_params->op) { 10838 printf("Test function %s line %u: failed to allocate symmetric " 10839 "crypto operation\n", __func__, __LINE__); 10840 ret = TEST_FAILED; 10841 goto on_err; 10842 } 10843 10844 /* Setup CRC operation parameters */ 10845 crc_len = d_td->ciphertext.no_crc == false ? 10846 (d_td->ciphertext.len - 10847 d_td->ciphertext.crc_offset - 10848 RTE_ETHER_CRC_LEN) : 10849 0; 10850 crc_len = crc_len > 0 ? crc_len : 0; 10851 crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN; 10852 ut_params->op->sym->auth.data.length = crc_len; 10853 ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset; 10854 10855 /* Setup cipher operation parameters */ 10856 cipher_len = d_td->ciphertext.no_cipher == false ? 10857 (d_td->ciphertext.len - 10858 d_td->ciphertext.cipher_offset) : 10859 0; 10860 cipher_len = cipher_len > 0 ? cipher_len : 0; 10861 ut_params->op->sym->cipher.data.length = cipher_len; 10862 ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset; 10863 10864 /* Setup cipher IV */ 10865 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 10866 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 10867 10868 /* Attach session to operation */ 10869 rte_security_attach_session(ut_params->op, ut_params->sec_session); 10870 10871 /* Set crypto operation mbufs */ 10872 ut_params->op->sym->m_src = ut_params->ibuf; 10873 ut_params->op->sym->m_dst = NULL; 10874 10875 /* Process crypto operation */ 10876 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 10877 NULL) { 10878 printf("Test function %s line %u: failed to process security " 10879 "crypto op\n", __func__, __LINE__); 10880 ret = TEST_FAILED; 10881 goto on_err; 10882 } 10883 10884 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 10885 printf("Test function %s line %u: failed to process crypto op\n", 10886 __func__, __LINE__); 10887 ret = TEST_FAILED; 10888 goto on_err; 10889 } 10890 10891 /* Validate plaintext */ 10892 plaintext = ciphertext; 10893 10894 if (memcmp(plaintext, d_td->plaintext.data, 10895 d_td->plaintext.len - crc_data_len)) { 10896 printf("Test function %s line %u: plaintext not as expected\n", 10897 __func__, __LINE__); 10898 rte_hexdump(stdout, "expected", d_td->plaintext.data, 10899 d_td->plaintext.len); 10900 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len); 10901 ret = TEST_FAILED; 10902 goto on_err; 10903 } 10904 10905 on_err: 10906 rte_crypto_op_free(ut_params->op); 10907 ut_params->op = NULL; 10908 10909 if (ut_params->sec_session) 10910 rte_security_session_destroy(ctx, ut_params->sec_session); 10911 ut_params->sec_session = NULL; 10912 10913 rte_pktmbuf_free(ut_params->ibuf); 10914 ut_params->ibuf = NULL; 10915 10916 return ret; 10917 } 10918 10919 static int 10920 test_docsis_proto_downlink(const void *data) 10921 { 10922 const struct docsis_test_data *d_td = data; 10923 struct crypto_testsuite_params *ts_params = &testsuite_params; 10924 struct crypto_unittest_params *ut_params = &unittest_params; 10925 uint8_t *plaintext = NULL; 10926 uint8_t *ciphertext = NULL; 10927 uint8_t *iv_ptr; 10928 int32_t cipher_len, crc_len; 10929 int ret = TEST_SUCCESS; 10930 10931 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 10932 rte_cryptodev_get_sec_ctx( 10933 ts_params->valid_devs[0]); 10934 10935 /* Verify the capabilities */ 10936 struct rte_security_capability_idx sec_cap_idx; 10937 const struct rte_security_capability *sec_cap; 10938 const struct rte_cryptodev_capabilities *crypto_cap; 10939 const struct rte_cryptodev_symmetric_capability *sym_cap; 10940 int j = 0; 10941 10942 /* Set action type */ 10943 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 10944 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 10945 gbl_action_type; 10946 10947 if (security_proto_supported(ut_params->type, 10948 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 10949 return TEST_SKIPPED; 10950 10951 sec_cap_idx.action = ut_params->type; 10952 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 10953 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 10954 10955 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 10956 if (sec_cap == NULL) 10957 return TEST_SKIPPED; 10958 10959 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 10960 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 10961 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 10962 crypto_cap->sym.xform_type == 10963 RTE_CRYPTO_SYM_XFORM_CIPHER && 10964 crypto_cap->sym.cipher.algo == 10965 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 10966 sym_cap = &crypto_cap->sym; 10967 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 10968 d_td->key.len, 10969 d_td->iv.len) == 0) 10970 break; 10971 } 10972 } 10973 10974 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 10975 return TEST_SKIPPED; 10976 10977 /* Setup source mbuf payload */ 10978 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10979 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10980 rte_pktmbuf_tailroom(ut_params->ibuf)); 10981 10982 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10983 d_td->plaintext.len); 10984 10985 memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len); 10986 10987 /* Setup cipher session parameters */ 10988 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10989 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 10990 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 10991 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 10992 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 10993 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 10994 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 10995 ut_params->cipher_xform.next = NULL; 10996 10997 /* Setup DOCSIS session parameters */ 10998 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 10999 11000 struct rte_security_session_conf sess_conf = { 11001 .action_type = ut_params->type, 11002 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 11003 .docsis = ut_params->docsis_xform, 11004 .crypto_xform = &ut_params->cipher_xform, 11005 }; 11006 11007 /* Create security session */ 11008 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 11009 ts_params->session_mpool); 11010 11011 if (!ut_params->sec_session) { 11012 printf("Test function %s line %u: failed to allocate session\n", 11013 __func__, __LINE__); 11014 ret = TEST_FAILED; 11015 goto on_err; 11016 } 11017 11018 /* Generate crypto op data structure */ 11019 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11020 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11021 if (!ut_params->op) { 11022 printf("Test function %s line %u: failed to allocate symmetric " 11023 "crypto operation\n", __func__, __LINE__); 11024 ret = TEST_FAILED; 11025 goto on_err; 11026 } 11027 11028 /* Setup CRC operation parameters */ 11029 crc_len = d_td->plaintext.no_crc == false ? 11030 (d_td->plaintext.len - 11031 d_td->plaintext.crc_offset - 11032 RTE_ETHER_CRC_LEN) : 11033 0; 11034 crc_len = crc_len > 0 ? crc_len : 0; 11035 ut_params->op->sym->auth.data.length = crc_len; 11036 ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset; 11037 11038 /* Setup cipher operation parameters */ 11039 cipher_len = d_td->plaintext.no_cipher == false ? 11040 (d_td->plaintext.len - 11041 d_td->plaintext.cipher_offset) : 11042 0; 11043 cipher_len = cipher_len > 0 ? cipher_len : 0; 11044 ut_params->op->sym->cipher.data.length = cipher_len; 11045 ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset; 11046 11047 /* Setup cipher IV */ 11048 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 11049 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 11050 11051 /* Attach session to operation */ 11052 rte_security_attach_session(ut_params->op, ut_params->sec_session); 11053 11054 /* Set crypto operation mbufs */ 11055 ut_params->op->sym->m_src = ut_params->ibuf; 11056 ut_params->op->sym->m_dst = NULL; 11057 11058 /* Process crypto operation */ 11059 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 11060 NULL) { 11061 printf("Test function %s line %u: failed to process crypto op\n", 11062 __func__, __LINE__); 11063 ret = TEST_FAILED; 11064 goto on_err; 11065 } 11066 11067 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 11068 printf("Test function %s line %u: crypto op processing failed\n", 11069 __func__, __LINE__); 11070 ret = TEST_FAILED; 11071 goto on_err; 11072 } 11073 11074 /* Validate ciphertext */ 11075 ciphertext = plaintext; 11076 11077 if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) { 11078 printf("Test function %s line %u: plaintext not as expected\n", 11079 __func__, __LINE__); 11080 rte_hexdump(stdout, "expected", d_td->ciphertext.data, 11081 d_td->ciphertext.len); 11082 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len); 11083 ret = TEST_FAILED; 11084 goto on_err; 11085 } 11086 11087 on_err: 11088 rte_crypto_op_free(ut_params->op); 11089 ut_params->op = NULL; 11090 11091 if (ut_params->sec_session) 11092 rte_security_session_destroy(ctx, ut_params->sec_session); 11093 ut_params->sec_session = NULL; 11094 11095 rte_pktmbuf_free(ut_params->ibuf); 11096 ut_params->ibuf = NULL; 11097 11098 return ret; 11099 } 11100 #endif 11101 11102 static int 11103 test_AES_GCM_authenticated_encryption_test_case_1(void) 11104 { 11105 return test_authenticated_encryption(&gcm_test_case_1); 11106 } 11107 11108 static int 11109 test_AES_GCM_authenticated_encryption_test_case_2(void) 11110 { 11111 return test_authenticated_encryption(&gcm_test_case_2); 11112 } 11113 11114 static int 11115 test_AES_GCM_authenticated_encryption_test_case_3(void) 11116 { 11117 return test_authenticated_encryption(&gcm_test_case_3); 11118 } 11119 11120 static int 11121 test_AES_GCM_authenticated_encryption_test_case_4(void) 11122 { 11123 return test_authenticated_encryption(&gcm_test_case_4); 11124 } 11125 11126 static int 11127 test_AES_GCM_authenticated_encryption_test_case_5(void) 11128 { 11129 return test_authenticated_encryption(&gcm_test_case_5); 11130 } 11131 11132 static int 11133 test_AES_GCM_authenticated_encryption_test_case_6(void) 11134 { 11135 return test_authenticated_encryption(&gcm_test_case_6); 11136 } 11137 11138 static int 11139 test_AES_GCM_authenticated_encryption_test_case_7(void) 11140 { 11141 return test_authenticated_encryption(&gcm_test_case_7); 11142 } 11143 11144 static int 11145 test_AES_GCM_authenticated_encryption_test_case_8(void) 11146 { 11147 return test_authenticated_encryption(&gcm_test_case_8); 11148 } 11149 11150 static int 11151 test_AES_GCM_J0_authenticated_encryption_test_case_1(void) 11152 { 11153 return test_authenticated_encryption(&gcm_J0_test_case_1); 11154 } 11155 11156 static int 11157 test_AES_GCM_auth_encryption_test_case_192_1(void) 11158 { 11159 return test_authenticated_encryption(&gcm_test_case_192_1); 11160 } 11161 11162 static int 11163 test_AES_GCM_auth_encryption_test_case_192_2(void) 11164 { 11165 return test_authenticated_encryption(&gcm_test_case_192_2); 11166 } 11167 11168 static int 11169 test_AES_GCM_auth_encryption_test_case_192_3(void) 11170 { 11171 return test_authenticated_encryption(&gcm_test_case_192_3); 11172 } 11173 11174 static int 11175 test_AES_GCM_auth_encryption_test_case_192_4(void) 11176 { 11177 return test_authenticated_encryption(&gcm_test_case_192_4); 11178 } 11179 11180 static int 11181 test_AES_GCM_auth_encryption_test_case_192_5(void) 11182 { 11183 return test_authenticated_encryption(&gcm_test_case_192_5); 11184 } 11185 11186 static int 11187 test_AES_GCM_auth_encryption_test_case_192_6(void) 11188 { 11189 return test_authenticated_encryption(&gcm_test_case_192_6); 11190 } 11191 11192 static int 11193 test_AES_GCM_auth_encryption_test_case_192_7(void) 11194 { 11195 return test_authenticated_encryption(&gcm_test_case_192_7); 11196 } 11197 11198 static int 11199 test_AES_GCM_auth_encryption_test_case_256_1(void) 11200 { 11201 return test_authenticated_encryption(&gcm_test_case_256_1); 11202 } 11203 11204 static int 11205 test_AES_GCM_auth_encryption_test_case_256_2(void) 11206 { 11207 return test_authenticated_encryption(&gcm_test_case_256_2); 11208 } 11209 11210 static int 11211 test_AES_GCM_auth_encryption_test_case_256_3(void) 11212 { 11213 return test_authenticated_encryption(&gcm_test_case_256_3); 11214 } 11215 11216 static int 11217 test_AES_GCM_auth_encryption_test_case_256_4(void) 11218 { 11219 return test_authenticated_encryption(&gcm_test_case_256_4); 11220 } 11221 11222 static int 11223 test_AES_GCM_auth_encryption_test_case_256_5(void) 11224 { 11225 return test_authenticated_encryption(&gcm_test_case_256_5); 11226 } 11227 11228 static int 11229 test_AES_GCM_auth_encryption_test_case_256_6(void) 11230 { 11231 return test_authenticated_encryption(&gcm_test_case_256_6); 11232 } 11233 11234 static int 11235 test_AES_GCM_auth_encryption_test_case_256_7(void) 11236 { 11237 return test_authenticated_encryption(&gcm_test_case_256_7); 11238 } 11239 11240 static int 11241 test_AES_GCM_auth_encryption_test_case_aad_1(void) 11242 { 11243 return test_authenticated_encryption(&gcm_test_case_aad_1); 11244 } 11245 11246 static int 11247 test_AES_GCM_auth_encryption_test_case_aad_2(void) 11248 { 11249 return test_authenticated_encryption(&gcm_test_case_aad_2); 11250 } 11251 11252 static int 11253 test_AES_GCM_auth_encryption_fail_iv_corrupt(void) 11254 { 11255 struct aead_test_data tdata; 11256 int res; 11257 11258 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11259 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11260 tdata.iv.data[0] += 1; 11261 res = test_authenticated_encryption(&tdata); 11262 if (res == TEST_SKIPPED) 11263 return res; 11264 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 11265 return TEST_SUCCESS; 11266 } 11267 11268 static int 11269 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void) 11270 { 11271 struct aead_test_data tdata; 11272 int res; 11273 11274 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11275 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11276 tdata.plaintext.data[0] += 1; 11277 res = test_authenticated_encryption(&tdata); 11278 if (res == TEST_SKIPPED) 11279 return res; 11280 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 11281 return TEST_SUCCESS; 11282 } 11283 11284 static int 11285 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void) 11286 { 11287 struct aead_test_data tdata; 11288 int res; 11289 11290 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11291 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11292 tdata.ciphertext.data[0] += 1; 11293 res = test_authenticated_encryption(&tdata); 11294 if (res == TEST_SKIPPED) 11295 return res; 11296 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 11297 return TEST_SUCCESS; 11298 } 11299 11300 static int 11301 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void) 11302 { 11303 struct aead_test_data tdata; 11304 int res; 11305 11306 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11307 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11308 tdata.aad.len += 1; 11309 res = test_authenticated_encryption(&tdata); 11310 if (res == TEST_SKIPPED) 11311 return res; 11312 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 11313 return TEST_SUCCESS; 11314 } 11315 11316 static int 11317 test_AES_GCM_auth_encryption_fail_aad_corrupt(void) 11318 { 11319 struct aead_test_data tdata; 11320 uint8_t aad[gcm_test_case_7.aad.len]; 11321 int res; 11322 11323 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11324 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11325 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 11326 aad[0] += 1; 11327 tdata.aad.data = aad; 11328 res = test_authenticated_encryption(&tdata); 11329 if (res == TEST_SKIPPED) 11330 return res; 11331 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 11332 return TEST_SUCCESS; 11333 } 11334 11335 static int 11336 test_AES_GCM_auth_encryption_fail_tag_corrupt(void) 11337 { 11338 struct aead_test_data tdata; 11339 int res; 11340 11341 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11342 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11343 tdata.auth_tag.data[0] += 1; 11344 res = test_authenticated_encryption(&tdata); 11345 if (res == TEST_SKIPPED) 11346 return res; 11347 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 11348 return TEST_SUCCESS; 11349 } 11350 11351 static int 11352 test_authenticated_decryption(const struct aead_test_data *tdata) 11353 { 11354 struct crypto_testsuite_params *ts_params = &testsuite_params; 11355 struct crypto_unittest_params *ut_params = &unittest_params; 11356 11357 int retval; 11358 uint8_t *plaintext; 11359 uint32_t i; 11360 struct rte_cryptodev_info dev_info; 11361 11362 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11363 uint64_t feat_flags = dev_info.feature_flags; 11364 11365 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11366 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11367 printf("Device doesn't support RAW data-path APIs.\n"); 11368 return TEST_SKIPPED; 11369 } 11370 11371 /* Verify the capabilities */ 11372 struct rte_cryptodev_sym_capability_idx cap_idx; 11373 const struct rte_cryptodev_symmetric_capability *capability; 11374 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11375 cap_idx.algo.aead = tdata->algo; 11376 capability = rte_cryptodev_sym_capability_get( 11377 ts_params->valid_devs[0], &cap_idx); 11378 if (capability == NULL) 11379 return TEST_SKIPPED; 11380 if (rte_cryptodev_sym_capability_check_aead( 11381 capability, tdata->key.len, tdata->auth_tag.len, 11382 tdata->aad.len, tdata->iv.len)) 11383 return TEST_SKIPPED; 11384 11385 /* Create AEAD session */ 11386 retval = create_aead_session(ts_params->valid_devs[0], 11387 tdata->algo, 11388 RTE_CRYPTO_AEAD_OP_DECRYPT, 11389 tdata->key.data, tdata->key.len, 11390 tdata->aad.len, tdata->auth_tag.len, 11391 tdata->iv.len); 11392 if (retval < 0) 11393 return retval; 11394 11395 /* alloc mbuf and set payload */ 11396 if (tdata->aad.len > MBUF_SIZE) { 11397 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 11398 /* Populate full size of add data */ 11399 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 11400 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 11401 } else 11402 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11403 11404 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11405 rte_pktmbuf_tailroom(ut_params->ibuf)); 11406 11407 /* Create AEAD operation */ 11408 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 11409 if (retval < 0) 11410 return retval; 11411 11412 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11413 11414 ut_params->op->sym->m_src = ut_params->ibuf; 11415 11416 /* Process crypto operation */ 11417 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11418 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 11419 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11420 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11421 ut_params->op, 0, 0, 0, 0); 11422 else 11423 TEST_ASSERT_NOT_NULL( 11424 process_crypto_request(ts_params->valid_devs[0], 11425 ut_params->op), "failed to process sym crypto op"); 11426 11427 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11428 "crypto op processing failed"); 11429 11430 if (ut_params->op->sym->m_dst) 11431 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 11432 uint8_t *); 11433 else 11434 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 11435 uint8_t *, 11436 ut_params->op->sym->cipher.data.offset); 11437 11438 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 11439 11440 /* Validate obuf */ 11441 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11442 plaintext, 11443 tdata->plaintext.data, 11444 tdata->plaintext.len, 11445 "Plaintext data not as expected"); 11446 11447 TEST_ASSERT_EQUAL(ut_params->op->status, 11448 RTE_CRYPTO_OP_STATUS_SUCCESS, 11449 "Authentication failed"); 11450 11451 return 0; 11452 } 11453 11454 static int 11455 test_AES_GCM_authenticated_decryption_test_case_1(void) 11456 { 11457 return test_authenticated_decryption(&gcm_test_case_1); 11458 } 11459 11460 static int 11461 test_AES_GCM_authenticated_decryption_test_case_2(void) 11462 { 11463 return test_authenticated_decryption(&gcm_test_case_2); 11464 } 11465 11466 static int 11467 test_AES_GCM_authenticated_decryption_test_case_3(void) 11468 { 11469 return test_authenticated_decryption(&gcm_test_case_3); 11470 } 11471 11472 static int 11473 test_AES_GCM_authenticated_decryption_test_case_4(void) 11474 { 11475 return test_authenticated_decryption(&gcm_test_case_4); 11476 } 11477 11478 static int 11479 test_AES_GCM_authenticated_decryption_test_case_5(void) 11480 { 11481 return test_authenticated_decryption(&gcm_test_case_5); 11482 } 11483 11484 static int 11485 test_AES_GCM_authenticated_decryption_test_case_6(void) 11486 { 11487 return test_authenticated_decryption(&gcm_test_case_6); 11488 } 11489 11490 static int 11491 test_AES_GCM_authenticated_decryption_test_case_7(void) 11492 { 11493 return test_authenticated_decryption(&gcm_test_case_7); 11494 } 11495 11496 static int 11497 test_AES_GCM_authenticated_decryption_test_case_8(void) 11498 { 11499 return test_authenticated_decryption(&gcm_test_case_8); 11500 } 11501 11502 static int 11503 test_AES_GCM_J0_authenticated_decryption_test_case_1(void) 11504 { 11505 return test_authenticated_decryption(&gcm_J0_test_case_1); 11506 } 11507 11508 static int 11509 test_AES_GCM_auth_decryption_test_case_192_1(void) 11510 { 11511 return test_authenticated_decryption(&gcm_test_case_192_1); 11512 } 11513 11514 static int 11515 test_AES_GCM_auth_decryption_test_case_192_2(void) 11516 { 11517 return test_authenticated_decryption(&gcm_test_case_192_2); 11518 } 11519 11520 static int 11521 test_AES_GCM_auth_decryption_test_case_192_3(void) 11522 { 11523 return test_authenticated_decryption(&gcm_test_case_192_3); 11524 } 11525 11526 static int 11527 test_AES_GCM_auth_decryption_test_case_192_4(void) 11528 { 11529 return test_authenticated_decryption(&gcm_test_case_192_4); 11530 } 11531 11532 static int 11533 test_AES_GCM_auth_decryption_test_case_192_5(void) 11534 { 11535 return test_authenticated_decryption(&gcm_test_case_192_5); 11536 } 11537 11538 static int 11539 test_AES_GCM_auth_decryption_test_case_192_6(void) 11540 { 11541 return test_authenticated_decryption(&gcm_test_case_192_6); 11542 } 11543 11544 static int 11545 test_AES_GCM_auth_decryption_test_case_192_7(void) 11546 { 11547 return test_authenticated_decryption(&gcm_test_case_192_7); 11548 } 11549 11550 static int 11551 test_AES_GCM_auth_decryption_test_case_256_1(void) 11552 { 11553 return test_authenticated_decryption(&gcm_test_case_256_1); 11554 } 11555 11556 static int 11557 test_AES_GCM_auth_decryption_test_case_256_2(void) 11558 { 11559 return test_authenticated_decryption(&gcm_test_case_256_2); 11560 } 11561 11562 static int 11563 test_AES_GCM_auth_decryption_test_case_256_3(void) 11564 { 11565 return test_authenticated_decryption(&gcm_test_case_256_3); 11566 } 11567 11568 static int 11569 test_AES_GCM_auth_decryption_test_case_256_4(void) 11570 { 11571 return test_authenticated_decryption(&gcm_test_case_256_4); 11572 } 11573 11574 static int 11575 test_AES_GCM_auth_decryption_test_case_256_5(void) 11576 { 11577 return test_authenticated_decryption(&gcm_test_case_256_5); 11578 } 11579 11580 static int 11581 test_AES_GCM_auth_decryption_test_case_256_6(void) 11582 { 11583 return test_authenticated_decryption(&gcm_test_case_256_6); 11584 } 11585 11586 static int 11587 test_AES_GCM_auth_decryption_test_case_256_7(void) 11588 { 11589 return test_authenticated_decryption(&gcm_test_case_256_7); 11590 } 11591 11592 static int 11593 test_AES_GCM_auth_decryption_test_case_aad_1(void) 11594 { 11595 return test_authenticated_decryption(&gcm_test_case_aad_1); 11596 } 11597 11598 static int 11599 test_AES_GCM_auth_decryption_test_case_aad_2(void) 11600 { 11601 return test_authenticated_decryption(&gcm_test_case_aad_2); 11602 } 11603 11604 static int 11605 test_AES_GCM_auth_decryption_fail_iv_corrupt(void) 11606 { 11607 struct aead_test_data tdata; 11608 int res; 11609 11610 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11611 tdata.iv.data[0] += 1; 11612 res = test_authenticated_decryption(&tdata); 11613 if (res == TEST_SKIPPED) 11614 return res; 11615 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11616 return TEST_SUCCESS; 11617 } 11618 11619 static int 11620 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void) 11621 { 11622 struct aead_test_data tdata; 11623 int res; 11624 11625 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11626 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11627 tdata.plaintext.data[0] += 1; 11628 res = test_authenticated_decryption(&tdata); 11629 if (res == TEST_SKIPPED) 11630 return res; 11631 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11632 return TEST_SUCCESS; 11633 } 11634 11635 static int 11636 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void) 11637 { 11638 struct aead_test_data tdata; 11639 int res; 11640 11641 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11642 tdata.ciphertext.data[0] += 1; 11643 res = test_authenticated_decryption(&tdata); 11644 if (res == TEST_SKIPPED) 11645 return res; 11646 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11647 return TEST_SUCCESS; 11648 } 11649 11650 static int 11651 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void) 11652 { 11653 struct aead_test_data tdata; 11654 int res; 11655 11656 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11657 tdata.aad.len += 1; 11658 res = test_authenticated_decryption(&tdata); 11659 if (res == TEST_SKIPPED) 11660 return res; 11661 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11662 return TEST_SUCCESS; 11663 } 11664 11665 static int 11666 test_AES_GCM_auth_decryption_fail_aad_corrupt(void) 11667 { 11668 struct aead_test_data tdata; 11669 uint8_t aad[gcm_test_case_7.aad.len]; 11670 int res; 11671 11672 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11673 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 11674 aad[0] += 1; 11675 tdata.aad.data = aad; 11676 res = test_authenticated_decryption(&tdata); 11677 if (res == TEST_SKIPPED) 11678 return res; 11679 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11680 return TEST_SUCCESS; 11681 } 11682 11683 static int 11684 test_AES_GCM_auth_decryption_fail_tag_corrupt(void) 11685 { 11686 struct aead_test_data tdata; 11687 int res; 11688 11689 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11690 tdata.auth_tag.data[0] += 1; 11691 res = test_authenticated_decryption(&tdata); 11692 if (res == TEST_SKIPPED) 11693 return res; 11694 TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed"); 11695 return TEST_SUCCESS; 11696 } 11697 11698 static int 11699 test_authenticated_encryption_oop(const struct aead_test_data *tdata) 11700 { 11701 struct crypto_testsuite_params *ts_params = &testsuite_params; 11702 struct crypto_unittest_params *ut_params = &unittest_params; 11703 11704 int retval; 11705 uint8_t *ciphertext, *auth_tag; 11706 uint16_t plaintext_pad_len; 11707 struct rte_cryptodev_info dev_info; 11708 11709 /* Verify the capabilities */ 11710 struct rte_cryptodev_sym_capability_idx cap_idx; 11711 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11712 cap_idx.algo.aead = tdata->algo; 11713 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11714 &cap_idx) == NULL) 11715 return TEST_SKIPPED; 11716 11717 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11718 uint64_t feat_flags = dev_info.feature_flags; 11719 11720 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11721 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) 11722 return TEST_SKIPPED; 11723 11724 /* not supported with CPU crypto */ 11725 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11726 return TEST_SKIPPED; 11727 11728 /* Create AEAD session */ 11729 retval = create_aead_session(ts_params->valid_devs[0], 11730 tdata->algo, 11731 RTE_CRYPTO_AEAD_OP_ENCRYPT, 11732 tdata->key.data, tdata->key.len, 11733 tdata->aad.len, tdata->auth_tag.len, 11734 tdata->iv.len); 11735 if (retval < 0) 11736 return retval; 11737 11738 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11739 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11740 11741 /* clear mbuf payload */ 11742 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11743 rte_pktmbuf_tailroom(ut_params->ibuf)); 11744 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 11745 rte_pktmbuf_tailroom(ut_params->obuf)); 11746 11747 /* Create AEAD operation */ 11748 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 11749 if (retval < 0) 11750 return retval; 11751 11752 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11753 11754 ut_params->op->sym->m_src = ut_params->ibuf; 11755 ut_params->op->sym->m_dst = ut_params->obuf; 11756 11757 /* Process crypto operation */ 11758 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11759 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11760 ut_params->op, 0, 0, 0, 0); 11761 else 11762 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 11763 ut_params->op), "failed to process sym crypto op"); 11764 11765 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11766 "crypto op processing failed"); 11767 11768 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 11769 11770 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 11771 ut_params->op->sym->cipher.data.offset); 11772 auth_tag = ciphertext + plaintext_pad_len; 11773 11774 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 11775 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 11776 11777 /* Validate obuf */ 11778 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11779 ciphertext, 11780 tdata->ciphertext.data, 11781 tdata->ciphertext.len, 11782 "Ciphertext data not as expected"); 11783 11784 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11785 auth_tag, 11786 tdata->auth_tag.data, 11787 tdata->auth_tag.len, 11788 "Generated auth tag not as expected"); 11789 11790 return 0; 11791 11792 } 11793 11794 static int 11795 test_AES_GCM_authenticated_encryption_oop_test_case_1(void) 11796 { 11797 return test_authenticated_encryption_oop(&gcm_test_case_5); 11798 } 11799 11800 static int 11801 test_authenticated_decryption_oop(const struct aead_test_data *tdata) 11802 { 11803 struct crypto_testsuite_params *ts_params = &testsuite_params; 11804 struct crypto_unittest_params *ut_params = &unittest_params; 11805 11806 int retval; 11807 uint8_t *plaintext; 11808 struct rte_cryptodev_info dev_info; 11809 11810 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11811 uint64_t feat_flags = dev_info.feature_flags; 11812 11813 /* Verify the capabilities */ 11814 struct rte_cryptodev_sym_capability_idx cap_idx; 11815 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11816 cap_idx.algo.aead = tdata->algo; 11817 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11818 &cap_idx) == NULL) 11819 return TEST_SKIPPED; 11820 11821 /* not supported with CPU crypto and raw data-path APIs*/ 11822 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO || 11823 global_api_test_type == CRYPTODEV_RAW_API_TEST) 11824 return TEST_SKIPPED; 11825 11826 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11827 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11828 printf("Device does not support RAW data-path APIs.\n"); 11829 return TEST_SKIPPED; 11830 } 11831 11832 /* Create AEAD session */ 11833 retval = create_aead_session(ts_params->valid_devs[0], 11834 tdata->algo, 11835 RTE_CRYPTO_AEAD_OP_DECRYPT, 11836 tdata->key.data, tdata->key.len, 11837 tdata->aad.len, tdata->auth_tag.len, 11838 tdata->iv.len); 11839 if (retval < 0) 11840 return retval; 11841 11842 /* alloc mbuf and set payload */ 11843 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11844 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11845 11846 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11847 rte_pktmbuf_tailroom(ut_params->ibuf)); 11848 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 11849 rte_pktmbuf_tailroom(ut_params->obuf)); 11850 11851 /* Create AEAD operation */ 11852 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 11853 if (retval < 0) 11854 return retval; 11855 11856 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11857 11858 ut_params->op->sym->m_src = ut_params->ibuf; 11859 ut_params->op->sym->m_dst = ut_params->obuf; 11860 11861 /* Process crypto operation */ 11862 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11863 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11864 ut_params->op, 0, 0, 0, 0); 11865 else 11866 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 11867 ut_params->op), "failed to process sym crypto op"); 11868 11869 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11870 "crypto op processing failed"); 11871 11872 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 11873 ut_params->op->sym->cipher.data.offset); 11874 11875 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 11876 11877 /* Validate obuf */ 11878 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11879 plaintext, 11880 tdata->plaintext.data, 11881 tdata->plaintext.len, 11882 "Plaintext data not as expected"); 11883 11884 TEST_ASSERT_EQUAL(ut_params->op->status, 11885 RTE_CRYPTO_OP_STATUS_SUCCESS, 11886 "Authentication failed"); 11887 return 0; 11888 } 11889 11890 static int 11891 test_AES_GCM_authenticated_decryption_oop_test_case_1(void) 11892 { 11893 return test_authenticated_decryption_oop(&gcm_test_case_5); 11894 } 11895 11896 static int 11897 test_authenticated_encryption_sessionless( 11898 const struct aead_test_data *tdata) 11899 { 11900 struct crypto_testsuite_params *ts_params = &testsuite_params; 11901 struct crypto_unittest_params *ut_params = &unittest_params; 11902 11903 int retval; 11904 uint8_t *ciphertext, *auth_tag; 11905 uint16_t plaintext_pad_len; 11906 uint8_t key[tdata->key.len + 1]; 11907 struct rte_cryptodev_info dev_info; 11908 11909 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11910 uint64_t feat_flags = dev_info.feature_flags; 11911 11912 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 11913 printf("Device doesn't support Sessionless ops.\n"); 11914 return TEST_SKIPPED; 11915 } 11916 11917 /* not supported with CPU crypto */ 11918 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11919 return TEST_SKIPPED; 11920 11921 /* Verify the capabilities */ 11922 struct rte_cryptodev_sym_capability_idx cap_idx; 11923 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11924 cap_idx.algo.aead = tdata->algo; 11925 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11926 &cap_idx) == NULL) 11927 return TEST_SKIPPED; 11928 11929 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11930 11931 /* clear mbuf payload */ 11932 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11933 rte_pktmbuf_tailroom(ut_params->ibuf)); 11934 11935 /* Create AEAD operation */ 11936 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 11937 if (retval < 0) 11938 return retval; 11939 11940 /* Create GCM xform */ 11941 memcpy(key, tdata->key.data, tdata->key.len); 11942 retval = create_aead_xform(ut_params->op, 11943 tdata->algo, 11944 RTE_CRYPTO_AEAD_OP_ENCRYPT, 11945 key, tdata->key.len, 11946 tdata->aad.len, tdata->auth_tag.len, 11947 tdata->iv.len); 11948 if (retval < 0) 11949 return retval; 11950 11951 ut_params->op->sym->m_src = ut_params->ibuf; 11952 11953 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 11954 RTE_CRYPTO_OP_SESSIONLESS, 11955 "crypto op session type not sessionless"); 11956 11957 /* Process crypto operation */ 11958 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 11959 ut_params->op), "failed to process sym crypto op"); 11960 11961 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 11962 11963 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11964 "crypto op status not success"); 11965 11966 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 11967 11968 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 11969 ut_params->op->sym->cipher.data.offset); 11970 auth_tag = ciphertext + plaintext_pad_len; 11971 11972 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 11973 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 11974 11975 /* Validate obuf */ 11976 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11977 ciphertext, 11978 tdata->ciphertext.data, 11979 tdata->ciphertext.len, 11980 "Ciphertext data not as expected"); 11981 11982 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11983 auth_tag, 11984 tdata->auth_tag.data, 11985 tdata->auth_tag.len, 11986 "Generated auth tag not as expected"); 11987 11988 return 0; 11989 11990 } 11991 11992 static int 11993 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void) 11994 { 11995 return test_authenticated_encryption_sessionless( 11996 &gcm_test_case_5); 11997 } 11998 11999 static int 12000 test_authenticated_decryption_sessionless( 12001 const struct aead_test_data *tdata) 12002 { 12003 struct crypto_testsuite_params *ts_params = &testsuite_params; 12004 struct crypto_unittest_params *ut_params = &unittest_params; 12005 12006 int retval; 12007 uint8_t *plaintext; 12008 uint8_t key[tdata->key.len + 1]; 12009 struct rte_cryptodev_info dev_info; 12010 12011 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12012 uint64_t feat_flags = dev_info.feature_flags; 12013 12014 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 12015 printf("Device doesn't support Sessionless ops.\n"); 12016 return TEST_SKIPPED; 12017 } 12018 12019 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12020 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12021 printf("Device doesn't support RAW data-path APIs.\n"); 12022 return TEST_SKIPPED; 12023 } 12024 12025 /* not supported with CPU crypto */ 12026 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12027 return TEST_SKIPPED; 12028 12029 /* Verify the capabilities */ 12030 struct rte_cryptodev_sym_capability_idx cap_idx; 12031 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12032 cap_idx.algo.aead = tdata->algo; 12033 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12034 &cap_idx) == NULL) 12035 return TEST_SKIPPED; 12036 12037 /* alloc mbuf and set payload */ 12038 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12039 12040 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12041 rte_pktmbuf_tailroom(ut_params->ibuf)); 12042 12043 /* Create AEAD operation */ 12044 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 12045 if (retval < 0) 12046 return retval; 12047 12048 /* Create AEAD xform */ 12049 memcpy(key, tdata->key.data, tdata->key.len); 12050 retval = create_aead_xform(ut_params->op, 12051 tdata->algo, 12052 RTE_CRYPTO_AEAD_OP_DECRYPT, 12053 key, tdata->key.len, 12054 tdata->aad.len, tdata->auth_tag.len, 12055 tdata->iv.len); 12056 if (retval < 0) 12057 return retval; 12058 12059 ut_params->op->sym->m_src = ut_params->ibuf; 12060 12061 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 12062 RTE_CRYPTO_OP_SESSIONLESS, 12063 "crypto op session type not sessionless"); 12064 12065 /* Process crypto operation */ 12066 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12067 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12068 ut_params->op, 0, 0, 0, 0); 12069 else 12070 TEST_ASSERT_NOT_NULL(process_crypto_request( 12071 ts_params->valid_devs[0], ut_params->op), 12072 "failed to process sym crypto op"); 12073 12074 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 12075 12076 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12077 "crypto op status not success"); 12078 12079 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 12080 ut_params->op->sym->cipher.data.offset); 12081 12082 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 12083 12084 /* Validate obuf */ 12085 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12086 plaintext, 12087 tdata->plaintext.data, 12088 tdata->plaintext.len, 12089 "Plaintext data not as expected"); 12090 12091 TEST_ASSERT_EQUAL(ut_params->op->status, 12092 RTE_CRYPTO_OP_STATUS_SUCCESS, 12093 "Authentication failed"); 12094 return 0; 12095 } 12096 12097 static int 12098 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void) 12099 { 12100 return test_authenticated_decryption_sessionless( 12101 &gcm_test_case_5); 12102 } 12103 12104 static int 12105 test_AES_CCM_authenticated_encryption_test_case_128_1(void) 12106 { 12107 return test_authenticated_encryption(&ccm_test_case_128_1); 12108 } 12109 12110 static int 12111 test_AES_CCM_authenticated_encryption_test_case_128_2(void) 12112 { 12113 return test_authenticated_encryption(&ccm_test_case_128_2); 12114 } 12115 12116 static int 12117 test_AES_CCM_authenticated_encryption_test_case_128_3(void) 12118 { 12119 return test_authenticated_encryption(&ccm_test_case_128_3); 12120 } 12121 12122 static int 12123 test_AES_CCM_authenticated_decryption_test_case_128_1(void) 12124 { 12125 return test_authenticated_decryption(&ccm_test_case_128_1); 12126 } 12127 12128 static int 12129 test_AES_CCM_authenticated_decryption_test_case_128_2(void) 12130 { 12131 return test_authenticated_decryption(&ccm_test_case_128_2); 12132 } 12133 12134 static int 12135 test_AES_CCM_authenticated_decryption_test_case_128_3(void) 12136 { 12137 return test_authenticated_decryption(&ccm_test_case_128_3); 12138 } 12139 12140 static int 12141 test_AES_CCM_authenticated_encryption_test_case_192_1(void) 12142 { 12143 return test_authenticated_encryption(&ccm_test_case_192_1); 12144 } 12145 12146 static int 12147 test_AES_CCM_authenticated_encryption_test_case_192_2(void) 12148 { 12149 return test_authenticated_encryption(&ccm_test_case_192_2); 12150 } 12151 12152 static int 12153 test_AES_CCM_authenticated_encryption_test_case_192_3(void) 12154 { 12155 return test_authenticated_encryption(&ccm_test_case_192_3); 12156 } 12157 12158 static int 12159 test_AES_CCM_authenticated_decryption_test_case_192_1(void) 12160 { 12161 return test_authenticated_decryption(&ccm_test_case_192_1); 12162 } 12163 12164 static int 12165 test_AES_CCM_authenticated_decryption_test_case_192_2(void) 12166 { 12167 return test_authenticated_decryption(&ccm_test_case_192_2); 12168 } 12169 12170 static int 12171 test_AES_CCM_authenticated_decryption_test_case_192_3(void) 12172 { 12173 return test_authenticated_decryption(&ccm_test_case_192_3); 12174 } 12175 12176 static int 12177 test_AES_CCM_authenticated_encryption_test_case_256_1(void) 12178 { 12179 return test_authenticated_encryption(&ccm_test_case_256_1); 12180 } 12181 12182 static int 12183 test_AES_CCM_authenticated_encryption_test_case_256_2(void) 12184 { 12185 return test_authenticated_encryption(&ccm_test_case_256_2); 12186 } 12187 12188 static int 12189 test_AES_CCM_authenticated_encryption_test_case_256_3(void) 12190 { 12191 return test_authenticated_encryption(&ccm_test_case_256_3); 12192 } 12193 12194 static int 12195 test_AES_CCM_authenticated_decryption_test_case_256_1(void) 12196 { 12197 return test_authenticated_decryption(&ccm_test_case_256_1); 12198 } 12199 12200 static int 12201 test_AES_CCM_authenticated_decryption_test_case_256_2(void) 12202 { 12203 return test_authenticated_decryption(&ccm_test_case_256_2); 12204 } 12205 12206 static int 12207 test_AES_CCM_authenticated_decryption_test_case_256_3(void) 12208 { 12209 return test_authenticated_decryption(&ccm_test_case_256_3); 12210 } 12211 12212 static int 12213 test_stats(void) 12214 { 12215 struct crypto_testsuite_params *ts_params = &testsuite_params; 12216 struct rte_cryptodev_stats stats; 12217 12218 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12219 return TEST_SKIPPED; 12220 12221 /* Verify the capabilities */ 12222 struct rte_cryptodev_sym_capability_idx cap_idx; 12223 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12224 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 12225 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12226 &cap_idx) == NULL) 12227 return TEST_SKIPPED; 12228 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12229 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 12230 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12231 &cap_idx) == NULL) 12232 return TEST_SKIPPED; 12233 12234 if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 12235 == -ENOTSUP) 12236 return TEST_SKIPPED; 12237 12238 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 12239 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 12240 &stats) == -ENODEV), 12241 "rte_cryptodev_stats_get invalid dev failed"); 12242 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 12243 "rte_cryptodev_stats_get invalid Param failed"); 12244 12245 /* Test expected values */ 12246 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 12247 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 12248 &stats), 12249 "rte_cryptodev_stats_get failed"); 12250 TEST_ASSERT((stats.enqueued_count == 1), 12251 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 12252 TEST_ASSERT((stats.dequeued_count == 1), 12253 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 12254 TEST_ASSERT((stats.enqueue_err_count == 0), 12255 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 12256 TEST_ASSERT((stats.dequeue_err_count == 0), 12257 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 12258 12259 /* invalid device but should ignore and not reset device stats*/ 12260 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 12261 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 12262 &stats), 12263 "rte_cryptodev_stats_get failed"); 12264 TEST_ASSERT((stats.enqueued_count == 1), 12265 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 12266 12267 /* check that a valid reset clears stats */ 12268 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 12269 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 12270 &stats), 12271 "rte_cryptodev_stats_get failed"); 12272 TEST_ASSERT((stats.enqueued_count == 0), 12273 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 12274 TEST_ASSERT((stats.dequeued_count == 0), 12275 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 12276 12277 return TEST_SUCCESS; 12278 } 12279 12280 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 12281 struct crypto_unittest_params *ut_params, 12282 enum rte_crypto_auth_operation op, 12283 const struct HMAC_MD5_vector *test_case) 12284 { 12285 uint8_t key[64]; 12286 12287 memcpy(key, test_case->key.data, test_case->key.len); 12288 12289 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12290 ut_params->auth_xform.next = NULL; 12291 ut_params->auth_xform.auth.op = op; 12292 12293 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 12294 12295 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 12296 ut_params->auth_xform.auth.key.length = test_case->key.len; 12297 ut_params->auth_xform.auth.key.data = key; 12298 12299 ut_params->sess = rte_cryptodev_sym_session_create( 12300 ts_params->valid_devs[0], &ut_params->auth_xform, 12301 ts_params->session_mpool); 12302 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 12303 return TEST_SKIPPED; 12304 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12305 12306 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12307 12308 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12309 rte_pktmbuf_tailroom(ut_params->ibuf)); 12310 12311 return 0; 12312 } 12313 12314 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 12315 const struct HMAC_MD5_vector *test_case, 12316 uint8_t **plaintext) 12317 { 12318 uint16_t plaintext_pad_len; 12319 12320 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12321 12322 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 12323 16); 12324 12325 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12326 plaintext_pad_len); 12327 memcpy(*plaintext, test_case->plaintext.data, 12328 test_case->plaintext.len); 12329 12330 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12331 ut_params->ibuf, MD5_DIGEST_LEN); 12332 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12333 "no room to append digest"); 12334 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12335 ut_params->ibuf, plaintext_pad_len); 12336 12337 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 12338 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 12339 test_case->auth_tag.len); 12340 } 12341 12342 sym_op->auth.data.offset = 0; 12343 sym_op->auth.data.length = test_case->plaintext.len; 12344 12345 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12346 ut_params->op->sym->m_src = ut_params->ibuf; 12347 12348 return 0; 12349 } 12350 12351 static int 12352 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 12353 { 12354 uint16_t plaintext_pad_len; 12355 uint8_t *plaintext, *auth_tag; 12356 12357 struct crypto_testsuite_params *ts_params = &testsuite_params; 12358 struct crypto_unittest_params *ut_params = &unittest_params; 12359 struct rte_cryptodev_info dev_info; 12360 12361 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12362 uint64_t feat_flags = dev_info.feature_flags; 12363 12364 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12365 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12366 printf("Device doesn't support RAW data-path APIs.\n"); 12367 return TEST_SKIPPED; 12368 } 12369 12370 /* Verify the capabilities */ 12371 struct rte_cryptodev_sym_capability_idx cap_idx; 12372 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12373 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 12374 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12375 &cap_idx) == NULL) 12376 return TEST_SKIPPED; 12377 12378 if (MD5_HMAC_create_session(ts_params, ut_params, 12379 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 12380 return TEST_FAILED; 12381 12382 /* Generate Crypto op data structure */ 12383 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12384 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12385 TEST_ASSERT_NOT_NULL(ut_params->op, 12386 "Failed to allocate symmetric crypto operation struct"); 12387 12388 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 12389 16); 12390 12391 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 12392 return TEST_FAILED; 12393 12394 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12395 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12396 ut_params->op); 12397 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12398 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12399 ut_params->op, 0, 1, 0, 0); 12400 else 12401 TEST_ASSERT_NOT_NULL( 12402 process_crypto_request(ts_params->valid_devs[0], 12403 ut_params->op), 12404 "failed to process sym crypto op"); 12405 12406 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12407 "crypto op processing failed"); 12408 12409 if (ut_params->op->sym->m_dst) { 12410 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 12411 uint8_t *, plaintext_pad_len); 12412 } else { 12413 auth_tag = plaintext + plaintext_pad_len; 12414 } 12415 12416 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12417 auth_tag, 12418 test_case->auth_tag.data, 12419 test_case->auth_tag.len, 12420 "HMAC_MD5 generated tag not as expected"); 12421 12422 return TEST_SUCCESS; 12423 } 12424 12425 static int 12426 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 12427 { 12428 uint8_t *plaintext; 12429 12430 struct crypto_testsuite_params *ts_params = &testsuite_params; 12431 struct crypto_unittest_params *ut_params = &unittest_params; 12432 struct rte_cryptodev_info dev_info; 12433 12434 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12435 uint64_t feat_flags = dev_info.feature_flags; 12436 12437 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12438 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12439 printf("Device doesn't support RAW data-path APIs.\n"); 12440 return TEST_SKIPPED; 12441 } 12442 12443 /* Verify the capabilities */ 12444 struct rte_cryptodev_sym_capability_idx cap_idx; 12445 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12446 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 12447 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12448 &cap_idx) == NULL) 12449 return TEST_SKIPPED; 12450 12451 if (MD5_HMAC_create_session(ts_params, ut_params, 12452 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 12453 return TEST_FAILED; 12454 } 12455 12456 /* Generate Crypto op data structure */ 12457 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12458 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12459 TEST_ASSERT_NOT_NULL(ut_params->op, 12460 "Failed to allocate symmetric crypto operation struct"); 12461 12462 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 12463 return TEST_FAILED; 12464 12465 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12466 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12467 ut_params->op); 12468 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12469 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12470 ut_params->op, 0, 1, 0, 0); 12471 else 12472 TEST_ASSERT_NOT_NULL( 12473 process_crypto_request(ts_params->valid_devs[0], 12474 ut_params->op), 12475 "failed to process sym crypto op"); 12476 12477 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12478 "HMAC_MD5 crypto op processing failed"); 12479 12480 return TEST_SUCCESS; 12481 } 12482 12483 static int 12484 test_MD5_HMAC_generate_case_1(void) 12485 { 12486 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 12487 } 12488 12489 static int 12490 test_MD5_HMAC_verify_case_1(void) 12491 { 12492 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 12493 } 12494 12495 static int 12496 test_MD5_HMAC_generate_case_2(void) 12497 { 12498 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 12499 } 12500 12501 static int 12502 test_MD5_HMAC_verify_case_2(void) 12503 { 12504 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 12505 } 12506 12507 static int 12508 test_multi_session(void) 12509 { 12510 struct crypto_testsuite_params *ts_params = &testsuite_params; 12511 struct crypto_unittest_params *ut_params = &unittest_params; 12512 struct rte_cryptodev_info dev_info; 12513 void **sessions; 12514 uint16_t i; 12515 12516 /* Verify the capabilities */ 12517 struct rte_cryptodev_sym_capability_idx cap_idx; 12518 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12519 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 12520 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12521 &cap_idx) == NULL) 12522 return TEST_SKIPPED; 12523 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12524 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 12525 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12526 &cap_idx) == NULL) 12527 return TEST_SKIPPED; 12528 12529 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 12530 aes_cbc_key, hmac_sha512_key); 12531 12532 12533 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12534 12535 sessions = rte_malloc(NULL, 12536 sizeof(void *) * 12537 (MAX_NB_SESSIONS + 1), 0); 12538 12539 /* Create multiple crypto sessions*/ 12540 for (i = 0; i < MAX_NB_SESSIONS; i++) { 12541 sessions[i] = rte_cryptodev_sym_session_create( 12542 ts_params->valid_devs[0], &ut_params->auth_xform, 12543 ts_params->session_mpool); 12544 if (sessions[i] == NULL && rte_errno == ENOTSUP) 12545 return TEST_SKIPPED; 12546 12547 TEST_ASSERT_NOT_NULL(sessions[i], 12548 "Session creation failed at session number %u", 12549 i); 12550 /* Attempt to send a request on each session */ 12551 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform( 12552 sessions[i], 12553 ut_params, 12554 ts_params, 12555 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 12556 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 12557 aes_cbc_iv), 12558 "Failed to perform decrypt on request number %u.", i); 12559 /* free crypto operation structure */ 12560 rte_crypto_op_free(ut_params->op); 12561 12562 /* 12563 * free mbuf - both obuf and ibuf are usually the same, 12564 * so check if they point at the same address is necessary, 12565 * to avoid freeing the mbuf twice. 12566 */ 12567 if (ut_params->obuf) { 12568 rte_pktmbuf_free(ut_params->obuf); 12569 if (ut_params->ibuf == ut_params->obuf) 12570 ut_params->ibuf = 0; 12571 ut_params->obuf = 0; 12572 } 12573 if (ut_params->ibuf) { 12574 rte_pktmbuf_free(ut_params->ibuf); 12575 ut_params->ibuf = 0; 12576 } 12577 } 12578 12579 for (i = 0; i < MAX_NB_SESSIONS; i++) { 12580 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 12581 sessions[i]); 12582 } 12583 12584 rte_free(sessions); 12585 12586 return TEST_SUCCESS; 12587 } 12588 12589 struct multi_session_params { 12590 struct crypto_unittest_params ut_params; 12591 uint8_t *cipher_key; 12592 uint8_t *hmac_key; 12593 const uint8_t *cipher; 12594 const uint8_t *digest; 12595 uint8_t *iv; 12596 }; 12597 12598 #define MB_SESSION_NUMBER 3 12599 12600 static int 12601 test_multi_session_random_usage(void) 12602 { 12603 struct crypto_testsuite_params *ts_params = &testsuite_params; 12604 struct rte_cryptodev_info dev_info; 12605 void **sessions; 12606 uint32_t i, j; 12607 struct multi_session_params ut_paramz[] = { 12608 12609 { 12610 .cipher_key = ms_aes_cbc_key0, 12611 .hmac_key = ms_hmac_key0, 12612 .cipher = ms_aes_cbc_cipher0, 12613 .digest = ms_hmac_digest0, 12614 .iv = ms_aes_cbc_iv0 12615 }, 12616 { 12617 .cipher_key = ms_aes_cbc_key1, 12618 .hmac_key = ms_hmac_key1, 12619 .cipher = ms_aes_cbc_cipher1, 12620 .digest = ms_hmac_digest1, 12621 .iv = ms_aes_cbc_iv1 12622 }, 12623 { 12624 .cipher_key = ms_aes_cbc_key2, 12625 .hmac_key = ms_hmac_key2, 12626 .cipher = ms_aes_cbc_cipher2, 12627 .digest = ms_hmac_digest2, 12628 .iv = ms_aes_cbc_iv2 12629 }, 12630 12631 }; 12632 12633 /* Verify the capabilities */ 12634 struct rte_cryptodev_sym_capability_idx cap_idx; 12635 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12636 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 12637 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12638 &cap_idx) == NULL) 12639 return TEST_SKIPPED; 12640 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12641 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 12642 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12643 &cap_idx) == NULL) 12644 return TEST_SKIPPED; 12645 12646 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12647 12648 sessions = rte_malloc(NULL, (sizeof(void *) 12649 * MAX_NB_SESSIONS) + 1, 0); 12650 12651 for (i = 0; i < MB_SESSION_NUMBER; i++) { 12652 12653 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params, 12654 sizeof(struct crypto_unittest_params)); 12655 12656 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 12657 &ut_paramz[i].ut_params, 12658 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 12659 12660 /* Create multiple crypto sessions*/ 12661 sessions[i] = rte_cryptodev_sym_session_create( 12662 ts_params->valid_devs[0], 12663 &ut_paramz[i].ut_params.auth_xform, 12664 ts_params->session_mpool); 12665 if (sessions[i] == NULL && rte_errno == ENOTSUP) 12666 return TEST_SKIPPED; 12667 12668 TEST_ASSERT_NOT_NULL(sessions[i], 12669 "Session creation failed at session number %u", 12670 i); 12671 } 12672 12673 srand(time(NULL)); 12674 for (i = 0; i < 40000; i++) { 12675 12676 j = rand() % MB_SESSION_NUMBER; 12677 12678 TEST_ASSERT_SUCCESS( 12679 test_AES_CBC_HMAC_SHA512_decrypt_perform( 12680 sessions[j], 12681 &ut_paramz[j].ut_params, 12682 ts_params, ut_paramz[j].cipher, 12683 ut_paramz[j].digest, 12684 ut_paramz[j].iv), 12685 "Failed to perform decrypt on request number %u.", i); 12686 12687 rte_crypto_op_free(ut_paramz[j].ut_params.op); 12688 12689 /* 12690 * free mbuf - both obuf and ibuf are usually the same, 12691 * so check if they point at the same address is necessary, 12692 * to avoid freeing the mbuf twice. 12693 */ 12694 if (ut_paramz[j].ut_params.obuf) { 12695 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 12696 if (ut_paramz[j].ut_params.ibuf 12697 == ut_paramz[j].ut_params.obuf) 12698 ut_paramz[j].ut_params.ibuf = 0; 12699 ut_paramz[j].ut_params.obuf = 0; 12700 } 12701 if (ut_paramz[j].ut_params.ibuf) { 12702 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 12703 ut_paramz[j].ut_params.ibuf = 0; 12704 } 12705 } 12706 12707 for (i = 0; i < MB_SESSION_NUMBER; i++) { 12708 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 12709 sessions[i]); 12710 } 12711 12712 rte_free(sessions); 12713 12714 return TEST_SUCCESS; 12715 } 12716 12717 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab, 12718 0xab, 0xab, 0xab, 0xab, 12719 0xab, 0xab, 0xab, 0xab, 12720 0xab, 0xab, 0xab, 0xab}; 12721 12722 static int 12723 test_null_invalid_operation(void) 12724 { 12725 struct crypto_testsuite_params *ts_params = &testsuite_params; 12726 struct crypto_unittest_params *ut_params = &unittest_params; 12727 12728 /* This test is for NULL PMD only */ 12729 if (gbl_driver_id != rte_cryptodev_driver_id_get( 12730 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 12731 return TEST_SKIPPED; 12732 12733 /* Setup Cipher Parameters */ 12734 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12735 ut_params->cipher_xform.next = NULL; 12736 12737 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 12738 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 12739 12740 /* Create Crypto session*/ 12741 ut_params->sess = rte_cryptodev_sym_session_create( 12742 ts_params->valid_devs[0], &ut_params->cipher_xform, 12743 ts_params->session_mpool); 12744 TEST_ASSERT(ut_params->sess == NULL, 12745 "Session creation succeeded unexpectedly"); 12746 12747 /* Setup HMAC Parameters */ 12748 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12749 ut_params->auth_xform.next = NULL; 12750 12751 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 12752 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 12753 12754 /* Create Crypto session*/ 12755 ut_params->sess = rte_cryptodev_sym_session_create( 12756 ts_params->valid_devs[0], &ut_params->auth_xform, 12757 ts_params->session_mpool); 12758 TEST_ASSERT(ut_params->sess == NULL, 12759 "Session creation succeeded unexpectedly"); 12760 12761 return TEST_SUCCESS; 12762 } 12763 12764 12765 #define NULL_BURST_LENGTH (32) 12766 12767 static int 12768 test_null_burst_operation(void) 12769 { 12770 struct crypto_testsuite_params *ts_params = &testsuite_params; 12771 struct crypto_unittest_params *ut_params = &unittest_params; 12772 12773 unsigned i, burst_len = NULL_BURST_LENGTH; 12774 12775 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 12776 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 12777 12778 /* This test is for NULL PMD only */ 12779 if (gbl_driver_id != rte_cryptodev_driver_id_get( 12780 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 12781 return TEST_SKIPPED; 12782 12783 /* Setup Cipher Parameters */ 12784 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12785 ut_params->cipher_xform.next = &ut_params->auth_xform; 12786 12787 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 12788 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 12789 12790 /* Setup HMAC Parameters */ 12791 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12792 ut_params->auth_xform.next = NULL; 12793 12794 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 12795 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 12796 12797 /* Create Crypto session*/ 12798 ut_params->sess = rte_cryptodev_sym_session_create( 12799 ts_params->valid_devs[0], 12800 &ut_params->auth_xform, 12801 ts_params->session_mpool); 12802 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 12803 return TEST_SKIPPED; 12804 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12805 12806 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 12807 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 12808 burst_len, "failed to generate burst of crypto ops"); 12809 12810 /* Generate an operation for each mbuf in burst */ 12811 for (i = 0; i < burst_len; i++) { 12812 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12813 12814 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 12815 12816 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 12817 sizeof(unsigned)); 12818 *data = i; 12819 12820 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 12821 12822 burst[i]->sym->m_src = m; 12823 } 12824 12825 /* Process crypto operation */ 12826 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 12827 0, burst, burst_len), 12828 burst_len, 12829 "Error enqueuing burst"); 12830 12831 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 12832 0, burst_dequeued, burst_len), 12833 burst_len, 12834 "Error dequeuing burst"); 12835 12836 12837 for (i = 0; i < burst_len; i++) { 12838 TEST_ASSERT_EQUAL( 12839 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 12840 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 12841 uint32_t *), 12842 "data not as expected"); 12843 12844 rte_pktmbuf_free(burst[i]->sym->m_src); 12845 rte_crypto_op_free(burst[i]); 12846 } 12847 12848 return TEST_SUCCESS; 12849 } 12850 12851 static uint16_t 12852 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 12853 uint16_t nb_ops, void *user_param) 12854 { 12855 RTE_SET_USED(dev_id); 12856 RTE_SET_USED(qp_id); 12857 RTE_SET_USED(ops); 12858 RTE_SET_USED(user_param); 12859 12860 printf("crypto enqueue callback called\n"); 12861 return nb_ops; 12862 } 12863 12864 static uint16_t 12865 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 12866 uint16_t nb_ops, void *user_param) 12867 { 12868 RTE_SET_USED(dev_id); 12869 RTE_SET_USED(qp_id); 12870 RTE_SET_USED(ops); 12871 RTE_SET_USED(user_param); 12872 12873 printf("crypto dequeue callback called\n"); 12874 return nb_ops; 12875 } 12876 12877 /* 12878 * Thread using enqueue/dequeue callback with RCU. 12879 */ 12880 static int 12881 test_enqdeq_callback_thread(void *arg) 12882 { 12883 RTE_SET_USED(arg); 12884 /* DP thread calls rte_cryptodev_enqueue_burst()/ 12885 * rte_cryptodev_dequeue_burst() and invokes callback. 12886 */ 12887 test_null_burst_operation(); 12888 return 0; 12889 } 12890 12891 static int 12892 test_enq_callback_setup(void) 12893 { 12894 struct crypto_testsuite_params *ts_params = &testsuite_params; 12895 struct rte_cryptodev_info dev_info; 12896 struct rte_cryptodev_qp_conf qp_conf = { 12897 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 12898 }; 12899 12900 struct rte_cryptodev_cb *cb; 12901 uint16_t qp_id = 0; 12902 12903 /* Stop the device in case it's started so it can be configured */ 12904 rte_cryptodev_stop(ts_params->valid_devs[0]); 12905 12906 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12907 12908 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 12909 &ts_params->conf), 12910 "Failed to configure cryptodev %u", 12911 ts_params->valid_devs[0]); 12912 12913 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 12914 qp_conf.mp_session = ts_params->session_mpool; 12915 12916 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 12917 ts_params->valid_devs[0], qp_id, &qp_conf, 12918 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 12919 "Failed test for " 12920 "rte_cryptodev_queue_pair_setup: num_inflights " 12921 "%u on qp %u on cryptodev %u", 12922 qp_conf.nb_descriptors, qp_id, 12923 ts_params->valid_devs[0]); 12924 12925 /* Test with invalid crypto device */ 12926 cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS, 12927 qp_id, test_enq_callback, NULL); 12928 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12929 "cryptodev %u did not fail", 12930 qp_id, RTE_CRYPTO_MAX_DEVS); 12931 12932 /* Test with invalid queue pair */ 12933 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 12934 dev_info.max_nb_queue_pairs + 1, 12935 test_enq_callback, NULL); 12936 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12937 "cryptodev %u did not fail", 12938 dev_info.max_nb_queue_pairs + 1, 12939 ts_params->valid_devs[0]); 12940 12941 /* Test with NULL callback */ 12942 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 12943 qp_id, NULL, NULL); 12944 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12945 "cryptodev %u did not fail", 12946 qp_id, ts_params->valid_devs[0]); 12947 12948 /* Test with valid configuration */ 12949 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 12950 qp_id, test_enq_callback, NULL); 12951 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 12952 "qp %u on cryptodev %u", 12953 qp_id, ts_params->valid_devs[0]); 12954 12955 rte_cryptodev_start(ts_params->valid_devs[0]); 12956 12957 /* Launch a thread */ 12958 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 12959 rte_get_next_lcore(-1, 1, 0)); 12960 12961 /* Wait until reader exited. */ 12962 rte_eal_mp_wait_lcore(); 12963 12964 /* Test with invalid crypto device */ 12965 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 12966 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 12967 "Expected call to fail as crypto device is invalid"); 12968 12969 /* Test with invalid queue pair */ 12970 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 12971 ts_params->valid_devs[0], 12972 dev_info.max_nb_queue_pairs + 1, cb), 12973 "Expected call to fail as queue pair is invalid"); 12974 12975 /* Test with NULL callback */ 12976 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 12977 ts_params->valid_devs[0], qp_id, NULL), 12978 "Expected call to fail as callback is NULL"); 12979 12980 /* Test with valid configuration */ 12981 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback( 12982 ts_params->valid_devs[0], qp_id, cb), 12983 "Failed test to remove callback on " 12984 "qp %u on cryptodev %u", 12985 qp_id, ts_params->valid_devs[0]); 12986 12987 return TEST_SUCCESS; 12988 } 12989 12990 static int 12991 test_deq_callback_setup(void) 12992 { 12993 struct crypto_testsuite_params *ts_params = &testsuite_params; 12994 struct rte_cryptodev_info dev_info; 12995 struct rte_cryptodev_qp_conf qp_conf = { 12996 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 12997 }; 12998 12999 struct rte_cryptodev_cb *cb; 13000 uint16_t qp_id = 0; 13001 13002 /* Stop the device in case it's started so it can be configured */ 13003 rte_cryptodev_stop(ts_params->valid_devs[0]); 13004 13005 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13006 13007 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 13008 &ts_params->conf), 13009 "Failed to configure cryptodev %u", 13010 ts_params->valid_devs[0]); 13011 13012 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 13013 qp_conf.mp_session = ts_params->session_mpool; 13014 13015 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 13016 ts_params->valid_devs[0], qp_id, &qp_conf, 13017 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 13018 "Failed test for " 13019 "rte_cryptodev_queue_pair_setup: num_inflights " 13020 "%u on qp %u on cryptodev %u", 13021 qp_conf.nb_descriptors, qp_id, 13022 ts_params->valid_devs[0]); 13023 13024 /* Test with invalid crypto device */ 13025 cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS, 13026 qp_id, test_deq_callback, NULL); 13027 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 13028 "cryptodev %u did not fail", 13029 qp_id, RTE_CRYPTO_MAX_DEVS); 13030 13031 /* Test with invalid queue pair */ 13032 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 13033 dev_info.max_nb_queue_pairs + 1, 13034 test_deq_callback, NULL); 13035 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 13036 "cryptodev %u did not fail", 13037 dev_info.max_nb_queue_pairs + 1, 13038 ts_params->valid_devs[0]); 13039 13040 /* Test with NULL callback */ 13041 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 13042 qp_id, NULL, NULL); 13043 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 13044 "cryptodev %u did not fail", 13045 qp_id, ts_params->valid_devs[0]); 13046 13047 /* Test with valid configuration */ 13048 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 13049 qp_id, test_deq_callback, NULL); 13050 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 13051 "qp %u on cryptodev %u", 13052 qp_id, ts_params->valid_devs[0]); 13053 13054 rte_cryptodev_start(ts_params->valid_devs[0]); 13055 13056 /* Launch a thread */ 13057 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 13058 rte_get_next_lcore(-1, 1, 0)); 13059 13060 /* Wait until reader exited. */ 13061 rte_eal_mp_wait_lcore(); 13062 13063 /* Test with invalid crypto device */ 13064 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 13065 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 13066 "Expected call to fail as crypto device is invalid"); 13067 13068 /* Test with invalid queue pair */ 13069 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 13070 ts_params->valid_devs[0], 13071 dev_info.max_nb_queue_pairs + 1, cb), 13072 "Expected call to fail as queue pair is invalid"); 13073 13074 /* Test with NULL callback */ 13075 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 13076 ts_params->valid_devs[0], qp_id, NULL), 13077 "Expected call to fail as callback is NULL"); 13078 13079 /* Test with valid configuration */ 13080 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback( 13081 ts_params->valid_devs[0], qp_id, cb), 13082 "Failed test to remove callback on " 13083 "qp %u on cryptodev %u", 13084 qp_id, ts_params->valid_devs[0]); 13085 13086 return TEST_SUCCESS; 13087 } 13088 13089 static void 13090 generate_gmac_large_plaintext(uint8_t *data) 13091 { 13092 uint16_t i; 13093 13094 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 13095 memcpy(&data[i], &data[0], 32); 13096 } 13097 13098 static int 13099 create_gmac_operation(enum rte_crypto_auth_operation op, 13100 const struct gmac_test_data *tdata) 13101 { 13102 struct crypto_testsuite_params *ts_params = &testsuite_params; 13103 struct crypto_unittest_params *ut_params = &unittest_params; 13104 struct rte_crypto_sym_op *sym_op; 13105 13106 uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 13107 13108 /* Generate Crypto op data structure */ 13109 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13110 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13111 TEST_ASSERT_NOT_NULL(ut_params->op, 13112 "Failed to allocate symmetric crypto operation struct"); 13113 13114 sym_op = ut_params->op->sym; 13115 13116 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 13117 ut_params->ibuf, tdata->gmac_tag.len); 13118 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13119 "no room to append digest"); 13120 13121 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 13122 ut_params->ibuf, plaintext_pad_len); 13123 13124 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 13125 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 13126 tdata->gmac_tag.len); 13127 debug_hexdump(stdout, "digest:", 13128 sym_op->auth.digest.data, 13129 tdata->gmac_tag.len); 13130 } 13131 13132 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 13133 uint8_t *, IV_OFFSET); 13134 13135 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 13136 13137 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 13138 13139 sym_op->cipher.data.length = 0; 13140 sym_op->cipher.data.offset = 0; 13141 13142 sym_op->auth.data.offset = 0; 13143 sym_op->auth.data.length = tdata->plaintext.len; 13144 13145 return 0; 13146 } 13147 13148 static int 13149 create_gmac_operation_sgl(enum rte_crypto_auth_operation op, 13150 const struct gmac_test_data *tdata, 13151 void *digest_mem, uint64_t digest_phys) 13152 { 13153 struct crypto_testsuite_params *ts_params = &testsuite_params; 13154 struct crypto_unittest_params *ut_params = &unittest_params; 13155 struct rte_crypto_sym_op *sym_op; 13156 13157 /* Generate Crypto op data structure */ 13158 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13159 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13160 TEST_ASSERT_NOT_NULL(ut_params->op, 13161 "Failed to allocate symmetric crypto operation struct"); 13162 13163 sym_op = ut_params->op->sym; 13164 13165 sym_op->auth.digest.data = digest_mem; 13166 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13167 "no room to append digest"); 13168 13169 sym_op->auth.digest.phys_addr = digest_phys; 13170 13171 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 13172 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 13173 tdata->gmac_tag.len); 13174 debug_hexdump(stdout, "digest:", 13175 sym_op->auth.digest.data, 13176 tdata->gmac_tag.len); 13177 } 13178 13179 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 13180 uint8_t *, IV_OFFSET); 13181 13182 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 13183 13184 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 13185 13186 sym_op->cipher.data.length = 0; 13187 sym_op->cipher.data.offset = 0; 13188 13189 sym_op->auth.data.offset = 0; 13190 sym_op->auth.data.length = tdata->plaintext.len; 13191 13192 return 0; 13193 } 13194 13195 static int create_gmac_session(uint8_t dev_id, 13196 const struct gmac_test_data *tdata, 13197 enum rte_crypto_auth_operation auth_op) 13198 { 13199 uint8_t auth_key[tdata->key.len]; 13200 13201 struct crypto_testsuite_params *ts_params = &testsuite_params; 13202 struct crypto_unittest_params *ut_params = &unittest_params; 13203 13204 memcpy(auth_key, tdata->key.data, tdata->key.len); 13205 13206 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13207 ut_params->auth_xform.next = NULL; 13208 13209 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 13210 ut_params->auth_xform.auth.op = auth_op; 13211 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 13212 ut_params->auth_xform.auth.key.length = tdata->key.len; 13213 ut_params->auth_xform.auth.key.data = auth_key; 13214 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 13215 ut_params->auth_xform.auth.iv.length = tdata->iv.len; 13216 13217 13218 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 13219 &ut_params->auth_xform, ts_params->session_mpool); 13220 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 13221 return TEST_SKIPPED; 13222 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13223 13224 return 0; 13225 } 13226 13227 static int 13228 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 13229 { 13230 struct crypto_testsuite_params *ts_params = &testsuite_params; 13231 struct crypto_unittest_params *ut_params = &unittest_params; 13232 struct rte_cryptodev_info dev_info; 13233 13234 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13235 uint64_t feat_flags = dev_info.feature_flags; 13236 13237 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13238 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13239 printf("Device doesn't support RAW data-path APIs.\n"); 13240 return TEST_SKIPPED; 13241 } 13242 13243 int retval; 13244 13245 uint8_t *auth_tag, *plaintext; 13246 uint16_t plaintext_pad_len; 13247 13248 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 13249 "No GMAC length in the source data"); 13250 13251 /* Verify the capabilities */ 13252 struct rte_cryptodev_sym_capability_idx cap_idx; 13253 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13254 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 13255 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13256 &cap_idx) == NULL) 13257 return TEST_SKIPPED; 13258 13259 retval = create_gmac_session(ts_params->valid_devs[0], 13260 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 13261 13262 if (retval == -ENOTSUP) 13263 return TEST_SKIPPED; 13264 if (retval < 0) 13265 return retval; 13266 13267 if (tdata->plaintext.len > MBUF_SIZE) 13268 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 13269 else 13270 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13271 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13272 "Failed to allocate input buffer in mempool"); 13273 13274 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13275 rte_pktmbuf_tailroom(ut_params->ibuf)); 13276 13277 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 13278 /* 13279 * Runtime generate the large plain text instead of use hard code 13280 * plain text vector. It is done to avoid create huge source file 13281 * with the test vector. 13282 */ 13283 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 13284 generate_gmac_large_plaintext(tdata->plaintext.data); 13285 13286 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13287 plaintext_pad_len); 13288 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13289 13290 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 13291 debug_hexdump(stdout, "plaintext:", plaintext, 13292 tdata->plaintext.len); 13293 13294 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 13295 tdata); 13296 13297 if (retval < 0) 13298 return retval; 13299 13300 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13301 13302 ut_params->op->sym->m_src = ut_params->ibuf; 13303 13304 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13305 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13306 ut_params->op); 13307 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13308 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13309 ut_params->op, 0, 1, 0, 0); 13310 else 13311 TEST_ASSERT_NOT_NULL( 13312 process_crypto_request(ts_params->valid_devs[0], 13313 ut_params->op), "failed to process sym crypto op"); 13314 13315 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13316 "crypto op processing failed"); 13317 13318 if (ut_params->op->sym->m_dst) { 13319 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 13320 uint8_t *, plaintext_pad_len); 13321 } else { 13322 auth_tag = plaintext + plaintext_pad_len; 13323 } 13324 13325 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 13326 13327 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13328 auth_tag, 13329 tdata->gmac_tag.data, 13330 tdata->gmac_tag.len, 13331 "GMAC Generated auth tag not as expected"); 13332 13333 return 0; 13334 } 13335 13336 static int 13337 test_AES_GMAC_authentication_test_case_1(void) 13338 { 13339 return test_AES_GMAC_authentication(&gmac_test_case_1); 13340 } 13341 13342 static int 13343 test_AES_GMAC_authentication_test_case_2(void) 13344 { 13345 return test_AES_GMAC_authentication(&gmac_test_case_2); 13346 } 13347 13348 static int 13349 test_AES_GMAC_authentication_test_case_3(void) 13350 { 13351 return test_AES_GMAC_authentication(&gmac_test_case_3); 13352 } 13353 13354 static int 13355 test_AES_GMAC_authentication_test_case_4(void) 13356 { 13357 return test_AES_GMAC_authentication(&gmac_test_case_4); 13358 } 13359 13360 static int 13361 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 13362 { 13363 struct crypto_testsuite_params *ts_params = &testsuite_params; 13364 struct crypto_unittest_params *ut_params = &unittest_params; 13365 int retval; 13366 uint32_t plaintext_pad_len; 13367 uint8_t *plaintext; 13368 struct rte_cryptodev_info dev_info; 13369 13370 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13371 uint64_t feat_flags = dev_info.feature_flags; 13372 13373 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13374 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13375 printf("Device doesn't support RAW data-path APIs.\n"); 13376 return TEST_SKIPPED; 13377 } 13378 13379 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 13380 "No GMAC length in the source data"); 13381 13382 /* Verify the capabilities */ 13383 struct rte_cryptodev_sym_capability_idx cap_idx; 13384 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13385 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 13386 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13387 &cap_idx) == NULL) 13388 return TEST_SKIPPED; 13389 13390 retval = create_gmac_session(ts_params->valid_devs[0], 13391 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 13392 13393 if (retval == -ENOTSUP) 13394 return TEST_SKIPPED; 13395 if (retval < 0) 13396 return retval; 13397 13398 if (tdata->plaintext.len > MBUF_SIZE) 13399 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 13400 else 13401 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13402 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13403 "Failed to allocate input buffer in mempool"); 13404 13405 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13406 rte_pktmbuf_tailroom(ut_params->ibuf)); 13407 13408 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 13409 13410 /* 13411 * Runtime generate the large plain text instead of use hard code 13412 * plain text vector. It is done to avoid create huge source file 13413 * with the test vector. 13414 */ 13415 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 13416 generate_gmac_large_plaintext(tdata->plaintext.data); 13417 13418 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13419 plaintext_pad_len); 13420 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13421 13422 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 13423 debug_hexdump(stdout, "plaintext:", plaintext, 13424 tdata->plaintext.len); 13425 13426 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 13427 tdata); 13428 13429 if (retval < 0) 13430 return retval; 13431 13432 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13433 13434 ut_params->op->sym->m_src = ut_params->ibuf; 13435 13436 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13437 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13438 ut_params->op); 13439 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13440 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13441 ut_params->op, 0, 1, 0, 0); 13442 else 13443 TEST_ASSERT_NOT_NULL( 13444 process_crypto_request(ts_params->valid_devs[0], 13445 ut_params->op), "failed to process sym crypto op"); 13446 13447 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13448 "crypto op processing failed"); 13449 13450 return 0; 13451 13452 } 13453 13454 static int 13455 test_AES_GMAC_authentication_verify_test_case_1(void) 13456 { 13457 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 13458 } 13459 13460 static int 13461 test_AES_GMAC_authentication_verify_test_case_2(void) 13462 { 13463 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 13464 } 13465 13466 static int 13467 test_AES_GMAC_authentication_verify_test_case_3(void) 13468 { 13469 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 13470 } 13471 13472 static int 13473 test_AES_GMAC_authentication_verify_test_case_4(void) 13474 { 13475 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 13476 } 13477 13478 static int 13479 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata, 13480 uint32_t fragsz) 13481 { 13482 struct crypto_testsuite_params *ts_params = &testsuite_params; 13483 struct crypto_unittest_params *ut_params = &unittest_params; 13484 struct rte_cryptodev_info dev_info; 13485 uint64_t feature_flags; 13486 unsigned int trn_data = 0; 13487 void *digest_mem = NULL; 13488 uint32_t segs = 1; 13489 unsigned int to_trn = 0; 13490 struct rte_mbuf *buf = NULL; 13491 uint8_t *auth_tag, *plaintext; 13492 int retval; 13493 13494 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 13495 "No GMAC length in the source data"); 13496 13497 /* Verify the capabilities */ 13498 struct rte_cryptodev_sym_capability_idx cap_idx; 13499 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13500 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 13501 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13502 &cap_idx) == NULL) 13503 return TEST_SKIPPED; 13504 13505 /* Check for any input SGL support */ 13506 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13507 feature_flags = dev_info.feature_flags; 13508 13509 if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) || 13510 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) || 13511 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))) 13512 return TEST_SKIPPED; 13513 13514 if (fragsz > tdata->plaintext.len) 13515 fragsz = tdata->plaintext.len; 13516 13517 uint16_t plaintext_len = fragsz; 13518 13519 retval = create_gmac_session(ts_params->valid_devs[0], 13520 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 13521 13522 if (retval == -ENOTSUP) 13523 return TEST_SKIPPED; 13524 if (retval < 0) 13525 return retval; 13526 13527 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13528 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13529 "Failed to allocate input buffer in mempool"); 13530 13531 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13532 rte_pktmbuf_tailroom(ut_params->ibuf)); 13533 13534 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13535 plaintext_len); 13536 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13537 13538 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 13539 13540 trn_data += plaintext_len; 13541 13542 buf = ut_params->ibuf; 13543 13544 /* 13545 * Loop until no more fragments 13546 */ 13547 13548 while (trn_data < tdata->plaintext.len) { 13549 ++segs; 13550 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 13551 (tdata->plaintext.len - trn_data) : fragsz; 13552 13553 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13554 buf = buf->next; 13555 13556 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 13557 rte_pktmbuf_tailroom(buf)); 13558 13559 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 13560 to_trn); 13561 13562 memcpy(plaintext, tdata->plaintext.data + trn_data, 13563 to_trn); 13564 trn_data += to_trn; 13565 if (trn_data == tdata->plaintext.len) 13566 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 13567 tdata->gmac_tag.len); 13568 } 13569 ut_params->ibuf->nb_segs = segs; 13570 13571 /* 13572 * Place digest at the end of the last buffer 13573 */ 13574 uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn; 13575 13576 if (!digest_mem) { 13577 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13578 + tdata->gmac_tag.len); 13579 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 13580 tdata->plaintext.len); 13581 } 13582 13583 retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE, 13584 tdata, digest_mem, digest_phys); 13585 13586 if (retval < 0) 13587 return retval; 13588 13589 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13590 13591 ut_params->op->sym->m_src = ut_params->ibuf; 13592 13593 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13594 return TEST_SKIPPED; 13595 13596 TEST_ASSERT_NOT_NULL( 13597 process_crypto_request(ts_params->valid_devs[0], 13598 ut_params->op), "failed to process sym crypto op"); 13599 13600 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13601 "crypto op processing failed"); 13602 13603 auth_tag = digest_mem; 13604 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 13605 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13606 auth_tag, 13607 tdata->gmac_tag.data, 13608 tdata->gmac_tag.len, 13609 "GMAC Generated auth tag not as expected"); 13610 13611 return 0; 13612 } 13613 13614 /* Segment size not multiple of block size (16B) */ 13615 static int 13616 test_AES_GMAC_authentication_SGL_40B(void) 13617 { 13618 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40); 13619 } 13620 13621 static int 13622 test_AES_GMAC_authentication_SGL_80B(void) 13623 { 13624 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80); 13625 } 13626 13627 static int 13628 test_AES_GMAC_authentication_SGL_2048B(void) 13629 { 13630 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048); 13631 } 13632 13633 /* Segment size not multiple of block size (16B) */ 13634 static int 13635 test_AES_GMAC_authentication_SGL_2047B(void) 13636 { 13637 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047); 13638 } 13639 13640 struct test_crypto_vector { 13641 enum rte_crypto_cipher_algorithm crypto_algo; 13642 unsigned int cipher_offset; 13643 unsigned int cipher_len; 13644 13645 struct { 13646 uint8_t data[64]; 13647 unsigned int len; 13648 } cipher_key; 13649 13650 struct { 13651 uint8_t data[64]; 13652 unsigned int len; 13653 } iv; 13654 13655 struct { 13656 const uint8_t *data; 13657 unsigned int len; 13658 } plaintext; 13659 13660 struct { 13661 const uint8_t *data; 13662 unsigned int len; 13663 } ciphertext; 13664 13665 enum rte_crypto_auth_algorithm auth_algo; 13666 unsigned int auth_offset; 13667 13668 struct { 13669 uint8_t data[128]; 13670 unsigned int len; 13671 } auth_key; 13672 13673 struct { 13674 const uint8_t *data; 13675 unsigned int len; 13676 } aad; 13677 13678 struct { 13679 uint8_t data[128]; 13680 unsigned int len; 13681 } digest; 13682 }; 13683 13684 static const struct test_crypto_vector 13685 hmac_sha1_test_crypto_vector = { 13686 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 13687 .plaintext = { 13688 .data = plaintext_hash, 13689 .len = 512 13690 }, 13691 .auth_key = { 13692 .data = { 13693 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 13694 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 13695 0xDE, 0xF4, 0xDE, 0xAD 13696 }, 13697 .len = 20 13698 }, 13699 .digest = { 13700 .data = { 13701 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 13702 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 13703 0x3F, 0x91, 0x64, 0x59 13704 }, 13705 .len = 20 13706 } 13707 }; 13708 13709 static const struct test_crypto_vector 13710 aes128_gmac_test_vector = { 13711 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 13712 .plaintext = { 13713 .data = plaintext_hash, 13714 .len = 512 13715 }, 13716 .iv = { 13717 .data = { 13718 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 13719 0x08, 0x09, 0x0A, 0x0B 13720 }, 13721 .len = 12 13722 }, 13723 .auth_key = { 13724 .data = { 13725 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 13726 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 13727 }, 13728 .len = 16 13729 }, 13730 .digest = { 13731 .data = { 13732 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 13733 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 13734 }, 13735 .len = 16 13736 } 13737 }; 13738 13739 static const struct test_crypto_vector 13740 aes128cbc_hmac_sha1_test_vector = { 13741 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 13742 .cipher_offset = 0, 13743 .cipher_len = 512, 13744 .cipher_key = { 13745 .data = { 13746 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 13747 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 13748 }, 13749 .len = 16 13750 }, 13751 .iv = { 13752 .data = { 13753 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 13754 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 13755 }, 13756 .len = 16 13757 }, 13758 .plaintext = { 13759 .data = plaintext_hash, 13760 .len = 512 13761 }, 13762 .ciphertext = { 13763 .data = ciphertext512_aes128cbc, 13764 .len = 512 13765 }, 13766 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 13767 .auth_offset = 0, 13768 .auth_key = { 13769 .data = { 13770 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 13771 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 13772 0xDE, 0xF4, 0xDE, 0xAD 13773 }, 13774 .len = 20 13775 }, 13776 .digest = { 13777 .data = { 13778 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 13779 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 13780 0x18, 0x8C, 0x1D, 0x32 13781 }, 13782 .len = 20 13783 } 13784 }; 13785 13786 static const struct test_crypto_vector 13787 aes128cbc_hmac_sha1_aad_test_vector = { 13788 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 13789 .cipher_offset = 8, 13790 .cipher_len = 496, 13791 .cipher_key = { 13792 .data = { 13793 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 13794 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 13795 }, 13796 .len = 16 13797 }, 13798 .iv = { 13799 .data = { 13800 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 13801 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 13802 }, 13803 .len = 16 13804 }, 13805 .plaintext = { 13806 .data = plaintext_hash, 13807 .len = 512 13808 }, 13809 .ciphertext = { 13810 .data = ciphertext512_aes128cbc_aad, 13811 .len = 512 13812 }, 13813 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 13814 .auth_offset = 0, 13815 .auth_key = { 13816 .data = { 13817 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 13818 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 13819 0xDE, 0xF4, 0xDE, 0xAD 13820 }, 13821 .len = 20 13822 }, 13823 .digest = { 13824 .data = { 13825 0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F, 13826 0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B, 13827 0x62, 0x0F, 0xFB, 0x10 13828 }, 13829 .len = 20 13830 } 13831 }; 13832 13833 static void 13834 data_corruption(uint8_t *data) 13835 { 13836 data[0] += 1; 13837 } 13838 13839 static void 13840 tag_corruption(uint8_t *data, unsigned int tag_offset) 13841 { 13842 data[tag_offset] += 1; 13843 } 13844 13845 static int 13846 create_auth_session(struct crypto_unittest_params *ut_params, 13847 uint8_t dev_id, 13848 const struct test_crypto_vector *reference, 13849 enum rte_crypto_auth_operation auth_op) 13850 { 13851 struct crypto_testsuite_params *ts_params = &testsuite_params; 13852 uint8_t auth_key[reference->auth_key.len + 1]; 13853 13854 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 13855 13856 /* Setup Authentication Parameters */ 13857 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13858 ut_params->auth_xform.auth.op = auth_op; 13859 ut_params->auth_xform.next = NULL; 13860 ut_params->auth_xform.auth.algo = reference->auth_algo; 13861 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 13862 ut_params->auth_xform.auth.key.data = auth_key; 13863 ut_params->auth_xform.auth.digest_length = reference->digest.len; 13864 13865 /* Create Crypto session*/ 13866 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 13867 &ut_params->auth_xform, 13868 ts_params->session_mpool); 13869 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 13870 return TEST_SKIPPED; 13871 13872 return 0; 13873 } 13874 13875 static int 13876 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 13877 uint8_t dev_id, 13878 const struct test_crypto_vector *reference, 13879 enum rte_crypto_auth_operation auth_op, 13880 enum rte_crypto_cipher_operation cipher_op) 13881 { 13882 struct crypto_testsuite_params *ts_params = &testsuite_params; 13883 uint8_t cipher_key[reference->cipher_key.len + 1]; 13884 uint8_t auth_key[reference->auth_key.len + 1]; 13885 13886 memcpy(cipher_key, reference->cipher_key.data, 13887 reference->cipher_key.len); 13888 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 13889 13890 /* Setup Authentication Parameters */ 13891 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13892 ut_params->auth_xform.auth.op = auth_op; 13893 ut_params->auth_xform.auth.algo = reference->auth_algo; 13894 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 13895 ut_params->auth_xform.auth.key.data = auth_key; 13896 ut_params->auth_xform.auth.digest_length = reference->digest.len; 13897 13898 if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) { 13899 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 13900 ut_params->auth_xform.auth.iv.length = reference->iv.len; 13901 } else { 13902 ut_params->auth_xform.next = &ut_params->cipher_xform; 13903 13904 /* Setup Cipher Parameters */ 13905 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13906 ut_params->cipher_xform.next = NULL; 13907 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 13908 ut_params->cipher_xform.cipher.op = cipher_op; 13909 ut_params->cipher_xform.cipher.key.data = cipher_key; 13910 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 13911 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 13912 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 13913 } 13914 13915 /* Create Crypto session*/ 13916 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 13917 &ut_params->auth_xform, 13918 ts_params->session_mpool); 13919 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 13920 return TEST_SKIPPED; 13921 13922 return 0; 13923 } 13924 13925 static int 13926 create_auth_operation(struct crypto_testsuite_params *ts_params, 13927 struct crypto_unittest_params *ut_params, 13928 const struct test_crypto_vector *reference, 13929 unsigned int auth_generate) 13930 { 13931 /* Generate Crypto op data structure */ 13932 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13933 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13934 TEST_ASSERT_NOT_NULL(ut_params->op, 13935 "Failed to allocate pktmbuf offload"); 13936 13937 /* Set crypto operation data parameters */ 13938 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13939 13940 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 13941 13942 /* set crypto operation source mbuf */ 13943 sym_op->m_src = ut_params->ibuf; 13944 13945 /* digest */ 13946 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 13947 ut_params->ibuf, reference->digest.len); 13948 13949 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13950 "no room to append auth tag"); 13951 13952 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 13953 ut_params->ibuf, reference->plaintext.len); 13954 13955 if (auth_generate) 13956 memset(sym_op->auth.digest.data, 0, reference->digest.len); 13957 else 13958 memcpy(sym_op->auth.digest.data, 13959 reference->digest.data, 13960 reference->digest.len); 13961 13962 debug_hexdump(stdout, "digest:", 13963 sym_op->auth.digest.data, 13964 reference->digest.len); 13965 13966 sym_op->auth.data.length = reference->plaintext.len; 13967 sym_op->auth.data.offset = 0; 13968 13969 return 0; 13970 } 13971 13972 static int 13973 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 13974 struct crypto_unittest_params *ut_params, 13975 const struct test_crypto_vector *reference, 13976 unsigned int auth_generate) 13977 { 13978 /* Generate Crypto op data structure */ 13979 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13980 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13981 TEST_ASSERT_NOT_NULL(ut_params->op, 13982 "Failed to allocate pktmbuf offload"); 13983 13984 /* Set crypto operation data parameters */ 13985 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13986 13987 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 13988 13989 /* set crypto operation source mbuf */ 13990 sym_op->m_src = ut_params->ibuf; 13991 13992 /* digest */ 13993 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 13994 ut_params->ibuf, reference->digest.len); 13995 13996 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13997 "no room to append auth tag"); 13998 13999 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 14000 ut_params->ibuf, reference->ciphertext.len); 14001 14002 if (auth_generate) 14003 memset(sym_op->auth.digest.data, 0, reference->digest.len); 14004 else 14005 memcpy(sym_op->auth.digest.data, 14006 reference->digest.data, 14007 reference->digest.len); 14008 14009 debug_hexdump(stdout, "digest:", 14010 sym_op->auth.digest.data, 14011 reference->digest.len); 14012 14013 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 14014 reference->iv.data, reference->iv.len); 14015 14016 sym_op->cipher.data.length = 0; 14017 sym_op->cipher.data.offset = 0; 14018 14019 sym_op->auth.data.length = reference->plaintext.len; 14020 sym_op->auth.data.offset = 0; 14021 14022 return 0; 14023 } 14024 14025 static int 14026 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 14027 struct crypto_unittest_params *ut_params, 14028 const struct test_crypto_vector *reference, 14029 unsigned int auth_generate) 14030 { 14031 /* Generate Crypto op data structure */ 14032 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 14033 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 14034 TEST_ASSERT_NOT_NULL(ut_params->op, 14035 "Failed to allocate pktmbuf offload"); 14036 14037 /* Set crypto operation data parameters */ 14038 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14039 14040 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 14041 14042 /* set crypto operation source mbuf */ 14043 sym_op->m_src = ut_params->ibuf; 14044 14045 /* digest */ 14046 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 14047 ut_params->ibuf, reference->digest.len); 14048 14049 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 14050 "no room to append auth tag"); 14051 14052 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 14053 ut_params->ibuf, reference->ciphertext.len); 14054 14055 if (auth_generate) 14056 memset(sym_op->auth.digest.data, 0, reference->digest.len); 14057 else 14058 memcpy(sym_op->auth.digest.data, 14059 reference->digest.data, 14060 reference->digest.len); 14061 14062 debug_hexdump(stdout, "digest:", 14063 sym_op->auth.digest.data, 14064 reference->digest.len); 14065 14066 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 14067 reference->iv.data, reference->iv.len); 14068 14069 sym_op->cipher.data.length = reference->cipher_len; 14070 sym_op->cipher.data.offset = reference->cipher_offset; 14071 14072 sym_op->auth.data.length = reference->plaintext.len; 14073 sym_op->auth.data.offset = reference->auth_offset; 14074 14075 return 0; 14076 } 14077 14078 static int 14079 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 14080 struct crypto_unittest_params *ut_params, 14081 const struct test_crypto_vector *reference) 14082 { 14083 return create_auth_operation(ts_params, ut_params, reference, 0); 14084 } 14085 14086 static int 14087 create_auth_verify_GMAC_operation( 14088 struct crypto_testsuite_params *ts_params, 14089 struct crypto_unittest_params *ut_params, 14090 const struct test_crypto_vector *reference) 14091 { 14092 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 14093 } 14094 14095 static int 14096 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params, 14097 struct crypto_unittest_params *ut_params, 14098 const struct test_crypto_vector *reference) 14099 { 14100 return create_cipher_auth_operation(ts_params, ut_params, reference, 0); 14101 } 14102 14103 static int 14104 test_authentication_verify_fail_when_data_corruption( 14105 struct crypto_testsuite_params *ts_params, 14106 struct crypto_unittest_params *ut_params, 14107 const struct test_crypto_vector *reference, 14108 unsigned int data_corrupted) 14109 { 14110 int retval; 14111 14112 uint8_t *plaintext; 14113 struct rte_cryptodev_info dev_info; 14114 14115 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14116 uint64_t feat_flags = dev_info.feature_flags; 14117 14118 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14119 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14120 printf("Device doesn't support RAW data-path APIs.\n"); 14121 return TEST_SKIPPED; 14122 } 14123 14124 /* Verify the capabilities */ 14125 struct rte_cryptodev_sym_capability_idx cap_idx; 14126 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14127 cap_idx.algo.auth = reference->auth_algo; 14128 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14129 &cap_idx) == NULL) 14130 return TEST_SKIPPED; 14131 14132 14133 /* Create session */ 14134 retval = create_auth_session(ut_params, 14135 ts_params->valid_devs[0], 14136 reference, 14137 RTE_CRYPTO_AUTH_OP_VERIFY); 14138 14139 if (retval == -ENOTSUP) 14140 return TEST_SKIPPED; 14141 if (retval < 0) 14142 return retval; 14143 14144 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14145 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14146 "Failed to allocate input buffer in mempool"); 14147 14148 /* clear mbuf payload */ 14149 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14150 rte_pktmbuf_tailroom(ut_params->ibuf)); 14151 14152 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14153 reference->plaintext.len); 14154 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14155 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 14156 14157 debug_hexdump(stdout, "plaintext:", plaintext, 14158 reference->plaintext.len); 14159 14160 /* Create operation */ 14161 retval = create_auth_verify_operation(ts_params, ut_params, reference); 14162 14163 if (retval < 0) 14164 return retval; 14165 14166 if (data_corrupted) 14167 data_corruption(plaintext); 14168 else 14169 tag_corruption(plaintext, reference->plaintext.len); 14170 14171 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 14172 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14173 ut_params->op); 14174 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 14175 RTE_CRYPTO_OP_STATUS_SUCCESS, 14176 "authentication not failed"); 14177 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14178 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 14179 ut_params->op, 0, 1, 0, 0); 14180 else { 14181 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 14182 ut_params->op); 14183 } 14184 if (ut_params->op == NULL) 14185 return 0; 14186 else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) 14187 return 0; 14188 14189 return -1; 14190 } 14191 14192 static int 14193 test_authentication_verify_GMAC_fail_when_corruption( 14194 struct crypto_testsuite_params *ts_params, 14195 struct crypto_unittest_params *ut_params, 14196 const struct test_crypto_vector *reference, 14197 unsigned int data_corrupted) 14198 { 14199 int retval; 14200 uint8_t *plaintext; 14201 struct rte_cryptodev_info dev_info; 14202 14203 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14204 uint64_t feat_flags = dev_info.feature_flags; 14205 14206 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14207 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14208 printf("Device doesn't support RAW data-path APIs.\n"); 14209 return TEST_SKIPPED; 14210 } 14211 14212 /* Verify the capabilities */ 14213 struct rte_cryptodev_sym_capability_idx cap_idx; 14214 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14215 cap_idx.algo.auth = reference->auth_algo; 14216 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14217 &cap_idx) == NULL) 14218 return TEST_SKIPPED; 14219 14220 /* Create session */ 14221 retval = create_auth_cipher_session(ut_params, 14222 ts_params->valid_devs[0], 14223 reference, 14224 RTE_CRYPTO_AUTH_OP_VERIFY, 14225 RTE_CRYPTO_CIPHER_OP_DECRYPT); 14226 if (retval < 0) 14227 return retval; 14228 14229 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14230 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14231 "Failed to allocate input buffer in mempool"); 14232 14233 /* clear mbuf payload */ 14234 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14235 rte_pktmbuf_tailroom(ut_params->ibuf)); 14236 14237 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14238 reference->plaintext.len); 14239 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14240 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 14241 14242 debug_hexdump(stdout, "plaintext:", plaintext, 14243 reference->plaintext.len); 14244 14245 /* Create operation */ 14246 retval = create_auth_verify_GMAC_operation(ts_params, 14247 ut_params, 14248 reference); 14249 14250 if (retval < 0) 14251 return retval; 14252 14253 if (data_corrupted) 14254 data_corruption(plaintext); 14255 else 14256 tag_corruption(plaintext, reference->aad.len); 14257 14258 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 14259 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14260 ut_params->op); 14261 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 14262 RTE_CRYPTO_OP_STATUS_SUCCESS, 14263 "authentication not failed"); 14264 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14265 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 14266 ut_params->op, 0, 1, 0, 0); 14267 else { 14268 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 14269 ut_params->op); 14270 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 14271 } 14272 14273 return 0; 14274 } 14275 14276 static int 14277 test_authenticated_decryption_fail_when_corruption( 14278 struct crypto_testsuite_params *ts_params, 14279 struct crypto_unittest_params *ut_params, 14280 const struct test_crypto_vector *reference, 14281 unsigned int data_corrupted) 14282 { 14283 int retval; 14284 14285 uint8_t *ciphertext; 14286 struct rte_cryptodev_info dev_info; 14287 14288 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14289 uint64_t feat_flags = dev_info.feature_flags; 14290 14291 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14292 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14293 printf("Device doesn't support RAW data-path APIs.\n"); 14294 return TEST_SKIPPED; 14295 } 14296 14297 /* Verify the capabilities */ 14298 struct rte_cryptodev_sym_capability_idx cap_idx; 14299 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14300 cap_idx.algo.auth = reference->auth_algo; 14301 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14302 &cap_idx) == NULL) 14303 return TEST_SKIPPED; 14304 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 14305 cap_idx.algo.cipher = reference->crypto_algo; 14306 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14307 &cap_idx) == NULL) 14308 return TEST_SKIPPED; 14309 14310 /* Create session */ 14311 retval = create_auth_cipher_session(ut_params, 14312 ts_params->valid_devs[0], 14313 reference, 14314 RTE_CRYPTO_AUTH_OP_VERIFY, 14315 RTE_CRYPTO_CIPHER_OP_DECRYPT); 14316 14317 if (retval == -ENOTSUP) 14318 return TEST_SKIPPED; 14319 if (retval < 0) 14320 return retval; 14321 14322 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14323 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14324 "Failed to allocate input buffer in mempool"); 14325 14326 /* clear mbuf payload */ 14327 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14328 rte_pktmbuf_tailroom(ut_params->ibuf)); 14329 14330 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14331 reference->ciphertext.len); 14332 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 14333 memcpy(ciphertext, reference->ciphertext.data, 14334 reference->ciphertext.len); 14335 14336 /* Create operation */ 14337 retval = create_cipher_auth_verify_operation(ts_params, 14338 ut_params, 14339 reference); 14340 14341 if (retval < 0) 14342 return retval; 14343 14344 if (data_corrupted) 14345 data_corruption(ciphertext); 14346 else 14347 tag_corruption(ciphertext, reference->ciphertext.len); 14348 14349 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 14350 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14351 ut_params->op); 14352 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 14353 RTE_CRYPTO_OP_STATUS_SUCCESS, 14354 "authentication not failed"); 14355 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14356 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 14357 ut_params->op, 1, 1, 0, 0); 14358 else { 14359 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 14360 ut_params->op); 14361 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 14362 } 14363 14364 return 0; 14365 } 14366 14367 static int 14368 test_authenticated_encrypt_with_esn( 14369 struct crypto_testsuite_params *ts_params, 14370 struct crypto_unittest_params *ut_params, 14371 const struct test_crypto_vector *reference) 14372 { 14373 int retval; 14374 14375 uint8_t *authciphertext, *plaintext, *auth_tag; 14376 uint16_t plaintext_pad_len; 14377 uint8_t cipher_key[reference->cipher_key.len + 1]; 14378 uint8_t auth_key[reference->auth_key.len + 1]; 14379 struct rte_cryptodev_info dev_info; 14380 14381 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14382 uint64_t feat_flags = dev_info.feature_flags; 14383 14384 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14385 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14386 printf("Device doesn't support RAW data-path APIs.\n"); 14387 return TEST_SKIPPED; 14388 } 14389 14390 /* Verify the capabilities */ 14391 struct rte_cryptodev_sym_capability_idx cap_idx; 14392 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14393 cap_idx.algo.auth = reference->auth_algo; 14394 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14395 &cap_idx) == NULL) 14396 return TEST_SKIPPED; 14397 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 14398 cap_idx.algo.cipher = reference->crypto_algo; 14399 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14400 &cap_idx) == NULL) 14401 return TEST_SKIPPED; 14402 14403 /* Create session */ 14404 memcpy(cipher_key, reference->cipher_key.data, 14405 reference->cipher_key.len); 14406 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 14407 14408 /* Setup Cipher Parameters */ 14409 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 14410 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 14411 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 14412 ut_params->cipher_xform.cipher.key.data = cipher_key; 14413 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 14414 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 14415 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 14416 14417 ut_params->cipher_xform.next = &ut_params->auth_xform; 14418 14419 /* Setup Authentication Parameters */ 14420 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14421 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 14422 ut_params->auth_xform.auth.algo = reference->auth_algo; 14423 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 14424 ut_params->auth_xform.auth.key.data = auth_key; 14425 ut_params->auth_xform.auth.digest_length = reference->digest.len; 14426 ut_params->auth_xform.next = NULL; 14427 14428 /* Create Crypto session*/ 14429 ut_params->sess = rte_cryptodev_sym_session_create( 14430 ts_params->valid_devs[0], &ut_params->cipher_xform, 14431 ts_params->session_mpool); 14432 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 14433 return TEST_SKIPPED; 14434 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 14435 14436 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14437 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14438 "Failed to allocate input buffer in mempool"); 14439 14440 /* clear mbuf payload */ 14441 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14442 rte_pktmbuf_tailroom(ut_params->ibuf)); 14443 14444 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14445 reference->plaintext.len); 14446 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14447 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 14448 14449 /* Create operation */ 14450 retval = create_cipher_auth_operation(ts_params, 14451 ut_params, 14452 reference, 0); 14453 14454 if (retval < 0) 14455 return retval; 14456 14457 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14458 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14459 ut_params->op); 14460 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14461 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 14462 ut_params->op, 1, 1, 0, 0); 14463 else 14464 ut_params->op = process_crypto_request( 14465 ts_params->valid_devs[0], ut_params->op); 14466 14467 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 14468 14469 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14470 "crypto op processing failed"); 14471 14472 plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16); 14473 14474 authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 14475 ut_params->op->sym->auth.data.offset); 14476 auth_tag = authciphertext + plaintext_pad_len; 14477 debug_hexdump(stdout, "ciphertext:", authciphertext, 14478 reference->ciphertext.len); 14479 debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len); 14480 14481 /* Validate obuf */ 14482 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14483 authciphertext, 14484 reference->ciphertext.data, 14485 reference->ciphertext.len, 14486 "Ciphertext data not as expected"); 14487 14488 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14489 auth_tag, 14490 reference->digest.data, 14491 reference->digest.len, 14492 "Generated digest not as expected"); 14493 14494 return TEST_SUCCESS; 14495 14496 } 14497 14498 static int 14499 test_authenticated_decrypt_with_esn( 14500 struct crypto_testsuite_params *ts_params, 14501 struct crypto_unittest_params *ut_params, 14502 const struct test_crypto_vector *reference) 14503 { 14504 int retval; 14505 14506 uint8_t *ciphertext; 14507 uint8_t cipher_key[reference->cipher_key.len + 1]; 14508 uint8_t auth_key[reference->auth_key.len + 1]; 14509 struct rte_cryptodev_info dev_info; 14510 14511 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14512 uint64_t feat_flags = dev_info.feature_flags; 14513 14514 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14515 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14516 printf("Device doesn't support RAW data-path APIs.\n"); 14517 return TEST_SKIPPED; 14518 } 14519 14520 /* Verify the capabilities */ 14521 struct rte_cryptodev_sym_capability_idx cap_idx; 14522 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14523 cap_idx.algo.auth = reference->auth_algo; 14524 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14525 &cap_idx) == NULL) 14526 return TEST_SKIPPED; 14527 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 14528 cap_idx.algo.cipher = reference->crypto_algo; 14529 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14530 &cap_idx) == NULL) 14531 return TEST_SKIPPED; 14532 14533 /* Create session */ 14534 memcpy(cipher_key, reference->cipher_key.data, 14535 reference->cipher_key.len); 14536 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 14537 14538 /* Setup Authentication Parameters */ 14539 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14540 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 14541 ut_params->auth_xform.auth.algo = reference->auth_algo; 14542 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 14543 ut_params->auth_xform.auth.key.data = auth_key; 14544 ut_params->auth_xform.auth.digest_length = reference->digest.len; 14545 ut_params->auth_xform.next = &ut_params->cipher_xform; 14546 14547 /* Setup Cipher Parameters */ 14548 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 14549 ut_params->cipher_xform.next = NULL; 14550 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 14551 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 14552 ut_params->cipher_xform.cipher.key.data = cipher_key; 14553 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 14554 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 14555 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 14556 14557 /* Create Crypto session*/ 14558 ut_params->sess = rte_cryptodev_sym_session_create( 14559 ts_params->valid_devs[0], &ut_params->auth_xform, 14560 ts_params->session_mpool); 14561 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 14562 return TEST_SKIPPED; 14563 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 14564 14565 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14566 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14567 "Failed to allocate input buffer in mempool"); 14568 14569 /* clear mbuf payload */ 14570 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14571 rte_pktmbuf_tailroom(ut_params->ibuf)); 14572 14573 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14574 reference->ciphertext.len); 14575 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 14576 memcpy(ciphertext, reference->ciphertext.data, 14577 reference->ciphertext.len); 14578 14579 /* Create operation */ 14580 retval = create_cipher_auth_verify_operation(ts_params, 14581 ut_params, 14582 reference); 14583 14584 if (retval < 0) 14585 return retval; 14586 14587 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14588 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14589 ut_params->op); 14590 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14591 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 14592 ut_params->op, 1, 1, 0, 0); 14593 else 14594 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 14595 ut_params->op); 14596 14597 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 14598 TEST_ASSERT_EQUAL(ut_params->op->status, 14599 RTE_CRYPTO_OP_STATUS_SUCCESS, 14600 "crypto op processing passed"); 14601 14602 ut_params->obuf = ut_params->op->sym->m_src; 14603 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 14604 14605 return 0; 14606 } 14607 14608 static int 14609 create_aead_operation_SGL(enum rte_crypto_aead_operation op, 14610 const struct aead_test_data *tdata, 14611 void *digest_mem, uint64_t digest_phys) 14612 { 14613 struct crypto_testsuite_params *ts_params = &testsuite_params; 14614 struct crypto_unittest_params *ut_params = &unittest_params; 14615 14616 const unsigned int auth_tag_len = tdata->auth_tag.len; 14617 const unsigned int iv_len = tdata->iv.len; 14618 unsigned int aad_len = tdata->aad.len; 14619 unsigned int aad_len_pad = 0; 14620 14621 /* Generate Crypto op data structure */ 14622 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 14623 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 14624 TEST_ASSERT_NOT_NULL(ut_params->op, 14625 "Failed to allocate symmetric crypto operation struct"); 14626 14627 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 14628 14629 sym_op->aead.digest.data = digest_mem; 14630 14631 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 14632 "no room to append digest"); 14633 14634 sym_op->aead.digest.phys_addr = digest_phys; 14635 14636 if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) { 14637 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 14638 auth_tag_len); 14639 debug_hexdump(stdout, "digest:", 14640 sym_op->aead.digest.data, 14641 auth_tag_len); 14642 } 14643 14644 /* Append aad data */ 14645 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 14646 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 14647 uint8_t *, IV_OFFSET); 14648 14649 /* Copy IV 1 byte after the IV pointer, according to the API */ 14650 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len); 14651 14652 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16); 14653 14654 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 14655 ut_params->ibuf, aad_len); 14656 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 14657 "no room to prepend aad"); 14658 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 14659 ut_params->ibuf); 14660 14661 memset(sym_op->aead.aad.data, 0, aad_len); 14662 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 14663 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 14664 14665 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 14666 debug_hexdump(stdout, "aad:", 14667 sym_op->aead.aad.data, aad_len); 14668 } else { 14669 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 14670 uint8_t *, IV_OFFSET); 14671 14672 rte_memcpy(iv_ptr, tdata->iv.data, iv_len); 14673 14674 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16); 14675 14676 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 14677 ut_params->ibuf, aad_len_pad); 14678 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 14679 "no room to prepend aad"); 14680 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 14681 ut_params->ibuf); 14682 14683 memset(sym_op->aead.aad.data, 0, aad_len); 14684 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 14685 14686 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 14687 debug_hexdump(stdout, "aad:", 14688 sym_op->aead.aad.data, aad_len); 14689 } 14690 14691 sym_op->aead.data.length = tdata->plaintext.len; 14692 sym_op->aead.data.offset = aad_len_pad; 14693 14694 return 0; 14695 } 14696 14697 #define SGL_MAX_NO 16 14698 14699 static int 14700 test_authenticated_encryption_SGL(const struct aead_test_data *tdata, 14701 const int oop, uint32_t fragsz, uint32_t fragsz_oop) 14702 { 14703 struct crypto_testsuite_params *ts_params = &testsuite_params; 14704 struct crypto_unittest_params *ut_params = &unittest_params; 14705 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL; 14706 int retval; 14707 int to_trn = 0; 14708 int to_trn_tbl[SGL_MAX_NO]; 14709 int segs = 1; 14710 unsigned int trn_data = 0; 14711 uint8_t *plaintext, *ciphertext, *auth_tag; 14712 struct rte_cryptodev_info dev_info; 14713 14714 /* Verify the capabilities */ 14715 struct rte_cryptodev_sym_capability_idx cap_idx; 14716 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 14717 cap_idx.algo.aead = tdata->algo; 14718 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14719 &cap_idx) == NULL) 14720 return TEST_SKIPPED; 14721 14722 /* OOP not supported with CPU crypto */ 14723 if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14724 return TEST_SKIPPED; 14725 14726 /* Detailed check for the particular SGL support flag */ 14727 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14728 if (!oop) { 14729 unsigned int sgl_in = fragsz < tdata->plaintext.len; 14730 if (sgl_in && (!(dev_info.feature_flags & 14731 RTE_CRYPTODEV_FF_IN_PLACE_SGL))) 14732 return TEST_SKIPPED; 14733 14734 uint64_t feat_flags = dev_info.feature_flags; 14735 14736 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14737 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14738 printf("Device doesn't support RAW data-path APIs.\n"); 14739 return TEST_SKIPPED; 14740 } 14741 } else { 14742 unsigned int sgl_in = fragsz < tdata->plaintext.len; 14743 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) < 14744 tdata->plaintext.len; 14745 /* Raw data path API does not support OOP */ 14746 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14747 return TEST_SKIPPED; 14748 if (sgl_in && !sgl_out) { 14749 if (!(dev_info.feature_flags & 14750 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) 14751 return TEST_SKIPPED; 14752 } else if (!sgl_in && sgl_out) { 14753 if (!(dev_info.feature_flags & 14754 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 14755 return TEST_SKIPPED; 14756 } else if (sgl_in && sgl_out) { 14757 if (!(dev_info.feature_flags & 14758 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 14759 return TEST_SKIPPED; 14760 } 14761 } 14762 14763 if (fragsz > tdata->plaintext.len) 14764 fragsz = tdata->plaintext.len; 14765 14766 uint16_t plaintext_len = fragsz; 14767 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 14768 14769 if (fragsz_oop > tdata->plaintext.len) 14770 frag_size_oop = tdata->plaintext.len; 14771 14772 int ecx = 0; 14773 void *digest_mem = NULL; 14774 14775 uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 14776 14777 if (tdata->plaintext.len % fragsz != 0) { 14778 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO) 14779 return 1; 14780 } else { 14781 if (tdata->plaintext.len / fragsz > SGL_MAX_NO) 14782 return 1; 14783 } 14784 14785 /* 14786 * For out-op-place we need to alloc another mbuf 14787 */ 14788 if (oop) { 14789 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14790 rte_pktmbuf_append(ut_params->obuf, 14791 frag_size_oop + prepend_len); 14792 buf_oop = ut_params->obuf; 14793 } 14794 14795 /* Create AEAD session */ 14796 retval = create_aead_session(ts_params->valid_devs[0], 14797 tdata->algo, 14798 RTE_CRYPTO_AEAD_OP_ENCRYPT, 14799 tdata->key.data, tdata->key.len, 14800 tdata->aad.len, tdata->auth_tag.len, 14801 tdata->iv.len); 14802 if (retval < 0) 14803 return retval; 14804 14805 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14806 14807 /* clear mbuf payload */ 14808 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14809 rte_pktmbuf_tailroom(ut_params->ibuf)); 14810 14811 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14812 plaintext_len); 14813 14814 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 14815 14816 trn_data += plaintext_len; 14817 14818 buf = ut_params->ibuf; 14819 14820 /* 14821 * Loop until no more fragments 14822 */ 14823 14824 while (trn_data < tdata->plaintext.len) { 14825 ++segs; 14826 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 14827 (tdata->plaintext.len - trn_data) : fragsz; 14828 14829 to_trn_tbl[ecx++] = to_trn; 14830 14831 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14832 buf = buf->next; 14833 14834 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 14835 rte_pktmbuf_tailroom(buf)); 14836 14837 /* OOP */ 14838 if (oop && !fragsz_oop) { 14839 buf_last_oop = buf_oop->next = 14840 rte_pktmbuf_alloc(ts_params->mbuf_pool); 14841 buf_oop = buf_oop->next; 14842 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 14843 0, rte_pktmbuf_tailroom(buf_oop)); 14844 rte_pktmbuf_append(buf_oop, to_trn); 14845 } 14846 14847 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 14848 to_trn); 14849 14850 memcpy(plaintext, tdata->plaintext.data + trn_data, 14851 to_trn); 14852 trn_data += to_trn; 14853 if (trn_data == tdata->plaintext.len) { 14854 if (oop) { 14855 if (!fragsz_oop) 14856 digest_mem = rte_pktmbuf_append(buf_oop, 14857 tdata->auth_tag.len); 14858 } else 14859 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 14860 tdata->auth_tag.len); 14861 } 14862 } 14863 14864 uint64_t digest_phys = 0; 14865 14866 ut_params->ibuf->nb_segs = segs; 14867 14868 segs = 1; 14869 if (fragsz_oop && oop) { 14870 to_trn = 0; 14871 ecx = 0; 14872 14873 if (frag_size_oop == tdata->plaintext.len) { 14874 digest_mem = rte_pktmbuf_append(ut_params->obuf, 14875 tdata->auth_tag.len); 14876 14877 digest_phys = rte_pktmbuf_iova_offset( 14878 ut_params->obuf, 14879 tdata->plaintext.len + prepend_len); 14880 } 14881 14882 trn_data = frag_size_oop; 14883 while (trn_data < tdata->plaintext.len) { 14884 ++segs; 14885 to_trn = 14886 (tdata->plaintext.len - trn_data < 14887 frag_size_oop) ? 14888 (tdata->plaintext.len - trn_data) : 14889 frag_size_oop; 14890 14891 to_trn_tbl[ecx++] = to_trn; 14892 14893 buf_last_oop = buf_oop->next = 14894 rte_pktmbuf_alloc(ts_params->mbuf_pool); 14895 buf_oop = buf_oop->next; 14896 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 14897 0, rte_pktmbuf_tailroom(buf_oop)); 14898 rte_pktmbuf_append(buf_oop, to_trn); 14899 14900 trn_data += to_trn; 14901 14902 if (trn_data == tdata->plaintext.len) { 14903 digest_mem = rte_pktmbuf_append(buf_oop, 14904 tdata->auth_tag.len); 14905 } 14906 } 14907 14908 ut_params->obuf->nb_segs = segs; 14909 } 14910 14911 /* 14912 * Place digest at the end of the last buffer 14913 */ 14914 if (!digest_phys) 14915 digest_phys = rte_pktmbuf_iova(buf) + to_trn; 14916 if (oop && buf_last_oop) 14917 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn; 14918 14919 if (!digest_mem && !oop) { 14920 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14921 + tdata->auth_tag.len); 14922 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 14923 tdata->plaintext.len); 14924 } 14925 14926 /* Create AEAD operation */ 14927 retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT, 14928 tdata, digest_mem, digest_phys); 14929 14930 if (retval < 0) 14931 return retval; 14932 14933 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14934 14935 ut_params->op->sym->m_src = ut_params->ibuf; 14936 if (oop) 14937 ut_params->op->sym->m_dst = ut_params->obuf; 14938 14939 /* Process crypto operation */ 14940 if (oop == IN_PLACE && 14941 gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14942 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 14943 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14944 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 14945 ut_params->op, 0, 0, 0, 0); 14946 else 14947 TEST_ASSERT_NOT_NULL( 14948 process_crypto_request(ts_params->valid_devs[0], 14949 ut_params->op), "failed to process sym crypto op"); 14950 14951 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14952 "crypto op processing failed"); 14953 14954 14955 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 14956 uint8_t *, prepend_len); 14957 if (oop) { 14958 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 14959 uint8_t *, prepend_len); 14960 } 14961 14962 if (fragsz_oop) 14963 fragsz = fragsz_oop; 14964 14965 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14966 ciphertext, 14967 tdata->ciphertext.data, 14968 fragsz, 14969 "Ciphertext data not as expected"); 14970 14971 buf = ut_params->op->sym->m_src->next; 14972 if (oop) 14973 buf = ut_params->op->sym->m_dst->next; 14974 14975 unsigned int off = fragsz; 14976 14977 ecx = 0; 14978 while (buf) { 14979 ciphertext = rte_pktmbuf_mtod(buf, 14980 uint8_t *); 14981 14982 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14983 ciphertext, 14984 tdata->ciphertext.data + off, 14985 to_trn_tbl[ecx], 14986 "Ciphertext data not as expected"); 14987 14988 off += to_trn_tbl[ecx++]; 14989 buf = buf->next; 14990 } 14991 14992 auth_tag = digest_mem; 14993 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14994 auth_tag, 14995 tdata->auth_tag.data, 14996 tdata->auth_tag.len, 14997 "Generated auth tag not as expected"); 14998 14999 return 0; 15000 } 15001 15002 static int 15003 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) 15004 { 15005 return test_authenticated_encryption_SGL( 15006 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400); 15007 } 15008 15009 static int 15010 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void) 15011 { 15012 return test_authenticated_encryption_SGL( 15013 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000); 15014 } 15015 15016 static int 15017 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void) 15018 { 15019 return test_authenticated_encryption_SGL( 15020 &gcm_test_case_8, OUT_OF_PLACE, 400, 15021 gcm_test_case_8.plaintext.len); 15022 } 15023 15024 static int 15025 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void) 15026 { 15027 /* This test is not for OPENSSL PMD */ 15028 if (gbl_driver_id == rte_cryptodev_driver_id_get( 15029 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) 15030 return TEST_SKIPPED; 15031 15032 return test_authenticated_encryption_SGL( 15033 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0); 15034 } 15035 15036 static int 15037 test_authentication_verify_fail_when_data_corrupted( 15038 struct crypto_testsuite_params *ts_params, 15039 struct crypto_unittest_params *ut_params, 15040 const struct test_crypto_vector *reference) 15041 { 15042 return test_authentication_verify_fail_when_data_corruption( 15043 ts_params, ut_params, reference, 1); 15044 } 15045 15046 static int 15047 test_authentication_verify_fail_when_tag_corrupted( 15048 struct crypto_testsuite_params *ts_params, 15049 struct crypto_unittest_params *ut_params, 15050 const struct test_crypto_vector *reference) 15051 { 15052 return test_authentication_verify_fail_when_data_corruption( 15053 ts_params, ut_params, reference, 0); 15054 } 15055 15056 static int 15057 test_authentication_verify_GMAC_fail_when_data_corrupted( 15058 struct crypto_testsuite_params *ts_params, 15059 struct crypto_unittest_params *ut_params, 15060 const struct test_crypto_vector *reference) 15061 { 15062 return test_authentication_verify_GMAC_fail_when_corruption( 15063 ts_params, ut_params, reference, 1); 15064 } 15065 15066 static int 15067 test_authentication_verify_GMAC_fail_when_tag_corrupted( 15068 struct crypto_testsuite_params *ts_params, 15069 struct crypto_unittest_params *ut_params, 15070 const struct test_crypto_vector *reference) 15071 { 15072 return test_authentication_verify_GMAC_fail_when_corruption( 15073 ts_params, ut_params, reference, 0); 15074 } 15075 15076 static int 15077 test_authenticated_decryption_fail_when_data_corrupted( 15078 struct crypto_testsuite_params *ts_params, 15079 struct crypto_unittest_params *ut_params, 15080 const struct test_crypto_vector *reference) 15081 { 15082 return test_authenticated_decryption_fail_when_corruption( 15083 ts_params, ut_params, reference, 1); 15084 } 15085 15086 static int 15087 test_authenticated_decryption_fail_when_tag_corrupted( 15088 struct crypto_testsuite_params *ts_params, 15089 struct crypto_unittest_params *ut_params, 15090 const struct test_crypto_vector *reference) 15091 { 15092 return test_authenticated_decryption_fail_when_corruption( 15093 ts_params, ut_params, reference, 0); 15094 } 15095 15096 static int 15097 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 15098 { 15099 return test_authentication_verify_fail_when_data_corrupted( 15100 &testsuite_params, &unittest_params, 15101 &hmac_sha1_test_crypto_vector); 15102 } 15103 15104 static int 15105 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 15106 { 15107 return test_authentication_verify_fail_when_tag_corrupted( 15108 &testsuite_params, &unittest_params, 15109 &hmac_sha1_test_crypto_vector); 15110 } 15111 15112 static int 15113 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 15114 { 15115 return test_authentication_verify_GMAC_fail_when_data_corrupted( 15116 &testsuite_params, &unittest_params, 15117 &aes128_gmac_test_vector); 15118 } 15119 15120 static int 15121 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 15122 { 15123 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 15124 &testsuite_params, &unittest_params, 15125 &aes128_gmac_test_vector); 15126 } 15127 15128 static int 15129 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 15130 { 15131 return test_authenticated_decryption_fail_when_data_corrupted( 15132 &testsuite_params, 15133 &unittest_params, 15134 &aes128cbc_hmac_sha1_test_vector); 15135 } 15136 15137 static int 15138 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 15139 { 15140 return test_authenticated_decryption_fail_when_tag_corrupted( 15141 &testsuite_params, 15142 &unittest_params, 15143 &aes128cbc_hmac_sha1_test_vector); 15144 } 15145 15146 static int 15147 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void) 15148 { 15149 return test_authenticated_encrypt_with_esn( 15150 &testsuite_params, 15151 &unittest_params, 15152 &aes128cbc_hmac_sha1_aad_test_vector); 15153 } 15154 15155 static int 15156 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void) 15157 { 15158 return test_authenticated_decrypt_with_esn( 15159 &testsuite_params, 15160 &unittest_params, 15161 &aes128cbc_hmac_sha1_aad_test_vector); 15162 } 15163 15164 static int 15165 test_chacha20_poly1305_encrypt_test_case_rfc8439(void) 15166 { 15167 return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439); 15168 } 15169 15170 static int 15171 test_chacha20_poly1305_decrypt_test_case_rfc8439(void) 15172 { 15173 return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439); 15174 } 15175 15176 static int 15177 test_chacha20_poly1305_encrypt_SGL_out_of_place(void) 15178 { 15179 return test_authenticated_encryption_SGL( 15180 &chacha20_poly1305_case_2, OUT_OF_PLACE, 32, 15181 chacha20_poly1305_case_2.plaintext.len); 15182 } 15183 15184 #ifdef RTE_CRYPTO_SCHEDULER 15185 15186 /* global AESNI worker IDs for the scheduler test */ 15187 uint8_t aesni_ids[2]; 15188 15189 static int 15190 scheduler_testsuite_setup(void) 15191 { 15192 uint32_t i = 0; 15193 int32_t nb_devs, ret; 15194 char vdev_args[VDEV_ARGS_SIZE] = {""}; 15195 char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core," 15196 "ordering=enable,name=cryptodev_test_scheduler,corelist="}; 15197 uint16_t worker_core_count = 0; 15198 uint16_t socket_id = 0; 15199 15200 if (gbl_driver_id == rte_cryptodev_driver_id_get( 15201 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) { 15202 15203 /* Identify the Worker Cores 15204 * Use 2 worker cores for the device args 15205 */ 15206 RTE_LCORE_FOREACH_WORKER(i) { 15207 if (worker_core_count > 1) 15208 break; 15209 snprintf(vdev_args, sizeof(vdev_args), 15210 "%s%d", temp_str, i); 15211 strcpy(temp_str, vdev_args); 15212 strlcat(temp_str, ";", sizeof(temp_str)); 15213 worker_core_count++; 15214 socket_id = rte_lcore_to_socket_id(i); 15215 } 15216 if (worker_core_count != 2) { 15217 RTE_LOG(ERR, USER1, 15218 "Cryptodev scheduler test require at least " 15219 "two worker cores to run. " 15220 "Please use the correct coremask.\n"); 15221 return TEST_FAILED; 15222 } 15223 strcpy(temp_str, vdev_args); 15224 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", 15225 temp_str, socket_id); 15226 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args); 15227 nb_devs = rte_cryptodev_device_count_by_driver( 15228 rte_cryptodev_driver_id_get( 15229 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))); 15230 if (nb_devs < 1) { 15231 ret = rte_vdev_init( 15232 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD), 15233 vdev_args); 15234 TEST_ASSERT(ret == 0, 15235 "Failed to create instance %u of pmd : %s", 15236 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 15237 } 15238 } 15239 return testsuite_setup(); 15240 } 15241 15242 static int 15243 test_scheduler_attach_worker_op(void) 15244 { 15245 struct crypto_testsuite_params *ts_params = &testsuite_params; 15246 uint8_t sched_id = ts_params->valid_devs[0]; 15247 uint32_t i, nb_devs_attached = 0; 15248 int ret; 15249 char vdev_name[32]; 15250 unsigned int count = rte_cryptodev_count(); 15251 15252 /* create 2 AESNI_MB vdevs on top of existing devices */ 15253 for (i = count; i < count + 2; i++) { 15254 snprintf(vdev_name, sizeof(vdev_name), "%s_%u", 15255 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), 15256 i); 15257 ret = rte_vdev_init(vdev_name, NULL); 15258 15259 TEST_ASSERT(ret == 0, 15260 "Failed to create instance %u of" 15261 " pmd : %s", 15262 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 15263 15264 if (ret < 0) { 15265 RTE_LOG(ERR, USER1, 15266 "Failed to create 2 AESNI MB PMDs.\n"); 15267 return TEST_SKIPPED; 15268 } 15269 } 15270 15271 /* attach 2 AESNI_MB cdevs */ 15272 for (i = count; i < count + 2; i++) { 15273 struct rte_cryptodev_info info; 15274 unsigned int session_size; 15275 15276 rte_cryptodev_info_get(i, &info); 15277 if (info.driver_id != rte_cryptodev_driver_id_get( 15278 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) 15279 continue; 15280 15281 session_size = rte_cryptodev_sym_get_private_session_size(i); 15282 /* 15283 * Create the session mempool again, since now there are new devices 15284 * to use the mempool. 15285 */ 15286 if (ts_params->session_mpool) { 15287 rte_mempool_free(ts_params->session_mpool); 15288 ts_params->session_mpool = NULL; 15289 } 15290 15291 if (info.sym.max_nb_sessions != 0 && 15292 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 15293 RTE_LOG(ERR, USER1, 15294 "Device does not support " 15295 "at least %u sessions\n", 15296 MAX_NB_SESSIONS); 15297 return TEST_FAILED; 15298 } 15299 /* 15300 * Create mempool with maximum number of sessions, 15301 * to include the session headers 15302 */ 15303 if (ts_params->session_mpool == NULL) { 15304 ts_params->session_mpool = 15305 rte_cryptodev_sym_session_pool_create( 15306 "test_sess_mp", 15307 MAX_NB_SESSIONS, session_size, 15308 0, 0, SOCKET_ID_ANY); 15309 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 15310 "session mempool allocation failed"); 15311 } 15312 15313 ts_params->qp_conf.mp_session = ts_params->session_mpool; 15314 15315 ret = rte_cryptodev_scheduler_worker_attach(sched_id, 15316 (uint8_t)i); 15317 15318 TEST_ASSERT(ret == 0, 15319 "Failed to attach device %u of pmd : %s", i, 15320 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 15321 15322 aesni_ids[nb_devs_attached] = (uint8_t)i; 15323 15324 nb_devs_attached++; 15325 } 15326 15327 return 0; 15328 } 15329 15330 static int 15331 test_scheduler_detach_worker_op(void) 15332 { 15333 struct crypto_testsuite_params *ts_params = &testsuite_params; 15334 uint8_t sched_id = ts_params->valid_devs[0]; 15335 uint32_t i; 15336 int ret; 15337 15338 for (i = 0; i < 2; i++) { 15339 ret = rte_cryptodev_scheduler_worker_detach(sched_id, 15340 aesni_ids[i]); 15341 TEST_ASSERT(ret == 0, 15342 "Failed to detach device %u", aesni_ids[i]); 15343 } 15344 15345 return 0; 15346 } 15347 15348 static int 15349 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode) 15350 { 15351 struct crypto_testsuite_params *ts_params = &testsuite_params; 15352 uint8_t sched_id = ts_params->valid_devs[0]; 15353 /* set mode */ 15354 return rte_cryptodev_scheduler_mode_set(sched_id, 15355 scheduler_mode); 15356 } 15357 15358 static int 15359 test_scheduler_mode_roundrobin_op(void) 15360 { 15361 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) == 15362 0, "Failed to set roundrobin mode"); 15363 return 0; 15364 15365 } 15366 15367 static int 15368 test_scheduler_mode_multicore_op(void) 15369 { 15370 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) == 15371 0, "Failed to set multicore mode"); 15372 15373 return 0; 15374 } 15375 15376 static int 15377 test_scheduler_mode_failover_op(void) 15378 { 15379 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) == 15380 0, "Failed to set failover mode"); 15381 15382 return 0; 15383 } 15384 15385 static int 15386 test_scheduler_mode_pkt_size_distr_op(void) 15387 { 15388 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) == 15389 0, "Failed to set pktsize mode"); 15390 15391 return 0; 15392 } 15393 15394 static int 15395 scheduler_multicore_testsuite_setup(void) 15396 { 15397 if (test_scheduler_attach_worker_op() < 0) 15398 return TEST_SKIPPED; 15399 if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0) 15400 return TEST_SKIPPED; 15401 return 0; 15402 } 15403 15404 static int 15405 scheduler_roundrobin_testsuite_setup(void) 15406 { 15407 if (test_scheduler_attach_worker_op() < 0) 15408 return TEST_SKIPPED; 15409 if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0) 15410 return TEST_SKIPPED; 15411 return 0; 15412 } 15413 15414 static int 15415 scheduler_failover_testsuite_setup(void) 15416 { 15417 if (test_scheduler_attach_worker_op() < 0) 15418 return TEST_SKIPPED; 15419 if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0) 15420 return TEST_SKIPPED; 15421 return 0; 15422 } 15423 15424 static int 15425 scheduler_pkt_size_distr_testsuite_setup(void) 15426 { 15427 if (test_scheduler_attach_worker_op() < 0) 15428 return TEST_SKIPPED; 15429 if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0) 15430 return TEST_SKIPPED; 15431 return 0; 15432 } 15433 15434 static void 15435 scheduler_mode_testsuite_teardown(void) 15436 { 15437 test_scheduler_detach_worker_op(); 15438 } 15439 15440 #endif /* RTE_CRYPTO_SCHEDULER */ 15441 15442 static struct unit_test_suite end_testsuite = { 15443 .suite_name = NULL, 15444 .setup = NULL, 15445 .teardown = NULL, 15446 .unit_test_suites = NULL 15447 }; 15448 15449 #ifdef RTE_LIB_SECURITY 15450 static struct unit_test_suite ipsec_proto_testsuite = { 15451 .suite_name = "IPsec Proto Unit Test Suite", 15452 .setup = ipsec_proto_testsuite_setup, 15453 .unit_test_cases = { 15454 TEST_CASE_NAMED_WITH_DATA( 15455 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 15456 ut_setup_security, ut_teardown, 15457 test_ipsec_proto_known_vec, &pkt_aes_128_gcm), 15458 TEST_CASE_NAMED_WITH_DATA( 15459 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 15460 ut_setup_security, ut_teardown, 15461 test_ipsec_proto_known_vec, &pkt_aes_192_gcm), 15462 TEST_CASE_NAMED_WITH_DATA( 15463 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 15464 ut_setup_security, ut_teardown, 15465 test_ipsec_proto_known_vec, &pkt_aes_256_gcm), 15466 TEST_CASE_NAMED_WITH_DATA( 15467 "Outbound known vector (ESP tunnel mode IPv4 AES-CCM 256)", 15468 ut_setup_security, ut_teardown, 15469 test_ipsec_proto_known_vec, &pkt_aes_256_ccm), 15470 TEST_CASE_NAMED_WITH_DATA( 15471 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC MD5 [12B ICV])", 15472 ut_setup_security, ut_teardown, 15473 test_ipsec_proto_known_vec, 15474 &pkt_aes_128_cbc_md5), 15475 TEST_CASE_NAMED_WITH_DATA( 15476 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])", 15477 ut_setup_security, ut_teardown, 15478 test_ipsec_proto_known_vec, 15479 &pkt_aes_128_cbc_hmac_sha256), 15480 TEST_CASE_NAMED_WITH_DATA( 15481 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])", 15482 ut_setup_security, ut_teardown, 15483 test_ipsec_proto_known_vec, 15484 &pkt_aes_128_cbc_hmac_sha384), 15485 TEST_CASE_NAMED_WITH_DATA( 15486 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])", 15487 ut_setup_security, ut_teardown, 15488 test_ipsec_proto_known_vec, 15489 &pkt_aes_128_cbc_hmac_sha512), 15490 TEST_CASE_NAMED_WITH_DATA( 15491 "Outbound known vector (ESP tunnel mode IPv6 AES-GCM 128)", 15492 ut_setup_security, ut_teardown, 15493 test_ipsec_proto_known_vec, &pkt_aes_256_gcm_v6), 15494 TEST_CASE_NAMED_WITH_DATA( 15495 "Outbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])", 15496 ut_setup_security, ut_teardown, 15497 test_ipsec_proto_known_vec, 15498 &pkt_aes_128_cbc_hmac_sha256_v6), 15499 TEST_CASE_NAMED_WITH_DATA( 15500 "Outbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])", 15501 ut_setup_security, ut_teardown, 15502 test_ipsec_proto_known_vec, 15503 &pkt_null_aes_xcbc), 15504 TEST_CASE_NAMED_WITH_DATA( 15505 "Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA256 [16B ICV])", 15506 ut_setup_security, ut_teardown, 15507 test_ipsec_proto_known_vec, 15508 &pkt_des_cbc_hmac_sha256), 15509 TEST_CASE_NAMED_WITH_DATA( 15510 "Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA384 [24B ICV])", 15511 ut_setup_security, ut_teardown, 15512 test_ipsec_proto_known_vec, 15513 &pkt_des_cbc_hmac_sha384), 15514 TEST_CASE_NAMED_WITH_DATA( 15515 "Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA512 [32B ICV])", 15516 ut_setup_security, ut_teardown, 15517 test_ipsec_proto_known_vec, 15518 &pkt_des_cbc_hmac_sha512), 15519 TEST_CASE_NAMED_WITH_DATA( 15520 "Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA256 [16B ICV])", 15521 ut_setup_security, ut_teardown, 15522 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha256), 15523 TEST_CASE_NAMED_WITH_DATA( 15524 "Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA384 [24B ICV])", 15525 ut_setup_security, ut_teardown, 15526 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha384), 15527 TEST_CASE_NAMED_WITH_DATA( 15528 "Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA512 [32B ICV])", 15529 ut_setup_security, ut_teardown, 15530 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha512), 15531 TEST_CASE_NAMED_WITH_DATA( 15532 "Outbound known vector (ESP tunnel mode IPv6 DES-CBC HMAC-SHA256 [16B ICV])", 15533 ut_setup_security, ut_teardown, 15534 test_ipsec_proto_known_vec, 15535 &pkt_des_cbc_hmac_sha256_v6), 15536 TEST_CASE_NAMED_WITH_DATA( 15537 "Outbound known vector (ESP tunnel mode IPv6 3DES-CBC HMAC-SHA256 [16B ICV])", 15538 ut_setup_security, ut_teardown, 15539 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha256_v6), 15540 TEST_CASE_NAMED_WITH_DATA( 15541 "Outbound known vector (AH tunnel mode IPv4 HMAC-SHA256)", 15542 ut_setup_security, ut_teardown, 15543 test_ipsec_proto_known_vec, 15544 &pkt_ah_tunnel_sha256), 15545 TEST_CASE_NAMED_WITH_DATA( 15546 "Outbound known vector (AH transport mode IPv4 HMAC-SHA256)", 15547 ut_setup_security, ut_teardown, 15548 test_ipsec_proto_known_vec, 15549 &pkt_ah_transport_sha256), 15550 TEST_CASE_NAMED_WITH_DATA( 15551 "Outbound known vector (AH transport mode IPv4 AES-GMAC 128)", 15552 ut_setup_security, ut_teardown, 15553 test_ipsec_proto_known_vec, 15554 &pkt_ah_ipv4_aes_gmac_128), 15555 TEST_CASE_NAMED_WITH_DATA( 15556 "Outbound fragmented packet", 15557 ut_setup_security, ut_teardown, 15558 test_ipsec_proto_known_vec_fragmented, 15559 &pkt_aes_128_gcm_frag), 15560 TEST_CASE_NAMED_WITH_DATA( 15561 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 15562 ut_setup_security, ut_teardown, 15563 test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm), 15564 TEST_CASE_NAMED_WITH_DATA( 15565 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 15566 ut_setup_security, ut_teardown, 15567 test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm), 15568 TEST_CASE_NAMED_WITH_DATA( 15569 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 15570 ut_setup_security, ut_teardown, 15571 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm), 15572 TEST_CASE_NAMED_WITH_DATA( 15573 "Inbound known vector (ESP tunnel mode IPv4 AES-CCM 256)", 15574 ut_setup_security, ut_teardown, 15575 test_ipsec_proto_known_vec_inb, &pkt_aes_256_ccm), 15576 TEST_CASE_NAMED_WITH_DATA( 15577 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)", 15578 ut_setup_security, ut_teardown, 15579 test_ipsec_proto_known_vec_inb, &pkt_aes_128_cbc_null), 15580 TEST_CASE_NAMED_WITH_DATA( 15581 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC MD5 [12B ICV])", 15582 ut_setup_security, ut_teardown, 15583 test_ipsec_proto_known_vec_inb, 15584 &pkt_aes_128_cbc_md5), 15585 TEST_CASE_NAMED_WITH_DATA( 15586 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])", 15587 ut_setup_security, ut_teardown, 15588 test_ipsec_proto_known_vec_inb, 15589 &pkt_aes_128_cbc_hmac_sha256), 15590 TEST_CASE_NAMED_WITH_DATA( 15591 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])", 15592 ut_setup_security, ut_teardown, 15593 test_ipsec_proto_known_vec_inb, 15594 &pkt_aes_128_cbc_hmac_sha384), 15595 TEST_CASE_NAMED_WITH_DATA( 15596 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])", 15597 ut_setup_security, ut_teardown, 15598 test_ipsec_proto_known_vec_inb, 15599 &pkt_aes_128_cbc_hmac_sha512), 15600 TEST_CASE_NAMED_WITH_DATA( 15601 "Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)", 15602 ut_setup_security, ut_teardown, 15603 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm_v6), 15604 TEST_CASE_NAMED_WITH_DATA( 15605 "Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])", 15606 ut_setup_security, ut_teardown, 15607 test_ipsec_proto_known_vec_inb, 15608 &pkt_aes_128_cbc_hmac_sha256_v6), 15609 TEST_CASE_NAMED_WITH_DATA( 15610 "Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])", 15611 ut_setup_security, ut_teardown, 15612 test_ipsec_proto_known_vec_inb, 15613 &pkt_null_aes_xcbc), 15614 TEST_CASE_NAMED_WITH_DATA( 15615 "Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA256 [16B ICV])", 15616 ut_setup_security, ut_teardown, 15617 test_ipsec_proto_known_vec_inb, 15618 &pkt_des_cbc_hmac_sha256), 15619 TEST_CASE_NAMED_WITH_DATA( 15620 "Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA384 [24B ICV])", 15621 ut_setup_security, ut_teardown, 15622 test_ipsec_proto_known_vec_inb, 15623 &pkt_des_cbc_hmac_sha384), 15624 TEST_CASE_NAMED_WITH_DATA( 15625 "Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA512 [32B ICV])", 15626 ut_setup_security, ut_teardown, 15627 test_ipsec_proto_known_vec_inb, 15628 &pkt_des_cbc_hmac_sha512), 15629 TEST_CASE_NAMED_WITH_DATA( 15630 "Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA256 [16B ICV])", 15631 ut_setup_security, ut_teardown, 15632 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha256), 15633 TEST_CASE_NAMED_WITH_DATA( 15634 "Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA384 [24B ICV])", 15635 ut_setup_security, ut_teardown, 15636 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha384), 15637 TEST_CASE_NAMED_WITH_DATA( 15638 "Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA512 [32B ICV])", 15639 ut_setup_security, ut_teardown, 15640 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha512), 15641 TEST_CASE_NAMED_WITH_DATA( 15642 "Inbound known vector (ESP tunnel mode IPv6 DES-CBC HMAC-SHA256 [16B ICV])", 15643 ut_setup_security, ut_teardown, 15644 test_ipsec_proto_known_vec_inb, 15645 &pkt_des_cbc_hmac_sha256_v6), 15646 TEST_CASE_NAMED_WITH_DATA( 15647 "Inbound known vector (ESP tunnel mode IPv6 3DES-CBC HMAC-SHA256 [16B ICV])", 15648 ut_setup_security, ut_teardown, 15649 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha256_v6), 15650 TEST_CASE_NAMED_WITH_DATA( 15651 "Inbound known vector (AH tunnel mode IPv4 HMAC-SHA256)", 15652 ut_setup_security, ut_teardown, 15653 test_ipsec_proto_known_vec_inb, 15654 &pkt_ah_tunnel_sha256), 15655 TEST_CASE_NAMED_WITH_DATA( 15656 "Inbound known vector (AH transport mode IPv4 HMAC-SHA256)", 15657 ut_setup_security, ut_teardown, 15658 test_ipsec_proto_known_vec_inb, 15659 &pkt_ah_transport_sha256), 15660 TEST_CASE_NAMED_WITH_DATA( 15661 "Inbound known vector (AH transport mode IPv4 AES-GMAC 128)", 15662 ut_setup_security, ut_teardown, 15663 test_ipsec_proto_known_vec_inb, 15664 &pkt_ah_ipv4_aes_gmac_128), 15665 TEST_CASE_NAMED_ST( 15666 "Combined test alg list", 15667 ut_setup_security, ut_teardown, 15668 test_ipsec_proto_display_list), 15669 TEST_CASE_NAMED_ST( 15670 "Combined test alg list (AH)", 15671 ut_setup_security, ut_teardown, 15672 test_ipsec_proto_ah_tunnel_ipv4), 15673 TEST_CASE_NAMED_ST( 15674 "IV generation", 15675 ut_setup_security, ut_teardown, 15676 test_ipsec_proto_iv_gen), 15677 TEST_CASE_NAMED_ST( 15678 "UDP encapsulation", 15679 ut_setup_security, ut_teardown, 15680 test_ipsec_proto_udp_encap), 15681 TEST_CASE_NAMED_ST( 15682 "UDP encapsulation with custom ports", 15683 ut_setup_security, ut_teardown, 15684 test_ipsec_proto_udp_encap_custom_ports), 15685 TEST_CASE_NAMED_ST( 15686 "UDP encapsulation ports verification test", 15687 ut_setup_security, ut_teardown, 15688 test_ipsec_proto_udp_ports_verify), 15689 TEST_CASE_NAMED_ST( 15690 "SA expiry packets soft", 15691 ut_setup_security, ut_teardown, 15692 test_ipsec_proto_sa_exp_pkts_soft), 15693 TEST_CASE_NAMED_ST( 15694 "SA expiry packets hard", 15695 ut_setup_security, ut_teardown, 15696 test_ipsec_proto_sa_exp_pkts_hard), 15697 TEST_CASE_NAMED_ST( 15698 "Negative test: ICV corruption", 15699 ut_setup_security, ut_teardown, 15700 test_ipsec_proto_err_icv_corrupt), 15701 TEST_CASE_NAMED_ST( 15702 "Tunnel dst addr verification", 15703 ut_setup_security, ut_teardown, 15704 test_ipsec_proto_tunnel_dst_addr_verify), 15705 TEST_CASE_NAMED_ST( 15706 "Tunnel src and dst addr verification", 15707 ut_setup_security, ut_teardown, 15708 test_ipsec_proto_tunnel_src_dst_addr_verify), 15709 TEST_CASE_NAMED_ST( 15710 "Inner IP checksum", 15711 ut_setup_security, ut_teardown, 15712 test_ipsec_proto_inner_ip_csum), 15713 TEST_CASE_NAMED_ST( 15714 "Inner L4 checksum", 15715 ut_setup_security, ut_teardown, 15716 test_ipsec_proto_inner_l4_csum), 15717 TEST_CASE_NAMED_ST( 15718 "Tunnel IPv4 in IPv4", 15719 ut_setup_security, ut_teardown, 15720 test_ipsec_proto_tunnel_v4_in_v4), 15721 TEST_CASE_NAMED_ST( 15722 "Tunnel IPv6 in IPv6", 15723 ut_setup_security, ut_teardown, 15724 test_ipsec_proto_tunnel_v6_in_v6), 15725 TEST_CASE_NAMED_ST( 15726 "Tunnel IPv4 in IPv6", 15727 ut_setup_security, ut_teardown, 15728 test_ipsec_proto_tunnel_v4_in_v6), 15729 TEST_CASE_NAMED_ST( 15730 "Tunnel IPv6 in IPv4", 15731 ut_setup_security, ut_teardown, 15732 test_ipsec_proto_tunnel_v6_in_v4), 15733 TEST_CASE_NAMED_ST( 15734 "Transport IPv4", 15735 ut_setup_security, ut_teardown, 15736 test_ipsec_proto_transport_v4), 15737 TEST_CASE_NAMED_ST( 15738 "AH transport IPv4", 15739 ut_setup_security, ut_teardown, 15740 test_ipsec_proto_ah_transport_ipv4), 15741 TEST_CASE_NAMED_ST( 15742 "Transport l4 checksum", 15743 ut_setup_security, ut_teardown, 15744 test_ipsec_proto_transport_l4_csum), 15745 TEST_CASE_NAMED_ST( 15746 "Statistics: success", 15747 ut_setup_security, ut_teardown, 15748 test_ipsec_proto_stats), 15749 TEST_CASE_NAMED_ST( 15750 "Fragmented packet", 15751 ut_setup_security, ut_teardown, 15752 test_ipsec_proto_pkt_fragment), 15753 TEST_CASE_NAMED_ST( 15754 "Tunnel header copy DF (inner 0)", 15755 ut_setup_security, ut_teardown, 15756 test_ipsec_proto_copy_df_inner_0), 15757 TEST_CASE_NAMED_ST( 15758 "Tunnel header copy DF (inner 1)", 15759 ut_setup_security, ut_teardown, 15760 test_ipsec_proto_copy_df_inner_1), 15761 TEST_CASE_NAMED_ST( 15762 "Tunnel header set DF 0 (inner 1)", 15763 ut_setup_security, ut_teardown, 15764 test_ipsec_proto_set_df_0_inner_1), 15765 TEST_CASE_NAMED_ST( 15766 "Tunnel header set DF 1 (inner 0)", 15767 ut_setup_security, ut_teardown, 15768 test_ipsec_proto_set_df_1_inner_0), 15769 TEST_CASE_NAMED_ST( 15770 "Tunnel header IPv4 copy DSCP (inner 0)", 15771 ut_setup_security, ut_teardown, 15772 test_ipsec_proto_ipv4_copy_dscp_inner_0), 15773 TEST_CASE_NAMED_ST( 15774 "Tunnel header IPv4 copy DSCP (inner 1)", 15775 ut_setup_security, ut_teardown, 15776 test_ipsec_proto_ipv4_copy_dscp_inner_1), 15777 TEST_CASE_NAMED_ST( 15778 "Tunnel header IPv4 set DSCP 0 (inner 1)", 15779 ut_setup_security, ut_teardown, 15780 test_ipsec_proto_ipv4_set_dscp_0_inner_1), 15781 TEST_CASE_NAMED_ST( 15782 "Tunnel header IPv4 set DSCP 1 (inner 0)", 15783 ut_setup_security, ut_teardown, 15784 test_ipsec_proto_ipv4_set_dscp_1_inner_0), 15785 TEST_CASE_NAMED_ST( 15786 "Tunnel header IPv6 copy DSCP (inner 0)", 15787 ut_setup_security, ut_teardown, 15788 test_ipsec_proto_ipv6_copy_dscp_inner_0), 15789 TEST_CASE_NAMED_ST( 15790 "Tunnel header IPv6 copy DSCP (inner 1)", 15791 ut_setup_security, ut_teardown, 15792 test_ipsec_proto_ipv6_copy_dscp_inner_1), 15793 TEST_CASE_NAMED_ST( 15794 "Tunnel header IPv6 set DSCP 0 (inner 1)", 15795 ut_setup_security, ut_teardown, 15796 test_ipsec_proto_ipv6_set_dscp_0_inner_1), 15797 TEST_CASE_NAMED_ST( 15798 "Tunnel header IPv6 set DSCP 1 (inner 0)", 15799 ut_setup_security, ut_teardown, 15800 test_ipsec_proto_ipv6_set_dscp_1_inner_0), 15801 TEST_CASE_NAMED_WITH_DATA( 15802 "Antireplay with window size 1024", 15803 ut_setup_security, ut_teardown, 15804 test_ipsec_proto_pkt_antireplay1024, &pkt_aes_128_gcm), 15805 TEST_CASE_NAMED_WITH_DATA( 15806 "Antireplay with window size 2048", 15807 ut_setup_security, ut_teardown, 15808 test_ipsec_proto_pkt_antireplay2048, &pkt_aes_128_gcm), 15809 TEST_CASE_NAMED_WITH_DATA( 15810 "Antireplay with window size 4096", 15811 ut_setup_security, ut_teardown, 15812 test_ipsec_proto_pkt_antireplay4096, &pkt_aes_128_gcm), 15813 TEST_CASE_NAMED_WITH_DATA( 15814 "ESN and Antireplay with window size 1024", 15815 ut_setup_security, ut_teardown, 15816 test_ipsec_proto_pkt_esn_antireplay1024, 15817 &pkt_aes_128_gcm), 15818 TEST_CASE_NAMED_WITH_DATA( 15819 "ESN and Antireplay with window size 2048", 15820 ut_setup_security, ut_teardown, 15821 test_ipsec_proto_pkt_esn_antireplay2048, 15822 &pkt_aes_128_gcm), 15823 TEST_CASE_NAMED_WITH_DATA( 15824 "ESN and Antireplay with window size 4096", 15825 ut_setup_security, ut_teardown, 15826 test_ipsec_proto_pkt_esn_antireplay4096, 15827 &pkt_aes_128_gcm), 15828 TEST_CASE_NAMED_ST( 15829 "Tunnel header IPv4 decrement inner TTL", 15830 ut_setup_security, ut_teardown, 15831 test_ipsec_proto_ipv4_ttl_decrement), 15832 TEST_CASE_NAMED_ST( 15833 "Tunnel header IPv6 decrement inner hop limit", 15834 ut_setup_security, ut_teardown, 15835 test_ipsec_proto_ipv6_hop_limit_decrement), 15836 TEST_CASE_NAMED_ST( 15837 "Multi-segmented mode", 15838 ut_setup_security, ut_teardown, 15839 test_ipsec_proto_sgl), 15840 TEST_CASES_END() /**< NULL terminate unit test array */ 15841 } 15842 }; 15843 15844 static struct unit_test_suite pdcp_proto_testsuite = { 15845 .suite_name = "PDCP Proto Unit Test Suite", 15846 .setup = pdcp_proto_testsuite_setup, 15847 .unit_test_cases = { 15848 TEST_CASE_ST(ut_setup_security, ut_teardown, 15849 test_PDCP_PROTO_all), 15850 TEST_CASES_END() /**< NULL terminate unit test array */ 15851 } 15852 }; 15853 15854 #define ADD_UPLINK_TESTCASE(data) \ 15855 TEST_CASE_NAMED_WITH_DATA(data.test_descr_uplink, ut_setup_security, \ 15856 ut_teardown, test_docsis_proto_uplink, (const void *) &data), \ 15857 15858 #define ADD_DOWNLINK_TESTCASE(data) \ 15859 TEST_CASE_NAMED_WITH_DATA(data.test_descr_downlink, ut_setup_security, \ 15860 ut_teardown, test_docsis_proto_downlink, (const void *) &data), \ 15861 15862 static struct unit_test_suite docsis_proto_testsuite = { 15863 .suite_name = "DOCSIS Proto Unit Test Suite", 15864 .setup = docsis_proto_testsuite_setup, 15865 .unit_test_cases = { 15866 /* Uplink */ 15867 ADD_UPLINK_TESTCASE(docsis_test_case_1) 15868 ADD_UPLINK_TESTCASE(docsis_test_case_2) 15869 ADD_UPLINK_TESTCASE(docsis_test_case_3) 15870 ADD_UPLINK_TESTCASE(docsis_test_case_4) 15871 ADD_UPLINK_TESTCASE(docsis_test_case_5) 15872 ADD_UPLINK_TESTCASE(docsis_test_case_6) 15873 ADD_UPLINK_TESTCASE(docsis_test_case_7) 15874 ADD_UPLINK_TESTCASE(docsis_test_case_8) 15875 ADD_UPLINK_TESTCASE(docsis_test_case_9) 15876 ADD_UPLINK_TESTCASE(docsis_test_case_10) 15877 ADD_UPLINK_TESTCASE(docsis_test_case_11) 15878 ADD_UPLINK_TESTCASE(docsis_test_case_12) 15879 ADD_UPLINK_TESTCASE(docsis_test_case_13) 15880 ADD_UPLINK_TESTCASE(docsis_test_case_14) 15881 ADD_UPLINK_TESTCASE(docsis_test_case_15) 15882 ADD_UPLINK_TESTCASE(docsis_test_case_16) 15883 ADD_UPLINK_TESTCASE(docsis_test_case_17) 15884 ADD_UPLINK_TESTCASE(docsis_test_case_18) 15885 ADD_UPLINK_TESTCASE(docsis_test_case_19) 15886 ADD_UPLINK_TESTCASE(docsis_test_case_20) 15887 ADD_UPLINK_TESTCASE(docsis_test_case_21) 15888 ADD_UPLINK_TESTCASE(docsis_test_case_22) 15889 ADD_UPLINK_TESTCASE(docsis_test_case_23) 15890 ADD_UPLINK_TESTCASE(docsis_test_case_24) 15891 ADD_UPLINK_TESTCASE(docsis_test_case_25) 15892 ADD_UPLINK_TESTCASE(docsis_test_case_26) 15893 /* Downlink */ 15894 ADD_DOWNLINK_TESTCASE(docsis_test_case_1) 15895 ADD_DOWNLINK_TESTCASE(docsis_test_case_2) 15896 ADD_DOWNLINK_TESTCASE(docsis_test_case_3) 15897 ADD_DOWNLINK_TESTCASE(docsis_test_case_4) 15898 ADD_DOWNLINK_TESTCASE(docsis_test_case_5) 15899 ADD_DOWNLINK_TESTCASE(docsis_test_case_6) 15900 ADD_DOWNLINK_TESTCASE(docsis_test_case_7) 15901 ADD_DOWNLINK_TESTCASE(docsis_test_case_8) 15902 ADD_DOWNLINK_TESTCASE(docsis_test_case_9) 15903 ADD_DOWNLINK_TESTCASE(docsis_test_case_10) 15904 ADD_DOWNLINK_TESTCASE(docsis_test_case_11) 15905 ADD_DOWNLINK_TESTCASE(docsis_test_case_12) 15906 ADD_DOWNLINK_TESTCASE(docsis_test_case_13) 15907 ADD_DOWNLINK_TESTCASE(docsis_test_case_14) 15908 ADD_DOWNLINK_TESTCASE(docsis_test_case_15) 15909 ADD_DOWNLINK_TESTCASE(docsis_test_case_16) 15910 ADD_DOWNLINK_TESTCASE(docsis_test_case_17) 15911 ADD_DOWNLINK_TESTCASE(docsis_test_case_18) 15912 ADD_DOWNLINK_TESTCASE(docsis_test_case_19) 15913 ADD_DOWNLINK_TESTCASE(docsis_test_case_20) 15914 ADD_DOWNLINK_TESTCASE(docsis_test_case_21) 15915 ADD_DOWNLINK_TESTCASE(docsis_test_case_22) 15916 ADD_DOWNLINK_TESTCASE(docsis_test_case_23) 15917 ADD_DOWNLINK_TESTCASE(docsis_test_case_24) 15918 ADD_DOWNLINK_TESTCASE(docsis_test_case_25) 15919 ADD_DOWNLINK_TESTCASE(docsis_test_case_26) 15920 TEST_CASES_END() /**< NULL terminate unit test array */ 15921 } 15922 }; 15923 #endif 15924 15925 static struct unit_test_suite cryptodev_gen_testsuite = { 15926 .suite_name = "Crypto General Unit Test Suite", 15927 .setup = crypto_gen_testsuite_setup, 15928 .unit_test_cases = { 15929 TEST_CASE_ST(ut_setup, ut_teardown, 15930 test_device_configure_invalid_dev_id), 15931 TEST_CASE_ST(ut_setup, ut_teardown, 15932 test_queue_pair_descriptor_setup), 15933 TEST_CASE_ST(ut_setup, ut_teardown, 15934 test_device_configure_invalid_queue_pair_ids), 15935 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 15936 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup), 15937 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup), 15938 TEST_CASES_END() /**< NULL terminate unit test array */ 15939 } 15940 }; 15941 15942 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = { 15943 .suite_name = "Negative HMAC SHA1 Unit Test Suite", 15944 .setup = negative_hmac_sha1_testsuite_setup, 15945 .unit_test_cases = { 15946 /** Negative tests */ 15947 TEST_CASE_ST(ut_setup, ut_teardown, 15948 authentication_verify_HMAC_SHA1_fail_data_corrupt), 15949 TEST_CASE_ST(ut_setup, ut_teardown, 15950 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 15951 TEST_CASE_ST(ut_setup, ut_teardown, 15952 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 15953 TEST_CASE_ST(ut_setup, ut_teardown, 15954 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 15955 15956 TEST_CASES_END() /**< NULL terminate unit test array */ 15957 } 15958 }; 15959 15960 static struct unit_test_suite cryptodev_multi_session_testsuite = { 15961 .suite_name = "Multi Session Unit Test Suite", 15962 .setup = multi_session_testsuite_setup, 15963 .unit_test_cases = { 15964 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 15965 TEST_CASE_ST(ut_setup, ut_teardown, 15966 test_multi_session_random_usage), 15967 15968 TEST_CASES_END() /**< NULL terminate unit test array */ 15969 } 15970 }; 15971 15972 static struct unit_test_suite cryptodev_null_testsuite = { 15973 .suite_name = "NULL Test Suite", 15974 .setup = null_testsuite_setup, 15975 .unit_test_cases = { 15976 TEST_CASE_ST(ut_setup, ut_teardown, 15977 test_null_invalid_operation), 15978 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation), 15979 TEST_CASES_END() 15980 } 15981 }; 15982 15983 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite = { 15984 .suite_name = "AES CCM Authenticated Test Suite", 15985 .setup = aes_ccm_auth_testsuite_setup, 15986 .unit_test_cases = { 15987 /** AES CCM Authenticated Encryption 128 bits key*/ 15988 TEST_CASE_ST(ut_setup, ut_teardown, 15989 test_AES_CCM_authenticated_encryption_test_case_128_1), 15990 TEST_CASE_ST(ut_setup, ut_teardown, 15991 test_AES_CCM_authenticated_encryption_test_case_128_2), 15992 TEST_CASE_ST(ut_setup, ut_teardown, 15993 test_AES_CCM_authenticated_encryption_test_case_128_3), 15994 15995 /** AES CCM Authenticated Decryption 128 bits key*/ 15996 TEST_CASE_ST(ut_setup, ut_teardown, 15997 test_AES_CCM_authenticated_decryption_test_case_128_1), 15998 TEST_CASE_ST(ut_setup, ut_teardown, 15999 test_AES_CCM_authenticated_decryption_test_case_128_2), 16000 TEST_CASE_ST(ut_setup, ut_teardown, 16001 test_AES_CCM_authenticated_decryption_test_case_128_3), 16002 16003 /** AES CCM Authenticated Encryption 192 bits key */ 16004 TEST_CASE_ST(ut_setup, ut_teardown, 16005 test_AES_CCM_authenticated_encryption_test_case_192_1), 16006 TEST_CASE_ST(ut_setup, ut_teardown, 16007 test_AES_CCM_authenticated_encryption_test_case_192_2), 16008 TEST_CASE_ST(ut_setup, ut_teardown, 16009 test_AES_CCM_authenticated_encryption_test_case_192_3), 16010 16011 /** AES CCM Authenticated Decryption 192 bits key*/ 16012 TEST_CASE_ST(ut_setup, ut_teardown, 16013 test_AES_CCM_authenticated_decryption_test_case_192_1), 16014 TEST_CASE_ST(ut_setup, ut_teardown, 16015 test_AES_CCM_authenticated_decryption_test_case_192_2), 16016 TEST_CASE_ST(ut_setup, ut_teardown, 16017 test_AES_CCM_authenticated_decryption_test_case_192_3), 16018 16019 /** AES CCM Authenticated Encryption 256 bits key */ 16020 TEST_CASE_ST(ut_setup, ut_teardown, 16021 test_AES_CCM_authenticated_encryption_test_case_256_1), 16022 TEST_CASE_ST(ut_setup, ut_teardown, 16023 test_AES_CCM_authenticated_encryption_test_case_256_2), 16024 TEST_CASE_ST(ut_setup, ut_teardown, 16025 test_AES_CCM_authenticated_encryption_test_case_256_3), 16026 16027 /** AES CCM Authenticated Decryption 256 bits key*/ 16028 TEST_CASE_ST(ut_setup, ut_teardown, 16029 test_AES_CCM_authenticated_decryption_test_case_256_1), 16030 TEST_CASE_ST(ut_setup, ut_teardown, 16031 test_AES_CCM_authenticated_decryption_test_case_256_2), 16032 TEST_CASE_ST(ut_setup, ut_teardown, 16033 test_AES_CCM_authenticated_decryption_test_case_256_3), 16034 TEST_CASES_END() 16035 } 16036 }; 16037 16038 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite = { 16039 .suite_name = "AES GCM Authenticated Test Suite", 16040 .setup = aes_gcm_auth_testsuite_setup, 16041 .unit_test_cases = { 16042 /** AES GCM Authenticated Encryption */ 16043 TEST_CASE_ST(ut_setup, ut_teardown, 16044 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 16045 TEST_CASE_ST(ut_setup, ut_teardown, 16046 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 16047 TEST_CASE_ST(ut_setup, ut_teardown, 16048 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 16049 TEST_CASE_ST(ut_setup, ut_teardown, 16050 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 16051 TEST_CASE_ST(ut_setup, ut_teardown, 16052 test_AES_GCM_authenticated_encryption_test_case_1), 16053 TEST_CASE_ST(ut_setup, ut_teardown, 16054 test_AES_GCM_authenticated_encryption_test_case_2), 16055 TEST_CASE_ST(ut_setup, ut_teardown, 16056 test_AES_GCM_authenticated_encryption_test_case_3), 16057 TEST_CASE_ST(ut_setup, ut_teardown, 16058 test_AES_GCM_authenticated_encryption_test_case_4), 16059 TEST_CASE_ST(ut_setup, ut_teardown, 16060 test_AES_GCM_authenticated_encryption_test_case_5), 16061 TEST_CASE_ST(ut_setup, ut_teardown, 16062 test_AES_GCM_authenticated_encryption_test_case_6), 16063 TEST_CASE_ST(ut_setup, ut_teardown, 16064 test_AES_GCM_authenticated_encryption_test_case_7), 16065 TEST_CASE_ST(ut_setup, ut_teardown, 16066 test_AES_GCM_authenticated_encryption_test_case_8), 16067 TEST_CASE_ST(ut_setup, ut_teardown, 16068 test_AES_GCM_J0_authenticated_encryption_test_case_1), 16069 16070 /** AES GCM Authenticated Decryption */ 16071 TEST_CASE_ST(ut_setup, ut_teardown, 16072 test_AES_GCM_authenticated_decryption_test_case_1), 16073 TEST_CASE_ST(ut_setup, ut_teardown, 16074 test_AES_GCM_authenticated_decryption_test_case_2), 16075 TEST_CASE_ST(ut_setup, ut_teardown, 16076 test_AES_GCM_authenticated_decryption_test_case_3), 16077 TEST_CASE_ST(ut_setup, ut_teardown, 16078 test_AES_GCM_authenticated_decryption_test_case_4), 16079 TEST_CASE_ST(ut_setup, ut_teardown, 16080 test_AES_GCM_authenticated_decryption_test_case_5), 16081 TEST_CASE_ST(ut_setup, ut_teardown, 16082 test_AES_GCM_authenticated_decryption_test_case_6), 16083 TEST_CASE_ST(ut_setup, ut_teardown, 16084 test_AES_GCM_authenticated_decryption_test_case_7), 16085 TEST_CASE_ST(ut_setup, ut_teardown, 16086 test_AES_GCM_authenticated_decryption_test_case_8), 16087 TEST_CASE_ST(ut_setup, ut_teardown, 16088 test_AES_GCM_J0_authenticated_decryption_test_case_1), 16089 16090 /** AES GCM Authenticated Encryption 192 bits key */ 16091 TEST_CASE_ST(ut_setup, ut_teardown, 16092 test_AES_GCM_auth_encryption_test_case_192_1), 16093 TEST_CASE_ST(ut_setup, ut_teardown, 16094 test_AES_GCM_auth_encryption_test_case_192_2), 16095 TEST_CASE_ST(ut_setup, ut_teardown, 16096 test_AES_GCM_auth_encryption_test_case_192_3), 16097 TEST_CASE_ST(ut_setup, ut_teardown, 16098 test_AES_GCM_auth_encryption_test_case_192_4), 16099 TEST_CASE_ST(ut_setup, ut_teardown, 16100 test_AES_GCM_auth_encryption_test_case_192_5), 16101 TEST_CASE_ST(ut_setup, ut_teardown, 16102 test_AES_GCM_auth_encryption_test_case_192_6), 16103 TEST_CASE_ST(ut_setup, ut_teardown, 16104 test_AES_GCM_auth_encryption_test_case_192_7), 16105 16106 /** AES GCM Authenticated Decryption 192 bits key */ 16107 TEST_CASE_ST(ut_setup, ut_teardown, 16108 test_AES_GCM_auth_decryption_test_case_192_1), 16109 TEST_CASE_ST(ut_setup, ut_teardown, 16110 test_AES_GCM_auth_decryption_test_case_192_2), 16111 TEST_CASE_ST(ut_setup, ut_teardown, 16112 test_AES_GCM_auth_decryption_test_case_192_3), 16113 TEST_CASE_ST(ut_setup, ut_teardown, 16114 test_AES_GCM_auth_decryption_test_case_192_4), 16115 TEST_CASE_ST(ut_setup, ut_teardown, 16116 test_AES_GCM_auth_decryption_test_case_192_5), 16117 TEST_CASE_ST(ut_setup, ut_teardown, 16118 test_AES_GCM_auth_decryption_test_case_192_6), 16119 TEST_CASE_ST(ut_setup, ut_teardown, 16120 test_AES_GCM_auth_decryption_test_case_192_7), 16121 16122 /** AES GCM Authenticated Encryption 256 bits key */ 16123 TEST_CASE_ST(ut_setup, ut_teardown, 16124 test_AES_GCM_auth_encryption_test_case_256_1), 16125 TEST_CASE_ST(ut_setup, ut_teardown, 16126 test_AES_GCM_auth_encryption_test_case_256_2), 16127 TEST_CASE_ST(ut_setup, ut_teardown, 16128 test_AES_GCM_auth_encryption_test_case_256_3), 16129 TEST_CASE_ST(ut_setup, ut_teardown, 16130 test_AES_GCM_auth_encryption_test_case_256_4), 16131 TEST_CASE_ST(ut_setup, ut_teardown, 16132 test_AES_GCM_auth_encryption_test_case_256_5), 16133 TEST_CASE_ST(ut_setup, ut_teardown, 16134 test_AES_GCM_auth_encryption_test_case_256_6), 16135 TEST_CASE_ST(ut_setup, ut_teardown, 16136 test_AES_GCM_auth_encryption_test_case_256_7), 16137 16138 /** AES GCM Authenticated Decryption 256 bits key */ 16139 TEST_CASE_ST(ut_setup, ut_teardown, 16140 test_AES_GCM_auth_decryption_test_case_256_1), 16141 TEST_CASE_ST(ut_setup, ut_teardown, 16142 test_AES_GCM_auth_decryption_test_case_256_2), 16143 TEST_CASE_ST(ut_setup, ut_teardown, 16144 test_AES_GCM_auth_decryption_test_case_256_3), 16145 TEST_CASE_ST(ut_setup, ut_teardown, 16146 test_AES_GCM_auth_decryption_test_case_256_4), 16147 TEST_CASE_ST(ut_setup, ut_teardown, 16148 test_AES_GCM_auth_decryption_test_case_256_5), 16149 TEST_CASE_ST(ut_setup, ut_teardown, 16150 test_AES_GCM_auth_decryption_test_case_256_6), 16151 TEST_CASE_ST(ut_setup, ut_teardown, 16152 test_AES_GCM_auth_decryption_test_case_256_7), 16153 16154 /** AES GCM Authenticated Encryption big aad size */ 16155 TEST_CASE_ST(ut_setup, ut_teardown, 16156 test_AES_GCM_auth_encryption_test_case_aad_1), 16157 TEST_CASE_ST(ut_setup, ut_teardown, 16158 test_AES_GCM_auth_encryption_test_case_aad_2), 16159 16160 /** AES GCM Authenticated Decryption big aad size */ 16161 TEST_CASE_ST(ut_setup, ut_teardown, 16162 test_AES_GCM_auth_decryption_test_case_aad_1), 16163 TEST_CASE_ST(ut_setup, ut_teardown, 16164 test_AES_GCM_auth_decryption_test_case_aad_2), 16165 16166 /** Out of place tests */ 16167 TEST_CASE_ST(ut_setup, ut_teardown, 16168 test_AES_GCM_authenticated_encryption_oop_test_case_1), 16169 TEST_CASE_ST(ut_setup, ut_teardown, 16170 test_AES_GCM_authenticated_decryption_oop_test_case_1), 16171 16172 /** Session-less tests */ 16173 TEST_CASE_ST(ut_setup, ut_teardown, 16174 test_AES_GCM_authenticated_encryption_sessionless_test_case_1), 16175 TEST_CASE_ST(ut_setup, ut_teardown, 16176 test_AES_GCM_authenticated_decryption_sessionless_test_case_1), 16177 16178 TEST_CASES_END() 16179 } 16180 }; 16181 16182 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite = { 16183 .suite_name = "AES GMAC Authentication Test Suite", 16184 .setup = aes_gmac_auth_testsuite_setup, 16185 .unit_test_cases = { 16186 TEST_CASE_ST(ut_setup, ut_teardown, 16187 test_AES_GMAC_authentication_test_case_1), 16188 TEST_CASE_ST(ut_setup, ut_teardown, 16189 test_AES_GMAC_authentication_verify_test_case_1), 16190 TEST_CASE_ST(ut_setup, ut_teardown, 16191 test_AES_GMAC_authentication_test_case_2), 16192 TEST_CASE_ST(ut_setup, ut_teardown, 16193 test_AES_GMAC_authentication_verify_test_case_2), 16194 TEST_CASE_ST(ut_setup, ut_teardown, 16195 test_AES_GMAC_authentication_test_case_3), 16196 TEST_CASE_ST(ut_setup, ut_teardown, 16197 test_AES_GMAC_authentication_verify_test_case_3), 16198 TEST_CASE_ST(ut_setup, ut_teardown, 16199 test_AES_GMAC_authentication_test_case_4), 16200 TEST_CASE_ST(ut_setup, ut_teardown, 16201 test_AES_GMAC_authentication_verify_test_case_4), 16202 TEST_CASE_ST(ut_setup, ut_teardown, 16203 test_AES_GMAC_authentication_SGL_40B), 16204 TEST_CASE_ST(ut_setup, ut_teardown, 16205 test_AES_GMAC_authentication_SGL_80B), 16206 TEST_CASE_ST(ut_setup, ut_teardown, 16207 test_AES_GMAC_authentication_SGL_2048B), 16208 TEST_CASE_ST(ut_setup, ut_teardown, 16209 test_AES_GMAC_authentication_SGL_2047B), 16210 16211 TEST_CASES_END() 16212 } 16213 }; 16214 16215 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite = { 16216 .suite_name = "Chacha20-Poly1305 Test Suite", 16217 .setup = chacha20_poly1305_testsuite_setup, 16218 .unit_test_cases = { 16219 TEST_CASE_ST(ut_setup, ut_teardown, 16220 test_chacha20_poly1305_encrypt_test_case_rfc8439), 16221 TEST_CASE_ST(ut_setup, ut_teardown, 16222 test_chacha20_poly1305_decrypt_test_case_rfc8439), 16223 TEST_CASE_ST(ut_setup, ut_teardown, 16224 test_chacha20_poly1305_encrypt_SGL_out_of_place), 16225 TEST_CASES_END() 16226 } 16227 }; 16228 16229 static struct unit_test_suite cryptodev_snow3g_testsuite = { 16230 .suite_name = "SNOW 3G Test Suite", 16231 .setup = snow3g_testsuite_setup, 16232 .unit_test_cases = { 16233 /** SNOW 3G encrypt only (UEA2) */ 16234 TEST_CASE_ST(ut_setup, ut_teardown, 16235 test_snow3g_encryption_test_case_1), 16236 TEST_CASE_ST(ut_setup, ut_teardown, 16237 test_snow3g_encryption_test_case_2), 16238 TEST_CASE_ST(ut_setup, ut_teardown, 16239 test_snow3g_encryption_test_case_3), 16240 TEST_CASE_ST(ut_setup, ut_teardown, 16241 test_snow3g_encryption_test_case_4), 16242 TEST_CASE_ST(ut_setup, ut_teardown, 16243 test_snow3g_encryption_test_case_5), 16244 16245 TEST_CASE_ST(ut_setup, ut_teardown, 16246 test_snow3g_encryption_test_case_1_oop), 16247 TEST_CASE_ST(ut_setup, ut_teardown, 16248 test_snow3g_encryption_test_case_1_oop_sgl), 16249 TEST_CASE_ST(ut_setup, ut_teardown, 16250 test_snow3g_encryption_test_case_1_oop_lb_in_sgl_out), 16251 TEST_CASE_ST(ut_setup, ut_teardown, 16252 test_snow3g_encryption_test_case_1_oop_sgl_in_lb_out), 16253 TEST_CASE_ST(ut_setup, ut_teardown, 16254 test_snow3g_encryption_test_case_1_offset_oop), 16255 TEST_CASE_ST(ut_setup, ut_teardown, 16256 test_snow3g_decryption_test_case_1_oop), 16257 16258 /** SNOW 3G generate auth, then encrypt (UEA2) */ 16259 TEST_CASE_ST(ut_setup, ut_teardown, 16260 test_snow3g_auth_cipher_test_case_1), 16261 TEST_CASE_ST(ut_setup, ut_teardown, 16262 test_snow3g_auth_cipher_test_case_2), 16263 TEST_CASE_ST(ut_setup, ut_teardown, 16264 test_snow3g_auth_cipher_test_case_2_oop), 16265 TEST_CASE_ST(ut_setup, ut_teardown, 16266 test_snow3g_auth_cipher_part_digest_enc), 16267 TEST_CASE_ST(ut_setup, ut_teardown, 16268 test_snow3g_auth_cipher_part_digest_enc_oop), 16269 TEST_CASE_ST(ut_setup, ut_teardown, 16270 test_snow3g_auth_cipher_test_case_3_sgl), 16271 TEST_CASE_ST(ut_setup, ut_teardown, 16272 test_snow3g_auth_cipher_test_case_3_oop_sgl), 16273 TEST_CASE_ST(ut_setup, ut_teardown, 16274 test_snow3g_auth_cipher_part_digest_enc_sgl), 16275 TEST_CASE_ST(ut_setup, ut_teardown, 16276 test_snow3g_auth_cipher_part_digest_enc_oop_sgl), 16277 TEST_CASE_ST(ut_setup, ut_teardown, 16278 test_snow3g_auth_cipher_total_digest_enc_1), 16279 TEST_CASE_ST(ut_setup, ut_teardown, 16280 test_snow3g_auth_cipher_total_digest_enc_1_oop), 16281 TEST_CASE_ST(ut_setup, ut_teardown, 16282 test_snow3g_auth_cipher_total_digest_enc_1_sgl), 16283 TEST_CASE_ST(ut_setup, ut_teardown, 16284 test_snow3g_auth_cipher_total_digest_enc_1_oop_sgl), 16285 16286 /** SNOW 3G decrypt (UEA2), then verify auth */ 16287 TEST_CASE_ST(ut_setup, ut_teardown, 16288 test_snow3g_auth_cipher_verify_test_case_1), 16289 TEST_CASE_ST(ut_setup, ut_teardown, 16290 test_snow3g_auth_cipher_verify_test_case_2), 16291 TEST_CASE_ST(ut_setup, ut_teardown, 16292 test_snow3g_auth_cipher_verify_test_case_2_oop), 16293 TEST_CASE_ST(ut_setup, ut_teardown, 16294 test_snow3g_auth_cipher_verify_part_digest_enc), 16295 TEST_CASE_ST(ut_setup, ut_teardown, 16296 test_snow3g_auth_cipher_verify_part_digest_enc_oop), 16297 TEST_CASE_ST(ut_setup, ut_teardown, 16298 test_snow3g_auth_cipher_verify_test_case_3_sgl), 16299 TEST_CASE_ST(ut_setup, ut_teardown, 16300 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl), 16301 TEST_CASE_ST(ut_setup, ut_teardown, 16302 test_snow3g_auth_cipher_verify_part_digest_enc_sgl), 16303 TEST_CASE_ST(ut_setup, ut_teardown, 16304 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl), 16305 TEST_CASE_ST(ut_setup, ut_teardown, 16306 test_snow3g_auth_cipher_verify_total_digest_enc_1), 16307 TEST_CASE_ST(ut_setup, ut_teardown, 16308 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop), 16309 TEST_CASE_ST(ut_setup, ut_teardown, 16310 test_snow3g_auth_cipher_verify_total_digest_enc_1_sgl), 16311 TEST_CASE_ST(ut_setup, ut_teardown, 16312 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop_sgl), 16313 16314 /** SNOW 3G decrypt only (UEA2) */ 16315 TEST_CASE_ST(ut_setup, ut_teardown, 16316 test_snow3g_decryption_test_case_1), 16317 TEST_CASE_ST(ut_setup, ut_teardown, 16318 test_snow3g_decryption_test_case_2), 16319 TEST_CASE_ST(ut_setup, ut_teardown, 16320 test_snow3g_decryption_test_case_3), 16321 TEST_CASE_ST(ut_setup, ut_teardown, 16322 test_snow3g_decryption_test_case_4), 16323 TEST_CASE_ST(ut_setup, ut_teardown, 16324 test_snow3g_decryption_test_case_5), 16325 TEST_CASE_ST(ut_setup, ut_teardown, 16326 test_snow3g_decryption_with_digest_test_case_1), 16327 TEST_CASE_ST(ut_setup, ut_teardown, 16328 test_snow3g_hash_generate_test_case_1), 16329 TEST_CASE_ST(ut_setup, ut_teardown, 16330 test_snow3g_hash_generate_test_case_2), 16331 TEST_CASE_ST(ut_setup, ut_teardown, 16332 test_snow3g_hash_generate_test_case_3), 16333 16334 /* Tests with buffers which length is not byte-aligned */ 16335 TEST_CASE_ST(ut_setup, ut_teardown, 16336 test_snow3g_hash_generate_test_case_4), 16337 TEST_CASE_ST(ut_setup, ut_teardown, 16338 test_snow3g_hash_generate_test_case_5), 16339 TEST_CASE_ST(ut_setup, ut_teardown, 16340 test_snow3g_hash_generate_test_case_6), 16341 TEST_CASE_ST(ut_setup, ut_teardown, 16342 test_snow3g_hash_verify_test_case_1), 16343 TEST_CASE_ST(ut_setup, ut_teardown, 16344 test_snow3g_hash_verify_test_case_2), 16345 TEST_CASE_ST(ut_setup, ut_teardown, 16346 test_snow3g_hash_verify_test_case_3), 16347 16348 /* Tests with buffers which length is not byte-aligned */ 16349 TEST_CASE_ST(ut_setup, ut_teardown, 16350 test_snow3g_hash_verify_test_case_4), 16351 TEST_CASE_ST(ut_setup, ut_teardown, 16352 test_snow3g_hash_verify_test_case_5), 16353 TEST_CASE_ST(ut_setup, ut_teardown, 16354 test_snow3g_hash_verify_test_case_6), 16355 TEST_CASE_ST(ut_setup, ut_teardown, 16356 test_snow3g_cipher_auth_test_case_1), 16357 TEST_CASE_ST(ut_setup, ut_teardown, 16358 test_snow3g_auth_cipher_with_digest_test_case_1), 16359 TEST_CASES_END() 16360 } 16361 }; 16362 16363 static struct unit_test_suite cryptodev_zuc_testsuite = { 16364 .suite_name = "ZUC Test Suite", 16365 .setup = zuc_testsuite_setup, 16366 .unit_test_cases = { 16367 /** ZUC encrypt only (EEA3) */ 16368 TEST_CASE_ST(ut_setup, ut_teardown, 16369 test_zuc_encryption_test_case_1), 16370 TEST_CASE_ST(ut_setup, ut_teardown, 16371 test_zuc_encryption_test_case_2), 16372 TEST_CASE_ST(ut_setup, ut_teardown, 16373 test_zuc_encryption_test_case_3), 16374 TEST_CASE_ST(ut_setup, ut_teardown, 16375 test_zuc_encryption_test_case_4), 16376 TEST_CASE_ST(ut_setup, ut_teardown, 16377 test_zuc_encryption_test_case_5), 16378 TEST_CASE_ST(ut_setup, ut_teardown, 16379 test_zuc_encryption_test_case_6_sgl), 16380 16381 /** ZUC decrypt only (EEA3) */ 16382 TEST_CASE_ST(ut_setup, ut_teardown, 16383 test_zuc_decryption_test_case_1), 16384 TEST_CASE_ST(ut_setup, ut_teardown, 16385 test_zuc_decryption_test_case_2), 16386 TEST_CASE_ST(ut_setup, ut_teardown, 16387 test_zuc_decryption_test_case_3), 16388 TEST_CASE_ST(ut_setup, ut_teardown, 16389 test_zuc_decryption_test_case_4), 16390 TEST_CASE_ST(ut_setup, ut_teardown, 16391 test_zuc_decryption_test_case_5), 16392 TEST_CASE_ST(ut_setup, ut_teardown, 16393 test_zuc_decryption_test_case_6_sgl), 16394 16395 /** ZUC authenticate (EIA3) */ 16396 TEST_CASE_ST(ut_setup, ut_teardown, 16397 test_zuc_hash_generate_test_case_1), 16398 TEST_CASE_ST(ut_setup, ut_teardown, 16399 test_zuc_hash_generate_test_case_2), 16400 TEST_CASE_ST(ut_setup, ut_teardown, 16401 test_zuc_hash_generate_test_case_3), 16402 TEST_CASE_ST(ut_setup, ut_teardown, 16403 test_zuc_hash_generate_test_case_4), 16404 TEST_CASE_ST(ut_setup, ut_teardown, 16405 test_zuc_hash_generate_test_case_5), 16406 TEST_CASE_ST(ut_setup, ut_teardown, 16407 test_zuc_hash_generate_test_case_6), 16408 TEST_CASE_ST(ut_setup, ut_teardown, 16409 test_zuc_hash_generate_test_case_7), 16410 TEST_CASE_ST(ut_setup, ut_teardown, 16411 test_zuc_hash_generate_test_case_8), 16412 16413 /** ZUC verify (EIA3) */ 16414 TEST_CASE_ST(ut_setup, ut_teardown, 16415 test_zuc_hash_verify_test_case_1), 16416 TEST_CASE_ST(ut_setup, ut_teardown, 16417 test_zuc_hash_verify_test_case_2), 16418 TEST_CASE_ST(ut_setup, ut_teardown, 16419 test_zuc_hash_verify_test_case_3), 16420 TEST_CASE_ST(ut_setup, ut_teardown, 16421 test_zuc_hash_verify_test_case_4), 16422 TEST_CASE_ST(ut_setup, ut_teardown, 16423 test_zuc_hash_verify_test_case_5), 16424 TEST_CASE_ST(ut_setup, ut_teardown, 16425 test_zuc_hash_verify_test_case_6), 16426 TEST_CASE_ST(ut_setup, ut_teardown, 16427 test_zuc_hash_verify_test_case_7), 16428 TEST_CASE_ST(ut_setup, ut_teardown, 16429 test_zuc_hash_verify_test_case_8), 16430 16431 /** ZUC alg-chain (EEA3/EIA3) */ 16432 TEST_CASE_ST(ut_setup, ut_teardown, 16433 test_zuc_cipher_auth_test_case_1), 16434 TEST_CASE_ST(ut_setup, ut_teardown, 16435 test_zuc_cipher_auth_test_case_2), 16436 16437 /** ZUC generate auth, then encrypt (EEA3) */ 16438 TEST_CASE_ST(ut_setup, ut_teardown, 16439 test_zuc_auth_cipher_test_case_1), 16440 TEST_CASE_ST(ut_setup, ut_teardown, 16441 test_zuc_auth_cipher_test_case_1_oop), 16442 TEST_CASE_ST(ut_setup, ut_teardown, 16443 test_zuc_auth_cipher_test_case_1_sgl), 16444 TEST_CASE_ST(ut_setup, ut_teardown, 16445 test_zuc_auth_cipher_test_case_1_oop_sgl), 16446 TEST_CASE_ST(ut_setup, ut_teardown, 16447 test_zuc_auth_cipher_test_case_2), 16448 TEST_CASE_ST(ut_setup, ut_teardown, 16449 test_zuc_auth_cipher_test_case_2_oop), 16450 16451 /** ZUC decrypt (EEA3), then verify auth */ 16452 TEST_CASE_ST(ut_setup, ut_teardown, 16453 test_zuc_auth_cipher_verify_test_case_1), 16454 TEST_CASE_ST(ut_setup, ut_teardown, 16455 test_zuc_auth_cipher_verify_test_case_1_oop), 16456 TEST_CASE_ST(ut_setup, ut_teardown, 16457 test_zuc_auth_cipher_verify_test_case_1_sgl), 16458 TEST_CASE_ST(ut_setup, ut_teardown, 16459 test_zuc_auth_cipher_verify_test_case_1_oop_sgl), 16460 TEST_CASE_ST(ut_setup, ut_teardown, 16461 test_zuc_auth_cipher_verify_test_case_2), 16462 TEST_CASE_ST(ut_setup, ut_teardown, 16463 test_zuc_auth_cipher_verify_test_case_2_oop), 16464 16465 /** ZUC-256 encrypt only **/ 16466 TEST_CASE_ST(ut_setup, ut_teardown, 16467 test_zuc256_encryption_test_case_1), 16468 TEST_CASE_ST(ut_setup, ut_teardown, 16469 test_zuc256_encryption_test_case_2), 16470 16471 /** ZUC-256 decrypt only **/ 16472 TEST_CASE_ST(ut_setup, ut_teardown, 16473 test_zuc256_decryption_test_case_1), 16474 TEST_CASE_ST(ut_setup, ut_teardown, 16475 test_zuc256_decryption_test_case_2), 16476 16477 /** ZUC-256 authentication only **/ 16478 TEST_CASE_ST(ut_setup, ut_teardown, 16479 test_zuc256_hash_generate_4b_tag_test_case_1), 16480 TEST_CASE_ST(ut_setup, ut_teardown, 16481 test_zuc256_hash_generate_4b_tag_test_case_2), 16482 TEST_CASE_ST(ut_setup, ut_teardown, 16483 test_zuc256_hash_generate_4b_tag_test_case_3), 16484 TEST_CASE_ST(ut_setup, ut_teardown, 16485 test_zuc256_hash_generate_8b_tag_test_case_1), 16486 TEST_CASE_ST(ut_setup, ut_teardown, 16487 test_zuc256_hash_generate_16b_tag_test_case_1), 16488 16489 /** ZUC-256 authentication verify only **/ 16490 TEST_CASE_ST(ut_setup, ut_teardown, 16491 test_zuc256_hash_verify_4b_tag_test_case_1), 16492 TEST_CASE_ST(ut_setup, ut_teardown, 16493 test_zuc256_hash_verify_4b_tag_test_case_2), 16494 TEST_CASE_ST(ut_setup, ut_teardown, 16495 test_zuc256_hash_verify_4b_tag_test_case_3), 16496 TEST_CASE_ST(ut_setup, ut_teardown, 16497 test_zuc256_hash_verify_8b_tag_test_case_1), 16498 TEST_CASE_ST(ut_setup, ut_teardown, 16499 test_zuc256_hash_verify_16b_tag_test_case_1), 16500 16501 TEST_CASES_END() 16502 } 16503 }; 16504 16505 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite = { 16506 .suite_name = "HMAC_MD5 Authentication Test Suite", 16507 .setup = hmac_md5_auth_testsuite_setup, 16508 .unit_test_cases = { 16509 TEST_CASE_ST(ut_setup, ut_teardown, 16510 test_MD5_HMAC_generate_case_1), 16511 TEST_CASE_ST(ut_setup, ut_teardown, 16512 test_MD5_HMAC_verify_case_1), 16513 TEST_CASE_ST(ut_setup, ut_teardown, 16514 test_MD5_HMAC_generate_case_2), 16515 TEST_CASE_ST(ut_setup, ut_teardown, 16516 test_MD5_HMAC_verify_case_2), 16517 TEST_CASES_END() 16518 } 16519 }; 16520 16521 static struct unit_test_suite cryptodev_kasumi_testsuite = { 16522 .suite_name = "Kasumi Test Suite", 16523 .setup = kasumi_testsuite_setup, 16524 .unit_test_cases = { 16525 /** KASUMI hash only (UIA1) */ 16526 TEST_CASE_ST(ut_setup, ut_teardown, 16527 test_kasumi_hash_generate_test_case_1), 16528 TEST_CASE_ST(ut_setup, ut_teardown, 16529 test_kasumi_hash_generate_test_case_2), 16530 TEST_CASE_ST(ut_setup, ut_teardown, 16531 test_kasumi_hash_generate_test_case_3), 16532 TEST_CASE_ST(ut_setup, ut_teardown, 16533 test_kasumi_hash_generate_test_case_4), 16534 TEST_CASE_ST(ut_setup, ut_teardown, 16535 test_kasumi_hash_generate_test_case_5), 16536 TEST_CASE_ST(ut_setup, ut_teardown, 16537 test_kasumi_hash_generate_test_case_6), 16538 16539 TEST_CASE_ST(ut_setup, ut_teardown, 16540 test_kasumi_hash_verify_test_case_1), 16541 TEST_CASE_ST(ut_setup, ut_teardown, 16542 test_kasumi_hash_verify_test_case_2), 16543 TEST_CASE_ST(ut_setup, ut_teardown, 16544 test_kasumi_hash_verify_test_case_3), 16545 TEST_CASE_ST(ut_setup, ut_teardown, 16546 test_kasumi_hash_verify_test_case_4), 16547 TEST_CASE_ST(ut_setup, ut_teardown, 16548 test_kasumi_hash_verify_test_case_5), 16549 16550 /** KASUMI encrypt only (UEA1) */ 16551 TEST_CASE_ST(ut_setup, ut_teardown, 16552 test_kasumi_encryption_test_case_1), 16553 TEST_CASE_ST(ut_setup, ut_teardown, 16554 test_kasumi_encryption_test_case_1_sgl), 16555 TEST_CASE_ST(ut_setup, ut_teardown, 16556 test_kasumi_encryption_test_case_1_oop), 16557 TEST_CASE_ST(ut_setup, ut_teardown, 16558 test_kasumi_encryption_test_case_1_oop_sgl), 16559 TEST_CASE_ST(ut_setup, ut_teardown, 16560 test_kasumi_encryption_test_case_2), 16561 TEST_CASE_ST(ut_setup, ut_teardown, 16562 test_kasumi_encryption_test_case_3), 16563 TEST_CASE_ST(ut_setup, ut_teardown, 16564 test_kasumi_encryption_test_case_4), 16565 TEST_CASE_ST(ut_setup, ut_teardown, 16566 test_kasumi_encryption_test_case_5), 16567 16568 /** KASUMI decrypt only (UEA1) */ 16569 TEST_CASE_ST(ut_setup, ut_teardown, 16570 test_kasumi_decryption_test_case_1), 16571 TEST_CASE_ST(ut_setup, ut_teardown, 16572 test_kasumi_decryption_test_case_2), 16573 TEST_CASE_ST(ut_setup, ut_teardown, 16574 test_kasumi_decryption_test_case_3), 16575 TEST_CASE_ST(ut_setup, ut_teardown, 16576 test_kasumi_decryption_test_case_4), 16577 TEST_CASE_ST(ut_setup, ut_teardown, 16578 test_kasumi_decryption_test_case_5), 16579 TEST_CASE_ST(ut_setup, ut_teardown, 16580 test_kasumi_decryption_test_case_1_oop), 16581 TEST_CASE_ST(ut_setup, ut_teardown, 16582 test_kasumi_cipher_auth_test_case_1), 16583 16584 /** KASUMI generate auth, then encrypt (F8) */ 16585 TEST_CASE_ST(ut_setup, ut_teardown, 16586 test_kasumi_auth_cipher_test_case_1), 16587 TEST_CASE_ST(ut_setup, ut_teardown, 16588 test_kasumi_auth_cipher_test_case_2), 16589 TEST_CASE_ST(ut_setup, ut_teardown, 16590 test_kasumi_auth_cipher_test_case_2_oop), 16591 TEST_CASE_ST(ut_setup, ut_teardown, 16592 test_kasumi_auth_cipher_test_case_2_sgl), 16593 TEST_CASE_ST(ut_setup, ut_teardown, 16594 test_kasumi_auth_cipher_test_case_2_oop_sgl), 16595 16596 /** KASUMI decrypt (F8), then verify auth */ 16597 TEST_CASE_ST(ut_setup, ut_teardown, 16598 test_kasumi_auth_cipher_verify_test_case_1), 16599 TEST_CASE_ST(ut_setup, ut_teardown, 16600 test_kasumi_auth_cipher_verify_test_case_2), 16601 TEST_CASE_ST(ut_setup, ut_teardown, 16602 test_kasumi_auth_cipher_verify_test_case_2_oop), 16603 TEST_CASE_ST(ut_setup, ut_teardown, 16604 test_kasumi_auth_cipher_verify_test_case_2_sgl), 16605 TEST_CASE_ST(ut_setup, ut_teardown, 16606 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl), 16607 16608 TEST_CASES_END() 16609 } 16610 }; 16611 16612 static struct unit_test_suite cryptodev_esn_testsuite = { 16613 .suite_name = "ESN Test Suite", 16614 .setup = esn_testsuite_setup, 16615 .unit_test_cases = { 16616 TEST_CASE_ST(ut_setup, ut_teardown, 16617 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 16618 TEST_CASE_ST(ut_setup, ut_teardown, 16619 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 16620 TEST_CASES_END() 16621 } 16622 }; 16623 16624 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite = { 16625 .suite_name = "Negative AES GCM Test Suite", 16626 .setup = negative_aes_gcm_testsuite_setup, 16627 .unit_test_cases = { 16628 TEST_CASE_ST(ut_setup, ut_teardown, 16629 test_AES_GCM_auth_encryption_fail_iv_corrupt), 16630 TEST_CASE_ST(ut_setup, ut_teardown, 16631 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 16632 TEST_CASE_ST(ut_setup, ut_teardown, 16633 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 16634 TEST_CASE_ST(ut_setup, ut_teardown, 16635 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 16636 TEST_CASE_ST(ut_setup, ut_teardown, 16637 test_AES_GCM_auth_encryption_fail_aad_corrupt), 16638 TEST_CASE_ST(ut_setup, ut_teardown, 16639 test_AES_GCM_auth_encryption_fail_tag_corrupt), 16640 TEST_CASE_ST(ut_setup, ut_teardown, 16641 test_AES_GCM_auth_decryption_fail_iv_corrupt), 16642 TEST_CASE_ST(ut_setup, ut_teardown, 16643 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 16644 TEST_CASE_ST(ut_setup, ut_teardown, 16645 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 16646 TEST_CASE_ST(ut_setup, ut_teardown, 16647 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 16648 TEST_CASE_ST(ut_setup, ut_teardown, 16649 test_AES_GCM_auth_decryption_fail_aad_corrupt), 16650 TEST_CASE_ST(ut_setup, ut_teardown, 16651 test_AES_GCM_auth_decryption_fail_tag_corrupt), 16652 16653 TEST_CASES_END() 16654 } 16655 }; 16656 16657 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite = { 16658 .suite_name = "Negative AES GMAC Test Suite", 16659 .setup = negative_aes_gmac_testsuite_setup, 16660 .unit_test_cases = { 16661 TEST_CASE_ST(ut_setup, ut_teardown, 16662 authentication_verify_AES128_GMAC_fail_data_corrupt), 16663 TEST_CASE_ST(ut_setup, ut_teardown, 16664 authentication_verify_AES128_GMAC_fail_tag_corrupt), 16665 16666 TEST_CASES_END() 16667 } 16668 }; 16669 16670 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite = { 16671 .suite_name = "Mixed CIPHER + HASH algorithms Test Suite", 16672 .setup = mixed_cipher_hash_testsuite_setup, 16673 .unit_test_cases = { 16674 /** AUTH AES CMAC + CIPHER AES CTR */ 16675 TEST_CASE_ST(ut_setup, ut_teardown, 16676 test_aes_cmac_aes_ctr_digest_enc_test_case_1), 16677 TEST_CASE_ST(ut_setup, ut_teardown, 16678 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 16679 TEST_CASE_ST(ut_setup, ut_teardown, 16680 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 16681 TEST_CASE_ST(ut_setup, ut_teardown, 16682 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 16683 TEST_CASE_ST(ut_setup, ut_teardown, 16684 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1), 16685 TEST_CASE_ST(ut_setup, ut_teardown, 16686 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 16687 TEST_CASE_ST(ut_setup, ut_teardown, 16688 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 16689 TEST_CASE_ST(ut_setup, ut_teardown, 16690 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 16691 TEST_CASE_ST(ut_setup, ut_teardown, 16692 test_aes_cmac_aes_ctr_digest_enc_test_case_2), 16693 TEST_CASE_ST(ut_setup, ut_teardown, 16694 test_aes_cmac_aes_ctr_digest_enc_test_case_2_oop), 16695 TEST_CASE_ST(ut_setup, ut_teardown, 16696 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2), 16697 TEST_CASE_ST(ut_setup, ut_teardown, 16698 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2_oop), 16699 16700 /** AUTH ZUC + CIPHER SNOW3G */ 16701 TEST_CASE_ST(ut_setup, ut_teardown, 16702 test_auth_zuc_cipher_snow_test_case_1), 16703 TEST_CASE_ST(ut_setup, ut_teardown, 16704 test_verify_auth_zuc_cipher_snow_test_case_1), 16705 TEST_CASE_ST(ut_setup, ut_teardown, 16706 test_auth_zuc_cipher_snow_test_case_1_inplace), 16707 TEST_CASE_ST(ut_setup, ut_teardown, 16708 test_verify_auth_zuc_cipher_snow_test_case_1_inplace), 16709 /** AUTH AES CMAC + CIPHER SNOW3G */ 16710 TEST_CASE_ST(ut_setup, ut_teardown, 16711 test_auth_aes_cmac_cipher_snow_test_case_1), 16712 TEST_CASE_ST(ut_setup, ut_teardown, 16713 test_verify_auth_aes_cmac_cipher_snow_test_case_1), 16714 TEST_CASE_ST(ut_setup, ut_teardown, 16715 test_auth_aes_cmac_cipher_snow_test_case_1_inplace), 16716 TEST_CASE_ST(ut_setup, ut_teardown, 16717 test_verify_auth_aes_cmac_cipher_snow_test_case_1_inplace), 16718 /** AUTH ZUC + CIPHER AES CTR */ 16719 TEST_CASE_ST(ut_setup, ut_teardown, 16720 test_auth_zuc_cipher_aes_ctr_test_case_1), 16721 TEST_CASE_ST(ut_setup, ut_teardown, 16722 test_verify_auth_zuc_cipher_aes_ctr_test_case_1), 16723 TEST_CASE_ST(ut_setup, ut_teardown, 16724 test_auth_zuc_cipher_aes_ctr_test_case_1_inplace), 16725 TEST_CASE_ST(ut_setup, ut_teardown, 16726 test_verify_auth_zuc_cipher_aes_ctr_test_case_1_inplace), 16727 /** AUTH SNOW3G + CIPHER AES CTR */ 16728 TEST_CASE_ST(ut_setup, ut_teardown, 16729 test_auth_snow_cipher_aes_ctr_test_case_1), 16730 TEST_CASE_ST(ut_setup, ut_teardown, 16731 test_verify_auth_snow_cipher_aes_ctr_test_case_1), 16732 TEST_CASE_ST(ut_setup, ut_teardown, 16733 test_auth_snow_cipher_aes_ctr_test_case_1_inplace), 16734 TEST_CASE_ST(ut_setup, ut_teardown, 16735 test_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl), 16736 TEST_CASE_ST(ut_setup, ut_teardown, 16737 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace), 16738 TEST_CASE_ST(ut_setup, ut_teardown, 16739 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl), 16740 /** AUTH SNOW3G + CIPHER ZUC */ 16741 TEST_CASE_ST(ut_setup, ut_teardown, 16742 test_auth_snow_cipher_zuc_test_case_1), 16743 TEST_CASE_ST(ut_setup, ut_teardown, 16744 test_verify_auth_snow_cipher_zuc_test_case_1), 16745 TEST_CASE_ST(ut_setup, ut_teardown, 16746 test_auth_snow_cipher_zuc_test_case_1_inplace), 16747 TEST_CASE_ST(ut_setup, ut_teardown, 16748 test_verify_auth_snow_cipher_zuc_test_case_1_inplace), 16749 /** AUTH AES CMAC + CIPHER ZUC */ 16750 TEST_CASE_ST(ut_setup, ut_teardown, 16751 test_auth_aes_cmac_cipher_zuc_test_case_1), 16752 TEST_CASE_ST(ut_setup, ut_teardown, 16753 test_verify_auth_aes_cmac_cipher_zuc_test_case_1), 16754 TEST_CASE_ST(ut_setup, ut_teardown, 16755 test_auth_aes_cmac_cipher_zuc_test_case_1_inplace), 16756 TEST_CASE_ST(ut_setup, ut_teardown, 16757 test_verify_auth_aes_cmac_cipher_zuc_test_case_1_inplace), 16758 16759 /** AUTH NULL + CIPHER SNOW3G */ 16760 TEST_CASE_ST(ut_setup, ut_teardown, 16761 test_auth_null_cipher_snow_test_case_1), 16762 TEST_CASE_ST(ut_setup, ut_teardown, 16763 test_verify_auth_null_cipher_snow_test_case_1), 16764 /** AUTH NULL + CIPHER ZUC */ 16765 TEST_CASE_ST(ut_setup, ut_teardown, 16766 test_auth_null_cipher_zuc_test_case_1), 16767 TEST_CASE_ST(ut_setup, ut_teardown, 16768 test_verify_auth_null_cipher_zuc_test_case_1), 16769 /** AUTH SNOW3G + CIPHER NULL */ 16770 TEST_CASE_ST(ut_setup, ut_teardown, 16771 test_auth_snow_cipher_null_test_case_1), 16772 TEST_CASE_ST(ut_setup, ut_teardown, 16773 test_verify_auth_snow_cipher_null_test_case_1), 16774 /** AUTH ZUC + CIPHER NULL */ 16775 TEST_CASE_ST(ut_setup, ut_teardown, 16776 test_auth_zuc_cipher_null_test_case_1), 16777 TEST_CASE_ST(ut_setup, ut_teardown, 16778 test_verify_auth_zuc_cipher_null_test_case_1), 16779 /** AUTH NULL + CIPHER AES CTR */ 16780 TEST_CASE_ST(ut_setup, ut_teardown, 16781 test_auth_null_cipher_aes_ctr_test_case_1), 16782 TEST_CASE_ST(ut_setup, ut_teardown, 16783 test_verify_auth_null_cipher_aes_ctr_test_case_1), 16784 /** AUTH AES CMAC + CIPHER NULL */ 16785 TEST_CASE_ST(ut_setup, ut_teardown, 16786 test_auth_aes_cmac_cipher_null_test_case_1), 16787 TEST_CASE_ST(ut_setup, ut_teardown, 16788 test_verify_auth_aes_cmac_cipher_null_test_case_1), 16789 TEST_CASES_END() 16790 } 16791 }; 16792 16793 static int 16794 run_cryptodev_testsuite(const char *pmd_name) 16795 { 16796 uint8_t ret, j, i = 0, blk_start_idx = 0; 16797 const enum blockcipher_test_type blk_suites[] = { 16798 BLKCIPHER_AES_CHAIN_TYPE, 16799 BLKCIPHER_AES_CIPHERONLY_TYPE, 16800 BLKCIPHER_AES_DOCSIS_TYPE, 16801 BLKCIPHER_3DES_CHAIN_TYPE, 16802 BLKCIPHER_3DES_CIPHERONLY_TYPE, 16803 BLKCIPHER_DES_CIPHERONLY_TYPE, 16804 BLKCIPHER_DES_DOCSIS_TYPE, 16805 BLKCIPHER_AUTHONLY_TYPE}; 16806 struct unit_test_suite *static_suites[] = { 16807 &cryptodev_multi_session_testsuite, 16808 &cryptodev_null_testsuite, 16809 &cryptodev_aes_ccm_auth_testsuite, 16810 &cryptodev_aes_gcm_auth_testsuite, 16811 &cryptodev_aes_gmac_auth_testsuite, 16812 &cryptodev_snow3g_testsuite, 16813 &cryptodev_chacha20_poly1305_testsuite, 16814 &cryptodev_zuc_testsuite, 16815 &cryptodev_hmac_md5_auth_testsuite, 16816 &cryptodev_kasumi_testsuite, 16817 &cryptodev_esn_testsuite, 16818 &cryptodev_negative_aes_gcm_testsuite, 16819 &cryptodev_negative_aes_gmac_testsuite, 16820 &cryptodev_mixed_cipher_hash_testsuite, 16821 &cryptodev_negative_hmac_sha1_testsuite, 16822 &cryptodev_gen_testsuite, 16823 #ifdef RTE_LIB_SECURITY 16824 &ipsec_proto_testsuite, 16825 &pdcp_proto_testsuite, 16826 &docsis_proto_testsuite, 16827 #endif 16828 &end_testsuite 16829 }; 16830 static struct unit_test_suite ts = { 16831 .suite_name = "Cryptodev Unit Test Suite", 16832 .setup = testsuite_setup, 16833 .teardown = testsuite_teardown, 16834 .unit_test_cases = {TEST_CASES_END()} 16835 }; 16836 16837 gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name); 16838 16839 if (gbl_driver_id == -1) { 16840 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name); 16841 return TEST_SKIPPED; 16842 } 16843 16844 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 16845 (RTE_DIM(blk_suites) + RTE_DIM(static_suites))); 16846 16847 ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites)); 16848 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 16849 ret = unit_test_suite_runner(&ts); 16850 16851 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites)); 16852 free(ts.unit_test_suites); 16853 return ret; 16854 } 16855 16856 static int 16857 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name) 16858 { 16859 struct rte_cryptodev_info dev_info; 16860 uint8_t i, nb_devs; 16861 int driver_id; 16862 16863 driver_id = rte_cryptodev_driver_id_get(pmd_name); 16864 if (driver_id == -1) { 16865 RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name); 16866 return TEST_SKIPPED; 16867 } 16868 16869 nb_devs = rte_cryptodev_count(); 16870 if (nb_devs < 1) { 16871 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 16872 return TEST_SKIPPED; 16873 } 16874 16875 for (i = 0; i < nb_devs; i++) { 16876 rte_cryptodev_info_get(i, &dev_info); 16877 if (dev_info.driver_id == driver_id) { 16878 if (!(dev_info.feature_flags & flag)) { 16879 RTE_LOG(INFO, USER1, "%s not supported\n", 16880 flag_name); 16881 return TEST_SKIPPED; 16882 } 16883 return 0; /* found */ 16884 } 16885 } 16886 16887 RTE_LOG(INFO, USER1, "%s not supported\n", flag_name); 16888 return TEST_SKIPPED; 16889 } 16890 16891 static int 16892 test_cryptodev_qat(void) 16893 { 16894 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 16895 } 16896 16897 static int 16898 test_cryptodev_uadk(void) 16899 { 16900 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_UADK_PMD)); 16901 } 16902 16903 static int 16904 test_cryptodev_virtio(void) 16905 { 16906 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)); 16907 } 16908 16909 static int 16910 test_cryptodev_aesni_mb(void) 16911 { 16912 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 16913 } 16914 16915 static int 16916 test_cryptodev_cpu_aesni_mb(void) 16917 { 16918 int32_t rc; 16919 enum rte_security_session_action_type at = gbl_action_type; 16920 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 16921 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 16922 gbl_action_type = at; 16923 return rc; 16924 } 16925 16926 static int 16927 test_cryptodev_chacha_poly_mb(void) 16928 { 16929 int32_t rc; 16930 enum rte_security_session_action_type at = gbl_action_type; 16931 rc = run_cryptodev_testsuite( 16932 RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD)); 16933 gbl_action_type = at; 16934 return rc; 16935 } 16936 16937 static int 16938 test_cryptodev_openssl(void) 16939 { 16940 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 16941 } 16942 16943 static int 16944 test_cryptodev_aesni_gcm(void) 16945 { 16946 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 16947 } 16948 16949 static int 16950 test_cryptodev_cpu_aesni_gcm(void) 16951 { 16952 int32_t rc; 16953 enum rte_security_session_action_type at = gbl_action_type; 16954 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 16955 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 16956 gbl_action_type = at; 16957 return rc; 16958 } 16959 16960 static int 16961 test_cryptodev_mlx5(void) 16962 { 16963 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD)); 16964 } 16965 16966 static int 16967 test_cryptodev_null(void) 16968 { 16969 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 16970 } 16971 16972 static int 16973 test_cryptodev_sw_snow3g(void) 16974 { 16975 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 16976 } 16977 16978 static int 16979 test_cryptodev_sw_kasumi(void) 16980 { 16981 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 16982 } 16983 16984 static int 16985 test_cryptodev_sw_zuc(void) 16986 { 16987 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 16988 } 16989 16990 static int 16991 test_cryptodev_armv8(void) 16992 { 16993 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 16994 } 16995 16996 static int 16997 test_cryptodev_mrvl(void) 16998 { 16999 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 17000 } 17001 17002 #ifdef RTE_CRYPTO_SCHEDULER 17003 17004 static int 17005 test_cryptodev_scheduler(void) 17006 { 17007 uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0; 17008 const enum blockcipher_test_type blk_suites[] = { 17009 BLKCIPHER_AES_CHAIN_TYPE, 17010 BLKCIPHER_AES_CIPHERONLY_TYPE, 17011 BLKCIPHER_AUTHONLY_TYPE 17012 }; 17013 static struct unit_test_suite scheduler_multicore = { 17014 .suite_name = "Scheduler Multicore Unit Test Suite", 17015 .setup = scheduler_multicore_testsuite_setup, 17016 .teardown = scheduler_mode_testsuite_teardown, 17017 .unit_test_cases = {TEST_CASES_END()} 17018 }; 17019 static struct unit_test_suite scheduler_round_robin = { 17020 .suite_name = "Scheduler Round Robin Unit Test Suite", 17021 .setup = scheduler_roundrobin_testsuite_setup, 17022 .teardown = scheduler_mode_testsuite_teardown, 17023 .unit_test_cases = {TEST_CASES_END()} 17024 }; 17025 static struct unit_test_suite scheduler_failover = { 17026 .suite_name = "Scheduler Failover Unit Test Suite", 17027 .setup = scheduler_failover_testsuite_setup, 17028 .teardown = scheduler_mode_testsuite_teardown, 17029 .unit_test_cases = {TEST_CASES_END()} 17030 }; 17031 static struct unit_test_suite scheduler_pkt_size_distr = { 17032 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite", 17033 .setup = scheduler_pkt_size_distr_testsuite_setup, 17034 .teardown = scheduler_mode_testsuite_teardown, 17035 .unit_test_cases = {TEST_CASES_END()} 17036 }; 17037 struct unit_test_suite *sched_mode_suites[] = { 17038 &scheduler_multicore, 17039 &scheduler_round_robin, 17040 &scheduler_failover, 17041 &scheduler_pkt_size_distr 17042 }; 17043 static struct unit_test_suite scheduler_config = { 17044 .suite_name = "Crypto Device Scheduler Config Unit Test Suite", 17045 .unit_test_cases = { 17046 TEST_CASE(test_scheduler_attach_worker_op), 17047 TEST_CASE(test_scheduler_mode_multicore_op), 17048 TEST_CASE(test_scheduler_mode_roundrobin_op), 17049 TEST_CASE(test_scheduler_mode_failover_op), 17050 TEST_CASE(test_scheduler_mode_pkt_size_distr_op), 17051 TEST_CASE(test_scheduler_detach_worker_op), 17052 17053 TEST_CASES_END() /**< NULL terminate array */ 17054 } 17055 }; 17056 struct unit_test_suite *static_suites[] = { 17057 &scheduler_config, 17058 &end_testsuite 17059 }; 17060 static struct unit_test_suite ts = { 17061 .suite_name = "Scheduler Unit Test Suite", 17062 .setup = scheduler_testsuite_setup, 17063 .teardown = testsuite_teardown, 17064 .unit_test_cases = {TEST_CASES_END()} 17065 }; 17066 17067 gbl_driver_id = rte_cryptodev_driver_id_get( 17068 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 17069 17070 if (gbl_driver_id == -1) { 17071 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n"); 17072 return TEST_SKIPPED; 17073 } 17074 17075 if (rte_cryptodev_driver_id_get( 17076 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) { 17077 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 17078 return TEST_SKIPPED; 17079 } 17080 17081 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 17082 uint8_t blk_i = 0; 17083 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof 17084 (struct unit_test_suite *) * 17085 (RTE_DIM(blk_suites) + 1)); 17086 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]), 17087 blk_suites, RTE_DIM(blk_suites)); 17088 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite; 17089 } 17090 17091 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 17092 (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites))); 17093 ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites, 17094 RTE_DIM(sched_mode_suites)); 17095 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 17096 ret = unit_test_suite_runner(&ts); 17097 17098 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 17099 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, 17100 (*sched_mode_suites[sched_i]), 17101 RTE_DIM(blk_suites)); 17102 free(sched_mode_suites[sched_i]->unit_test_suites); 17103 } 17104 free(ts.unit_test_suites); 17105 return ret; 17106 } 17107 17108 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler); 17109 17110 #endif 17111 17112 static int 17113 test_cryptodev_dpaa2_sec(void) 17114 { 17115 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 17116 } 17117 17118 static int 17119 test_cryptodev_dpaa_sec(void) 17120 { 17121 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 17122 } 17123 17124 static int 17125 test_cryptodev_ccp(void) 17126 { 17127 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 17128 } 17129 17130 static int 17131 test_cryptodev_octeontx(void) 17132 { 17133 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)); 17134 } 17135 17136 static int 17137 test_cryptodev_caam_jr(void) 17138 { 17139 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)); 17140 } 17141 17142 static int 17143 test_cryptodev_nitrox(void) 17144 { 17145 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD)); 17146 } 17147 17148 static int 17149 test_cryptodev_bcmfs(void) 17150 { 17151 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD)); 17152 } 17153 17154 static int 17155 test_cryptodev_qat_raw_api(void) 17156 { 17157 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD); 17158 int ret; 17159 17160 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 17161 "RAW API"); 17162 if (ret) 17163 return ret; 17164 17165 global_api_test_type = CRYPTODEV_RAW_API_TEST; 17166 ret = run_cryptodev_testsuite(pmd_name); 17167 global_api_test_type = CRYPTODEV_API_TEST; 17168 17169 return ret; 17170 } 17171 17172 static int 17173 test_cryptodev_cn9k(void) 17174 { 17175 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD)); 17176 } 17177 17178 static int 17179 test_cryptodev_cn10k(void) 17180 { 17181 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD)); 17182 } 17183 17184 static int 17185 test_cryptodev_dpaa2_sec_raw_api(void) 17186 { 17187 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD); 17188 int ret; 17189 17190 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 17191 "RAW API"); 17192 if (ret) 17193 return ret; 17194 17195 global_api_test_type = CRYPTODEV_RAW_API_TEST; 17196 ret = run_cryptodev_testsuite(pmd_name); 17197 global_api_test_type = CRYPTODEV_API_TEST; 17198 17199 return ret; 17200 } 17201 17202 static int 17203 test_cryptodev_dpaa_sec_raw_api(void) 17204 { 17205 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD); 17206 int ret; 17207 17208 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 17209 "RAW API"); 17210 if (ret) 17211 return ret; 17212 17213 global_api_test_type = CRYPTODEV_RAW_API_TEST; 17214 ret = run_cryptodev_testsuite(pmd_name); 17215 global_api_test_type = CRYPTODEV_API_TEST; 17216 17217 return ret; 17218 } 17219 17220 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_raw_api_autotest, 17221 test_cryptodev_dpaa2_sec_raw_api); 17222 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_raw_api_autotest, 17223 test_cryptodev_dpaa_sec_raw_api); 17224 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest, 17225 test_cryptodev_qat_raw_api); 17226 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat); 17227 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 17228 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest, 17229 test_cryptodev_cpu_aesni_mb); 17230 REGISTER_TEST_COMMAND(cryptodev_chacha_poly_mb_autotest, 17231 test_cryptodev_chacha_poly_mb); 17232 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl); 17233 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 17234 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest, 17235 test_cryptodev_cpu_aesni_gcm); 17236 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5); 17237 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null); 17238 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 17239 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 17240 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 17241 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8); 17242 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl); 17243 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec); 17244 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec); 17245 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp); 17246 REGISTER_TEST_COMMAND(cryptodev_uadk_autotest, test_cryptodev_uadk); 17247 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio); 17248 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx); 17249 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr); 17250 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox); 17251 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs); 17252 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k); 17253 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k); 17254