1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2015-2020 Intel Corporation 3 * Copyright 2020 NXP 4 */ 5 6 #include <time.h> 7 8 #include <rte_common.h> 9 #include <rte_hexdump.h> 10 #include <rte_mbuf.h> 11 #include <rte_malloc.h> 12 #include <rte_memcpy.h> 13 #include <rte_pause.h> 14 #include <rte_bus_vdev.h> 15 #include <rte_ether.h> 16 17 #include <rte_crypto.h> 18 #include <rte_cryptodev.h> 19 #include <rte_ip.h> 20 #include <rte_string_fns.h> 21 #include <rte_tcp.h> 22 #include <rte_udp.h> 23 24 #ifdef RTE_CRYPTO_SCHEDULER 25 #include <rte_cryptodev_scheduler.h> 26 #include <rte_cryptodev_scheduler_operations.h> 27 #endif 28 29 #include <rte_lcore.h> 30 31 #include "test.h" 32 #include "test_cryptodev.h" 33 34 #include "test_cryptodev_blockcipher.h" 35 #include "test_cryptodev_aes_test_vectors.h" 36 #include "test_cryptodev_des_test_vectors.h" 37 #include "test_cryptodev_hash_test_vectors.h" 38 #include "test_cryptodev_kasumi_test_vectors.h" 39 #include "test_cryptodev_kasumi_hash_test_vectors.h" 40 #include "test_cryptodev_snow3g_test_vectors.h" 41 #include "test_cryptodev_snow3g_hash_test_vectors.h" 42 #include "test_cryptodev_zuc_test_vectors.h" 43 #include "test_cryptodev_aead_test_vectors.h" 44 #include "test_cryptodev_hmac_test_vectors.h" 45 #include "test_cryptodev_mixed_test_vectors.h" 46 #ifdef RTE_LIB_SECURITY 47 #include "test_cryptodev_security_ipsec.h" 48 #include "test_cryptodev_security_ipsec_test_vectors.h" 49 #include "test_cryptodev_security_pdcp_test_vectors.h" 50 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h" 51 #include "test_cryptodev_security_pdcp_test_func.h" 52 #include "test_cryptodev_security_docsis_test_vectors.h" 53 54 #define SDAP_DISABLED 0 55 #define SDAP_ENABLED 1 56 #endif 57 58 #define VDEV_ARGS_SIZE 100 59 #define MAX_NB_SESSIONS 4 60 61 #define MAX_DRV_SERVICE_CTX_SIZE 256 62 63 #define MAX_RAW_DEQUEUE_COUNT 65535 64 65 #define IN_PLACE 0 66 #define OUT_OF_PLACE 1 67 68 static int gbl_driver_id; 69 70 static enum rte_security_session_action_type gbl_action_type = 71 RTE_SECURITY_ACTION_TYPE_NONE; 72 73 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST; 74 75 struct crypto_unittest_params { 76 struct rte_crypto_sym_xform cipher_xform; 77 struct rte_crypto_sym_xform auth_xform; 78 struct rte_crypto_sym_xform aead_xform; 79 #ifdef RTE_LIB_SECURITY 80 struct rte_security_docsis_xform docsis_xform; 81 #endif 82 83 union { 84 struct rte_cryptodev_sym_session *sess; 85 #ifdef RTE_LIB_SECURITY 86 struct rte_security_session *sec_session; 87 #endif 88 }; 89 #ifdef RTE_LIB_SECURITY 90 enum rte_security_session_action_type type; 91 #endif 92 struct rte_crypto_op *op; 93 94 struct rte_mbuf *obuf, *ibuf; 95 96 uint8_t *digest; 97 }; 98 99 #define ALIGN_POW2_ROUNDUP(num, align) \ 100 (((num) + (align) - 1) & ~((align) - 1)) 101 102 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts) \ 103 for (j = 0; j < num_child_ts; index++, j++) \ 104 parent_ts.unit_test_suites[index] = child_ts[j] 105 106 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types) \ 107 for (j = 0; j < num_blk_types; index++, j++) \ 108 parent_ts.unit_test_suites[index] = \ 109 build_blockcipher_test_suite(blk_types[j]) 110 111 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types) \ 112 for (j = index; j < index + num_blk_types; j++) \ 113 free_blockcipher_test_suite(parent_ts.unit_test_suites[j]) 114 115 /* 116 * Forward declarations. 117 */ 118 static int 119 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 120 struct crypto_unittest_params *ut_params, uint8_t *cipher_key, 121 uint8_t *hmac_key); 122 123 static int 124 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 125 struct crypto_unittest_params *ut_params, 126 struct crypto_testsuite_params *ts_param, 127 const uint8_t *cipher, 128 const uint8_t *digest, 129 const uint8_t *iv); 130 131 static int 132 security_proto_supported(enum rte_security_session_action_type action, 133 enum rte_security_session_protocol proto); 134 135 static int 136 dev_configure_and_start(uint64_t ff_disable); 137 138 static struct rte_mbuf * 139 setup_test_string(struct rte_mempool *mpool, 140 const char *string, size_t len, uint8_t blocksize) 141 { 142 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool); 143 size_t t_len = len - (blocksize ? (len % blocksize) : 0); 144 145 if (m) { 146 char *dst; 147 148 memset(m->buf_addr, 0, m->buf_len); 149 dst = rte_pktmbuf_append(m, t_len); 150 if (!dst) { 151 rte_pktmbuf_free(m); 152 return NULL; 153 } 154 if (string != NULL) 155 rte_memcpy(dst, string, t_len); 156 else 157 memset(dst, 0, t_len); 158 } 159 160 return m; 161 } 162 163 /* Get number of bytes in X bits (rounding up) */ 164 static uint32_t 165 ceil_byte_length(uint32_t num_bits) 166 { 167 if (num_bits % 8) 168 return ((num_bits >> 3) + 1); 169 else 170 return (num_bits >> 3); 171 } 172 173 static void 174 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused, 175 uint8_t is_op_success) 176 { 177 struct rte_crypto_op *op = user_data; 178 op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS : 179 RTE_CRYPTO_OP_STATUS_ERROR; 180 } 181 182 void 183 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id, 184 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth, 185 uint8_t len_in_bits, uint8_t cipher_iv_len) 186 { 187 struct rte_crypto_sym_op *sop = op->sym; 188 struct rte_crypto_op *ret_op = NULL; 189 struct rte_crypto_vec data_vec[UINT8_MAX], dest_data_vec[UINT8_MAX]; 190 struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv; 191 union rte_crypto_sym_ofs ofs; 192 struct rte_crypto_sym_vec vec; 193 struct rte_crypto_sgl sgl, dest_sgl; 194 uint32_t max_len; 195 union rte_cryptodev_session_ctx sess; 196 uint32_t count = 0; 197 struct rte_crypto_raw_dp_ctx *ctx; 198 uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0, 199 auth_len = 0; 200 int32_t n; 201 uint32_t n_success; 202 int ctx_service_size; 203 int32_t status = 0; 204 int enqueue_status, dequeue_status; 205 206 ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id); 207 if (ctx_service_size < 0) { 208 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 209 return; 210 } 211 212 ctx = malloc(ctx_service_size); 213 if (!ctx) { 214 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 215 return; 216 } 217 218 /* Both are enums, setting crypto_sess will suit any session type */ 219 sess.crypto_sess = op->sym->session; 220 221 if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx, 222 op->sess_type, sess, 0) < 0) { 223 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 224 goto exit; 225 } 226 227 cipher_iv.iova = 0; 228 cipher_iv.va = NULL; 229 aad_auth_iv.iova = 0; 230 aad_auth_iv.va = NULL; 231 digest.iova = 0; 232 digest.va = NULL; 233 sgl.vec = data_vec; 234 vec.num = 1; 235 vec.src_sgl = &sgl; 236 vec.iv = &cipher_iv; 237 vec.digest = &digest; 238 vec.aad = &aad_auth_iv; 239 vec.status = &status; 240 241 ofs.raw = 0; 242 243 if (is_cipher && is_auth) { 244 cipher_offset = sop->cipher.data.offset; 245 cipher_len = sop->cipher.data.length; 246 auth_offset = sop->auth.data.offset; 247 auth_len = sop->auth.data.length; 248 max_len = RTE_MAX(cipher_offset + cipher_len, 249 auth_offset + auth_len); 250 if (len_in_bits) { 251 max_len = max_len >> 3; 252 cipher_offset = cipher_offset >> 3; 253 auth_offset = auth_offset >> 3; 254 cipher_len = cipher_len >> 3; 255 auth_len = auth_len >> 3; 256 } 257 ofs.ofs.cipher.head = cipher_offset; 258 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 259 ofs.ofs.auth.head = auth_offset; 260 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 261 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 262 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 263 aad_auth_iv.va = rte_crypto_op_ctod_offset( 264 op, void *, IV_OFFSET + cipher_iv_len); 265 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 266 cipher_iv_len); 267 digest.va = (void *)sop->auth.digest.data; 268 digest.iova = sop->auth.digest.phys_addr; 269 270 } else if (is_cipher) { 271 cipher_offset = sop->cipher.data.offset; 272 cipher_len = sop->cipher.data.length; 273 max_len = cipher_len + cipher_offset; 274 if (len_in_bits) { 275 max_len = max_len >> 3; 276 cipher_offset = cipher_offset >> 3; 277 cipher_len = cipher_len >> 3; 278 } 279 ofs.ofs.cipher.head = cipher_offset; 280 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 281 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 282 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 283 284 } else if (is_auth) { 285 auth_offset = sop->auth.data.offset; 286 auth_len = sop->auth.data.length; 287 max_len = auth_len + auth_offset; 288 if (len_in_bits) { 289 max_len = max_len >> 3; 290 auth_offset = auth_offset >> 3; 291 auth_len = auth_len >> 3; 292 } 293 ofs.ofs.auth.head = auth_offset; 294 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 295 aad_auth_iv.va = rte_crypto_op_ctod_offset( 296 op, void *, IV_OFFSET + cipher_iv_len); 297 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 298 cipher_iv_len); 299 digest.va = (void *)sop->auth.digest.data; 300 digest.iova = sop->auth.digest.phys_addr; 301 302 } else { /* aead */ 303 cipher_offset = sop->aead.data.offset; 304 cipher_len = sop->aead.data.length; 305 max_len = cipher_len + cipher_offset; 306 if (len_in_bits) { 307 max_len = max_len >> 3; 308 cipher_offset = cipher_offset >> 3; 309 cipher_len = cipher_len >> 3; 310 } 311 ofs.ofs.cipher.head = cipher_offset; 312 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 313 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 314 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 315 aad_auth_iv.va = (void *)sop->aead.aad.data; 316 aad_auth_iv.iova = sop->aead.aad.phys_addr; 317 digest.va = (void *)sop->aead.digest.data; 318 digest.iova = sop->aead.digest.phys_addr; 319 } 320 321 n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len, 322 data_vec, RTE_DIM(data_vec)); 323 if (n < 0 || n > sop->m_src->nb_segs) { 324 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 325 goto exit; 326 } 327 328 sgl.num = n; 329 /* Out of place */ 330 if (sop->m_dst != NULL) { 331 dest_sgl.vec = dest_data_vec; 332 vec.dest_sgl = &dest_sgl; 333 n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len, 334 dest_data_vec, RTE_DIM(dest_data_vec)); 335 if (n < 0 || n > sop->m_dst->nb_segs) { 336 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 337 goto exit; 338 } 339 dest_sgl.num = n; 340 } else 341 vec.dest_sgl = NULL; 342 343 if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op, 344 &enqueue_status) < 1) { 345 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 346 goto exit; 347 } 348 349 if (enqueue_status == 0) { 350 status = rte_cryptodev_raw_enqueue_done(ctx, 1); 351 if (status < 0) { 352 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 353 goto exit; 354 } 355 } else if (enqueue_status < 0) { 356 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 357 goto exit; 358 } 359 360 n = n_success = 0; 361 while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) { 362 n = rte_cryptodev_raw_dequeue_burst(ctx, 363 NULL, 1, post_process_raw_dp_op, 364 (void **)&ret_op, 0, &n_success, 365 &dequeue_status); 366 if (dequeue_status < 0) { 367 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 368 goto exit; 369 } 370 if (n == 0) 371 rte_pause(); 372 } 373 374 if (n == 1 && dequeue_status == 0) { 375 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) { 376 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 377 goto exit; 378 } 379 } 380 381 op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op || 382 ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR || 383 n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR : 384 RTE_CRYPTO_OP_STATUS_SUCCESS; 385 386 exit: 387 free(ctx); 388 } 389 390 static void 391 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op) 392 { 393 int32_t n, st; 394 struct rte_crypto_sym_op *sop; 395 union rte_crypto_sym_ofs ofs; 396 struct rte_crypto_sgl sgl; 397 struct rte_crypto_sym_vec symvec; 398 struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr; 399 struct rte_crypto_vec vec[UINT8_MAX]; 400 401 sop = op->sym; 402 403 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset, 404 sop->aead.data.length, vec, RTE_DIM(vec)); 405 406 if (n < 0 || n != sop->m_src->nb_segs) { 407 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 408 return; 409 } 410 411 sgl.vec = vec; 412 sgl.num = n; 413 symvec.src_sgl = &sgl; 414 symvec.iv = &iv_ptr; 415 symvec.digest = &digest_ptr; 416 symvec.aad = &aad_ptr; 417 symvec.status = &st; 418 symvec.num = 1; 419 420 /* for CPU crypto the IOVA address is not required */ 421 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 422 digest_ptr.va = (void *)sop->aead.digest.data; 423 aad_ptr.va = (void *)sop->aead.aad.data; 424 425 ofs.raw = 0; 426 427 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 428 &symvec); 429 430 if (n != 1) 431 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 432 else 433 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 434 } 435 436 static void 437 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op) 438 { 439 int32_t n, st; 440 struct rte_crypto_sym_op *sop; 441 union rte_crypto_sym_ofs ofs; 442 struct rte_crypto_sgl sgl; 443 struct rte_crypto_sym_vec symvec; 444 struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr; 445 struct rte_crypto_vec vec[UINT8_MAX]; 446 447 sop = op->sym; 448 449 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset, 450 sop->auth.data.length, vec, RTE_DIM(vec)); 451 452 if (n < 0 || n != sop->m_src->nb_segs) { 453 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 454 return; 455 } 456 457 sgl.vec = vec; 458 sgl.num = n; 459 symvec.src_sgl = &sgl; 460 symvec.iv = &iv_ptr; 461 symvec.digest = &digest_ptr; 462 symvec.status = &st; 463 symvec.num = 1; 464 465 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 466 digest_ptr.va = (void *)sop->auth.digest.data; 467 468 ofs.raw = 0; 469 ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset; 470 ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) - 471 (sop->cipher.data.offset + sop->cipher.data.length); 472 473 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 474 &symvec); 475 476 if (n != 1) 477 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 478 else 479 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 480 } 481 482 static struct rte_crypto_op * 483 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op) 484 { 485 486 RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO); 487 488 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 489 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n"); 490 return NULL; 491 } 492 493 op = NULL; 494 495 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 496 rte_pause(); 497 498 if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 499 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status); 500 return NULL; 501 } 502 503 return op; 504 } 505 506 static struct crypto_testsuite_params testsuite_params = { NULL }; 507 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params; 508 static struct crypto_unittest_params unittest_params; 509 510 static int 511 testsuite_setup(void) 512 { 513 struct crypto_testsuite_params *ts_params = &testsuite_params; 514 struct rte_cryptodev_info info; 515 uint32_t i = 0, nb_devs, dev_id; 516 uint16_t qp_id; 517 518 memset(ts_params, 0, sizeof(*ts_params)); 519 520 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 521 if (ts_params->mbuf_pool == NULL) { 522 /* Not already created so create */ 523 ts_params->mbuf_pool = rte_pktmbuf_pool_create( 524 "CRYPTO_MBUFPOOL", 525 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE, 526 rte_socket_id()); 527 if (ts_params->mbuf_pool == NULL) { 528 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n"); 529 return TEST_FAILED; 530 } 531 } 532 533 ts_params->large_mbuf_pool = rte_mempool_lookup( 534 "CRYPTO_LARGE_MBUFPOOL"); 535 if (ts_params->large_mbuf_pool == NULL) { 536 /* Not already created so create */ 537 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create( 538 "CRYPTO_LARGE_MBUFPOOL", 539 1, 0, 0, UINT16_MAX, 540 rte_socket_id()); 541 if (ts_params->large_mbuf_pool == NULL) { 542 RTE_LOG(ERR, USER1, 543 "Can't create CRYPTO_LARGE_MBUFPOOL\n"); 544 return TEST_FAILED; 545 } 546 } 547 548 ts_params->op_mpool = rte_crypto_op_pool_create( 549 "MBUF_CRYPTO_SYM_OP_POOL", 550 RTE_CRYPTO_OP_TYPE_SYMMETRIC, 551 NUM_MBUFS, MBUF_CACHE_SIZE, 552 DEFAULT_NUM_XFORMS * 553 sizeof(struct rte_crypto_sym_xform) + 554 MAXIMUM_IV_LENGTH, 555 rte_socket_id()); 556 if (ts_params->op_mpool == NULL) { 557 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n"); 558 return TEST_FAILED; 559 } 560 561 nb_devs = rte_cryptodev_count(); 562 if (nb_devs < 1) { 563 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 564 return TEST_SKIPPED; 565 } 566 567 if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) { 568 RTE_LOG(WARNING, USER1, "No %s devices found?\n", 569 rte_cryptodev_driver_name_get(gbl_driver_id)); 570 return TEST_SKIPPED; 571 } 572 573 /* Create list of valid crypto devs */ 574 for (i = 0; i < nb_devs; i++) { 575 rte_cryptodev_info_get(i, &info); 576 if (info.driver_id == gbl_driver_id) 577 ts_params->valid_devs[ts_params->valid_dev_count++] = i; 578 } 579 580 if (ts_params->valid_dev_count < 1) 581 return TEST_FAILED; 582 583 /* Set up all the qps on the first of the valid devices found */ 584 585 dev_id = ts_params->valid_devs[0]; 586 587 rte_cryptodev_info_get(dev_id, &info); 588 589 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; 590 ts_params->conf.socket_id = SOCKET_ID_ANY; 591 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY; 592 593 unsigned int session_size = 594 rte_cryptodev_sym_get_private_session_size(dev_id); 595 596 #ifdef RTE_LIB_SECURITY 597 unsigned int security_session_size = rte_security_session_get_size( 598 rte_cryptodev_get_sec_ctx(dev_id)); 599 600 if (session_size < security_session_size) 601 session_size = security_session_size; 602 #endif 603 /* 604 * Create mempool with maximum number of sessions. 605 */ 606 if (info.sym.max_nb_sessions != 0 && 607 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 608 RTE_LOG(ERR, USER1, "Device does not support " 609 "at least %u sessions\n", 610 MAX_NB_SESSIONS); 611 return TEST_FAILED; 612 } 613 614 ts_params->session_mpool = rte_cryptodev_sym_session_pool_create( 615 "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0, 616 SOCKET_ID_ANY); 617 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 618 "session mempool allocation failed"); 619 620 ts_params->session_priv_mpool = rte_mempool_create( 621 "test_sess_mp_priv", 622 MAX_NB_SESSIONS, 623 session_size, 624 0, 0, NULL, NULL, NULL, 625 NULL, SOCKET_ID_ANY, 626 0); 627 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 628 "session mempool allocation failed"); 629 630 631 632 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, 633 &ts_params->conf), 634 "Failed to configure cryptodev %u with %u qps", 635 dev_id, ts_params->conf.nb_queue_pairs); 636 637 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 638 ts_params->qp_conf.mp_session = ts_params->session_mpool; 639 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 640 641 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 642 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 643 dev_id, qp_id, &ts_params->qp_conf, 644 rte_cryptodev_socket_id(dev_id)), 645 "Failed to setup queue pair %u on cryptodev %u", 646 qp_id, dev_id); 647 } 648 649 return TEST_SUCCESS; 650 } 651 652 static void 653 testsuite_teardown(void) 654 { 655 struct crypto_testsuite_params *ts_params = &testsuite_params; 656 int res; 657 658 if (ts_params->mbuf_pool != NULL) { 659 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 660 rte_mempool_avail_count(ts_params->mbuf_pool)); 661 } 662 663 if (ts_params->op_mpool != NULL) { 664 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", 665 rte_mempool_avail_count(ts_params->op_mpool)); 666 } 667 668 /* Free session mempools */ 669 if (ts_params->session_priv_mpool != NULL) { 670 rte_mempool_free(ts_params->session_priv_mpool); 671 ts_params->session_priv_mpool = NULL; 672 } 673 674 if (ts_params->session_mpool != NULL) { 675 rte_mempool_free(ts_params->session_mpool); 676 ts_params->session_mpool = NULL; 677 } 678 679 res = rte_cryptodev_close(ts_params->valid_devs[0]); 680 if (res) 681 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res); 682 } 683 684 static int 685 check_capabilities_supported(enum rte_crypto_sym_xform_type type, 686 const int *algs, uint16_t num_algs) 687 { 688 uint8_t dev_id = testsuite_params.valid_devs[0]; 689 bool some_alg_supported = FALSE; 690 uint16_t i; 691 692 for (i = 0; i < num_algs && !some_alg_supported; i++) { 693 struct rte_cryptodev_sym_capability_idx alg = { 694 type, {algs[i]} 695 }; 696 if (rte_cryptodev_sym_capability_get(dev_id, 697 &alg) != NULL) 698 some_alg_supported = TRUE; 699 } 700 if (!some_alg_supported) 701 return TEST_SKIPPED; 702 703 return 0; 704 } 705 706 int 707 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers, 708 uint16_t num_ciphers) 709 { 710 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER, 711 (const int *) ciphers, num_ciphers); 712 } 713 714 int 715 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths, 716 uint16_t num_auths) 717 { 718 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH, 719 (const int *) auths, num_auths); 720 } 721 722 int 723 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads, 724 uint16_t num_aeads) 725 { 726 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD, 727 (const int *) aeads, num_aeads); 728 } 729 730 static int 731 null_testsuite_setup(void) 732 { 733 struct crypto_testsuite_params *ts_params = &testsuite_params; 734 uint8_t dev_id = ts_params->valid_devs[0]; 735 struct rte_cryptodev_info dev_info; 736 const enum rte_crypto_cipher_algorithm ciphers[] = { 737 RTE_CRYPTO_CIPHER_NULL 738 }; 739 const enum rte_crypto_auth_algorithm auths[] = { 740 RTE_CRYPTO_AUTH_NULL 741 }; 742 743 rte_cryptodev_info_get(dev_id, &dev_info); 744 745 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 746 RTE_LOG(INFO, USER1, "Feature flag requirements for NULL " 747 "testsuite not met\n"); 748 return TEST_SKIPPED; 749 } 750 751 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 752 && check_auth_capabilities_supported(auths, 753 RTE_DIM(auths)) != 0) { 754 RTE_LOG(INFO, USER1, "Capability requirements for NULL " 755 "testsuite not met\n"); 756 return TEST_SKIPPED; 757 } 758 759 return 0; 760 } 761 762 static int 763 crypto_gen_testsuite_setup(void) 764 { 765 struct crypto_testsuite_params *ts_params = &testsuite_params; 766 uint8_t dev_id = ts_params->valid_devs[0]; 767 struct rte_cryptodev_info dev_info; 768 769 rte_cryptodev_info_get(dev_id, &dev_info); 770 771 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 772 RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen " 773 "testsuite not met\n"); 774 return TEST_SKIPPED; 775 } 776 777 return 0; 778 } 779 780 #ifdef RTE_LIB_SECURITY 781 static int 782 ipsec_proto_testsuite_setup(void) 783 { 784 struct crypto_testsuite_params *ts_params = &testsuite_params; 785 struct crypto_unittest_params *ut_params = &unittest_params; 786 struct rte_cryptodev_info dev_info; 787 int ret = 0; 788 789 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 790 791 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) { 792 RTE_LOG(INFO, USER1, "Feature flag requirements for IPsec Proto " 793 "testsuite not met\n"); 794 return TEST_SKIPPED; 795 } 796 797 /* Reconfigure to enable security */ 798 ret = dev_configure_and_start(0); 799 if (ret != TEST_SUCCESS) 800 return ret; 801 802 /* Set action type */ 803 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 804 805 if (security_proto_supported( 806 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 807 RTE_SECURITY_PROTOCOL_IPSEC) < 0) { 808 RTE_LOG(INFO, USER1, "Capability requirements for IPsec Proto " 809 "test not met\n"); 810 ret = TEST_SKIPPED; 811 } 812 813 /* 814 * Stop the device. Device would be started again by individual test 815 * case setup routine. 816 */ 817 rte_cryptodev_stop(ts_params->valid_devs[0]); 818 819 return ret; 820 } 821 822 static int 823 pdcp_proto_testsuite_setup(void) 824 { 825 struct crypto_testsuite_params *ts_params = &testsuite_params; 826 uint8_t dev_id = ts_params->valid_devs[0]; 827 struct rte_cryptodev_info dev_info; 828 const enum rte_crypto_cipher_algorithm ciphers[] = { 829 RTE_CRYPTO_CIPHER_NULL, 830 RTE_CRYPTO_CIPHER_AES_CTR, 831 RTE_CRYPTO_CIPHER_ZUC_EEA3, 832 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 833 }; 834 const enum rte_crypto_auth_algorithm auths[] = { 835 RTE_CRYPTO_AUTH_NULL, 836 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 837 RTE_CRYPTO_AUTH_AES_CMAC, 838 RTE_CRYPTO_AUTH_ZUC_EIA3 839 }; 840 841 rte_cryptodev_info_get(dev_id, &dev_info); 842 843 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 844 !(dev_info.feature_flags & 845 RTE_CRYPTODEV_FF_SECURITY)) { 846 RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto " 847 "testsuite not met\n"); 848 return TEST_SKIPPED; 849 } 850 851 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 852 && check_auth_capabilities_supported(auths, 853 RTE_DIM(auths)) != 0) { 854 RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto " 855 "testsuite not met\n"); 856 return TEST_SKIPPED; 857 } 858 859 return 0; 860 } 861 862 static int 863 docsis_proto_testsuite_setup(void) 864 { 865 struct crypto_testsuite_params *ts_params = &testsuite_params; 866 uint8_t dev_id = ts_params->valid_devs[0]; 867 struct rte_cryptodev_info dev_info; 868 const enum rte_crypto_cipher_algorithm ciphers[] = { 869 RTE_CRYPTO_CIPHER_AES_DOCSISBPI 870 }; 871 872 rte_cryptodev_info_get(dev_id, &dev_info); 873 874 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 875 !(dev_info.feature_flags & 876 RTE_CRYPTODEV_FF_SECURITY)) { 877 RTE_LOG(INFO, USER1, "Feature flag requirements for Docsis " 878 "Proto testsuite not met\n"); 879 return TEST_SKIPPED; 880 } 881 882 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { 883 RTE_LOG(INFO, USER1, "Capability requirements for Docsis Proto " 884 "testsuite not met\n"); 885 return TEST_SKIPPED; 886 } 887 888 return 0; 889 } 890 #endif 891 892 static int 893 aes_ccm_auth_testsuite_setup(void) 894 { 895 struct crypto_testsuite_params *ts_params = &testsuite_params; 896 uint8_t dev_id = ts_params->valid_devs[0]; 897 struct rte_cryptodev_info dev_info; 898 const enum rte_crypto_aead_algorithm aeads[] = { 899 RTE_CRYPTO_AEAD_AES_CCM 900 }; 901 902 rte_cryptodev_info_get(dev_id, &dev_info); 903 904 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 905 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 906 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 907 RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM " 908 "testsuite not met\n"); 909 return TEST_SKIPPED; 910 } 911 912 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 913 RTE_LOG(INFO, USER1, "Capability requirements for AES CCM " 914 "testsuite not met\n"); 915 return TEST_SKIPPED; 916 } 917 918 return 0; 919 } 920 921 static int 922 aes_gcm_auth_testsuite_setup(void) 923 { 924 struct crypto_testsuite_params *ts_params = &testsuite_params; 925 uint8_t dev_id = ts_params->valid_devs[0]; 926 struct rte_cryptodev_info dev_info; 927 const enum rte_crypto_aead_algorithm aeads[] = { 928 RTE_CRYPTO_AEAD_AES_GCM 929 }; 930 931 rte_cryptodev_info_get(dev_id, &dev_info); 932 933 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 934 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM " 935 "testsuite not met\n"); 936 return TEST_SKIPPED; 937 } 938 939 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 940 RTE_LOG(INFO, USER1, "Capability requirements for AES GCM " 941 "testsuite not met\n"); 942 return TEST_SKIPPED; 943 } 944 945 return 0; 946 } 947 948 static int 949 aes_gmac_auth_testsuite_setup(void) 950 { 951 struct crypto_testsuite_params *ts_params = &testsuite_params; 952 uint8_t dev_id = ts_params->valid_devs[0]; 953 struct rte_cryptodev_info dev_info; 954 const enum rte_crypto_auth_algorithm auths[] = { 955 RTE_CRYPTO_AUTH_AES_GMAC 956 }; 957 958 rte_cryptodev_info_get(dev_id, &dev_info); 959 960 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 961 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 962 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 963 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC " 964 "testsuite not met\n"); 965 return TEST_SKIPPED; 966 } 967 968 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 969 RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC " 970 "testsuite not met\n"); 971 return TEST_SKIPPED; 972 } 973 974 return 0; 975 } 976 977 static int 978 chacha20_poly1305_testsuite_setup(void) 979 { 980 struct crypto_testsuite_params *ts_params = &testsuite_params; 981 uint8_t dev_id = ts_params->valid_devs[0]; 982 struct rte_cryptodev_info dev_info; 983 const enum rte_crypto_aead_algorithm aeads[] = { 984 RTE_CRYPTO_AEAD_CHACHA20_POLY1305 985 }; 986 987 rte_cryptodev_info_get(dev_id, &dev_info); 988 989 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 990 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 991 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 992 RTE_LOG(INFO, USER1, "Feature flag requirements for " 993 "Chacha20-Poly1305 testsuite not met\n"); 994 return TEST_SKIPPED; 995 } 996 997 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 998 RTE_LOG(INFO, USER1, "Capability requirements for " 999 "Chacha20-Poly1305 testsuite not met\n"); 1000 return TEST_SKIPPED; 1001 } 1002 1003 return 0; 1004 } 1005 1006 static int 1007 snow3g_testsuite_setup(void) 1008 { 1009 struct crypto_testsuite_params *ts_params = &testsuite_params; 1010 uint8_t dev_id = ts_params->valid_devs[0]; 1011 struct rte_cryptodev_info dev_info; 1012 const enum rte_crypto_cipher_algorithm ciphers[] = { 1013 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1014 1015 }; 1016 const enum rte_crypto_auth_algorithm auths[] = { 1017 RTE_CRYPTO_AUTH_SNOW3G_UIA2 1018 }; 1019 1020 rte_cryptodev_info_get(dev_id, &dev_info); 1021 1022 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1023 RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G " 1024 "testsuite not met\n"); 1025 return TEST_SKIPPED; 1026 } 1027 1028 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1029 && check_auth_capabilities_supported(auths, 1030 RTE_DIM(auths)) != 0) { 1031 RTE_LOG(INFO, USER1, "Capability requirements for Snow3G " 1032 "testsuite not met\n"); 1033 return TEST_SKIPPED; 1034 } 1035 1036 return 0; 1037 } 1038 1039 static int 1040 zuc_testsuite_setup(void) 1041 { 1042 struct crypto_testsuite_params *ts_params = &testsuite_params; 1043 uint8_t dev_id = ts_params->valid_devs[0]; 1044 struct rte_cryptodev_info dev_info; 1045 const enum rte_crypto_cipher_algorithm ciphers[] = { 1046 RTE_CRYPTO_CIPHER_ZUC_EEA3 1047 }; 1048 const enum rte_crypto_auth_algorithm auths[] = { 1049 RTE_CRYPTO_AUTH_ZUC_EIA3 1050 }; 1051 1052 rte_cryptodev_info_get(dev_id, &dev_info); 1053 1054 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1055 RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC " 1056 "testsuite not met\n"); 1057 return TEST_SKIPPED; 1058 } 1059 1060 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1061 && check_auth_capabilities_supported(auths, 1062 RTE_DIM(auths)) != 0) { 1063 RTE_LOG(INFO, USER1, "Capability requirements for ZUC " 1064 "testsuite not met\n"); 1065 return TEST_SKIPPED; 1066 } 1067 1068 return 0; 1069 } 1070 1071 static int 1072 hmac_md5_auth_testsuite_setup(void) 1073 { 1074 struct crypto_testsuite_params *ts_params = &testsuite_params; 1075 uint8_t dev_id = ts_params->valid_devs[0]; 1076 struct rte_cryptodev_info dev_info; 1077 const enum rte_crypto_auth_algorithm auths[] = { 1078 RTE_CRYPTO_AUTH_MD5_HMAC 1079 }; 1080 1081 rte_cryptodev_info_get(dev_id, &dev_info); 1082 1083 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1084 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1085 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1086 RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 " 1087 "Auth testsuite not met\n"); 1088 return TEST_SKIPPED; 1089 } 1090 1091 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1092 RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 " 1093 "testsuite not met\n"); 1094 return TEST_SKIPPED; 1095 } 1096 1097 return 0; 1098 } 1099 1100 static int 1101 kasumi_testsuite_setup(void) 1102 { 1103 struct crypto_testsuite_params *ts_params = &testsuite_params; 1104 uint8_t dev_id = ts_params->valid_devs[0]; 1105 struct rte_cryptodev_info dev_info; 1106 const enum rte_crypto_cipher_algorithm ciphers[] = { 1107 RTE_CRYPTO_CIPHER_KASUMI_F8 1108 }; 1109 const enum rte_crypto_auth_algorithm auths[] = { 1110 RTE_CRYPTO_AUTH_KASUMI_F9 1111 }; 1112 1113 rte_cryptodev_info_get(dev_id, &dev_info); 1114 1115 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1116 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1117 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1118 RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi " 1119 "testsuite not met\n"); 1120 return TEST_SKIPPED; 1121 } 1122 1123 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1124 && check_auth_capabilities_supported(auths, 1125 RTE_DIM(auths)) != 0) { 1126 RTE_LOG(INFO, USER1, "Capability requirements for Kasumi " 1127 "testsuite not met\n"); 1128 return TEST_SKIPPED; 1129 } 1130 1131 return 0; 1132 } 1133 1134 static int 1135 negative_aes_gcm_testsuite_setup(void) 1136 { 1137 struct crypto_testsuite_params *ts_params = &testsuite_params; 1138 uint8_t dev_id = ts_params->valid_devs[0]; 1139 struct rte_cryptodev_info dev_info; 1140 const enum rte_crypto_aead_algorithm aeads[] = { 1141 RTE_CRYPTO_AEAD_AES_GCM 1142 }; 1143 1144 rte_cryptodev_info_get(dev_id, &dev_info); 1145 1146 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1147 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1148 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1149 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1150 "AES GCM testsuite not met\n"); 1151 return TEST_SKIPPED; 1152 } 1153 1154 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1155 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1156 "AES GCM testsuite not met\n"); 1157 return TEST_SKIPPED; 1158 } 1159 1160 return 0; 1161 } 1162 1163 static int 1164 negative_aes_gmac_testsuite_setup(void) 1165 { 1166 struct crypto_testsuite_params *ts_params = &testsuite_params; 1167 uint8_t dev_id = ts_params->valid_devs[0]; 1168 struct rte_cryptodev_info dev_info; 1169 const enum rte_crypto_auth_algorithm auths[] = { 1170 RTE_CRYPTO_AUTH_AES_GMAC 1171 }; 1172 1173 rte_cryptodev_info_get(dev_id, &dev_info); 1174 1175 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1176 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1177 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1178 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1179 "AES GMAC testsuite not met\n"); 1180 return TEST_SKIPPED; 1181 } 1182 1183 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1184 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1185 "AES GMAC testsuite not met\n"); 1186 return TEST_SKIPPED; 1187 } 1188 1189 return 0; 1190 } 1191 1192 static int 1193 mixed_cipher_hash_testsuite_setup(void) 1194 { 1195 struct crypto_testsuite_params *ts_params = &testsuite_params; 1196 uint8_t dev_id = ts_params->valid_devs[0]; 1197 struct rte_cryptodev_info dev_info; 1198 uint64_t feat_flags; 1199 const enum rte_crypto_cipher_algorithm ciphers[] = { 1200 RTE_CRYPTO_CIPHER_NULL, 1201 RTE_CRYPTO_CIPHER_AES_CTR, 1202 RTE_CRYPTO_CIPHER_ZUC_EEA3, 1203 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1204 }; 1205 const enum rte_crypto_auth_algorithm auths[] = { 1206 RTE_CRYPTO_AUTH_NULL, 1207 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 1208 RTE_CRYPTO_AUTH_AES_CMAC, 1209 RTE_CRYPTO_AUTH_ZUC_EIA3 1210 }; 1211 1212 rte_cryptodev_info_get(dev_id, &dev_info); 1213 feat_flags = dev_info.feature_flags; 1214 1215 if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1216 (global_api_test_type == CRYPTODEV_RAW_API_TEST)) { 1217 RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed " 1218 "Cipher Hash testsuite not met\n"); 1219 return TEST_SKIPPED; 1220 } 1221 1222 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1223 && check_auth_capabilities_supported(auths, 1224 RTE_DIM(auths)) != 0) { 1225 RTE_LOG(INFO, USER1, "Capability requirements for Mixed " 1226 "Cipher Hash testsuite not met\n"); 1227 return TEST_SKIPPED; 1228 } 1229 1230 return 0; 1231 } 1232 1233 static int 1234 esn_testsuite_setup(void) 1235 { 1236 struct crypto_testsuite_params *ts_params = &testsuite_params; 1237 uint8_t dev_id = ts_params->valid_devs[0]; 1238 struct rte_cryptodev_info dev_info; 1239 const enum rte_crypto_cipher_algorithm ciphers[] = { 1240 RTE_CRYPTO_CIPHER_AES_CBC 1241 }; 1242 const enum rte_crypto_auth_algorithm auths[] = { 1243 RTE_CRYPTO_AUTH_SHA1_HMAC 1244 }; 1245 1246 rte_cryptodev_info_get(dev_id, &dev_info); 1247 1248 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1249 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1250 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1251 RTE_LOG(INFO, USER1, "Feature flag requirements for ESN " 1252 "testsuite not met\n"); 1253 return TEST_SKIPPED; 1254 } 1255 1256 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1257 && check_auth_capabilities_supported(auths, 1258 RTE_DIM(auths)) != 0) { 1259 RTE_LOG(INFO, USER1, "Capability requirements for ESN " 1260 "testsuite not met\n"); 1261 return TEST_SKIPPED; 1262 } 1263 1264 return 0; 1265 } 1266 1267 static int 1268 multi_session_testsuite_setup(void) 1269 { 1270 struct crypto_testsuite_params *ts_params = &testsuite_params; 1271 uint8_t dev_id = ts_params->valid_devs[0]; 1272 struct rte_cryptodev_info dev_info; 1273 const enum rte_crypto_cipher_algorithm ciphers[] = { 1274 RTE_CRYPTO_CIPHER_AES_CBC 1275 }; 1276 const enum rte_crypto_auth_algorithm auths[] = { 1277 RTE_CRYPTO_AUTH_SHA512_HMAC 1278 }; 1279 1280 rte_cryptodev_info_get(dev_id, &dev_info); 1281 1282 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1283 RTE_LOG(INFO, USER1, "Feature flag requirements for Multi " 1284 "Session testsuite not met\n"); 1285 return TEST_SKIPPED; 1286 } 1287 1288 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1289 && check_auth_capabilities_supported(auths, 1290 RTE_DIM(auths)) != 0) { 1291 RTE_LOG(INFO, USER1, "Capability requirements for Multi " 1292 "Session testsuite not met\n"); 1293 return TEST_SKIPPED; 1294 } 1295 1296 return 0; 1297 } 1298 1299 static int 1300 negative_hmac_sha1_testsuite_setup(void) 1301 { 1302 struct crypto_testsuite_params *ts_params = &testsuite_params; 1303 uint8_t dev_id = ts_params->valid_devs[0]; 1304 struct rte_cryptodev_info dev_info; 1305 const enum rte_crypto_cipher_algorithm ciphers[] = { 1306 RTE_CRYPTO_CIPHER_AES_CBC 1307 }; 1308 const enum rte_crypto_auth_algorithm auths[] = { 1309 RTE_CRYPTO_AUTH_SHA1_HMAC 1310 }; 1311 1312 rte_cryptodev_info_get(dev_id, &dev_info); 1313 1314 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1315 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1316 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1317 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1318 "HMAC SHA1 testsuite not met\n"); 1319 return TEST_SKIPPED; 1320 } 1321 1322 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1323 && check_auth_capabilities_supported(auths, 1324 RTE_DIM(auths)) != 0) { 1325 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1326 "HMAC SHA1 testsuite not met\n"); 1327 return TEST_SKIPPED; 1328 } 1329 1330 return 0; 1331 } 1332 1333 static int 1334 dev_configure_and_start(uint64_t ff_disable) 1335 { 1336 struct crypto_testsuite_params *ts_params = &testsuite_params; 1337 struct crypto_unittest_params *ut_params = &unittest_params; 1338 1339 uint16_t qp_id; 1340 1341 /* Clear unit test parameters before running test */ 1342 memset(ut_params, 0, sizeof(*ut_params)); 1343 1344 /* Reconfigure device to default parameters */ 1345 ts_params->conf.socket_id = SOCKET_ID_ANY; 1346 ts_params->conf.ff_disable = ff_disable; 1347 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 1348 ts_params->qp_conf.mp_session = ts_params->session_mpool; 1349 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 1350 1351 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1352 &ts_params->conf), 1353 "Failed to configure cryptodev %u", 1354 ts_params->valid_devs[0]); 1355 1356 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { 1357 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1358 ts_params->valid_devs[0], qp_id, 1359 &ts_params->qp_conf, 1360 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1361 "Failed to setup queue pair %u on cryptodev %u", 1362 qp_id, ts_params->valid_devs[0]); 1363 } 1364 1365 1366 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 1367 1368 /* Start the device */ 1369 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 1370 "Failed to start cryptodev %u", 1371 ts_params->valid_devs[0]); 1372 1373 return TEST_SUCCESS; 1374 } 1375 1376 int 1377 ut_setup(void) 1378 { 1379 /* Configure and start the device with security feature disabled */ 1380 return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY); 1381 } 1382 1383 static int 1384 ut_setup_security(void) 1385 { 1386 /* Configure and start the device with no features disabled */ 1387 return dev_configure_and_start(0); 1388 } 1389 1390 void 1391 ut_teardown(void) 1392 { 1393 struct crypto_testsuite_params *ts_params = &testsuite_params; 1394 struct crypto_unittest_params *ut_params = &unittest_params; 1395 struct rte_cryptodev_stats stats; 1396 1397 /* free crypto session structure */ 1398 #ifdef RTE_LIB_SECURITY 1399 if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) { 1400 if (ut_params->sec_session) { 1401 rte_security_session_destroy(rte_cryptodev_get_sec_ctx 1402 (ts_params->valid_devs[0]), 1403 ut_params->sec_session); 1404 ut_params->sec_session = NULL; 1405 } 1406 } else 1407 #endif 1408 { 1409 if (ut_params->sess) { 1410 rte_cryptodev_sym_session_clear( 1411 ts_params->valid_devs[0], 1412 ut_params->sess); 1413 rte_cryptodev_sym_session_free(ut_params->sess); 1414 ut_params->sess = NULL; 1415 } 1416 } 1417 1418 /* free crypto operation structure */ 1419 if (ut_params->op) 1420 rte_crypto_op_free(ut_params->op); 1421 1422 /* 1423 * free mbuf - both obuf and ibuf are usually the same, 1424 * so check if they point at the same address is necessary, 1425 * to avoid freeing the mbuf twice. 1426 */ 1427 if (ut_params->obuf) { 1428 rte_pktmbuf_free(ut_params->obuf); 1429 if (ut_params->ibuf == ut_params->obuf) 1430 ut_params->ibuf = 0; 1431 ut_params->obuf = 0; 1432 } 1433 if (ut_params->ibuf) { 1434 rte_pktmbuf_free(ut_params->ibuf); 1435 ut_params->ibuf = 0; 1436 } 1437 1438 if (ts_params->mbuf_pool != NULL) 1439 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 1440 rte_mempool_avail_count(ts_params->mbuf_pool)); 1441 1442 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats); 1443 1444 /* Stop the device */ 1445 rte_cryptodev_stop(ts_params->valid_devs[0]); 1446 } 1447 1448 static int 1449 test_device_configure_invalid_dev_id(void) 1450 { 1451 struct crypto_testsuite_params *ts_params = &testsuite_params; 1452 uint16_t dev_id, num_devs = 0; 1453 1454 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 1455 "Need at least %d devices for test", 1); 1456 1457 /* valid dev_id values */ 1458 dev_id = ts_params->valid_devs[0]; 1459 1460 /* Stop the device in case it's started so it can be configured */ 1461 rte_cryptodev_stop(dev_id); 1462 1463 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 1464 "Failed test for rte_cryptodev_configure: " 1465 "invalid dev_num %u", dev_id); 1466 1467 /* invalid dev_id values */ 1468 dev_id = num_devs; 1469 1470 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1471 "Failed test for rte_cryptodev_configure: " 1472 "invalid dev_num %u", dev_id); 1473 1474 dev_id = 0xff; 1475 1476 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1477 "Failed test for rte_cryptodev_configure:" 1478 "invalid dev_num %u", dev_id); 1479 1480 return TEST_SUCCESS; 1481 } 1482 1483 static int 1484 test_device_configure_invalid_queue_pair_ids(void) 1485 { 1486 struct crypto_testsuite_params *ts_params = &testsuite_params; 1487 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 1488 1489 /* Stop the device in case it's started so it can be configured */ 1490 rte_cryptodev_stop(ts_params->valid_devs[0]); 1491 1492 /* valid - max value queue pairs */ 1493 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1494 1495 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1496 &ts_params->conf), 1497 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1498 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 1499 1500 /* valid - one queue pairs */ 1501 ts_params->conf.nb_queue_pairs = 1; 1502 1503 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1504 &ts_params->conf), 1505 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1506 ts_params->valid_devs[0], 1507 ts_params->conf.nb_queue_pairs); 1508 1509 1510 /* invalid - zero queue pairs */ 1511 ts_params->conf.nb_queue_pairs = 0; 1512 1513 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1514 &ts_params->conf), 1515 "Failed test for rte_cryptodev_configure, dev_id %u," 1516 " invalid qps: %u", 1517 ts_params->valid_devs[0], 1518 ts_params->conf.nb_queue_pairs); 1519 1520 1521 /* invalid - max value supported by field queue pairs */ 1522 ts_params->conf.nb_queue_pairs = UINT16_MAX; 1523 1524 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1525 &ts_params->conf), 1526 "Failed test for rte_cryptodev_configure, dev_id %u," 1527 " invalid qps: %u", 1528 ts_params->valid_devs[0], 1529 ts_params->conf.nb_queue_pairs); 1530 1531 1532 /* invalid - max value + 1 queue pairs */ 1533 ts_params->conf.nb_queue_pairs = orig_nb_qps + 1; 1534 1535 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1536 &ts_params->conf), 1537 "Failed test for rte_cryptodev_configure, dev_id %u," 1538 " invalid qps: %u", 1539 ts_params->valid_devs[0], 1540 ts_params->conf.nb_queue_pairs); 1541 1542 /* revert to original testsuite value */ 1543 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1544 1545 return TEST_SUCCESS; 1546 } 1547 1548 static int 1549 test_queue_pair_descriptor_setup(void) 1550 { 1551 struct crypto_testsuite_params *ts_params = &testsuite_params; 1552 struct rte_cryptodev_qp_conf qp_conf = { 1553 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 1554 }; 1555 uint16_t qp_id; 1556 1557 /* Stop the device in case it's started so it can be configured */ 1558 rte_cryptodev_stop(ts_params->valid_devs[0]); 1559 1560 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1561 &ts_params->conf), 1562 "Failed to configure cryptodev %u", 1563 ts_params->valid_devs[0]); 1564 1565 /* 1566 * Test various ring sizes on this device. memzones can't be 1567 * freed so are re-used if ring is released and re-created. 1568 */ 1569 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/ 1570 qp_conf.mp_session = ts_params->session_mpool; 1571 qp_conf.mp_session_private = ts_params->session_priv_mpool; 1572 1573 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1574 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1575 ts_params->valid_devs[0], qp_id, &qp_conf, 1576 rte_cryptodev_socket_id( 1577 ts_params->valid_devs[0])), 1578 "Failed test for " 1579 "rte_cryptodev_queue_pair_setup: num_inflights " 1580 "%u on qp %u on cryptodev %u", 1581 qp_conf.nb_descriptors, qp_id, 1582 ts_params->valid_devs[0]); 1583 } 1584 1585 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2); 1586 1587 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1588 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1589 ts_params->valid_devs[0], qp_id, &qp_conf, 1590 rte_cryptodev_socket_id( 1591 ts_params->valid_devs[0])), 1592 "Failed test for" 1593 " rte_cryptodev_queue_pair_setup: num_inflights" 1594 " %u on qp %u on cryptodev %u", 1595 qp_conf.nb_descriptors, qp_id, 1596 ts_params->valid_devs[0]); 1597 } 1598 1599 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */ 1600 1601 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1602 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1603 ts_params->valid_devs[0], qp_id, &qp_conf, 1604 rte_cryptodev_socket_id( 1605 ts_params->valid_devs[0])), 1606 "Failed test for " 1607 "rte_cryptodev_queue_pair_setup: num_inflights" 1608 " %u on qp %u on cryptodev %u", 1609 qp_conf.nb_descriptors, qp_id, 1610 ts_params->valid_devs[0]); 1611 } 1612 1613 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 1614 1615 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1616 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1617 ts_params->valid_devs[0], qp_id, &qp_conf, 1618 rte_cryptodev_socket_id( 1619 ts_params->valid_devs[0])), 1620 "Failed test for" 1621 " rte_cryptodev_queue_pair_setup:" 1622 "num_inflights %u on qp %u on cryptodev %u", 1623 qp_conf.nb_descriptors, qp_id, 1624 ts_params->valid_devs[0]); 1625 } 1626 1627 /* test invalid queue pair id */ 1628 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */ 1629 1630 qp_id = ts_params->conf.nb_queue_pairs; /*invalid */ 1631 1632 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1633 ts_params->valid_devs[0], 1634 qp_id, &qp_conf, 1635 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1636 "Failed test for rte_cryptodev_queue_pair_setup:" 1637 "invalid qp %u on cryptodev %u", 1638 qp_id, ts_params->valid_devs[0]); 1639 1640 qp_id = 0xffff; /*invalid*/ 1641 1642 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1643 ts_params->valid_devs[0], 1644 qp_id, &qp_conf, 1645 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1646 "Failed test for rte_cryptodev_queue_pair_setup:" 1647 "invalid qp %u on cryptodev %u", 1648 qp_id, ts_params->valid_devs[0]); 1649 1650 return TEST_SUCCESS; 1651 } 1652 1653 /* ***** Plaintext data for tests ***** */ 1654 1655 const char catch_22_quote_1[] = 1656 "There was only one catch and that was Catch-22, which " 1657 "specified that a concern for one's safety in the face of " 1658 "dangers that were real and immediate was the process of a " 1659 "rational mind. Orr was crazy and could be grounded. All he " 1660 "had to do was ask; and as soon as he did, he would no longer " 1661 "be crazy and would have to fly more missions. Orr would be " 1662 "crazy to fly more missions and sane if he didn't, but if he " 1663 "was sane he had to fly them. If he flew them he was crazy " 1664 "and didn't have to; but if he didn't want to he was sane and " 1665 "had to. Yossarian was moved very deeply by the absolute " 1666 "simplicity of this clause of Catch-22 and let out a " 1667 "respectful whistle. \"That's some catch, that Catch-22\", he " 1668 "observed. \"It's the best there is,\" Doc Daneeka agreed."; 1669 1670 const char catch_22_quote[] = 1671 "What a lousy earth! He wondered how many people were " 1672 "destitute that same night even in his own prosperous country, " 1673 "how many homes were shanties, how many husbands were drunk " 1674 "and wives socked, and how many children were bullied, abused, " 1675 "or abandoned. How many families hungered for food they could " 1676 "not afford to buy? How many hearts were broken? How many " 1677 "suicides would take place that same night, how many people " 1678 "would go insane? How many cockroaches and landlords would " 1679 "triumph? How many winners were losers, successes failures, " 1680 "and rich men poor men? How many wise guys were stupid? How " 1681 "many happy endings were unhappy endings? How many honest men " 1682 "were liars, brave men cowards, loyal men traitors, how many " 1683 "sainted men were corrupt, how many people in positions of " 1684 "trust had sold their souls to bodyguards, how many had never " 1685 "had souls? How many straight-and-narrow paths were crooked " 1686 "paths? How many best families were worst families and how " 1687 "many good people were bad people? When you added them all up " 1688 "and then subtracted, you might be left with only the children, " 1689 "and perhaps with Albert Einstein and an old violinist or " 1690 "sculptor somewhere."; 1691 1692 #define QUOTE_480_BYTES (480) 1693 #define QUOTE_512_BYTES (512) 1694 #define QUOTE_768_BYTES (768) 1695 #define QUOTE_1024_BYTES (1024) 1696 1697 1698 1699 /* ***** SHA1 Hash Tests ***** */ 1700 1701 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1) 1702 1703 static uint8_t hmac_sha1_key[] = { 1704 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 1705 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 1706 0xDE, 0xF4, 0xDE, 0xAD }; 1707 1708 /* ***** SHA224 Hash Tests ***** */ 1709 1710 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224) 1711 1712 1713 /* ***** AES-CBC Cipher Tests ***** */ 1714 1715 #define CIPHER_KEY_LENGTH_AES_CBC (16) 1716 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC) 1717 1718 static uint8_t aes_cbc_key[] = { 1719 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 1720 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A }; 1721 1722 static uint8_t aes_cbc_iv[] = { 1723 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 1724 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; 1725 1726 1727 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */ 1728 1729 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = { 1730 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, 1731 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, 1732 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, 1733 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, 1734 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E, 1735 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08, 1736 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0, 1737 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01, 1738 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57, 1739 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE, 1740 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9, 1741 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9, 1742 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D, 1743 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3, 1744 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46, 1745 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3, 1746 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80, 1747 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92, 1748 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5, 1749 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5, 1750 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2, 1751 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5, 1752 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1753 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76, 1754 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4, 1755 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62, 1756 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4, 1757 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4, 1758 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54, 1759 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61, 1760 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91, 1761 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A, 1762 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF, 1763 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F, 1764 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28, 1765 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E, 1766 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7, 1767 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76, 1768 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6, 1769 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03, 1770 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C, 1771 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2, 1772 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6, 1773 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96, 1774 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6, 1775 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA, 1776 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87, 1777 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55, 1778 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B, 1779 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98, 1780 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53, 1781 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A, 1782 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26, 1783 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36, 1784 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36, 1785 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D, 1786 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E, 1787 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E, 1788 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A, 1789 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6, 1790 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4, 1791 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7, 1792 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1, 1793 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C 1794 }; 1795 1796 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = { 1797 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60, 1798 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1799 0x18, 0x8c, 0x1d, 0x32 1800 }; 1801 1802 1803 /* Multisession Vector context Test */ 1804 /*Begin Session 0 */ 1805 static uint8_t ms_aes_cbc_key0[] = { 1806 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1807 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1808 }; 1809 1810 static uint8_t ms_aes_cbc_iv0[] = { 1811 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1812 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1813 }; 1814 1815 static const uint8_t ms_aes_cbc_cipher0[] = { 1816 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38, 1817 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC, 1818 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB, 1819 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9, 1820 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D, 1821 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4, 1822 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34, 1823 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F, 1824 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99, 1825 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED, 1826 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D, 1827 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24, 1828 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71, 1829 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72, 1830 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E, 1831 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD, 1832 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18, 1833 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6, 1834 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29, 1835 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C, 1836 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96, 1837 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26, 1838 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55, 1839 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46, 1840 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B, 1841 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4, 1842 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7, 1843 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5, 1844 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0, 1845 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E, 1846 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D, 1847 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44, 1848 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76, 1849 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3, 1850 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83, 1851 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85, 1852 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45, 1853 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25, 1854 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A, 1855 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1, 1856 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA, 1857 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3, 1858 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4, 1859 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60, 1860 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A, 1861 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A, 1862 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9, 1863 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55, 1864 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13, 1865 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B, 1866 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1, 1867 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0, 1868 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3, 1869 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23, 1870 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B, 1871 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07, 1872 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB, 1873 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1, 1874 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F, 1875 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F, 1876 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84, 1877 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B, 1878 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17, 1879 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF 1880 }; 1881 1882 1883 static uint8_t ms_hmac_key0[] = { 1884 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1885 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1886 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1887 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1888 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1889 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1890 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1891 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1892 }; 1893 1894 static const uint8_t ms_hmac_digest0[] = { 1895 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51, 1896 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F, 1897 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C, 1898 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4, 1899 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56, 1900 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4, 1901 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23, 1902 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90 1903 }; 1904 1905 /* End Session 0 */ 1906 /* Begin session 1 */ 1907 1908 static uint8_t ms_aes_cbc_key1[] = { 1909 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1910 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1911 }; 1912 1913 static uint8_t ms_aes_cbc_iv1[] = { 1914 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1915 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1916 }; 1917 1918 static const uint8_t ms_aes_cbc_cipher1[] = { 1919 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71, 1920 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23, 1921 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09, 1922 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A, 1923 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C, 1924 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F, 1925 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9, 1926 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66, 1927 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43, 1928 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB, 1929 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23, 1930 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29, 1931 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26, 1932 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F, 1933 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68, 1934 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77, 1935 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8, 1936 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97, 1937 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3, 1938 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90, 1939 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5, 1940 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E, 1941 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45, 1942 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B, 1943 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5, 1944 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D, 1945 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E, 1946 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD, 1947 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE, 1948 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1, 1949 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F, 1950 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25, 1951 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1, 1952 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3, 1953 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE, 1954 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6, 1955 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52, 1956 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA, 1957 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63, 1958 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E, 1959 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA, 1960 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB, 1961 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71, 1962 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF, 1963 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A, 1964 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95, 1965 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73, 1966 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49, 1967 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB, 1968 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B, 1969 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC, 1970 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED, 1971 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02, 1972 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4, 1973 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF, 1974 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82, 1975 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D, 1976 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6, 1977 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9, 1978 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35, 1979 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0, 1980 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53, 1981 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5, 1982 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3 1983 1984 }; 1985 1986 static uint8_t ms_hmac_key1[] = { 1987 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1988 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1989 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1990 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1991 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1992 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1993 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1994 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1995 }; 1996 1997 static const uint8_t ms_hmac_digest1[] = { 1998 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69, 1999 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50, 2000 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20, 2001 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD, 2002 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9, 2003 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4, 2004 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA, 2005 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F 2006 }; 2007 /* End Session 1 */ 2008 /* Begin Session 2 */ 2009 static uint8_t ms_aes_cbc_key2[] = { 2010 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2011 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2012 }; 2013 2014 static uint8_t ms_aes_cbc_iv2[] = { 2015 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2016 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2017 }; 2018 2019 static const uint8_t ms_aes_cbc_cipher2[] = { 2020 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91, 2021 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97, 2022 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8, 2023 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5, 2024 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98, 2025 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69, 2026 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09, 2027 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF, 2028 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44, 2029 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B, 2030 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9, 2031 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34, 2032 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99, 2033 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF, 2034 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC, 2035 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26, 2036 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3, 2037 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF, 2038 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3, 2039 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3, 2040 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA, 2041 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13, 2042 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38, 2043 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71, 2044 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC, 2045 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1, 2046 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E, 2047 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22, 2048 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62, 2049 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72, 2050 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6, 2051 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6, 2052 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44, 2053 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24, 2054 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5, 2055 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E, 2056 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17, 2057 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9, 2058 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D, 2059 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D, 2060 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22, 2061 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9, 2062 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49, 2063 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E, 2064 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B, 2065 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2, 2066 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95, 2067 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07, 2068 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3, 2069 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A, 2070 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57, 2071 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84, 2072 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61, 2073 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF, 2074 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17, 2075 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A, 2076 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1, 2077 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53, 2078 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7, 2079 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2, 2080 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A, 2081 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8, 2082 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70, 2083 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92 2084 }; 2085 2086 static uint8_t ms_hmac_key2[] = { 2087 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2088 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2089 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2090 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2091 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2092 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2093 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2094 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2095 }; 2096 2097 static const uint8_t ms_hmac_digest2[] = { 2098 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF, 2099 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6, 2100 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77, 2101 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27, 2102 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82, 2103 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24, 2104 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E, 2105 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59 2106 }; 2107 2108 /* End Session 2 */ 2109 2110 2111 static int 2112 test_AES_CBC_HMAC_SHA1_encrypt_digest(void) 2113 { 2114 struct crypto_testsuite_params *ts_params = &testsuite_params; 2115 struct crypto_unittest_params *ut_params = &unittest_params; 2116 2117 /* Verify the capabilities */ 2118 struct rte_cryptodev_sym_capability_idx cap_idx; 2119 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2120 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 2121 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2122 &cap_idx) == NULL) 2123 return TEST_SKIPPED; 2124 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2125 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 2126 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2127 &cap_idx) == NULL) 2128 return TEST_SKIPPED; 2129 2130 /* Generate test mbuf data and space for digest */ 2131 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2132 catch_22_quote, QUOTE_512_BYTES, 0); 2133 2134 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2135 DIGEST_BYTE_LENGTH_SHA1); 2136 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2137 2138 /* Setup Cipher Parameters */ 2139 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2140 ut_params->cipher_xform.next = &ut_params->auth_xform; 2141 2142 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2143 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 2144 ut_params->cipher_xform.cipher.key.data = aes_cbc_key; 2145 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2146 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2147 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2148 2149 /* Setup HMAC Parameters */ 2150 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2151 2152 ut_params->auth_xform.next = NULL; 2153 2154 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 2155 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 2156 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; 2157 ut_params->auth_xform.auth.key.data = hmac_sha1_key; 2158 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; 2159 2160 ut_params->sess = rte_cryptodev_sym_session_create( 2161 ts_params->session_mpool); 2162 2163 /* Create crypto session*/ 2164 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 2165 ut_params->sess, &ut_params->cipher_xform, 2166 ts_params->session_priv_mpool); 2167 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2168 2169 /* Generate crypto op data structure */ 2170 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2171 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2172 TEST_ASSERT_NOT_NULL(ut_params->op, 2173 "Failed to allocate symmetric crypto operation struct"); 2174 2175 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2176 2177 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2178 2179 /* set crypto operation source mbuf */ 2180 sym_op->m_src = ut_params->ibuf; 2181 2182 /* Set crypto operation authentication parameters */ 2183 sym_op->auth.digest.data = ut_params->digest; 2184 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2185 ut_params->ibuf, QUOTE_512_BYTES); 2186 2187 sym_op->auth.data.offset = 0; 2188 sym_op->auth.data.length = QUOTE_512_BYTES; 2189 2190 /* Copy IV at the end of the crypto operation */ 2191 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2192 aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC); 2193 2194 /* Set crypto operation cipher parameters */ 2195 sym_op->cipher.data.offset = 0; 2196 sym_op->cipher.data.length = QUOTE_512_BYTES; 2197 2198 /* Process crypto operation */ 2199 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2200 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2201 ut_params->op); 2202 else 2203 TEST_ASSERT_NOT_NULL( 2204 process_crypto_request(ts_params->valid_devs[0], 2205 ut_params->op), 2206 "failed to process sym crypto op"); 2207 2208 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2209 "crypto op processing failed"); 2210 2211 /* Validate obuf */ 2212 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 2213 uint8_t *); 2214 2215 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, 2216 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 2217 QUOTE_512_BYTES, 2218 "ciphertext data not as expected"); 2219 2220 uint8_t *digest = ciphertext + QUOTE_512_BYTES; 2221 2222 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, 2223 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, 2224 gbl_driver_id == rte_cryptodev_driver_id_get( 2225 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ? 2226 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : 2227 DIGEST_BYTE_LENGTH_SHA1, 2228 "Generated digest data not as expected"); 2229 2230 return TEST_SUCCESS; 2231 } 2232 2233 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ 2234 2235 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) 2236 2237 static uint8_t hmac_sha512_key[] = { 2238 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 2239 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2240 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2241 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60, 2242 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1, 2243 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2244 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76, 2245 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 }; 2246 2247 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = { 2248 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8, 2249 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48, 2250 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8, 2251 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70, 2252 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8, 2253 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E, 2254 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D, 2255 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A }; 2256 2257 2258 2259 static int 2260 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2261 struct crypto_unittest_params *ut_params, 2262 uint8_t *cipher_key, 2263 uint8_t *hmac_key); 2264 2265 static int 2266 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 2267 struct crypto_unittest_params *ut_params, 2268 struct crypto_testsuite_params *ts_params, 2269 const uint8_t *cipher, 2270 const uint8_t *digest, 2271 const uint8_t *iv); 2272 2273 2274 static int 2275 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2276 struct crypto_unittest_params *ut_params, 2277 uint8_t *cipher_key, 2278 uint8_t *hmac_key) 2279 { 2280 2281 /* Setup Cipher Parameters */ 2282 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2283 ut_params->cipher_xform.next = NULL; 2284 2285 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2286 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 2287 ut_params->cipher_xform.cipher.key.data = cipher_key; 2288 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2289 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2290 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2291 2292 /* Setup HMAC Parameters */ 2293 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2294 ut_params->auth_xform.next = &ut_params->cipher_xform; 2295 2296 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 2297 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC; 2298 ut_params->auth_xform.auth.key.data = hmac_key; 2299 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512; 2300 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512; 2301 2302 return TEST_SUCCESS; 2303 } 2304 2305 2306 static int 2307 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 2308 struct crypto_unittest_params *ut_params, 2309 struct crypto_testsuite_params *ts_params, 2310 const uint8_t *cipher, 2311 const uint8_t *digest, 2312 const uint8_t *iv) 2313 { 2314 /* Generate test mbuf data and digest */ 2315 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2316 (const char *) 2317 cipher, 2318 QUOTE_512_BYTES, 0); 2319 2320 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2321 DIGEST_BYTE_LENGTH_SHA512); 2322 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2323 2324 rte_memcpy(ut_params->digest, 2325 digest, 2326 DIGEST_BYTE_LENGTH_SHA512); 2327 2328 /* Generate Crypto op data structure */ 2329 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2330 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2331 TEST_ASSERT_NOT_NULL(ut_params->op, 2332 "Failed to allocate symmetric crypto operation struct"); 2333 2334 rte_crypto_op_attach_sym_session(ut_params->op, sess); 2335 2336 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2337 2338 /* set crypto operation source mbuf */ 2339 sym_op->m_src = ut_params->ibuf; 2340 2341 sym_op->auth.digest.data = ut_params->digest; 2342 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2343 ut_params->ibuf, QUOTE_512_BYTES); 2344 2345 sym_op->auth.data.offset = 0; 2346 sym_op->auth.data.length = QUOTE_512_BYTES; 2347 2348 /* Copy IV at the end of the crypto operation */ 2349 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2350 iv, CIPHER_IV_LENGTH_AES_CBC); 2351 2352 sym_op->cipher.data.offset = 0; 2353 sym_op->cipher.data.length = QUOTE_512_BYTES; 2354 2355 /* Process crypto operation */ 2356 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2357 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2358 ut_params->op); 2359 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2360 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2361 ut_params->op, 1, 1, 0, 0); 2362 else 2363 TEST_ASSERT_NOT_NULL( 2364 process_crypto_request(ts_params->valid_devs[0], 2365 ut_params->op), 2366 "failed to process sym crypto op"); 2367 2368 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2369 "crypto op processing failed"); 2370 2371 ut_params->obuf = ut_params->op->sym->m_src; 2372 2373 /* Validate obuf */ 2374 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2375 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 2376 catch_22_quote, 2377 QUOTE_512_BYTES, 2378 "Plaintext data not as expected"); 2379 2380 /* Validate obuf */ 2381 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2382 "Digest verification failed"); 2383 2384 return TEST_SUCCESS; 2385 } 2386 2387 /* ***** SNOW 3G Tests ***** */ 2388 static int 2389 create_wireless_algo_hash_session(uint8_t dev_id, 2390 const uint8_t *key, const uint8_t key_len, 2391 const uint8_t iv_len, const uint8_t auth_len, 2392 enum rte_crypto_auth_operation op, 2393 enum rte_crypto_auth_algorithm algo) 2394 { 2395 uint8_t hash_key[key_len]; 2396 int status; 2397 2398 struct crypto_testsuite_params *ts_params = &testsuite_params; 2399 struct crypto_unittest_params *ut_params = &unittest_params; 2400 2401 memcpy(hash_key, key, key_len); 2402 2403 debug_hexdump(stdout, "key:", key, key_len); 2404 2405 /* Setup Authentication Parameters */ 2406 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2407 ut_params->auth_xform.next = NULL; 2408 2409 ut_params->auth_xform.auth.op = op; 2410 ut_params->auth_xform.auth.algo = algo; 2411 ut_params->auth_xform.auth.key.length = key_len; 2412 ut_params->auth_xform.auth.key.data = hash_key; 2413 ut_params->auth_xform.auth.digest_length = auth_len; 2414 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 2415 ut_params->auth_xform.auth.iv.length = iv_len; 2416 ut_params->sess = rte_cryptodev_sym_session_create( 2417 ts_params->session_mpool); 2418 2419 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2420 &ut_params->auth_xform, 2421 ts_params->session_priv_mpool); 2422 if (status == -ENOTSUP) 2423 return TEST_SKIPPED; 2424 2425 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2426 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2427 return 0; 2428 } 2429 2430 static int 2431 create_wireless_algo_cipher_session(uint8_t dev_id, 2432 enum rte_crypto_cipher_operation op, 2433 enum rte_crypto_cipher_algorithm algo, 2434 const uint8_t *key, const uint8_t key_len, 2435 uint8_t iv_len) 2436 { 2437 uint8_t cipher_key[key_len]; 2438 int status; 2439 struct crypto_testsuite_params *ts_params = &testsuite_params; 2440 struct crypto_unittest_params *ut_params = &unittest_params; 2441 2442 memcpy(cipher_key, key, key_len); 2443 2444 /* Setup Cipher Parameters */ 2445 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2446 ut_params->cipher_xform.next = NULL; 2447 2448 ut_params->cipher_xform.cipher.algo = algo; 2449 ut_params->cipher_xform.cipher.op = op; 2450 ut_params->cipher_xform.cipher.key.data = cipher_key; 2451 ut_params->cipher_xform.cipher.key.length = key_len; 2452 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2453 ut_params->cipher_xform.cipher.iv.length = iv_len; 2454 2455 debug_hexdump(stdout, "key:", key, key_len); 2456 2457 /* Create Crypto session */ 2458 ut_params->sess = rte_cryptodev_sym_session_create( 2459 ts_params->session_mpool); 2460 2461 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2462 &ut_params->cipher_xform, 2463 ts_params->session_priv_mpool); 2464 if (status == -ENOTSUP) 2465 return TEST_SKIPPED; 2466 2467 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2468 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2469 return 0; 2470 } 2471 2472 static int 2473 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len, 2474 unsigned int cipher_len, 2475 unsigned int cipher_offset) 2476 { 2477 struct crypto_testsuite_params *ts_params = &testsuite_params; 2478 struct crypto_unittest_params *ut_params = &unittest_params; 2479 2480 /* Generate Crypto op data structure */ 2481 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2482 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2483 TEST_ASSERT_NOT_NULL(ut_params->op, 2484 "Failed to allocate pktmbuf offload"); 2485 2486 /* Set crypto operation data parameters */ 2487 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2488 2489 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2490 2491 /* set crypto operation source mbuf */ 2492 sym_op->m_src = ut_params->ibuf; 2493 2494 /* iv */ 2495 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2496 iv, iv_len); 2497 sym_op->cipher.data.length = cipher_len; 2498 sym_op->cipher.data.offset = cipher_offset; 2499 return 0; 2500 } 2501 2502 static int 2503 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len, 2504 unsigned int cipher_len, 2505 unsigned int cipher_offset) 2506 { 2507 struct crypto_testsuite_params *ts_params = &testsuite_params; 2508 struct crypto_unittest_params *ut_params = &unittest_params; 2509 2510 /* Generate Crypto op data structure */ 2511 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2512 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2513 TEST_ASSERT_NOT_NULL(ut_params->op, 2514 "Failed to allocate pktmbuf offload"); 2515 2516 /* Set crypto operation data parameters */ 2517 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2518 2519 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2520 2521 /* set crypto operation source mbuf */ 2522 sym_op->m_src = ut_params->ibuf; 2523 sym_op->m_dst = ut_params->obuf; 2524 2525 /* iv */ 2526 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2527 iv, iv_len); 2528 sym_op->cipher.data.length = cipher_len; 2529 sym_op->cipher.data.offset = cipher_offset; 2530 return 0; 2531 } 2532 2533 static int 2534 create_wireless_algo_cipher_auth_session(uint8_t dev_id, 2535 enum rte_crypto_cipher_operation cipher_op, 2536 enum rte_crypto_auth_operation auth_op, 2537 enum rte_crypto_auth_algorithm auth_algo, 2538 enum rte_crypto_cipher_algorithm cipher_algo, 2539 const uint8_t *key, uint8_t key_len, 2540 uint8_t auth_iv_len, uint8_t auth_len, 2541 uint8_t cipher_iv_len) 2542 2543 { 2544 uint8_t cipher_auth_key[key_len]; 2545 int status; 2546 2547 struct crypto_testsuite_params *ts_params = &testsuite_params; 2548 struct crypto_unittest_params *ut_params = &unittest_params; 2549 2550 memcpy(cipher_auth_key, key, key_len); 2551 2552 /* Setup Authentication Parameters */ 2553 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2554 ut_params->auth_xform.next = NULL; 2555 2556 ut_params->auth_xform.auth.op = auth_op; 2557 ut_params->auth_xform.auth.algo = auth_algo; 2558 ut_params->auth_xform.auth.key.length = key_len; 2559 /* Hash key = cipher key */ 2560 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2561 ut_params->auth_xform.auth.digest_length = auth_len; 2562 /* Auth IV will be after cipher IV */ 2563 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2564 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2565 2566 /* Setup Cipher Parameters */ 2567 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2568 ut_params->cipher_xform.next = &ut_params->auth_xform; 2569 2570 ut_params->cipher_xform.cipher.algo = cipher_algo; 2571 ut_params->cipher_xform.cipher.op = cipher_op; 2572 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2573 ut_params->cipher_xform.cipher.key.length = key_len; 2574 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2575 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2576 2577 debug_hexdump(stdout, "key:", key, key_len); 2578 2579 /* Create Crypto session*/ 2580 ut_params->sess = rte_cryptodev_sym_session_create( 2581 ts_params->session_mpool); 2582 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2583 2584 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2585 &ut_params->cipher_xform, 2586 ts_params->session_priv_mpool); 2587 if (status == -ENOTSUP) 2588 return TEST_SKIPPED; 2589 2590 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2591 return 0; 2592 } 2593 2594 static int 2595 create_wireless_cipher_auth_session(uint8_t dev_id, 2596 enum rte_crypto_cipher_operation cipher_op, 2597 enum rte_crypto_auth_operation auth_op, 2598 enum rte_crypto_auth_algorithm auth_algo, 2599 enum rte_crypto_cipher_algorithm cipher_algo, 2600 const struct wireless_test_data *tdata) 2601 { 2602 const uint8_t key_len = tdata->key.len; 2603 uint8_t cipher_auth_key[key_len]; 2604 int status; 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( 2645 ts_params->session_mpool); 2646 2647 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2648 &ut_params->cipher_xform, 2649 ts_params->session_priv_mpool); 2650 if (status == -ENOTSUP) 2651 return TEST_SKIPPED; 2652 2653 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2654 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2655 return 0; 2656 } 2657 2658 static int 2659 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id, 2660 const struct wireless_test_data *tdata) 2661 { 2662 return create_wireless_cipher_auth_session(dev_id, 2663 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2664 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3, 2665 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata); 2666 } 2667 2668 static int 2669 create_wireless_algo_auth_cipher_session(uint8_t dev_id, 2670 enum rte_crypto_cipher_operation cipher_op, 2671 enum rte_crypto_auth_operation auth_op, 2672 enum rte_crypto_auth_algorithm auth_algo, 2673 enum rte_crypto_cipher_algorithm cipher_algo, 2674 const uint8_t *key, const uint8_t key_len, 2675 uint8_t auth_iv_len, uint8_t auth_len, 2676 uint8_t cipher_iv_len) 2677 { 2678 uint8_t auth_cipher_key[key_len]; 2679 int status; 2680 struct crypto_testsuite_params *ts_params = &testsuite_params; 2681 struct crypto_unittest_params *ut_params = &unittest_params; 2682 2683 memcpy(auth_cipher_key, key, key_len); 2684 2685 /* Setup Authentication Parameters */ 2686 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2687 ut_params->auth_xform.auth.op = auth_op; 2688 ut_params->auth_xform.next = &ut_params->cipher_xform; 2689 ut_params->auth_xform.auth.algo = auth_algo; 2690 ut_params->auth_xform.auth.key.length = key_len; 2691 ut_params->auth_xform.auth.key.data = auth_cipher_key; 2692 ut_params->auth_xform.auth.digest_length = auth_len; 2693 /* Auth IV will be after cipher IV */ 2694 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2695 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2696 2697 /* Setup Cipher Parameters */ 2698 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2699 ut_params->cipher_xform.next = NULL; 2700 ut_params->cipher_xform.cipher.algo = cipher_algo; 2701 ut_params->cipher_xform.cipher.op = cipher_op; 2702 ut_params->cipher_xform.cipher.key.data = auth_cipher_key; 2703 ut_params->cipher_xform.cipher.key.length = key_len; 2704 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2705 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2706 2707 debug_hexdump(stdout, "key:", key, key_len); 2708 2709 /* Create Crypto session*/ 2710 ut_params->sess = rte_cryptodev_sym_session_create( 2711 ts_params->session_mpool); 2712 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2713 2714 if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 2715 ut_params->auth_xform.next = NULL; 2716 ut_params->cipher_xform.next = &ut_params->auth_xform; 2717 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2718 &ut_params->cipher_xform, 2719 ts_params->session_priv_mpool); 2720 2721 } else 2722 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2723 &ut_params->auth_xform, 2724 ts_params->session_priv_mpool); 2725 2726 if (status == -ENOTSUP) 2727 return TEST_SKIPPED; 2728 2729 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2730 2731 return 0; 2732 } 2733 2734 static int 2735 create_wireless_algo_hash_operation(const uint8_t *auth_tag, 2736 unsigned int auth_tag_len, 2737 const uint8_t *iv, unsigned int iv_len, 2738 unsigned int data_pad_len, 2739 enum rte_crypto_auth_operation op, 2740 unsigned int auth_len, unsigned int auth_offset) 2741 { 2742 struct crypto_testsuite_params *ts_params = &testsuite_params; 2743 2744 struct crypto_unittest_params *ut_params = &unittest_params; 2745 2746 /* Generate Crypto op data structure */ 2747 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2748 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2749 TEST_ASSERT_NOT_NULL(ut_params->op, 2750 "Failed to allocate pktmbuf offload"); 2751 2752 /* Set crypto operation data parameters */ 2753 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2754 2755 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2756 2757 /* set crypto operation source mbuf */ 2758 sym_op->m_src = ut_params->ibuf; 2759 2760 /* iv */ 2761 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2762 iv, iv_len); 2763 /* digest */ 2764 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2765 ut_params->ibuf, auth_tag_len); 2766 2767 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2768 "no room to append auth tag"); 2769 ut_params->digest = sym_op->auth.digest.data; 2770 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2771 ut_params->ibuf, data_pad_len); 2772 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2773 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2774 else 2775 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2776 2777 debug_hexdump(stdout, "digest:", 2778 sym_op->auth.digest.data, 2779 auth_tag_len); 2780 2781 sym_op->auth.data.length = auth_len; 2782 sym_op->auth.data.offset = auth_offset; 2783 2784 return 0; 2785 } 2786 2787 static int 2788 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata, 2789 enum rte_crypto_auth_operation op) 2790 { 2791 struct crypto_testsuite_params *ts_params = &testsuite_params; 2792 struct crypto_unittest_params *ut_params = &unittest_params; 2793 2794 const uint8_t *auth_tag = tdata->digest.data; 2795 const unsigned int auth_tag_len = tdata->digest.len; 2796 unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len); 2797 unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2798 2799 const uint8_t *cipher_iv = tdata->cipher_iv.data; 2800 const uint8_t cipher_iv_len = tdata->cipher_iv.len; 2801 const uint8_t *auth_iv = tdata->auth_iv.data; 2802 const uint8_t auth_iv_len = tdata->auth_iv.len; 2803 const unsigned int cipher_len = tdata->validCipherLenInBits.len; 2804 const unsigned int auth_len = tdata->validAuthLenInBits.len; 2805 2806 /* Generate Crypto op data structure */ 2807 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2808 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2809 TEST_ASSERT_NOT_NULL(ut_params->op, 2810 "Failed to allocate pktmbuf offload"); 2811 /* Set crypto operation data parameters */ 2812 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2813 2814 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2815 2816 /* set crypto operation source mbuf */ 2817 sym_op->m_src = ut_params->ibuf; 2818 2819 /* digest */ 2820 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2821 ut_params->ibuf, auth_tag_len); 2822 2823 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2824 "no room to append auth tag"); 2825 ut_params->digest = sym_op->auth.digest.data; 2826 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2827 ut_params->ibuf, data_pad_len); 2828 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2829 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2830 else 2831 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2832 2833 debug_hexdump(stdout, "digest:", 2834 sym_op->auth.digest.data, 2835 auth_tag_len); 2836 2837 /* Copy cipher and auth IVs at the end of the crypto operation */ 2838 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2839 IV_OFFSET); 2840 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2841 iv_ptr += cipher_iv_len; 2842 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2843 2844 sym_op->cipher.data.length = cipher_len; 2845 sym_op->cipher.data.offset = 0; 2846 sym_op->auth.data.length = auth_len; 2847 sym_op->auth.data.offset = 0; 2848 2849 return 0; 2850 } 2851 2852 static int 2853 create_zuc_cipher_hash_generate_operation( 2854 const struct wireless_test_data *tdata) 2855 { 2856 return create_wireless_cipher_hash_operation(tdata, 2857 RTE_CRYPTO_AUTH_OP_GENERATE); 2858 } 2859 2860 static int 2861 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag, 2862 const unsigned auth_tag_len, 2863 const uint8_t *auth_iv, uint8_t auth_iv_len, 2864 unsigned data_pad_len, 2865 enum rte_crypto_auth_operation op, 2866 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2867 const unsigned cipher_len, const unsigned cipher_offset, 2868 const unsigned auth_len, const unsigned auth_offset) 2869 { 2870 struct crypto_testsuite_params *ts_params = &testsuite_params; 2871 struct crypto_unittest_params *ut_params = &unittest_params; 2872 2873 enum rte_crypto_cipher_algorithm cipher_algo = 2874 ut_params->cipher_xform.cipher.algo; 2875 enum rte_crypto_auth_algorithm auth_algo = 2876 ut_params->auth_xform.auth.algo; 2877 2878 /* Generate Crypto op data structure */ 2879 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2880 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2881 TEST_ASSERT_NOT_NULL(ut_params->op, 2882 "Failed to allocate pktmbuf offload"); 2883 /* Set crypto operation data parameters */ 2884 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2885 2886 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2887 2888 /* set crypto operation source mbuf */ 2889 sym_op->m_src = ut_params->ibuf; 2890 2891 /* digest */ 2892 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2893 ut_params->ibuf, auth_tag_len); 2894 2895 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2896 "no room to append auth tag"); 2897 ut_params->digest = sym_op->auth.digest.data; 2898 2899 if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) { 2900 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2901 ut_params->ibuf, data_pad_len); 2902 } else { 2903 struct rte_mbuf *m = ut_params->ibuf; 2904 unsigned int offset = data_pad_len; 2905 2906 while (offset > m->data_len && m->next != NULL) { 2907 offset -= m->data_len; 2908 m = m->next; 2909 } 2910 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2911 m, offset); 2912 } 2913 2914 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2915 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2916 else 2917 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2918 2919 debug_hexdump(stdout, "digest:", 2920 sym_op->auth.digest.data, 2921 auth_tag_len); 2922 2923 /* Copy cipher and auth IVs at the end of the crypto operation */ 2924 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2925 IV_OFFSET); 2926 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2927 iv_ptr += cipher_iv_len; 2928 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2929 2930 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 2931 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 2932 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 2933 sym_op->cipher.data.length = cipher_len; 2934 sym_op->cipher.data.offset = cipher_offset; 2935 } else { 2936 sym_op->cipher.data.length = cipher_len >> 3; 2937 sym_op->cipher.data.offset = cipher_offset >> 3; 2938 } 2939 2940 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 2941 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 2942 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 2943 sym_op->auth.data.length = auth_len; 2944 sym_op->auth.data.offset = auth_offset; 2945 } else { 2946 sym_op->auth.data.length = auth_len >> 3; 2947 sym_op->auth.data.offset = auth_offset >> 3; 2948 } 2949 2950 return 0; 2951 } 2952 2953 static int 2954 create_wireless_algo_auth_cipher_operation( 2955 const uint8_t *auth_tag, unsigned int auth_tag_len, 2956 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2957 const uint8_t *auth_iv, uint8_t auth_iv_len, 2958 unsigned int data_pad_len, 2959 unsigned int cipher_len, unsigned int cipher_offset, 2960 unsigned int auth_len, unsigned int auth_offset, 2961 uint8_t op_mode, uint8_t do_sgl, uint8_t verify) 2962 { 2963 struct crypto_testsuite_params *ts_params = &testsuite_params; 2964 struct crypto_unittest_params *ut_params = &unittest_params; 2965 2966 enum rte_crypto_cipher_algorithm cipher_algo = 2967 ut_params->cipher_xform.cipher.algo; 2968 enum rte_crypto_auth_algorithm auth_algo = 2969 ut_params->auth_xform.auth.algo; 2970 2971 /* Generate Crypto op data structure */ 2972 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2973 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2974 TEST_ASSERT_NOT_NULL(ut_params->op, 2975 "Failed to allocate pktmbuf offload"); 2976 2977 /* Set crypto operation data parameters */ 2978 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2979 2980 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2981 2982 /* set crypto operation mbufs */ 2983 sym_op->m_src = ut_params->ibuf; 2984 if (op_mode == OUT_OF_PLACE) 2985 sym_op->m_dst = ut_params->obuf; 2986 2987 /* digest */ 2988 if (!do_sgl) { 2989 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset( 2990 (op_mode == IN_PLACE ? 2991 ut_params->ibuf : ut_params->obuf), 2992 uint8_t *, data_pad_len); 2993 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2994 (op_mode == IN_PLACE ? 2995 ut_params->ibuf : ut_params->obuf), 2996 data_pad_len); 2997 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2998 } else { 2999 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3); 3000 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ? 3001 sym_op->m_src : sym_op->m_dst); 3002 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) { 3003 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 3004 sgl_buf = sgl_buf->next; 3005 } 3006 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf, 3007 uint8_t *, remaining_off); 3008 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf, 3009 remaining_off); 3010 memset(sym_op->auth.digest.data, 0, remaining_off); 3011 while (sgl_buf->next != NULL) { 3012 memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *), 3013 0, rte_pktmbuf_data_len(sgl_buf)); 3014 sgl_buf = sgl_buf->next; 3015 } 3016 } 3017 3018 /* Copy digest for the verification */ 3019 if (verify) 3020 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3021 3022 /* Copy cipher and auth IVs at the end of the crypto operation */ 3023 uint8_t *iv_ptr = rte_crypto_op_ctod_offset( 3024 ut_params->op, uint8_t *, IV_OFFSET); 3025 3026 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 3027 iv_ptr += cipher_iv_len; 3028 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 3029 3030 /* Only copy over the offset data needed from src to dst in OOP, 3031 * if the auth and cipher offsets are not aligned 3032 */ 3033 if (op_mode == OUT_OF_PLACE) { 3034 if (cipher_offset > auth_offset) 3035 rte_memcpy( 3036 rte_pktmbuf_mtod_offset( 3037 sym_op->m_dst, 3038 uint8_t *, auth_offset >> 3), 3039 rte_pktmbuf_mtod_offset( 3040 sym_op->m_src, 3041 uint8_t *, auth_offset >> 3), 3042 ((cipher_offset >> 3) - (auth_offset >> 3))); 3043 } 3044 3045 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 3046 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 3047 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 3048 sym_op->cipher.data.length = cipher_len; 3049 sym_op->cipher.data.offset = cipher_offset; 3050 } else { 3051 sym_op->cipher.data.length = cipher_len >> 3; 3052 sym_op->cipher.data.offset = cipher_offset >> 3; 3053 } 3054 3055 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 3056 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 3057 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 3058 sym_op->auth.data.length = auth_len; 3059 sym_op->auth.data.offset = auth_offset; 3060 } else { 3061 sym_op->auth.data.length = auth_len >> 3; 3062 sym_op->auth.data.offset = auth_offset >> 3; 3063 } 3064 3065 return 0; 3066 } 3067 3068 static int 3069 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) 3070 { 3071 struct crypto_testsuite_params *ts_params = &testsuite_params; 3072 struct crypto_unittest_params *ut_params = &unittest_params; 3073 3074 int retval; 3075 unsigned plaintext_pad_len; 3076 unsigned plaintext_len; 3077 uint8_t *plaintext; 3078 struct rte_cryptodev_info dev_info; 3079 3080 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3081 uint64_t feat_flags = dev_info.feature_flags; 3082 3083 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3084 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3085 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3086 return TEST_SKIPPED; 3087 } 3088 3089 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3090 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3091 printf("Device doesn't support RAW data-path APIs.\n"); 3092 return TEST_SKIPPED; 3093 } 3094 3095 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3096 return TEST_SKIPPED; 3097 3098 /* Verify the capabilities */ 3099 struct rte_cryptodev_sym_capability_idx cap_idx; 3100 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3101 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3102 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3103 &cap_idx) == NULL) 3104 return TEST_SKIPPED; 3105 3106 /* Create SNOW 3G session */ 3107 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3108 tdata->key.data, tdata->key.len, 3109 tdata->auth_iv.len, tdata->digest.len, 3110 RTE_CRYPTO_AUTH_OP_GENERATE, 3111 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3112 if (retval < 0) 3113 return retval; 3114 3115 /* alloc mbuf and set payload */ 3116 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3117 3118 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3119 rte_pktmbuf_tailroom(ut_params->ibuf)); 3120 3121 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3122 /* Append data which is padded to a multiple of */ 3123 /* the algorithms block size */ 3124 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3125 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3126 plaintext_pad_len); 3127 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3128 3129 /* Create SNOW 3G operation */ 3130 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3131 tdata->auth_iv.data, tdata->auth_iv.len, 3132 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3133 tdata->validAuthLenInBits.len, 3134 0); 3135 if (retval < 0) 3136 return retval; 3137 3138 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3139 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3140 ut_params->op, 0, 1, 1, 0); 3141 else 3142 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3143 ut_params->op); 3144 ut_params->obuf = ut_params->op->sym->m_src; 3145 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3146 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3147 + plaintext_pad_len; 3148 3149 /* Validate obuf */ 3150 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3151 ut_params->digest, 3152 tdata->digest.data, 3153 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 3154 "SNOW 3G Generated auth tag not as expected"); 3155 3156 return 0; 3157 } 3158 3159 static int 3160 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) 3161 { 3162 struct crypto_testsuite_params *ts_params = &testsuite_params; 3163 struct crypto_unittest_params *ut_params = &unittest_params; 3164 3165 int retval; 3166 unsigned plaintext_pad_len; 3167 unsigned plaintext_len; 3168 uint8_t *plaintext; 3169 struct rte_cryptodev_info dev_info; 3170 3171 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3172 uint64_t feat_flags = dev_info.feature_flags; 3173 3174 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3175 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3176 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3177 return TEST_SKIPPED; 3178 } 3179 3180 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3181 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3182 printf("Device doesn't support RAW data-path APIs.\n"); 3183 return TEST_SKIPPED; 3184 } 3185 3186 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3187 return TEST_SKIPPED; 3188 3189 /* Verify the capabilities */ 3190 struct rte_cryptodev_sym_capability_idx cap_idx; 3191 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3192 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3193 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3194 &cap_idx) == NULL) 3195 return TEST_SKIPPED; 3196 3197 /* Create SNOW 3G session */ 3198 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3199 tdata->key.data, tdata->key.len, 3200 tdata->auth_iv.len, tdata->digest.len, 3201 RTE_CRYPTO_AUTH_OP_VERIFY, 3202 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3203 if (retval < 0) 3204 return retval; 3205 /* alloc mbuf and set payload */ 3206 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3207 3208 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3209 rte_pktmbuf_tailroom(ut_params->ibuf)); 3210 3211 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3212 /* Append data which is padded to a multiple of */ 3213 /* the algorithms block size */ 3214 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3215 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3216 plaintext_pad_len); 3217 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3218 3219 /* Create SNOW 3G operation */ 3220 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3221 tdata->digest.len, 3222 tdata->auth_iv.data, tdata->auth_iv.len, 3223 plaintext_pad_len, 3224 RTE_CRYPTO_AUTH_OP_VERIFY, 3225 tdata->validAuthLenInBits.len, 3226 0); 3227 if (retval < 0) 3228 return retval; 3229 3230 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3231 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3232 ut_params->op, 0, 1, 1, 0); 3233 else 3234 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3235 ut_params->op); 3236 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3237 ut_params->obuf = ut_params->op->sym->m_src; 3238 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3239 + plaintext_pad_len; 3240 3241 /* Validate obuf */ 3242 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3243 return 0; 3244 else 3245 return -1; 3246 3247 return 0; 3248 } 3249 3250 static int 3251 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata) 3252 { 3253 struct crypto_testsuite_params *ts_params = &testsuite_params; 3254 struct crypto_unittest_params *ut_params = &unittest_params; 3255 3256 int retval; 3257 unsigned plaintext_pad_len; 3258 unsigned plaintext_len; 3259 uint8_t *plaintext; 3260 struct rte_cryptodev_info dev_info; 3261 3262 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3263 uint64_t feat_flags = dev_info.feature_flags; 3264 3265 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3266 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3267 printf("Device doesn't support RAW data-path APIs.\n"); 3268 return TEST_SKIPPED; 3269 } 3270 3271 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3272 return TEST_SKIPPED; 3273 3274 /* Verify the capabilities */ 3275 struct rte_cryptodev_sym_capability_idx cap_idx; 3276 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3277 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3278 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3279 &cap_idx) == NULL) 3280 return TEST_SKIPPED; 3281 3282 /* Create KASUMI session */ 3283 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3284 tdata->key.data, tdata->key.len, 3285 0, tdata->digest.len, 3286 RTE_CRYPTO_AUTH_OP_GENERATE, 3287 RTE_CRYPTO_AUTH_KASUMI_F9); 3288 if (retval < 0) 3289 return retval; 3290 3291 /* alloc mbuf and set payload */ 3292 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3293 3294 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3295 rte_pktmbuf_tailroom(ut_params->ibuf)); 3296 3297 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3298 /* Append data which is padded to a multiple of */ 3299 /* the algorithms block size */ 3300 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3301 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3302 plaintext_pad_len); 3303 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3304 3305 /* Create KASUMI operation */ 3306 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3307 NULL, 0, 3308 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3309 tdata->plaintext.len, 3310 0); 3311 if (retval < 0) 3312 return retval; 3313 3314 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3315 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 3316 ut_params->op); 3317 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3318 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3319 ut_params->op, 0, 1, 1, 0); 3320 else 3321 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3322 ut_params->op); 3323 3324 ut_params->obuf = ut_params->op->sym->m_src; 3325 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3326 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3327 + plaintext_pad_len; 3328 3329 /* Validate obuf */ 3330 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3331 ut_params->digest, 3332 tdata->digest.data, 3333 DIGEST_BYTE_LENGTH_KASUMI_F9, 3334 "KASUMI Generated auth tag not as expected"); 3335 3336 return 0; 3337 } 3338 3339 static int 3340 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata) 3341 { 3342 struct crypto_testsuite_params *ts_params = &testsuite_params; 3343 struct crypto_unittest_params *ut_params = &unittest_params; 3344 3345 int retval; 3346 unsigned plaintext_pad_len; 3347 unsigned plaintext_len; 3348 uint8_t *plaintext; 3349 struct rte_cryptodev_info dev_info; 3350 3351 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3352 uint64_t feat_flags = dev_info.feature_flags; 3353 3354 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3355 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3356 printf("Device doesn't support RAW data-path APIs.\n"); 3357 return TEST_SKIPPED; 3358 } 3359 3360 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3361 return TEST_SKIPPED; 3362 3363 /* Verify the capabilities */ 3364 struct rte_cryptodev_sym_capability_idx cap_idx; 3365 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3366 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3367 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3368 &cap_idx) == NULL) 3369 return TEST_SKIPPED; 3370 3371 /* Create KASUMI session */ 3372 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3373 tdata->key.data, tdata->key.len, 3374 0, tdata->digest.len, 3375 RTE_CRYPTO_AUTH_OP_VERIFY, 3376 RTE_CRYPTO_AUTH_KASUMI_F9); 3377 if (retval < 0) 3378 return retval; 3379 /* alloc mbuf and set payload */ 3380 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3381 3382 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3383 rte_pktmbuf_tailroom(ut_params->ibuf)); 3384 3385 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3386 /* Append data which is padded to a multiple */ 3387 /* of the algorithms block size */ 3388 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3389 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3390 plaintext_pad_len); 3391 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3392 3393 /* Create KASUMI operation */ 3394 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3395 tdata->digest.len, 3396 NULL, 0, 3397 plaintext_pad_len, 3398 RTE_CRYPTO_AUTH_OP_VERIFY, 3399 tdata->plaintext.len, 3400 0); 3401 if (retval < 0) 3402 return retval; 3403 3404 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3405 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3406 ut_params->op, 0, 1, 1, 0); 3407 else 3408 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3409 ut_params->op); 3410 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3411 ut_params->obuf = ut_params->op->sym->m_src; 3412 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3413 + plaintext_pad_len; 3414 3415 /* Validate obuf */ 3416 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3417 return 0; 3418 else 3419 return -1; 3420 3421 return 0; 3422 } 3423 3424 static int 3425 test_snow3g_hash_generate_test_case_1(void) 3426 { 3427 return test_snow3g_authentication(&snow3g_hash_test_case_1); 3428 } 3429 3430 static int 3431 test_snow3g_hash_generate_test_case_2(void) 3432 { 3433 return test_snow3g_authentication(&snow3g_hash_test_case_2); 3434 } 3435 3436 static int 3437 test_snow3g_hash_generate_test_case_3(void) 3438 { 3439 return test_snow3g_authentication(&snow3g_hash_test_case_3); 3440 } 3441 3442 static int 3443 test_snow3g_hash_generate_test_case_4(void) 3444 { 3445 return test_snow3g_authentication(&snow3g_hash_test_case_4); 3446 } 3447 3448 static int 3449 test_snow3g_hash_generate_test_case_5(void) 3450 { 3451 return test_snow3g_authentication(&snow3g_hash_test_case_5); 3452 } 3453 3454 static int 3455 test_snow3g_hash_generate_test_case_6(void) 3456 { 3457 return test_snow3g_authentication(&snow3g_hash_test_case_6); 3458 } 3459 3460 static int 3461 test_snow3g_hash_verify_test_case_1(void) 3462 { 3463 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1); 3464 3465 } 3466 3467 static int 3468 test_snow3g_hash_verify_test_case_2(void) 3469 { 3470 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2); 3471 } 3472 3473 static int 3474 test_snow3g_hash_verify_test_case_3(void) 3475 { 3476 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3); 3477 } 3478 3479 static int 3480 test_snow3g_hash_verify_test_case_4(void) 3481 { 3482 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4); 3483 } 3484 3485 static int 3486 test_snow3g_hash_verify_test_case_5(void) 3487 { 3488 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5); 3489 } 3490 3491 static int 3492 test_snow3g_hash_verify_test_case_6(void) 3493 { 3494 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6); 3495 } 3496 3497 static int 3498 test_kasumi_hash_generate_test_case_1(void) 3499 { 3500 return test_kasumi_authentication(&kasumi_hash_test_case_1); 3501 } 3502 3503 static int 3504 test_kasumi_hash_generate_test_case_2(void) 3505 { 3506 return test_kasumi_authentication(&kasumi_hash_test_case_2); 3507 } 3508 3509 static int 3510 test_kasumi_hash_generate_test_case_3(void) 3511 { 3512 return test_kasumi_authentication(&kasumi_hash_test_case_3); 3513 } 3514 3515 static int 3516 test_kasumi_hash_generate_test_case_4(void) 3517 { 3518 return test_kasumi_authentication(&kasumi_hash_test_case_4); 3519 } 3520 3521 static int 3522 test_kasumi_hash_generate_test_case_5(void) 3523 { 3524 return test_kasumi_authentication(&kasumi_hash_test_case_5); 3525 } 3526 3527 static int 3528 test_kasumi_hash_generate_test_case_6(void) 3529 { 3530 return test_kasumi_authentication(&kasumi_hash_test_case_6); 3531 } 3532 3533 static int 3534 test_kasumi_hash_verify_test_case_1(void) 3535 { 3536 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1); 3537 } 3538 3539 static int 3540 test_kasumi_hash_verify_test_case_2(void) 3541 { 3542 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2); 3543 } 3544 3545 static int 3546 test_kasumi_hash_verify_test_case_3(void) 3547 { 3548 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3); 3549 } 3550 3551 static int 3552 test_kasumi_hash_verify_test_case_4(void) 3553 { 3554 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4); 3555 } 3556 3557 static int 3558 test_kasumi_hash_verify_test_case_5(void) 3559 { 3560 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5); 3561 } 3562 3563 static int 3564 test_kasumi_encryption(const struct kasumi_test_data *tdata) 3565 { 3566 struct crypto_testsuite_params *ts_params = &testsuite_params; 3567 struct crypto_unittest_params *ut_params = &unittest_params; 3568 3569 int retval; 3570 uint8_t *plaintext, *ciphertext; 3571 unsigned plaintext_pad_len; 3572 unsigned plaintext_len; 3573 struct rte_cryptodev_info dev_info; 3574 3575 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3576 uint64_t feat_flags = dev_info.feature_flags; 3577 3578 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3579 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3580 printf("Device doesn't support RAW data-path APIs.\n"); 3581 return TEST_SKIPPED; 3582 } 3583 3584 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3585 return TEST_SKIPPED; 3586 3587 /* Verify the capabilities */ 3588 struct rte_cryptodev_sym_capability_idx cap_idx; 3589 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3590 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3591 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3592 &cap_idx) == NULL) 3593 return TEST_SKIPPED; 3594 3595 /* Create KASUMI session */ 3596 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3597 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3598 RTE_CRYPTO_CIPHER_KASUMI_F8, 3599 tdata->key.data, tdata->key.len, 3600 tdata->cipher_iv.len); 3601 if (retval < 0) 3602 return retval; 3603 3604 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3605 3606 /* Clear mbuf payload */ 3607 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3608 rte_pktmbuf_tailroom(ut_params->ibuf)); 3609 3610 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3611 /* Append data which is padded to a multiple */ 3612 /* of the algorithms block size */ 3613 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3614 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3615 plaintext_pad_len); 3616 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3617 3618 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3619 3620 /* Create KASUMI operation */ 3621 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3622 tdata->cipher_iv.len, 3623 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3624 tdata->validCipherOffsetInBits.len); 3625 if (retval < 0) 3626 return retval; 3627 3628 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3629 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3630 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3631 else 3632 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3633 ut_params->op); 3634 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3635 3636 ut_params->obuf = ut_params->op->sym->m_dst; 3637 if (ut_params->obuf) 3638 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3639 else 3640 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3641 3642 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3643 3644 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3645 (tdata->validCipherOffsetInBits.len >> 3); 3646 /* Validate obuf */ 3647 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3648 ciphertext, 3649 reference_ciphertext, 3650 tdata->validCipherLenInBits.len, 3651 "KASUMI Ciphertext data not as expected"); 3652 return 0; 3653 } 3654 3655 static int 3656 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata) 3657 { 3658 struct crypto_testsuite_params *ts_params = &testsuite_params; 3659 struct crypto_unittest_params *ut_params = &unittest_params; 3660 3661 int retval; 3662 3663 unsigned int plaintext_pad_len; 3664 unsigned int plaintext_len; 3665 3666 uint8_t buffer[10000]; 3667 const uint8_t *ciphertext; 3668 3669 struct rte_cryptodev_info dev_info; 3670 3671 /* Verify the capabilities */ 3672 struct rte_cryptodev_sym_capability_idx cap_idx; 3673 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3674 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3675 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3676 &cap_idx) == NULL) 3677 return TEST_SKIPPED; 3678 3679 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3680 3681 uint64_t feat_flags = dev_info.feature_flags; 3682 3683 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 3684 printf("Device doesn't support in-place scatter-gather. " 3685 "Test Skipped.\n"); 3686 return TEST_SKIPPED; 3687 } 3688 3689 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3690 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3691 printf("Device doesn't support RAW data-path APIs.\n"); 3692 return TEST_SKIPPED; 3693 } 3694 3695 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3696 return TEST_SKIPPED; 3697 3698 /* Create KASUMI session */ 3699 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3700 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3701 RTE_CRYPTO_CIPHER_KASUMI_F8, 3702 tdata->key.data, tdata->key.len, 3703 tdata->cipher_iv.len); 3704 if (retval < 0) 3705 return retval; 3706 3707 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3708 3709 3710 /* Append data which is padded to a multiple */ 3711 /* of the algorithms block size */ 3712 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3713 3714 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3715 plaintext_pad_len, 10, 0); 3716 3717 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3718 3719 /* Create KASUMI operation */ 3720 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3721 tdata->cipher_iv.len, 3722 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3723 tdata->validCipherOffsetInBits.len); 3724 if (retval < 0) 3725 return retval; 3726 3727 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3728 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3729 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3730 else 3731 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3732 ut_params->op); 3733 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3734 3735 ut_params->obuf = ut_params->op->sym->m_dst; 3736 3737 if (ut_params->obuf) 3738 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3739 plaintext_len, buffer); 3740 else 3741 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3742 tdata->validCipherOffsetInBits.len >> 3, 3743 plaintext_len, buffer); 3744 3745 /* Validate obuf */ 3746 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3747 3748 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3749 (tdata->validCipherOffsetInBits.len >> 3); 3750 /* Validate obuf */ 3751 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3752 ciphertext, 3753 reference_ciphertext, 3754 tdata->validCipherLenInBits.len, 3755 "KASUMI Ciphertext data not as expected"); 3756 return 0; 3757 } 3758 3759 static int 3760 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata) 3761 { 3762 struct crypto_testsuite_params *ts_params = &testsuite_params; 3763 struct crypto_unittest_params *ut_params = &unittest_params; 3764 3765 int retval; 3766 uint8_t *plaintext, *ciphertext; 3767 unsigned plaintext_pad_len; 3768 unsigned plaintext_len; 3769 3770 /* Verify the capabilities */ 3771 struct rte_cryptodev_sym_capability_idx cap_idx; 3772 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3773 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3774 /* Data-path service does not support OOP */ 3775 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3776 &cap_idx) == NULL) 3777 return TEST_SKIPPED; 3778 3779 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3780 return TEST_SKIPPED; 3781 3782 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3783 return TEST_SKIPPED; 3784 3785 /* Create KASUMI session */ 3786 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3787 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3788 RTE_CRYPTO_CIPHER_KASUMI_F8, 3789 tdata->key.data, tdata->key.len, 3790 tdata->cipher_iv.len); 3791 if (retval < 0) 3792 return retval; 3793 3794 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3795 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3796 3797 /* Clear mbuf payload */ 3798 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3799 rte_pktmbuf_tailroom(ut_params->ibuf)); 3800 3801 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3802 /* Append data which is padded to a multiple */ 3803 /* of the algorithms block size */ 3804 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3805 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3806 plaintext_pad_len); 3807 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3808 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3809 3810 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3811 3812 /* Create KASUMI operation */ 3813 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3814 tdata->cipher_iv.len, 3815 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3816 tdata->validCipherOffsetInBits.len); 3817 if (retval < 0) 3818 return retval; 3819 3820 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3821 ut_params->op); 3822 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3823 3824 ut_params->obuf = ut_params->op->sym->m_dst; 3825 if (ut_params->obuf) 3826 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3827 else 3828 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3829 3830 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3831 3832 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3833 (tdata->validCipherOffsetInBits.len >> 3); 3834 /* Validate obuf */ 3835 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3836 ciphertext, 3837 reference_ciphertext, 3838 tdata->validCipherLenInBits.len, 3839 "KASUMI Ciphertext data not as expected"); 3840 return 0; 3841 } 3842 3843 static int 3844 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata) 3845 { 3846 struct crypto_testsuite_params *ts_params = &testsuite_params; 3847 struct crypto_unittest_params *ut_params = &unittest_params; 3848 3849 int retval; 3850 unsigned int plaintext_pad_len; 3851 unsigned int plaintext_len; 3852 3853 const uint8_t *ciphertext; 3854 uint8_t buffer[2048]; 3855 3856 struct rte_cryptodev_info dev_info; 3857 3858 /* Verify the capabilities */ 3859 struct rte_cryptodev_sym_capability_idx cap_idx; 3860 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3861 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3862 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3863 &cap_idx) == NULL) 3864 return TEST_SKIPPED; 3865 3866 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3867 return TEST_SKIPPED; 3868 3869 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3870 return TEST_SKIPPED; 3871 3872 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3873 3874 uint64_t feat_flags = dev_info.feature_flags; 3875 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 3876 printf("Device doesn't support out-of-place scatter-gather " 3877 "in both input and output mbufs. " 3878 "Test Skipped.\n"); 3879 return TEST_SKIPPED; 3880 } 3881 3882 /* Create KASUMI session */ 3883 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3884 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3885 RTE_CRYPTO_CIPHER_KASUMI_F8, 3886 tdata->key.data, tdata->key.len, 3887 tdata->cipher_iv.len); 3888 if (retval < 0) 3889 return retval; 3890 3891 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3892 /* Append data which is padded to a multiple */ 3893 /* of the algorithms block size */ 3894 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3895 3896 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3897 plaintext_pad_len, 10, 0); 3898 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 3899 plaintext_pad_len, 3, 0); 3900 3901 /* Append data which is padded to a multiple */ 3902 /* of the algorithms block size */ 3903 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3904 3905 /* Create KASUMI operation */ 3906 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3907 tdata->cipher_iv.len, 3908 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3909 tdata->validCipherOffsetInBits.len); 3910 if (retval < 0) 3911 return retval; 3912 3913 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3914 ut_params->op); 3915 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3916 3917 ut_params->obuf = ut_params->op->sym->m_dst; 3918 if (ut_params->obuf) 3919 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3920 plaintext_pad_len, buffer); 3921 else 3922 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3923 tdata->validCipherOffsetInBits.len >> 3, 3924 plaintext_pad_len, buffer); 3925 3926 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3927 (tdata->validCipherOffsetInBits.len >> 3); 3928 /* Validate obuf */ 3929 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3930 ciphertext, 3931 reference_ciphertext, 3932 tdata->validCipherLenInBits.len, 3933 "KASUMI Ciphertext data not as expected"); 3934 return 0; 3935 } 3936 3937 3938 static int 3939 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata) 3940 { 3941 struct crypto_testsuite_params *ts_params = &testsuite_params; 3942 struct crypto_unittest_params *ut_params = &unittest_params; 3943 3944 int retval; 3945 uint8_t *ciphertext, *plaintext; 3946 unsigned ciphertext_pad_len; 3947 unsigned ciphertext_len; 3948 3949 /* Verify the capabilities */ 3950 struct rte_cryptodev_sym_capability_idx cap_idx; 3951 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3952 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3953 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3954 &cap_idx) == NULL) 3955 return TEST_SKIPPED; 3956 3957 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3958 return TEST_SKIPPED; 3959 3960 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3961 return TEST_SKIPPED; 3962 3963 /* Create KASUMI session */ 3964 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3965 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3966 RTE_CRYPTO_CIPHER_KASUMI_F8, 3967 tdata->key.data, tdata->key.len, 3968 tdata->cipher_iv.len); 3969 if (retval < 0) 3970 return retval; 3971 3972 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3973 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3974 3975 /* Clear mbuf payload */ 3976 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3977 rte_pktmbuf_tailroom(ut_params->ibuf)); 3978 3979 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 3980 /* Append data which is padded to a multiple */ 3981 /* of the algorithms block size */ 3982 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 3983 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3984 ciphertext_pad_len); 3985 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 3986 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 3987 3988 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 3989 3990 /* Create KASUMI operation */ 3991 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3992 tdata->cipher_iv.len, 3993 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3994 tdata->validCipherOffsetInBits.len); 3995 if (retval < 0) 3996 return retval; 3997 3998 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3999 ut_params->op); 4000 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4001 4002 ut_params->obuf = ut_params->op->sym->m_dst; 4003 if (ut_params->obuf) 4004 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4005 else 4006 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4007 4008 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4009 4010 const uint8_t *reference_plaintext = tdata->plaintext.data + 4011 (tdata->validCipherOffsetInBits.len >> 3); 4012 /* Validate obuf */ 4013 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4014 plaintext, 4015 reference_plaintext, 4016 tdata->validCipherLenInBits.len, 4017 "KASUMI Plaintext data not as expected"); 4018 return 0; 4019 } 4020 4021 static int 4022 test_kasumi_decryption(const struct kasumi_test_data *tdata) 4023 { 4024 struct crypto_testsuite_params *ts_params = &testsuite_params; 4025 struct crypto_unittest_params *ut_params = &unittest_params; 4026 4027 int retval; 4028 uint8_t *ciphertext, *plaintext; 4029 unsigned ciphertext_pad_len; 4030 unsigned ciphertext_len; 4031 struct rte_cryptodev_info dev_info; 4032 4033 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4034 uint64_t feat_flags = dev_info.feature_flags; 4035 4036 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4037 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4038 printf("Device doesn't support RAW data-path APIs.\n"); 4039 return TEST_SKIPPED; 4040 } 4041 4042 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4043 return TEST_SKIPPED; 4044 4045 /* Verify the capabilities */ 4046 struct rte_cryptodev_sym_capability_idx cap_idx; 4047 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4048 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4049 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4050 &cap_idx) == NULL) 4051 return TEST_SKIPPED; 4052 4053 /* Create KASUMI session */ 4054 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4055 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4056 RTE_CRYPTO_CIPHER_KASUMI_F8, 4057 tdata->key.data, tdata->key.len, 4058 tdata->cipher_iv.len); 4059 if (retval < 0) 4060 return retval; 4061 4062 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4063 4064 /* Clear mbuf payload */ 4065 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4066 rte_pktmbuf_tailroom(ut_params->ibuf)); 4067 4068 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4069 /* Append data which is padded to a multiple */ 4070 /* of the algorithms block size */ 4071 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4072 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4073 ciphertext_pad_len); 4074 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4075 4076 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4077 4078 /* Create KASUMI operation */ 4079 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4080 tdata->cipher_iv.len, 4081 tdata->ciphertext.len, 4082 tdata->validCipherOffsetInBits.len); 4083 if (retval < 0) 4084 return retval; 4085 4086 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4087 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4088 ut_params->op, 1, 0, 1, 0); 4089 else 4090 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4091 ut_params->op); 4092 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4093 4094 ut_params->obuf = ut_params->op->sym->m_dst; 4095 if (ut_params->obuf) 4096 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4097 else 4098 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4099 4100 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4101 4102 const uint8_t *reference_plaintext = tdata->plaintext.data + 4103 (tdata->validCipherOffsetInBits.len >> 3); 4104 /* Validate obuf */ 4105 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4106 plaintext, 4107 reference_plaintext, 4108 tdata->validCipherLenInBits.len, 4109 "KASUMI Plaintext data not as expected"); 4110 return 0; 4111 } 4112 4113 static int 4114 test_snow3g_encryption(const struct snow3g_test_data *tdata) 4115 { 4116 struct crypto_testsuite_params *ts_params = &testsuite_params; 4117 struct crypto_unittest_params *ut_params = &unittest_params; 4118 4119 int retval; 4120 uint8_t *plaintext, *ciphertext; 4121 unsigned plaintext_pad_len; 4122 unsigned plaintext_len; 4123 struct rte_cryptodev_info dev_info; 4124 4125 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4126 uint64_t feat_flags = dev_info.feature_flags; 4127 4128 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4129 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4130 printf("Device doesn't support RAW data-path APIs.\n"); 4131 return TEST_SKIPPED; 4132 } 4133 4134 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4135 return TEST_SKIPPED; 4136 4137 /* Verify the capabilities */ 4138 struct rte_cryptodev_sym_capability_idx cap_idx; 4139 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4140 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4141 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4142 &cap_idx) == NULL) 4143 return TEST_SKIPPED; 4144 4145 /* Create SNOW 3G session */ 4146 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4147 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4148 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4149 tdata->key.data, tdata->key.len, 4150 tdata->cipher_iv.len); 4151 if (retval < 0) 4152 return retval; 4153 4154 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4155 4156 /* Clear mbuf payload */ 4157 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4158 rte_pktmbuf_tailroom(ut_params->ibuf)); 4159 4160 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4161 /* Append data which is padded to a multiple of */ 4162 /* the algorithms block size */ 4163 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4164 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4165 plaintext_pad_len); 4166 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4167 4168 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4169 4170 /* Create SNOW 3G operation */ 4171 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4172 tdata->cipher_iv.len, 4173 tdata->validCipherLenInBits.len, 4174 0); 4175 if (retval < 0) 4176 return retval; 4177 4178 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4179 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4180 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4181 else 4182 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4183 ut_params->op); 4184 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4185 4186 ut_params->obuf = ut_params->op->sym->m_dst; 4187 if (ut_params->obuf) 4188 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4189 else 4190 ciphertext = plaintext; 4191 4192 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4193 4194 /* Validate obuf */ 4195 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4196 ciphertext, 4197 tdata->ciphertext.data, 4198 tdata->validDataLenInBits.len, 4199 "SNOW 3G Ciphertext data not as expected"); 4200 return 0; 4201 } 4202 4203 4204 static int 4205 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) 4206 { 4207 struct crypto_testsuite_params *ts_params = &testsuite_params; 4208 struct crypto_unittest_params *ut_params = &unittest_params; 4209 uint8_t *plaintext, *ciphertext; 4210 4211 int retval; 4212 unsigned plaintext_pad_len; 4213 unsigned plaintext_len; 4214 struct rte_cryptodev_info dev_info; 4215 4216 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4217 uint64_t feat_flags = dev_info.feature_flags; 4218 4219 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4220 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4221 printf("Device does not support RAW data-path APIs.\n"); 4222 return -ENOTSUP; 4223 } 4224 4225 /* Verify the capabilities */ 4226 struct rte_cryptodev_sym_capability_idx cap_idx; 4227 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4228 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4229 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4230 &cap_idx) == NULL) 4231 return TEST_SKIPPED; 4232 4233 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4234 return TEST_SKIPPED; 4235 4236 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4237 return TEST_SKIPPED; 4238 4239 /* Create SNOW 3G session */ 4240 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4241 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4242 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4243 tdata->key.data, tdata->key.len, 4244 tdata->cipher_iv.len); 4245 if (retval < 0) 4246 return retval; 4247 4248 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4249 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4250 4251 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4252 "Failed to allocate input buffer in mempool"); 4253 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4254 "Failed to allocate output buffer in mempool"); 4255 4256 /* Clear mbuf payload */ 4257 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4258 rte_pktmbuf_tailroom(ut_params->ibuf)); 4259 4260 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4261 /* Append data which is padded to a multiple of */ 4262 /* the algorithms block size */ 4263 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4264 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4265 plaintext_pad_len); 4266 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4267 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4268 4269 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4270 4271 /* Create SNOW 3G operation */ 4272 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4273 tdata->cipher_iv.len, 4274 tdata->validCipherLenInBits.len, 4275 0); 4276 if (retval < 0) 4277 return retval; 4278 4279 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4280 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4281 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4282 else 4283 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4284 ut_params->op); 4285 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4286 4287 ut_params->obuf = ut_params->op->sym->m_dst; 4288 if (ut_params->obuf) 4289 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4290 else 4291 ciphertext = plaintext; 4292 4293 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4294 4295 /* Validate obuf */ 4296 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4297 ciphertext, 4298 tdata->ciphertext.data, 4299 tdata->validDataLenInBits.len, 4300 "SNOW 3G Ciphertext data not as expected"); 4301 return 0; 4302 } 4303 4304 static int 4305 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata) 4306 { 4307 struct crypto_testsuite_params *ts_params = &testsuite_params; 4308 struct crypto_unittest_params *ut_params = &unittest_params; 4309 4310 int retval; 4311 unsigned int plaintext_pad_len; 4312 unsigned int plaintext_len; 4313 uint8_t buffer[10000]; 4314 const uint8_t *ciphertext; 4315 4316 struct rte_cryptodev_info dev_info; 4317 4318 /* Verify the capabilities */ 4319 struct rte_cryptodev_sym_capability_idx cap_idx; 4320 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4321 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4322 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4323 &cap_idx) == NULL) 4324 return TEST_SKIPPED; 4325 4326 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4327 return TEST_SKIPPED; 4328 4329 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4330 return TEST_SKIPPED; 4331 4332 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4333 4334 uint64_t feat_flags = dev_info.feature_flags; 4335 4336 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 4337 printf("Device doesn't support out-of-place scatter-gather " 4338 "in both input and output mbufs. " 4339 "Test Skipped.\n"); 4340 return TEST_SKIPPED; 4341 } 4342 4343 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4344 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4345 printf("Device does not support RAW data-path APIs.\n"); 4346 return -ENOTSUP; 4347 } 4348 4349 /* Create SNOW 3G session */ 4350 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4351 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4352 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4353 tdata->key.data, tdata->key.len, 4354 tdata->cipher_iv.len); 4355 if (retval < 0) 4356 return retval; 4357 4358 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4359 /* Append data which is padded to a multiple of */ 4360 /* the algorithms block size */ 4361 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4362 4363 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4364 plaintext_pad_len, 10, 0); 4365 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4366 plaintext_pad_len, 3, 0); 4367 4368 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4369 "Failed to allocate input buffer in mempool"); 4370 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4371 "Failed to allocate output buffer in mempool"); 4372 4373 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 4374 4375 /* Create SNOW 3G operation */ 4376 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4377 tdata->cipher_iv.len, 4378 tdata->validCipherLenInBits.len, 4379 0); 4380 if (retval < 0) 4381 return retval; 4382 4383 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4384 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4385 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4386 else 4387 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4388 ut_params->op); 4389 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4390 4391 ut_params->obuf = ut_params->op->sym->m_dst; 4392 if (ut_params->obuf) 4393 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4394 plaintext_len, buffer); 4395 else 4396 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4397 plaintext_len, buffer); 4398 4399 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4400 4401 /* Validate obuf */ 4402 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4403 ciphertext, 4404 tdata->ciphertext.data, 4405 tdata->validDataLenInBits.len, 4406 "SNOW 3G Ciphertext data not as expected"); 4407 4408 return 0; 4409 } 4410 4411 /* Shift right a buffer by "offset" bits, "offset" < 8 */ 4412 static void 4413 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) 4414 { 4415 uint8_t curr_byte, prev_byte; 4416 uint32_t length_in_bytes = ceil_byte_length(length + offset); 4417 uint8_t lower_byte_mask = (1 << offset) - 1; 4418 unsigned i; 4419 4420 prev_byte = buffer[0]; 4421 buffer[0] >>= offset; 4422 4423 for (i = 1; i < length_in_bytes; i++) { 4424 curr_byte = buffer[i]; 4425 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | 4426 (curr_byte >> offset); 4427 prev_byte = curr_byte; 4428 } 4429 } 4430 4431 static int 4432 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) 4433 { 4434 struct crypto_testsuite_params *ts_params = &testsuite_params; 4435 struct crypto_unittest_params *ut_params = &unittest_params; 4436 uint8_t *plaintext, *ciphertext; 4437 int retval; 4438 uint32_t plaintext_len; 4439 uint32_t plaintext_pad_len; 4440 uint8_t extra_offset = 4; 4441 uint8_t *expected_ciphertext_shifted; 4442 struct rte_cryptodev_info dev_info; 4443 4444 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4445 uint64_t feat_flags = dev_info.feature_flags; 4446 4447 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4448 ((tdata->validDataLenInBits.len % 8) != 0)) { 4449 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4450 return TEST_SKIPPED; 4451 } 4452 4453 /* Verify the capabilities */ 4454 struct rte_cryptodev_sym_capability_idx cap_idx; 4455 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4456 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4457 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4458 &cap_idx) == NULL) 4459 return TEST_SKIPPED; 4460 4461 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4462 return TEST_SKIPPED; 4463 4464 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4465 return TEST_SKIPPED; 4466 4467 /* Create SNOW 3G session */ 4468 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4469 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4470 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4471 tdata->key.data, tdata->key.len, 4472 tdata->cipher_iv.len); 4473 if (retval < 0) 4474 return retval; 4475 4476 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4477 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4478 4479 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4480 "Failed to allocate input buffer in mempool"); 4481 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4482 "Failed to allocate output buffer in mempool"); 4483 4484 /* Clear mbuf payload */ 4485 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4486 rte_pktmbuf_tailroom(ut_params->ibuf)); 4487 4488 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset); 4489 /* 4490 * Append data which is padded to a 4491 * multiple of the algorithms block size 4492 */ 4493 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4494 4495 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, 4496 plaintext_pad_len); 4497 4498 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4499 4500 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); 4501 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); 4502 4503 #ifdef RTE_APP_TEST_DEBUG 4504 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); 4505 #endif 4506 /* Create SNOW 3G operation */ 4507 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4508 tdata->cipher_iv.len, 4509 tdata->validCipherLenInBits.len, 4510 extra_offset); 4511 if (retval < 0) 4512 return retval; 4513 4514 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4515 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4516 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4517 else 4518 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4519 ut_params->op); 4520 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4521 4522 ut_params->obuf = ut_params->op->sym->m_dst; 4523 if (ut_params->obuf) 4524 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4525 else 4526 ciphertext = plaintext; 4527 4528 #ifdef RTE_APP_TEST_DEBUG 4529 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4530 #endif 4531 4532 expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8); 4533 4534 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, 4535 "failed to reserve memory for ciphertext shifted\n"); 4536 4537 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, 4538 ceil_byte_length(tdata->ciphertext.len)); 4539 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, 4540 extra_offset); 4541 /* Validate obuf */ 4542 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4543 ciphertext, 4544 expected_ciphertext_shifted, 4545 tdata->validDataLenInBits.len, 4546 extra_offset, 4547 "SNOW 3G Ciphertext data not as expected"); 4548 return 0; 4549 } 4550 4551 static int test_snow3g_decryption(const struct snow3g_test_data *tdata) 4552 { 4553 struct crypto_testsuite_params *ts_params = &testsuite_params; 4554 struct crypto_unittest_params *ut_params = &unittest_params; 4555 4556 int retval; 4557 4558 uint8_t *plaintext, *ciphertext; 4559 unsigned ciphertext_pad_len; 4560 unsigned ciphertext_len; 4561 struct rte_cryptodev_info dev_info; 4562 4563 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4564 uint64_t feat_flags = dev_info.feature_flags; 4565 4566 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4567 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4568 printf("Device doesn't support RAW data-path APIs.\n"); 4569 return TEST_SKIPPED; 4570 } 4571 4572 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4573 return TEST_SKIPPED; 4574 4575 /* Verify the capabilities */ 4576 struct rte_cryptodev_sym_capability_idx cap_idx; 4577 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4578 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4579 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4580 &cap_idx) == NULL) 4581 return TEST_SKIPPED; 4582 4583 /* Create SNOW 3G session */ 4584 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4585 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4586 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4587 tdata->key.data, tdata->key.len, 4588 tdata->cipher_iv.len); 4589 if (retval < 0) 4590 return retval; 4591 4592 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4593 4594 /* Clear mbuf payload */ 4595 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4596 rte_pktmbuf_tailroom(ut_params->ibuf)); 4597 4598 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4599 /* Append data which is padded to a multiple of */ 4600 /* the algorithms block size */ 4601 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4602 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4603 ciphertext_pad_len); 4604 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4605 4606 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4607 4608 /* Create SNOW 3G operation */ 4609 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4610 tdata->cipher_iv.len, 4611 tdata->validCipherLenInBits.len, 4612 tdata->cipher.offset_bits); 4613 if (retval < 0) 4614 return retval; 4615 4616 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4617 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4618 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4619 else 4620 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4621 ut_params->op); 4622 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4623 ut_params->obuf = ut_params->op->sym->m_dst; 4624 if (ut_params->obuf) 4625 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4626 else 4627 plaintext = ciphertext; 4628 4629 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4630 4631 /* Validate obuf */ 4632 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4633 tdata->plaintext.data, 4634 tdata->validDataLenInBits.len, 4635 "SNOW 3G Plaintext data not as expected"); 4636 return 0; 4637 } 4638 4639 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) 4640 { 4641 struct crypto_testsuite_params *ts_params = &testsuite_params; 4642 struct crypto_unittest_params *ut_params = &unittest_params; 4643 4644 int retval; 4645 4646 uint8_t *plaintext, *ciphertext; 4647 unsigned ciphertext_pad_len; 4648 unsigned ciphertext_len; 4649 struct rte_cryptodev_info dev_info; 4650 4651 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4652 uint64_t feat_flags = dev_info.feature_flags; 4653 4654 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4655 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4656 printf("Device does not support RAW data-path APIs.\n"); 4657 return -ENOTSUP; 4658 } 4659 /* Verify the capabilities */ 4660 struct rte_cryptodev_sym_capability_idx cap_idx; 4661 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4662 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4663 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4664 &cap_idx) == NULL) 4665 return TEST_SKIPPED; 4666 4667 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4668 return TEST_SKIPPED; 4669 4670 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4671 return TEST_SKIPPED; 4672 4673 /* Create SNOW 3G session */ 4674 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4675 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4676 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4677 tdata->key.data, tdata->key.len, 4678 tdata->cipher_iv.len); 4679 if (retval < 0) 4680 return retval; 4681 4682 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4683 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4684 4685 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4686 "Failed to allocate input buffer"); 4687 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4688 "Failed to allocate output buffer"); 4689 4690 /* Clear mbuf payload */ 4691 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4692 rte_pktmbuf_tailroom(ut_params->ibuf)); 4693 4694 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4695 rte_pktmbuf_tailroom(ut_params->obuf)); 4696 4697 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4698 /* Append data which is padded to a multiple of */ 4699 /* the algorithms block size */ 4700 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4701 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4702 ciphertext_pad_len); 4703 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4704 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4705 4706 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4707 4708 /* Create SNOW 3G operation */ 4709 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4710 tdata->cipher_iv.len, 4711 tdata->validCipherLenInBits.len, 4712 0); 4713 if (retval < 0) 4714 return retval; 4715 4716 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4717 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4718 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4719 else 4720 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4721 ut_params->op); 4722 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4723 ut_params->obuf = ut_params->op->sym->m_dst; 4724 if (ut_params->obuf) 4725 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4726 else 4727 plaintext = ciphertext; 4728 4729 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4730 4731 /* Validate obuf */ 4732 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4733 tdata->plaintext.data, 4734 tdata->validDataLenInBits.len, 4735 "SNOW 3G Plaintext data not as expected"); 4736 return 0; 4737 } 4738 4739 static int 4740 test_zuc_cipher_auth(const struct wireless_test_data *tdata) 4741 { 4742 struct crypto_testsuite_params *ts_params = &testsuite_params; 4743 struct crypto_unittest_params *ut_params = &unittest_params; 4744 4745 int retval; 4746 4747 uint8_t *plaintext, *ciphertext; 4748 unsigned int plaintext_pad_len; 4749 unsigned int plaintext_len; 4750 4751 struct rte_cryptodev_info dev_info; 4752 struct rte_cryptodev_sym_capability_idx cap_idx; 4753 4754 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4755 uint64_t feat_flags = dev_info.feature_flags; 4756 4757 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4758 ((tdata->validAuthLenInBits.len % 8 != 0) || 4759 (tdata->validDataLenInBits.len % 8 != 0))) { 4760 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4761 return TEST_SKIPPED; 4762 } 4763 4764 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4765 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4766 printf("Device doesn't support RAW data-path APIs.\n"); 4767 return TEST_SKIPPED; 4768 } 4769 4770 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4771 return TEST_SKIPPED; 4772 4773 /* Check if device supports ZUC EEA3 */ 4774 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4775 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 4776 4777 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4778 &cap_idx) == NULL) 4779 return TEST_SKIPPED; 4780 4781 /* Check if device supports ZUC EIA3 */ 4782 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4783 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 4784 4785 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4786 &cap_idx) == NULL) 4787 return TEST_SKIPPED; 4788 4789 /* Create ZUC session */ 4790 retval = create_zuc_cipher_auth_encrypt_generate_session( 4791 ts_params->valid_devs[0], 4792 tdata); 4793 if (retval != 0) 4794 return retval; 4795 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4796 4797 /* clear mbuf payload */ 4798 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4799 rte_pktmbuf_tailroom(ut_params->ibuf)); 4800 4801 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4802 /* Append data which is padded to a multiple of */ 4803 /* the algorithms block size */ 4804 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4805 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4806 plaintext_pad_len); 4807 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4808 4809 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4810 4811 /* Create ZUC operation */ 4812 retval = create_zuc_cipher_hash_generate_operation(tdata); 4813 if (retval < 0) 4814 return retval; 4815 4816 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4817 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4818 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4819 else 4820 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4821 ut_params->op); 4822 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4823 ut_params->obuf = ut_params->op->sym->m_src; 4824 if (ut_params->obuf) 4825 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4826 else 4827 ciphertext = plaintext; 4828 4829 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4830 /* Validate obuf */ 4831 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4832 ciphertext, 4833 tdata->ciphertext.data, 4834 tdata->validDataLenInBits.len, 4835 "ZUC Ciphertext data not as expected"); 4836 4837 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4838 + plaintext_pad_len; 4839 4840 /* Validate obuf */ 4841 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4842 ut_params->digest, 4843 tdata->digest.data, 4844 4, 4845 "ZUC Generated auth tag not as expected"); 4846 return 0; 4847 } 4848 4849 static int 4850 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) 4851 { 4852 struct crypto_testsuite_params *ts_params = &testsuite_params; 4853 struct crypto_unittest_params *ut_params = &unittest_params; 4854 4855 int retval; 4856 4857 uint8_t *plaintext, *ciphertext; 4858 unsigned plaintext_pad_len; 4859 unsigned plaintext_len; 4860 struct rte_cryptodev_info dev_info; 4861 4862 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4863 uint64_t feat_flags = dev_info.feature_flags; 4864 4865 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4866 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4867 printf("Device doesn't support RAW data-path APIs.\n"); 4868 return TEST_SKIPPED; 4869 } 4870 4871 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4872 return TEST_SKIPPED; 4873 4874 /* Verify the capabilities */ 4875 struct rte_cryptodev_sym_capability_idx cap_idx; 4876 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4877 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4878 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4879 &cap_idx) == NULL) 4880 return TEST_SKIPPED; 4881 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4882 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4883 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4884 &cap_idx) == NULL) 4885 return TEST_SKIPPED; 4886 4887 /* Create SNOW 3G session */ 4888 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0], 4889 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4890 RTE_CRYPTO_AUTH_OP_GENERATE, 4891 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4892 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4893 tdata->key.data, tdata->key.len, 4894 tdata->auth_iv.len, tdata->digest.len, 4895 tdata->cipher_iv.len); 4896 if (retval != 0) 4897 return retval; 4898 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4899 4900 /* clear mbuf payload */ 4901 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4902 rte_pktmbuf_tailroom(ut_params->ibuf)); 4903 4904 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4905 /* Append data which is padded to a multiple of */ 4906 /* the algorithms block size */ 4907 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4908 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4909 plaintext_pad_len); 4910 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4911 4912 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4913 4914 /* Create SNOW 3G operation */ 4915 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 4916 tdata->digest.len, tdata->auth_iv.data, 4917 tdata->auth_iv.len, 4918 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 4919 tdata->cipher_iv.data, tdata->cipher_iv.len, 4920 tdata->validCipherLenInBits.len, 4921 0, 4922 tdata->validAuthLenInBits.len, 4923 0 4924 ); 4925 if (retval < 0) 4926 return retval; 4927 4928 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4929 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4930 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4931 else 4932 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4933 ut_params->op); 4934 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4935 ut_params->obuf = ut_params->op->sym->m_src; 4936 if (ut_params->obuf) 4937 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4938 else 4939 ciphertext = plaintext; 4940 4941 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4942 /* Validate obuf */ 4943 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4944 ciphertext, 4945 tdata->ciphertext.data, 4946 tdata->validDataLenInBits.len, 4947 "SNOW 3G Ciphertext data not as expected"); 4948 4949 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4950 + plaintext_pad_len; 4951 4952 /* Validate obuf */ 4953 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4954 ut_params->digest, 4955 tdata->digest.data, 4956 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4957 "SNOW 3G Generated auth tag not as expected"); 4958 return 0; 4959 } 4960 4961 static int 4962 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata, 4963 uint8_t op_mode, uint8_t verify) 4964 { 4965 struct crypto_testsuite_params *ts_params = &testsuite_params; 4966 struct crypto_unittest_params *ut_params = &unittest_params; 4967 4968 int retval; 4969 4970 uint8_t *plaintext = NULL, *ciphertext = NULL; 4971 unsigned int plaintext_pad_len; 4972 unsigned int plaintext_len; 4973 unsigned int ciphertext_pad_len; 4974 unsigned int ciphertext_len; 4975 4976 struct rte_cryptodev_info dev_info; 4977 4978 /* Verify the capabilities */ 4979 struct rte_cryptodev_sym_capability_idx cap_idx; 4980 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4981 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4982 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4983 &cap_idx) == NULL) 4984 return TEST_SKIPPED; 4985 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4986 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4987 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4988 &cap_idx) == NULL) 4989 return TEST_SKIPPED; 4990 4991 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4992 return TEST_SKIPPED; 4993 4994 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4995 4996 uint64_t feat_flags = dev_info.feature_flags; 4997 4998 if (op_mode == OUT_OF_PLACE) { 4999 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5000 printf("Device doesn't support digest encrypted.\n"); 5001 return TEST_SKIPPED; 5002 } 5003 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5004 return TEST_SKIPPED; 5005 } 5006 5007 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5008 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5009 printf("Device doesn't support RAW data-path APIs.\n"); 5010 return TEST_SKIPPED; 5011 } 5012 5013 /* Create SNOW 3G session */ 5014 retval = create_wireless_algo_auth_cipher_session( 5015 ts_params->valid_devs[0], 5016 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5017 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5018 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5019 : RTE_CRYPTO_AUTH_OP_GENERATE), 5020 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5021 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5022 tdata->key.data, tdata->key.len, 5023 tdata->auth_iv.len, tdata->digest.len, 5024 tdata->cipher_iv.len); 5025 if (retval != 0) 5026 return retval; 5027 5028 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5029 if (op_mode == OUT_OF_PLACE) 5030 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5031 5032 /* clear mbuf payload */ 5033 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5034 rte_pktmbuf_tailroom(ut_params->ibuf)); 5035 if (op_mode == OUT_OF_PLACE) 5036 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5037 rte_pktmbuf_tailroom(ut_params->obuf)); 5038 5039 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5040 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5041 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5042 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5043 5044 if (verify) { 5045 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5046 ciphertext_pad_len); 5047 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5048 if (op_mode == OUT_OF_PLACE) 5049 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5050 debug_hexdump(stdout, "ciphertext:", ciphertext, 5051 ciphertext_len); 5052 } else { 5053 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5054 plaintext_pad_len); 5055 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5056 if (op_mode == OUT_OF_PLACE) 5057 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5058 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5059 } 5060 5061 /* Create SNOW 3G operation */ 5062 retval = create_wireless_algo_auth_cipher_operation( 5063 tdata->digest.data, tdata->digest.len, 5064 tdata->cipher_iv.data, tdata->cipher_iv.len, 5065 tdata->auth_iv.data, tdata->auth_iv.len, 5066 (tdata->digest.offset_bytes == 0 ? 5067 (verify ? ciphertext_pad_len : plaintext_pad_len) 5068 : tdata->digest.offset_bytes), 5069 tdata->validCipherLenInBits.len, 5070 tdata->cipher.offset_bits, 5071 tdata->validAuthLenInBits.len, 5072 tdata->auth.offset_bits, 5073 op_mode, 0, verify); 5074 5075 if (retval < 0) 5076 return retval; 5077 5078 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5079 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5080 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5081 else 5082 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5083 ut_params->op); 5084 5085 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5086 5087 ut_params->obuf = (op_mode == IN_PLACE ? 5088 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5089 5090 if (verify) { 5091 if (ut_params->obuf) 5092 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5093 uint8_t *); 5094 else 5095 plaintext = ciphertext + 5096 (tdata->cipher.offset_bits >> 3); 5097 5098 debug_hexdump(stdout, "plaintext:", plaintext, 5099 (tdata->plaintext.len >> 3) - tdata->digest.len); 5100 debug_hexdump(stdout, "plaintext expected:", 5101 tdata->plaintext.data, 5102 (tdata->plaintext.len >> 3) - tdata->digest.len); 5103 } else { 5104 if (ut_params->obuf) 5105 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5106 uint8_t *); 5107 else 5108 ciphertext = plaintext; 5109 5110 debug_hexdump(stdout, "ciphertext:", ciphertext, 5111 ciphertext_len); 5112 debug_hexdump(stdout, "ciphertext expected:", 5113 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5114 5115 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5116 + (tdata->digest.offset_bytes == 0 ? 5117 plaintext_pad_len : tdata->digest.offset_bytes); 5118 5119 debug_hexdump(stdout, "digest:", ut_params->digest, 5120 tdata->digest.len); 5121 debug_hexdump(stdout, "digest expected:", tdata->digest.data, 5122 tdata->digest.len); 5123 } 5124 5125 /* Validate obuf */ 5126 if (verify) { 5127 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5128 plaintext, 5129 tdata->plaintext.data, 5130 (tdata->plaintext.len - tdata->cipher.offset_bits - 5131 (tdata->digest.len << 3)), 5132 tdata->cipher.offset_bits, 5133 "SNOW 3G Plaintext data not as expected"); 5134 } else { 5135 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5136 ciphertext, 5137 tdata->ciphertext.data, 5138 (tdata->validDataLenInBits.len - 5139 tdata->cipher.offset_bits), 5140 tdata->cipher.offset_bits, 5141 "SNOW 3G Ciphertext data not as expected"); 5142 5143 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5144 ut_params->digest, 5145 tdata->digest.data, 5146 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5147 "SNOW 3G Generated auth tag not as expected"); 5148 } 5149 return 0; 5150 } 5151 5152 static int 5153 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata, 5154 uint8_t op_mode, uint8_t verify) 5155 { 5156 struct crypto_testsuite_params *ts_params = &testsuite_params; 5157 struct crypto_unittest_params *ut_params = &unittest_params; 5158 5159 int retval; 5160 5161 const uint8_t *plaintext = NULL; 5162 const uint8_t *ciphertext = NULL; 5163 const uint8_t *digest = NULL; 5164 unsigned int plaintext_pad_len; 5165 unsigned int plaintext_len; 5166 unsigned int ciphertext_pad_len; 5167 unsigned int ciphertext_len; 5168 uint8_t buffer[10000]; 5169 uint8_t digest_buffer[10000]; 5170 5171 struct rte_cryptodev_info dev_info; 5172 5173 /* Verify the capabilities */ 5174 struct rte_cryptodev_sym_capability_idx cap_idx; 5175 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5176 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5177 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5178 &cap_idx) == NULL) 5179 return TEST_SKIPPED; 5180 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5181 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5182 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5183 &cap_idx) == NULL) 5184 return TEST_SKIPPED; 5185 5186 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5187 return TEST_SKIPPED; 5188 5189 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5190 5191 uint64_t feat_flags = dev_info.feature_flags; 5192 5193 if (op_mode == IN_PLACE) { 5194 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5195 printf("Device doesn't support in-place scatter-gather " 5196 "in both input and output mbufs.\n"); 5197 return TEST_SKIPPED; 5198 } 5199 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5200 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5201 printf("Device doesn't support RAW data-path APIs.\n"); 5202 return TEST_SKIPPED; 5203 } 5204 } else { 5205 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5206 return TEST_SKIPPED; 5207 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5208 printf("Device doesn't support out-of-place scatter-gather " 5209 "in both input and output mbufs.\n"); 5210 return TEST_SKIPPED; 5211 } 5212 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5213 printf("Device doesn't support digest encrypted.\n"); 5214 return TEST_SKIPPED; 5215 } 5216 } 5217 5218 /* Create SNOW 3G session */ 5219 retval = create_wireless_algo_auth_cipher_session( 5220 ts_params->valid_devs[0], 5221 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5222 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5223 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5224 : RTE_CRYPTO_AUTH_OP_GENERATE), 5225 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5226 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5227 tdata->key.data, tdata->key.len, 5228 tdata->auth_iv.len, tdata->digest.len, 5229 tdata->cipher_iv.len); 5230 5231 if (retval != 0) 5232 return retval; 5233 5234 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5235 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5236 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5237 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5238 5239 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5240 plaintext_pad_len, 15, 0); 5241 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5242 "Failed to allocate input buffer in mempool"); 5243 5244 if (op_mode == OUT_OF_PLACE) { 5245 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5246 plaintext_pad_len, 15, 0); 5247 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5248 "Failed to allocate output buffer in mempool"); 5249 } 5250 5251 if (verify) { 5252 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5253 tdata->ciphertext.data); 5254 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5255 ciphertext_len, buffer); 5256 debug_hexdump(stdout, "ciphertext:", ciphertext, 5257 ciphertext_len); 5258 } else { 5259 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5260 tdata->plaintext.data); 5261 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5262 plaintext_len, buffer); 5263 debug_hexdump(stdout, "plaintext:", plaintext, 5264 plaintext_len); 5265 } 5266 memset(buffer, 0, sizeof(buffer)); 5267 5268 /* Create SNOW 3G operation */ 5269 retval = create_wireless_algo_auth_cipher_operation( 5270 tdata->digest.data, tdata->digest.len, 5271 tdata->cipher_iv.data, tdata->cipher_iv.len, 5272 tdata->auth_iv.data, tdata->auth_iv.len, 5273 (tdata->digest.offset_bytes == 0 ? 5274 (verify ? ciphertext_pad_len : plaintext_pad_len) 5275 : tdata->digest.offset_bytes), 5276 tdata->validCipherLenInBits.len, 5277 tdata->cipher.offset_bits, 5278 tdata->validAuthLenInBits.len, 5279 tdata->auth.offset_bits, 5280 op_mode, 1, verify); 5281 5282 if (retval < 0) 5283 return retval; 5284 5285 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5286 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5287 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5288 else 5289 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5290 ut_params->op); 5291 5292 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5293 5294 ut_params->obuf = (op_mode == IN_PLACE ? 5295 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5296 5297 if (verify) { 5298 if (ut_params->obuf) 5299 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5300 plaintext_len, buffer); 5301 else 5302 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5303 plaintext_len, buffer); 5304 5305 debug_hexdump(stdout, "plaintext:", plaintext, 5306 (tdata->plaintext.len >> 3) - tdata->digest.len); 5307 debug_hexdump(stdout, "plaintext expected:", 5308 tdata->plaintext.data, 5309 (tdata->plaintext.len >> 3) - tdata->digest.len); 5310 } else { 5311 if (ut_params->obuf) 5312 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5313 ciphertext_len, buffer); 5314 else 5315 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5316 ciphertext_len, buffer); 5317 5318 debug_hexdump(stdout, "ciphertext:", ciphertext, 5319 ciphertext_len); 5320 debug_hexdump(stdout, "ciphertext expected:", 5321 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5322 5323 if (ut_params->obuf) 5324 digest = rte_pktmbuf_read(ut_params->obuf, 5325 (tdata->digest.offset_bytes == 0 ? 5326 plaintext_pad_len : tdata->digest.offset_bytes), 5327 tdata->digest.len, digest_buffer); 5328 else 5329 digest = rte_pktmbuf_read(ut_params->ibuf, 5330 (tdata->digest.offset_bytes == 0 ? 5331 plaintext_pad_len : tdata->digest.offset_bytes), 5332 tdata->digest.len, digest_buffer); 5333 5334 debug_hexdump(stdout, "digest:", digest, 5335 tdata->digest.len); 5336 debug_hexdump(stdout, "digest expected:", 5337 tdata->digest.data, tdata->digest.len); 5338 } 5339 5340 /* Validate obuf */ 5341 if (verify) { 5342 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5343 plaintext, 5344 tdata->plaintext.data, 5345 (tdata->plaintext.len - tdata->cipher.offset_bits - 5346 (tdata->digest.len << 3)), 5347 tdata->cipher.offset_bits, 5348 "SNOW 3G Plaintext data not as expected"); 5349 } else { 5350 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5351 ciphertext, 5352 tdata->ciphertext.data, 5353 (tdata->validDataLenInBits.len - 5354 tdata->cipher.offset_bits), 5355 tdata->cipher.offset_bits, 5356 "SNOW 3G Ciphertext data not as expected"); 5357 5358 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5359 digest, 5360 tdata->digest.data, 5361 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5362 "SNOW 3G Generated auth tag not as expected"); 5363 } 5364 return 0; 5365 } 5366 5367 static int 5368 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata, 5369 uint8_t op_mode, uint8_t verify) 5370 { 5371 struct crypto_testsuite_params *ts_params = &testsuite_params; 5372 struct crypto_unittest_params *ut_params = &unittest_params; 5373 5374 int retval; 5375 5376 uint8_t *plaintext = NULL, *ciphertext = NULL; 5377 unsigned int plaintext_pad_len; 5378 unsigned int plaintext_len; 5379 unsigned int ciphertext_pad_len; 5380 unsigned int ciphertext_len; 5381 5382 struct rte_cryptodev_info dev_info; 5383 5384 /* Verify the capabilities */ 5385 struct rte_cryptodev_sym_capability_idx cap_idx; 5386 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5387 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5388 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5389 &cap_idx) == NULL) 5390 return TEST_SKIPPED; 5391 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5392 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5393 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5394 &cap_idx) == NULL) 5395 return TEST_SKIPPED; 5396 5397 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5398 5399 uint64_t feat_flags = dev_info.feature_flags; 5400 5401 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5402 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5403 printf("Device doesn't support RAW data-path APIs.\n"); 5404 return TEST_SKIPPED; 5405 } 5406 5407 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5408 return TEST_SKIPPED; 5409 5410 if (op_mode == OUT_OF_PLACE) { 5411 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5412 return TEST_SKIPPED; 5413 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5414 printf("Device doesn't support digest encrypted.\n"); 5415 return TEST_SKIPPED; 5416 } 5417 } 5418 5419 /* Create KASUMI session */ 5420 retval = create_wireless_algo_auth_cipher_session( 5421 ts_params->valid_devs[0], 5422 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5423 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5424 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5425 : RTE_CRYPTO_AUTH_OP_GENERATE), 5426 RTE_CRYPTO_AUTH_KASUMI_F9, 5427 RTE_CRYPTO_CIPHER_KASUMI_F8, 5428 tdata->key.data, tdata->key.len, 5429 0, tdata->digest.len, 5430 tdata->cipher_iv.len); 5431 5432 if (retval != 0) 5433 return retval; 5434 5435 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5436 if (op_mode == OUT_OF_PLACE) 5437 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5438 5439 /* clear mbuf payload */ 5440 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5441 rte_pktmbuf_tailroom(ut_params->ibuf)); 5442 if (op_mode == OUT_OF_PLACE) 5443 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5444 rte_pktmbuf_tailroom(ut_params->obuf)); 5445 5446 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5447 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5448 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5449 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5450 5451 if (verify) { 5452 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5453 ciphertext_pad_len); 5454 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5455 if (op_mode == OUT_OF_PLACE) 5456 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5457 debug_hexdump(stdout, "ciphertext:", ciphertext, 5458 ciphertext_len); 5459 } else { 5460 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5461 plaintext_pad_len); 5462 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5463 if (op_mode == OUT_OF_PLACE) 5464 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5465 debug_hexdump(stdout, "plaintext:", plaintext, 5466 plaintext_len); 5467 } 5468 5469 /* Create KASUMI operation */ 5470 retval = create_wireless_algo_auth_cipher_operation( 5471 tdata->digest.data, tdata->digest.len, 5472 tdata->cipher_iv.data, tdata->cipher_iv.len, 5473 NULL, 0, 5474 (tdata->digest.offset_bytes == 0 ? 5475 (verify ? ciphertext_pad_len : plaintext_pad_len) 5476 : tdata->digest.offset_bytes), 5477 tdata->validCipherLenInBits.len, 5478 tdata->validCipherOffsetInBits.len, 5479 tdata->validAuthLenInBits.len, 5480 0, 5481 op_mode, 0, verify); 5482 5483 if (retval < 0) 5484 return retval; 5485 5486 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5487 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5488 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5489 else 5490 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5491 ut_params->op); 5492 5493 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5494 5495 ut_params->obuf = (op_mode == IN_PLACE ? 5496 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5497 5498 5499 if (verify) { 5500 if (ut_params->obuf) 5501 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5502 uint8_t *); 5503 else 5504 plaintext = ciphertext; 5505 5506 debug_hexdump(stdout, "plaintext:", plaintext, 5507 (tdata->plaintext.len >> 3) - tdata->digest.len); 5508 debug_hexdump(stdout, "plaintext expected:", 5509 tdata->plaintext.data, 5510 (tdata->plaintext.len >> 3) - tdata->digest.len); 5511 } else { 5512 if (ut_params->obuf) 5513 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5514 uint8_t *); 5515 else 5516 ciphertext = plaintext; 5517 5518 debug_hexdump(stdout, "ciphertext:", ciphertext, 5519 ciphertext_len); 5520 debug_hexdump(stdout, "ciphertext expected:", 5521 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5522 5523 ut_params->digest = rte_pktmbuf_mtod( 5524 ut_params->obuf, uint8_t *) + 5525 (tdata->digest.offset_bytes == 0 ? 5526 plaintext_pad_len : tdata->digest.offset_bytes); 5527 5528 debug_hexdump(stdout, "digest:", ut_params->digest, 5529 tdata->digest.len); 5530 debug_hexdump(stdout, "digest expected:", 5531 tdata->digest.data, tdata->digest.len); 5532 } 5533 5534 /* Validate obuf */ 5535 if (verify) { 5536 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5537 plaintext, 5538 tdata->plaintext.data, 5539 tdata->plaintext.len >> 3, 5540 "KASUMI Plaintext data not as expected"); 5541 } else { 5542 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5543 ciphertext, 5544 tdata->ciphertext.data, 5545 tdata->ciphertext.len >> 3, 5546 "KASUMI Ciphertext data not as expected"); 5547 5548 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5549 ut_params->digest, 5550 tdata->digest.data, 5551 DIGEST_BYTE_LENGTH_KASUMI_F9, 5552 "KASUMI Generated auth tag not as expected"); 5553 } 5554 return 0; 5555 } 5556 5557 static int 5558 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata, 5559 uint8_t op_mode, uint8_t verify) 5560 { 5561 struct crypto_testsuite_params *ts_params = &testsuite_params; 5562 struct crypto_unittest_params *ut_params = &unittest_params; 5563 5564 int retval; 5565 5566 const uint8_t *plaintext = NULL; 5567 const uint8_t *ciphertext = NULL; 5568 const uint8_t *digest = NULL; 5569 unsigned int plaintext_pad_len; 5570 unsigned int plaintext_len; 5571 unsigned int ciphertext_pad_len; 5572 unsigned int ciphertext_len; 5573 uint8_t buffer[10000]; 5574 uint8_t digest_buffer[10000]; 5575 5576 struct rte_cryptodev_info dev_info; 5577 5578 /* Verify the capabilities */ 5579 struct rte_cryptodev_sym_capability_idx cap_idx; 5580 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5581 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5582 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5583 &cap_idx) == NULL) 5584 return TEST_SKIPPED; 5585 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5586 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5587 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5588 &cap_idx) == NULL) 5589 return TEST_SKIPPED; 5590 5591 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5592 return TEST_SKIPPED; 5593 5594 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5595 5596 uint64_t feat_flags = dev_info.feature_flags; 5597 5598 if (op_mode == IN_PLACE) { 5599 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5600 printf("Device doesn't support in-place scatter-gather " 5601 "in both input and output mbufs.\n"); 5602 return TEST_SKIPPED; 5603 } 5604 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5605 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5606 printf("Device doesn't support RAW data-path APIs.\n"); 5607 return TEST_SKIPPED; 5608 } 5609 } else { 5610 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5611 return TEST_SKIPPED; 5612 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5613 printf("Device doesn't support out-of-place scatter-gather " 5614 "in both input and output mbufs.\n"); 5615 return TEST_SKIPPED; 5616 } 5617 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5618 printf("Device doesn't support digest encrypted.\n"); 5619 return TEST_SKIPPED; 5620 } 5621 } 5622 5623 /* Create KASUMI session */ 5624 retval = create_wireless_algo_auth_cipher_session( 5625 ts_params->valid_devs[0], 5626 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5627 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5628 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5629 : RTE_CRYPTO_AUTH_OP_GENERATE), 5630 RTE_CRYPTO_AUTH_KASUMI_F9, 5631 RTE_CRYPTO_CIPHER_KASUMI_F8, 5632 tdata->key.data, tdata->key.len, 5633 0, tdata->digest.len, 5634 tdata->cipher_iv.len); 5635 5636 if (retval != 0) 5637 return retval; 5638 5639 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5640 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5641 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5642 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5643 5644 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5645 plaintext_pad_len, 15, 0); 5646 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5647 "Failed to allocate input buffer in mempool"); 5648 5649 if (op_mode == OUT_OF_PLACE) { 5650 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5651 plaintext_pad_len, 15, 0); 5652 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5653 "Failed to allocate output buffer in mempool"); 5654 } 5655 5656 if (verify) { 5657 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5658 tdata->ciphertext.data); 5659 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5660 ciphertext_len, buffer); 5661 debug_hexdump(stdout, "ciphertext:", ciphertext, 5662 ciphertext_len); 5663 } else { 5664 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5665 tdata->plaintext.data); 5666 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5667 plaintext_len, buffer); 5668 debug_hexdump(stdout, "plaintext:", plaintext, 5669 plaintext_len); 5670 } 5671 memset(buffer, 0, sizeof(buffer)); 5672 5673 /* Create KASUMI operation */ 5674 retval = create_wireless_algo_auth_cipher_operation( 5675 tdata->digest.data, tdata->digest.len, 5676 tdata->cipher_iv.data, tdata->cipher_iv.len, 5677 NULL, 0, 5678 (tdata->digest.offset_bytes == 0 ? 5679 (verify ? ciphertext_pad_len : plaintext_pad_len) 5680 : tdata->digest.offset_bytes), 5681 tdata->validCipherLenInBits.len, 5682 tdata->validCipherOffsetInBits.len, 5683 tdata->validAuthLenInBits.len, 5684 0, 5685 op_mode, 1, verify); 5686 5687 if (retval < 0) 5688 return retval; 5689 5690 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5691 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5692 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5693 else 5694 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5695 ut_params->op); 5696 5697 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5698 5699 ut_params->obuf = (op_mode == IN_PLACE ? 5700 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5701 5702 if (verify) { 5703 if (ut_params->obuf) 5704 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5705 plaintext_len, buffer); 5706 else 5707 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5708 plaintext_len, buffer); 5709 5710 debug_hexdump(stdout, "plaintext:", plaintext, 5711 (tdata->plaintext.len >> 3) - tdata->digest.len); 5712 debug_hexdump(stdout, "plaintext expected:", 5713 tdata->plaintext.data, 5714 (tdata->plaintext.len >> 3) - tdata->digest.len); 5715 } else { 5716 if (ut_params->obuf) 5717 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5718 ciphertext_len, buffer); 5719 else 5720 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5721 ciphertext_len, buffer); 5722 5723 debug_hexdump(stdout, "ciphertext:", ciphertext, 5724 ciphertext_len); 5725 debug_hexdump(stdout, "ciphertext expected:", 5726 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5727 5728 if (ut_params->obuf) 5729 digest = rte_pktmbuf_read(ut_params->obuf, 5730 (tdata->digest.offset_bytes == 0 ? 5731 plaintext_pad_len : tdata->digest.offset_bytes), 5732 tdata->digest.len, digest_buffer); 5733 else 5734 digest = rte_pktmbuf_read(ut_params->ibuf, 5735 (tdata->digest.offset_bytes == 0 ? 5736 plaintext_pad_len : tdata->digest.offset_bytes), 5737 tdata->digest.len, digest_buffer); 5738 5739 debug_hexdump(stdout, "digest:", digest, 5740 tdata->digest.len); 5741 debug_hexdump(stdout, "digest expected:", 5742 tdata->digest.data, tdata->digest.len); 5743 } 5744 5745 /* Validate obuf */ 5746 if (verify) { 5747 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5748 plaintext, 5749 tdata->plaintext.data, 5750 tdata->plaintext.len >> 3, 5751 "KASUMI Plaintext data not as expected"); 5752 } else { 5753 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5754 ciphertext, 5755 tdata->ciphertext.data, 5756 tdata->validDataLenInBits.len, 5757 "KASUMI Ciphertext data not as expected"); 5758 5759 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5760 digest, 5761 tdata->digest.data, 5762 DIGEST_BYTE_LENGTH_KASUMI_F9, 5763 "KASUMI Generated auth tag not as expected"); 5764 } 5765 return 0; 5766 } 5767 5768 static int 5769 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata) 5770 { 5771 struct crypto_testsuite_params *ts_params = &testsuite_params; 5772 struct crypto_unittest_params *ut_params = &unittest_params; 5773 5774 int retval; 5775 5776 uint8_t *plaintext, *ciphertext; 5777 unsigned plaintext_pad_len; 5778 unsigned plaintext_len; 5779 struct rte_cryptodev_info dev_info; 5780 5781 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5782 uint64_t feat_flags = dev_info.feature_flags; 5783 5784 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5785 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5786 printf("Device doesn't support RAW data-path APIs.\n"); 5787 return TEST_SKIPPED; 5788 } 5789 5790 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5791 return TEST_SKIPPED; 5792 5793 /* Verify the capabilities */ 5794 struct rte_cryptodev_sym_capability_idx cap_idx; 5795 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5796 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5797 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5798 &cap_idx) == NULL) 5799 return TEST_SKIPPED; 5800 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5801 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5802 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5803 &cap_idx) == NULL) 5804 return TEST_SKIPPED; 5805 5806 /* Create KASUMI session */ 5807 retval = create_wireless_algo_cipher_auth_session( 5808 ts_params->valid_devs[0], 5809 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5810 RTE_CRYPTO_AUTH_OP_GENERATE, 5811 RTE_CRYPTO_AUTH_KASUMI_F9, 5812 RTE_CRYPTO_CIPHER_KASUMI_F8, 5813 tdata->key.data, tdata->key.len, 5814 0, tdata->digest.len, 5815 tdata->cipher_iv.len); 5816 if (retval != 0) 5817 return retval; 5818 5819 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5820 5821 /* clear mbuf payload */ 5822 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5823 rte_pktmbuf_tailroom(ut_params->ibuf)); 5824 5825 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5826 /* Append data which is padded to a multiple of */ 5827 /* the algorithms block size */ 5828 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5829 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5830 plaintext_pad_len); 5831 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5832 5833 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5834 5835 /* Create KASUMI operation */ 5836 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 5837 tdata->digest.len, NULL, 0, 5838 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5839 tdata->cipher_iv.data, tdata->cipher_iv.len, 5840 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 5841 tdata->validCipherOffsetInBits.len, 5842 tdata->validAuthLenInBits.len, 5843 0 5844 ); 5845 if (retval < 0) 5846 return retval; 5847 5848 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5849 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5850 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5851 else 5852 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5853 ut_params->op); 5854 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5855 5856 if (ut_params->op->sym->m_dst) 5857 ut_params->obuf = ut_params->op->sym->m_dst; 5858 else 5859 ut_params->obuf = ut_params->op->sym->m_src; 5860 5861 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 5862 tdata->validCipherOffsetInBits.len >> 3); 5863 5864 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5865 + plaintext_pad_len; 5866 5867 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 5868 (tdata->validCipherOffsetInBits.len >> 3); 5869 /* Validate obuf */ 5870 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5871 ciphertext, 5872 reference_ciphertext, 5873 tdata->validCipherLenInBits.len, 5874 "KASUMI Ciphertext data not as expected"); 5875 5876 /* Validate obuf */ 5877 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5878 ut_params->digest, 5879 tdata->digest.data, 5880 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5881 "KASUMI Generated auth tag not as expected"); 5882 return 0; 5883 } 5884 5885 static int 5886 check_cipher_capability(const struct crypto_testsuite_params *ts_params, 5887 const enum rte_crypto_cipher_algorithm cipher_algo, 5888 const uint16_t key_size, const uint16_t iv_size) 5889 { 5890 struct rte_cryptodev_sym_capability_idx cap_idx; 5891 const struct rte_cryptodev_symmetric_capability *cap; 5892 5893 /* Check if device supports the algorithm */ 5894 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5895 cap_idx.algo.cipher = cipher_algo; 5896 5897 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5898 &cap_idx); 5899 5900 if (cap == NULL) 5901 return -1; 5902 5903 /* Check if device supports key size and IV size */ 5904 if (rte_cryptodev_sym_capability_check_cipher(cap, key_size, 5905 iv_size) < 0) { 5906 return -1; 5907 } 5908 5909 return 0; 5910 } 5911 5912 static int 5913 check_auth_capability(const struct crypto_testsuite_params *ts_params, 5914 const enum rte_crypto_auth_algorithm auth_algo, 5915 const uint16_t key_size, const uint16_t iv_size, 5916 const uint16_t tag_size) 5917 { 5918 struct rte_cryptodev_sym_capability_idx cap_idx; 5919 const struct rte_cryptodev_symmetric_capability *cap; 5920 5921 /* Check if device supports the algorithm */ 5922 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5923 cap_idx.algo.auth = auth_algo; 5924 5925 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5926 &cap_idx); 5927 5928 if (cap == NULL) 5929 return -1; 5930 5931 /* Check if device supports key size and IV size */ 5932 if (rte_cryptodev_sym_capability_check_auth(cap, key_size, 5933 tag_size, iv_size) < 0) { 5934 return -1; 5935 } 5936 5937 return 0; 5938 } 5939 5940 static int 5941 test_zuc_encryption(const struct wireless_test_data *tdata) 5942 { 5943 struct crypto_testsuite_params *ts_params = &testsuite_params; 5944 struct crypto_unittest_params *ut_params = &unittest_params; 5945 5946 int retval; 5947 uint8_t *plaintext, *ciphertext; 5948 unsigned plaintext_pad_len; 5949 unsigned plaintext_len; 5950 struct rte_cryptodev_info dev_info; 5951 5952 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5953 uint64_t feat_flags = dev_info.feature_flags; 5954 5955 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5956 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5957 printf("Device doesn't support RAW data-path APIs.\n"); 5958 return TEST_SKIPPED; 5959 } 5960 5961 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5962 return TEST_SKIPPED; 5963 5964 /* Check if device supports ZUC EEA3 */ 5965 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 5966 tdata->key.len, tdata->cipher_iv.len) < 0) 5967 return TEST_SKIPPED; 5968 5969 /* Create ZUC session */ 5970 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 5971 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5972 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5973 tdata->key.data, tdata->key.len, 5974 tdata->cipher_iv.len); 5975 if (retval != 0) 5976 return retval; 5977 5978 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5979 5980 /* Clear mbuf payload */ 5981 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5982 rte_pktmbuf_tailroom(ut_params->ibuf)); 5983 5984 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5985 /* Append data which is padded to a multiple */ 5986 /* of the algorithms block size */ 5987 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 5988 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5989 plaintext_pad_len); 5990 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5991 5992 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5993 5994 /* Create ZUC operation */ 5995 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 5996 tdata->cipher_iv.len, 5997 tdata->plaintext.len, 5998 0); 5999 if (retval < 0) 6000 return retval; 6001 6002 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6003 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6004 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 6005 else 6006 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6007 ut_params->op); 6008 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6009 6010 ut_params->obuf = ut_params->op->sym->m_dst; 6011 if (ut_params->obuf) 6012 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 6013 else 6014 ciphertext = plaintext; 6015 6016 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6017 6018 /* Validate obuf */ 6019 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6020 ciphertext, 6021 tdata->ciphertext.data, 6022 tdata->validCipherLenInBits.len, 6023 "ZUC Ciphertext data not as expected"); 6024 return 0; 6025 } 6026 6027 static int 6028 test_zuc_encryption_sgl(const struct wireless_test_data *tdata) 6029 { 6030 struct crypto_testsuite_params *ts_params = &testsuite_params; 6031 struct crypto_unittest_params *ut_params = &unittest_params; 6032 6033 int retval; 6034 6035 unsigned int plaintext_pad_len; 6036 unsigned int plaintext_len; 6037 const uint8_t *ciphertext; 6038 uint8_t ciphertext_buffer[2048]; 6039 struct rte_cryptodev_info dev_info; 6040 6041 /* Check if device supports ZUC EEA3 */ 6042 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6043 tdata->key.len, tdata->cipher_iv.len) < 0) 6044 return TEST_SKIPPED; 6045 6046 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6047 return TEST_SKIPPED; 6048 6049 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6050 6051 uint64_t feat_flags = dev_info.feature_flags; 6052 6053 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6054 printf("Device doesn't support in-place scatter-gather. " 6055 "Test Skipped.\n"); 6056 return TEST_SKIPPED; 6057 } 6058 6059 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6060 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6061 printf("Device doesn't support RAW data-path APIs.\n"); 6062 return TEST_SKIPPED; 6063 } 6064 6065 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6066 6067 /* Append data which is padded to a multiple */ 6068 /* of the algorithms block size */ 6069 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6070 6071 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6072 plaintext_pad_len, 10, 0); 6073 6074 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6075 tdata->plaintext.data); 6076 6077 /* Create ZUC session */ 6078 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 6079 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6080 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6081 tdata->key.data, tdata->key.len, 6082 tdata->cipher_iv.len); 6083 if (retval < 0) 6084 return retval; 6085 6086 /* Clear mbuf payload */ 6087 6088 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 6089 6090 /* Create ZUC operation */ 6091 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6092 tdata->cipher_iv.len, tdata->plaintext.len, 6093 0); 6094 if (retval < 0) 6095 return retval; 6096 6097 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6098 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6099 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 6100 else 6101 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6102 ut_params->op); 6103 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6104 6105 ut_params->obuf = ut_params->op->sym->m_dst; 6106 if (ut_params->obuf) 6107 ciphertext = rte_pktmbuf_read(ut_params->obuf, 6108 0, plaintext_len, ciphertext_buffer); 6109 else 6110 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 6111 0, plaintext_len, ciphertext_buffer); 6112 6113 /* Validate obuf */ 6114 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6115 6116 /* Validate obuf */ 6117 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6118 ciphertext, 6119 tdata->ciphertext.data, 6120 tdata->validCipherLenInBits.len, 6121 "ZUC Ciphertext data not as expected"); 6122 6123 return 0; 6124 } 6125 6126 static int 6127 test_zuc_authentication(const struct wireless_test_data *tdata) 6128 { 6129 struct crypto_testsuite_params *ts_params = &testsuite_params; 6130 struct crypto_unittest_params *ut_params = &unittest_params; 6131 6132 int retval; 6133 unsigned plaintext_pad_len; 6134 unsigned plaintext_len; 6135 uint8_t *plaintext; 6136 6137 struct rte_cryptodev_info dev_info; 6138 6139 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6140 uint64_t feat_flags = dev_info.feature_flags; 6141 6142 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 6143 (tdata->validAuthLenInBits.len % 8 != 0)) { 6144 printf("Device doesn't support NON-Byte Aligned Data.\n"); 6145 return TEST_SKIPPED; 6146 } 6147 6148 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6149 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6150 printf("Device doesn't support RAW data-path APIs.\n"); 6151 return TEST_SKIPPED; 6152 } 6153 6154 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6155 return TEST_SKIPPED; 6156 6157 /* Check if device supports ZUC EIA3 */ 6158 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6159 tdata->key.len, tdata->auth_iv.len, 6160 tdata->digest.len) < 0) 6161 return TEST_SKIPPED; 6162 6163 /* Create ZUC session */ 6164 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 6165 tdata->key.data, tdata->key.len, 6166 tdata->auth_iv.len, tdata->digest.len, 6167 RTE_CRYPTO_AUTH_OP_GENERATE, 6168 RTE_CRYPTO_AUTH_ZUC_EIA3); 6169 if (retval != 0) 6170 return retval; 6171 6172 /* alloc mbuf and set payload */ 6173 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6174 6175 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6176 rte_pktmbuf_tailroom(ut_params->ibuf)); 6177 6178 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6179 /* Append data which is padded to a multiple of */ 6180 /* the algorithms block size */ 6181 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6182 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6183 plaintext_pad_len); 6184 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6185 6186 /* Create ZUC operation */ 6187 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 6188 tdata->auth_iv.data, tdata->auth_iv.len, 6189 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 6190 tdata->validAuthLenInBits.len, 6191 0); 6192 if (retval < 0) 6193 return retval; 6194 6195 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6196 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6197 ut_params->op, 0, 1, 1, 0); 6198 else 6199 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6200 ut_params->op); 6201 ut_params->obuf = ut_params->op->sym->m_src; 6202 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6203 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 6204 + plaintext_pad_len; 6205 6206 /* Validate obuf */ 6207 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6208 ut_params->digest, 6209 tdata->digest.data, 6210 tdata->digest.len, 6211 "ZUC Generated auth tag not as expected"); 6212 6213 return 0; 6214 } 6215 6216 static int 6217 test_zuc_auth_cipher(const struct wireless_test_data *tdata, 6218 uint8_t op_mode, uint8_t verify) 6219 { 6220 struct crypto_testsuite_params *ts_params = &testsuite_params; 6221 struct crypto_unittest_params *ut_params = &unittest_params; 6222 6223 int retval; 6224 6225 uint8_t *plaintext = NULL, *ciphertext = NULL; 6226 unsigned int plaintext_pad_len; 6227 unsigned int plaintext_len; 6228 unsigned int ciphertext_pad_len; 6229 unsigned int ciphertext_len; 6230 6231 struct rte_cryptodev_info dev_info; 6232 6233 /* Check if device supports ZUC EEA3 */ 6234 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6235 tdata->key.len, tdata->cipher_iv.len) < 0) 6236 return TEST_SKIPPED; 6237 6238 /* Check if device supports ZUC EIA3 */ 6239 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6240 tdata->key.len, tdata->auth_iv.len, 6241 tdata->digest.len) < 0) 6242 return TEST_SKIPPED; 6243 6244 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6245 6246 uint64_t feat_flags = dev_info.feature_flags; 6247 6248 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6249 printf("Device doesn't support digest encrypted.\n"); 6250 return TEST_SKIPPED; 6251 } 6252 if (op_mode == IN_PLACE) { 6253 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6254 printf("Device doesn't support in-place scatter-gather " 6255 "in both input and output mbufs.\n"); 6256 return TEST_SKIPPED; 6257 } 6258 6259 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6260 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6261 printf("Device doesn't support RAW data-path APIs.\n"); 6262 return TEST_SKIPPED; 6263 } 6264 } else { 6265 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6266 return TEST_SKIPPED; 6267 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6268 printf("Device doesn't support out-of-place scatter-gather " 6269 "in both input and output mbufs.\n"); 6270 return TEST_SKIPPED; 6271 } 6272 } 6273 6274 /* Create ZUC session */ 6275 retval = create_wireless_algo_auth_cipher_session( 6276 ts_params->valid_devs[0], 6277 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6278 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6279 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6280 : RTE_CRYPTO_AUTH_OP_GENERATE), 6281 RTE_CRYPTO_AUTH_ZUC_EIA3, 6282 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6283 tdata->key.data, tdata->key.len, 6284 tdata->auth_iv.len, tdata->digest.len, 6285 tdata->cipher_iv.len); 6286 6287 if (retval != 0) 6288 return retval; 6289 6290 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6291 if (op_mode == OUT_OF_PLACE) 6292 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6293 6294 /* clear mbuf payload */ 6295 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6296 rte_pktmbuf_tailroom(ut_params->ibuf)); 6297 if (op_mode == OUT_OF_PLACE) 6298 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 6299 rte_pktmbuf_tailroom(ut_params->obuf)); 6300 6301 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6302 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6303 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6304 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6305 6306 if (verify) { 6307 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6308 ciphertext_pad_len); 6309 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6310 if (op_mode == OUT_OF_PLACE) 6311 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 6312 debug_hexdump(stdout, "ciphertext:", ciphertext, 6313 ciphertext_len); 6314 } else { 6315 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6316 plaintext_pad_len); 6317 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6318 if (op_mode == OUT_OF_PLACE) 6319 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 6320 debug_hexdump(stdout, "plaintext:", plaintext, 6321 plaintext_len); 6322 } 6323 6324 /* Create ZUC operation */ 6325 retval = create_wireless_algo_auth_cipher_operation( 6326 tdata->digest.data, tdata->digest.len, 6327 tdata->cipher_iv.data, tdata->cipher_iv.len, 6328 tdata->auth_iv.data, tdata->auth_iv.len, 6329 (tdata->digest.offset_bytes == 0 ? 6330 (verify ? ciphertext_pad_len : plaintext_pad_len) 6331 : tdata->digest.offset_bytes), 6332 tdata->validCipherLenInBits.len, 6333 tdata->validCipherOffsetInBits.len, 6334 tdata->validAuthLenInBits.len, 6335 0, 6336 op_mode, 0, verify); 6337 6338 if (retval < 0) 6339 return retval; 6340 6341 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6342 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6343 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 6344 else 6345 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6346 ut_params->op); 6347 6348 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6349 6350 ut_params->obuf = (op_mode == IN_PLACE ? 6351 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6352 6353 6354 if (verify) { 6355 if (ut_params->obuf) 6356 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 6357 uint8_t *); 6358 else 6359 plaintext = ciphertext; 6360 6361 debug_hexdump(stdout, "plaintext:", plaintext, 6362 (tdata->plaintext.len >> 3) - tdata->digest.len); 6363 debug_hexdump(stdout, "plaintext expected:", 6364 tdata->plaintext.data, 6365 (tdata->plaintext.len >> 3) - tdata->digest.len); 6366 } else { 6367 if (ut_params->obuf) 6368 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 6369 uint8_t *); 6370 else 6371 ciphertext = plaintext; 6372 6373 debug_hexdump(stdout, "ciphertext:", ciphertext, 6374 ciphertext_len); 6375 debug_hexdump(stdout, "ciphertext expected:", 6376 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6377 6378 ut_params->digest = rte_pktmbuf_mtod( 6379 ut_params->obuf, uint8_t *) + 6380 (tdata->digest.offset_bytes == 0 ? 6381 plaintext_pad_len : tdata->digest.offset_bytes); 6382 6383 debug_hexdump(stdout, "digest:", ut_params->digest, 6384 tdata->digest.len); 6385 debug_hexdump(stdout, "digest expected:", 6386 tdata->digest.data, tdata->digest.len); 6387 } 6388 6389 /* Validate obuf */ 6390 if (verify) { 6391 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6392 plaintext, 6393 tdata->plaintext.data, 6394 tdata->plaintext.len >> 3, 6395 "ZUC Plaintext data not as expected"); 6396 } else { 6397 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6398 ciphertext, 6399 tdata->ciphertext.data, 6400 tdata->ciphertext.len >> 3, 6401 "ZUC Ciphertext data not as expected"); 6402 6403 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6404 ut_params->digest, 6405 tdata->digest.data, 6406 DIGEST_BYTE_LENGTH_KASUMI_F9, 6407 "ZUC Generated auth tag not as expected"); 6408 } 6409 return 0; 6410 } 6411 6412 static int 6413 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata, 6414 uint8_t op_mode, uint8_t verify) 6415 { 6416 struct crypto_testsuite_params *ts_params = &testsuite_params; 6417 struct crypto_unittest_params *ut_params = &unittest_params; 6418 6419 int retval; 6420 6421 const uint8_t *plaintext = NULL; 6422 const uint8_t *ciphertext = NULL; 6423 const uint8_t *digest = NULL; 6424 unsigned int plaintext_pad_len; 6425 unsigned int plaintext_len; 6426 unsigned int ciphertext_pad_len; 6427 unsigned int ciphertext_len; 6428 uint8_t buffer[10000]; 6429 uint8_t digest_buffer[10000]; 6430 6431 struct rte_cryptodev_info dev_info; 6432 6433 /* Check if device supports ZUC EEA3 */ 6434 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6435 tdata->key.len, tdata->cipher_iv.len) < 0) 6436 return TEST_SKIPPED; 6437 6438 /* Check if device supports ZUC EIA3 */ 6439 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6440 tdata->key.len, tdata->auth_iv.len, 6441 tdata->digest.len) < 0) 6442 return TEST_SKIPPED; 6443 6444 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6445 6446 uint64_t feat_flags = dev_info.feature_flags; 6447 6448 if (op_mode == IN_PLACE) { 6449 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6450 printf("Device doesn't support in-place scatter-gather " 6451 "in both input and output mbufs.\n"); 6452 return TEST_SKIPPED; 6453 } 6454 6455 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6456 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6457 printf("Device doesn't support RAW data-path APIs.\n"); 6458 return TEST_SKIPPED; 6459 } 6460 } else { 6461 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6462 return TEST_SKIPPED; 6463 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6464 printf("Device doesn't support out-of-place scatter-gather " 6465 "in both input and output mbufs.\n"); 6466 return TEST_SKIPPED; 6467 } 6468 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6469 printf("Device doesn't support digest encrypted.\n"); 6470 return TEST_SKIPPED; 6471 } 6472 } 6473 6474 /* Create ZUC session */ 6475 retval = create_wireless_algo_auth_cipher_session( 6476 ts_params->valid_devs[0], 6477 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6478 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6479 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6480 : RTE_CRYPTO_AUTH_OP_GENERATE), 6481 RTE_CRYPTO_AUTH_ZUC_EIA3, 6482 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6483 tdata->key.data, tdata->key.len, 6484 tdata->auth_iv.len, tdata->digest.len, 6485 tdata->cipher_iv.len); 6486 6487 if (retval != 0) 6488 return retval; 6489 6490 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6491 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6492 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6493 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6494 6495 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6496 plaintext_pad_len, 15, 0); 6497 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6498 "Failed to allocate input buffer in mempool"); 6499 6500 if (op_mode == OUT_OF_PLACE) { 6501 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 6502 plaintext_pad_len, 15, 0); 6503 TEST_ASSERT_NOT_NULL(ut_params->obuf, 6504 "Failed to allocate output buffer in mempool"); 6505 } 6506 6507 if (verify) { 6508 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6509 tdata->ciphertext.data); 6510 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6511 ciphertext_len, buffer); 6512 debug_hexdump(stdout, "ciphertext:", ciphertext, 6513 ciphertext_len); 6514 } else { 6515 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6516 tdata->plaintext.data); 6517 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6518 plaintext_len, buffer); 6519 debug_hexdump(stdout, "plaintext:", plaintext, 6520 plaintext_len); 6521 } 6522 memset(buffer, 0, sizeof(buffer)); 6523 6524 /* Create ZUC operation */ 6525 retval = create_wireless_algo_auth_cipher_operation( 6526 tdata->digest.data, tdata->digest.len, 6527 tdata->cipher_iv.data, tdata->cipher_iv.len, 6528 NULL, 0, 6529 (tdata->digest.offset_bytes == 0 ? 6530 (verify ? ciphertext_pad_len : plaintext_pad_len) 6531 : tdata->digest.offset_bytes), 6532 tdata->validCipherLenInBits.len, 6533 tdata->validCipherOffsetInBits.len, 6534 tdata->validAuthLenInBits.len, 6535 0, 6536 op_mode, 1, verify); 6537 6538 if (retval < 0) 6539 return retval; 6540 6541 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6542 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6543 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 6544 else 6545 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6546 ut_params->op); 6547 6548 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6549 6550 ut_params->obuf = (op_mode == IN_PLACE ? 6551 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6552 6553 if (verify) { 6554 if (ut_params->obuf) 6555 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 6556 plaintext_len, buffer); 6557 else 6558 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6559 plaintext_len, buffer); 6560 6561 debug_hexdump(stdout, "plaintext:", plaintext, 6562 (tdata->plaintext.len >> 3) - tdata->digest.len); 6563 debug_hexdump(stdout, "plaintext expected:", 6564 tdata->plaintext.data, 6565 (tdata->plaintext.len >> 3) - tdata->digest.len); 6566 } else { 6567 if (ut_params->obuf) 6568 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 6569 ciphertext_len, buffer); 6570 else 6571 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6572 ciphertext_len, buffer); 6573 6574 debug_hexdump(stdout, "ciphertext:", ciphertext, 6575 ciphertext_len); 6576 debug_hexdump(stdout, "ciphertext expected:", 6577 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6578 6579 if (ut_params->obuf) 6580 digest = rte_pktmbuf_read(ut_params->obuf, 6581 (tdata->digest.offset_bytes == 0 ? 6582 plaintext_pad_len : tdata->digest.offset_bytes), 6583 tdata->digest.len, digest_buffer); 6584 else 6585 digest = rte_pktmbuf_read(ut_params->ibuf, 6586 (tdata->digest.offset_bytes == 0 ? 6587 plaintext_pad_len : tdata->digest.offset_bytes), 6588 tdata->digest.len, digest_buffer); 6589 6590 debug_hexdump(stdout, "digest:", digest, 6591 tdata->digest.len); 6592 debug_hexdump(stdout, "digest expected:", 6593 tdata->digest.data, tdata->digest.len); 6594 } 6595 6596 /* Validate obuf */ 6597 if (verify) { 6598 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6599 plaintext, 6600 tdata->plaintext.data, 6601 tdata->plaintext.len >> 3, 6602 "ZUC Plaintext data not as expected"); 6603 } else { 6604 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6605 ciphertext, 6606 tdata->ciphertext.data, 6607 tdata->validDataLenInBits.len, 6608 "ZUC Ciphertext data not as expected"); 6609 6610 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6611 digest, 6612 tdata->digest.data, 6613 DIGEST_BYTE_LENGTH_KASUMI_F9, 6614 "ZUC Generated auth tag not as expected"); 6615 } 6616 return 0; 6617 } 6618 6619 static int 6620 test_kasumi_encryption_test_case_1(void) 6621 { 6622 return test_kasumi_encryption(&kasumi_test_case_1); 6623 } 6624 6625 static int 6626 test_kasumi_encryption_test_case_1_sgl(void) 6627 { 6628 return test_kasumi_encryption_sgl(&kasumi_test_case_1); 6629 } 6630 6631 static int 6632 test_kasumi_encryption_test_case_1_oop(void) 6633 { 6634 return test_kasumi_encryption_oop(&kasumi_test_case_1); 6635 } 6636 6637 static int 6638 test_kasumi_encryption_test_case_1_oop_sgl(void) 6639 { 6640 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1); 6641 } 6642 6643 static int 6644 test_kasumi_encryption_test_case_2(void) 6645 { 6646 return test_kasumi_encryption(&kasumi_test_case_2); 6647 } 6648 6649 static int 6650 test_kasumi_encryption_test_case_3(void) 6651 { 6652 return test_kasumi_encryption(&kasumi_test_case_3); 6653 } 6654 6655 static int 6656 test_kasumi_encryption_test_case_4(void) 6657 { 6658 return test_kasumi_encryption(&kasumi_test_case_4); 6659 } 6660 6661 static int 6662 test_kasumi_encryption_test_case_5(void) 6663 { 6664 return test_kasumi_encryption(&kasumi_test_case_5); 6665 } 6666 6667 static int 6668 test_kasumi_decryption_test_case_1(void) 6669 { 6670 return test_kasumi_decryption(&kasumi_test_case_1); 6671 } 6672 6673 static int 6674 test_kasumi_decryption_test_case_1_oop(void) 6675 { 6676 return test_kasumi_decryption_oop(&kasumi_test_case_1); 6677 } 6678 6679 static int 6680 test_kasumi_decryption_test_case_2(void) 6681 { 6682 return test_kasumi_decryption(&kasumi_test_case_2); 6683 } 6684 6685 static int 6686 test_kasumi_decryption_test_case_3(void) 6687 { 6688 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6689 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6690 return TEST_SKIPPED; 6691 return test_kasumi_decryption(&kasumi_test_case_3); 6692 } 6693 6694 static int 6695 test_kasumi_decryption_test_case_4(void) 6696 { 6697 return test_kasumi_decryption(&kasumi_test_case_4); 6698 } 6699 6700 static int 6701 test_kasumi_decryption_test_case_5(void) 6702 { 6703 return test_kasumi_decryption(&kasumi_test_case_5); 6704 } 6705 static int 6706 test_snow3g_encryption_test_case_1(void) 6707 { 6708 return test_snow3g_encryption(&snow3g_test_case_1); 6709 } 6710 6711 static int 6712 test_snow3g_encryption_test_case_1_oop(void) 6713 { 6714 return test_snow3g_encryption_oop(&snow3g_test_case_1); 6715 } 6716 6717 static int 6718 test_snow3g_encryption_test_case_1_oop_sgl(void) 6719 { 6720 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1); 6721 } 6722 6723 6724 static int 6725 test_snow3g_encryption_test_case_1_offset_oop(void) 6726 { 6727 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); 6728 } 6729 6730 static int 6731 test_snow3g_encryption_test_case_2(void) 6732 { 6733 return test_snow3g_encryption(&snow3g_test_case_2); 6734 } 6735 6736 static int 6737 test_snow3g_encryption_test_case_3(void) 6738 { 6739 return test_snow3g_encryption(&snow3g_test_case_3); 6740 } 6741 6742 static int 6743 test_snow3g_encryption_test_case_4(void) 6744 { 6745 return test_snow3g_encryption(&snow3g_test_case_4); 6746 } 6747 6748 static int 6749 test_snow3g_encryption_test_case_5(void) 6750 { 6751 return test_snow3g_encryption(&snow3g_test_case_5); 6752 } 6753 6754 static int 6755 test_snow3g_decryption_test_case_1(void) 6756 { 6757 return test_snow3g_decryption(&snow3g_test_case_1); 6758 } 6759 6760 static int 6761 test_snow3g_decryption_test_case_1_oop(void) 6762 { 6763 return test_snow3g_decryption_oop(&snow3g_test_case_1); 6764 } 6765 6766 static int 6767 test_snow3g_decryption_test_case_2(void) 6768 { 6769 return test_snow3g_decryption(&snow3g_test_case_2); 6770 } 6771 6772 static int 6773 test_snow3g_decryption_test_case_3(void) 6774 { 6775 return test_snow3g_decryption(&snow3g_test_case_3); 6776 } 6777 6778 static int 6779 test_snow3g_decryption_test_case_4(void) 6780 { 6781 return test_snow3g_decryption(&snow3g_test_case_4); 6782 } 6783 6784 static int 6785 test_snow3g_decryption_test_case_5(void) 6786 { 6787 return test_snow3g_decryption(&snow3g_test_case_5); 6788 } 6789 6790 /* 6791 * Function prepares snow3g_hash_test_data from snow3g_test_data. 6792 * Pattern digest from snow3g_test_data must be allocated as 6793 * 4 last bytes in plaintext. 6794 */ 6795 static void 6796 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern, 6797 struct snow3g_hash_test_data *output) 6798 { 6799 if ((pattern != NULL) && (output != NULL)) { 6800 output->key.len = pattern->key.len; 6801 6802 memcpy(output->key.data, 6803 pattern->key.data, pattern->key.len); 6804 6805 output->auth_iv.len = pattern->auth_iv.len; 6806 6807 memcpy(output->auth_iv.data, 6808 pattern->auth_iv.data, pattern->auth_iv.len); 6809 6810 output->plaintext.len = pattern->plaintext.len; 6811 6812 memcpy(output->plaintext.data, 6813 pattern->plaintext.data, pattern->plaintext.len >> 3); 6814 6815 output->digest.len = pattern->digest.len; 6816 6817 memcpy(output->digest.data, 6818 &pattern->plaintext.data[pattern->digest.offset_bytes], 6819 pattern->digest.len); 6820 6821 output->validAuthLenInBits.len = 6822 pattern->validAuthLenInBits.len; 6823 } 6824 } 6825 6826 /* 6827 * Test case verify computed cipher and digest from snow3g_test_case_7 data. 6828 */ 6829 static int 6830 test_snow3g_decryption_with_digest_test_case_1(void) 6831 { 6832 struct snow3g_hash_test_data snow3g_hash_data; 6833 struct rte_cryptodev_info dev_info; 6834 struct crypto_testsuite_params *ts_params = &testsuite_params; 6835 6836 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6837 uint64_t feat_flags = dev_info.feature_flags; 6838 6839 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6840 printf("Device doesn't support encrypted digest operations.\n"); 6841 return TEST_SKIPPED; 6842 } 6843 6844 /* 6845 * Function prepare data for hash veryfication test case. 6846 * Digest is allocated in 4 last bytes in plaintext, pattern. 6847 */ 6848 snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data); 6849 6850 return test_snow3g_decryption(&snow3g_test_case_7) & 6851 test_snow3g_authentication_verify(&snow3g_hash_data); 6852 } 6853 6854 static int 6855 test_snow3g_cipher_auth_test_case_1(void) 6856 { 6857 return test_snow3g_cipher_auth(&snow3g_test_case_3); 6858 } 6859 6860 static int 6861 test_snow3g_auth_cipher_test_case_1(void) 6862 { 6863 return test_snow3g_auth_cipher( 6864 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0); 6865 } 6866 6867 static int 6868 test_snow3g_auth_cipher_test_case_2(void) 6869 { 6870 return test_snow3g_auth_cipher( 6871 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0); 6872 } 6873 6874 static int 6875 test_snow3g_auth_cipher_test_case_2_oop(void) 6876 { 6877 return test_snow3g_auth_cipher( 6878 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6879 } 6880 6881 static int 6882 test_snow3g_auth_cipher_part_digest_enc(void) 6883 { 6884 return test_snow3g_auth_cipher( 6885 &snow3g_auth_cipher_partial_digest_encryption, 6886 IN_PLACE, 0); 6887 } 6888 6889 static int 6890 test_snow3g_auth_cipher_part_digest_enc_oop(void) 6891 { 6892 return test_snow3g_auth_cipher( 6893 &snow3g_auth_cipher_partial_digest_encryption, 6894 OUT_OF_PLACE, 0); 6895 } 6896 6897 static int 6898 test_snow3g_auth_cipher_test_case_3_sgl(void) 6899 { 6900 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6901 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6902 return TEST_SKIPPED; 6903 return test_snow3g_auth_cipher_sgl( 6904 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0); 6905 } 6906 6907 static int 6908 test_snow3g_auth_cipher_test_case_3_oop_sgl(void) 6909 { 6910 return test_snow3g_auth_cipher_sgl( 6911 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0); 6912 } 6913 6914 static int 6915 test_snow3g_auth_cipher_part_digest_enc_sgl(void) 6916 { 6917 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6918 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6919 return TEST_SKIPPED; 6920 return test_snow3g_auth_cipher_sgl( 6921 &snow3g_auth_cipher_partial_digest_encryption, 6922 IN_PLACE, 0); 6923 } 6924 6925 static int 6926 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void) 6927 { 6928 return test_snow3g_auth_cipher_sgl( 6929 &snow3g_auth_cipher_partial_digest_encryption, 6930 OUT_OF_PLACE, 0); 6931 } 6932 6933 static int 6934 test_snow3g_auth_cipher_verify_test_case_1(void) 6935 { 6936 return test_snow3g_auth_cipher( 6937 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1); 6938 } 6939 6940 static int 6941 test_snow3g_auth_cipher_verify_test_case_2(void) 6942 { 6943 return test_snow3g_auth_cipher( 6944 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1); 6945 } 6946 6947 static int 6948 test_snow3g_auth_cipher_verify_test_case_2_oop(void) 6949 { 6950 return test_snow3g_auth_cipher( 6951 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 6952 } 6953 6954 static int 6955 test_snow3g_auth_cipher_verify_part_digest_enc(void) 6956 { 6957 return test_snow3g_auth_cipher( 6958 &snow3g_auth_cipher_partial_digest_encryption, 6959 IN_PLACE, 1); 6960 } 6961 6962 static int 6963 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void) 6964 { 6965 return test_snow3g_auth_cipher( 6966 &snow3g_auth_cipher_partial_digest_encryption, 6967 OUT_OF_PLACE, 1); 6968 } 6969 6970 static int 6971 test_snow3g_auth_cipher_verify_test_case_3_sgl(void) 6972 { 6973 return test_snow3g_auth_cipher_sgl( 6974 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1); 6975 } 6976 6977 static int 6978 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void) 6979 { 6980 return test_snow3g_auth_cipher_sgl( 6981 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1); 6982 } 6983 6984 static int 6985 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void) 6986 { 6987 return test_snow3g_auth_cipher_sgl( 6988 &snow3g_auth_cipher_partial_digest_encryption, 6989 IN_PLACE, 1); 6990 } 6991 6992 static int 6993 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void) 6994 { 6995 return test_snow3g_auth_cipher_sgl( 6996 &snow3g_auth_cipher_partial_digest_encryption, 6997 OUT_OF_PLACE, 1); 6998 } 6999 7000 static int 7001 test_snow3g_auth_cipher_with_digest_test_case_1(void) 7002 { 7003 return test_snow3g_auth_cipher( 7004 &snow3g_test_case_7, IN_PLACE, 0); 7005 } 7006 7007 static int 7008 test_kasumi_auth_cipher_test_case_1(void) 7009 { 7010 return test_kasumi_auth_cipher( 7011 &kasumi_test_case_3, IN_PLACE, 0); 7012 } 7013 7014 static int 7015 test_kasumi_auth_cipher_test_case_2(void) 7016 { 7017 return test_kasumi_auth_cipher( 7018 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7019 } 7020 7021 static int 7022 test_kasumi_auth_cipher_test_case_2_oop(void) 7023 { 7024 return test_kasumi_auth_cipher( 7025 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7026 } 7027 7028 static int 7029 test_kasumi_auth_cipher_test_case_2_sgl(void) 7030 { 7031 return test_kasumi_auth_cipher_sgl( 7032 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7033 } 7034 7035 static int 7036 test_kasumi_auth_cipher_test_case_2_oop_sgl(void) 7037 { 7038 return test_kasumi_auth_cipher_sgl( 7039 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7040 } 7041 7042 static int 7043 test_kasumi_auth_cipher_verify_test_case_1(void) 7044 { 7045 return test_kasumi_auth_cipher( 7046 &kasumi_test_case_3, IN_PLACE, 1); 7047 } 7048 7049 static int 7050 test_kasumi_auth_cipher_verify_test_case_2(void) 7051 { 7052 return test_kasumi_auth_cipher( 7053 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7054 } 7055 7056 static int 7057 test_kasumi_auth_cipher_verify_test_case_2_oop(void) 7058 { 7059 return test_kasumi_auth_cipher( 7060 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7061 } 7062 7063 static int 7064 test_kasumi_auth_cipher_verify_test_case_2_sgl(void) 7065 { 7066 return test_kasumi_auth_cipher_sgl( 7067 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7068 } 7069 7070 static int 7071 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void) 7072 { 7073 return test_kasumi_auth_cipher_sgl( 7074 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7075 } 7076 7077 static int 7078 test_kasumi_cipher_auth_test_case_1(void) 7079 { 7080 return test_kasumi_cipher_auth(&kasumi_test_case_6); 7081 } 7082 7083 static int 7084 test_zuc_encryption_test_case_1(void) 7085 { 7086 return test_zuc_encryption(&zuc_test_case_cipher_193b); 7087 } 7088 7089 static int 7090 test_zuc_encryption_test_case_2(void) 7091 { 7092 return test_zuc_encryption(&zuc_test_case_cipher_800b); 7093 } 7094 7095 static int 7096 test_zuc_encryption_test_case_3(void) 7097 { 7098 return test_zuc_encryption(&zuc_test_case_cipher_1570b); 7099 } 7100 7101 static int 7102 test_zuc_encryption_test_case_4(void) 7103 { 7104 return test_zuc_encryption(&zuc_test_case_cipher_2798b); 7105 } 7106 7107 static int 7108 test_zuc_encryption_test_case_5(void) 7109 { 7110 return test_zuc_encryption(&zuc_test_case_cipher_4019b); 7111 } 7112 7113 static int 7114 test_zuc_encryption_test_case_6_sgl(void) 7115 { 7116 return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b); 7117 } 7118 7119 static int 7120 test_zuc_encryption_test_case_7(void) 7121 { 7122 return test_zuc_encryption(&zuc_test_case_cipher_800b_key_256b); 7123 } 7124 7125 static int 7126 test_zuc_hash_generate_test_case_1(void) 7127 { 7128 return test_zuc_authentication(&zuc_test_case_auth_1b); 7129 } 7130 7131 static int 7132 test_zuc_hash_generate_test_case_2(void) 7133 { 7134 return test_zuc_authentication(&zuc_test_case_auth_90b); 7135 } 7136 7137 static int 7138 test_zuc_hash_generate_test_case_3(void) 7139 { 7140 return test_zuc_authentication(&zuc_test_case_auth_577b); 7141 } 7142 7143 static int 7144 test_zuc_hash_generate_test_case_4(void) 7145 { 7146 return test_zuc_authentication(&zuc_test_case_auth_2079b); 7147 } 7148 7149 static int 7150 test_zuc_hash_generate_test_case_5(void) 7151 { 7152 return test_zuc_authentication(&zuc_test_auth_5670b); 7153 } 7154 7155 static int 7156 test_zuc_hash_generate_test_case_6(void) 7157 { 7158 return test_zuc_authentication(&zuc_test_case_auth_128b); 7159 } 7160 7161 static int 7162 test_zuc_hash_generate_test_case_7(void) 7163 { 7164 return test_zuc_authentication(&zuc_test_case_auth_2080b); 7165 } 7166 7167 static int 7168 test_zuc_hash_generate_test_case_8(void) 7169 { 7170 return test_zuc_authentication(&zuc_test_case_auth_584b); 7171 } 7172 7173 static int 7174 test_zuc_hash_generate_test_case_9(void) 7175 { 7176 return test_zuc_authentication(&zuc_test_case_auth_584b_mac_64b); 7177 } 7178 7179 static int 7180 test_zuc_hash_generate_test_case_10(void) 7181 { 7182 return test_zuc_authentication(&zuc_test_case_auth_2080b_mac_128b); 7183 } 7184 7185 static int 7186 test_zuc_cipher_auth_test_case_1(void) 7187 { 7188 return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b); 7189 } 7190 7191 static int 7192 test_zuc_cipher_auth_test_case_2(void) 7193 { 7194 return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b); 7195 } 7196 7197 static int 7198 test_zuc_auth_cipher_test_case_1(void) 7199 { 7200 return test_zuc_auth_cipher( 7201 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7202 } 7203 7204 static int 7205 test_zuc_auth_cipher_test_case_1_oop(void) 7206 { 7207 return test_zuc_auth_cipher( 7208 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7209 } 7210 7211 static int 7212 test_zuc_auth_cipher_test_case_1_sgl(void) 7213 { 7214 return test_zuc_auth_cipher_sgl( 7215 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7216 } 7217 7218 static int 7219 test_zuc_auth_cipher_test_case_1_oop_sgl(void) 7220 { 7221 return test_zuc_auth_cipher_sgl( 7222 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7223 } 7224 7225 static int 7226 test_zuc_auth_cipher_verify_test_case_1(void) 7227 { 7228 return test_zuc_auth_cipher( 7229 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7230 } 7231 7232 static int 7233 test_zuc_auth_cipher_verify_test_case_1_oop(void) 7234 { 7235 return test_zuc_auth_cipher( 7236 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7237 } 7238 7239 static int 7240 test_zuc_auth_cipher_verify_test_case_1_sgl(void) 7241 { 7242 return test_zuc_auth_cipher_sgl( 7243 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7244 } 7245 7246 static int 7247 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void) 7248 { 7249 return test_zuc_auth_cipher_sgl( 7250 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7251 } 7252 7253 static int 7254 test_zuc256_encryption_test_case_1(void) 7255 { 7256 return test_zuc_encryption(&zuc256_test_case_cipher_1); 7257 } 7258 7259 static int 7260 test_zuc256_encryption_test_case_2(void) 7261 { 7262 return test_zuc_encryption(&zuc256_test_case_cipher_2); 7263 } 7264 7265 static int 7266 test_zuc256_authentication_test_case_1(void) 7267 { 7268 return test_zuc_authentication(&zuc256_test_case_auth_1); 7269 } 7270 7271 static int 7272 test_zuc256_authentication_test_case_2(void) 7273 { 7274 return test_zuc_authentication(&zuc256_test_case_auth_2); 7275 } 7276 7277 static int 7278 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata) 7279 { 7280 uint8_t dev_id = testsuite_params.valid_devs[0]; 7281 7282 struct rte_cryptodev_sym_capability_idx cap_idx; 7283 7284 /* Check if device supports particular cipher algorithm */ 7285 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 7286 cap_idx.algo.cipher = tdata->cipher_algo; 7287 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 7288 return TEST_SKIPPED; 7289 7290 /* Check if device supports particular hash algorithm */ 7291 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 7292 cap_idx.algo.auth = tdata->auth_algo; 7293 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 7294 return TEST_SKIPPED; 7295 7296 return 0; 7297 } 7298 7299 static int 7300 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata, 7301 uint8_t op_mode, uint8_t verify) 7302 { 7303 struct crypto_testsuite_params *ts_params = &testsuite_params; 7304 struct crypto_unittest_params *ut_params = &unittest_params; 7305 7306 int retval; 7307 7308 uint8_t *plaintext = NULL, *ciphertext = NULL; 7309 unsigned int plaintext_pad_len; 7310 unsigned int plaintext_len; 7311 unsigned int ciphertext_pad_len; 7312 unsigned int ciphertext_len; 7313 7314 struct rte_cryptodev_info dev_info; 7315 struct rte_crypto_op *op; 7316 7317 /* Check if device supports particular algorithms separately */ 7318 if (test_mixed_check_if_unsupported(tdata)) 7319 return TEST_SKIPPED; 7320 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7321 return TEST_SKIPPED; 7322 7323 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7324 7325 uint64_t feat_flags = dev_info.feature_flags; 7326 7327 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7328 printf("Device doesn't support digest encrypted.\n"); 7329 return TEST_SKIPPED; 7330 } 7331 7332 /* Create the session */ 7333 if (verify) 7334 retval = create_wireless_algo_cipher_auth_session( 7335 ts_params->valid_devs[0], 7336 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7337 RTE_CRYPTO_AUTH_OP_VERIFY, 7338 tdata->auth_algo, 7339 tdata->cipher_algo, 7340 tdata->auth_key.data, tdata->auth_key.len, 7341 tdata->auth_iv.len, tdata->digest_enc.len, 7342 tdata->cipher_iv.len); 7343 else 7344 retval = create_wireless_algo_auth_cipher_session( 7345 ts_params->valid_devs[0], 7346 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7347 RTE_CRYPTO_AUTH_OP_GENERATE, 7348 tdata->auth_algo, 7349 tdata->cipher_algo, 7350 tdata->auth_key.data, tdata->auth_key.len, 7351 tdata->auth_iv.len, tdata->digest_enc.len, 7352 tdata->cipher_iv.len); 7353 if (retval != 0) 7354 return retval; 7355 7356 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7357 if (op_mode == OUT_OF_PLACE) 7358 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7359 7360 /* clear mbuf payload */ 7361 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7362 rte_pktmbuf_tailroom(ut_params->ibuf)); 7363 if (op_mode == OUT_OF_PLACE) { 7364 7365 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 7366 rte_pktmbuf_tailroom(ut_params->obuf)); 7367 } 7368 7369 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 7370 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 7371 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 7372 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 7373 7374 if (verify) { 7375 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7376 ciphertext_pad_len); 7377 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 7378 if (op_mode == OUT_OF_PLACE) 7379 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 7380 debug_hexdump(stdout, "ciphertext:", ciphertext, 7381 ciphertext_len); 7382 } else { 7383 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7384 plaintext_pad_len); 7385 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 7386 if (op_mode == OUT_OF_PLACE) 7387 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 7388 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 7389 } 7390 7391 /* Create the operation */ 7392 retval = create_wireless_algo_auth_cipher_operation( 7393 tdata->digest_enc.data, tdata->digest_enc.len, 7394 tdata->cipher_iv.data, tdata->cipher_iv.len, 7395 tdata->auth_iv.data, tdata->auth_iv.len, 7396 (tdata->digest_enc.offset == 0 ? 7397 plaintext_pad_len 7398 : tdata->digest_enc.offset), 7399 tdata->validCipherLen.len_bits, 7400 tdata->cipher.offset_bits, 7401 tdata->validAuthLen.len_bits, 7402 tdata->auth.offset_bits, 7403 op_mode, 0, verify); 7404 7405 if (retval < 0) 7406 return retval; 7407 7408 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 7409 7410 /* Check if the op failed because the device doesn't */ 7411 /* support this particular combination of algorithms */ 7412 if (op == NULL && ut_params->op->status == 7413 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 7414 printf("Device doesn't support this mixed combination. " 7415 "Test Skipped.\n"); 7416 return TEST_SKIPPED; 7417 } 7418 ut_params->op = op; 7419 7420 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 7421 7422 ut_params->obuf = (op_mode == IN_PLACE ? 7423 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 7424 7425 if (verify) { 7426 if (ut_params->obuf) 7427 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 7428 uint8_t *); 7429 else 7430 plaintext = ciphertext + 7431 (tdata->cipher.offset_bits >> 3); 7432 7433 debug_hexdump(stdout, "plaintext:", plaintext, 7434 tdata->plaintext.len_bits >> 3); 7435 debug_hexdump(stdout, "plaintext expected:", 7436 tdata->plaintext.data, 7437 tdata->plaintext.len_bits >> 3); 7438 } else { 7439 if (ut_params->obuf) 7440 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 7441 uint8_t *); 7442 else 7443 ciphertext = plaintext; 7444 7445 debug_hexdump(stdout, "ciphertext:", ciphertext, 7446 ciphertext_len); 7447 debug_hexdump(stdout, "ciphertext expected:", 7448 tdata->ciphertext.data, 7449 tdata->ciphertext.len_bits >> 3); 7450 7451 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 7452 + (tdata->digest_enc.offset == 0 ? 7453 plaintext_pad_len : tdata->digest_enc.offset); 7454 7455 debug_hexdump(stdout, "digest:", ut_params->digest, 7456 tdata->digest_enc.len); 7457 debug_hexdump(stdout, "digest expected:", 7458 tdata->digest_enc.data, 7459 tdata->digest_enc.len); 7460 } 7461 7462 /* Validate obuf */ 7463 if (verify) { 7464 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7465 plaintext, 7466 tdata->plaintext.data, 7467 tdata->plaintext.len_bits >> 3, 7468 "Plaintext data not as expected"); 7469 } else { 7470 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7471 ciphertext, 7472 tdata->ciphertext.data, 7473 tdata->validDataLen.len_bits, 7474 "Ciphertext data not as expected"); 7475 7476 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7477 ut_params->digest, 7478 tdata->digest_enc.data, 7479 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 7480 "Generated auth tag not as expected"); 7481 } 7482 7483 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7484 "crypto op processing failed"); 7485 7486 return 0; 7487 } 7488 7489 static int 7490 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata, 7491 uint8_t op_mode, uint8_t verify) 7492 { 7493 struct crypto_testsuite_params *ts_params = &testsuite_params; 7494 struct crypto_unittest_params *ut_params = &unittest_params; 7495 7496 int retval; 7497 7498 const uint8_t *plaintext = NULL; 7499 const uint8_t *ciphertext = NULL; 7500 const uint8_t *digest = NULL; 7501 unsigned int plaintext_pad_len; 7502 unsigned int plaintext_len; 7503 unsigned int ciphertext_pad_len; 7504 unsigned int ciphertext_len; 7505 uint8_t buffer[10000]; 7506 uint8_t digest_buffer[10000]; 7507 7508 struct rte_cryptodev_info dev_info; 7509 struct rte_crypto_op *op; 7510 7511 /* Check if device supports particular algorithms */ 7512 if (test_mixed_check_if_unsupported(tdata)) 7513 return TEST_SKIPPED; 7514 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7515 return TEST_SKIPPED; 7516 7517 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7518 7519 uint64_t feat_flags = dev_info.feature_flags; 7520 7521 if (op_mode == IN_PLACE) { 7522 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 7523 printf("Device doesn't support in-place scatter-gather " 7524 "in both input and output mbufs.\n"); 7525 return TEST_SKIPPED; 7526 } 7527 } else { 7528 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 7529 printf("Device doesn't support out-of-place scatter-gather " 7530 "in both input and output mbufs.\n"); 7531 return TEST_SKIPPED; 7532 } 7533 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7534 printf("Device doesn't support digest encrypted.\n"); 7535 return TEST_SKIPPED; 7536 } 7537 } 7538 7539 /* Create the session */ 7540 if (verify) 7541 retval = create_wireless_algo_cipher_auth_session( 7542 ts_params->valid_devs[0], 7543 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7544 RTE_CRYPTO_AUTH_OP_VERIFY, 7545 tdata->auth_algo, 7546 tdata->cipher_algo, 7547 tdata->auth_key.data, tdata->auth_key.len, 7548 tdata->auth_iv.len, tdata->digest_enc.len, 7549 tdata->cipher_iv.len); 7550 else 7551 retval = create_wireless_algo_auth_cipher_session( 7552 ts_params->valid_devs[0], 7553 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7554 RTE_CRYPTO_AUTH_OP_GENERATE, 7555 tdata->auth_algo, 7556 tdata->cipher_algo, 7557 tdata->auth_key.data, tdata->auth_key.len, 7558 tdata->auth_iv.len, tdata->digest_enc.len, 7559 tdata->cipher_iv.len); 7560 if (retval != 0) 7561 return retval; 7562 7563 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 7564 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 7565 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 7566 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 7567 7568 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 7569 ciphertext_pad_len, 15, 0); 7570 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 7571 "Failed to allocate input buffer in mempool"); 7572 7573 if (op_mode == OUT_OF_PLACE) { 7574 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 7575 plaintext_pad_len, 15, 0); 7576 TEST_ASSERT_NOT_NULL(ut_params->obuf, 7577 "Failed to allocate output buffer in mempool"); 7578 } 7579 7580 if (verify) { 7581 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 7582 tdata->ciphertext.data); 7583 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7584 ciphertext_len, buffer); 7585 debug_hexdump(stdout, "ciphertext:", ciphertext, 7586 ciphertext_len); 7587 } else { 7588 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 7589 tdata->plaintext.data); 7590 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7591 plaintext_len, buffer); 7592 debug_hexdump(stdout, "plaintext:", plaintext, 7593 plaintext_len); 7594 } 7595 memset(buffer, 0, sizeof(buffer)); 7596 7597 /* Create the operation */ 7598 retval = create_wireless_algo_auth_cipher_operation( 7599 tdata->digest_enc.data, tdata->digest_enc.len, 7600 tdata->cipher_iv.data, tdata->cipher_iv.len, 7601 tdata->auth_iv.data, tdata->auth_iv.len, 7602 (tdata->digest_enc.offset == 0 ? 7603 plaintext_pad_len 7604 : tdata->digest_enc.offset), 7605 tdata->validCipherLen.len_bits, 7606 tdata->cipher.offset_bits, 7607 tdata->validAuthLen.len_bits, 7608 tdata->auth.offset_bits, 7609 op_mode, 1, verify); 7610 7611 if (retval < 0) 7612 return retval; 7613 7614 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 7615 7616 /* Check if the op failed because the device doesn't */ 7617 /* support this particular combination of algorithms */ 7618 if (op == NULL && ut_params->op->status == 7619 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 7620 printf("Device doesn't support this mixed combination. " 7621 "Test Skipped.\n"); 7622 return TEST_SKIPPED; 7623 } 7624 ut_params->op = op; 7625 7626 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 7627 7628 ut_params->obuf = (op_mode == IN_PLACE ? 7629 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 7630 7631 if (verify) { 7632 if (ut_params->obuf) 7633 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 7634 plaintext_len, buffer); 7635 else 7636 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7637 plaintext_len, buffer); 7638 7639 debug_hexdump(stdout, "plaintext:", plaintext, 7640 (tdata->plaintext.len_bits >> 3) - 7641 tdata->digest_enc.len); 7642 debug_hexdump(stdout, "plaintext expected:", 7643 tdata->plaintext.data, 7644 (tdata->plaintext.len_bits >> 3) - 7645 tdata->digest_enc.len); 7646 } else { 7647 if (ut_params->obuf) 7648 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 7649 ciphertext_len, buffer); 7650 else 7651 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7652 ciphertext_len, buffer); 7653 7654 debug_hexdump(stdout, "ciphertext:", ciphertext, 7655 ciphertext_len); 7656 debug_hexdump(stdout, "ciphertext expected:", 7657 tdata->ciphertext.data, 7658 tdata->ciphertext.len_bits >> 3); 7659 7660 if (ut_params->obuf) 7661 digest = rte_pktmbuf_read(ut_params->obuf, 7662 (tdata->digest_enc.offset == 0 ? 7663 plaintext_pad_len : 7664 tdata->digest_enc.offset), 7665 tdata->digest_enc.len, digest_buffer); 7666 else 7667 digest = rte_pktmbuf_read(ut_params->ibuf, 7668 (tdata->digest_enc.offset == 0 ? 7669 plaintext_pad_len : 7670 tdata->digest_enc.offset), 7671 tdata->digest_enc.len, digest_buffer); 7672 7673 debug_hexdump(stdout, "digest:", digest, 7674 tdata->digest_enc.len); 7675 debug_hexdump(stdout, "digest expected:", 7676 tdata->digest_enc.data, tdata->digest_enc.len); 7677 } 7678 7679 /* Validate obuf */ 7680 if (verify) { 7681 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7682 plaintext, 7683 tdata->plaintext.data, 7684 tdata->plaintext.len_bits >> 3, 7685 "Plaintext data not as expected"); 7686 } else { 7687 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7688 ciphertext, 7689 tdata->ciphertext.data, 7690 tdata->validDataLen.len_bits, 7691 "Ciphertext data not as expected"); 7692 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7693 digest, 7694 tdata->digest_enc.data, 7695 tdata->digest_enc.len, 7696 "Generated auth tag not as expected"); 7697 } 7698 7699 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7700 "crypto op processing failed"); 7701 7702 return 0; 7703 } 7704 7705 /** AUTH AES CMAC + CIPHER AES CTR */ 7706 7707 static int 7708 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7709 { 7710 return test_mixed_auth_cipher( 7711 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7712 } 7713 7714 static int 7715 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7716 { 7717 return test_mixed_auth_cipher( 7718 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7719 } 7720 7721 static int 7722 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7723 { 7724 return test_mixed_auth_cipher_sgl( 7725 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7726 } 7727 7728 static int 7729 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7730 { 7731 return test_mixed_auth_cipher_sgl( 7732 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7733 } 7734 7735 static int 7736 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7737 { 7738 return test_mixed_auth_cipher( 7739 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7740 } 7741 7742 static int 7743 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7744 { 7745 return test_mixed_auth_cipher( 7746 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7747 } 7748 7749 static int 7750 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7751 { 7752 return test_mixed_auth_cipher_sgl( 7753 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7754 } 7755 7756 static int 7757 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7758 { 7759 return test_mixed_auth_cipher_sgl( 7760 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7761 } 7762 7763 /** MIXED AUTH + CIPHER */ 7764 7765 static int 7766 test_auth_zuc_cipher_snow_test_case_1(void) 7767 { 7768 return test_mixed_auth_cipher( 7769 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7770 } 7771 7772 static int 7773 test_verify_auth_zuc_cipher_snow_test_case_1(void) 7774 { 7775 return test_mixed_auth_cipher( 7776 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7777 } 7778 7779 static int 7780 test_auth_aes_cmac_cipher_snow_test_case_1(void) 7781 { 7782 return test_mixed_auth_cipher( 7783 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7784 } 7785 7786 static int 7787 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void) 7788 { 7789 return test_mixed_auth_cipher( 7790 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7791 } 7792 7793 static int 7794 test_auth_zuc_cipher_aes_ctr_test_case_1(void) 7795 { 7796 return test_mixed_auth_cipher( 7797 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7798 } 7799 7800 static int 7801 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void) 7802 { 7803 return test_mixed_auth_cipher( 7804 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7805 } 7806 7807 static int 7808 test_auth_snow_cipher_aes_ctr_test_case_1(void) 7809 { 7810 return test_mixed_auth_cipher( 7811 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7812 } 7813 7814 static int 7815 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void) 7816 { 7817 return test_mixed_auth_cipher( 7818 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7819 } 7820 7821 static int 7822 test_auth_snow_cipher_zuc_test_case_1(void) 7823 { 7824 return test_mixed_auth_cipher( 7825 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7826 } 7827 7828 static int 7829 test_verify_auth_snow_cipher_zuc_test_case_1(void) 7830 { 7831 return test_mixed_auth_cipher( 7832 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7833 } 7834 7835 static int 7836 test_auth_aes_cmac_cipher_zuc_test_case_1(void) 7837 { 7838 return test_mixed_auth_cipher( 7839 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7840 } 7841 7842 static int 7843 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void) 7844 { 7845 return test_mixed_auth_cipher( 7846 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7847 } 7848 7849 static int 7850 test_auth_null_cipher_snow_test_case_1(void) 7851 { 7852 return test_mixed_auth_cipher( 7853 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7854 } 7855 7856 static int 7857 test_verify_auth_null_cipher_snow_test_case_1(void) 7858 { 7859 return test_mixed_auth_cipher( 7860 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7861 } 7862 7863 static int 7864 test_auth_null_cipher_zuc_test_case_1(void) 7865 { 7866 return test_mixed_auth_cipher( 7867 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7868 } 7869 7870 static int 7871 test_verify_auth_null_cipher_zuc_test_case_1(void) 7872 { 7873 return test_mixed_auth_cipher( 7874 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7875 } 7876 7877 static int 7878 test_auth_snow_cipher_null_test_case_1(void) 7879 { 7880 return test_mixed_auth_cipher( 7881 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7882 } 7883 7884 static int 7885 test_verify_auth_snow_cipher_null_test_case_1(void) 7886 { 7887 return test_mixed_auth_cipher( 7888 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7889 } 7890 7891 static int 7892 test_auth_zuc_cipher_null_test_case_1(void) 7893 { 7894 return test_mixed_auth_cipher( 7895 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7896 } 7897 7898 static int 7899 test_verify_auth_zuc_cipher_null_test_case_1(void) 7900 { 7901 return test_mixed_auth_cipher( 7902 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7903 } 7904 7905 static int 7906 test_auth_null_cipher_aes_ctr_test_case_1(void) 7907 { 7908 return test_mixed_auth_cipher( 7909 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7910 } 7911 7912 static int 7913 test_verify_auth_null_cipher_aes_ctr_test_case_1(void) 7914 { 7915 return test_mixed_auth_cipher( 7916 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7917 } 7918 7919 static int 7920 test_auth_aes_cmac_cipher_null_test_case_1(void) 7921 { 7922 return test_mixed_auth_cipher( 7923 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7924 } 7925 7926 static int 7927 test_verify_auth_aes_cmac_cipher_null_test_case_1(void) 7928 { 7929 return test_mixed_auth_cipher( 7930 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7931 } 7932 7933 /* ***** AEAD algorithm Tests ***** */ 7934 7935 static int 7936 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo, 7937 enum rte_crypto_aead_operation op, 7938 const uint8_t *key, const uint8_t key_len, 7939 const uint16_t aad_len, const uint8_t auth_len, 7940 uint8_t iv_len) 7941 { 7942 uint8_t aead_key[key_len]; 7943 7944 struct crypto_testsuite_params *ts_params = &testsuite_params; 7945 struct crypto_unittest_params *ut_params = &unittest_params; 7946 7947 memcpy(aead_key, key, key_len); 7948 7949 /* Setup AEAD Parameters */ 7950 ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 7951 ut_params->aead_xform.next = NULL; 7952 ut_params->aead_xform.aead.algo = algo; 7953 ut_params->aead_xform.aead.op = op; 7954 ut_params->aead_xform.aead.key.data = aead_key; 7955 ut_params->aead_xform.aead.key.length = key_len; 7956 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 7957 ut_params->aead_xform.aead.iv.length = iv_len; 7958 ut_params->aead_xform.aead.digest_length = auth_len; 7959 ut_params->aead_xform.aead.aad_length = aad_len; 7960 7961 debug_hexdump(stdout, "key:", key, key_len); 7962 7963 /* Create Crypto session*/ 7964 ut_params->sess = rte_cryptodev_sym_session_create( 7965 ts_params->session_mpool); 7966 7967 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 7968 &ut_params->aead_xform, 7969 ts_params->session_priv_mpool); 7970 7971 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 7972 7973 return 0; 7974 } 7975 7976 static int 7977 create_aead_xform(struct rte_crypto_op *op, 7978 enum rte_crypto_aead_algorithm algo, 7979 enum rte_crypto_aead_operation aead_op, 7980 uint8_t *key, const uint8_t key_len, 7981 const uint8_t aad_len, const uint8_t auth_len, 7982 uint8_t iv_len) 7983 { 7984 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1), 7985 "failed to allocate space for crypto transform"); 7986 7987 struct rte_crypto_sym_op *sym_op = op->sym; 7988 7989 /* Setup AEAD Parameters */ 7990 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD; 7991 sym_op->xform->next = NULL; 7992 sym_op->xform->aead.algo = algo; 7993 sym_op->xform->aead.op = aead_op; 7994 sym_op->xform->aead.key.data = key; 7995 sym_op->xform->aead.key.length = key_len; 7996 sym_op->xform->aead.iv.offset = IV_OFFSET; 7997 sym_op->xform->aead.iv.length = iv_len; 7998 sym_op->xform->aead.digest_length = auth_len; 7999 sym_op->xform->aead.aad_length = aad_len; 8000 8001 debug_hexdump(stdout, "key:", key, key_len); 8002 8003 return 0; 8004 } 8005 8006 static int 8007 create_aead_operation(enum rte_crypto_aead_operation op, 8008 const struct aead_test_data *tdata) 8009 { 8010 struct crypto_testsuite_params *ts_params = &testsuite_params; 8011 struct crypto_unittest_params *ut_params = &unittest_params; 8012 8013 uint8_t *plaintext, *ciphertext; 8014 unsigned int aad_pad_len, plaintext_pad_len; 8015 8016 /* Generate Crypto op data structure */ 8017 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8018 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8019 TEST_ASSERT_NOT_NULL(ut_params->op, 8020 "Failed to allocate symmetric crypto operation struct"); 8021 8022 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 8023 8024 /* Append aad data */ 8025 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 8026 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16); 8027 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8028 aad_pad_len); 8029 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8030 "no room to append aad"); 8031 8032 sym_op->aead.aad.phys_addr = 8033 rte_pktmbuf_iova(ut_params->ibuf); 8034 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 8035 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len); 8036 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 8037 tdata->aad.len); 8038 8039 /* Append IV at the end of the crypto operation*/ 8040 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8041 uint8_t *, IV_OFFSET); 8042 8043 /* Copy IV 1 byte after the IV pointer, according to the API */ 8044 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len); 8045 debug_hexdump(stdout, "iv:", iv_ptr, 8046 tdata->iv.len); 8047 } else { 8048 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 8049 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8050 aad_pad_len); 8051 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8052 "no room to append aad"); 8053 8054 sym_op->aead.aad.phys_addr = 8055 rte_pktmbuf_iova(ut_params->ibuf); 8056 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len); 8057 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 8058 tdata->aad.len); 8059 8060 /* Append IV at the end of the crypto operation*/ 8061 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8062 uint8_t *, IV_OFFSET); 8063 8064 if (tdata->iv.len == 0) { 8065 rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH); 8066 debug_hexdump(stdout, "iv:", iv_ptr, 8067 AES_GCM_J0_LENGTH); 8068 } else { 8069 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 8070 debug_hexdump(stdout, "iv:", iv_ptr, 8071 tdata->iv.len); 8072 } 8073 } 8074 8075 /* Append plaintext/ciphertext */ 8076 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 8077 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 8078 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8079 plaintext_pad_len); 8080 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 8081 8082 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 8083 debug_hexdump(stdout, "plaintext:", plaintext, 8084 tdata->plaintext.len); 8085 8086 if (ut_params->obuf) { 8087 ciphertext = (uint8_t *)rte_pktmbuf_append( 8088 ut_params->obuf, 8089 plaintext_pad_len + aad_pad_len); 8090 TEST_ASSERT_NOT_NULL(ciphertext, 8091 "no room to append ciphertext"); 8092 8093 memset(ciphertext + aad_pad_len, 0, 8094 tdata->ciphertext.len); 8095 } 8096 } else { 8097 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); 8098 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8099 plaintext_pad_len); 8100 TEST_ASSERT_NOT_NULL(ciphertext, 8101 "no room to append ciphertext"); 8102 8103 memcpy(ciphertext, tdata->ciphertext.data, 8104 tdata->ciphertext.len); 8105 debug_hexdump(stdout, "ciphertext:", ciphertext, 8106 tdata->ciphertext.len); 8107 8108 if (ut_params->obuf) { 8109 plaintext = (uint8_t *)rte_pktmbuf_append( 8110 ut_params->obuf, 8111 plaintext_pad_len + aad_pad_len); 8112 TEST_ASSERT_NOT_NULL(plaintext, 8113 "no room to append plaintext"); 8114 8115 memset(plaintext + aad_pad_len, 0, 8116 tdata->plaintext.len); 8117 } 8118 } 8119 8120 /* Append digest data */ 8121 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 8122 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 8123 ut_params->obuf ? ut_params->obuf : 8124 ut_params->ibuf, 8125 tdata->auth_tag.len); 8126 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 8127 "no room to append digest"); 8128 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len); 8129 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 8130 ut_params->obuf ? ut_params->obuf : 8131 ut_params->ibuf, 8132 plaintext_pad_len + 8133 aad_pad_len); 8134 } else { 8135 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 8136 ut_params->ibuf, tdata->auth_tag.len); 8137 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 8138 "no room to append digest"); 8139 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 8140 ut_params->ibuf, 8141 plaintext_pad_len + aad_pad_len); 8142 8143 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 8144 tdata->auth_tag.len); 8145 debug_hexdump(stdout, "digest:", 8146 sym_op->aead.digest.data, 8147 tdata->auth_tag.len); 8148 } 8149 8150 sym_op->aead.data.length = tdata->plaintext.len; 8151 sym_op->aead.data.offset = aad_pad_len; 8152 8153 return 0; 8154 } 8155 8156 static int 8157 test_authenticated_encryption(const struct aead_test_data *tdata) 8158 { 8159 struct crypto_testsuite_params *ts_params = &testsuite_params; 8160 struct crypto_unittest_params *ut_params = &unittest_params; 8161 8162 int retval; 8163 uint8_t *ciphertext, *auth_tag; 8164 uint16_t plaintext_pad_len; 8165 uint32_t i; 8166 struct rte_cryptodev_info dev_info; 8167 8168 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8169 uint64_t feat_flags = dev_info.feature_flags; 8170 8171 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 8172 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 8173 printf("Device doesn't support RAW data-path APIs.\n"); 8174 return TEST_SKIPPED; 8175 } 8176 8177 /* Verify the capabilities */ 8178 struct rte_cryptodev_sym_capability_idx cap_idx; 8179 const struct rte_cryptodev_symmetric_capability *capability; 8180 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 8181 cap_idx.algo.aead = tdata->algo; 8182 capability = rte_cryptodev_sym_capability_get( 8183 ts_params->valid_devs[0], &cap_idx); 8184 if (capability == NULL) 8185 return TEST_SKIPPED; 8186 if (rte_cryptodev_sym_capability_check_aead( 8187 capability, tdata->key.len, tdata->auth_tag.len, 8188 tdata->aad.len, tdata->iv.len)) 8189 return TEST_SKIPPED; 8190 8191 /* Create AEAD session */ 8192 retval = create_aead_session(ts_params->valid_devs[0], 8193 tdata->algo, 8194 RTE_CRYPTO_AEAD_OP_ENCRYPT, 8195 tdata->key.data, tdata->key.len, 8196 tdata->aad.len, tdata->auth_tag.len, 8197 tdata->iv.len); 8198 if (retval < 0) 8199 return retval; 8200 8201 if (tdata->aad.len > MBUF_SIZE) { 8202 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 8203 /* Populate full size of add data */ 8204 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 8205 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 8206 } else 8207 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8208 8209 /* clear mbuf payload */ 8210 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8211 rte_pktmbuf_tailroom(ut_params->ibuf)); 8212 8213 /* Create AEAD operation */ 8214 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 8215 if (retval < 0) 8216 return retval; 8217 8218 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 8219 8220 ut_params->op->sym->m_src = ut_params->ibuf; 8221 8222 /* Process crypto operation */ 8223 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8224 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 8225 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 8226 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 8227 ut_params->op, 0, 0, 0, 0); 8228 else 8229 TEST_ASSERT_NOT_NULL( 8230 process_crypto_request(ts_params->valid_devs[0], 8231 ut_params->op), "failed to process sym crypto op"); 8232 8233 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8234 "crypto op processing failed"); 8235 8236 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 8237 8238 if (ut_params->op->sym->m_dst) { 8239 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8240 uint8_t *); 8241 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 8242 uint8_t *, plaintext_pad_len); 8243 } else { 8244 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 8245 uint8_t *, 8246 ut_params->op->sym->cipher.data.offset); 8247 auth_tag = ciphertext + plaintext_pad_len; 8248 } 8249 8250 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 8251 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 8252 8253 /* Validate obuf */ 8254 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8255 ciphertext, 8256 tdata->ciphertext.data, 8257 tdata->ciphertext.len, 8258 "Ciphertext data not as expected"); 8259 8260 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8261 auth_tag, 8262 tdata->auth_tag.data, 8263 tdata->auth_tag.len, 8264 "Generated auth tag not as expected"); 8265 8266 return 0; 8267 8268 } 8269 8270 #ifdef RTE_LIB_SECURITY 8271 static int 8272 security_proto_supported(enum rte_security_session_action_type action, 8273 enum rte_security_session_protocol proto) 8274 { 8275 struct crypto_testsuite_params *ts_params = &testsuite_params; 8276 8277 const struct rte_security_capability *capabilities; 8278 const struct rte_security_capability *capability; 8279 uint16_t i = 0; 8280 8281 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8282 rte_cryptodev_get_sec_ctx( 8283 ts_params->valid_devs[0]); 8284 8285 8286 capabilities = rte_security_capabilities_get(ctx); 8287 8288 if (capabilities == NULL) 8289 return -ENOTSUP; 8290 8291 while ((capability = &capabilities[i++])->action != 8292 RTE_SECURITY_ACTION_TYPE_NONE) { 8293 if (capability->action == action && 8294 capability->protocol == proto) 8295 return 0; 8296 } 8297 8298 return -ENOTSUP; 8299 } 8300 8301 /* Basic algorithm run function for async inplace mode. 8302 * Creates a session from input parameters and runs one operation 8303 * on input_vec. Checks the output of the crypto operation against 8304 * output_vec. 8305 */ 8306 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc, 8307 enum rte_crypto_auth_operation opa, 8308 const uint8_t *input_vec, unsigned int input_vec_len, 8309 const uint8_t *output_vec, 8310 unsigned int output_vec_len, 8311 enum rte_crypto_cipher_algorithm cipher_alg, 8312 const uint8_t *cipher_key, uint32_t cipher_key_len, 8313 enum rte_crypto_auth_algorithm auth_alg, 8314 const uint8_t *auth_key, uint32_t auth_key_len, 8315 uint8_t bearer, enum rte_security_pdcp_domain domain, 8316 uint8_t packet_direction, uint8_t sn_size, 8317 uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap) 8318 { 8319 struct crypto_testsuite_params *ts_params = &testsuite_params; 8320 struct crypto_unittest_params *ut_params = &unittest_params; 8321 uint8_t *plaintext; 8322 int ret = TEST_SUCCESS; 8323 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8324 rte_cryptodev_get_sec_ctx( 8325 ts_params->valid_devs[0]); 8326 8327 /* Verify the capabilities */ 8328 struct rte_security_capability_idx sec_cap_idx; 8329 8330 sec_cap_idx.action = ut_params->type; 8331 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 8332 sec_cap_idx.pdcp.domain = domain; 8333 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 8334 return TEST_SKIPPED; 8335 8336 /* Generate test mbuf data */ 8337 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8338 8339 /* clear mbuf payload */ 8340 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8341 rte_pktmbuf_tailroom(ut_params->ibuf)); 8342 8343 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8344 input_vec_len); 8345 memcpy(plaintext, input_vec, input_vec_len); 8346 8347 /* Out of place support */ 8348 if (oop) { 8349 /* 8350 * For out-op-place we need to alloc another mbuf 8351 */ 8352 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8353 rte_pktmbuf_append(ut_params->obuf, output_vec_len); 8354 } 8355 8356 /* Setup Cipher Parameters */ 8357 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8358 ut_params->cipher_xform.cipher.algo = cipher_alg; 8359 ut_params->cipher_xform.cipher.op = opc; 8360 ut_params->cipher_xform.cipher.key.data = cipher_key; 8361 ut_params->cipher_xform.cipher.key.length = cipher_key_len; 8362 ut_params->cipher_xform.cipher.iv.length = 8363 packet_direction ? 4 : 0; 8364 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 8365 8366 /* Setup HMAC Parameters if ICV header is required */ 8367 if (auth_alg != 0) { 8368 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8369 ut_params->auth_xform.next = NULL; 8370 ut_params->auth_xform.auth.algo = auth_alg; 8371 ut_params->auth_xform.auth.op = opa; 8372 ut_params->auth_xform.auth.key.data = auth_key; 8373 ut_params->auth_xform.auth.key.length = auth_key_len; 8374 8375 ut_params->cipher_xform.next = &ut_params->auth_xform; 8376 } else { 8377 ut_params->cipher_xform.next = NULL; 8378 } 8379 8380 struct rte_security_session_conf sess_conf = { 8381 .action_type = ut_params->type, 8382 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 8383 {.pdcp = { 8384 .bearer = bearer, 8385 .domain = domain, 8386 .pkt_dir = packet_direction, 8387 .sn_size = sn_size, 8388 .hfn = packet_direction ? 0 : hfn, 8389 /** 8390 * hfn can be set as pdcp_test_hfn[i] 8391 * if hfn_ovrd is not set. Here, PDCP 8392 * packet direction is just used to 8393 * run half of the cases with session 8394 * HFN and other half with per packet 8395 * HFN. 8396 */ 8397 .hfn_threshold = hfn_threshold, 8398 .hfn_ovrd = packet_direction ? 1 : 0, 8399 .sdap_enabled = sdap, 8400 } }, 8401 .crypto_xform = &ut_params->cipher_xform 8402 }; 8403 8404 /* Create security session */ 8405 ut_params->sec_session = rte_security_session_create(ctx, 8406 &sess_conf, ts_params->session_mpool, 8407 ts_params->session_priv_mpool); 8408 8409 if (!ut_params->sec_session) { 8410 printf("TestCase %s()-%d line %d failed %s: ", 8411 __func__, i, __LINE__, "Failed to allocate session"); 8412 ret = TEST_FAILED; 8413 goto on_err; 8414 } 8415 8416 /* Generate crypto op data structure */ 8417 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8418 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8419 if (!ut_params->op) { 8420 printf("TestCase %s()-%d line %d failed %s: ", 8421 __func__, i, __LINE__, 8422 "Failed to allocate symmetric crypto operation struct"); 8423 ret = TEST_FAILED; 8424 goto on_err; 8425 } 8426 8427 uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op, 8428 uint32_t *, IV_OFFSET); 8429 *per_pkt_hfn = packet_direction ? hfn : 0; 8430 8431 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8432 8433 /* set crypto operation source mbuf */ 8434 ut_params->op->sym->m_src = ut_params->ibuf; 8435 if (oop) 8436 ut_params->op->sym->m_dst = ut_params->obuf; 8437 8438 /* Process crypto operation */ 8439 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) 8440 == NULL) { 8441 printf("TestCase %s()-%d line %d failed %s: ", 8442 __func__, i, __LINE__, 8443 "failed to process sym crypto op"); 8444 ret = TEST_FAILED; 8445 goto on_err; 8446 } 8447 8448 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8449 printf("TestCase %s()-%d line %d failed %s: ", 8450 __func__, i, __LINE__, "crypto op processing failed"); 8451 ret = TEST_FAILED; 8452 goto on_err; 8453 } 8454 8455 /* Validate obuf */ 8456 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 8457 uint8_t *); 8458 if (oop) { 8459 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8460 uint8_t *); 8461 } 8462 8463 if (memcmp(ciphertext, output_vec, output_vec_len)) { 8464 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8465 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len); 8466 rte_hexdump(stdout, "reference", output_vec, output_vec_len); 8467 ret = TEST_FAILED; 8468 goto on_err; 8469 } 8470 8471 on_err: 8472 rte_crypto_op_free(ut_params->op); 8473 ut_params->op = NULL; 8474 8475 if (ut_params->sec_session) 8476 rte_security_session_destroy(ctx, ut_params->sec_session); 8477 ut_params->sec_session = NULL; 8478 8479 rte_pktmbuf_free(ut_params->ibuf); 8480 ut_params->ibuf = NULL; 8481 if (oop) { 8482 rte_pktmbuf_free(ut_params->obuf); 8483 ut_params->obuf = NULL; 8484 } 8485 8486 return ret; 8487 } 8488 8489 static int 8490 test_pdcp_proto_SGL(int i, int oop, 8491 enum rte_crypto_cipher_operation opc, 8492 enum rte_crypto_auth_operation opa, 8493 uint8_t *input_vec, 8494 unsigned int input_vec_len, 8495 uint8_t *output_vec, 8496 unsigned int output_vec_len, 8497 uint32_t fragsz, 8498 uint32_t fragsz_oop) 8499 { 8500 struct crypto_testsuite_params *ts_params = &testsuite_params; 8501 struct crypto_unittest_params *ut_params = &unittest_params; 8502 uint8_t *plaintext; 8503 struct rte_mbuf *buf, *buf_oop = NULL; 8504 int ret = TEST_SUCCESS; 8505 int to_trn = 0; 8506 int to_trn_tbl[16]; 8507 int segs = 1; 8508 unsigned int trn_data = 0; 8509 struct rte_cryptodev_info dev_info; 8510 uint64_t feat_flags; 8511 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8512 rte_cryptodev_get_sec_ctx( 8513 ts_params->valid_devs[0]); 8514 struct rte_mbuf *temp_mbuf; 8515 8516 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8517 feat_flags = dev_info.feature_flags; 8518 8519 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 8520 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 8521 printf("Device does not support RAW data-path APIs.\n"); 8522 return -ENOTSUP; 8523 } 8524 /* Verify the capabilities */ 8525 struct rte_security_capability_idx sec_cap_idx; 8526 8527 sec_cap_idx.action = ut_params->type; 8528 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 8529 sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain; 8530 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 8531 return TEST_SKIPPED; 8532 8533 if (fragsz > input_vec_len) 8534 fragsz = input_vec_len; 8535 8536 uint16_t plaintext_len = fragsz; 8537 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 8538 8539 if (fragsz_oop > output_vec_len) 8540 frag_size_oop = output_vec_len; 8541 8542 int ecx = 0; 8543 if (input_vec_len % fragsz != 0) { 8544 if (input_vec_len / fragsz + 1 > 16) 8545 return 1; 8546 } else if (input_vec_len / fragsz > 16) 8547 return 1; 8548 8549 /* Out of place support */ 8550 if (oop) { 8551 /* 8552 * For out-op-place we need to alloc another mbuf 8553 */ 8554 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8555 rte_pktmbuf_append(ut_params->obuf, frag_size_oop); 8556 buf_oop = ut_params->obuf; 8557 } 8558 8559 /* Generate test mbuf data */ 8560 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8561 8562 /* clear mbuf payload */ 8563 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8564 rte_pktmbuf_tailroom(ut_params->ibuf)); 8565 8566 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8567 plaintext_len); 8568 memcpy(plaintext, input_vec, plaintext_len); 8569 trn_data += plaintext_len; 8570 8571 buf = ut_params->ibuf; 8572 8573 /* 8574 * Loop until no more fragments 8575 */ 8576 8577 while (trn_data < input_vec_len) { 8578 ++segs; 8579 to_trn = (input_vec_len - trn_data < fragsz) ? 8580 (input_vec_len - trn_data) : fragsz; 8581 8582 to_trn_tbl[ecx++] = to_trn; 8583 8584 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8585 buf = buf->next; 8586 8587 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 8588 rte_pktmbuf_tailroom(buf)); 8589 8590 /* OOP */ 8591 if (oop && !fragsz_oop) { 8592 buf_oop->next = 8593 rte_pktmbuf_alloc(ts_params->mbuf_pool); 8594 buf_oop = buf_oop->next; 8595 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 8596 0, rte_pktmbuf_tailroom(buf_oop)); 8597 rte_pktmbuf_append(buf_oop, to_trn); 8598 } 8599 8600 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 8601 to_trn); 8602 8603 memcpy(plaintext, input_vec + trn_data, to_trn); 8604 trn_data += to_trn; 8605 } 8606 8607 ut_params->ibuf->nb_segs = segs; 8608 8609 segs = 1; 8610 if (fragsz_oop && oop) { 8611 to_trn = 0; 8612 ecx = 0; 8613 8614 trn_data = frag_size_oop; 8615 while (trn_data < output_vec_len) { 8616 ++segs; 8617 to_trn = 8618 (output_vec_len - trn_data < 8619 frag_size_oop) ? 8620 (output_vec_len - trn_data) : 8621 frag_size_oop; 8622 8623 to_trn_tbl[ecx++] = to_trn; 8624 8625 buf_oop->next = 8626 rte_pktmbuf_alloc(ts_params->mbuf_pool); 8627 buf_oop = buf_oop->next; 8628 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 8629 0, rte_pktmbuf_tailroom(buf_oop)); 8630 rte_pktmbuf_append(buf_oop, to_trn); 8631 8632 trn_data += to_trn; 8633 } 8634 ut_params->obuf->nb_segs = segs; 8635 } 8636 8637 /* Setup Cipher Parameters */ 8638 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8639 ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg; 8640 ut_params->cipher_xform.cipher.op = opc; 8641 ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i]; 8642 ut_params->cipher_xform.cipher.key.length = 8643 pdcp_test_params[i].cipher_key_len; 8644 ut_params->cipher_xform.cipher.iv.length = 0; 8645 8646 /* Setup HMAC Parameters if ICV header is required */ 8647 if (pdcp_test_params[i].auth_alg != 0) { 8648 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8649 ut_params->auth_xform.next = NULL; 8650 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg; 8651 ut_params->auth_xform.auth.op = opa; 8652 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i]; 8653 ut_params->auth_xform.auth.key.length = 8654 pdcp_test_params[i].auth_key_len; 8655 8656 ut_params->cipher_xform.next = &ut_params->auth_xform; 8657 } else { 8658 ut_params->cipher_xform.next = NULL; 8659 } 8660 8661 struct rte_security_session_conf sess_conf = { 8662 .action_type = ut_params->type, 8663 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 8664 {.pdcp = { 8665 .bearer = pdcp_test_bearer[i], 8666 .domain = pdcp_test_params[i].domain, 8667 .pkt_dir = pdcp_test_packet_direction[i], 8668 .sn_size = pdcp_test_data_sn_size[i], 8669 .hfn = pdcp_test_hfn[i], 8670 .hfn_threshold = pdcp_test_hfn_threshold[i], 8671 .hfn_ovrd = 0, 8672 } }, 8673 .crypto_xform = &ut_params->cipher_xform 8674 }; 8675 8676 /* Create security session */ 8677 ut_params->sec_session = rte_security_session_create(ctx, 8678 &sess_conf, ts_params->session_mpool, 8679 ts_params->session_priv_mpool); 8680 8681 if (!ut_params->sec_session) { 8682 printf("TestCase %s()-%d line %d failed %s: ", 8683 __func__, i, __LINE__, "Failed to allocate session"); 8684 ret = TEST_FAILED; 8685 goto on_err; 8686 } 8687 8688 /* Generate crypto op data structure */ 8689 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8690 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8691 if (!ut_params->op) { 8692 printf("TestCase %s()-%d line %d failed %s: ", 8693 __func__, i, __LINE__, 8694 "Failed to allocate symmetric crypto operation struct"); 8695 ret = TEST_FAILED; 8696 goto on_err; 8697 } 8698 8699 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8700 8701 /* set crypto operation source mbuf */ 8702 ut_params->op->sym->m_src = ut_params->ibuf; 8703 if (oop) 8704 ut_params->op->sym->m_dst = ut_params->obuf; 8705 8706 /* Process crypto operation */ 8707 temp_mbuf = ut_params->op->sym->m_src; 8708 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 8709 /* filling lengths */ 8710 while (temp_mbuf) { 8711 ut_params->op->sym->cipher.data.length 8712 += temp_mbuf->pkt_len; 8713 ut_params->op->sym->auth.data.length 8714 += temp_mbuf->pkt_len; 8715 temp_mbuf = temp_mbuf->next; 8716 } 8717 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 8718 ut_params->op, 1, 1, 0, 0); 8719 } else { 8720 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 8721 ut_params->op); 8722 } 8723 if (ut_params->op == NULL) { 8724 printf("TestCase %s()-%d line %d failed %s: ", 8725 __func__, i, __LINE__, 8726 "failed to process sym crypto op"); 8727 ret = TEST_FAILED; 8728 goto on_err; 8729 } 8730 8731 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8732 printf("TestCase %s()-%d line %d failed %s: ", 8733 __func__, i, __LINE__, "crypto op processing failed"); 8734 ret = TEST_FAILED; 8735 goto on_err; 8736 } 8737 8738 /* Validate obuf */ 8739 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 8740 uint8_t *); 8741 if (oop) { 8742 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8743 uint8_t *); 8744 } 8745 if (fragsz_oop) 8746 fragsz = frag_size_oop; 8747 if (memcmp(ciphertext, output_vec, fragsz)) { 8748 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8749 rte_hexdump(stdout, "encrypted", ciphertext, fragsz); 8750 rte_hexdump(stdout, "reference", output_vec, fragsz); 8751 ret = TEST_FAILED; 8752 goto on_err; 8753 } 8754 8755 buf = ut_params->op->sym->m_src->next; 8756 if (oop) 8757 buf = ut_params->op->sym->m_dst->next; 8758 8759 unsigned int off = fragsz; 8760 8761 ecx = 0; 8762 while (buf) { 8763 ciphertext = rte_pktmbuf_mtod(buf, 8764 uint8_t *); 8765 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) { 8766 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8767 rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]); 8768 rte_hexdump(stdout, "reference", output_vec + off, 8769 to_trn_tbl[ecx]); 8770 ret = TEST_FAILED; 8771 goto on_err; 8772 } 8773 off += to_trn_tbl[ecx++]; 8774 buf = buf->next; 8775 } 8776 on_err: 8777 rte_crypto_op_free(ut_params->op); 8778 ut_params->op = NULL; 8779 8780 if (ut_params->sec_session) 8781 rte_security_session_destroy(ctx, ut_params->sec_session); 8782 ut_params->sec_session = NULL; 8783 8784 rte_pktmbuf_free(ut_params->ibuf); 8785 ut_params->ibuf = NULL; 8786 if (oop) { 8787 rte_pktmbuf_free(ut_params->obuf); 8788 ut_params->obuf = NULL; 8789 } 8790 8791 return ret; 8792 } 8793 8794 int 8795 test_pdcp_proto_cplane_encap(int i) 8796 { 8797 return test_pdcp_proto( 8798 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8799 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8800 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8801 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8802 pdcp_test_params[i].cipher_key_len, 8803 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8804 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8805 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8806 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8807 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8808 } 8809 8810 int 8811 test_pdcp_proto_uplane_encap(int i) 8812 { 8813 return test_pdcp_proto( 8814 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8815 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8816 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 8817 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8818 pdcp_test_params[i].cipher_key_len, 8819 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8820 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8821 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8822 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8823 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8824 } 8825 8826 int 8827 test_pdcp_proto_uplane_encap_with_int(int i) 8828 { 8829 return test_pdcp_proto( 8830 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8831 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8832 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8833 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8834 pdcp_test_params[i].cipher_key_len, 8835 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8836 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8837 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8838 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8839 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8840 } 8841 8842 int 8843 test_pdcp_proto_cplane_decap(int i) 8844 { 8845 return test_pdcp_proto( 8846 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8847 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8848 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8849 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8850 pdcp_test_params[i].cipher_key_len, 8851 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8852 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8853 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8854 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8855 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8856 } 8857 8858 int 8859 test_pdcp_proto_uplane_decap(int i) 8860 { 8861 return test_pdcp_proto( 8862 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8863 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 8864 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8865 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8866 pdcp_test_params[i].cipher_key_len, 8867 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8868 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8869 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8870 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8871 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8872 } 8873 8874 int 8875 test_pdcp_proto_uplane_decap_with_int(int i) 8876 { 8877 return test_pdcp_proto( 8878 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8879 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8880 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8881 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8882 pdcp_test_params[i].cipher_key_len, 8883 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8884 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8885 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8886 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8887 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8888 } 8889 8890 static int 8891 test_PDCP_PROTO_SGL_in_place_32B(void) 8892 { 8893 /* i can be used for running any PDCP case 8894 * In this case it is uplane 12-bit AES-SNOW DL encap 8895 */ 8896 int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK; 8897 return test_pdcp_proto_SGL(i, IN_PLACE, 8898 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8899 RTE_CRYPTO_AUTH_OP_GENERATE, 8900 pdcp_test_data_in[i], 8901 pdcp_test_data_in_len[i], 8902 pdcp_test_data_out[i], 8903 pdcp_test_data_in_len[i]+4, 8904 32, 0); 8905 } 8906 static int 8907 test_PDCP_PROTO_SGL_oop_32B_128B(void) 8908 { 8909 /* i can be used for running any PDCP case 8910 * In this case it is uplane 18-bit NULL-NULL DL encap 8911 */ 8912 int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK; 8913 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8914 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8915 RTE_CRYPTO_AUTH_OP_GENERATE, 8916 pdcp_test_data_in[i], 8917 pdcp_test_data_in_len[i], 8918 pdcp_test_data_out[i], 8919 pdcp_test_data_in_len[i]+4, 8920 32, 128); 8921 } 8922 static int 8923 test_PDCP_PROTO_SGL_oop_32B_40B(void) 8924 { 8925 /* i can be used for running any PDCP case 8926 * In this case it is uplane 18-bit AES DL encap 8927 */ 8928 int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET 8929 + DOWNLINK; 8930 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8931 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8932 RTE_CRYPTO_AUTH_OP_GENERATE, 8933 pdcp_test_data_in[i], 8934 pdcp_test_data_in_len[i], 8935 pdcp_test_data_out[i], 8936 pdcp_test_data_in_len[i], 8937 32, 40); 8938 } 8939 static int 8940 test_PDCP_PROTO_SGL_oop_128B_32B(void) 8941 { 8942 /* i can be used for running any PDCP case 8943 * In this case it is cplane 12-bit AES-ZUC DL encap 8944 */ 8945 int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK; 8946 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8947 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8948 RTE_CRYPTO_AUTH_OP_GENERATE, 8949 pdcp_test_data_in[i], 8950 pdcp_test_data_in_len[i], 8951 pdcp_test_data_out[i], 8952 pdcp_test_data_in_len[i]+4, 8953 128, 32); 8954 } 8955 8956 static int 8957 test_PDCP_SDAP_PROTO_encap_all(void) 8958 { 8959 int i = 0, size = 0; 8960 int err, all_err = TEST_SUCCESS; 8961 const struct pdcp_sdap_test *cur_test; 8962 8963 size = RTE_DIM(list_pdcp_sdap_tests); 8964 8965 for (i = 0; i < size; i++) { 8966 cur_test = &list_pdcp_sdap_tests[i]; 8967 err = test_pdcp_proto( 8968 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8969 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 8970 cur_test->in_len, cur_test->data_out, 8971 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 8972 cur_test->param.cipher_alg, cur_test->cipher_key, 8973 cur_test->param.cipher_key_len, 8974 cur_test->param.auth_alg, 8975 cur_test->auth_key, cur_test->param.auth_key_len, 8976 cur_test->bearer, cur_test->param.domain, 8977 cur_test->packet_direction, cur_test->sn_size, 8978 cur_test->hfn, 8979 cur_test->hfn_threshold, SDAP_ENABLED); 8980 if (err) { 8981 printf("\t%d) %s: Encapsulation failed\n", 8982 cur_test->test_idx, 8983 cur_test->param.name); 8984 err = TEST_FAILED; 8985 } else { 8986 printf("\t%d) %s: Encap PASS\n", cur_test->test_idx, 8987 cur_test->param.name); 8988 err = TEST_SUCCESS; 8989 } 8990 all_err += err; 8991 } 8992 8993 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 8994 8995 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 8996 } 8997 8998 static int 8999 test_PDCP_PROTO_short_mac(void) 9000 { 9001 int i = 0, size = 0; 9002 int err, all_err = TEST_SUCCESS; 9003 const struct pdcp_short_mac_test *cur_test; 9004 9005 size = RTE_DIM(list_pdcp_smac_tests); 9006 9007 for (i = 0; i < size; i++) { 9008 cur_test = &list_pdcp_smac_tests[i]; 9009 err = test_pdcp_proto( 9010 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9011 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9012 cur_test->in_len, cur_test->data_out, 9013 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9014 RTE_CRYPTO_CIPHER_NULL, NULL, 9015 0, cur_test->param.auth_alg, 9016 cur_test->auth_key, cur_test->param.auth_key_len, 9017 0, cur_test->param.domain, 0, 0, 9018 0, 0, 0); 9019 if (err) { 9020 printf("\t%d) %s: Short MAC test failed\n", 9021 cur_test->test_idx, 9022 cur_test->param.name); 9023 err = TEST_FAILED; 9024 } else { 9025 printf("\t%d) %s: Short MAC test PASS\n", 9026 cur_test->test_idx, 9027 cur_test->param.name); 9028 rte_hexdump(stdout, "MAC I", 9029 cur_test->data_out + cur_test->in_len + 2, 9030 2); 9031 err = TEST_SUCCESS; 9032 } 9033 all_err += err; 9034 } 9035 9036 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9037 9038 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9039 9040 } 9041 9042 static int 9043 test_PDCP_SDAP_PROTO_decap_all(void) 9044 { 9045 int i = 0, size = 0; 9046 int err, all_err = TEST_SUCCESS; 9047 const struct pdcp_sdap_test *cur_test; 9048 9049 size = RTE_DIM(list_pdcp_sdap_tests); 9050 9051 for (i = 0; i < size; i++) { 9052 cur_test = &list_pdcp_sdap_tests[i]; 9053 err = test_pdcp_proto( 9054 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, 9055 RTE_CRYPTO_AUTH_OP_VERIFY, 9056 cur_test->data_out, 9057 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9058 cur_test->data_in, cur_test->in_len, 9059 cur_test->param.cipher_alg, 9060 cur_test->cipher_key, cur_test->param.cipher_key_len, 9061 cur_test->param.auth_alg, cur_test->auth_key, 9062 cur_test->param.auth_key_len, cur_test->bearer, 9063 cur_test->param.domain, cur_test->packet_direction, 9064 cur_test->sn_size, cur_test->hfn, 9065 cur_test->hfn_threshold, SDAP_ENABLED); 9066 if (err) { 9067 printf("\t%d) %s: Decapsulation failed\n", 9068 cur_test->test_idx, 9069 cur_test->param.name); 9070 err = TEST_FAILED; 9071 } else { 9072 printf("\t%d) %s: Decap PASS\n", cur_test->test_idx, 9073 cur_test->param.name); 9074 err = TEST_SUCCESS; 9075 } 9076 all_err += err; 9077 } 9078 9079 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9080 9081 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9082 } 9083 9084 static int 9085 test_ipsec_proto_process(const struct ipsec_test_data td[], 9086 struct ipsec_test_data res_d[], 9087 int nb_td, 9088 bool silent, 9089 const struct ipsec_test_flags *flags) 9090 { 9091 struct crypto_testsuite_params *ts_params = &testsuite_params; 9092 struct crypto_unittest_params *ut_params = &unittest_params; 9093 struct rte_security_capability_idx sec_cap_idx; 9094 const struct rte_security_capability *sec_cap; 9095 struct rte_security_ipsec_xform ipsec_xform; 9096 uint8_t dev_id = ts_params->valid_devs[0]; 9097 enum rte_security_ipsec_sa_direction dir; 9098 struct ipsec_test_data *res_d_tmp = NULL; 9099 uint32_t src = RTE_IPV4(192, 168, 1, 0); 9100 uint32_t dst = RTE_IPV4(192, 168, 1, 1); 9101 int salt_len, i, ret = TEST_SUCCESS; 9102 struct rte_security_ctx *ctx; 9103 uint8_t *input_text; 9104 uint32_t verify; 9105 9106 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 9107 gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 9108 9109 /* Use first test data to create session */ 9110 9111 /* Copy IPsec xform */ 9112 memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform)); 9113 9114 dir = ipsec_xform.direction; 9115 verify = flags->tunnel_hdr_verify; 9116 9117 if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) { 9118 if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR) 9119 src += 1; 9120 else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR) 9121 dst += 1; 9122 } 9123 9124 memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, sizeof(src)); 9125 memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, sizeof(dst)); 9126 9127 ctx = rte_cryptodev_get_sec_ctx(dev_id); 9128 9129 sec_cap_idx.action = ut_params->type; 9130 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC; 9131 sec_cap_idx.ipsec.proto = ipsec_xform.proto; 9132 sec_cap_idx.ipsec.mode = ipsec_xform.mode; 9133 sec_cap_idx.ipsec.direction = ipsec_xform.direction; 9134 9135 if (flags->udp_encap) 9136 ipsec_xform.options.udp_encap = 1; 9137 9138 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 9139 if (sec_cap == NULL) 9140 return TEST_SKIPPED; 9141 9142 /* Copy cipher session parameters */ 9143 if (td[0].aead) { 9144 memcpy(&ut_params->aead_xform, &td[0].xform.aead, 9145 sizeof(ut_params->aead_xform)); 9146 ut_params->aead_xform.aead.key.data = td[0].key.data; 9147 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 9148 9149 /* Verify crypto capabilities */ 9150 if (test_ipsec_crypto_caps_aead_verify( 9151 sec_cap, 9152 &ut_params->aead_xform) != 0) { 9153 if (!silent) 9154 RTE_LOG(INFO, USER1, 9155 "Crypto capabilities not supported\n"); 9156 return TEST_SKIPPED; 9157 } 9158 } else { 9159 /* Only AEAD supported now */ 9160 return TEST_SKIPPED; 9161 } 9162 9163 if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0) 9164 return TEST_SKIPPED; 9165 9166 salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len); 9167 memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len); 9168 9169 struct rte_security_session_conf sess_conf = { 9170 .action_type = ut_params->type, 9171 .protocol = RTE_SECURITY_PROTOCOL_IPSEC, 9172 .ipsec = ipsec_xform, 9173 .crypto_xform = &ut_params->aead_xform, 9174 }; 9175 9176 /* Create security session */ 9177 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 9178 ts_params->session_mpool, 9179 ts_params->session_priv_mpool); 9180 9181 if (ut_params->sec_session == NULL) 9182 return TEST_SKIPPED; 9183 9184 for (i = 0; i < nb_td; i++) { 9185 /* Setup source mbuf payload */ 9186 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9187 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9188 rte_pktmbuf_tailroom(ut_params->ibuf)); 9189 9190 input_text = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9191 td[i].input_text.len); 9192 9193 memcpy(input_text, td[i].input_text.data, 9194 td[i].input_text.len); 9195 9196 /* Generate crypto op data structure */ 9197 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9198 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9199 if (!ut_params->op) { 9200 printf("TestCase %s line %d: %s\n", 9201 __func__, __LINE__, 9202 "failed to allocate crypto op"); 9203 ret = TEST_FAILED; 9204 goto crypto_op_free; 9205 } 9206 9207 /* Attach session to operation */ 9208 rte_security_attach_session(ut_params->op, 9209 ut_params->sec_session); 9210 9211 /* Set crypto operation mbufs */ 9212 ut_params->op->sym->m_src = ut_params->ibuf; 9213 ut_params->op->sym->m_dst = NULL; 9214 9215 /* Copy IV in crypto operation when IV generation is disabled */ 9216 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS && 9217 ipsec_xform.options.iv_gen_disable == 1) { 9218 uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op, 9219 uint8_t *, 9220 IV_OFFSET); 9221 int len; 9222 9223 if (td[i].aead) 9224 len = td[i].xform.aead.aead.iv.length; 9225 else 9226 len = td[i].xform.chain.cipher.cipher.iv.length; 9227 9228 memcpy(iv, td[i].iv.data, len); 9229 } 9230 9231 /* Process crypto operation */ 9232 process_crypto_request(dev_id, ut_params->op); 9233 9234 ret = test_ipsec_status_check(ut_params->op, flags, dir, i + 1); 9235 if (ret != TEST_SUCCESS) 9236 goto crypto_op_free; 9237 9238 if (res_d != NULL) 9239 res_d_tmp = &res_d[i]; 9240 9241 ret = test_ipsec_post_process(ut_params->ibuf, &td[i], 9242 res_d_tmp, silent, flags); 9243 if (ret != TEST_SUCCESS) 9244 goto crypto_op_free; 9245 9246 rte_crypto_op_free(ut_params->op); 9247 ut_params->op = NULL; 9248 9249 rte_pktmbuf_free(ut_params->ibuf); 9250 ut_params->ibuf = NULL; 9251 } 9252 9253 crypto_op_free: 9254 rte_crypto_op_free(ut_params->op); 9255 ut_params->op = NULL; 9256 9257 rte_pktmbuf_free(ut_params->ibuf); 9258 ut_params->ibuf = NULL; 9259 9260 if (ut_params->sec_session) 9261 rte_security_session_destroy(ctx, ut_params->sec_session); 9262 ut_params->sec_session = NULL; 9263 9264 return ret; 9265 } 9266 9267 static int 9268 test_ipsec_proto_known_vec(const void *test_data) 9269 { 9270 struct ipsec_test_data td_outb; 9271 struct ipsec_test_flags flags; 9272 9273 memset(&flags, 0, sizeof(flags)); 9274 9275 memcpy(&td_outb, test_data, sizeof(td_outb)); 9276 9277 /* Disable IV gen to be able to test with known vectors */ 9278 td_outb.ipsec_xform.options.iv_gen_disable = 1; 9279 9280 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 9281 } 9282 9283 static int 9284 test_ipsec_proto_known_vec_inb(const void *td_outb) 9285 { 9286 struct ipsec_test_flags flags; 9287 struct ipsec_test_data td_inb; 9288 9289 memset(&flags, 0, sizeof(flags)); 9290 9291 test_ipsec_td_in_from_out(td_outb, &td_inb); 9292 9293 return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags); 9294 } 9295 9296 static int 9297 test_ipsec_proto_all(const struct ipsec_test_flags *flags) 9298 { 9299 struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX]; 9300 struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX]; 9301 unsigned int i, nb_pkts = 1, pass_cnt = 0; 9302 int ret; 9303 9304 if (flags->iv_gen || 9305 flags->sa_expiry_pkts_soft || 9306 flags->sa_expiry_pkts_hard) 9307 nb_pkts = IPSEC_TEST_PACKETS_MAX; 9308 9309 for (i = 0; i < RTE_DIM(aead_list); i++) { 9310 test_ipsec_td_prepare(&aead_list[i], 9311 NULL, 9312 flags, 9313 td_outb, 9314 nb_pkts); 9315 9316 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 9317 flags); 9318 if (ret == TEST_SKIPPED) 9319 continue; 9320 9321 if (ret == TEST_FAILED) 9322 return TEST_FAILED; 9323 9324 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags); 9325 9326 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 9327 flags); 9328 if (ret == TEST_SKIPPED) 9329 continue; 9330 9331 if (ret == TEST_FAILED) 9332 return TEST_FAILED; 9333 9334 if (flags->display_alg) 9335 test_ipsec_display_alg(&aead_list[i], NULL); 9336 9337 pass_cnt++; 9338 } 9339 9340 if (pass_cnt > 0) 9341 return TEST_SUCCESS; 9342 else 9343 return TEST_SKIPPED; 9344 } 9345 9346 static int 9347 test_ipsec_proto_display_list(const void *data __rte_unused) 9348 { 9349 struct ipsec_test_flags flags; 9350 9351 memset(&flags, 0, sizeof(flags)); 9352 9353 flags.display_alg = true; 9354 9355 return test_ipsec_proto_all(&flags); 9356 } 9357 9358 static int 9359 test_ipsec_proto_iv_gen(const void *data __rte_unused) 9360 { 9361 struct ipsec_test_flags flags; 9362 9363 memset(&flags, 0, sizeof(flags)); 9364 9365 flags.iv_gen = true; 9366 9367 return test_ipsec_proto_all(&flags); 9368 } 9369 9370 static int 9371 test_ipsec_proto_sa_exp_pkts_soft(const void *data __rte_unused) 9372 { 9373 struct ipsec_test_flags flags; 9374 9375 memset(&flags, 0, sizeof(flags)); 9376 9377 flags.sa_expiry_pkts_soft = true; 9378 9379 return test_ipsec_proto_all(&flags); 9380 } 9381 9382 static int 9383 test_ipsec_proto_sa_exp_pkts_hard(const void *data __rte_unused) 9384 { 9385 struct ipsec_test_flags flags; 9386 9387 memset(&flags, 0, sizeof(flags)); 9388 9389 flags.sa_expiry_pkts_hard = true; 9390 9391 return test_ipsec_proto_all(&flags); 9392 } 9393 9394 static int 9395 test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused) 9396 { 9397 struct ipsec_test_flags flags; 9398 9399 memset(&flags, 0, sizeof(flags)); 9400 9401 flags.icv_corrupt = true; 9402 9403 return test_ipsec_proto_all(&flags); 9404 } 9405 9406 static int 9407 test_ipsec_proto_udp_encap(const void *data __rte_unused) 9408 { 9409 struct ipsec_test_flags flags; 9410 9411 memset(&flags, 0, sizeof(flags)); 9412 9413 flags.udp_encap = true; 9414 9415 return test_ipsec_proto_all(&flags); 9416 } 9417 9418 static int 9419 test_ipsec_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused) 9420 { 9421 struct ipsec_test_flags flags; 9422 9423 memset(&flags, 0, sizeof(flags)); 9424 9425 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR; 9426 9427 return test_ipsec_proto_all(&flags); 9428 } 9429 9430 static int 9431 test_ipsec_proto_tunnel_dst_addr_verify(const void *data __rte_unused) 9432 { 9433 struct ipsec_test_flags flags; 9434 9435 memset(&flags, 0, sizeof(flags)); 9436 9437 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR; 9438 9439 return test_ipsec_proto_all(&flags); 9440 } 9441 9442 static int 9443 test_ipsec_proto_udp_ports_verify(const void *data __rte_unused) 9444 { 9445 struct ipsec_test_flags flags; 9446 9447 memset(&flags, 0, sizeof(flags)); 9448 9449 flags.udp_encap = true; 9450 flags.udp_ports_verify = true; 9451 9452 return test_ipsec_proto_all(&flags); 9453 } 9454 9455 static int 9456 test_ipsec_proto_inner_ip_csum(const void *data __rte_unused) 9457 { 9458 struct ipsec_test_flags flags; 9459 9460 memset(&flags, 0, sizeof(flags)); 9461 9462 flags.ip_csum = true; 9463 9464 return test_ipsec_proto_all(&flags); 9465 } 9466 9467 static int 9468 test_ipsec_proto_inner_l4_csum(const void *data __rte_unused) 9469 { 9470 struct ipsec_test_flags flags; 9471 9472 memset(&flags, 0, sizeof(flags)); 9473 9474 flags.l4_csum = true; 9475 9476 return test_ipsec_proto_all(&flags); 9477 } 9478 9479 static int 9480 test_PDCP_PROTO_all(void) 9481 { 9482 struct crypto_testsuite_params *ts_params = &testsuite_params; 9483 struct crypto_unittest_params *ut_params = &unittest_params; 9484 struct rte_cryptodev_info dev_info; 9485 int status; 9486 9487 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9488 uint64_t feat_flags = dev_info.feature_flags; 9489 9490 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 9491 return TEST_SKIPPED; 9492 9493 /* Set action type */ 9494 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 9495 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 9496 gbl_action_type; 9497 9498 if (security_proto_supported(ut_params->type, 9499 RTE_SECURITY_PROTOCOL_PDCP) < 0) 9500 return TEST_SKIPPED; 9501 9502 status = test_PDCP_PROTO_cplane_encap_all(); 9503 status += test_PDCP_PROTO_cplane_decap_all(); 9504 status += test_PDCP_PROTO_uplane_encap_all(); 9505 status += test_PDCP_PROTO_uplane_decap_all(); 9506 status += test_PDCP_PROTO_SGL_in_place_32B(); 9507 status += test_PDCP_PROTO_SGL_oop_32B_128B(); 9508 status += test_PDCP_PROTO_SGL_oop_32B_40B(); 9509 status += test_PDCP_PROTO_SGL_oop_128B_32B(); 9510 status += test_PDCP_SDAP_PROTO_encap_all(); 9511 status += test_PDCP_SDAP_PROTO_decap_all(); 9512 status += test_PDCP_PROTO_short_mac(); 9513 9514 if (status) 9515 return TEST_FAILED; 9516 else 9517 return TEST_SUCCESS; 9518 } 9519 9520 static int 9521 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td) 9522 { 9523 struct crypto_testsuite_params *ts_params = &testsuite_params; 9524 struct crypto_unittest_params *ut_params = &unittest_params; 9525 uint8_t *plaintext, *ciphertext; 9526 uint8_t *iv_ptr; 9527 int32_t cipher_len, crc_len; 9528 uint32_t crc_data_len; 9529 int ret = TEST_SUCCESS; 9530 9531 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 9532 rte_cryptodev_get_sec_ctx( 9533 ts_params->valid_devs[0]); 9534 9535 /* Verify the capabilities */ 9536 struct rte_security_capability_idx sec_cap_idx; 9537 const struct rte_security_capability *sec_cap; 9538 const struct rte_cryptodev_capabilities *crypto_cap; 9539 const struct rte_cryptodev_symmetric_capability *sym_cap; 9540 int j = 0; 9541 9542 sec_cap_idx.action = ut_params->type; 9543 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 9544 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK; 9545 9546 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 9547 if (sec_cap == NULL) 9548 return TEST_SKIPPED; 9549 9550 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 9551 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 9552 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 9553 crypto_cap->sym.xform_type == 9554 RTE_CRYPTO_SYM_XFORM_CIPHER && 9555 crypto_cap->sym.cipher.algo == 9556 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 9557 sym_cap = &crypto_cap->sym; 9558 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 9559 d_td->key.len, 9560 d_td->iv.len) == 0) 9561 break; 9562 } 9563 } 9564 9565 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 9566 return TEST_SKIPPED; 9567 9568 /* Setup source mbuf payload */ 9569 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9570 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9571 rte_pktmbuf_tailroom(ut_params->ibuf)); 9572 9573 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9574 d_td->ciphertext.len); 9575 9576 memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len); 9577 9578 /* Setup cipher session parameters */ 9579 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9580 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 9581 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 9582 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 9583 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 9584 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 9585 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 9586 ut_params->cipher_xform.next = NULL; 9587 9588 /* Setup DOCSIS session parameters */ 9589 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK; 9590 9591 struct rte_security_session_conf sess_conf = { 9592 .action_type = ut_params->type, 9593 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 9594 .docsis = ut_params->docsis_xform, 9595 .crypto_xform = &ut_params->cipher_xform, 9596 }; 9597 9598 /* Create security session */ 9599 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 9600 ts_params->session_mpool, 9601 ts_params->session_priv_mpool); 9602 9603 if (!ut_params->sec_session) { 9604 printf("TestCase %s(%d) line %d: %s\n", 9605 __func__, i, __LINE__, "failed to allocate session"); 9606 ret = TEST_FAILED; 9607 goto on_err; 9608 } 9609 9610 /* Generate crypto op data structure */ 9611 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9612 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9613 if (!ut_params->op) { 9614 printf("TestCase %s(%d) line %d: %s\n", 9615 __func__, i, __LINE__, 9616 "failed to allocate symmetric crypto operation"); 9617 ret = TEST_FAILED; 9618 goto on_err; 9619 } 9620 9621 /* Setup CRC operation parameters */ 9622 crc_len = d_td->ciphertext.no_crc == false ? 9623 (d_td->ciphertext.len - 9624 d_td->ciphertext.crc_offset - 9625 RTE_ETHER_CRC_LEN) : 9626 0; 9627 crc_len = crc_len > 0 ? crc_len : 0; 9628 crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN; 9629 ut_params->op->sym->auth.data.length = crc_len; 9630 ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset; 9631 9632 /* Setup cipher operation parameters */ 9633 cipher_len = d_td->ciphertext.no_cipher == false ? 9634 (d_td->ciphertext.len - 9635 d_td->ciphertext.cipher_offset) : 9636 0; 9637 cipher_len = cipher_len > 0 ? cipher_len : 0; 9638 ut_params->op->sym->cipher.data.length = cipher_len; 9639 ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset; 9640 9641 /* Setup cipher IV */ 9642 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 9643 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 9644 9645 /* Attach session to operation */ 9646 rte_security_attach_session(ut_params->op, ut_params->sec_session); 9647 9648 /* Set crypto operation mbufs */ 9649 ut_params->op->sym->m_src = ut_params->ibuf; 9650 ut_params->op->sym->m_dst = NULL; 9651 9652 /* Process crypto operation */ 9653 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 9654 NULL) { 9655 printf("TestCase %s(%d) line %d: %s\n", 9656 __func__, i, __LINE__, 9657 "failed to process security crypto op"); 9658 ret = TEST_FAILED; 9659 goto on_err; 9660 } 9661 9662 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 9663 printf("TestCase %s(%d) line %d: %s\n", 9664 __func__, i, __LINE__, "crypto op processing failed"); 9665 ret = TEST_FAILED; 9666 goto on_err; 9667 } 9668 9669 /* Validate plaintext */ 9670 plaintext = ciphertext; 9671 9672 if (memcmp(plaintext, d_td->plaintext.data, 9673 d_td->plaintext.len - crc_data_len)) { 9674 printf("TestCase %s(%d) line %d: %s\n", 9675 __func__, i, __LINE__, "plaintext not as expected\n"); 9676 rte_hexdump(stdout, "expected", d_td->plaintext.data, 9677 d_td->plaintext.len); 9678 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len); 9679 ret = TEST_FAILED; 9680 goto on_err; 9681 } 9682 9683 on_err: 9684 rte_crypto_op_free(ut_params->op); 9685 ut_params->op = NULL; 9686 9687 if (ut_params->sec_session) 9688 rte_security_session_destroy(ctx, ut_params->sec_session); 9689 ut_params->sec_session = NULL; 9690 9691 rte_pktmbuf_free(ut_params->ibuf); 9692 ut_params->ibuf = NULL; 9693 9694 return ret; 9695 } 9696 9697 static int 9698 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td) 9699 { 9700 struct crypto_testsuite_params *ts_params = &testsuite_params; 9701 struct crypto_unittest_params *ut_params = &unittest_params; 9702 uint8_t *plaintext, *ciphertext; 9703 uint8_t *iv_ptr; 9704 int32_t cipher_len, crc_len; 9705 int ret = TEST_SUCCESS; 9706 9707 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 9708 rte_cryptodev_get_sec_ctx( 9709 ts_params->valid_devs[0]); 9710 9711 /* Verify the capabilities */ 9712 struct rte_security_capability_idx sec_cap_idx; 9713 const struct rte_security_capability *sec_cap; 9714 const struct rte_cryptodev_capabilities *crypto_cap; 9715 const struct rte_cryptodev_symmetric_capability *sym_cap; 9716 int j = 0; 9717 9718 sec_cap_idx.action = ut_params->type; 9719 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 9720 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 9721 9722 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 9723 if (sec_cap == NULL) 9724 return TEST_SKIPPED; 9725 9726 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 9727 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 9728 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 9729 crypto_cap->sym.xform_type == 9730 RTE_CRYPTO_SYM_XFORM_CIPHER && 9731 crypto_cap->sym.cipher.algo == 9732 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 9733 sym_cap = &crypto_cap->sym; 9734 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 9735 d_td->key.len, 9736 d_td->iv.len) == 0) 9737 break; 9738 } 9739 } 9740 9741 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 9742 return TEST_SKIPPED; 9743 9744 /* Setup source mbuf payload */ 9745 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9746 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9747 rte_pktmbuf_tailroom(ut_params->ibuf)); 9748 9749 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9750 d_td->plaintext.len); 9751 9752 memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len); 9753 9754 /* Setup cipher session parameters */ 9755 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9756 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 9757 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 9758 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 9759 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 9760 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 9761 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 9762 ut_params->cipher_xform.next = NULL; 9763 9764 /* Setup DOCSIS session parameters */ 9765 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 9766 9767 struct rte_security_session_conf sess_conf = { 9768 .action_type = ut_params->type, 9769 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 9770 .docsis = ut_params->docsis_xform, 9771 .crypto_xform = &ut_params->cipher_xform, 9772 }; 9773 9774 /* Create security session */ 9775 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 9776 ts_params->session_mpool, 9777 ts_params->session_priv_mpool); 9778 9779 if (!ut_params->sec_session) { 9780 printf("TestCase %s(%d) line %d: %s\n", 9781 __func__, i, __LINE__, "failed to allocate session"); 9782 ret = TEST_FAILED; 9783 goto on_err; 9784 } 9785 9786 /* Generate crypto op data structure */ 9787 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9788 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9789 if (!ut_params->op) { 9790 printf("TestCase %s(%d) line %d: %s\n", 9791 __func__, i, __LINE__, 9792 "failed to allocate security crypto operation"); 9793 ret = TEST_FAILED; 9794 goto on_err; 9795 } 9796 9797 /* Setup CRC operation parameters */ 9798 crc_len = d_td->plaintext.no_crc == false ? 9799 (d_td->plaintext.len - 9800 d_td->plaintext.crc_offset - 9801 RTE_ETHER_CRC_LEN) : 9802 0; 9803 crc_len = crc_len > 0 ? crc_len : 0; 9804 ut_params->op->sym->auth.data.length = crc_len; 9805 ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset; 9806 9807 /* Setup cipher operation parameters */ 9808 cipher_len = d_td->plaintext.no_cipher == false ? 9809 (d_td->plaintext.len - 9810 d_td->plaintext.cipher_offset) : 9811 0; 9812 cipher_len = cipher_len > 0 ? cipher_len : 0; 9813 ut_params->op->sym->cipher.data.length = cipher_len; 9814 ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset; 9815 9816 /* Setup cipher IV */ 9817 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 9818 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 9819 9820 /* Attach session to operation */ 9821 rte_security_attach_session(ut_params->op, ut_params->sec_session); 9822 9823 /* Set crypto operation mbufs */ 9824 ut_params->op->sym->m_src = ut_params->ibuf; 9825 ut_params->op->sym->m_dst = NULL; 9826 9827 /* Process crypto operation */ 9828 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 9829 NULL) { 9830 printf("TestCase %s(%d) line %d: %s\n", 9831 __func__, i, __LINE__, 9832 "failed to process security crypto op"); 9833 ret = TEST_FAILED; 9834 goto on_err; 9835 } 9836 9837 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 9838 printf("TestCase %s(%d) line %d: %s\n", 9839 __func__, i, __LINE__, "crypto op processing failed"); 9840 ret = TEST_FAILED; 9841 goto on_err; 9842 } 9843 9844 /* Validate ciphertext */ 9845 ciphertext = plaintext; 9846 9847 if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) { 9848 printf("TestCase %s(%d) line %d: %s\n", 9849 __func__, i, __LINE__, "ciphertext not as expected\n"); 9850 rte_hexdump(stdout, "expected", d_td->ciphertext.data, 9851 d_td->ciphertext.len); 9852 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len); 9853 ret = TEST_FAILED; 9854 goto on_err; 9855 } 9856 9857 on_err: 9858 rte_crypto_op_free(ut_params->op); 9859 ut_params->op = NULL; 9860 9861 if (ut_params->sec_session) 9862 rte_security_session_destroy(ctx, ut_params->sec_session); 9863 ut_params->sec_session = NULL; 9864 9865 rte_pktmbuf_free(ut_params->ibuf); 9866 ut_params->ibuf = NULL; 9867 9868 return ret; 9869 } 9870 9871 #define TEST_DOCSIS_COUNT(func) do { \ 9872 int ret = func; \ 9873 if (ret == TEST_SUCCESS) { \ 9874 printf("\t%2d)", n++); \ 9875 printf("+++++ PASSED:" #func"\n"); \ 9876 p++; \ 9877 } else if (ret == TEST_SKIPPED) { \ 9878 printf("\t%2d)", n++); \ 9879 printf("~~~~~ SKIPPED:" #func"\n"); \ 9880 s++; \ 9881 } else { \ 9882 printf("\t%2d)", n++); \ 9883 printf("----- FAILED:" #func"\n"); \ 9884 f++; \ 9885 } \ 9886 } while (0) 9887 9888 static int 9889 test_DOCSIS_PROTO_uplink_all(void) 9890 { 9891 int p = 0, s = 0, f = 0, n = 0; 9892 9893 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1)); 9894 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2)); 9895 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3)); 9896 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4)); 9897 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5)); 9898 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6)); 9899 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7)); 9900 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8)); 9901 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9)); 9902 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10)); 9903 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11)); 9904 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12)); 9905 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13)); 9906 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14)); 9907 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15)); 9908 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16)); 9909 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17)); 9910 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18)); 9911 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19)); 9912 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20)); 9913 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21)); 9914 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22)); 9915 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23)); 9916 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24)); 9917 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25)); 9918 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26)); 9919 9920 if (f) 9921 printf("## %s: %d passed out of %d (%d skipped)\n", 9922 __func__, p, n, s); 9923 9924 return f; 9925 }; 9926 9927 static int 9928 test_DOCSIS_PROTO_downlink_all(void) 9929 { 9930 int p = 0, s = 0, f = 0, n = 0; 9931 9932 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1)); 9933 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2)); 9934 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3)); 9935 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4)); 9936 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5)); 9937 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6)); 9938 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7)); 9939 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8)); 9940 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9)); 9941 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10)); 9942 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11)); 9943 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12)); 9944 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13)); 9945 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14)); 9946 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15)); 9947 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16)); 9948 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17)); 9949 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18)); 9950 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19)); 9951 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20)); 9952 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21)); 9953 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22)); 9954 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23)); 9955 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24)); 9956 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25)); 9957 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26)); 9958 9959 if (f) 9960 printf("## %s: %d passed out of %d (%d skipped)\n", 9961 __func__, p, n, s); 9962 9963 return f; 9964 }; 9965 9966 static int 9967 test_DOCSIS_PROTO_all(void) 9968 { 9969 struct crypto_testsuite_params *ts_params = &testsuite_params; 9970 struct crypto_unittest_params *ut_params = &unittest_params; 9971 struct rte_cryptodev_info dev_info; 9972 int status; 9973 9974 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9975 uint64_t feat_flags = dev_info.feature_flags; 9976 9977 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 9978 return TEST_SKIPPED; 9979 9980 /* Set action type */ 9981 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 9982 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 9983 gbl_action_type; 9984 9985 if (security_proto_supported(ut_params->type, 9986 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 9987 return TEST_SKIPPED; 9988 9989 status = test_DOCSIS_PROTO_uplink_all(); 9990 status += test_DOCSIS_PROTO_downlink_all(); 9991 9992 if (status) 9993 return TEST_FAILED; 9994 else 9995 return TEST_SUCCESS; 9996 } 9997 #endif 9998 9999 static int 10000 test_AES_GCM_authenticated_encryption_test_case_1(void) 10001 { 10002 return test_authenticated_encryption(&gcm_test_case_1); 10003 } 10004 10005 static int 10006 test_AES_GCM_authenticated_encryption_test_case_2(void) 10007 { 10008 return test_authenticated_encryption(&gcm_test_case_2); 10009 } 10010 10011 static int 10012 test_AES_GCM_authenticated_encryption_test_case_3(void) 10013 { 10014 return test_authenticated_encryption(&gcm_test_case_3); 10015 } 10016 10017 static int 10018 test_AES_GCM_authenticated_encryption_test_case_4(void) 10019 { 10020 return test_authenticated_encryption(&gcm_test_case_4); 10021 } 10022 10023 static int 10024 test_AES_GCM_authenticated_encryption_test_case_5(void) 10025 { 10026 return test_authenticated_encryption(&gcm_test_case_5); 10027 } 10028 10029 static int 10030 test_AES_GCM_authenticated_encryption_test_case_6(void) 10031 { 10032 return test_authenticated_encryption(&gcm_test_case_6); 10033 } 10034 10035 static int 10036 test_AES_GCM_authenticated_encryption_test_case_7(void) 10037 { 10038 return test_authenticated_encryption(&gcm_test_case_7); 10039 } 10040 10041 static int 10042 test_AES_GCM_authenticated_encryption_test_case_8(void) 10043 { 10044 return test_authenticated_encryption(&gcm_test_case_8); 10045 } 10046 10047 static int 10048 test_AES_GCM_J0_authenticated_encryption_test_case_1(void) 10049 { 10050 return test_authenticated_encryption(&gcm_J0_test_case_1); 10051 } 10052 10053 static int 10054 test_AES_GCM_auth_encryption_test_case_192_1(void) 10055 { 10056 return test_authenticated_encryption(&gcm_test_case_192_1); 10057 } 10058 10059 static int 10060 test_AES_GCM_auth_encryption_test_case_192_2(void) 10061 { 10062 return test_authenticated_encryption(&gcm_test_case_192_2); 10063 } 10064 10065 static int 10066 test_AES_GCM_auth_encryption_test_case_192_3(void) 10067 { 10068 return test_authenticated_encryption(&gcm_test_case_192_3); 10069 } 10070 10071 static int 10072 test_AES_GCM_auth_encryption_test_case_192_4(void) 10073 { 10074 return test_authenticated_encryption(&gcm_test_case_192_4); 10075 } 10076 10077 static int 10078 test_AES_GCM_auth_encryption_test_case_192_5(void) 10079 { 10080 return test_authenticated_encryption(&gcm_test_case_192_5); 10081 } 10082 10083 static int 10084 test_AES_GCM_auth_encryption_test_case_192_6(void) 10085 { 10086 return test_authenticated_encryption(&gcm_test_case_192_6); 10087 } 10088 10089 static int 10090 test_AES_GCM_auth_encryption_test_case_192_7(void) 10091 { 10092 return test_authenticated_encryption(&gcm_test_case_192_7); 10093 } 10094 10095 static int 10096 test_AES_GCM_auth_encryption_test_case_256_1(void) 10097 { 10098 return test_authenticated_encryption(&gcm_test_case_256_1); 10099 } 10100 10101 static int 10102 test_AES_GCM_auth_encryption_test_case_256_2(void) 10103 { 10104 return test_authenticated_encryption(&gcm_test_case_256_2); 10105 } 10106 10107 static int 10108 test_AES_GCM_auth_encryption_test_case_256_3(void) 10109 { 10110 return test_authenticated_encryption(&gcm_test_case_256_3); 10111 } 10112 10113 static int 10114 test_AES_GCM_auth_encryption_test_case_256_4(void) 10115 { 10116 return test_authenticated_encryption(&gcm_test_case_256_4); 10117 } 10118 10119 static int 10120 test_AES_GCM_auth_encryption_test_case_256_5(void) 10121 { 10122 return test_authenticated_encryption(&gcm_test_case_256_5); 10123 } 10124 10125 static int 10126 test_AES_GCM_auth_encryption_test_case_256_6(void) 10127 { 10128 return test_authenticated_encryption(&gcm_test_case_256_6); 10129 } 10130 10131 static int 10132 test_AES_GCM_auth_encryption_test_case_256_7(void) 10133 { 10134 return test_authenticated_encryption(&gcm_test_case_256_7); 10135 } 10136 10137 static int 10138 test_AES_GCM_auth_encryption_test_case_aad_1(void) 10139 { 10140 return test_authenticated_encryption(&gcm_test_case_aad_1); 10141 } 10142 10143 static int 10144 test_AES_GCM_auth_encryption_test_case_aad_2(void) 10145 { 10146 return test_authenticated_encryption(&gcm_test_case_aad_2); 10147 } 10148 10149 static int 10150 test_AES_GCM_auth_encryption_fail_iv_corrupt(void) 10151 { 10152 struct aead_test_data tdata; 10153 int res; 10154 10155 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10156 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10157 tdata.iv.data[0] += 1; 10158 res = test_authenticated_encryption(&tdata); 10159 if (res == TEST_SKIPPED) 10160 return res; 10161 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10162 return TEST_SUCCESS; 10163 } 10164 10165 static int 10166 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void) 10167 { 10168 struct aead_test_data tdata; 10169 int res; 10170 10171 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10172 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10173 tdata.plaintext.data[0] += 1; 10174 res = test_authenticated_encryption(&tdata); 10175 if (res == TEST_SKIPPED) 10176 return res; 10177 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10178 return TEST_SUCCESS; 10179 } 10180 10181 static int 10182 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void) 10183 { 10184 struct aead_test_data tdata; 10185 int res; 10186 10187 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10188 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10189 tdata.ciphertext.data[0] += 1; 10190 res = test_authenticated_encryption(&tdata); 10191 if (res == TEST_SKIPPED) 10192 return res; 10193 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10194 return TEST_SUCCESS; 10195 } 10196 10197 static int 10198 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void) 10199 { 10200 struct aead_test_data tdata; 10201 int res; 10202 10203 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10204 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10205 tdata.aad.len += 1; 10206 res = test_authenticated_encryption(&tdata); 10207 if (res == TEST_SKIPPED) 10208 return res; 10209 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10210 return TEST_SUCCESS; 10211 } 10212 10213 static int 10214 test_AES_GCM_auth_encryption_fail_aad_corrupt(void) 10215 { 10216 struct aead_test_data tdata; 10217 uint8_t aad[gcm_test_case_7.aad.len]; 10218 int res; 10219 10220 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10221 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10222 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 10223 aad[0] += 1; 10224 tdata.aad.data = aad; 10225 res = test_authenticated_encryption(&tdata); 10226 if (res == TEST_SKIPPED) 10227 return res; 10228 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10229 return TEST_SUCCESS; 10230 } 10231 10232 static int 10233 test_AES_GCM_auth_encryption_fail_tag_corrupt(void) 10234 { 10235 struct aead_test_data tdata; 10236 int res; 10237 10238 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10239 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10240 tdata.auth_tag.data[0] += 1; 10241 res = test_authenticated_encryption(&tdata); 10242 if (res == TEST_SKIPPED) 10243 return res; 10244 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10245 return TEST_SUCCESS; 10246 } 10247 10248 static int 10249 test_authenticated_decryption(const struct aead_test_data *tdata) 10250 { 10251 struct crypto_testsuite_params *ts_params = &testsuite_params; 10252 struct crypto_unittest_params *ut_params = &unittest_params; 10253 10254 int retval; 10255 uint8_t *plaintext; 10256 uint32_t i; 10257 struct rte_cryptodev_info dev_info; 10258 10259 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10260 uint64_t feat_flags = dev_info.feature_flags; 10261 10262 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10263 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10264 printf("Device doesn't support RAW data-path APIs.\n"); 10265 return TEST_SKIPPED; 10266 } 10267 10268 /* Verify the capabilities */ 10269 struct rte_cryptodev_sym_capability_idx cap_idx; 10270 const struct rte_cryptodev_symmetric_capability *capability; 10271 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10272 cap_idx.algo.aead = tdata->algo; 10273 capability = rte_cryptodev_sym_capability_get( 10274 ts_params->valid_devs[0], &cap_idx); 10275 if (capability == NULL) 10276 return TEST_SKIPPED; 10277 if (rte_cryptodev_sym_capability_check_aead( 10278 capability, tdata->key.len, tdata->auth_tag.len, 10279 tdata->aad.len, tdata->iv.len)) 10280 return TEST_SKIPPED; 10281 10282 /* Create AEAD session */ 10283 retval = create_aead_session(ts_params->valid_devs[0], 10284 tdata->algo, 10285 RTE_CRYPTO_AEAD_OP_DECRYPT, 10286 tdata->key.data, tdata->key.len, 10287 tdata->aad.len, tdata->auth_tag.len, 10288 tdata->iv.len); 10289 if (retval < 0) 10290 return retval; 10291 10292 /* alloc mbuf and set payload */ 10293 if (tdata->aad.len > MBUF_SIZE) { 10294 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 10295 /* Populate full size of add data */ 10296 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 10297 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 10298 } else 10299 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10300 10301 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10302 rte_pktmbuf_tailroom(ut_params->ibuf)); 10303 10304 /* Create AEAD operation */ 10305 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 10306 if (retval < 0) 10307 return retval; 10308 10309 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10310 10311 ut_params->op->sym->m_src = ut_params->ibuf; 10312 10313 /* Process crypto operation */ 10314 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10315 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 10316 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10317 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10318 ut_params->op, 0, 0, 0, 0); 10319 else 10320 TEST_ASSERT_NOT_NULL( 10321 process_crypto_request(ts_params->valid_devs[0], 10322 ut_params->op), "failed to process sym crypto op"); 10323 10324 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10325 "crypto op processing failed"); 10326 10327 if (ut_params->op->sym->m_dst) 10328 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 10329 uint8_t *); 10330 else 10331 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 10332 uint8_t *, 10333 ut_params->op->sym->cipher.data.offset); 10334 10335 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 10336 10337 /* Validate obuf */ 10338 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10339 plaintext, 10340 tdata->plaintext.data, 10341 tdata->plaintext.len, 10342 "Plaintext data not as expected"); 10343 10344 TEST_ASSERT_EQUAL(ut_params->op->status, 10345 RTE_CRYPTO_OP_STATUS_SUCCESS, 10346 "Authentication failed"); 10347 10348 return 0; 10349 } 10350 10351 static int 10352 test_AES_GCM_authenticated_decryption_test_case_1(void) 10353 { 10354 return test_authenticated_decryption(&gcm_test_case_1); 10355 } 10356 10357 static int 10358 test_AES_GCM_authenticated_decryption_test_case_2(void) 10359 { 10360 return test_authenticated_decryption(&gcm_test_case_2); 10361 } 10362 10363 static int 10364 test_AES_GCM_authenticated_decryption_test_case_3(void) 10365 { 10366 return test_authenticated_decryption(&gcm_test_case_3); 10367 } 10368 10369 static int 10370 test_AES_GCM_authenticated_decryption_test_case_4(void) 10371 { 10372 return test_authenticated_decryption(&gcm_test_case_4); 10373 } 10374 10375 static int 10376 test_AES_GCM_authenticated_decryption_test_case_5(void) 10377 { 10378 return test_authenticated_decryption(&gcm_test_case_5); 10379 } 10380 10381 static int 10382 test_AES_GCM_authenticated_decryption_test_case_6(void) 10383 { 10384 return test_authenticated_decryption(&gcm_test_case_6); 10385 } 10386 10387 static int 10388 test_AES_GCM_authenticated_decryption_test_case_7(void) 10389 { 10390 return test_authenticated_decryption(&gcm_test_case_7); 10391 } 10392 10393 static int 10394 test_AES_GCM_authenticated_decryption_test_case_8(void) 10395 { 10396 return test_authenticated_decryption(&gcm_test_case_8); 10397 } 10398 10399 static int 10400 test_AES_GCM_J0_authenticated_decryption_test_case_1(void) 10401 { 10402 return test_authenticated_decryption(&gcm_J0_test_case_1); 10403 } 10404 10405 static int 10406 test_AES_GCM_auth_decryption_test_case_192_1(void) 10407 { 10408 return test_authenticated_decryption(&gcm_test_case_192_1); 10409 } 10410 10411 static int 10412 test_AES_GCM_auth_decryption_test_case_192_2(void) 10413 { 10414 return test_authenticated_decryption(&gcm_test_case_192_2); 10415 } 10416 10417 static int 10418 test_AES_GCM_auth_decryption_test_case_192_3(void) 10419 { 10420 return test_authenticated_decryption(&gcm_test_case_192_3); 10421 } 10422 10423 static int 10424 test_AES_GCM_auth_decryption_test_case_192_4(void) 10425 { 10426 return test_authenticated_decryption(&gcm_test_case_192_4); 10427 } 10428 10429 static int 10430 test_AES_GCM_auth_decryption_test_case_192_5(void) 10431 { 10432 return test_authenticated_decryption(&gcm_test_case_192_5); 10433 } 10434 10435 static int 10436 test_AES_GCM_auth_decryption_test_case_192_6(void) 10437 { 10438 return test_authenticated_decryption(&gcm_test_case_192_6); 10439 } 10440 10441 static int 10442 test_AES_GCM_auth_decryption_test_case_192_7(void) 10443 { 10444 return test_authenticated_decryption(&gcm_test_case_192_7); 10445 } 10446 10447 static int 10448 test_AES_GCM_auth_decryption_test_case_256_1(void) 10449 { 10450 return test_authenticated_decryption(&gcm_test_case_256_1); 10451 } 10452 10453 static int 10454 test_AES_GCM_auth_decryption_test_case_256_2(void) 10455 { 10456 return test_authenticated_decryption(&gcm_test_case_256_2); 10457 } 10458 10459 static int 10460 test_AES_GCM_auth_decryption_test_case_256_3(void) 10461 { 10462 return test_authenticated_decryption(&gcm_test_case_256_3); 10463 } 10464 10465 static int 10466 test_AES_GCM_auth_decryption_test_case_256_4(void) 10467 { 10468 return test_authenticated_decryption(&gcm_test_case_256_4); 10469 } 10470 10471 static int 10472 test_AES_GCM_auth_decryption_test_case_256_5(void) 10473 { 10474 return test_authenticated_decryption(&gcm_test_case_256_5); 10475 } 10476 10477 static int 10478 test_AES_GCM_auth_decryption_test_case_256_6(void) 10479 { 10480 return test_authenticated_decryption(&gcm_test_case_256_6); 10481 } 10482 10483 static int 10484 test_AES_GCM_auth_decryption_test_case_256_7(void) 10485 { 10486 return test_authenticated_decryption(&gcm_test_case_256_7); 10487 } 10488 10489 static int 10490 test_AES_GCM_auth_decryption_test_case_aad_1(void) 10491 { 10492 return test_authenticated_decryption(&gcm_test_case_aad_1); 10493 } 10494 10495 static int 10496 test_AES_GCM_auth_decryption_test_case_aad_2(void) 10497 { 10498 return test_authenticated_decryption(&gcm_test_case_aad_2); 10499 } 10500 10501 static int 10502 test_AES_GCM_auth_decryption_fail_iv_corrupt(void) 10503 { 10504 struct aead_test_data tdata; 10505 int res; 10506 10507 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10508 tdata.iv.data[0] += 1; 10509 res = test_authenticated_decryption(&tdata); 10510 if (res == TEST_SKIPPED) 10511 return res; 10512 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10513 return TEST_SUCCESS; 10514 } 10515 10516 static int 10517 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void) 10518 { 10519 struct aead_test_data tdata; 10520 int res; 10521 10522 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10523 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10524 tdata.plaintext.data[0] += 1; 10525 res = test_authenticated_decryption(&tdata); 10526 if (res == TEST_SKIPPED) 10527 return res; 10528 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10529 return TEST_SUCCESS; 10530 } 10531 10532 static int 10533 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void) 10534 { 10535 struct aead_test_data tdata; 10536 int res; 10537 10538 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10539 tdata.ciphertext.data[0] += 1; 10540 res = test_authenticated_decryption(&tdata); 10541 if (res == TEST_SKIPPED) 10542 return res; 10543 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10544 return TEST_SUCCESS; 10545 } 10546 10547 static int 10548 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void) 10549 { 10550 struct aead_test_data tdata; 10551 int res; 10552 10553 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10554 tdata.aad.len += 1; 10555 res = test_authenticated_decryption(&tdata); 10556 if (res == TEST_SKIPPED) 10557 return res; 10558 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10559 return TEST_SUCCESS; 10560 } 10561 10562 static int 10563 test_AES_GCM_auth_decryption_fail_aad_corrupt(void) 10564 { 10565 struct aead_test_data tdata; 10566 uint8_t aad[gcm_test_case_7.aad.len]; 10567 int res; 10568 10569 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10570 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 10571 aad[0] += 1; 10572 tdata.aad.data = aad; 10573 res = test_authenticated_decryption(&tdata); 10574 if (res == TEST_SKIPPED) 10575 return res; 10576 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 10577 return TEST_SUCCESS; 10578 } 10579 10580 static int 10581 test_AES_GCM_auth_decryption_fail_tag_corrupt(void) 10582 { 10583 struct aead_test_data tdata; 10584 int res; 10585 10586 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10587 tdata.auth_tag.data[0] += 1; 10588 res = test_authenticated_decryption(&tdata); 10589 if (res == TEST_SKIPPED) 10590 return res; 10591 TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed"); 10592 return TEST_SUCCESS; 10593 } 10594 10595 static int 10596 test_authenticated_encryption_oop(const struct aead_test_data *tdata) 10597 { 10598 struct crypto_testsuite_params *ts_params = &testsuite_params; 10599 struct crypto_unittest_params *ut_params = &unittest_params; 10600 10601 int retval; 10602 uint8_t *ciphertext, *auth_tag; 10603 uint16_t plaintext_pad_len; 10604 struct rte_cryptodev_info dev_info; 10605 10606 /* Verify the capabilities */ 10607 struct rte_cryptodev_sym_capability_idx cap_idx; 10608 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10609 cap_idx.algo.aead = tdata->algo; 10610 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10611 &cap_idx) == NULL) 10612 return TEST_SKIPPED; 10613 10614 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10615 uint64_t feat_flags = dev_info.feature_flags; 10616 10617 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10618 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) 10619 return TEST_SKIPPED; 10620 10621 /* not supported with CPU crypto */ 10622 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10623 return TEST_SKIPPED; 10624 10625 /* Create AEAD session */ 10626 retval = create_aead_session(ts_params->valid_devs[0], 10627 tdata->algo, 10628 RTE_CRYPTO_AEAD_OP_ENCRYPT, 10629 tdata->key.data, tdata->key.len, 10630 tdata->aad.len, tdata->auth_tag.len, 10631 tdata->iv.len); 10632 if (retval < 0) 10633 return retval; 10634 10635 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10636 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10637 10638 /* clear mbuf payload */ 10639 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10640 rte_pktmbuf_tailroom(ut_params->ibuf)); 10641 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 10642 rte_pktmbuf_tailroom(ut_params->obuf)); 10643 10644 /* Create AEAD operation */ 10645 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 10646 if (retval < 0) 10647 return retval; 10648 10649 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10650 10651 ut_params->op->sym->m_src = ut_params->ibuf; 10652 ut_params->op->sym->m_dst = ut_params->obuf; 10653 10654 /* Process crypto operation */ 10655 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10656 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10657 ut_params->op, 0, 0, 0, 0); 10658 else 10659 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 10660 ut_params->op), "failed to process sym crypto op"); 10661 10662 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10663 "crypto op processing failed"); 10664 10665 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 10666 10667 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 10668 ut_params->op->sym->cipher.data.offset); 10669 auth_tag = ciphertext + plaintext_pad_len; 10670 10671 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 10672 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 10673 10674 /* Validate obuf */ 10675 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10676 ciphertext, 10677 tdata->ciphertext.data, 10678 tdata->ciphertext.len, 10679 "Ciphertext data not as expected"); 10680 10681 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10682 auth_tag, 10683 tdata->auth_tag.data, 10684 tdata->auth_tag.len, 10685 "Generated auth tag not as expected"); 10686 10687 return 0; 10688 10689 } 10690 10691 static int 10692 test_AES_GCM_authenticated_encryption_oop_test_case_1(void) 10693 { 10694 return test_authenticated_encryption_oop(&gcm_test_case_5); 10695 } 10696 10697 static int 10698 test_authenticated_decryption_oop(const struct aead_test_data *tdata) 10699 { 10700 struct crypto_testsuite_params *ts_params = &testsuite_params; 10701 struct crypto_unittest_params *ut_params = &unittest_params; 10702 10703 int retval; 10704 uint8_t *plaintext; 10705 struct rte_cryptodev_info dev_info; 10706 10707 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10708 uint64_t feat_flags = dev_info.feature_flags; 10709 10710 /* Verify the capabilities */ 10711 struct rte_cryptodev_sym_capability_idx cap_idx; 10712 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10713 cap_idx.algo.aead = tdata->algo; 10714 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10715 &cap_idx) == NULL) 10716 return TEST_SKIPPED; 10717 10718 /* not supported with CPU crypto and raw data-path APIs*/ 10719 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO || 10720 global_api_test_type == CRYPTODEV_RAW_API_TEST) 10721 return TEST_SKIPPED; 10722 10723 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10724 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10725 printf("Device does not support RAW data-path APIs.\n"); 10726 return TEST_SKIPPED; 10727 } 10728 10729 /* Create AEAD session */ 10730 retval = create_aead_session(ts_params->valid_devs[0], 10731 tdata->algo, 10732 RTE_CRYPTO_AEAD_OP_DECRYPT, 10733 tdata->key.data, tdata->key.len, 10734 tdata->aad.len, tdata->auth_tag.len, 10735 tdata->iv.len); 10736 if (retval < 0) 10737 return retval; 10738 10739 /* alloc mbuf and set payload */ 10740 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10741 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10742 10743 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10744 rte_pktmbuf_tailroom(ut_params->ibuf)); 10745 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 10746 rte_pktmbuf_tailroom(ut_params->obuf)); 10747 10748 /* Create AEAD operation */ 10749 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 10750 if (retval < 0) 10751 return retval; 10752 10753 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10754 10755 ut_params->op->sym->m_src = ut_params->ibuf; 10756 ut_params->op->sym->m_dst = ut_params->obuf; 10757 10758 /* Process crypto operation */ 10759 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10760 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10761 ut_params->op, 0, 0, 0, 0); 10762 else 10763 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 10764 ut_params->op), "failed to process sym crypto op"); 10765 10766 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10767 "crypto op processing failed"); 10768 10769 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 10770 ut_params->op->sym->cipher.data.offset); 10771 10772 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 10773 10774 /* Validate obuf */ 10775 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10776 plaintext, 10777 tdata->plaintext.data, 10778 tdata->plaintext.len, 10779 "Plaintext data not as expected"); 10780 10781 TEST_ASSERT_EQUAL(ut_params->op->status, 10782 RTE_CRYPTO_OP_STATUS_SUCCESS, 10783 "Authentication failed"); 10784 return 0; 10785 } 10786 10787 static int 10788 test_AES_GCM_authenticated_decryption_oop_test_case_1(void) 10789 { 10790 return test_authenticated_decryption_oop(&gcm_test_case_5); 10791 } 10792 10793 static int 10794 test_authenticated_encryption_sessionless( 10795 const struct aead_test_data *tdata) 10796 { 10797 struct crypto_testsuite_params *ts_params = &testsuite_params; 10798 struct crypto_unittest_params *ut_params = &unittest_params; 10799 10800 int retval; 10801 uint8_t *ciphertext, *auth_tag; 10802 uint16_t plaintext_pad_len; 10803 uint8_t key[tdata->key.len + 1]; 10804 struct rte_cryptodev_info dev_info; 10805 10806 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10807 uint64_t feat_flags = dev_info.feature_flags; 10808 10809 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 10810 printf("Device doesn't support Sessionless ops.\n"); 10811 return TEST_SKIPPED; 10812 } 10813 10814 /* not supported with CPU crypto */ 10815 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10816 return TEST_SKIPPED; 10817 10818 /* Verify the capabilities */ 10819 struct rte_cryptodev_sym_capability_idx cap_idx; 10820 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10821 cap_idx.algo.aead = tdata->algo; 10822 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10823 &cap_idx) == NULL) 10824 return TEST_SKIPPED; 10825 10826 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10827 10828 /* clear mbuf payload */ 10829 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10830 rte_pktmbuf_tailroom(ut_params->ibuf)); 10831 10832 /* Create AEAD operation */ 10833 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 10834 if (retval < 0) 10835 return retval; 10836 10837 /* Create GCM xform */ 10838 memcpy(key, tdata->key.data, tdata->key.len); 10839 retval = create_aead_xform(ut_params->op, 10840 tdata->algo, 10841 RTE_CRYPTO_AEAD_OP_ENCRYPT, 10842 key, tdata->key.len, 10843 tdata->aad.len, tdata->auth_tag.len, 10844 tdata->iv.len); 10845 if (retval < 0) 10846 return retval; 10847 10848 ut_params->op->sym->m_src = ut_params->ibuf; 10849 10850 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 10851 RTE_CRYPTO_OP_SESSIONLESS, 10852 "crypto op session type not sessionless"); 10853 10854 /* Process crypto operation */ 10855 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 10856 ut_params->op), "failed to process sym crypto op"); 10857 10858 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 10859 10860 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10861 "crypto op status not success"); 10862 10863 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 10864 10865 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 10866 ut_params->op->sym->cipher.data.offset); 10867 auth_tag = ciphertext + plaintext_pad_len; 10868 10869 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 10870 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 10871 10872 /* Validate obuf */ 10873 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10874 ciphertext, 10875 tdata->ciphertext.data, 10876 tdata->ciphertext.len, 10877 "Ciphertext data not as expected"); 10878 10879 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10880 auth_tag, 10881 tdata->auth_tag.data, 10882 tdata->auth_tag.len, 10883 "Generated auth tag not as expected"); 10884 10885 return 0; 10886 10887 } 10888 10889 static int 10890 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void) 10891 { 10892 return test_authenticated_encryption_sessionless( 10893 &gcm_test_case_5); 10894 } 10895 10896 static int 10897 test_authenticated_decryption_sessionless( 10898 const struct aead_test_data *tdata) 10899 { 10900 struct crypto_testsuite_params *ts_params = &testsuite_params; 10901 struct crypto_unittest_params *ut_params = &unittest_params; 10902 10903 int retval; 10904 uint8_t *plaintext; 10905 uint8_t key[tdata->key.len + 1]; 10906 struct rte_cryptodev_info dev_info; 10907 10908 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10909 uint64_t feat_flags = dev_info.feature_flags; 10910 10911 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 10912 printf("Device doesn't support Sessionless ops.\n"); 10913 return TEST_SKIPPED; 10914 } 10915 10916 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10917 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10918 printf("Device doesn't support RAW data-path APIs.\n"); 10919 return TEST_SKIPPED; 10920 } 10921 10922 /* not supported with CPU crypto */ 10923 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10924 return TEST_SKIPPED; 10925 10926 /* Verify the capabilities */ 10927 struct rte_cryptodev_sym_capability_idx cap_idx; 10928 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10929 cap_idx.algo.aead = tdata->algo; 10930 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10931 &cap_idx) == NULL) 10932 return TEST_SKIPPED; 10933 10934 /* alloc mbuf and set payload */ 10935 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10936 10937 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10938 rte_pktmbuf_tailroom(ut_params->ibuf)); 10939 10940 /* Create AEAD operation */ 10941 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 10942 if (retval < 0) 10943 return retval; 10944 10945 /* Create AEAD xform */ 10946 memcpy(key, tdata->key.data, tdata->key.len); 10947 retval = create_aead_xform(ut_params->op, 10948 tdata->algo, 10949 RTE_CRYPTO_AEAD_OP_DECRYPT, 10950 key, tdata->key.len, 10951 tdata->aad.len, tdata->auth_tag.len, 10952 tdata->iv.len); 10953 if (retval < 0) 10954 return retval; 10955 10956 ut_params->op->sym->m_src = ut_params->ibuf; 10957 10958 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 10959 RTE_CRYPTO_OP_SESSIONLESS, 10960 "crypto op session type not sessionless"); 10961 10962 /* Process crypto operation */ 10963 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10964 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10965 ut_params->op, 0, 0, 0, 0); 10966 else 10967 TEST_ASSERT_NOT_NULL(process_crypto_request( 10968 ts_params->valid_devs[0], ut_params->op), 10969 "failed to process sym crypto op"); 10970 10971 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 10972 10973 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10974 "crypto op status not success"); 10975 10976 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 10977 ut_params->op->sym->cipher.data.offset); 10978 10979 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 10980 10981 /* Validate obuf */ 10982 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10983 plaintext, 10984 tdata->plaintext.data, 10985 tdata->plaintext.len, 10986 "Plaintext data not as expected"); 10987 10988 TEST_ASSERT_EQUAL(ut_params->op->status, 10989 RTE_CRYPTO_OP_STATUS_SUCCESS, 10990 "Authentication failed"); 10991 return 0; 10992 } 10993 10994 static int 10995 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void) 10996 { 10997 return test_authenticated_decryption_sessionless( 10998 &gcm_test_case_5); 10999 } 11000 11001 static int 11002 test_AES_CCM_authenticated_encryption_test_case_128_1(void) 11003 { 11004 return test_authenticated_encryption(&ccm_test_case_128_1); 11005 } 11006 11007 static int 11008 test_AES_CCM_authenticated_encryption_test_case_128_2(void) 11009 { 11010 return test_authenticated_encryption(&ccm_test_case_128_2); 11011 } 11012 11013 static int 11014 test_AES_CCM_authenticated_encryption_test_case_128_3(void) 11015 { 11016 return test_authenticated_encryption(&ccm_test_case_128_3); 11017 } 11018 11019 static int 11020 test_AES_CCM_authenticated_decryption_test_case_128_1(void) 11021 { 11022 return test_authenticated_decryption(&ccm_test_case_128_1); 11023 } 11024 11025 static int 11026 test_AES_CCM_authenticated_decryption_test_case_128_2(void) 11027 { 11028 return test_authenticated_decryption(&ccm_test_case_128_2); 11029 } 11030 11031 static int 11032 test_AES_CCM_authenticated_decryption_test_case_128_3(void) 11033 { 11034 return test_authenticated_decryption(&ccm_test_case_128_3); 11035 } 11036 11037 static int 11038 test_AES_CCM_authenticated_encryption_test_case_192_1(void) 11039 { 11040 return test_authenticated_encryption(&ccm_test_case_192_1); 11041 } 11042 11043 static int 11044 test_AES_CCM_authenticated_encryption_test_case_192_2(void) 11045 { 11046 return test_authenticated_encryption(&ccm_test_case_192_2); 11047 } 11048 11049 static int 11050 test_AES_CCM_authenticated_encryption_test_case_192_3(void) 11051 { 11052 return test_authenticated_encryption(&ccm_test_case_192_3); 11053 } 11054 11055 static int 11056 test_AES_CCM_authenticated_decryption_test_case_192_1(void) 11057 { 11058 return test_authenticated_decryption(&ccm_test_case_192_1); 11059 } 11060 11061 static int 11062 test_AES_CCM_authenticated_decryption_test_case_192_2(void) 11063 { 11064 return test_authenticated_decryption(&ccm_test_case_192_2); 11065 } 11066 11067 static int 11068 test_AES_CCM_authenticated_decryption_test_case_192_3(void) 11069 { 11070 return test_authenticated_decryption(&ccm_test_case_192_3); 11071 } 11072 11073 static int 11074 test_AES_CCM_authenticated_encryption_test_case_256_1(void) 11075 { 11076 return test_authenticated_encryption(&ccm_test_case_256_1); 11077 } 11078 11079 static int 11080 test_AES_CCM_authenticated_encryption_test_case_256_2(void) 11081 { 11082 return test_authenticated_encryption(&ccm_test_case_256_2); 11083 } 11084 11085 static int 11086 test_AES_CCM_authenticated_encryption_test_case_256_3(void) 11087 { 11088 return test_authenticated_encryption(&ccm_test_case_256_3); 11089 } 11090 11091 static int 11092 test_AES_CCM_authenticated_decryption_test_case_256_1(void) 11093 { 11094 return test_authenticated_decryption(&ccm_test_case_256_1); 11095 } 11096 11097 static int 11098 test_AES_CCM_authenticated_decryption_test_case_256_2(void) 11099 { 11100 return test_authenticated_decryption(&ccm_test_case_256_2); 11101 } 11102 11103 static int 11104 test_AES_CCM_authenticated_decryption_test_case_256_3(void) 11105 { 11106 return test_authenticated_decryption(&ccm_test_case_256_3); 11107 } 11108 11109 static int 11110 test_stats(void) 11111 { 11112 struct crypto_testsuite_params *ts_params = &testsuite_params; 11113 struct rte_cryptodev_stats stats; 11114 11115 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11116 return TEST_SKIPPED; 11117 11118 /* Verify the capabilities */ 11119 struct rte_cryptodev_sym_capability_idx cap_idx; 11120 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11121 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 11122 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11123 &cap_idx) == NULL) 11124 return TEST_SKIPPED; 11125 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11126 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 11127 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11128 &cap_idx) == NULL) 11129 return TEST_SKIPPED; 11130 11131 if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 11132 == -ENOTSUP) 11133 return TEST_SKIPPED; 11134 11135 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 11136 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 11137 &stats) == -ENODEV), 11138 "rte_cryptodev_stats_get invalid dev failed"); 11139 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 11140 "rte_cryptodev_stats_get invalid Param failed"); 11141 11142 /* Test expected values */ 11143 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 11144 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11145 &stats), 11146 "rte_cryptodev_stats_get failed"); 11147 TEST_ASSERT((stats.enqueued_count == 1), 11148 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11149 TEST_ASSERT((stats.dequeued_count == 1), 11150 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11151 TEST_ASSERT((stats.enqueue_err_count == 0), 11152 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11153 TEST_ASSERT((stats.dequeue_err_count == 0), 11154 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11155 11156 /* invalid device but should ignore and not reset device stats*/ 11157 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 11158 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11159 &stats), 11160 "rte_cryptodev_stats_get failed"); 11161 TEST_ASSERT((stats.enqueued_count == 1), 11162 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11163 11164 /* check that a valid reset clears stats */ 11165 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 11166 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11167 &stats), 11168 "rte_cryptodev_stats_get failed"); 11169 TEST_ASSERT((stats.enqueued_count == 0), 11170 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11171 TEST_ASSERT((stats.dequeued_count == 0), 11172 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11173 11174 return TEST_SUCCESS; 11175 } 11176 11177 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 11178 struct crypto_unittest_params *ut_params, 11179 enum rte_crypto_auth_operation op, 11180 const struct HMAC_MD5_vector *test_case) 11181 { 11182 uint8_t key[64]; 11183 11184 memcpy(key, test_case->key.data, test_case->key.len); 11185 11186 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11187 ut_params->auth_xform.next = NULL; 11188 ut_params->auth_xform.auth.op = op; 11189 11190 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 11191 11192 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 11193 ut_params->auth_xform.auth.key.length = test_case->key.len; 11194 ut_params->auth_xform.auth.key.data = key; 11195 11196 ut_params->sess = rte_cryptodev_sym_session_create( 11197 ts_params->session_mpool); 11198 11199 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11200 ut_params->sess, &ut_params->auth_xform, 11201 ts_params->session_priv_mpool); 11202 11203 if (ut_params->sess == NULL) 11204 return TEST_FAILED; 11205 11206 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11207 11208 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11209 rte_pktmbuf_tailroom(ut_params->ibuf)); 11210 11211 return 0; 11212 } 11213 11214 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 11215 const struct HMAC_MD5_vector *test_case, 11216 uint8_t **plaintext) 11217 { 11218 uint16_t plaintext_pad_len; 11219 11220 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 11221 11222 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 11223 16); 11224 11225 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11226 plaintext_pad_len); 11227 memcpy(*plaintext, test_case->plaintext.data, 11228 test_case->plaintext.len); 11229 11230 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11231 ut_params->ibuf, MD5_DIGEST_LEN); 11232 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11233 "no room to append digest"); 11234 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11235 ut_params->ibuf, plaintext_pad_len); 11236 11237 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 11238 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 11239 test_case->auth_tag.len); 11240 } 11241 11242 sym_op->auth.data.offset = 0; 11243 sym_op->auth.data.length = test_case->plaintext.len; 11244 11245 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11246 ut_params->op->sym->m_src = ut_params->ibuf; 11247 11248 return 0; 11249 } 11250 11251 static int 11252 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 11253 { 11254 uint16_t plaintext_pad_len; 11255 uint8_t *plaintext, *auth_tag; 11256 11257 struct crypto_testsuite_params *ts_params = &testsuite_params; 11258 struct crypto_unittest_params *ut_params = &unittest_params; 11259 struct rte_cryptodev_info dev_info; 11260 11261 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11262 uint64_t feat_flags = dev_info.feature_flags; 11263 11264 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11265 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11266 printf("Device doesn't support RAW data-path APIs.\n"); 11267 return TEST_SKIPPED; 11268 } 11269 11270 /* Verify the capabilities */ 11271 struct rte_cryptodev_sym_capability_idx cap_idx; 11272 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11273 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 11274 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11275 &cap_idx) == NULL) 11276 return TEST_SKIPPED; 11277 11278 if (MD5_HMAC_create_session(ts_params, ut_params, 11279 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 11280 return TEST_FAILED; 11281 11282 /* Generate Crypto op data structure */ 11283 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11284 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11285 TEST_ASSERT_NOT_NULL(ut_params->op, 11286 "Failed to allocate symmetric crypto operation struct"); 11287 11288 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 11289 16); 11290 11291 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 11292 return TEST_FAILED; 11293 11294 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11295 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11296 ut_params->op); 11297 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11298 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11299 ut_params->op, 0, 1, 0, 0); 11300 else 11301 TEST_ASSERT_NOT_NULL( 11302 process_crypto_request(ts_params->valid_devs[0], 11303 ut_params->op), 11304 "failed to process sym crypto op"); 11305 11306 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11307 "crypto op processing failed"); 11308 11309 if (ut_params->op->sym->m_dst) { 11310 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 11311 uint8_t *, plaintext_pad_len); 11312 } else { 11313 auth_tag = plaintext + plaintext_pad_len; 11314 } 11315 11316 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11317 auth_tag, 11318 test_case->auth_tag.data, 11319 test_case->auth_tag.len, 11320 "HMAC_MD5 generated tag not as expected"); 11321 11322 return TEST_SUCCESS; 11323 } 11324 11325 static int 11326 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 11327 { 11328 uint8_t *plaintext; 11329 11330 struct crypto_testsuite_params *ts_params = &testsuite_params; 11331 struct crypto_unittest_params *ut_params = &unittest_params; 11332 struct rte_cryptodev_info dev_info; 11333 11334 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11335 uint64_t feat_flags = dev_info.feature_flags; 11336 11337 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11338 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11339 printf("Device doesn't support RAW data-path APIs.\n"); 11340 return TEST_SKIPPED; 11341 } 11342 11343 /* Verify the capabilities */ 11344 struct rte_cryptodev_sym_capability_idx cap_idx; 11345 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11346 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 11347 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11348 &cap_idx) == NULL) 11349 return TEST_SKIPPED; 11350 11351 if (MD5_HMAC_create_session(ts_params, ut_params, 11352 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 11353 return TEST_FAILED; 11354 } 11355 11356 /* Generate Crypto op data structure */ 11357 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11358 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11359 TEST_ASSERT_NOT_NULL(ut_params->op, 11360 "Failed to allocate symmetric crypto operation struct"); 11361 11362 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 11363 return TEST_FAILED; 11364 11365 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11366 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11367 ut_params->op); 11368 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11369 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11370 ut_params->op, 0, 1, 0, 0); 11371 else 11372 TEST_ASSERT_NOT_NULL( 11373 process_crypto_request(ts_params->valid_devs[0], 11374 ut_params->op), 11375 "failed to process sym crypto op"); 11376 11377 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11378 "HMAC_MD5 crypto op processing failed"); 11379 11380 return TEST_SUCCESS; 11381 } 11382 11383 static int 11384 test_MD5_HMAC_generate_case_1(void) 11385 { 11386 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 11387 } 11388 11389 static int 11390 test_MD5_HMAC_verify_case_1(void) 11391 { 11392 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 11393 } 11394 11395 static int 11396 test_MD5_HMAC_generate_case_2(void) 11397 { 11398 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 11399 } 11400 11401 static int 11402 test_MD5_HMAC_verify_case_2(void) 11403 { 11404 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 11405 } 11406 11407 static int 11408 test_multi_session(void) 11409 { 11410 struct crypto_testsuite_params *ts_params = &testsuite_params; 11411 struct crypto_unittest_params *ut_params = &unittest_params; 11412 11413 struct rte_cryptodev_info dev_info; 11414 struct rte_cryptodev_sym_session **sessions; 11415 11416 uint16_t i; 11417 11418 /* Verify the capabilities */ 11419 struct rte_cryptodev_sym_capability_idx cap_idx; 11420 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11421 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 11422 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11423 &cap_idx) == NULL) 11424 return TEST_SKIPPED; 11425 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11426 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 11427 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11428 &cap_idx) == NULL) 11429 return TEST_SKIPPED; 11430 11431 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 11432 aes_cbc_key, hmac_sha512_key); 11433 11434 11435 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11436 11437 sessions = rte_malloc(NULL, 11438 sizeof(struct rte_cryptodev_sym_session *) * 11439 (MAX_NB_SESSIONS + 1), 0); 11440 11441 /* Create multiple crypto sessions*/ 11442 for (i = 0; i < MAX_NB_SESSIONS; i++) { 11443 11444 sessions[i] = rte_cryptodev_sym_session_create( 11445 ts_params->session_mpool); 11446 11447 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11448 sessions[i], &ut_params->auth_xform, 11449 ts_params->session_priv_mpool); 11450 TEST_ASSERT_NOT_NULL(sessions[i], 11451 "Session creation failed at session number %u", 11452 i); 11453 11454 /* Attempt to send a request on each session */ 11455 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform( 11456 sessions[i], 11457 ut_params, 11458 ts_params, 11459 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 11460 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 11461 aes_cbc_iv), 11462 "Failed to perform decrypt on request number %u.", i); 11463 /* free crypto operation structure */ 11464 if (ut_params->op) 11465 rte_crypto_op_free(ut_params->op); 11466 11467 /* 11468 * free mbuf - both obuf and ibuf are usually the same, 11469 * so check if they point at the same address is necessary, 11470 * to avoid freeing the mbuf twice. 11471 */ 11472 if (ut_params->obuf) { 11473 rte_pktmbuf_free(ut_params->obuf); 11474 if (ut_params->ibuf == ut_params->obuf) 11475 ut_params->ibuf = 0; 11476 ut_params->obuf = 0; 11477 } 11478 if (ut_params->ibuf) { 11479 rte_pktmbuf_free(ut_params->ibuf); 11480 ut_params->ibuf = 0; 11481 } 11482 } 11483 11484 sessions[i] = NULL; 11485 /* Next session create should fail */ 11486 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11487 sessions[i], &ut_params->auth_xform, 11488 ts_params->session_priv_mpool); 11489 TEST_ASSERT_NULL(sessions[i], 11490 "Session creation succeeded unexpectedly!"); 11491 11492 for (i = 0; i < MAX_NB_SESSIONS; i++) { 11493 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 11494 sessions[i]); 11495 rte_cryptodev_sym_session_free(sessions[i]); 11496 } 11497 11498 rte_free(sessions); 11499 11500 return TEST_SUCCESS; 11501 } 11502 11503 struct multi_session_params { 11504 struct crypto_unittest_params ut_params; 11505 uint8_t *cipher_key; 11506 uint8_t *hmac_key; 11507 const uint8_t *cipher; 11508 const uint8_t *digest; 11509 uint8_t *iv; 11510 }; 11511 11512 #define MB_SESSION_NUMBER 3 11513 11514 static int 11515 test_multi_session_random_usage(void) 11516 { 11517 struct crypto_testsuite_params *ts_params = &testsuite_params; 11518 struct rte_cryptodev_info dev_info; 11519 struct rte_cryptodev_sym_session **sessions; 11520 uint32_t i, j; 11521 struct multi_session_params ut_paramz[] = { 11522 11523 { 11524 .cipher_key = ms_aes_cbc_key0, 11525 .hmac_key = ms_hmac_key0, 11526 .cipher = ms_aes_cbc_cipher0, 11527 .digest = ms_hmac_digest0, 11528 .iv = ms_aes_cbc_iv0 11529 }, 11530 { 11531 .cipher_key = ms_aes_cbc_key1, 11532 .hmac_key = ms_hmac_key1, 11533 .cipher = ms_aes_cbc_cipher1, 11534 .digest = ms_hmac_digest1, 11535 .iv = ms_aes_cbc_iv1 11536 }, 11537 { 11538 .cipher_key = ms_aes_cbc_key2, 11539 .hmac_key = ms_hmac_key2, 11540 .cipher = ms_aes_cbc_cipher2, 11541 .digest = ms_hmac_digest2, 11542 .iv = ms_aes_cbc_iv2 11543 }, 11544 11545 }; 11546 11547 /* Verify the capabilities */ 11548 struct rte_cryptodev_sym_capability_idx cap_idx; 11549 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11550 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 11551 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11552 &cap_idx) == NULL) 11553 return TEST_SKIPPED; 11554 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11555 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 11556 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11557 &cap_idx) == NULL) 11558 return TEST_SKIPPED; 11559 11560 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11561 11562 sessions = rte_malloc(NULL, 11563 (sizeof(struct rte_cryptodev_sym_session *) 11564 * MAX_NB_SESSIONS) + 1, 0); 11565 11566 for (i = 0; i < MB_SESSION_NUMBER; i++) { 11567 sessions[i] = rte_cryptodev_sym_session_create( 11568 ts_params->session_mpool); 11569 11570 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params, 11571 sizeof(struct crypto_unittest_params)); 11572 11573 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 11574 &ut_paramz[i].ut_params, 11575 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 11576 11577 /* Create multiple crypto sessions*/ 11578 rte_cryptodev_sym_session_init( 11579 ts_params->valid_devs[0], 11580 sessions[i], 11581 &ut_paramz[i].ut_params.auth_xform, 11582 ts_params->session_priv_mpool); 11583 11584 TEST_ASSERT_NOT_NULL(sessions[i], 11585 "Session creation failed at session number %u", 11586 i); 11587 11588 } 11589 11590 srand(time(NULL)); 11591 for (i = 0; i < 40000; i++) { 11592 11593 j = rand() % MB_SESSION_NUMBER; 11594 11595 TEST_ASSERT_SUCCESS( 11596 test_AES_CBC_HMAC_SHA512_decrypt_perform( 11597 sessions[j], 11598 &ut_paramz[j].ut_params, 11599 ts_params, ut_paramz[j].cipher, 11600 ut_paramz[j].digest, 11601 ut_paramz[j].iv), 11602 "Failed to perform decrypt on request number %u.", i); 11603 11604 if (ut_paramz[j].ut_params.op) 11605 rte_crypto_op_free(ut_paramz[j].ut_params.op); 11606 11607 /* 11608 * free mbuf - both obuf and ibuf are usually the same, 11609 * so check if they point at the same address is necessary, 11610 * to avoid freeing the mbuf twice. 11611 */ 11612 if (ut_paramz[j].ut_params.obuf) { 11613 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 11614 if (ut_paramz[j].ut_params.ibuf 11615 == ut_paramz[j].ut_params.obuf) 11616 ut_paramz[j].ut_params.ibuf = 0; 11617 ut_paramz[j].ut_params.obuf = 0; 11618 } 11619 if (ut_paramz[j].ut_params.ibuf) { 11620 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 11621 ut_paramz[j].ut_params.ibuf = 0; 11622 } 11623 } 11624 11625 for (i = 0; i < MB_SESSION_NUMBER; i++) { 11626 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 11627 sessions[i]); 11628 rte_cryptodev_sym_session_free(sessions[i]); 11629 } 11630 11631 rte_free(sessions); 11632 11633 return TEST_SUCCESS; 11634 } 11635 11636 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab, 11637 0xab, 0xab, 0xab, 0xab, 11638 0xab, 0xab, 0xab, 0xab, 11639 0xab, 0xab, 0xab, 0xab}; 11640 11641 static int 11642 test_null_invalid_operation(void) 11643 { 11644 struct crypto_testsuite_params *ts_params = &testsuite_params; 11645 struct crypto_unittest_params *ut_params = &unittest_params; 11646 int ret; 11647 11648 /* This test is for NULL PMD only */ 11649 if (gbl_driver_id != rte_cryptodev_driver_id_get( 11650 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 11651 return TEST_SKIPPED; 11652 11653 /* Setup Cipher Parameters */ 11654 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11655 ut_params->cipher_xform.next = NULL; 11656 11657 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 11658 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 11659 11660 ut_params->sess = rte_cryptodev_sym_session_create( 11661 ts_params->session_mpool); 11662 11663 /* Create Crypto session*/ 11664 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11665 ut_params->sess, &ut_params->cipher_xform, 11666 ts_params->session_priv_mpool); 11667 TEST_ASSERT(ret < 0, 11668 "Session creation succeeded unexpectedly"); 11669 11670 11671 /* Setup HMAC Parameters */ 11672 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11673 ut_params->auth_xform.next = NULL; 11674 11675 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 11676 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 11677 11678 ut_params->sess = rte_cryptodev_sym_session_create( 11679 ts_params->session_mpool); 11680 11681 /* Create Crypto session*/ 11682 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11683 ut_params->sess, &ut_params->auth_xform, 11684 ts_params->session_priv_mpool); 11685 TEST_ASSERT(ret < 0, 11686 "Session creation succeeded unexpectedly"); 11687 11688 return TEST_SUCCESS; 11689 } 11690 11691 11692 #define NULL_BURST_LENGTH (32) 11693 11694 static int 11695 test_null_burst_operation(void) 11696 { 11697 struct crypto_testsuite_params *ts_params = &testsuite_params; 11698 struct crypto_unittest_params *ut_params = &unittest_params; 11699 11700 unsigned i, burst_len = NULL_BURST_LENGTH; 11701 11702 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 11703 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 11704 11705 /* This test is for NULL PMD only */ 11706 if (gbl_driver_id != rte_cryptodev_driver_id_get( 11707 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 11708 return TEST_SKIPPED; 11709 11710 /* Setup Cipher Parameters */ 11711 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11712 ut_params->cipher_xform.next = &ut_params->auth_xform; 11713 11714 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 11715 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 11716 11717 /* Setup HMAC Parameters */ 11718 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11719 ut_params->auth_xform.next = NULL; 11720 11721 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 11722 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 11723 11724 ut_params->sess = rte_cryptodev_sym_session_create( 11725 ts_params->session_mpool); 11726 11727 /* Create Crypto session*/ 11728 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11729 ut_params->sess, &ut_params->cipher_xform, 11730 ts_params->session_priv_mpool); 11731 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11732 11733 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 11734 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 11735 burst_len, "failed to generate burst of crypto ops"); 11736 11737 /* Generate an operation for each mbuf in burst */ 11738 for (i = 0; i < burst_len; i++) { 11739 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11740 11741 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 11742 11743 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 11744 sizeof(unsigned)); 11745 *data = i; 11746 11747 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 11748 11749 burst[i]->sym->m_src = m; 11750 } 11751 11752 /* Process crypto operation */ 11753 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 11754 0, burst, burst_len), 11755 burst_len, 11756 "Error enqueuing burst"); 11757 11758 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 11759 0, burst_dequeued, burst_len), 11760 burst_len, 11761 "Error dequeuing burst"); 11762 11763 11764 for (i = 0; i < burst_len; i++) { 11765 TEST_ASSERT_EQUAL( 11766 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 11767 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 11768 uint32_t *), 11769 "data not as expected"); 11770 11771 rte_pktmbuf_free(burst[i]->sym->m_src); 11772 rte_crypto_op_free(burst[i]); 11773 } 11774 11775 return TEST_SUCCESS; 11776 } 11777 11778 static uint16_t 11779 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 11780 uint16_t nb_ops, void *user_param) 11781 { 11782 RTE_SET_USED(dev_id); 11783 RTE_SET_USED(qp_id); 11784 RTE_SET_USED(ops); 11785 RTE_SET_USED(user_param); 11786 11787 printf("crypto enqueue callback called\n"); 11788 return nb_ops; 11789 } 11790 11791 static uint16_t 11792 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 11793 uint16_t nb_ops, void *user_param) 11794 { 11795 RTE_SET_USED(dev_id); 11796 RTE_SET_USED(qp_id); 11797 RTE_SET_USED(ops); 11798 RTE_SET_USED(user_param); 11799 11800 printf("crypto dequeue callback called\n"); 11801 return nb_ops; 11802 } 11803 11804 /* 11805 * Thread using enqueue/dequeue callback with RCU. 11806 */ 11807 static int 11808 test_enqdeq_callback_thread(void *arg) 11809 { 11810 RTE_SET_USED(arg); 11811 /* DP thread calls rte_cryptodev_enqueue_burst()/ 11812 * rte_cryptodev_dequeue_burst() and invokes callback. 11813 */ 11814 test_null_burst_operation(); 11815 return 0; 11816 } 11817 11818 static int 11819 test_enq_callback_setup(void) 11820 { 11821 struct crypto_testsuite_params *ts_params = &testsuite_params; 11822 struct rte_cryptodev_info dev_info; 11823 struct rte_cryptodev_qp_conf qp_conf = { 11824 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 11825 }; 11826 11827 struct rte_cryptodev_cb *cb; 11828 uint16_t qp_id = 0; 11829 11830 /* Stop the device in case it's started so it can be configured */ 11831 rte_cryptodev_stop(ts_params->valid_devs[0]); 11832 11833 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11834 11835 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 11836 &ts_params->conf), 11837 "Failed to configure cryptodev %u", 11838 ts_params->valid_devs[0]); 11839 11840 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 11841 qp_conf.mp_session = ts_params->session_mpool; 11842 qp_conf.mp_session_private = ts_params->session_priv_mpool; 11843 11844 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 11845 ts_params->valid_devs[0], qp_id, &qp_conf, 11846 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 11847 "Failed test for " 11848 "rte_cryptodev_queue_pair_setup: num_inflights " 11849 "%u on qp %u on cryptodev %u", 11850 qp_conf.nb_descriptors, qp_id, 11851 ts_params->valid_devs[0]); 11852 11853 /* Test with invalid crypto device */ 11854 cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS, 11855 qp_id, test_enq_callback, NULL); 11856 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11857 "cryptodev %u did not fail", 11858 qp_id, RTE_CRYPTO_MAX_DEVS); 11859 11860 /* Test with invalid queue pair */ 11861 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 11862 dev_info.max_nb_queue_pairs + 1, 11863 test_enq_callback, NULL); 11864 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11865 "cryptodev %u did not fail", 11866 dev_info.max_nb_queue_pairs + 1, 11867 ts_params->valid_devs[0]); 11868 11869 /* Test with NULL callback */ 11870 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 11871 qp_id, NULL, NULL); 11872 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11873 "cryptodev %u did not fail", 11874 qp_id, ts_params->valid_devs[0]); 11875 11876 /* Test with valid configuration */ 11877 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 11878 qp_id, test_enq_callback, NULL); 11879 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 11880 "qp %u on cryptodev %u", 11881 qp_id, ts_params->valid_devs[0]); 11882 11883 rte_cryptodev_start(ts_params->valid_devs[0]); 11884 11885 /* Launch a thread */ 11886 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 11887 rte_get_next_lcore(-1, 1, 0)); 11888 11889 /* Wait until reader exited. */ 11890 rte_eal_mp_wait_lcore(); 11891 11892 /* Test with invalid crypto device */ 11893 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 11894 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 11895 "Expected call to fail as crypto device is invalid"); 11896 11897 /* Test with invalid queue pair */ 11898 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 11899 ts_params->valid_devs[0], 11900 dev_info.max_nb_queue_pairs + 1, cb), 11901 "Expected call to fail as queue pair is invalid"); 11902 11903 /* Test with NULL callback */ 11904 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 11905 ts_params->valid_devs[0], qp_id, NULL), 11906 "Expected call to fail as callback is NULL"); 11907 11908 /* Test with valid configuration */ 11909 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback( 11910 ts_params->valid_devs[0], qp_id, cb), 11911 "Failed test to remove callback on " 11912 "qp %u on cryptodev %u", 11913 qp_id, ts_params->valid_devs[0]); 11914 11915 return TEST_SUCCESS; 11916 } 11917 11918 static int 11919 test_deq_callback_setup(void) 11920 { 11921 struct crypto_testsuite_params *ts_params = &testsuite_params; 11922 struct rte_cryptodev_info dev_info; 11923 struct rte_cryptodev_qp_conf qp_conf = { 11924 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 11925 }; 11926 11927 struct rte_cryptodev_cb *cb; 11928 uint16_t qp_id = 0; 11929 11930 /* Stop the device in case it's started so it can be configured */ 11931 rte_cryptodev_stop(ts_params->valid_devs[0]); 11932 11933 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11934 11935 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 11936 &ts_params->conf), 11937 "Failed to configure cryptodev %u", 11938 ts_params->valid_devs[0]); 11939 11940 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 11941 qp_conf.mp_session = ts_params->session_mpool; 11942 qp_conf.mp_session_private = ts_params->session_priv_mpool; 11943 11944 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 11945 ts_params->valid_devs[0], qp_id, &qp_conf, 11946 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 11947 "Failed test for " 11948 "rte_cryptodev_queue_pair_setup: num_inflights " 11949 "%u on qp %u on cryptodev %u", 11950 qp_conf.nb_descriptors, qp_id, 11951 ts_params->valid_devs[0]); 11952 11953 /* Test with invalid crypto device */ 11954 cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS, 11955 qp_id, test_deq_callback, NULL); 11956 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11957 "cryptodev %u did not fail", 11958 qp_id, RTE_CRYPTO_MAX_DEVS); 11959 11960 /* Test with invalid queue pair */ 11961 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 11962 dev_info.max_nb_queue_pairs + 1, 11963 test_deq_callback, NULL); 11964 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11965 "cryptodev %u did not fail", 11966 dev_info.max_nb_queue_pairs + 1, 11967 ts_params->valid_devs[0]); 11968 11969 /* Test with NULL callback */ 11970 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 11971 qp_id, NULL, NULL); 11972 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 11973 "cryptodev %u did not fail", 11974 qp_id, ts_params->valid_devs[0]); 11975 11976 /* Test with valid configuration */ 11977 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 11978 qp_id, test_deq_callback, NULL); 11979 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 11980 "qp %u on cryptodev %u", 11981 qp_id, ts_params->valid_devs[0]); 11982 11983 rte_cryptodev_start(ts_params->valid_devs[0]); 11984 11985 /* Launch a thread */ 11986 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 11987 rte_get_next_lcore(-1, 1, 0)); 11988 11989 /* Wait until reader exited. */ 11990 rte_eal_mp_wait_lcore(); 11991 11992 /* Test with invalid crypto device */ 11993 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 11994 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 11995 "Expected call to fail as crypto device is invalid"); 11996 11997 /* Test with invalid queue pair */ 11998 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 11999 ts_params->valid_devs[0], 12000 dev_info.max_nb_queue_pairs + 1, cb), 12001 "Expected call to fail as queue pair is invalid"); 12002 12003 /* Test with NULL callback */ 12004 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 12005 ts_params->valid_devs[0], qp_id, NULL), 12006 "Expected call to fail as callback is NULL"); 12007 12008 /* Test with valid configuration */ 12009 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback( 12010 ts_params->valid_devs[0], qp_id, cb), 12011 "Failed test to remove callback on " 12012 "qp %u on cryptodev %u", 12013 qp_id, ts_params->valid_devs[0]); 12014 12015 return TEST_SUCCESS; 12016 } 12017 12018 static void 12019 generate_gmac_large_plaintext(uint8_t *data) 12020 { 12021 uint16_t i; 12022 12023 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 12024 memcpy(&data[i], &data[0], 32); 12025 } 12026 12027 static int 12028 create_gmac_operation(enum rte_crypto_auth_operation op, 12029 const struct gmac_test_data *tdata) 12030 { 12031 struct crypto_testsuite_params *ts_params = &testsuite_params; 12032 struct crypto_unittest_params *ut_params = &unittest_params; 12033 struct rte_crypto_sym_op *sym_op; 12034 12035 uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12036 12037 /* Generate Crypto op data structure */ 12038 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12039 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12040 TEST_ASSERT_NOT_NULL(ut_params->op, 12041 "Failed to allocate symmetric crypto operation struct"); 12042 12043 sym_op = ut_params->op->sym; 12044 12045 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12046 ut_params->ibuf, tdata->gmac_tag.len); 12047 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12048 "no room to append digest"); 12049 12050 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12051 ut_params->ibuf, plaintext_pad_len); 12052 12053 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 12054 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 12055 tdata->gmac_tag.len); 12056 debug_hexdump(stdout, "digest:", 12057 sym_op->auth.digest.data, 12058 tdata->gmac_tag.len); 12059 } 12060 12061 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12062 uint8_t *, IV_OFFSET); 12063 12064 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 12065 12066 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 12067 12068 sym_op->cipher.data.length = 0; 12069 sym_op->cipher.data.offset = 0; 12070 12071 sym_op->auth.data.offset = 0; 12072 sym_op->auth.data.length = tdata->plaintext.len; 12073 12074 return 0; 12075 } 12076 12077 static int 12078 create_gmac_operation_sgl(enum rte_crypto_auth_operation op, 12079 const struct gmac_test_data *tdata, 12080 void *digest_mem, uint64_t digest_phys) 12081 { 12082 struct crypto_testsuite_params *ts_params = &testsuite_params; 12083 struct crypto_unittest_params *ut_params = &unittest_params; 12084 struct rte_crypto_sym_op *sym_op; 12085 12086 /* Generate Crypto op data structure */ 12087 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12088 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12089 TEST_ASSERT_NOT_NULL(ut_params->op, 12090 "Failed to allocate symmetric crypto operation struct"); 12091 12092 sym_op = ut_params->op->sym; 12093 12094 sym_op->auth.digest.data = digest_mem; 12095 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12096 "no room to append digest"); 12097 12098 sym_op->auth.digest.phys_addr = digest_phys; 12099 12100 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 12101 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 12102 tdata->gmac_tag.len); 12103 debug_hexdump(stdout, "digest:", 12104 sym_op->auth.digest.data, 12105 tdata->gmac_tag.len); 12106 } 12107 12108 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12109 uint8_t *, IV_OFFSET); 12110 12111 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 12112 12113 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 12114 12115 sym_op->cipher.data.length = 0; 12116 sym_op->cipher.data.offset = 0; 12117 12118 sym_op->auth.data.offset = 0; 12119 sym_op->auth.data.length = tdata->plaintext.len; 12120 12121 return 0; 12122 } 12123 12124 static int create_gmac_session(uint8_t dev_id, 12125 const struct gmac_test_data *tdata, 12126 enum rte_crypto_auth_operation auth_op) 12127 { 12128 uint8_t auth_key[tdata->key.len]; 12129 12130 struct crypto_testsuite_params *ts_params = &testsuite_params; 12131 struct crypto_unittest_params *ut_params = &unittest_params; 12132 12133 memcpy(auth_key, tdata->key.data, tdata->key.len); 12134 12135 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12136 ut_params->auth_xform.next = NULL; 12137 12138 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 12139 ut_params->auth_xform.auth.op = auth_op; 12140 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 12141 ut_params->auth_xform.auth.key.length = tdata->key.len; 12142 ut_params->auth_xform.auth.key.data = auth_key; 12143 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 12144 ut_params->auth_xform.auth.iv.length = tdata->iv.len; 12145 12146 12147 ut_params->sess = rte_cryptodev_sym_session_create( 12148 ts_params->session_mpool); 12149 12150 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 12151 &ut_params->auth_xform, 12152 ts_params->session_priv_mpool); 12153 12154 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12155 12156 return 0; 12157 } 12158 12159 static int 12160 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 12161 { 12162 struct crypto_testsuite_params *ts_params = &testsuite_params; 12163 struct crypto_unittest_params *ut_params = &unittest_params; 12164 struct rte_cryptodev_info dev_info; 12165 12166 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12167 uint64_t feat_flags = dev_info.feature_flags; 12168 12169 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12170 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12171 printf("Device doesn't support RAW data-path APIs.\n"); 12172 return TEST_SKIPPED; 12173 } 12174 12175 int retval; 12176 12177 uint8_t *auth_tag, *plaintext; 12178 uint16_t plaintext_pad_len; 12179 12180 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 12181 "No GMAC length in the source data"); 12182 12183 /* Verify the capabilities */ 12184 struct rte_cryptodev_sym_capability_idx cap_idx; 12185 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12186 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 12187 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12188 &cap_idx) == NULL) 12189 return TEST_SKIPPED; 12190 12191 retval = create_gmac_session(ts_params->valid_devs[0], 12192 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 12193 12194 if (retval < 0) 12195 return retval; 12196 12197 if (tdata->plaintext.len > MBUF_SIZE) 12198 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 12199 else 12200 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12201 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12202 "Failed to allocate input buffer in mempool"); 12203 12204 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12205 rte_pktmbuf_tailroom(ut_params->ibuf)); 12206 12207 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12208 /* 12209 * Runtime generate the large plain text instead of use hard code 12210 * plain text vector. It is done to avoid create huge source file 12211 * with the test vector. 12212 */ 12213 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 12214 generate_gmac_large_plaintext(tdata->plaintext.data); 12215 12216 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12217 plaintext_pad_len); 12218 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12219 12220 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 12221 debug_hexdump(stdout, "plaintext:", plaintext, 12222 tdata->plaintext.len); 12223 12224 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 12225 tdata); 12226 12227 if (retval < 0) 12228 return retval; 12229 12230 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12231 12232 ut_params->op->sym->m_src = ut_params->ibuf; 12233 12234 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12235 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12236 ut_params->op); 12237 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12238 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12239 ut_params->op, 0, 1, 0, 0); 12240 else 12241 TEST_ASSERT_NOT_NULL( 12242 process_crypto_request(ts_params->valid_devs[0], 12243 ut_params->op), "failed to process sym crypto op"); 12244 12245 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12246 "crypto op processing failed"); 12247 12248 if (ut_params->op->sym->m_dst) { 12249 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 12250 uint8_t *, plaintext_pad_len); 12251 } else { 12252 auth_tag = plaintext + plaintext_pad_len; 12253 } 12254 12255 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 12256 12257 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12258 auth_tag, 12259 tdata->gmac_tag.data, 12260 tdata->gmac_tag.len, 12261 "GMAC Generated auth tag not as expected"); 12262 12263 return 0; 12264 } 12265 12266 static int 12267 test_AES_GMAC_authentication_test_case_1(void) 12268 { 12269 return test_AES_GMAC_authentication(&gmac_test_case_1); 12270 } 12271 12272 static int 12273 test_AES_GMAC_authentication_test_case_2(void) 12274 { 12275 return test_AES_GMAC_authentication(&gmac_test_case_2); 12276 } 12277 12278 static int 12279 test_AES_GMAC_authentication_test_case_3(void) 12280 { 12281 return test_AES_GMAC_authentication(&gmac_test_case_3); 12282 } 12283 12284 static int 12285 test_AES_GMAC_authentication_test_case_4(void) 12286 { 12287 return test_AES_GMAC_authentication(&gmac_test_case_4); 12288 } 12289 12290 static int 12291 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 12292 { 12293 struct crypto_testsuite_params *ts_params = &testsuite_params; 12294 struct crypto_unittest_params *ut_params = &unittest_params; 12295 int retval; 12296 uint32_t plaintext_pad_len; 12297 uint8_t *plaintext; 12298 struct rte_cryptodev_info dev_info; 12299 12300 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12301 uint64_t feat_flags = dev_info.feature_flags; 12302 12303 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12304 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12305 printf("Device doesn't support RAW data-path APIs.\n"); 12306 return TEST_SKIPPED; 12307 } 12308 12309 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 12310 "No GMAC length in the source data"); 12311 12312 /* Verify the capabilities */ 12313 struct rte_cryptodev_sym_capability_idx cap_idx; 12314 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12315 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 12316 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12317 &cap_idx) == NULL) 12318 return TEST_SKIPPED; 12319 12320 retval = create_gmac_session(ts_params->valid_devs[0], 12321 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 12322 12323 if (retval < 0) 12324 return retval; 12325 12326 if (tdata->plaintext.len > MBUF_SIZE) 12327 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 12328 else 12329 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12330 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12331 "Failed to allocate input buffer in mempool"); 12332 12333 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12334 rte_pktmbuf_tailroom(ut_params->ibuf)); 12335 12336 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12337 12338 /* 12339 * Runtime generate the large plain text instead of use hard code 12340 * plain text vector. It is done to avoid create huge source file 12341 * with the test vector. 12342 */ 12343 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 12344 generate_gmac_large_plaintext(tdata->plaintext.data); 12345 12346 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12347 plaintext_pad_len); 12348 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12349 12350 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 12351 debug_hexdump(stdout, "plaintext:", plaintext, 12352 tdata->plaintext.len); 12353 12354 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 12355 tdata); 12356 12357 if (retval < 0) 12358 return retval; 12359 12360 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12361 12362 ut_params->op->sym->m_src = ut_params->ibuf; 12363 12364 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12365 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12366 ut_params->op); 12367 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12368 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12369 ut_params->op, 0, 1, 0, 0); 12370 else 12371 TEST_ASSERT_NOT_NULL( 12372 process_crypto_request(ts_params->valid_devs[0], 12373 ut_params->op), "failed to process sym crypto op"); 12374 12375 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12376 "crypto op processing failed"); 12377 12378 return 0; 12379 12380 } 12381 12382 static int 12383 test_AES_GMAC_authentication_verify_test_case_1(void) 12384 { 12385 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 12386 } 12387 12388 static int 12389 test_AES_GMAC_authentication_verify_test_case_2(void) 12390 { 12391 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 12392 } 12393 12394 static int 12395 test_AES_GMAC_authentication_verify_test_case_3(void) 12396 { 12397 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 12398 } 12399 12400 static int 12401 test_AES_GMAC_authentication_verify_test_case_4(void) 12402 { 12403 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 12404 } 12405 12406 static int 12407 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata, 12408 uint32_t fragsz) 12409 { 12410 struct crypto_testsuite_params *ts_params = &testsuite_params; 12411 struct crypto_unittest_params *ut_params = &unittest_params; 12412 struct rte_cryptodev_info dev_info; 12413 uint64_t feature_flags; 12414 unsigned int trn_data = 0; 12415 void *digest_mem = NULL; 12416 uint32_t segs = 1; 12417 unsigned int to_trn = 0; 12418 struct rte_mbuf *buf = NULL; 12419 uint8_t *auth_tag, *plaintext; 12420 int retval; 12421 12422 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 12423 "No GMAC length in the source data"); 12424 12425 /* Verify the capabilities */ 12426 struct rte_cryptodev_sym_capability_idx cap_idx; 12427 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12428 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 12429 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12430 &cap_idx) == NULL) 12431 return TEST_SKIPPED; 12432 12433 /* Check for any input SGL support */ 12434 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12435 feature_flags = dev_info.feature_flags; 12436 12437 if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) || 12438 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) || 12439 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))) 12440 return TEST_SKIPPED; 12441 12442 if (fragsz > tdata->plaintext.len) 12443 fragsz = tdata->plaintext.len; 12444 12445 uint16_t plaintext_len = fragsz; 12446 12447 retval = create_gmac_session(ts_params->valid_devs[0], 12448 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 12449 12450 if (retval < 0) 12451 return retval; 12452 12453 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12454 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12455 "Failed to allocate input buffer in mempool"); 12456 12457 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12458 rte_pktmbuf_tailroom(ut_params->ibuf)); 12459 12460 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12461 plaintext_len); 12462 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12463 12464 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 12465 12466 trn_data += plaintext_len; 12467 12468 buf = ut_params->ibuf; 12469 12470 /* 12471 * Loop until no more fragments 12472 */ 12473 12474 while (trn_data < tdata->plaintext.len) { 12475 ++segs; 12476 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 12477 (tdata->plaintext.len - trn_data) : fragsz; 12478 12479 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12480 buf = buf->next; 12481 12482 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 12483 rte_pktmbuf_tailroom(buf)); 12484 12485 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 12486 to_trn); 12487 12488 memcpy(plaintext, tdata->plaintext.data + trn_data, 12489 to_trn); 12490 trn_data += to_trn; 12491 if (trn_data == tdata->plaintext.len) 12492 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 12493 tdata->gmac_tag.len); 12494 } 12495 ut_params->ibuf->nb_segs = segs; 12496 12497 /* 12498 * Place digest at the end of the last buffer 12499 */ 12500 uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn; 12501 12502 if (!digest_mem) { 12503 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12504 + tdata->gmac_tag.len); 12505 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 12506 tdata->plaintext.len); 12507 } 12508 12509 retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE, 12510 tdata, digest_mem, digest_phys); 12511 12512 if (retval < 0) 12513 return retval; 12514 12515 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12516 12517 ut_params->op->sym->m_src = ut_params->ibuf; 12518 12519 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12520 return TEST_SKIPPED; 12521 12522 TEST_ASSERT_NOT_NULL( 12523 process_crypto_request(ts_params->valid_devs[0], 12524 ut_params->op), "failed to process sym crypto op"); 12525 12526 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12527 "crypto op processing failed"); 12528 12529 auth_tag = digest_mem; 12530 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 12531 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12532 auth_tag, 12533 tdata->gmac_tag.data, 12534 tdata->gmac_tag.len, 12535 "GMAC Generated auth tag not as expected"); 12536 12537 return 0; 12538 } 12539 12540 /* Segment size not multiple of block size (16B) */ 12541 static int 12542 test_AES_GMAC_authentication_SGL_40B(void) 12543 { 12544 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40); 12545 } 12546 12547 static int 12548 test_AES_GMAC_authentication_SGL_80B(void) 12549 { 12550 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80); 12551 } 12552 12553 static int 12554 test_AES_GMAC_authentication_SGL_2048B(void) 12555 { 12556 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048); 12557 } 12558 12559 /* Segment size not multiple of block size (16B) */ 12560 static int 12561 test_AES_GMAC_authentication_SGL_2047B(void) 12562 { 12563 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047); 12564 } 12565 12566 struct test_crypto_vector { 12567 enum rte_crypto_cipher_algorithm crypto_algo; 12568 unsigned int cipher_offset; 12569 unsigned int cipher_len; 12570 12571 struct { 12572 uint8_t data[64]; 12573 unsigned int len; 12574 } cipher_key; 12575 12576 struct { 12577 uint8_t data[64]; 12578 unsigned int len; 12579 } iv; 12580 12581 struct { 12582 const uint8_t *data; 12583 unsigned int len; 12584 } plaintext; 12585 12586 struct { 12587 const uint8_t *data; 12588 unsigned int len; 12589 } ciphertext; 12590 12591 enum rte_crypto_auth_algorithm auth_algo; 12592 unsigned int auth_offset; 12593 12594 struct { 12595 uint8_t data[128]; 12596 unsigned int len; 12597 } auth_key; 12598 12599 struct { 12600 const uint8_t *data; 12601 unsigned int len; 12602 } aad; 12603 12604 struct { 12605 uint8_t data[128]; 12606 unsigned int len; 12607 } digest; 12608 }; 12609 12610 static const struct test_crypto_vector 12611 hmac_sha1_test_crypto_vector = { 12612 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 12613 .plaintext = { 12614 .data = plaintext_hash, 12615 .len = 512 12616 }, 12617 .auth_key = { 12618 .data = { 12619 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 12620 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 12621 0xDE, 0xF4, 0xDE, 0xAD 12622 }, 12623 .len = 20 12624 }, 12625 .digest = { 12626 .data = { 12627 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 12628 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 12629 0x3F, 0x91, 0x64, 0x59 12630 }, 12631 .len = 20 12632 } 12633 }; 12634 12635 static const struct test_crypto_vector 12636 aes128_gmac_test_vector = { 12637 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 12638 .plaintext = { 12639 .data = plaintext_hash, 12640 .len = 512 12641 }, 12642 .iv = { 12643 .data = { 12644 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 12645 0x08, 0x09, 0x0A, 0x0B 12646 }, 12647 .len = 12 12648 }, 12649 .auth_key = { 12650 .data = { 12651 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 12652 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 12653 }, 12654 .len = 16 12655 }, 12656 .digest = { 12657 .data = { 12658 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 12659 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 12660 }, 12661 .len = 16 12662 } 12663 }; 12664 12665 static const struct test_crypto_vector 12666 aes128cbc_hmac_sha1_test_vector = { 12667 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 12668 .cipher_offset = 0, 12669 .cipher_len = 512, 12670 .cipher_key = { 12671 .data = { 12672 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 12673 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 12674 }, 12675 .len = 16 12676 }, 12677 .iv = { 12678 .data = { 12679 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 12680 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 12681 }, 12682 .len = 16 12683 }, 12684 .plaintext = { 12685 .data = plaintext_hash, 12686 .len = 512 12687 }, 12688 .ciphertext = { 12689 .data = ciphertext512_aes128cbc, 12690 .len = 512 12691 }, 12692 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 12693 .auth_offset = 0, 12694 .auth_key = { 12695 .data = { 12696 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 12697 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 12698 0xDE, 0xF4, 0xDE, 0xAD 12699 }, 12700 .len = 20 12701 }, 12702 .digest = { 12703 .data = { 12704 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 12705 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 12706 0x18, 0x8C, 0x1D, 0x32 12707 }, 12708 .len = 20 12709 } 12710 }; 12711 12712 static const struct test_crypto_vector 12713 aes128cbc_hmac_sha1_aad_test_vector = { 12714 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 12715 .cipher_offset = 8, 12716 .cipher_len = 496, 12717 .cipher_key = { 12718 .data = { 12719 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 12720 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 12721 }, 12722 .len = 16 12723 }, 12724 .iv = { 12725 .data = { 12726 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 12727 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 12728 }, 12729 .len = 16 12730 }, 12731 .plaintext = { 12732 .data = plaintext_hash, 12733 .len = 512 12734 }, 12735 .ciphertext = { 12736 .data = ciphertext512_aes128cbc_aad, 12737 .len = 512 12738 }, 12739 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 12740 .auth_offset = 0, 12741 .auth_key = { 12742 .data = { 12743 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 12744 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 12745 0xDE, 0xF4, 0xDE, 0xAD 12746 }, 12747 .len = 20 12748 }, 12749 .digest = { 12750 .data = { 12751 0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F, 12752 0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B, 12753 0x62, 0x0F, 0xFB, 0x10 12754 }, 12755 .len = 20 12756 } 12757 }; 12758 12759 static void 12760 data_corruption(uint8_t *data) 12761 { 12762 data[0] += 1; 12763 } 12764 12765 static void 12766 tag_corruption(uint8_t *data, unsigned int tag_offset) 12767 { 12768 data[tag_offset] += 1; 12769 } 12770 12771 static int 12772 create_auth_session(struct crypto_unittest_params *ut_params, 12773 uint8_t dev_id, 12774 const struct test_crypto_vector *reference, 12775 enum rte_crypto_auth_operation auth_op) 12776 { 12777 struct crypto_testsuite_params *ts_params = &testsuite_params; 12778 uint8_t auth_key[reference->auth_key.len + 1]; 12779 12780 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 12781 12782 /* Setup Authentication Parameters */ 12783 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12784 ut_params->auth_xform.auth.op = auth_op; 12785 ut_params->auth_xform.next = NULL; 12786 ut_params->auth_xform.auth.algo = reference->auth_algo; 12787 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 12788 ut_params->auth_xform.auth.key.data = auth_key; 12789 ut_params->auth_xform.auth.digest_length = reference->digest.len; 12790 12791 /* Create Crypto session*/ 12792 ut_params->sess = rte_cryptodev_sym_session_create( 12793 ts_params->session_mpool); 12794 12795 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 12796 &ut_params->auth_xform, 12797 ts_params->session_priv_mpool); 12798 12799 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12800 12801 return 0; 12802 } 12803 12804 static int 12805 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 12806 uint8_t dev_id, 12807 const struct test_crypto_vector *reference, 12808 enum rte_crypto_auth_operation auth_op, 12809 enum rte_crypto_cipher_operation cipher_op) 12810 { 12811 struct crypto_testsuite_params *ts_params = &testsuite_params; 12812 uint8_t cipher_key[reference->cipher_key.len + 1]; 12813 uint8_t auth_key[reference->auth_key.len + 1]; 12814 12815 memcpy(cipher_key, reference->cipher_key.data, 12816 reference->cipher_key.len); 12817 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 12818 12819 /* Setup Authentication Parameters */ 12820 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12821 ut_params->auth_xform.auth.op = auth_op; 12822 ut_params->auth_xform.auth.algo = reference->auth_algo; 12823 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 12824 ut_params->auth_xform.auth.key.data = auth_key; 12825 ut_params->auth_xform.auth.digest_length = reference->digest.len; 12826 12827 if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) { 12828 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 12829 ut_params->auth_xform.auth.iv.length = reference->iv.len; 12830 } else { 12831 ut_params->auth_xform.next = &ut_params->cipher_xform; 12832 12833 /* Setup Cipher Parameters */ 12834 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12835 ut_params->cipher_xform.next = NULL; 12836 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 12837 ut_params->cipher_xform.cipher.op = cipher_op; 12838 ut_params->cipher_xform.cipher.key.data = cipher_key; 12839 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 12840 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 12841 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 12842 } 12843 12844 /* Create Crypto session*/ 12845 ut_params->sess = rte_cryptodev_sym_session_create( 12846 ts_params->session_mpool); 12847 12848 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 12849 &ut_params->auth_xform, 12850 ts_params->session_priv_mpool); 12851 12852 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12853 12854 return 0; 12855 } 12856 12857 static int 12858 create_auth_operation(struct crypto_testsuite_params *ts_params, 12859 struct crypto_unittest_params *ut_params, 12860 const struct test_crypto_vector *reference, 12861 unsigned int auth_generate) 12862 { 12863 /* Generate Crypto op data structure */ 12864 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12865 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12866 TEST_ASSERT_NOT_NULL(ut_params->op, 12867 "Failed to allocate pktmbuf offload"); 12868 12869 /* Set crypto operation data parameters */ 12870 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12871 12872 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12873 12874 /* set crypto operation source mbuf */ 12875 sym_op->m_src = ut_params->ibuf; 12876 12877 /* digest */ 12878 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12879 ut_params->ibuf, reference->digest.len); 12880 12881 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12882 "no room to append auth tag"); 12883 12884 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12885 ut_params->ibuf, reference->plaintext.len); 12886 12887 if (auth_generate) 12888 memset(sym_op->auth.digest.data, 0, reference->digest.len); 12889 else 12890 memcpy(sym_op->auth.digest.data, 12891 reference->digest.data, 12892 reference->digest.len); 12893 12894 debug_hexdump(stdout, "digest:", 12895 sym_op->auth.digest.data, 12896 reference->digest.len); 12897 12898 sym_op->auth.data.length = reference->plaintext.len; 12899 sym_op->auth.data.offset = 0; 12900 12901 return 0; 12902 } 12903 12904 static int 12905 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 12906 struct crypto_unittest_params *ut_params, 12907 const struct test_crypto_vector *reference, 12908 unsigned int auth_generate) 12909 { 12910 /* Generate Crypto op data structure */ 12911 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12912 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12913 TEST_ASSERT_NOT_NULL(ut_params->op, 12914 "Failed to allocate pktmbuf offload"); 12915 12916 /* Set crypto operation data parameters */ 12917 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12918 12919 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12920 12921 /* set crypto operation source mbuf */ 12922 sym_op->m_src = ut_params->ibuf; 12923 12924 /* digest */ 12925 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12926 ut_params->ibuf, reference->digest.len); 12927 12928 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12929 "no room to append auth tag"); 12930 12931 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12932 ut_params->ibuf, reference->ciphertext.len); 12933 12934 if (auth_generate) 12935 memset(sym_op->auth.digest.data, 0, reference->digest.len); 12936 else 12937 memcpy(sym_op->auth.digest.data, 12938 reference->digest.data, 12939 reference->digest.len); 12940 12941 debug_hexdump(stdout, "digest:", 12942 sym_op->auth.digest.data, 12943 reference->digest.len); 12944 12945 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 12946 reference->iv.data, reference->iv.len); 12947 12948 sym_op->cipher.data.length = 0; 12949 sym_op->cipher.data.offset = 0; 12950 12951 sym_op->auth.data.length = reference->plaintext.len; 12952 sym_op->auth.data.offset = 0; 12953 12954 return 0; 12955 } 12956 12957 static int 12958 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 12959 struct crypto_unittest_params *ut_params, 12960 const struct test_crypto_vector *reference, 12961 unsigned int auth_generate) 12962 { 12963 /* Generate Crypto op data structure */ 12964 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12965 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12966 TEST_ASSERT_NOT_NULL(ut_params->op, 12967 "Failed to allocate pktmbuf offload"); 12968 12969 /* Set crypto operation data parameters */ 12970 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12971 12972 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12973 12974 /* set crypto operation source mbuf */ 12975 sym_op->m_src = ut_params->ibuf; 12976 12977 /* digest */ 12978 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12979 ut_params->ibuf, reference->digest.len); 12980 12981 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12982 "no room to append auth tag"); 12983 12984 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12985 ut_params->ibuf, reference->ciphertext.len); 12986 12987 if (auth_generate) 12988 memset(sym_op->auth.digest.data, 0, reference->digest.len); 12989 else 12990 memcpy(sym_op->auth.digest.data, 12991 reference->digest.data, 12992 reference->digest.len); 12993 12994 debug_hexdump(stdout, "digest:", 12995 sym_op->auth.digest.data, 12996 reference->digest.len); 12997 12998 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 12999 reference->iv.data, reference->iv.len); 13000 13001 sym_op->cipher.data.length = reference->cipher_len; 13002 sym_op->cipher.data.offset = reference->cipher_offset; 13003 13004 sym_op->auth.data.length = reference->plaintext.len; 13005 sym_op->auth.data.offset = reference->auth_offset; 13006 13007 return 0; 13008 } 13009 13010 static int 13011 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 13012 struct crypto_unittest_params *ut_params, 13013 const struct test_crypto_vector *reference) 13014 { 13015 return create_auth_operation(ts_params, ut_params, reference, 0); 13016 } 13017 13018 static int 13019 create_auth_verify_GMAC_operation( 13020 struct crypto_testsuite_params *ts_params, 13021 struct crypto_unittest_params *ut_params, 13022 const struct test_crypto_vector *reference) 13023 { 13024 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 13025 } 13026 13027 static int 13028 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params, 13029 struct crypto_unittest_params *ut_params, 13030 const struct test_crypto_vector *reference) 13031 { 13032 return create_cipher_auth_operation(ts_params, ut_params, reference, 0); 13033 } 13034 13035 static int 13036 test_authentication_verify_fail_when_data_corruption( 13037 struct crypto_testsuite_params *ts_params, 13038 struct crypto_unittest_params *ut_params, 13039 const struct test_crypto_vector *reference, 13040 unsigned int data_corrupted) 13041 { 13042 int retval; 13043 13044 uint8_t *plaintext; 13045 struct rte_cryptodev_info dev_info; 13046 13047 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13048 uint64_t feat_flags = dev_info.feature_flags; 13049 13050 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13051 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13052 printf("Device doesn't support RAW data-path APIs.\n"); 13053 return TEST_SKIPPED; 13054 } 13055 13056 /* Verify the capabilities */ 13057 struct rte_cryptodev_sym_capability_idx cap_idx; 13058 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13059 cap_idx.algo.auth = reference->auth_algo; 13060 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13061 &cap_idx) == NULL) 13062 return TEST_SKIPPED; 13063 13064 13065 /* Create session */ 13066 retval = create_auth_session(ut_params, 13067 ts_params->valid_devs[0], 13068 reference, 13069 RTE_CRYPTO_AUTH_OP_VERIFY); 13070 if (retval < 0) 13071 return retval; 13072 13073 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13074 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13075 "Failed to allocate input buffer in mempool"); 13076 13077 /* clear mbuf payload */ 13078 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13079 rte_pktmbuf_tailroom(ut_params->ibuf)); 13080 13081 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13082 reference->plaintext.len); 13083 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13084 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 13085 13086 debug_hexdump(stdout, "plaintext:", plaintext, 13087 reference->plaintext.len); 13088 13089 /* Create operation */ 13090 retval = create_auth_verify_operation(ts_params, ut_params, reference); 13091 13092 if (retval < 0) 13093 return retval; 13094 13095 if (data_corrupted) 13096 data_corruption(plaintext); 13097 else 13098 tag_corruption(plaintext, reference->plaintext.len); 13099 13100 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13101 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13102 ut_params->op); 13103 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13104 RTE_CRYPTO_OP_STATUS_SUCCESS, 13105 "authentication not failed"); 13106 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13107 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13108 ut_params->op, 0, 1, 0, 0); 13109 else { 13110 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13111 ut_params->op); 13112 } 13113 if (ut_params->op == NULL) 13114 return 0; 13115 else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) 13116 return 0; 13117 13118 return -1; 13119 } 13120 13121 static int 13122 test_authentication_verify_GMAC_fail_when_corruption( 13123 struct crypto_testsuite_params *ts_params, 13124 struct crypto_unittest_params *ut_params, 13125 const struct test_crypto_vector *reference, 13126 unsigned int data_corrupted) 13127 { 13128 int retval; 13129 uint8_t *plaintext; 13130 struct rte_cryptodev_info dev_info; 13131 13132 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13133 uint64_t feat_flags = dev_info.feature_flags; 13134 13135 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13136 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13137 printf("Device doesn't support RAW data-path APIs.\n"); 13138 return TEST_SKIPPED; 13139 } 13140 13141 /* Verify the capabilities */ 13142 struct rte_cryptodev_sym_capability_idx cap_idx; 13143 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13144 cap_idx.algo.auth = reference->auth_algo; 13145 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13146 &cap_idx) == NULL) 13147 return TEST_SKIPPED; 13148 13149 /* Create session */ 13150 retval = create_auth_cipher_session(ut_params, 13151 ts_params->valid_devs[0], 13152 reference, 13153 RTE_CRYPTO_AUTH_OP_VERIFY, 13154 RTE_CRYPTO_CIPHER_OP_DECRYPT); 13155 if (retval < 0) 13156 return retval; 13157 13158 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13159 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13160 "Failed to allocate input buffer in mempool"); 13161 13162 /* clear mbuf payload */ 13163 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13164 rte_pktmbuf_tailroom(ut_params->ibuf)); 13165 13166 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13167 reference->plaintext.len); 13168 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13169 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 13170 13171 debug_hexdump(stdout, "plaintext:", plaintext, 13172 reference->plaintext.len); 13173 13174 /* Create operation */ 13175 retval = create_auth_verify_GMAC_operation(ts_params, 13176 ut_params, 13177 reference); 13178 13179 if (retval < 0) 13180 return retval; 13181 13182 if (data_corrupted) 13183 data_corruption(plaintext); 13184 else 13185 tag_corruption(plaintext, reference->aad.len); 13186 13187 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13188 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13189 ut_params->op); 13190 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13191 RTE_CRYPTO_OP_STATUS_SUCCESS, 13192 "authentication not failed"); 13193 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13194 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13195 ut_params->op, 0, 1, 0, 0); 13196 else { 13197 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13198 ut_params->op); 13199 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 13200 } 13201 13202 return 0; 13203 } 13204 13205 static int 13206 test_authenticated_decryption_fail_when_corruption( 13207 struct crypto_testsuite_params *ts_params, 13208 struct crypto_unittest_params *ut_params, 13209 const struct test_crypto_vector *reference, 13210 unsigned int data_corrupted) 13211 { 13212 int retval; 13213 13214 uint8_t *ciphertext; 13215 struct rte_cryptodev_info dev_info; 13216 13217 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13218 uint64_t feat_flags = dev_info.feature_flags; 13219 13220 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13221 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13222 printf("Device doesn't support RAW data-path APIs.\n"); 13223 return TEST_SKIPPED; 13224 } 13225 13226 /* Verify the capabilities */ 13227 struct rte_cryptodev_sym_capability_idx cap_idx; 13228 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13229 cap_idx.algo.auth = reference->auth_algo; 13230 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13231 &cap_idx) == NULL) 13232 return TEST_SKIPPED; 13233 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13234 cap_idx.algo.cipher = reference->crypto_algo; 13235 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13236 &cap_idx) == NULL) 13237 return TEST_SKIPPED; 13238 13239 /* Create session */ 13240 retval = create_auth_cipher_session(ut_params, 13241 ts_params->valid_devs[0], 13242 reference, 13243 RTE_CRYPTO_AUTH_OP_VERIFY, 13244 RTE_CRYPTO_CIPHER_OP_DECRYPT); 13245 if (retval < 0) 13246 return retval; 13247 13248 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13249 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13250 "Failed to allocate input buffer in mempool"); 13251 13252 /* clear mbuf payload */ 13253 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13254 rte_pktmbuf_tailroom(ut_params->ibuf)); 13255 13256 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13257 reference->ciphertext.len); 13258 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 13259 memcpy(ciphertext, reference->ciphertext.data, 13260 reference->ciphertext.len); 13261 13262 /* Create operation */ 13263 retval = create_cipher_auth_verify_operation(ts_params, 13264 ut_params, 13265 reference); 13266 13267 if (retval < 0) 13268 return retval; 13269 13270 if (data_corrupted) 13271 data_corruption(ciphertext); 13272 else 13273 tag_corruption(ciphertext, reference->ciphertext.len); 13274 13275 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13276 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13277 ut_params->op); 13278 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13279 RTE_CRYPTO_OP_STATUS_SUCCESS, 13280 "authentication not failed"); 13281 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13282 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13283 ut_params->op, 1, 1, 0, 0); 13284 else { 13285 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13286 ut_params->op); 13287 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 13288 } 13289 13290 return 0; 13291 } 13292 13293 static int 13294 test_authenticated_encrypt_with_esn( 13295 struct crypto_testsuite_params *ts_params, 13296 struct crypto_unittest_params *ut_params, 13297 const struct test_crypto_vector *reference) 13298 { 13299 int retval; 13300 13301 uint8_t *authciphertext, *plaintext, *auth_tag; 13302 uint16_t plaintext_pad_len; 13303 uint8_t cipher_key[reference->cipher_key.len + 1]; 13304 uint8_t auth_key[reference->auth_key.len + 1]; 13305 struct rte_cryptodev_info dev_info; 13306 13307 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13308 uint64_t feat_flags = dev_info.feature_flags; 13309 13310 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13311 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13312 printf("Device doesn't support RAW data-path APIs.\n"); 13313 return TEST_SKIPPED; 13314 } 13315 13316 /* Verify the capabilities */ 13317 struct rte_cryptodev_sym_capability_idx cap_idx; 13318 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13319 cap_idx.algo.auth = reference->auth_algo; 13320 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13321 &cap_idx) == NULL) 13322 return TEST_SKIPPED; 13323 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13324 cap_idx.algo.cipher = reference->crypto_algo; 13325 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13326 &cap_idx) == NULL) 13327 return TEST_SKIPPED; 13328 13329 /* Create session */ 13330 memcpy(cipher_key, reference->cipher_key.data, 13331 reference->cipher_key.len); 13332 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 13333 13334 /* Setup Cipher Parameters */ 13335 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13336 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 13337 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 13338 ut_params->cipher_xform.cipher.key.data = cipher_key; 13339 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 13340 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 13341 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 13342 13343 ut_params->cipher_xform.next = &ut_params->auth_xform; 13344 13345 /* Setup Authentication Parameters */ 13346 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13347 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 13348 ut_params->auth_xform.auth.algo = reference->auth_algo; 13349 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 13350 ut_params->auth_xform.auth.key.data = auth_key; 13351 ut_params->auth_xform.auth.digest_length = reference->digest.len; 13352 ut_params->auth_xform.next = NULL; 13353 13354 /* Create Crypto session*/ 13355 ut_params->sess = rte_cryptodev_sym_session_create( 13356 ts_params->session_mpool); 13357 13358 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 13359 ut_params->sess, 13360 &ut_params->cipher_xform, 13361 ts_params->session_priv_mpool); 13362 13363 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13364 13365 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13366 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13367 "Failed to allocate input buffer in mempool"); 13368 13369 /* clear mbuf payload */ 13370 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13371 rte_pktmbuf_tailroom(ut_params->ibuf)); 13372 13373 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13374 reference->plaintext.len); 13375 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13376 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 13377 13378 /* Create operation */ 13379 retval = create_cipher_auth_operation(ts_params, 13380 ut_params, 13381 reference, 0); 13382 13383 if (retval < 0) 13384 return retval; 13385 13386 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13387 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13388 ut_params->op); 13389 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13390 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13391 ut_params->op, 1, 1, 0, 0); 13392 else 13393 ut_params->op = process_crypto_request( 13394 ts_params->valid_devs[0], ut_params->op); 13395 13396 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 13397 13398 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13399 "crypto op processing failed"); 13400 13401 plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16); 13402 13403 authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 13404 ut_params->op->sym->auth.data.offset); 13405 auth_tag = authciphertext + plaintext_pad_len; 13406 debug_hexdump(stdout, "ciphertext:", authciphertext, 13407 reference->ciphertext.len); 13408 debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len); 13409 13410 /* Validate obuf */ 13411 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13412 authciphertext, 13413 reference->ciphertext.data, 13414 reference->ciphertext.len, 13415 "Ciphertext data not as expected"); 13416 13417 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13418 auth_tag, 13419 reference->digest.data, 13420 reference->digest.len, 13421 "Generated digest not as expected"); 13422 13423 return TEST_SUCCESS; 13424 13425 } 13426 13427 static int 13428 test_authenticated_decrypt_with_esn( 13429 struct crypto_testsuite_params *ts_params, 13430 struct crypto_unittest_params *ut_params, 13431 const struct test_crypto_vector *reference) 13432 { 13433 int retval; 13434 13435 uint8_t *ciphertext; 13436 uint8_t cipher_key[reference->cipher_key.len + 1]; 13437 uint8_t auth_key[reference->auth_key.len + 1]; 13438 struct rte_cryptodev_info dev_info; 13439 13440 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13441 uint64_t feat_flags = dev_info.feature_flags; 13442 13443 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13444 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13445 printf("Device doesn't support RAW data-path APIs.\n"); 13446 return TEST_SKIPPED; 13447 } 13448 13449 /* Verify the capabilities */ 13450 struct rte_cryptodev_sym_capability_idx cap_idx; 13451 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13452 cap_idx.algo.auth = reference->auth_algo; 13453 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13454 &cap_idx) == NULL) 13455 return TEST_SKIPPED; 13456 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13457 cap_idx.algo.cipher = reference->crypto_algo; 13458 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13459 &cap_idx) == NULL) 13460 return TEST_SKIPPED; 13461 13462 /* Create session */ 13463 memcpy(cipher_key, reference->cipher_key.data, 13464 reference->cipher_key.len); 13465 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 13466 13467 /* Setup Authentication Parameters */ 13468 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13469 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 13470 ut_params->auth_xform.auth.algo = reference->auth_algo; 13471 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 13472 ut_params->auth_xform.auth.key.data = auth_key; 13473 ut_params->auth_xform.auth.digest_length = reference->digest.len; 13474 ut_params->auth_xform.next = &ut_params->cipher_xform; 13475 13476 /* Setup Cipher Parameters */ 13477 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13478 ut_params->cipher_xform.next = NULL; 13479 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 13480 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 13481 ut_params->cipher_xform.cipher.key.data = cipher_key; 13482 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 13483 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 13484 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 13485 13486 /* Create Crypto session*/ 13487 ut_params->sess = rte_cryptodev_sym_session_create( 13488 ts_params->session_mpool); 13489 13490 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 13491 ut_params->sess, 13492 &ut_params->auth_xform, 13493 ts_params->session_priv_mpool); 13494 13495 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13496 13497 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13498 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13499 "Failed to allocate input buffer in mempool"); 13500 13501 /* clear mbuf payload */ 13502 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13503 rte_pktmbuf_tailroom(ut_params->ibuf)); 13504 13505 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13506 reference->ciphertext.len); 13507 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 13508 memcpy(ciphertext, reference->ciphertext.data, 13509 reference->ciphertext.len); 13510 13511 /* Create operation */ 13512 retval = create_cipher_auth_verify_operation(ts_params, 13513 ut_params, 13514 reference); 13515 13516 if (retval < 0) 13517 return retval; 13518 13519 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13520 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13521 ut_params->op); 13522 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13523 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13524 ut_params->op, 1, 1, 0, 0); 13525 else 13526 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13527 ut_params->op); 13528 13529 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 13530 TEST_ASSERT_EQUAL(ut_params->op->status, 13531 RTE_CRYPTO_OP_STATUS_SUCCESS, 13532 "crypto op processing passed"); 13533 13534 ut_params->obuf = ut_params->op->sym->m_src; 13535 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 13536 13537 return 0; 13538 } 13539 13540 static int 13541 create_aead_operation_SGL(enum rte_crypto_aead_operation op, 13542 const struct aead_test_data *tdata, 13543 void *digest_mem, uint64_t digest_phys) 13544 { 13545 struct crypto_testsuite_params *ts_params = &testsuite_params; 13546 struct crypto_unittest_params *ut_params = &unittest_params; 13547 13548 const unsigned int auth_tag_len = tdata->auth_tag.len; 13549 const unsigned int iv_len = tdata->iv.len; 13550 unsigned int aad_len = tdata->aad.len; 13551 unsigned int aad_len_pad = 0; 13552 13553 /* Generate Crypto op data structure */ 13554 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13555 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13556 TEST_ASSERT_NOT_NULL(ut_params->op, 13557 "Failed to allocate symmetric crypto operation struct"); 13558 13559 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 13560 13561 sym_op->aead.digest.data = digest_mem; 13562 13563 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 13564 "no room to append digest"); 13565 13566 sym_op->aead.digest.phys_addr = digest_phys; 13567 13568 if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) { 13569 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 13570 auth_tag_len); 13571 debug_hexdump(stdout, "digest:", 13572 sym_op->aead.digest.data, 13573 auth_tag_len); 13574 } 13575 13576 /* Append aad data */ 13577 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 13578 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 13579 uint8_t *, IV_OFFSET); 13580 13581 /* Copy IV 1 byte after the IV pointer, according to the API */ 13582 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len); 13583 13584 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16); 13585 13586 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 13587 ut_params->ibuf, aad_len); 13588 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 13589 "no room to prepend aad"); 13590 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 13591 ut_params->ibuf); 13592 13593 memset(sym_op->aead.aad.data, 0, aad_len); 13594 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 13595 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 13596 13597 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 13598 debug_hexdump(stdout, "aad:", 13599 sym_op->aead.aad.data, aad_len); 13600 } else { 13601 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 13602 uint8_t *, IV_OFFSET); 13603 13604 rte_memcpy(iv_ptr, tdata->iv.data, iv_len); 13605 13606 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16); 13607 13608 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 13609 ut_params->ibuf, aad_len_pad); 13610 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 13611 "no room to prepend aad"); 13612 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 13613 ut_params->ibuf); 13614 13615 memset(sym_op->aead.aad.data, 0, aad_len); 13616 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 13617 13618 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 13619 debug_hexdump(stdout, "aad:", 13620 sym_op->aead.aad.data, aad_len); 13621 } 13622 13623 sym_op->aead.data.length = tdata->plaintext.len; 13624 sym_op->aead.data.offset = aad_len_pad; 13625 13626 return 0; 13627 } 13628 13629 #define SGL_MAX_NO 16 13630 13631 static int 13632 test_authenticated_encryption_SGL(const struct aead_test_data *tdata, 13633 const int oop, uint32_t fragsz, uint32_t fragsz_oop) 13634 { 13635 struct crypto_testsuite_params *ts_params = &testsuite_params; 13636 struct crypto_unittest_params *ut_params = &unittest_params; 13637 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL; 13638 int retval; 13639 int to_trn = 0; 13640 int to_trn_tbl[SGL_MAX_NO]; 13641 int segs = 1; 13642 unsigned int trn_data = 0; 13643 uint8_t *plaintext, *ciphertext, *auth_tag; 13644 struct rte_cryptodev_info dev_info; 13645 13646 /* Verify the capabilities */ 13647 struct rte_cryptodev_sym_capability_idx cap_idx; 13648 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 13649 cap_idx.algo.aead = tdata->algo; 13650 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13651 &cap_idx) == NULL) 13652 return TEST_SKIPPED; 13653 13654 /* OOP not supported with CPU crypto */ 13655 if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13656 return TEST_SKIPPED; 13657 13658 /* Detailed check for the particular SGL support flag */ 13659 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13660 if (!oop) { 13661 unsigned int sgl_in = fragsz < tdata->plaintext.len; 13662 if (sgl_in && (!(dev_info.feature_flags & 13663 RTE_CRYPTODEV_FF_IN_PLACE_SGL))) 13664 return TEST_SKIPPED; 13665 13666 uint64_t feat_flags = dev_info.feature_flags; 13667 13668 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13669 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13670 printf("Device doesn't support RAW data-path APIs.\n"); 13671 return TEST_SKIPPED; 13672 } 13673 } else { 13674 unsigned int sgl_in = fragsz < tdata->plaintext.len; 13675 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) < 13676 tdata->plaintext.len; 13677 /* Raw data path API does not support OOP */ 13678 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13679 return TEST_SKIPPED; 13680 if (sgl_in && !sgl_out) { 13681 if (!(dev_info.feature_flags & 13682 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) 13683 return TEST_SKIPPED; 13684 } else if (!sgl_in && sgl_out) { 13685 if (!(dev_info.feature_flags & 13686 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 13687 return TEST_SKIPPED; 13688 } else if (sgl_in && sgl_out) { 13689 if (!(dev_info.feature_flags & 13690 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 13691 return TEST_SKIPPED; 13692 } 13693 } 13694 13695 if (fragsz > tdata->plaintext.len) 13696 fragsz = tdata->plaintext.len; 13697 13698 uint16_t plaintext_len = fragsz; 13699 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 13700 13701 if (fragsz_oop > tdata->plaintext.len) 13702 frag_size_oop = tdata->plaintext.len; 13703 13704 int ecx = 0; 13705 void *digest_mem = NULL; 13706 13707 uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 13708 13709 if (tdata->plaintext.len % fragsz != 0) { 13710 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO) 13711 return 1; 13712 } else { 13713 if (tdata->plaintext.len / fragsz > SGL_MAX_NO) 13714 return 1; 13715 } 13716 13717 /* 13718 * For out-op-place we need to alloc another mbuf 13719 */ 13720 if (oop) { 13721 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13722 rte_pktmbuf_append(ut_params->obuf, 13723 frag_size_oop + prepend_len); 13724 buf_oop = ut_params->obuf; 13725 } 13726 13727 /* Create AEAD session */ 13728 retval = create_aead_session(ts_params->valid_devs[0], 13729 tdata->algo, 13730 RTE_CRYPTO_AEAD_OP_ENCRYPT, 13731 tdata->key.data, tdata->key.len, 13732 tdata->aad.len, tdata->auth_tag.len, 13733 tdata->iv.len); 13734 if (retval < 0) 13735 return retval; 13736 13737 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13738 13739 /* clear mbuf payload */ 13740 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13741 rte_pktmbuf_tailroom(ut_params->ibuf)); 13742 13743 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13744 plaintext_len); 13745 13746 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 13747 13748 trn_data += plaintext_len; 13749 13750 buf = ut_params->ibuf; 13751 13752 /* 13753 * Loop until no more fragments 13754 */ 13755 13756 while (trn_data < tdata->plaintext.len) { 13757 ++segs; 13758 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 13759 (tdata->plaintext.len - trn_data) : fragsz; 13760 13761 to_trn_tbl[ecx++] = to_trn; 13762 13763 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13764 buf = buf->next; 13765 13766 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 13767 rte_pktmbuf_tailroom(buf)); 13768 13769 /* OOP */ 13770 if (oop && !fragsz_oop) { 13771 buf_last_oop = buf_oop->next = 13772 rte_pktmbuf_alloc(ts_params->mbuf_pool); 13773 buf_oop = buf_oop->next; 13774 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 13775 0, rte_pktmbuf_tailroom(buf_oop)); 13776 rte_pktmbuf_append(buf_oop, to_trn); 13777 } 13778 13779 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 13780 to_trn); 13781 13782 memcpy(plaintext, tdata->plaintext.data + trn_data, 13783 to_trn); 13784 trn_data += to_trn; 13785 if (trn_data == tdata->plaintext.len) { 13786 if (oop) { 13787 if (!fragsz_oop) 13788 digest_mem = rte_pktmbuf_append(buf_oop, 13789 tdata->auth_tag.len); 13790 } else 13791 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 13792 tdata->auth_tag.len); 13793 } 13794 } 13795 13796 uint64_t digest_phys = 0; 13797 13798 ut_params->ibuf->nb_segs = segs; 13799 13800 segs = 1; 13801 if (fragsz_oop && oop) { 13802 to_trn = 0; 13803 ecx = 0; 13804 13805 if (frag_size_oop == tdata->plaintext.len) { 13806 digest_mem = rte_pktmbuf_append(ut_params->obuf, 13807 tdata->auth_tag.len); 13808 13809 digest_phys = rte_pktmbuf_iova_offset( 13810 ut_params->obuf, 13811 tdata->plaintext.len + prepend_len); 13812 } 13813 13814 trn_data = frag_size_oop; 13815 while (trn_data < tdata->plaintext.len) { 13816 ++segs; 13817 to_trn = 13818 (tdata->plaintext.len - trn_data < 13819 frag_size_oop) ? 13820 (tdata->plaintext.len - trn_data) : 13821 frag_size_oop; 13822 13823 to_trn_tbl[ecx++] = to_trn; 13824 13825 buf_last_oop = buf_oop->next = 13826 rte_pktmbuf_alloc(ts_params->mbuf_pool); 13827 buf_oop = buf_oop->next; 13828 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 13829 0, rte_pktmbuf_tailroom(buf_oop)); 13830 rte_pktmbuf_append(buf_oop, to_trn); 13831 13832 trn_data += to_trn; 13833 13834 if (trn_data == tdata->plaintext.len) { 13835 digest_mem = rte_pktmbuf_append(buf_oop, 13836 tdata->auth_tag.len); 13837 } 13838 } 13839 13840 ut_params->obuf->nb_segs = segs; 13841 } 13842 13843 /* 13844 * Place digest at the end of the last buffer 13845 */ 13846 if (!digest_phys) 13847 digest_phys = rte_pktmbuf_iova(buf) + to_trn; 13848 if (oop && buf_last_oop) 13849 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn; 13850 13851 if (!digest_mem && !oop) { 13852 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13853 + tdata->auth_tag.len); 13854 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 13855 tdata->plaintext.len); 13856 } 13857 13858 /* Create AEAD operation */ 13859 retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT, 13860 tdata, digest_mem, digest_phys); 13861 13862 if (retval < 0) 13863 return retval; 13864 13865 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13866 13867 ut_params->op->sym->m_src = ut_params->ibuf; 13868 if (oop) 13869 ut_params->op->sym->m_dst = ut_params->obuf; 13870 13871 /* Process crypto operation */ 13872 if (oop == IN_PLACE && 13873 gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13874 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 13875 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13876 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13877 ut_params->op, 0, 0, 0, 0); 13878 else 13879 TEST_ASSERT_NOT_NULL( 13880 process_crypto_request(ts_params->valid_devs[0], 13881 ut_params->op), "failed to process sym crypto op"); 13882 13883 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13884 "crypto op processing failed"); 13885 13886 13887 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 13888 uint8_t *, prepend_len); 13889 if (oop) { 13890 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 13891 uint8_t *, prepend_len); 13892 } 13893 13894 if (fragsz_oop) 13895 fragsz = fragsz_oop; 13896 13897 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13898 ciphertext, 13899 tdata->ciphertext.data, 13900 fragsz, 13901 "Ciphertext data not as expected"); 13902 13903 buf = ut_params->op->sym->m_src->next; 13904 if (oop) 13905 buf = ut_params->op->sym->m_dst->next; 13906 13907 unsigned int off = fragsz; 13908 13909 ecx = 0; 13910 while (buf) { 13911 ciphertext = rte_pktmbuf_mtod(buf, 13912 uint8_t *); 13913 13914 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13915 ciphertext, 13916 tdata->ciphertext.data + off, 13917 to_trn_tbl[ecx], 13918 "Ciphertext data not as expected"); 13919 13920 off += to_trn_tbl[ecx++]; 13921 buf = buf->next; 13922 } 13923 13924 auth_tag = digest_mem; 13925 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13926 auth_tag, 13927 tdata->auth_tag.data, 13928 tdata->auth_tag.len, 13929 "Generated auth tag not as expected"); 13930 13931 return 0; 13932 } 13933 13934 static int 13935 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) 13936 { 13937 return test_authenticated_encryption_SGL( 13938 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400); 13939 } 13940 13941 static int 13942 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void) 13943 { 13944 return test_authenticated_encryption_SGL( 13945 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000); 13946 } 13947 13948 static int 13949 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void) 13950 { 13951 return test_authenticated_encryption_SGL( 13952 &gcm_test_case_8, OUT_OF_PLACE, 400, 13953 gcm_test_case_8.plaintext.len); 13954 } 13955 13956 static int 13957 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void) 13958 { 13959 /* This test is not for OPENSSL PMD */ 13960 if (gbl_driver_id == rte_cryptodev_driver_id_get( 13961 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) 13962 return TEST_SKIPPED; 13963 13964 return test_authenticated_encryption_SGL( 13965 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0); 13966 } 13967 13968 static int 13969 test_authentication_verify_fail_when_data_corrupted( 13970 struct crypto_testsuite_params *ts_params, 13971 struct crypto_unittest_params *ut_params, 13972 const struct test_crypto_vector *reference) 13973 { 13974 return test_authentication_verify_fail_when_data_corruption( 13975 ts_params, ut_params, reference, 1); 13976 } 13977 13978 static int 13979 test_authentication_verify_fail_when_tag_corrupted( 13980 struct crypto_testsuite_params *ts_params, 13981 struct crypto_unittest_params *ut_params, 13982 const struct test_crypto_vector *reference) 13983 { 13984 return test_authentication_verify_fail_when_data_corruption( 13985 ts_params, ut_params, reference, 0); 13986 } 13987 13988 static int 13989 test_authentication_verify_GMAC_fail_when_data_corrupted( 13990 struct crypto_testsuite_params *ts_params, 13991 struct crypto_unittest_params *ut_params, 13992 const struct test_crypto_vector *reference) 13993 { 13994 return test_authentication_verify_GMAC_fail_when_corruption( 13995 ts_params, ut_params, reference, 1); 13996 } 13997 13998 static int 13999 test_authentication_verify_GMAC_fail_when_tag_corrupted( 14000 struct crypto_testsuite_params *ts_params, 14001 struct crypto_unittest_params *ut_params, 14002 const struct test_crypto_vector *reference) 14003 { 14004 return test_authentication_verify_GMAC_fail_when_corruption( 14005 ts_params, ut_params, reference, 0); 14006 } 14007 14008 static int 14009 test_authenticated_decryption_fail_when_data_corrupted( 14010 struct crypto_testsuite_params *ts_params, 14011 struct crypto_unittest_params *ut_params, 14012 const struct test_crypto_vector *reference) 14013 { 14014 return test_authenticated_decryption_fail_when_corruption( 14015 ts_params, ut_params, reference, 1); 14016 } 14017 14018 static int 14019 test_authenticated_decryption_fail_when_tag_corrupted( 14020 struct crypto_testsuite_params *ts_params, 14021 struct crypto_unittest_params *ut_params, 14022 const struct test_crypto_vector *reference) 14023 { 14024 return test_authenticated_decryption_fail_when_corruption( 14025 ts_params, ut_params, reference, 0); 14026 } 14027 14028 static int 14029 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 14030 { 14031 return test_authentication_verify_fail_when_data_corrupted( 14032 &testsuite_params, &unittest_params, 14033 &hmac_sha1_test_crypto_vector); 14034 } 14035 14036 static int 14037 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 14038 { 14039 return test_authentication_verify_fail_when_tag_corrupted( 14040 &testsuite_params, &unittest_params, 14041 &hmac_sha1_test_crypto_vector); 14042 } 14043 14044 static int 14045 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 14046 { 14047 return test_authentication_verify_GMAC_fail_when_data_corrupted( 14048 &testsuite_params, &unittest_params, 14049 &aes128_gmac_test_vector); 14050 } 14051 14052 static int 14053 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 14054 { 14055 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 14056 &testsuite_params, &unittest_params, 14057 &aes128_gmac_test_vector); 14058 } 14059 14060 static int 14061 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 14062 { 14063 return test_authenticated_decryption_fail_when_data_corrupted( 14064 &testsuite_params, 14065 &unittest_params, 14066 &aes128cbc_hmac_sha1_test_vector); 14067 } 14068 14069 static int 14070 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 14071 { 14072 return test_authenticated_decryption_fail_when_tag_corrupted( 14073 &testsuite_params, 14074 &unittest_params, 14075 &aes128cbc_hmac_sha1_test_vector); 14076 } 14077 14078 static int 14079 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void) 14080 { 14081 return test_authenticated_encrypt_with_esn( 14082 &testsuite_params, 14083 &unittest_params, 14084 &aes128cbc_hmac_sha1_aad_test_vector); 14085 } 14086 14087 static int 14088 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void) 14089 { 14090 return test_authenticated_decrypt_with_esn( 14091 &testsuite_params, 14092 &unittest_params, 14093 &aes128cbc_hmac_sha1_aad_test_vector); 14094 } 14095 14096 static int 14097 test_chacha20_poly1305_encrypt_test_case_rfc8439(void) 14098 { 14099 return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439); 14100 } 14101 14102 static int 14103 test_chacha20_poly1305_decrypt_test_case_rfc8439(void) 14104 { 14105 return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439); 14106 } 14107 14108 static int 14109 test_chacha20_poly1305_encrypt_SGL_out_of_place(void) 14110 { 14111 return test_authenticated_encryption_SGL( 14112 &chacha20_poly1305_case_2, OUT_OF_PLACE, 32, 14113 chacha20_poly1305_case_2.plaintext.len); 14114 } 14115 14116 #ifdef RTE_CRYPTO_SCHEDULER 14117 14118 /* global AESNI worker IDs for the scheduler test */ 14119 uint8_t aesni_ids[2]; 14120 14121 static int 14122 scheduler_testsuite_setup(void) 14123 { 14124 uint32_t i = 0; 14125 int32_t nb_devs, ret; 14126 char vdev_args[VDEV_ARGS_SIZE] = {""}; 14127 char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core," 14128 "ordering=enable,name=cryptodev_test_scheduler,corelist="}; 14129 uint16_t worker_core_count = 0; 14130 uint16_t socket_id = 0; 14131 14132 if (gbl_driver_id == rte_cryptodev_driver_id_get( 14133 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) { 14134 14135 /* Identify the Worker Cores 14136 * Use 2 worker cores for the device args 14137 */ 14138 RTE_LCORE_FOREACH_WORKER(i) { 14139 if (worker_core_count > 1) 14140 break; 14141 snprintf(vdev_args, sizeof(vdev_args), 14142 "%s%d", temp_str, i); 14143 strcpy(temp_str, vdev_args); 14144 strlcat(temp_str, ";", sizeof(temp_str)); 14145 worker_core_count++; 14146 socket_id = rte_lcore_to_socket_id(i); 14147 } 14148 if (worker_core_count != 2) { 14149 RTE_LOG(ERR, USER1, 14150 "Cryptodev scheduler test require at least " 14151 "two worker cores to run. " 14152 "Please use the correct coremask.\n"); 14153 return TEST_FAILED; 14154 } 14155 strcpy(temp_str, vdev_args); 14156 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", 14157 temp_str, socket_id); 14158 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args); 14159 nb_devs = rte_cryptodev_device_count_by_driver( 14160 rte_cryptodev_driver_id_get( 14161 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))); 14162 if (nb_devs < 1) { 14163 ret = rte_vdev_init( 14164 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD), 14165 vdev_args); 14166 TEST_ASSERT(ret == 0, 14167 "Failed to create instance %u of pmd : %s", 14168 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 14169 } 14170 } 14171 return testsuite_setup(); 14172 } 14173 14174 static int 14175 test_scheduler_attach_worker_op(void) 14176 { 14177 struct crypto_testsuite_params *ts_params = &testsuite_params; 14178 uint8_t sched_id = ts_params->valid_devs[0]; 14179 uint32_t i, nb_devs_attached = 0; 14180 int ret; 14181 char vdev_name[32]; 14182 unsigned int count = rte_cryptodev_count(); 14183 14184 /* create 2 AESNI_MB vdevs on top of existing devices */ 14185 for (i = count; i < count + 2; i++) { 14186 snprintf(vdev_name, sizeof(vdev_name), "%s_%u", 14187 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), 14188 i); 14189 ret = rte_vdev_init(vdev_name, NULL); 14190 14191 TEST_ASSERT(ret == 0, 14192 "Failed to create instance %u of" 14193 " pmd : %s", 14194 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 14195 14196 if (ret < 0) { 14197 RTE_LOG(ERR, USER1, 14198 "Failed to create 2 AESNI MB PMDs.\n"); 14199 return TEST_SKIPPED; 14200 } 14201 } 14202 14203 /* attach 2 AESNI_MB cdevs */ 14204 for (i = count; i < count + 2; i++) { 14205 struct rte_cryptodev_info info; 14206 unsigned int session_size; 14207 14208 rte_cryptodev_info_get(i, &info); 14209 if (info.driver_id != rte_cryptodev_driver_id_get( 14210 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) 14211 continue; 14212 14213 session_size = rte_cryptodev_sym_get_private_session_size(i); 14214 /* 14215 * Create the session mempool again, since now there are new devices 14216 * to use the mempool. 14217 */ 14218 if (ts_params->session_mpool) { 14219 rte_mempool_free(ts_params->session_mpool); 14220 ts_params->session_mpool = NULL; 14221 } 14222 if (ts_params->session_priv_mpool) { 14223 rte_mempool_free(ts_params->session_priv_mpool); 14224 ts_params->session_priv_mpool = NULL; 14225 } 14226 14227 if (info.sym.max_nb_sessions != 0 && 14228 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 14229 RTE_LOG(ERR, USER1, 14230 "Device does not support " 14231 "at least %u sessions\n", 14232 MAX_NB_SESSIONS); 14233 return TEST_FAILED; 14234 } 14235 /* 14236 * Create mempool with maximum number of sessions, 14237 * to include the session headers 14238 */ 14239 if (ts_params->session_mpool == NULL) { 14240 ts_params->session_mpool = 14241 rte_cryptodev_sym_session_pool_create( 14242 "test_sess_mp", 14243 MAX_NB_SESSIONS, 0, 0, 0, 14244 SOCKET_ID_ANY); 14245 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 14246 "session mempool allocation failed"); 14247 } 14248 14249 /* 14250 * Create mempool with maximum number of sessions, 14251 * to include device specific session private data 14252 */ 14253 if (ts_params->session_priv_mpool == NULL) { 14254 ts_params->session_priv_mpool = rte_mempool_create( 14255 "test_sess_mp_priv", 14256 MAX_NB_SESSIONS, 14257 session_size, 14258 0, 0, NULL, NULL, NULL, 14259 NULL, SOCKET_ID_ANY, 14260 0); 14261 14262 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 14263 "session mempool allocation failed"); 14264 } 14265 14266 ts_params->qp_conf.mp_session = ts_params->session_mpool; 14267 ts_params->qp_conf.mp_session_private = 14268 ts_params->session_priv_mpool; 14269 14270 ret = rte_cryptodev_scheduler_worker_attach(sched_id, 14271 (uint8_t)i); 14272 14273 TEST_ASSERT(ret == 0, 14274 "Failed to attach device %u of pmd : %s", i, 14275 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 14276 14277 aesni_ids[nb_devs_attached] = (uint8_t)i; 14278 14279 nb_devs_attached++; 14280 } 14281 14282 return 0; 14283 } 14284 14285 static int 14286 test_scheduler_detach_worker_op(void) 14287 { 14288 struct crypto_testsuite_params *ts_params = &testsuite_params; 14289 uint8_t sched_id = ts_params->valid_devs[0]; 14290 uint32_t i; 14291 int ret; 14292 14293 for (i = 0; i < 2; i++) { 14294 ret = rte_cryptodev_scheduler_worker_detach(sched_id, 14295 aesni_ids[i]); 14296 TEST_ASSERT(ret == 0, 14297 "Failed to detach device %u", aesni_ids[i]); 14298 } 14299 14300 return 0; 14301 } 14302 14303 static int 14304 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode) 14305 { 14306 struct crypto_testsuite_params *ts_params = &testsuite_params; 14307 uint8_t sched_id = ts_params->valid_devs[0]; 14308 /* set mode */ 14309 return rte_cryptodev_scheduler_mode_set(sched_id, 14310 scheduler_mode); 14311 } 14312 14313 static int 14314 test_scheduler_mode_roundrobin_op(void) 14315 { 14316 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) == 14317 0, "Failed to set roundrobin mode"); 14318 return 0; 14319 14320 } 14321 14322 static int 14323 test_scheduler_mode_multicore_op(void) 14324 { 14325 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) == 14326 0, "Failed to set multicore mode"); 14327 14328 return 0; 14329 } 14330 14331 static int 14332 test_scheduler_mode_failover_op(void) 14333 { 14334 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) == 14335 0, "Failed to set failover mode"); 14336 14337 return 0; 14338 } 14339 14340 static int 14341 test_scheduler_mode_pkt_size_distr_op(void) 14342 { 14343 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) == 14344 0, "Failed to set pktsize mode"); 14345 14346 return 0; 14347 } 14348 14349 static int 14350 scheduler_multicore_testsuite_setup(void) 14351 { 14352 if (test_scheduler_attach_worker_op() < 0) 14353 return TEST_SKIPPED; 14354 if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0) 14355 return TEST_SKIPPED; 14356 return 0; 14357 } 14358 14359 static int 14360 scheduler_roundrobin_testsuite_setup(void) 14361 { 14362 if (test_scheduler_attach_worker_op() < 0) 14363 return TEST_SKIPPED; 14364 if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0) 14365 return TEST_SKIPPED; 14366 return 0; 14367 } 14368 14369 static int 14370 scheduler_failover_testsuite_setup(void) 14371 { 14372 if (test_scheduler_attach_worker_op() < 0) 14373 return TEST_SKIPPED; 14374 if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0) 14375 return TEST_SKIPPED; 14376 return 0; 14377 } 14378 14379 static int 14380 scheduler_pkt_size_distr_testsuite_setup(void) 14381 { 14382 if (test_scheduler_attach_worker_op() < 0) 14383 return TEST_SKIPPED; 14384 if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0) 14385 return TEST_SKIPPED; 14386 return 0; 14387 } 14388 14389 static void 14390 scheduler_mode_testsuite_teardown(void) 14391 { 14392 test_scheduler_detach_worker_op(); 14393 } 14394 14395 #endif /* RTE_CRYPTO_SCHEDULER */ 14396 14397 static struct unit_test_suite end_testsuite = { 14398 .suite_name = NULL, 14399 .setup = NULL, 14400 .teardown = NULL, 14401 .unit_test_suites = NULL 14402 }; 14403 14404 #ifdef RTE_LIB_SECURITY 14405 static struct unit_test_suite ipsec_proto_testsuite = { 14406 .suite_name = "IPsec Proto Unit Test Suite", 14407 .setup = ipsec_proto_testsuite_setup, 14408 .unit_test_cases = { 14409 TEST_CASE_NAMED_WITH_DATA( 14410 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 14411 ut_setup_security, ut_teardown, 14412 test_ipsec_proto_known_vec, &pkt_aes_128_gcm), 14413 TEST_CASE_NAMED_WITH_DATA( 14414 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 14415 ut_setup_security, ut_teardown, 14416 test_ipsec_proto_known_vec, &pkt_aes_192_gcm), 14417 TEST_CASE_NAMED_WITH_DATA( 14418 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 14419 ut_setup_security, ut_teardown, 14420 test_ipsec_proto_known_vec, &pkt_aes_256_gcm), 14421 TEST_CASE_NAMED_WITH_DATA( 14422 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 14423 ut_setup_security, ut_teardown, 14424 test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm), 14425 TEST_CASE_NAMED_WITH_DATA( 14426 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 14427 ut_setup_security, ut_teardown, 14428 test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm), 14429 TEST_CASE_NAMED_WITH_DATA( 14430 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 14431 ut_setup_security, ut_teardown, 14432 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm), 14433 TEST_CASE_NAMED_ST( 14434 "Combined test alg list", 14435 ut_setup_security, ut_teardown, 14436 test_ipsec_proto_display_list), 14437 TEST_CASE_NAMED_ST( 14438 "IV generation", 14439 ut_setup_security, ut_teardown, 14440 test_ipsec_proto_iv_gen), 14441 TEST_CASE_NAMED_ST( 14442 "UDP encapsulation", 14443 ut_setup_security, ut_teardown, 14444 test_ipsec_proto_udp_encap), 14445 TEST_CASE_NAMED_ST( 14446 "UDP encapsulation ports verification test", 14447 ut_setup_security, ut_teardown, 14448 test_ipsec_proto_udp_ports_verify), 14449 TEST_CASE_NAMED_ST( 14450 "SA expiry packets soft", 14451 ut_setup_security, ut_teardown, 14452 test_ipsec_proto_sa_exp_pkts_soft), 14453 TEST_CASE_NAMED_ST( 14454 "SA expiry packets hard", 14455 ut_setup_security, ut_teardown, 14456 test_ipsec_proto_sa_exp_pkts_hard), 14457 TEST_CASE_NAMED_ST( 14458 "Negative test: ICV corruption", 14459 ut_setup_security, ut_teardown, 14460 test_ipsec_proto_err_icv_corrupt), 14461 TEST_CASE_NAMED_ST( 14462 "Tunnel dst addr verification", 14463 ut_setup_security, ut_teardown, 14464 test_ipsec_proto_tunnel_dst_addr_verify), 14465 TEST_CASE_NAMED_ST( 14466 "Tunnel src and dst addr verification", 14467 ut_setup_security, ut_teardown, 14468 test_ipsec_proto_tunnel_src_dst_addr_verify), 14469 TEST_CASE_NAMED_ST( 14470 "Inner IP checksum", 14471 ut_setup_security, ut_teardown, 14472 test_ipsec_proto_inner_ip_csum), 14473 TEST_CASE_NAMED_ST( 14474 "Inner L4 checksum", 14475 ut_setup_security, ut_teardown, 14476 test_ipsec_proto_inner_l4_csum), 14477 TEST_CASES_END() /**< NULL terminate unit test array */ 14478 } 14479 }; 14480 14481 static struct unit_test_suite pdcp_proto_testsuite = { 14482 .suite_name = "PDCP Proto Unit Test Suite", 14483 .setup = pdcp_proto_testsuite_setup, 14484 .unit_test_cases = { 14485 TEST_CASE_ST(ut_setup_security, ut_teardown, 14486 test_PDCP_PROTO_all), 14487 TEST_CASES_END() /**< NULL terminate unit test array */ 14488 } 14489 }; 14490 14491 static struct unit_test_suite docsis_proto_testsuite = { 14492 .suite_name = "Docsis Proto Unit Test Suite", 14493 .setup = docsis_proto_testsuite_setup, 14494 .unit_test_cases = { 14495 TEST_CASE_ST(ut_setup_security, ut_teardown, 14496 test_DOCSIS_PROTO_all), 14497 TEST_CASES_END() /**< NULL terminate unit test array */ 14498 } 14499 }; 14500 #endif 14501 14502 static struct unit_test_suite cryptodev_gen_testsuite = { 14503 .suite_name = "Crypto General Unit Test Suite", 14504 .setup = crypto_gen_testsuite_setup, 14505 .unit_test_cases = { 14506 TEST_CASE_ST(ut_setup, ut_teardown, 14507 test_device_configure_invalid_dev_id), 14508 TEST_CASE_ST(ut_setup, ut_teardown, 14509 test_queue_pair_descriptor_setup), 14510 TEST_CASE_ST(ut_setup, ut_teardown, 14511 test_device_configure_invalid_queue_pair_ids), 14512 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 14513 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup), 14514 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup), 14515 TEST_CASES_END() /**< NULL terminate unit test array */ 14516 } 14517 }; 14518 14519 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = { 14520 .suite_name = "Negative HMAC SHA1 Unit Test Suite", 14521 .setup = negative_hmac_sha1_testsuite_setup, 14522 .unit_test_cases = { 14523 /** Negative tests */ 14524 TEST_CASE_ST(ut_setup, ut_teardown, 14525 authentication_verify_HMAC_SHA1_fail_data_corrupt), 14526 TEST_CASE_ST(ut_setup, ut_teardown, 14527 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 14528 TEST_CASE_ST(ut_setup, ut_teardown, 14529 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 14530 TEST_CASE_ST(ut_setup, ut_teardown, 14531 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 14532 14533 TEST_CASES_END() /**< NULL terminate unit test array */ 14534 } 14535 }; 14536 14537 static struct unit_test_suite cryptodev_multi_session_testsuite = { 14538 .suite_name = "Multi Session Unit Test Suite", 14539 .setup = multi_session_testsuite_setup, 14540 .unit_test_cases = { 14541 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 14542 TEST_CASE_ST(ut_setup, ut_teardown, 14543 test_multi_session_random_usage), 14544 14545 TEST_CASES_END() /**< NULL terminate unit test array */ 14546 } 14547 }; 14548 14549 static struct unit_test_suite cryptodev_null_testsuite = { 14550 .suite_name = "NULL Test Suite", 14551 .setup = null_testsuite_setup, 14552 .unit_test_cases = { 14553 TEST_CASE_ST(ut_setup, ut_teardown, 14554 test_null_invalid_operation), 14555 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation), 14556 TEST_CASES_END() 14557 } 14558 }; 14559 14560 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite = { 14561 .suite_name = "AES CCM Authenticated Test Suite", 14562 .setup = aes_ccm_auth_testsuite_setup, 14563 .unit_test_cases = { 14564 /** AES CCM Authenticated Encryption 128 bits key*/ 14565 TEST_CASE_ST(ut_setup, ut_teardown, 14566 test_AES_CCM_authenticated_encryption_test_case_128_1), 14567 TEST_CASE_ST(ut_setup, ut_teardown, 14568 test_AES_CCM_authenticated_encryption_test_case_128_2), 14569 TEST_CASE_ST(ut_setup, ut_teardown, 14570 test_AES_CCM_authenticated_encryption_test_case_128_3), 14571 14572 /** AES CCM Authenticated Decryption 128 bits key*/ 14573 TEST_CASE_ST(ut_setup, ut_teardown, 14574 test_AES_CCM_authenticated_decryption_test_case_128_1), 14575 TEST_CASE_ST(ut_setup, ut_teardown, 14576 test_AES_CCM_authenticated_decryption_test_case_128_2), 14577 TEST_CASE_ST(ut_setup, ut_teardown, 14578 test_AES_CCM_authenticated_decryption_test_case_128_3), 14579 14580 /** AES CCM Authenticated Encryption 192 bits key */ 14581 TEST_CASE_ST(ut_setup, ut_teardown, 14582 test_AES_CCM_authenticated_encryption_test_case_192_1), 14583 TEST_CASE_ST(ut_setup, ut_teardown, 14584 test_AES_CCM_authenticated_encryption_test_case_192_2), 14585 TEST_CASE_ST(ut_setup, ut_teardown, 14586 test_AES_CCM_authenticated_encryption_test_case_192_3), 14587 14588 /** AES CCM Authenticated Decryption 192 bits key*/ 14589 TEST_CASE_ST(ut_setup, ut_teardown, 14590 test_AES_CCM_authenticated_decryption_test_case_192_1), 14591 TEST_CASE_ST(ut_setup, ut_teardown, 14592 test_AES_CCM_authenticated_decryption_test_case_192_2), 14593 TEST_CASE_ST(ut_setup, ut_teardown, 14594 test_AES_CCM_authenticated_decryption_test_case_192_3), 14595 14596 /** AES CCM Authenticated Encryption 256 bits key */ 14597 TEST_CASE_ST(ut_setup, ut_teardown, 14598 test_AES_CCM_authenticated_encryption_test_case_256_1), 14599 TEST_CASE_ST(ut_setup, ut_teardown, 14600 test_AES_CCM_authenticated_encryption_test_case_256_2), 14601 TEST_CASE_ST(ut_setup, ut_teardown, 14602 test_AES_CCM_authenticated_encryption_test_case_256_3), 14603 14604 /** AES CCM Authenticated Decryption 256 bits key*/ 14605 TEST_CASE_ST(ut_setup, ut_teardown, 14606 test_AES_CCM_authenticated_decryption_test_case_256_1), 14607 TEST_CASE_ST(ut_setup, ut_teardown, 14608 test_AES_CCM_authenticated_decryption_test_case_256_2), 14609 TEST_CASE_ST(ut_setup, ut_teardown, 14610 test_AES_CCM_authenticated_decryption_test_case_256_3), 14611 TEST_CASES_END() 14612 } 14613 }; 14614 14615 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite = { 14616 .suite_name = "AES GCM Authenticated Test Suite", 14617 .setup = aes_gcm_auth_testsuite_setup, 14618 .unit_test_cases = { 14619 /** AES GCM Authenticated Encryption */ 14620 TEST_CASE_ST(ut_setup, ut_teardown, 14621 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 14622 TEST_CASE_ST(ut_setup, ut_teardown, 14623 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 14624 TEST_CASE_ST(ut_setup, ut_teardown, 14625 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 14626 TEST_CASE_ST(ut_setup, ut_teardown, 14627 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 14628 TEST_CASE_ST(ut_setup, ut_teardown, 14629 test_AES_GCM_authenticated_encryption_test_case_1), 14630 TEST_CASE_ST(ut_setup, ut_teardown, 14631 test_AES_GCM_authenticated_encryption_test_case_2), 14632 TEST_CASE_ST(ut_setup, ut_teardown, 14633 test_AES_GCM_authenticated_encryption_test_case_3), 14634 TEST_CASE_ST(ut_setup, ut_teardown, 14635 test_AES_GCM_authenticated_encryption_test_case_4), 14636 TEST_CASE_ST(ut_setup, ut_teardown, 14637 test_AES_GCM_authenticated_encryption_test_case_5), 14638 TEST_CASE_ST(ut_setup, ut_teardown, 14639 test_AES_GCM_authenticated_encryption_test_case_6), 14640 TEST_CASE_ST(ut_setup, ut_teardown, 14641 test_AES_GCM_authenticated_encryption_test_case_7), 14642 TEST_CASE_ST(ut_setup, ut_teardown, 14643 test_AES_GCM_authenticated_encryption_test_case_8), 14644 TEST_CASE_ST(ut_setup, ut_teardown, 14645 test_AES_GCM_J0_authenticated_encryption_test_case_1), 14646 14647 /** AES GCM Authenticated Decryption */ 14648 TEST_CASE_ST(ut_setup, ut_teardown, 14649 test_AES_GCM_authenticated_decryption_test_case_1), 14650 TEST_CASE_ST(ut_setup, ut_teardown, 14651 test_AES_GCM_authenticated_decryption_test_case_2), 14652 TEST_CASE_ST(ut_setup, ut_teardown, 14653 test_AES_GCM_authenticated_decryption_test_case_3), 14654 TEST_CASE_ST(ut_setup, ut_teardown, 14655 test_AES_GCM_authenticated_decryption_test_case_4), 14656 TEST_CASE_ST(ut_setup, ut_teardown, 14657 test_AES_GCM_authenticated_decryption_test_case_5), 14658 TEST_CASE_ST(ut_setup, ut_teardown, 14659 test_AES_GCM_authenticated_decryption_test_case_6), 14660 TEST_CASE_ST(ut_setup, ut_teardown, 14661 test_AES_GCM_authenticated_decryption_test_case_7), 14662 TEST_CASE_ST(ut_setup, ut_teardown, 14663 test_AES_GCM_authenticated_decryption_test_case_8), 14664 TEST_CASE_ST(ut_setup, ut_teardown, 14665 test_AES_GCM_J0_authenticated_decryption_test_case_1), 14666 14667 /** AES GCM Authenticated Encryption 192 bits key */ 14668 TEST_CASE_ST(ut_setup, ut_teardown, 14669 test_AES_GCM_auth_encryption_test_case_192_1), 14670 TEST_CASE_ST(ut_setup, ut_teardown, 14671 test_AES_GCM_auth_encryption_test_case_192_2), 14672 TEST_CASE_ST(ut_setup, ut_teardown, 14673 test_AES_GCM_auth_encryption_test_case_192_3), 14674 TEST_CASE_ST(ut_setup, ut_teardown, 14675 test_AES_GCM_auth_encryption_test_case_192_4), 14676 TEST_CASE_ST(ut_setup, ut_teardown, 14677 test_AES_GCM_auth_encryption_test_case_192_5), 14678 TEST_CASE_ST(ut_setup, ut_teardown, 14679 test_AES_GCM_auth_encryption_test_case_192_6), 14680 TEST_CASE_ST(ut_setup, ut_teardown, 14681 test_AES_GCM_auth_encryption_test_case_192_7), 14682 14683 /** AES GCM Authenticated Decryption 192 bits key */ 14684 TEST_CASE_ST(ut_setup, ut_teardown, 14685 test_AES_GCM_auth_decryption_test_case_192_1), 14686 TEST_CASE_ST(ut_setup, ut_teardown, 14687 test_AES_GCM_auth_decryption_test_case_192_2), 14688 TEST_CASE_ST(ut_setup, ut_teardown, 14689 test_AES_GCM_auth_decryption_test_case_192_3), 14690 TEST_CASE_ST(ut_setup, ut_teardown, 14691 test_AES_GCM_auth_decryption_test_case_192_4), 14692 TEST_CASE_ST(ut_setup, ut_teardown, 14693 test_AES_GCM_auth_decryption_test_case_192_5), 14694 TEST_CASE_ST(ut_setup, ut_teardown, 14695 test_AES_GCM_auth_decryption_test_case_192_6), 14696 TEST_CASE_ST(ut_setup, ut_teardown, 14697 test_AES_GCM_auth_decryption_test_case_192_7), 14698 14699 /** AES GCM Authenticated Encryption 256 bits key */ 14700 TEST_CASE_ST(ut_setup, ut_teardown, 14701 test_AES_GCM_auth_encryption_test_case_256_1), 14702 TEST_CASE_ST(ut_setup, ut_teardown, 14703 test_AES_GCM_auth_encryption_test_case_256_2), 14704 TEST_CASE_ST(ut_setup, ut_teardown, 14705 test_AES_GCM_auth_encryption_test_case_256_3), 14706 TEST_CASE_ST(ut_setup, ut_teardown, 14707 test_AES_GCM_auth_encryption_test_case_256_4), 14708 TEST_CASE_ST(ut_setup, ut_teardown, 14709 test_AES_GCM_auth_encryption_test_case_256_5), 14710 TEST_CASE_ST(ut_setup, ut_teardown, 14711 test_AES_GCM_auth_encryption_test_case_256_6), 14712 TEST_CASE_ST(ut_setup, ut_teardown, 14713 test_AES_GCM_auth_encryption_test_case_256_7), 14714 14715 /** AES GCM Authenticated Decryption 256 bits key */ 14716 TEST_CASE_ST(ut_setup, ut_teardown, 14717 test_AES_GCM_auth_decryption_test_case_256_1), 14718 TEST_CASE_ST(ut_setup, ut_teardown, 14719 test_AES_GCM_auth_decryption_test_case_256_2), 14720 TEST_CASE_ST(ut_setup, ut_teardown, 14721 test_AES_GCM_auth_decryption_test_case_256_3), 14722 TEST_CASE_ST(ut_setup, ut_teardown, 14723 test_AES_GCM_auth_decryption_test_case_256_4), 14724 TEST_CASE_ST(ut_setup, ut_teardown, 14725 test_AES_GCM_auth_decryption_test_case_256_5), 14726 TEST_CASE_ST(ut_setup, ut_teardown, 14727 test_AES_GCM_auth_decryption_test_case_256_6), 14728 TEST_CASE_ST(ut_setup, ut_teardown, 14729 test_AES_GCM_auth_decryption_test_case_256_7), 14730 14731 /** AES GCM Authenticated Encryption big aad size */ 14732 TEST_CASE_ST(ut_setup, ut_teardown, 14733 test_AES_GCM_auth_encryption_test_case_aad_1), 14734 TEST_CASE_ST(ut_setup, ut_teardown, 14735 test_AES_GCM_auth_encryption_test_case_aad_2), 14736 14737 /** AES GCM Authenticated Decryption big aad size */ 14738 TEST_CASE_ST(ut_setup, ut_teardown, 14739 test_AES_GCM_auth_decryption_test_case_aad_1), 14740 TEST_CASE_ST(ut_setup, ut_teardown, 14741 test_AES_GCM_auth_decryption_test_case_aad_2), 14742 14743 /** Out of place tests */ 14744 TEST_CASE_ST(ut_setup, ut_teardown, 14745 test_AES_GCM_authenticated_encryption_oop_test_case_1), 14746 TEST_CASE_ST(ut_setup, ut_teardown, 14747 test_AES_GCM_authenticated_decryption_oop_test_case_1), 14748 14749 /** Session-less tests */ 14750 TEST_CASE_ST(ut_setup, ut_teardown, 14751 test_AES_GCM_authenticated_encryption_sessionless_test_case_1), 14752 TEST_CASE_ST(ut_setup, ut_teardown, 14753 test_AES_GCM_authenticated_decryption_sessionless_test_case_1), 14754 14755 TEST_CASES_END() 14756 } 14757 }; 14758 14759 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite = { 14760 .suite_name = "AES GMAC Authentication Test Suite", 14761 .setup = aes_gmac_auth_testsuite_setup, 14762 .unit_test_cases = { 14763 TEST_CASE_ST(ut_setup, ut_teardown, 14764 test_AES_GMAC_authentication_test_case_1), 14765 TEST_CASE_ST(ut_setup, ut_teardown, 14766 test_AES_GMAC_authentication_verify_test_case_1), 14767 TEST_CASE_ST(ut_setup, ut_teardown, 14768 test_AES_GMAC_authentication_test_case_2), 14769 TEST_CASE_ST(ut_setup, ut_teardown, 14770 test_AES_GMAC_authentication_verify_test_case_2), 14771 TEST_CASE_ST(ut_setup, ut_teardown, 14772 test_AES_GMAC_authentication_test_case_3), 14773 TEST_CASE_ST(ut_setup, ut_teardown, 14774 test_AES_GMAC_authentication_verify_test_case_3), 14775 TEST_CASE_ST(ut_setup, ut_teardown, 14776 test_AES_GMAC_authentication_test_case_4), 14777 TEST_CASE_ST(ut_setup, ut_teardown, 14778 test_AES_GMAC_authentication_verify_test_case_4), 14779 TEST_CASE_ST(ut_setup, ut_teardown, 14780 test_AES_GMAC_authentication_SGL_40B), 14781 TEST_CASE_ST(ut_setup, ut_teardown, 14782 test_AES_GMAC_authentication_SGL_80B), 14783 TEST_CASE_ST(ut_setup, ut_teardown, 14784 test_AES_GMAC_authentication_SGL_2048B), 14785 TEST_CASE_ST(ut_setup, ut_teardown, 14786 test_AES_GMAC_authentication_SGL_2047B), 14787 14788 TEST_CASES_END() 14789 } 14790 }; 14791 14792 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite = { 14793 .suite_name = "Chacha20-Poly1305 Test Suite", 14794 .setup = chacha20_poly1305_testsuite_setup, 14795 .unit_test_cases = { 14796 TEST_CASE_ST(ut_setup, ut_teardown, 14797 test_chacha20_poly1305_encrypt_test_case_rfc8439), 14798 TEST_CASE_ST(ut_setup, ut_teardown, 14799 test_chacha20_poly1305_decrypt_test_case_rfc8439), 14800 TEST_CASE_ST(ut_setup, ut_teardown, 14801 test_chacha20_poly1305_encrypt_SGL_out_of_place), 14802 TEST_CASES_END() 14803 } 14804 }; 14805 14806 static struct unit_test_suite cryptodev_snow3g_testsuite = { 14807 .suite_name = "SNOW 3G Test Suite", 14808 .setup = snow3g_testsuite_setup, 14809 .unit_test_cases = { 14810 /** SNOW 3G encrypt only (UEA2) */ 14811 TEST_CASE_ST(ut_setup, ut_teardown, 14812 test_snow3g_encryption_test_case_1), 14813 TEST_CASE_ST(ut_setup, ut_teardown, 14814 test_snow3g_encryption_test_case_2), 14815 TEST_CASE_ST(ut_setup, ut_teardown, 14816 test_snow3g_encryption_test_case_3), 14817 TEST_CASE_ST(ut_setup, ut_teardown, 14818 test_snow3g_encryption_test_case_4), 14819 TEST_CASE_ST(ut_setup, ut_teardown, 14820 test_snow3g_encryption_test_case_5), 14821 14822 TEST_CASE_ST(ut_setup, ut_teardown, 14823 test_snow3g_encryption_test_case_1_oop), 14824 TEST_CASE_ST(ut_setup, ut_teardown, 14825 test_snow3g_encryption_test_case_1_oop_sgl), 14826 TEST_CASE_ST(ut_setup, ut_teardown, 14827 test_snow3g_encryption_test_case_1_offset_oop), 14828 TEST_CASE_ST(ut_setup, ut_teardown, 14829 test_snow3g_decryption_test_case_1_oop), 14830 14831 /** SNOW 3G generate auth, then encrypt (UEA2) */ 14832 TEST_CASE_ST(ut_setup, ut_teardown, 14833 test_snow3g_auth_cipher_test_case_1), 14834 TEST_CASE_ST(ut_setup, ut_teardown, 14835 test_snow3g_auth_cipher_test_case_2), 14836 TEST_CASE_ST(ut_setup, ut_teardown, 14837 test_snow3g_auth_cipher_test_case_2_oop), 14838 TEST_CASE_ST(ut_setup, ut_teardown, 14839 test_snow3g_auth_cipher_part_digest_enc), 14840 TEST_CASE_ST(ut_setup, ut_teardown, 14841 test_snow3g_auth_cipher_part_digest_enc_oop), 14842 TEST_CASE_ST(ut_setup, ut_teardown, 14843 test_snow3g_auth_cipher_test_case_3_sgl), 14844 TEST_CASE_ST(ut_setup, ut_teardown, 14845 test_snow3g_auth_cipher_test_case_3_oop_sgl), 14846 TEST_CASE_ST(ut_setup, ut_teardown, 14847 test_snow3g_auth_cipher_part_digest_enc_sgl), 14848 TEST_CASE_ST(ut_setup, ut_teardown, 14849 test_snow3g_auth_cipher_part_digest_enc_oop_sgl), 14850 14851 /** SNOW 3G decrypt (UEA2), then verify auth */ 14852 TEST_CASE_ST(ut_setup, ut_teardown, 14853 test_snow3g_auth_cipher_verify_test_case_1), 14854 TEST_CASE_ST(ut_setup, ut_teardown, 14855 test_snow3g_auth_cipher_verify_test_case_2), 14856 TEST_CASE_ST(ut_setup, ut_teardown, 14857 test_snow3g_auth_cipher_verify_test_case_2_oop), 14858 TEST_CASE_ST(ut_setup, ut_teardown, 14859 test_snow3g_auth_cipher_verify_part_digest_enc), 14860 TEST_CASE_ST(ut_setup, ut_teardown, 14861 test_snow3g_auth_cipher_verify_part_digest_enc_oop), 14862 TEST_CASE_ST(ut_setup, ut_teardown, 14863 test_snow3g_auth_cipher_verify_test_case_3_sgl), 14864 TEST_CASE_ST(ut_setup, ut_teardown, 14865 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl), 14866 TEST_CASE_ST(ut_setup, ut_teardown, 14867 test_snow3g_auth_cipher_verify_part_digest_enc_sgl), 14868 TEST_CASE_ST(ut_setup, ut_teardown, 14869 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl), 14870 14871 /** SNOW 3G decrypt only (UEA2) */ 14872 TEST_CASE_ST(ut_setup, ut_teardown, 14873 test_snow3g_decryption_test_case_1), 14874 TEST_CASE_ST(ut_setup, ut_teardown, 14875 test_snow3g_decryption_test_case_2), 14876 TEST_CASE_ST(ut_setup, ut_teardown, 14877 test_snow3g_decryption_test_case_3), 14878 TEST_CASE_ST(ut_setup, ut_teardown, 14879 test_snow3g_decryption_test_case_4), 14880 TEST_CASE_ST(ut_setup, ut_teardown, 14881 test_snow3g_decryption_test_case_5), 14882 TEST_CASE_ST(ut_setup, ut_teardown, 14883 test_snow3g_decryption_with_digest_test_case_1), 14884 TEST_CASE_ST(ut_setup, ut_teardown, 14885 test_snow3g_hash_generate_test_case_1), 14886 TEST_CASE_ST(ut_setup, ut_teardown, 14887 test_snow3g_hash_generate_test_case_2), 14888 TEST_CASE_ST(ut_setup, ut_teardown, 14889 test_snow3g_hash_generate_test_case_3), 14890 14891 /* Tests with buffers which length is not byte-aligned */ 14892 TEST_CASE_ST(ut_setup, ut_teardown, 14893 test_snow3g_hash_generate_test_case_4), 14894 TEST_CASE_ST(ut_setup, ut_teardown, 14895 test_snow3g_hash_generate_test_case_5), 14896 TEST_CASE_ST(ut_setup, ut_teardown, 14897 test_snow3g_hash_generate_test_case_6), 14898 TEST_CASE_ST(ut_setup, ut_teardown, 14899 test_snow3g_hash_verify_test_case_1), 14900 TEST_CASE_ST(ut_setup, ut_teardown, 14901 test_snow3g_hash_verify_test_case_2), 14902 TEST_CASE_ST(ut_setup, ut_teardown, 14903 test_snow3g_hash_verify_test_case_3), 14904 14905 /* Tests with buffers which length is not byte-aligned */ 14906 TEST_CASE_ST(ut_setup, ut_teardown, 14907 test_snow3g_hash_verify_test_case_4), 14908 TEST_CASE_ST(ut_setup, ut_teardown, 14909 test_snow3g_hash_verify_test_case_5), 14910 TEST_CASE_ST(ut_setup, ut_teardown, 14911 test_snow3g_hash_verify_test_case_6), 14912 TEST_CASE_ST(ut_setup, ut_teardown, 14913 test_snow3g_cipher_auth_test_case_1), 14914 TEST_CASE_ST(ut_setup, ut_teardown, 14915 test_snow3g_auth_cipher_with_digest_test_case_1), 14916 TEST_CASES_END() 14917 } 14918 }; 14919 14920 static struct unit_test_suite cryptodev_zuc_testsuite = { 14921 .suite_name = "ZUC Test Suite", 14922 .setup = zuc_testsuite_setup, 14923 .unit_test_cases = { 14924 /** ZUC encrypt only (EEA3) */ 14925 TEST_CASE_ST(ut_setup, ut_teardown, 14926 test_zuc_encryption_test_case_1), 14927 TEST_CASE_ST(ut_setup, ut_teardown, 14928 test_zuc_encryption_test_case_2), 14929 TEST_CASE_ST(ut_setup, ut_teardown, 14930 test_zuc_encryption_test_case_3), 14931 TEST_CASE_ST(ut_setup, ut_teardown, 14932 test_zuc_encryption_test_case_4), 14933 TEST_CASE_ST(ut_setup, ut_teardown, 14934 test_zuc_encryption_test_case_5), 14935 TEST_CASE_ST(ut_setup, ut_teardown, 14936 test_zuc_encryption_test_case_6_sgl), 14937 TEST_CASE_ST(ut_setup, ut_teardown, 14938 test_zuc_encryption_test_case_7), 14939 14940 /** ZUC authenticate (EIA3) */ 14941 TEST_CASE_ST(ut_setup, ut_teardown, 14942 test_zuc_hash_generate_test_case_1), 14943 TEST_CASE_ST(ut_setup, ut_teardown, 14944 test_zuc_hash_generate_test_case_2), 14945 TEST_CASE_ST(ut_setup, ut_teardown, 14946 test_zuc_hash_generate_test_case_3), 14947 TEST_CASE_ST(ut_setup, ut_teardown, 14948 test_zuc_hash_generate_test_case_4), 14949 TEST_CASE_ST(ut_setup, ut_teardown, 14950 test_zuc_hash_generate_test_case_5), 14951 TEST_CASE_ST(ut_setup, ut_teardown, 14952 test_zuc_hash_generate_test_case_6), 14953 TEST_CASE_ST(ut_setup, ut_teardown, 14954 test_zuc_hash_generate_test_case_7), 14955 TEST_CASE_ST(ut_setup, ut_teardown, 14956 test_zuc_hash_generate_test_case_8), 14957 TEST_CASE_ST(ut_setup, ut_teardown, 14958 test_zuc_hash_generate_test_case_9), 14959 TEST_CASE_ST(ut_setup, ut_teardown, 14960 test_zuc_hash_generate_test_case_10), 14961 14962 14963 /** ZUC alg-chain (EEA3/EIA3) */ 14964 TEST_CASE_ST(ut_setup, ut_teardown, 14965 test_zuc_cipher_auth_test_case_1), 14966 TEST_CASE_ST(ut_setup, ut_teardown, 14967 test_zuc_cipher_auth_test_case_2), 14968 14969 /** ZUC generate auth, then encrypt (EEA3) */ 14970 TEST_CASE_ST(ut_setup, ut_teardown, 14971 test_zuc_auth_cipher_test_case_1), 14972 TEST_CASE_ST(ut_setup, ut_teardown, 14973 test_zuc_auth_cipher_test_case_1_oop), 14974 TEST_CASE_ST(ut_setup, ut_teardown, 14975 test_zuc_auth_cipher_test_case_1_sgl), 14976 TEST_CASE_ST(ut_setup, ut_teardown, 14977 test_zuc_auth_cipher_test_case_1_oop_sgl), 14978 14979 /** ZUC decrypt (EEA3), then verify auth */ 14980 TEST_CASE_ST(ut_setup, ut_teardown, 14981 test_zuc_auth_cipher_verify_test_case_1), 14982 TEST_CASE_ST(ut_setup, ut_teardown, 14983 test_zuc_auth_cipher_verify_test_case_1_oop), 14984 TEST_CASE_ST(ut_setup, ut_teardown, 14985 test_zuc_auth_cipher_verify_test_case_1_sgl), 14986 TEST_CASE_ST(ut_setup, ut_teardown, 14987 test_zuc_auth_cipher_verify_test_case_1_oop_sgl), 14988 14989 /** ZUC-256 encrypt only **/ 14990 TEST_CASE_ST(ut_setup, ut_teardown, 14991 test_zuc256_encryption_test_case_1), 14992 TEST_CASE_ST(ut_setup, ut_teardown, 14993 test_zuc256_encryption_test_case_2), 14994 14995 /** ZUC-256 authentication only **/ 14996 TEST_CASE_ST(ut_setup, ut_teardown, 14997 test_zuc256_authentication_test_case_1), 14998 TEST_CASE_ST(ut_setup, ut_teardown, 14999 test_zuc256_authentication_test_case_2), 15000 15001 TEST_CASES_END() 15002 } 15003 }; 15004 15005 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite = { 15006 .suite_name = "HMAC_MD5 Authentication Test Suite", 15007 .setup = hmac_md5_auth_testsuite_setup, 15008 .unit_test_cases = { 15009 TEST_CASE_ST(ut_setup, ut_teardown, 15010 test_MD5_HMAC_generate_case_1), 15011 TEST_CASE_ST(ut_setup, ut_teardown, 15012 test_MD5_HMAC_verify_case_1), 15013 TEST_CASE_ST(ut_setup, ut_teardown, 15014 test_MD5_HMAC_generate_case_2), 15015 TEST_CASE_ST(ut_setup, ut_teardown, 15016 test_MD5_HMAC_verify_case_2), 15017 TEST_CASES_END() 15018 } 15019 }; 15020 15021 static struct unit_test_suite cryptodev_kasumi_testsuite = { 15022 .suite_name = "Kasumi Test Suite", 15023 .setup = kasumi_testsuite_setup, 15024 .unit_test_cases = { 15025 /** KASUMI hash only (UIA1) */ 15026 TEST_CASE_ST(ut_setup, ut_teardown, 15027 test_kasumi_hash_generate_test_case_1), 15028 TEST_CASE_ST(ut_setup, ut_teardown, 15029 test_kasumi_hash_generate_test_case_2), 15030 TEST_CASE_ST(ut_setup, ut_teardown, 15031 test_kasumi_hash_generate_test_case_3), 15032 TEST_CASE_ST(ut_setup, ut_teardown, 15033 test_kasumi_hash_generate_test_case_4), 15034 TEST_CASE_ST(ut_setup, ut_teardown, 15035 test_kasumi_hash_generate_test_case_5), 15036 TEST_CASE_ST(ut_setup, ut_teardown, 15037 test_kasumi_hash_generate_test_case_6), 15038 15039 TEST_CASE_ST(ut_setup, ut_teardown, 15040 test_kasumi_hash_verify_test_case_1), 15041 TEST_CASE_ST(ut_setup, ut_teardown, 15042 test_kasumi_hash_verify_test_case_2), 15043 TEST_CASE_ST(ut_setup, ut_teardown, 15044 test_kasumi_hash_verify_test_case_3), 15045 TEST_CASE_ST(ut_setup, ut_teardown, 15046 test_kasumi_hash_verify_test_case_4), 15047 TEST_CASE_ST(ut_setup, ut_teardown, 15048 test_kasumi_hash_verify_test_case_5), 15049 15050 /** KASUMI encrypt only (UEA1) */ 15051 TEST_CASE_ST(ut_setup, ut_teardown, 15052 test_kasumi_encryption_test_case_1), 15053 TEST_CASE_ST(ut_setup, ut_teardown, 15054 test_kasumi_encryption_test_case_1_sgl), 15055 TEST_CASE_ST(ut_setup, ut_teardown, 15056 test_kasumi_encryption_test_case_1_oop), 15057 TEST_CASE_ST(ut_setup, ut_teardown, 15058 test_kasumi_encryption_test_case_1_oop_sgl), 15059 TEST_CASE_ST(ut_setup, ut_teardown, 15060 test_kasumi_encryption_test_case_2), 15061 TEST_CASE_ST(ut_setup, ut_teardown, 15062 test_kasumi_encryption_test_case_3), 15063 TEST_CASE_ST(ut_setup, ut_teardown, 15064 test_kasumi_encryption_test_case_4), 15065 TEST_CASE_ST(ut_setup, ut_teardown, 15066 test_kasumi_encryption_test_case_5), 15067 15068 /** KASUMI decrypt only (UEA1) */ 15069 TEST_CASE_ST(ut_setup, ut_teardown, 15070 test_kasumi_decryption_test_case_1), 15071 TEST_CASE_ST(ut_setup, ut_teardown, 15072 test_kasumi_decryption_test_case_2), 15073 TEST_CASE_ST(ut_setup, ut_teardown, 15074 test_kasumi_decryption_test_case_3), 15075 TEST_CASE_ST(ut_setup, ut_teardown, 15076 test_kasumi_decryption_test_case_4), 15077 TEST_CASE_ST(ut_setup, ut_teardown, 15078 test_kasumi_decryption_test_case_5), 15079 TEST_CASE_ST(ut_setup, ut_teardown, 15080 test_kasumi_decryption_test_case_1_oop), 15081 TEST_CASE_ST(ut_setup, ut_teardown, 15082 test_kasumi_cipher_auth_test_case_1), 15083 15084 /** KASUMI generate auth, then encrypt (F8) */ 15085 TEST_CASE_ST(ut_setup, ut_teardown, 15086 test_kasumi_auth_cipher_test_case_1), 15087 TEST_CASE_ST(ut_setup, ut_teardown, 15088 test_kasumi_auth_cipher_test_case_2), 15089 TEST_CASE_ST(ut_setup, ut_teardown, 15090 test_kasumi_auth_cipher_test_case_2_oop), 15091 TEST_CASE_ST(ut_setup, ut_teardown, 15092 test_kasumi_auth_cipher_test_case_2_sgl), 15093 TEST_CASE_ST(ut_setup, ut_teardown, 15094 test_kasumi_auth_cipher_test_case_2_oop_sgl), 15095 15096 /** KASUMI decrypt (F8), then verify auth */ 15097 TEST_CASE_ST(ut_setup, ut_teardown, 15098 test_kasumi_auth_cipher_verify_test_case_1), 15099 TEST_CASE_ST(ut_setup, ut_teardown, 15100 test_kasumi_auth_cipher_verify_test_case_2), 15101 TEST_CASE_ST(ut_setup, ut_teardown, 15102 test_kasumi_auth_cipher_verify_test_case_2_oop), 15103 TEST_CASE_ST(ut_setup, ut_teardown, 15104 test_kasumi_auth_cipher_verify_test_case_2_sgl), 15105 TEST_CASE_ST(ut_setup, ut_teardown, 15106 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl), 15107 15108 TEST_CASES_END() 15109 } 15110 }; 15111 15112 static struct unit_test_suite cryptodev_esn_testsuite = { 15113 .suite_name = "ESN Test Suite", 15114 .setup = esn_testsuite_setup, 15115 .unit_test_cases = { 15116 TEST_CASE_ST(ut_setup, ut_teardown, 15117 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 15118 TEST_CASE_ST(ut_setup, ut_teardown, 15119 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 15120 TEST_CASES_END() 15121 } 15122 }; 15123 15124 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite = { 15125 .suite_name = "Negative AES GCM Test Suite", 15126 .setup = negative_aes_gcm_testsuite_setup, 15127 .unit_test_cases = { 15128 TEST_CASE_ST(ut_setup, ut_teardown, 15129 test_AES_GCM_auth_encryption_fail_iv_corrupt), 15130 TEST_CASE_ST(ut_setup, ut_teardown, 15131 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 15132 TEST_CASE_ST(ut_setup, ut_teardown, 15133 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 15134 TEST_CASE_ST(ut_setup, ut_teardown, 15135 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 15136 TEST_CASE_ST(ut_setup, ut_teardown, 15137 test_AES_GCM_auth_encryption_fail_aad_corrupt), 15138 TEST_CASE_ST(ut_setup, ut_teardown, 15139 test_AES_GCM_auth_encryption_fail_tag_corrupt), 15140 TEST_CASE_ST(ut_setup, ut_teardown, 15141 test_AES_GCM_auth_decryption_fail_iv_corrupt), 15142 TEST_CASE_ST(ut_setup, ut_teardown, 15143 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 15144 TEST_CASE_ST(ut_setup, ut_teardown, 15145 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 15146 TEST_CASE_ST(ut_setup, ut_teardown, 15147 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 15148 TEST_CASE_ST(ut_setup, ut_teardown, 15149 test_AES_GCM_auth_decryption_fail_aad_corrupt), 15150 TEST_CASE_ST(ut_setup, ut_teardown, 15151 test_AES_GCM_auth_decryption_fail_tag_corrupt), 15152 15153 TEST_CASES_END() 15154 } 15155 }; 15156 15157 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite = { 15158 .suite_name = "Negative AES GMAC Test Suite", 15159 .setup = negative_aes_gmac_testsuite_setup, 15160 .unit_test_cases = { 15161 TEST_CASE_ST(ut_setup, ut_teardown, 15162 authentication_verify_AES128_GMAC_fail_data_corrupt), 15163 TEST_CASE_ST(ut_setup, ut_teardown, 15164 authentication_verify_AES128_GMAC_fail_tag_corrupt), 15165 15166 TEST_CASES_END() 15167 } 15168 }; 15169 15170 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite = { 15171 .suite_name = "Mixed CIPHER + HASH algorithms Test Suite", 15172 .setup = mixed_cipher_hash_testsuite_setup, 15173 .unit_test_cases = { 15174 /** AUTH AES CMAC + CIPHER AES CTR */ 15175 TEST_CASE_ST(ut_setup, ut_teardown, 15176 test_aes_cmac_aes_ctr_digest_enc_test_case_1), 15177 TEST_CASE_ST(ut_setup, ut_teardown, 15178 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 15179 TEST_CASE_ST(ut_setup, ut_teardown, 15180 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 15181 TEST_CASE_ST(ut_setup, ut_teardown, 15182 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 15183 TEST_CASE_ST(ut_setup, ut_teardown, 15184 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1), 15185 TEST_CASE_ST(ut_setup, ut_teardown, 15186 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 15187 TEST_CASE_ST(ut_setup, ut_teardown, 15188 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 15189 TEST_CASE_ST(ut_setup, ut_teardown, 15190 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 15191 15192 /** AUTH ZUC + CIPHER SNOW3G */ 15193 TEST_CASE_ST(ut_setup, ut_teardown, 15194 test_auth_zuc_cipher_snow_test_case_1), 15195 TEST_CASE_ST(ut_setup, ut_teardown, 15196 test_verify_auth_zuc_cipher_snow_test_case_1), 15197 /** AUTH AES CMAC + CIPHER SNOW3G */ 15198 TEST_CASE_ST(ut_setup, ut_teardown, 15199 test_auth_aes_cmac_cipher_snow_test_case_1), 15200 TEST_CASE_ST(ut_setup, ut_teardown, 15201 test_verify_auth_aes_cmac_cipher_snow_test_case_1), 15202 /** AUTH ZUC + CIPHER AES CTR */ 15203 TEST_CASE_ST(ut_setup, ut_teardown, 15204 test_auth_zuc_cipher_aes_ctr_test_case_1), 15205 TEST_CASE_ST(ut_setup, ut_teardown, 15206 test_verify_auth_zuc_cipher_aes_ctr_test_case_1), 15207 /** AUTH SNOW3G + CIPHER AES CTR */ 15208 TEST_CASE_ST(ut_setup, ut_teardown, 15209 test_auth_snow_cipher_aes_ctr_test_case_1), 15210 TEST_CASE_ST(ut_setup, ut_teardown, 15211 test_verify_auth_snow_cipher_aes_ctr_test_case_1), 15212 /** AUTH SNOW3G + CIPHER ZUC */ 15213 TEST_CASE_ST(ut_setup, ut_teardown, 15214 test_auth_snow_cipher_zuc_test_case_1), 15215 TEST_CASE_ST(ut_setup, ut_teardown, 15216 test_verify_auth_snow_cipher_zuc_test_case_1), 15217 /** AUTH AES CMAC + CIPHER ZUC */ 15218 TEST_CASE_ST(ut_setup, ut_teardown, 15219 test_auth_aes_cmac_cipher_zuc_test_case_1), 15220 TEST_CASE_ST(ut_setup, ut_teardown, 15221 test_verify_auth_aes_cmac_cipher_zuc_test_case_1), 15222 15223 /** AUTH NULL + CIPHER SNOW3G */ 15224 TEST_CASE_ST(ut_setup, ut_teardown, 15225 test_auth_null_cipher_snow_test_case_1), 15226 TEST_CASE_ST(ut_setup, ut_teardown, 15227 test_verify_auth_null_cipher_snow_test_case_1), 15228 /** AUTH NULL + CIPHER ZUC */ 15229 TEST_CASE_ST(ut_setup, ut_teardown, 15230 test_auth_null_cipher_zuc_test_case_1), 15231 TEST_CASE_ST(ut_setup, ut_teardown, 15232 test_verify_auth_null_cipher_zuc_test_case_1), 15233 /** AUTH SNOW3G + CIPHER NULL */ 15234 TEST_CASE_ST(ut_setup, ut_teardown, 15235 test_auth_snow_cipher_null_test_case_1), 15236 TEST_CASE_ST(ut_setup, ut_teardown, 15237 test_verify_auth_snow_cipher_null_test_case_1), 15238 /** AUTH ZUC + CIPHER NULL */ 15239 TEST_CASE_ST(ut_setup, ut_teardown, 15240 test_auth_zuc_cipher_null_test_case_1), 15241 TEST_CASE_ST(ut_setup, ut_teardown, 15242 test_verify_auth_zuc_cipher_null_test_case_1), 15243 /** AUTH NULL + CIPHER AES CTR */ 15244 TEST_CASE_ST(ut_setup, ut_teardown, 15245 test_auth_null_cipher_aes_ctr_test_case_1), 15246 TEST_CASE_ST(ut_setup, ut_teardown, 15247 test_verify_auth_null_cipher_aes_ctr_test_case_1), 15248 /** AUTH AES CMAC + CIPHER NULL */ 15249 TEST_CASE_ST(ut_setup, ut_teardown, 15250 test_auth_aes_cmac_cipher_null_test_case_1), 15251 TEST_CASE_ST(ut_setup, ut_teardown, 15252 test_verify_auth_aes_cmac_cipher_null_test_case_1), 15253 TEST_CASES_END() 15254 } 15255 }; 15256 15257 static int 15258 run_cryptodev_testsuite(const char *pmd_name) 15259 { 15260 uint8_t ret, j, i = 0, blk_start_idx = 0; 15261 const enum blockcipher_test_type blk_suites[] = { 15262 BLKCIPHER_AES_CHAIN_TYPE, 15263 BLKCIPHER_AES_CIPHERONLY_TYPE, 15264 BLKCIPHER_AES_DOCSIS_TYPE, 15265 BLKCIPHER_3DES_CHAIN_TYPE, 15266 BLKCIPHER_3DES_CIPHERONLY_TYPE, 15267 BLKCIPHER_DES_CIPHERONLY_TYPE, 15268 BLKCIPHER_DES_DOCSIS_TYPE, 15269 BLKCIPHER_AUTHONLY_TYPE}; 15270 struct unit_test_suite *static_suites[] = { 15271 &cryptodev_multi_session_testsuite, 15272 &cryptodev_null_testsuite, 15273 &cryptodev_aes_ccm_auth_testsuite, 15274 &cryptodev_aes_gcm_auth_testsuite, 15275 &cryptodev_aes_gmac_auth_testsuite, 15276 &cryptodev_snow3g_testsuite, 15277 &cryptodev_chacha20_poly1305_testsuite, 15278 &cryptodev_zuc_testsuite, 15279 &cryptodev_hmac_md5_auth_testsuite, 15280 &cryptodev_kasumi_testsuite, 15281 &cryptodev_esn_testsuite, 15282 &cryptodev_negative_aes_gcm_testsuite, 15283 &cryptodev_negative_aes_gmac_testsuite, 15284 &cryptodev_mixed_cipher_hash_testsuite, 15285 &cryptodev_negative_hmac_sha1_testsuite, 15286 &cryptodev_gen_testsuite, 15287 #ifdef RTE_LIB_SECURITY 15288 &ipsec_proto_testsuite, 15289 &pdcp_proto_testsuite, 15290 &docsis_proto_testsuite, 15291 #endif 15292 &end_testsuite 15293 }; 15294 static struct unit_test_suite ts = { 15295 .suite_name = "Cryptodev Unit Test Suite", 15296 .setup = testsuite_setup, 15297 .teardown = testsuite_teardown, 15298 .unit_test_cases = {TEST_CASES_END()} 15299 }; 15300 15301 gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name); 15302 15303 if (gbl_driver_id == -1) { 15304 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name); 15305 return TEST_SKIPPED; 15306 } 15307 15308 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 15309 (RTE_DIM(blk_suites) + RTE_DIM(static_suites))); 15310 15311 ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites)); 15312 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 15313 ret = unit_test_suite_runner(&ts); 15314 15315 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites)); 15316 free(ts.unit_test_suites); 15317 return ret; 15318 } 15319 15320 static int 15321 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name) 15322 { 15323 struct rte_cryptodev_info dev_info; 15324 uint8_t i, nb_devs; 15325 int driver_id; 15326 15327 driver_id = rte_cryptodev_driver_id_get(pmd_name); 15328 if (driver_id == -1) { 15329 RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name); 15330 return TEST_SKIPPED; 15331 } 15332 15333 nb_devs = rte_cryptodev_count(); 15334 if (nb_devs < 1) { 15335 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 15336 return TEST_SKIPPED; 15337 } 15338 15339 for (i = 0; i < nb_devs; i++) { 15340 rte_cryptodev_info_get(i, &dev_info); 15341 if (dev_info.driver_id == driver_id) { 15342 if (!(dev_info.feature_flags & flag)) { 15343 RTE_LOG(INFO, USER1, "%s not supported\n", 15344 flag_name); 15345 return TEST_SKIPPED; 15346 } 15347 return 0; /* found */ 15348 } 15349 } 15350 15351 RTE_LOG(INFO, USER1, "%s not supported\n", flag_name); 15352 return TEST_SKIPPED; 15353 } 15354 15355 static int 15356 test_cryptodev_qat(void) 15357 { 15358 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 15359 } 15360 15361 static int 15362 test_cryptodev_virtio(void) 15363 { 15364 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)); 15365 } 15366 15367 static int 15368 test_cryptodev_aesni_mb(void) 15369 { 15370 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 15371 } 15372 15373 static int 15374 test_cryptodev_cpu_aesni_mb(void) 15375 { 15376 int32_t rc; 15377 enum rte_security_session_action_type at = gbl_action_type; 15378 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 15379 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 15380 gbl_action_type = at; 15381 return rc; 15382 } 15383 15384 static int 15385 test_cryptodev_chacha_poly_mb(void) 15386 { 15387 int32_t rc; 15388 enum rte_security_session_action_type at = gbl_action_type; 15389 rc = run_cryptodev_testsuite( 15390 RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD)); 15391 gbl_action_type = at; 15392 return rc; 15393 } 15394 15395 static int 15396 test_cryptodev_openssl(void) 15397 { 15398 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 15399 } 15400 15401 static int 15402 test_cryptodev_aesni_gcm(void) 15403 { 15404 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 15405 } 15406 15407 static int 15408 test_cryptodev_cpu_aesni_gcm(void) 15409 { 15410 int32_t rc; 15411 enum rte_security_session_action_type at = gbl_action_type; 15412 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 15413 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 15414 gbl_action_type = at; 15415 return rc; 15416 } 15417 15418 static int 15419 test_cryptodev_mlx5(void) 15420 { 15421 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD)); 15422 } 15423 15424 static int 15425 test_cryptodev_null(void) 15426 { 15427 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 15428 } 15429 15430 static int 15431 test_cryptodev_sw_snow3g(void) 15432 { 15433 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 15434 } 15435 15436 static int 15437 test_cryptodev_sw_kasumi(void) 15438 { 15439 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 15440 } 15441 15442 static int 15443 test_cryptodev_sw_zuc(void) 15444 { 15445 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 15446 } 15447 15448 static int 15449 test_cryptodev_armv8(void) 15450 { 15451 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 15452 } 15453 15454 static int 15455 test_cryptodev_mrvl(void) 15456 { 15457 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 15458 } 15459 15460 #ifdef RTE_CRYPTO_SCHEDULER 15461 15462 static int 15463 test_cryptodev_scheduler(void) 15464 { 15465 uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0; 15466 const enum blockcipher_test_type blk_suites[] = { 15467 BLKCIPHER_AES_CHAIN_TYPE, 15468 BLKCIPHER_AES_CIPHERONLY_TYPE, 15469 BLKCIPHER_AUTHONLY_TYPE 15470 }; 15471 static struct unit_test_suite scheduler_multicore = { 15472 .suite_name = "Scheduler Multicore Unit Test Suite", 15473 .setup = scheduler_multicore_testsuite_setup, 15474 .teardown = scheduler_mode_testsuite_teardown, 15475 .unit_test_cases = {TEST_CASES_END()} 15476 }; 15477 static struct unit_test_suite scheduler_round_robin = { 15478 .suite_name = "Scheduler Round Robin Unit Test Suite", 15479 .setup = scheduler_roundrobin_testsuite_setup, 15480 .teardown = scheduler_mode_testsuite_teardown, 15481 .unit_test_cases = {TEST_CASES_END()} 15482 }; 15483 static struct unit_test_suite scheduler_failover = { 15484 .suite_name = "Scheduler Failover Unit Test Suite", 15485 .setup = scheduler_failover_testsuite_setup, 15486 .teardown = scheduler_mode_testsuite_teardown, 15487 .unit_test_cases = {TEST_CASES_END()} 15488 }; 15489 static struct unit_test_suite scheduler_pkt_size_distr = { 15490 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite", 15491 .setup = scheduler_pkt_size_distr_testsuite_setup, 15492 .teardown = scheduler_mode_testsuite_teardown, 15493 .unit_test_cases = {TEST_CASES_END()} 15494 }; 15495 struct unit_test_suite *sched_mode_suites[] = { 15496 &scheduler_multicore, 15497 &scheduler_round_robin, 15498 &scheduler_failover, 15499 &scheduler_pkt_size_distr 15500 }; 15501 static struct unit_test_suite scheduler_config = { 15502 .suite_name = "Crypto Device Scheduler Config Unit Test Suite", 15503 .unit_test_cases = { 15504 TEST_CASE(test_scheduler_attach_worker_op), 15505 TEST_CASE(test_scheduler_mode_multicore_op), 15506 TEST_CASE(test_scheduler_mode_roundrobin_op), 15507 TEST_CASE(test_scheduler_mode_failover_op), 15508 TEST_CASE(test_scheduler_mode_pkt_size_distr_op), 15509 TEST_CASE(test_scheduler_detach_worker_op), 15510 15511 TEST_CASES_END() /**< NULL terminate array */ 15512 } 15513 }; 15514 struct unit_test_suite *static_suites[] = { 15515 &scheduler_config, 15516 &end_testsuite 15517 }; 15518 static struct unit_test_suite ts = { 15519 .suite_name = "Scheduler Unit Test Suite", 15520 .setup = scheduler_testsuite_setup, 15521 .teardown = testsuite_teardown, 15522 .unit_test_cases = {TEST_CASES_END()} 15523 }; 15524 15525 gbl_driver_id = rte_cryptodev_driver_id_get( 15526 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 15527 15528 if (gbl_driver_id == -1) { 15529 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n"); 15530 return TEST_SKIPPED; 15531 } 15532 15533 if (rte_cryptodev_driver_id_get( 15534 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) { 15535 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 15536 return TEST_SKIPPED; 15537 } 15538 15539 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 15540 uint8_t blk_i = 0; 15541 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof 15542 (struct unit_test_suite *) * 15543 (RTE_DIM(blk_suites) + 1)); 15544 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]), 15545 blk_suites, RTE_DIM(blk_suites)); 15546 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite; 15547 } 15548 15549 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 15550 (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites))); 15551 ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites, 15552 RTE_DIM(sched_mode_suites)); 15553 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 15554 ret = unit_test_suite_runner(&ts); 15555 15556 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 15557 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, 15558 (*sched_mode_suites[sched_i]), 15559 RTE_DIM(blk_suites)); 15560 free(sched_mode_suites[sched_i]->unit_test_suites); 15561 } 15562 free(ts.unit_test_suites); 15563 return ret; 15564 } 15565 15566 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler); 15567 15568 #endif 15569 15570 static int 15571 test_cryptodev_dpaa2_sec(void) 15572 { 15573 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 15574 } 15575 15576 static int 15577 test_cryptodev_dpaa_sec(void) 15578 { 15579 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 15580 } 15581 15582 static int 15583 test_cryptodev_ccp(void) 15584 { 15585 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 15586 } 15587 15588 static int 15589 test_cryptodev_octeontx(void) 15590 { 15591 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)); 15592 } 15593 15594 static int 15595 test_cryptodev_octeontx2(void) 15596 { 15597 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD)); 15598 } 15599 15600 static int 15601 test_cryptodev_caam_jr(void) 15602 { 15603 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)); 15604 } 15605 15606 static int 15607 test_cryptodev_nitrox(void) 15608 { 15609 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD)); 15610 } 15611 15612 static int 15613 test_cryptodev_bcmfs(void) 15614 { 15615 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD)); 15616 } 15617 15618 static int 15619 test_cryptodev_qat_raw_api(void) 15620 { 15621 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD); 15622 int ret; 15623 15624 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 15625 "RAW API"); 15626 if (ret) 15627 return ret; 15628 15629 global_api_test_type = CRYPTODEV_RAW_API_TEST; 15630 ret = run_cryptodev_testsuite(pmd_name); 15631 global_api_test_type = CRYPTODEV_API_TEST; 15632 15633 return ret; 15634 } 15635 15636 static int 15637 test_cryptodev_cn9k(void) 15638 { 15639 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD)); 15640 } 15641 15642 static int 15643 test_cryptodev_cn10k(void) 15644 { 15645 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD)); 15646 } 15647 15648 static int 15649 test_cryptodev_dpaa2_sec_raw_api(void) 15650 { 15651 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD); 15652 int ret; 15653 15654 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 15655 "RAW API"); 15656 if (ret) 15657 return ret; 15658 15659 global_api_test_type = CRYPTODEV_RAW_API_TEST; 15660 ret = run_cryptodev_testsuite(pmd_name); 15661 global_api_test_type = CRYPTODEV_API_TEST; 15662 15663 return ret; 15664 } 15665 15666 static int 15667 test_cryptodev_dpaa_sec_raw_api(void) 15668 { 15669 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD); 15670 int ret; 15671 15672 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 15673 "RAW API"); 15674 if (ret) 15675 return ret; 15676 15677 global_api_test_type = CRYPTODEV_RAW_API_TEST; 15678 ret = run_cryptodev_testsuite(pmd_name); 15679 global_api_test_type = CRYPTODEV_API_TEST; 15680 15681 return ret; 15682 } 15683 15684 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_raw_api_autotest, 15685 test_cryptodev_dpaa2_sec_raw_api); 15686 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_raw_api_autotest, 15687 test_cryptodev_dpaa_sec_raw_api); 15688 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest, 15689 test_cryptodev_qat_raw_api); 15690 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat); 15691 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 15692 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest, 15693 test_cryptodev_cpu_aesni_mb); 15694 REGISTER_TEST_COMMAND(cryptodev_chacha_poly_mb_autotest, 15695 test_cryptodev_chacha_poly_mb); 15696 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl); 15697 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 15698 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest, 15699 test_cryptodev_cpu_aesni_gcm); 15700 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5); 15701 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null); 15702 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 15703 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 15704 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 15705 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8); 15706 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl); 15707 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec); 15708 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec); 15709 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp); 15710 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio); 15711 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx); 15712 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2); 15713 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr); 15714 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox); 15715 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs); 15716 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k); 15717 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k); 15718