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 static struct crypto_testsuite_params testsuite_params = { NULL }; 183 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params; 184 static struct crypto_unittest_params unittest_params; 185 186 void 187 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id, 188 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth, 189 uint8_t len_in_bits, uint8_t cipher_iv_len) 190 { 191 struct rte_crypto_sym_op *sop = op->sym; 192 struct rte_crypto_op *ret_op = NULL; 193 struct rte_crypto_vec data_vec[UINT8_MAX], dest_data_vec[UINT8_MAX]; 194 struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv; 195 union rte_crypto_sym_ofs ofs; 196 struct rte_crypto_sym_vec vec; 197 struct rte_crypto_sgl sgl, dest_sgl; 198 uint32_t max_len; 199 union rte_cryptodev_session_ctx sess; 200 uint64_t auth_end_iova; 201 uint32_t count = 0; 202 struct rte_crypto_raw_dp_ctx *ctx; 203 uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0, 204 auth_len = 0; 205 int32_t n; 206 uint32_t n_success; 207 int ctx_service_size; 208 int32_t status = 0; 209 int enqueue_status, dequeue_status; 210 struct crypto_unittest_params *ut_params = &unittest_params; 211 int is_sgl = sop->m_src->nb_segs > 1; 212 int is_oop = 0; 213 214 ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id); 215 if (ctx_service_size < 0) { 216 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 217 return; 218 } 219 220 ctx = malloc(ctx_service_size); 221 if (!ctx) { 222 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 223 return; 224 } 225 226 /* Both are enums, setting crypto_sess will suit any session type */ 227 sess.crypto_sess = op->sym->session; 228 229 if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx, 230 op->sess_type, sess, 0) < 0) { 231 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 232 goto exit; 233 } 234 235 cipher_iv.iova = 0; 236 cipher_iv.va = NULL; 237 aad_auth_iv.iova = 0; 238 aad_auth_iv.va = NULL; 239 digest.iova = 0; 240 digest.va = NULL; 241 sgl.vec = data_vec; 242 vec.num = 1; 243 vec.src_sgl = &sgl; 244 vec.iv = &cipher_iv; 245 vec.digest = &digest; 246 vec.aad = &aad_auth_iv; 247 vec.status = &status; 248 249 ofs.raw = 0; 250 251 if ((sop->m_dst != NULL) && (sop->m_dst != sop->m_src)) 252 is_oop = 1; 253 254 if (is_cipher && is_auth) { 255 cipher_offset = sop->cipher.data.offset; 256 cipher_len = sop->cipher.data.length; 257 auth_offset = sop->auth.data.offset; 258 auth_len = sop->auth.data.length; 259 max_len = RTE_MAX(cipher_offset + cipher_len, 260 auth_offset + auth_len); 261 if (len_in_bits) { 262 max_len = max_len >> 3; 263 cipher_offset = cipher_offset >> 3; 264 auth_offset = auth_offset >> 3; 265 cipher_len = cipher_len >> 3; 266 auth_len = auth_len >> 3; 267 } 268 ofs.ofs.cipher.head = cipher_offset; 269 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 270 ofs.ofs.auth.head = auth_offset; 271 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 272 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 273 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 274 aad_auth_iv.va = rte_crypto_op_ctod_offset( 275 op, void *, IV_OFFSET + cipher_iv_len); 276 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 277 cipher_iv_len); 278 digest.va = (void *)sop->auth.digest.data; 279 digest.iova = sop->auth.digest.phys_addr; 280 281 if (is_sgl) { 282 uint32_t remaining_off = auth_offset + auth_len; 283 struct rte_mbuf *sgl_buf = sop->m_src; 284 if (is_oop) 285 sgl_buf = sop->m_dst; 286 287 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf) 288 && sgl_buf->next != NULL) { 289 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 290 sgl_buf = sgl_buf->next; 291 } 292 293 auth_end_iova = (uint64_t)rte_pktmbuf_iova_offset( 294 sgl_buf, remaining_off); 295 } else { 296 auth_end_iova = rte_pktmbuf_iova(op->sym->m_src) + 297 auth_offset + auth_len; 298 } 299 /* Then check if digest-encrypted conditions are met */ 300 if ((auth_offset + auth_len < cipher_offset + cipher_len) && 301 (digest.iova == auth_end_iova) && is_sgl) 302 max_len = RTE_MAX(max_len, 303 auth_offset + auth_len + 304 ut_params->auth_xform.auth.digest_length); 305 306 } else if (is_cipher) { 307 cipher_offset = sop->cipher.data.offset; 308 cipher_len = sop->cipher.data.length; 309 max_len = cipher_len + cipher_offset; 310 if (len_in_bits) { 311 max_len = max_len >> 3; 312 cipher_offset = cipher_offset >> 3; 313 cipher_len = cipher_len >> 3; 314 } 315 ofs.ofs.cipher.head = cipher_offset; 316 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 317 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 318 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 319 320 } else if (is_auth) { 321 auth_offset = sop->auth.data.offset; 322 auth_len = sop->auth.data.length; 323 max_len = auth_len + auth_offset; 324 if (len_in_bits) { 325 max_len = max_len >> 3; 326 auth_offset = auth_offset >> 3; 327 auth_len = auth_len >> 3; 328 } 329 ofs.ofs.auth.head = auth_offset; 330 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 331 aad_auth_iv.va = rte_crypto_op_ctod_offset( 332 op, void *, IV_OFFSET + cipher_iv_len); 333 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 334 cipher_iv_len); 335 digest.va = (void *)sop->auth.digest.data; 336 digest.iova = sop->auth.digest.phys_addr; 337 338 } else { /* aead */ 339 cipher_offset = sop->aead.data.offset; 340 cipher_len = sop->aead.data.length; 341 max_len = cipher_len + cipher_offset; 342 if (len_in_bits) { 343 max_len = max_len >> 3; 344 cipher_offset = cipher_offset >> 3; 345 cipher_len = cipher_len >> 3; 346 } 347 ofs.ofs.cipher.head = cipher_offset; 348 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 349 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 350 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 351 aad_auth_iv.va = (void *)sop->aead.aad.data; 352 aad_auth_iv.iova = sop->aead.aad.phys_addr; 353 digest.va = (void *)sop->aead.digest.data; 354 digest.iova = sop->aead.digest.phys_addr; 355 } 356 357 n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len, 358 data_vec, RTE_DIM(data_vec)); 359 if (n < 0 || n > sop->m_src->nb_segs) { 360 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 361 goto exit; 362 } 363 364 sgl.num = n; 365 /* Out of place */ 366 if (is_oop) { 367 dest_sgl.vec = dest_data_vec; 368 vec.dest_sgl = &dest_sgl; 369 n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len, 370 dest_data_vec, RTE_DIM(dest_data_vec)); 371 if (n < 0 || n > sop->m_dst->nb_segs) { 372 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 373 goto exit; 374 } 375 dest_sgl.num = n; 376 } else 377 vec.dest_sgl = NULL; 378 379 if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op, 380 &enqueue_status) < 1) { 381 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 382 goto exit; 383 } 384 385 if (enqueue_status == 0) { 386 status = rte_cryptodev_raw_enqueue_done(ctx, 1); 387 if (status < 0) { 388 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 389 goto exit; 390 } 391 } else if (enqueue_status < 0) { 392 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 393 goto exit; 394 } 395 396 n = n_success = 0; 397 while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) { 398 n = rte_cryptodev_raw_dequeue_burst(ctx, 399 NULL, 1, post_process_raw_dp_op, 400 (void **)&ret_op, 0, &n_success, 401 &dequeue_status); 402 if (dequeue_status < 0) { 403 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 404 goto exit; 405 } 406 if (n == 0) 407 rte_pause(); 408 } 409 410 if (n == 1 && dequeue_status == 0) { 411 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) { 412 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 413 goto exit; 414 } 415 } 416 417 op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op || 418 ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR || 419 n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR : 420 RTE_CRYPTO_OP_STATUS_SUCCESS; 421 422 exit: 423 free(ctx); 424 } 425 426 static void 427 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op) 428 { 429 int32_t n, st; 430 struct rte_crypto_sym_op *sop; 431 union rte_crypto_sym_ofs ofs; 432 struct rte_crypto_sgl sgl; 433 struct rte_crypto_sym_vec symvec; 434 struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr; 435 struct rte_crypto_vec vec[UINT8_MAX]; 436 437 sop = op->sym; 438 439 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset, 440 sop->aead.data.length, vec, RTE_DIM(vec)); 441 442 if (n < 0 || n != sop->m_src->nb_segs) { 443 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 444 return; 445 } 446 447 sgl.vec = vec; 448 sgl.num = n; 449 symvec.src_sgl = &sgl; 450 symvec.iv = &iv_ptr; 451 symvec.digest = &digest_ptr; 452 symvec.aad = &aad_ptr; 453 symvec.status = &st; 454 symvec.num = 1; 455 456 /* for CPU crypto the IOVA address is not required */ 457 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 458 digest_ptr.va = (void *)sop->aead.digest.data; 459 aad_ptr.va = (void *)sop->aead.aad.data; 460 461 ofs.raw = 0; 462 463 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 464 &symvec); 465 466 if (n != 1) 467 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 468 else 469 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 470 } 471 472 static void 473 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op) 474 { 475 int32_t n, st; 476 struct rte_crypto_sym_op *sop; 477 union rte_crypto_sym_ofs ofs; 478 struct rte_crypto_sgl sgl; 479 struct rte_crypto_sym_vec symvec; 480 struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr; 481 struct rte_crypto_vec vec[UINT8_MAX]; 482 483 sop = op->sym; 484 485 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset, 486 sop->auth.data.length, vec, RTE_DIM(vec)); 487 488 if (n < 0 || n != sop->m_src->nb_segs) { 489 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 490 return; 491 } 492 493 sgl.vec = vec; 494 sgl.num = n; 495 symvec.src_sgl = &sgl; 496 symvec.iv = &iv_ptr; 497 symvec.digest = &digest_ptr; 498 symvec.status = &st; 499 symvec.num = 1; 500 501 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 502 digest_ptr.va = (void *)sop->auth.digest.data; 503 504 ofs.raw = 0; 505 ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset; 506 ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) - 507 (sop->cipher.data.offset + sop->cipher.data.length); 508 509 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 510 &symvec); 511 512 if (n != 1) 513 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 514 else 515 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 516 } 517 518 static struct rte_crypto_op * 519 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op) 520 { 521 522 RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO); 523 524 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 525 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n"); 526 return NULL; 527 } 528 529 op = NULL; 530 531 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 532 rte_pause(); 533 534 if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 535 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status); 536 return NULL; 537 } 538 539 return op; 540 } 541 542 static int 543 testsuite_setup(void) 544 { 545 struct crypto_testsuite_params *ts_params = &testsuite_params; 546 struct rte_cryptodev_info info; 547 uint32_t i = 0, nb_devs, dev_id; 548 uint16_t qp_id; 549 550 memset(ts_params, 0, sizeof(*ts_params)); 551 552 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 553 if (ts_params->mbuf_pool == NULL) { 554 /* Not already created so create */ 555 ts_params->mbuf_pool = rte_pktmbuf_pool_create( 556 "CRYPTO_MBUFPOOL", 557 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE, 558 rte_socket_id()); 559 if (ts_params->mbuf_pool == NULL) { 560 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n"); 561 return TEST_FAILED; 562 } 563 } 564 565 ts_params->large_mbuf_pool = rte_mempool_lookup( 566 "CRYPTO_LARGE_MBUFPOOL"); 567 if (ts_params->large_mbuf_pool == NULL) { 568 /* Not already created so create */ 569 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create( 570 "CRYPTO_LARGE_MBUFPOOL", 571 1, 0, 0, UINT16_MAX, 572 rte_socket_id()); 573 if (ts_params->large_mbuf_pool == NULL) { 574 RTE_LOG(ERR, USER1, 575 "Can't create CRYPTO_LARGE_MBUFPOOL\n"); 576 return TEST_FAILED; 577 } 578 } 579 580 ts_params->op_mpool = rte_crypto_op_pool_create( 581 "MBUF_CRYPTO_SYM_OP_POOL", 582 RTE_CRYPTO_OP_TYPE_SYMMETRIC, 583 NUM_MBUFS, MBUF_CACHE_SIZE, 584 DEFAULT_NUM_XFORMS * 585 sizeof(struct rte_crypto_sym_xform) + 586 MAXIMUM_IV_LENGTH, 587 rte_socket_id()); 588 if (ts_params->op_mpool == NULL) { 589 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n"); 590 return TEST_FAILED; 591 } 592 593 nb_devs = rte_cryptodev_count(); 594 if (nb_devs < 1) { 595 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 596 return TEST_SKIPPED; 597 } 598 599 if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) { 600 RTE_LOG(WARNING, USER1, "No %s devices found?\n", 601 rte_cryptodev_driver_name_get(gbl_driver_id)); 602 return TEST_SKIPPED; 603 } 604 605 /* Create list of valid crypto devs */ 606 for (i = 0; i < nb_devs; i++) { 607 rte_cryptodev_info_get(i, &info); 608 if (info.driver_id == gbl_driver_id) 609 ts_params->valid_devs[ts_params->valid_dev_count++] = i; 610 } 611 612 if (ts_params->valid_dev_count < 1) 613 return TEST_FAILED; 614 615 /* Set up all the qps on the first of the valid devices found */ 616 617 dev_id = ts_params->valid_devs[0]; 618 619 rte_cryptodev_info_get(dev_id, &info); 620 621 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; 622 ts_params->conf.socket_id = SOCKET_ID_ANY; 623 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY; 624 625 unsigned int session_size = 626 rte_cryptodev_sym_get_private_session_size(dev_id); 627 628 #ifdef RTE_LIB_SECURITY 629 unsigned int security_session_size = rte_security_session_get_size( 630 rte_cryptodev_get_sec_ctx(dev_id)); 631 632 if (session_size < security_session_size) 633 session_size = security_session_size; 634 #endif 635 /* 636 * Create mempool with maximum number of sessions. 637 */ 638 if (info.sym.max_nb_sessions != 0 && 639 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 640 RTE_LOG(ERR, USER1, "Device does not support " 641 "at least %u sessions\n", 642 MAX_NB_SESSIONS); 643 return TEST_FAILED; 644 } 645 646 ts_params->session_mpool = rte_cryptodev_sym_session_pool_create( 647 "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0, 648 SOCKET_ID_ANY); 649 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 650 "session mempool allocation failed"); 651 652 ts_params->session_priv_mpool = rte_mempool_create( 653 "test_sess_mp_priv", 654 MAX_NB_SESSIONS, 655 session_size, 656 0, 0, NULL, NULL, NULL, 657 NULL, SOCKET_ID_ANY, 658 0); 659 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 660 "session mempool allocation failed"); 661 662 663 664 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, 665 &ts_params->conf), 666 "Failed to configure cryptodev %u with %u qps", 667 dev_id, ts_params->conf.nb_queue_pairs); 668 669 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 670 ts_params->qp_conf.mp_session = ts_params->session_mpool; 671 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 672 673 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 674 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 675 dev_id, qp_id, &ts_params->qp_conf, 676 rte_cryptodev_socket_id(dev_id)), 677 "Failed to setup queue pair %u on cryptodev %u", 678 qp_id, dev_id); 679 } 680 681 return TEST_SUCCESS; 682 } 683 684 static void 685 testsuite_teardown(void) 686 { 687 struct crypto_testsuite_params *ts_params = &testsuite_params; 688 int res; 689 690 if (ts_params->mbuf_pool != NULL) { 691 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 692 rte_mempool_avail_count(ts_params->mbuf_pool)); 693 } 694 695 if (ts_params->op_mpool != NULL) { 696 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", 697 rte_mempool_avail_count(ts_params->op_mpool)); 698 } 699 700 /* Free session mempools */ 701 if (ts_params->session_priv_mpool != NULL) { 702 rte_mempool_free(ts_params->session_priv_mpool); 703 ts_params->session_priv_mpool = NULL; 704 } 705 706 if (ts_params->session_mpool != NULL) { 707 rte_mempool_free(ts_params->session_mpool); 708 ts_params->session_mpool = NULL; 709 } 710 711 res = rte_cryptodev_close(ts_params->valid_devs[0]); 712 if (res) 713 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res); 714 } 715 716 static int 717 check_capabilities_supported(enum rte_crypto_sym_xform_type type, 718 const int *algs, uint16_t num_algs) 719 { 720 uint8_t dev_id = testsuite_params.valid_devs[0]; 721 bool some_alg_supported = FALSE; 722 uint16_t i; 723 724 for (i = 0; i < num_algs && !some_alg_supported; i++) { 725 struct rte_cryptodev_sym_capability_idx alg = { 726 type, {algs[i]} 727 }; 728 if (rte_cryptodev_sym_capability_get(dev_id, 729 &alg) != NULL) 730 some_alg_supported = TRUE; 731 } 732 if (!some_alg_supported) 733 return TEST_SKIPPED; 734 735 return 0; 736 } 737 738 int 739 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers, 740 uint16_t num_ciphers) 741 { 742 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER, 743 (const int *) ciphers, num_ciphers); 744 } 745 746 int 747 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths, 748 uint16_t num_auths) 749 { 750 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH, 751 (const int *) auths, num_auths); 752 } 753 754 int 755 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads, 756 uint16_t num_aeads) 757 { 758 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD, 759 (const int *) aeads, num_aeads); 760 } 761 762 static int 763 null_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 const enum rte_crypto_cipher_algorithm ciphers[] = { 769 RTE_CRYPTO_CIPHER_NULL 770 }; 771 const enum rte_crypto_auth_algorithm auths[] = { 772 RTE_CRYPTO_AUTH_NULL 773 }; 774 775 rte_cryptodev_info_get(dev_id, &dev_info); 776 777 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 778 RTE_LOG(INFO, USER1, "Feature flag requirements for NULL " 779 "testsuite not met\n"); 780 return TEST_SKIPPED; 781 } 782 783 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 784 && check_auth_capabilities_supported(auths, 785 RTE_DIM(auths)) != 0) { 786 RTE_LOG(INFO, USER1, "Capability requirements for NULL " 787 "testsuite not met\n"); 788 return TEST_SKIPPED; 789 } 790 791 return 0; 792 } 793 794 static int 795 crypto_gen_testsuite_setup(void) 796 { 797 struct crypto_testsuite_params *ts_params = &testsuite_params; 798 uint8_t dev_id = ts_params->valid_devs[0]; 799 struct rte_cryptodev_info dev_info; 800 801 rte_cryptodev_info_get(dev_id, &dev_info); 802 803 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 804 RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen " 805 "testsuite not met\n"); 806 return TEST_SKIPPED; 807 } 808 809 return 0; 810 } 811 812 #ifdef RTE_LIB_SECURITY 813 static int 814 ipsec_proto_testsuite_setup(void) 815 { 816 struct crypto_testsuite_params *ts_params = &testsuite_params; 817 struct crypto_unittest_params *ut_params = &unittest_params; 818 struct rte_cryptodev_info dev_info; 819 int ret = 0; 820 821 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 822 823 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) { 824 RTE_LOG(INFO, USER1, "Feature flag requirements for IPsec Proto " 825 "testsuite not met\n"); 826 return TEST_SKIPPED; 827 } 828 829 /* Reconfigure to enable security */ 830 ret = dev_configure_and_start(0); 831 if (ret != TEST_SUCCESS) 832 return ret; 833 834 /* Set action type */ 835 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 836 837 if (security_proto_supported( 838 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 839 RTE_SECURITY_PROTOCOL_IPSEC) < 0) { 840 RTE_LOG(INFO, USER1, "Capability requirements for IPsec Proto " 841 "test not met\n"); 842 ret = TEST_SKIPPED; 843 } 844 845 test_ipsec_alg_list_populate(); 846 test_ipsec_ah_alg_list_populate(); 847 848 /* 849 * Stop the device. Device would be started again by individual test 850 * case setup routine. 851 */ 852 rte_cryptodev_stop(ts_params->valid_devs[0]); 853 854 return ret; 855 } 856 857 static int 858 pdcp_proto_testsuite_setup(void) 859 { 860 struct crypto_testsuite_params *ts_params = &testsuite_params; 861 uint8_t dev_id = ts_params->valid_devs[0]; 862 struct rte_cryptodev_info dev_info; 863 const enum rte_crypto_cipher_algorithm ciphers[] = { 864 RTE_CRYPTO_CIPHER_NULL, 865 RTE_CRYPTO_CIPHER_AES_CTR, 866 RTE_CRYPTO_CIPHER_ZUC_EEA3, 867 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 868 }; 869 const enum rte_crypto_auth_algorithm auths[] = { 870 RTE_CRYPTO_AUTH_NULL, 871 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 872 RTE_CRYPTO_AUTH_AES_CMAC, 873 RTE_CRYPTO_AUTH_ZUC_EIA3 874 }; 875 876 rte_cryptodev_info_get(dev_id, &dev_info); 877 878 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 879 !(dev_info.feature_flags & 880 RTE_CRYPTODEV_FF_SECURITY)) { 881 RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto " 882 "testsuite not met\n"); 883 return TEST_SKIPPED; 884 } 885 886 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 887 && check_auth_capabilities_supported(auths, 888 RTE_DIM(auths)) != 0) { 889 RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto " 890 "testsuite not met\n"); 891 return TEST_SKIPPED; 892 } 893 894 return 0; 895 } 896 897 static int 898 docsis_proto_testsuite_setup(void) 899 { 900 struct crypto_testsuite_params *ts_params = &testsuite_params; 901 uint8_t dev_id = ts_params->valid_devs[0]; 902 struct rte_cryptodev_info dev_info; 903 const enum rte_crypto_cipher_algorithm ciphers[] = { 904 RTE_CRYPTO_CIPHER_AES_DOCSISBPI 905 }; 906 907 rte_cryptodev_info_get(dev_id, &dev_info); 908 909 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 910 !(dev_info.feature_flags & 911 RTE_CRYPTODEV_FF_SECURITY)) { 912 RTE_LOG(INFO, USER1, "Feature flag requirements for DOCSIS " 913 "Proto testsuite not met\n"); 914 return TEST_SKIPPED; 915 } 916 917 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { 918 RTE_LOG(INFO, USER1, "Capability requirements for DOCSIS Proto " 919 "testsuite not met\n"); 920 return TEST_SKIPPED; 921 } 922 923 return 0; 924 } 925 #endif 926 927 static int 928 aes_ccm_auth_testsuite_setup(void) 929 { 930 struct crypto_testsuite_params *ts_params = &testsuite_params; 931 uint8_t dev_id = ts_params->valid_devs[0]; 932 struct rte_cryptodev_info dev_info; 933 const enum rte_crypto_aead_algorithm aeads[] = { 934 RTE_CRYPTO_AEAD_AES_CCM 935 }; 936 937 rte_cryptodev_info_get(dev_id, &dev_info); 938 939 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 940 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 941 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 942 RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM " 943 "testsuite not met\n"); 944 return TEST_SKIPPED; 945 } 946 947 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 948 RTE_LOG(INFO, USER1, "Capability requirements for AES CCM " 949 "testsuite not met\n"); 950 return TEST_SKIPPED; 951 } 952 953 return 0; 954 } 955 956 static int 957 aes_gcm_auth_testsuite_setup(void) 958 { 959 struct crypto_testsuite_params *ts_params = &testsuite_params; 960 uint8_t dev_id = ts_params->valid_devs[0]; 961 struct rte_cryptodev_info dev_info; 962 const enum rte_crypto_aead_algorithm aeads[] = { 963 RTE_CRYPTO_AEAD_AES_GCM 964 }; 965 966 rte_cryptodev_info_get(dev_id, &dev_info); 967 968 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 969 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM " 970 "testsuite not met\n"); 971 return TEST_SKIPPED; 972 } 973 974 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 975 RTE_LOG(INFO, USER1, "Capability requirements for AES GCM " 976 "testsuite not met\n"); 977 return TEST_SKIPPED; 978 } 979 980 return 0; 981 } 982 983 static int 984 aes_gmac_auth_testsuite_setup(void) 985 { 986 struct crypto_testsuite_params *ts_params = &testsuite_params; 987 uint8_t dev_id = ts_params->valid_devs[0]; 988 struct rte_cryptodev_info dev_info; 989 const enum rte_crypto_auth_algorithm auths[] = { 990 RTE_CRYPTO_AUTH_AES_GMAC 991 }; 992 993 rte_cryptodev_info_get(dev_id, &dev_info); 994 995 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 996 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 997 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 998 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC " 999 "testsuite not met\n"); 1000 return TEST_SKIPPED; 1001 } 1002 1003 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1004 RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC " 1005 "testsuite not met\n"); 1006 return TEST_SKIPPED; 1007 } 1008 1009 return 0; 1010 } 1011 1012 static int 1013 chacha20_poly1305_testsuite_setup(void) 1014 { 1015 struct crypto_testsuite_params *ts_params = &testsuite_params; 1016 uint8_t dev_id = ts_params->valid_devs[0]; 1017 struct rte_cryptodev_info dev_info; 1018 const enum rte_crypto_aead_algorithm aeads[] = { 1019 RTE_CRYPTO_AEAD_CHACHA20_POLY1305 1020 }; 1021 1022 rte_cryptodev_info_get(dev_id, &dev_info); 1023 1024 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1025 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1026 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1027 RTE_LOG(INFO, USER1, "Feature flag requirements for " 1028 "Chacha20-Poly1305 testsuite not met\n"); 1029 return TEST_SKIPPED; 1030 } 1031 1032 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1033 RTE_LOG(INFO, USER1, "Capability requirements for " 1034 "Chacha20-Poly1305 testsuite not met\n"); 1035 return TEST_SKIPPED; 1036 } 1037 1038 return 0; 1039 } 1040 1041 static int 1042 snow3g_testsuite_setup(void) 1043 { 1044 struct crypto_testsuite_params *ts_params = &testsuite_params; 1045 uint8_t dev_id = ts_params->valid_devs[0]; 1046 struct rte_cryptodev_info dev_info; 1047 const enum rte_crypto_cipher_algorithm ciphers[] = { 1048 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1049 1050 }; 1051 const enum rte_crypto_auth_algorithm auths[] = { 1052 RTE_CRYPTO_AUTH_SNOW3G_UIA2 1053 }; 1054 1055 rte_cryptodev_info_get(dev_id, &dev_info); 1056 1057 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1058 RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G " 1059 "testsuite not met\n"); 1060 return TEST_SKIPPED; 1061 } 1062 1063 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1064 && check_auth_capabilities_supported(auths, 1065 RTE_DIM(auths)) != 0) { 1066 RTE_LOG(INFO, USER1, "Capability requirements for Snow3G " 1067 "testsuite not met\n"); 1068 return TEST_SKIPPED; 1069 } 1070 1071 return 0; 1072 } 1073 1074 static int 1075 zuc_testsuite_setup(void) 1076 { 1077 struct crypto_testsuite_params *ts_params = &testsuite_params; 1078 uint8_t dev_id = ts_params->valid_devs[0]; 1079 struct rte_cryptodev_info dev_info; 1080 const enum rte_crypto_cipher_algorithm ciphers[] = { 1081 RTE_CRYPTO_CIPHER_ZUC_EEA3 1082 }; 1083 const enum rte_crypto_auth_algorithm auths[] = { 1084 RTE_CRYPTO_AUTH_ZUC_EIA3 1085 }; 1086 1087 rte_cryptodev_info_get(dev_id, &dev_info); 1088 1089 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1090 RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC " 1091 "testsuite not met\n"); 1092 return TEST_SKIPPED; 1093 } 1094 1095 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1096 && check_auth_capabilities_supported(auths, 1097 RTE_DIM(auths)) != 0) { 1098 RTE_LOG(INFO, USER1, "Capability requirements for ZUC " 1099 "testsuite not met\n"); 1100 return TEST_SKIPPED; 1101 } 1102 1103 return 0; 1104 } 1105 1106 static int 1107 hmac_md5_auth_testsuite_setup(void) 1108 { 1109 struct crypto_testsuite_params *ts_params = &testsuite_params; 1110 uint8_t dev_id = ts_params->valid_devs[0]; 1111 struct rte_cryptodev_info dev_info; 1112 const enum rte_crypto_auth_algorithm auths[] = { 1113 RTE_CRYPTO_AUTH_MD5_HMAC 1114 }; 1115 1116 rte_cryptodev_info_get(dev_id, &dev_info); 1117 1118 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1119 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1120 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1121 RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 " 1122 "Auth testsuite not met\n"); 1123 return TEST_SKIPPED; 1124 } 1125 1126 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1127 RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 " 1128 "testsuite not met\n"); 1129 return TEST_SKIPPED; 1130 } 1131 1132 return 0; 1133 } 1134 1135 static int 1136 kasumi_testsuite_setup(void) 1137 { 1138 struct crypto_testsuite_params *ts_params = &testsuite_params; 1139 uint8_t dev_id = ts_params->valid_devs[0]; 1140 struct rte_cryptodev_info dev_info; 1141 const enum rte_crypto_cipher_algorithm ciphers[] = { 1142 RTE_CRYPTO_CIPHER_KASUMI_F8 1143 }; 1144 const enum rte_crypto_auth_algorithm auths[] = { 1145 RTE_CRYPTO_AUTH_KASUMI_F9 1146 }; 1147 1148 rte_cryptodev_info_get(dev_id, &dev_info); 1149 1150 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1151 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1152 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1153 RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi " 1154 "testsuite not met\n"); 1155 return TEST_SKIPPED; 1156 } 1157 1158 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1159 && check_auth_capabilities_supported(auths, 1160 RTE_DIM(auths)) != 0) { 1161 RTE_LOG(INFO, USER1, "Capability requirements for Kasumi " 1162 "testsuite not met\n"); 1163 return TEST_SKIPPED; 1164 } 1165 1166 return 0; 1167 } 1168 1169 static int 1170 negative_aes_gcm_testsuite_setup(void) 1171 { 1172 struct crypto_testsuite_params *ts_params = &testsuite_params; 1173 uint8_t dev_id = ts_params->valid_devs[0]; 1174 struct rte_cryptodev_info dev_info; 1175 const enum rte_crypto_aead_algorithm aeads[] = { 1176 RTE_CRYPTO_AEAD_AES_GCM 1177 }; 1178 1179 rte_cryptodev_info_get(dev_id, &dev_info); 1180 1181 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1182 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1183 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1184 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1185 "AES GCM testsuite not met\n"); 1186 return TEST_SKIPPED; 1187 } 1188 1189 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1190 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1191 "AES GCM testsuite not met\n"); 1192 return TEST_SKIPPED; 1193 } 1194 1195 return 0; 1196 } 1197 1198 static int 1199 negative_aes_gmac_testsuite_setup(void) 1200 { 1201 struct crypto_testsuite_params *ts_params = &testsuite_params; 1202 uint8_t dev_id = ts_params->valid_devs[0]; 1203 struct rte_cryptodev_info dev_info; 1204 const enum rte_crypto_auth_algorithm auths[] = { 1205 RTE_CRYPTO_AUTH_AES_GMAC 1206 }; 1207 1208 rte_cryptodev_info_get(dev_id, &dev_info); 1209 1210 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1211 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1212 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1213 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1214 "AES GMAC testsuite not met\n"); 1215 return TEST_SKIPPED; 1216 } 1217 1218 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1219 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1220 "AES GMAC testsuite not met\n"); 1221 return TEST_SKIPPED; 1222 } 1223 1224 return 0; 1225 } 1226 1227 static int 1228 mixed_cipher_hash_testsuite_setup(void) 1229 { 1230 struct crypto_testsuite_params *ts_params = &testsuite_params; 1231 uint8_t dev_id = ts_params->valid_devs[0]; 1232 struct rte_cryptodev_info dev_info; 1233 uint64_t feat_flags; 1234 const enum rte_crypto_cipher_algorithm ciphers[] = { 1235 RTE_CRYPTO_CIPHER_NULL, 1236 RTE_CRYPTO_CIPHER_AES_CTR, 1237 RTE_CRYPTO_CIPHER_ZUC_EEA3, 1238 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1239 }; 1240 const enum rte_crypto_auth_algorithm auths[] = { 1241 RTE_CRYPTO_AUTH_NULL, 1242 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 1243 RTE_CRYPTO_AUTH_AES_CMAC, 1244 RTE_CRYPTO_AUTH_ZUC_EIA3 1245 }; 1246 1247 rte_cryptodev_info_get(dev_id, &dev_info); 1248 feat_flags = dev_info.feature_flags; 1249 1250 if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1251 (global_api_test_type == CRYPTODEV_RAW_API_TEST)) { 1252 RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed " 1253 "Cipher Hash testsuite not met\n"); 1254 return TEST_SKIPPED; 1255 } 1256 1257 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1258 && check_auth_capabilities_supported(auths, 1259 RTE_DIM(auths)) != 0) { 1260 RTE_LOG(INFO, USER1, "Capability requirements for Mixed " 1261 "Cipher Hash testsuite not met\n"); 1262 return TEST_SKIPPED; 1263 } 1264 1265 return 0; 1266 } 1267 1268 static int 1269 esn_testsuite_setup(void) 1270 { 1271 struct crypto_testsuite_params *ts_params = &testsuite_params; 1272 uint8_t dev_id = ts_params->valid_devs[0]; 1273 struct rte_cryptodev_info dev_info; 1274 const enum rte_crypto_cipher_algorithm ciphers[] = { 1275 RTE_CRYPTO_CIPHER_AES_CBC 1276 }; 1277 const enum rte_crypto_auth_algorithm auths[] = { 1278 RTE_CRYPTO_AUTH_SHA1_HMAC 1279 }; 1280 1281 rte_cryptodev_info_get(dev_id, &dev_info); 1282 1283 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1284 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1285 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1286 RTE_LOG(INFO, USER1, "Feature flag requirements for ESN " 1287 "testsuite not met\n"); 1288 return TEST_SKIPPED; 1289 } 1290 1291 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1292 && check_auth_capabilities_supported(auths, 1293 RTE_DIM(auths)) != 0) { 1294 RTE_LOG(INFO, USER1, "Capability requirements for ESN " 1295 "testsuite not met\n"); 1296 return TEST_SKIPPED; 1297 } 1298 1299 return 0; 1300 } 1301 1302 static int 1303 multi_session_testsuite_setup(void) 1304 { 1305 struct crypto_testsuite_params *ts_params = &testsuite_params; 1306 uint8_t dev_id = ts_params->valid_devs[0]; 1307 struct rte_cryptodev_info dev_info; 1308 const enum rte_crypto_cipher_algorithm ciphers[] = { 1309 RTE_CRYPTO_CIPHER_AES_CBC 1310 }; 1311 const enum rte_crypto_auth_algorithm auths[] = { 1312 RTE_CRYPTO_AUTH_SHA512_HMAC 1313 }; 1314 1315 rte_cryptodev_info_get(dev_id, &dev_info); 1316 1317 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1318 RTE_LOG(INFO, USER1, "Feature flag requirements for Multi " 1319 "Session testsuite not met\n"); 1320 return TEST_SKIPPED; 1321 } 1322 1323 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1324 && check_auth_capabilities_supported(auths, 1325 RTE_DIM(auths)) != 0) { 1326 RTE_LOG(INFO, USER1, "Capability requirements for Multi " 1327 "Session testsuite not met\n"); 1328 return TEST_SKIPPED; 1329 } 1330 1331 return 0; 1332 } 1333 1334 static int 1335 negative_hmac_sha1_testsuite_setup(void) 1336 { 1337 struct crypto_testsuite_params *ts_params = &testsuite_params; 1338 uint8_t dev_id = ts_params->valid_devs[0]; 1339 struct rte_cryptodev_info dev_info; 1340 const enum rte_crypto_cipher_algorithm ciphers[] = { 1341 RTE_CRYPTO_CIPHER_AES_CBC 1342 }; 1343 const enum rte_crypto_auth_algorithm auths[] = { 1344 RTE_CRYPTO_AUTH_SHA1_HMAC 1345 }; 1346 1347 rte_cryptodev_info_get(dev_id, &dev_info); 1348 1349 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1350 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1351 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1352 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1353 "HMAC SHA1 testsuite not met\n"); 1354 return TEST_SKIPPED; 1355 } 1356 1357 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1358 && check_auth_capabilities_supported(auths, 1359 RTE_DIM(auths)) != 0) { 1360 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1361 "HMAC SHA1 testsuite not met\n"); 1362 return TEST_SKIPPED; 1363 } 1364 1365 return 0; 1366 } 1367 1368 static int 1369 dev_configure_and_start(uint64_t ff_disable) 1370 { 1371 struct crypto_testsuite_params *ts_params = &testsuite_params; 1372 struct crypto_unittest_params *ut_params = &unittest_params; 1373 1374 uint16_t qp_id; 1375 1376 /* Clear unit test parameters before running test */ 1377 memset(ut_params, 0, sizeof(*ut_params)); 1378 1379 /* Reconfigure device to default parameters */ 1380 ts_params->conf.socket_id = SOCKET_ID_ANY; 1381 ts_params->conf.ff_disable = ff_disable; 1382 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 1383 ts_params->qp_conf.mp_session = ts_params->session_mpool; 1384 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 1385 1386 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1387 &ts_params->conf), 1388 "Failed to configure cryptodev %u", 1389 ts_params->valid_devs[0]); 1390 1391 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { 1392 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1393 ts_params->valid_devs[0], qp_id, 1394 &ts_params->qp_conf, 1395 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1396 "Failed to setup queue pair %u on cryptodev %u", 1397 qp_id, ts_params->valid_devs[0]); 1398 } 1399 1400 1401 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 1402 1403 /* Start the device */ 1404 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 1405 "Failed to start cryptodev %u", 1406 ts_params->valid_devs[0]); 1407 1408 return TEST_SUCCESS; 1409 } 1410 1411 int 1412 ut_setup(void) 1413 { 1414 /* Configure and start the device with security feature disabled */ 1415 return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY); 1416 } 1417 1418 static int 1419 ut_setup_security(void) 1420 { 1421 /* Configure and start the device with no features disabled */ 1422 return dev_configure_and_start(0); 1423 } 1424 1425 void 1426 ut_teardown(void) 1427 { 1428 struct crypto_testsuite_params *ts_params = &testsuite_params; 1429 struct crypto_unittest_params *ut_params = &unittest_params; 1430 1431 /* free crypto session structure */ 1432 #ifdef RTE_LIB_SECURITY 1433 if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) { 1434 if (ut_params->sec_session) { 1435 rte_security_session_destroy(rte_cryptodev_get_sec_ctx 1436 (ts_params->valid_devs[0]), 1437 ut_params->sec_session); 1438 ut_params->sec_session = NULL; 1439 } 1440 } else 1441 #endif 1442 { 1443 if (ut_params->sess) { 1444 rte_cryptodev_sym_session_clear( 1445 ts_params->valid_devs[0], 1446 ut_params->sess); 1447 rte_cryptodev_sym_session_free(ut_params->sess); 1448 ut_params->sess = NULL; 1449 } 1450 } 1451 1452 /* free crypto operation structure */ 1453 if (ut_params->op) 1454 rte_crypto_op_free(ut_params->op); 1455 1456 /* 1457 * free mbuf - both obuf and ibuf are usually the same, 1458 * so check if they point at the same address is necessary, 1459 * to avoid freeing the mbuf twice. 1460 */ 1461 if (ut_params->obuf) { 1462 rte_pktmbuf_free(ut_params->obuf); 1463 if (ut_params->ibuf == ut_params->obuf) 1464 ut_params->ibuf = 0; 1465 ut_params->obuf = 0; 1466 } 1467 if (ut_params->ibuf) { 1468 rte_pktmbuf_free(ut_params->ibuf); 1469 ut_params->ibuf = 0; 1470 } 1471 1472 if (ts_params->mbuf_pool != NULL) 1473 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 1474 rte_mempool_avail_count(ts_params->mbuf_pool)); 1475 1476 /* Stop the device */ 1477 rte_cryptodev_stop(ts_params->valid_devs[0]); 1478 } 1479 1480 static int 1481 test_device_configure_invalid_dev_id(void) 1482 { 1483 struct crypto_testsuite_params *ts_params = &testsuite_params; 1484 uint16_t dev_id, num_devs = 0; 1485 1486 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 1487 "Need at least %d devices for test", 1); 1488 1489 /* valid dev_id values */ 1490 dev_id = ts_params->valid_devs[0]; 1491 1492 /* Stop the device in case it's started so it can be configured */ 1493 rte_cryptodev_stop(dev_id); 1494 1495 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 1496 "Failed test for rte_cryptodev_configure: " 1497 "invalid dev_num %u", dev_id); 1498 1499 /* invalid dev_id values */ 1500 dev_id = num_devs; 1501 1502 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1503 "Failed test for rte_cryptodev_configure: " 1504 "invalid dev_num %u", dev_id); 1505 1506 dev_id = 0xff; 1507 1508 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1509 "Failed test for rte_cryptodev_configure:" 1510 "invalid dev_num %u", dev_id); 1511 1512 return TEST_SUCCESS; 1513 } 1514 1515 static int 1516 test_device_configure_invalid_queue_pair_ids(void) 1517 { 1518 struct crypto_testsuite_params *ts_params = &testsuite_params; 1519 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 1520 1521 /* Stop the device in case it's started so it can be configured */ 1522 rte_cryptodev_stop(ts_params->valid_devs[0]); 1523 1524 /* valid - max value queue pairs */ 1525 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1526 1527 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1528 &ts_params->conf), 1529 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1530 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 1531 1532 /* valid - one queue pairs */ 1533 ts_params->conf.nb_queue_pairs = 1; 1534 1535 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1536 &ts_params->conf), 1537 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1538 ts_params->valid_devs[0], 1539 ts_params->conf.nb_queue_pairs); 1540 1541 1542 /* invalid - zero queue pairs */ 1543 ts_params->conf.nb_queue_pairs = 0; 1544 1545 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1546 &ts_params->conf), 1547 "Failed test for rte_cryptodev_configure, dev_id %u," 1548 " invalid qps: %u", 1549 ts_params->valid_devs[0], 1550 ts_params->conf.nb_queue_pairs); 1551 1552 1553 /* invalid - max value supported by field queue pairs */ 1554 ts_params->conf.nb_queue_pairs = UINT16_MAX; 1555 1556 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1557 &ts_params->conf), 1558 "Failed test for rte_cryptodev_configure, dev_id %u," 1559 " invalid qps: %u", 1560 ts_params->valid_devs[0], 1561 ts_params->conf.nb_queue_pairs); 1562 1563 1564 /* invalid - max value + 1 queue pairs */ 1565 ts_params->conf.nb_queue_pairs = orig_nb_qps + 1; 1566 1567 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1568 &ts_params->conf), 1569 "Failed test for rte_cryptodev_configure, dev_id %u," 1570 " invalid qps: %u", 1571 ts_params->valid_devs[0], 1572 ts_params->conf.nb_queue_pairs); 1573 1574 /* revert to original testsuite value */ 1575 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1576 1577 return TEST_SUCCESS; 1578 } 1579 1580 static int 1581 test_queue_pair_descriptor_setup(void) 1582 { 1583 struct crypto_testsuite_params *ts_params = &testsuite_params; 1584 struct rte_cryptodev_qp_conf qp_conf = { 1585 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 1586 }; 1587 uint16_t qp_id; 1588 1589 /* Stop the device in case it's started so it can be configured */ 1590 rte_cryptodev_stop(ts_params->valid_devs[0]); 1591 1592 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1593 &ts_params->conf), 1594 "Failed to configure cryptodev %u", 1595 ts_params->valid_devs[0]); 1596 1597 /* 1598 * Test various ring sizes on this device. memzones can't be 1599 * freed so are re-used if ring is released and re-created. 1600 */ 1601 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/ 1602 qp_conf.mp_session = ts_params->session_mpool; 1603 qp_conf.mp_session_private = ts_params->session_priv_mpool; 1604 1605 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1606 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1607 ts_params->valid_devs[0], qp_id, &qp_conf, 1608 rte_cryptodev_socket_id( 1609 ts_params->valid_devs[0])), 1610 "Failed test for " 1611 "rte_cryptodev_queue_pair_setup: num_inflights " 1612 "%u on qp %u on cryptodev %u", 1613 qp_conf.nb_descriptors, qp_id, 1614 ts_params->valid_devs[0]); 1615 } 1616 1617 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2); 1618 1619 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1620 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1621 ts_params->valid_devs[0], qp_id, &qp_conf, 1622 rte_cryptodev_socket_id( 1623 ts_params->valid_devs[0])), 1624 "Failed test for" 1625 " rte_cryptodev_queue_pair_setup: num_inflights" 1626 " %u on qp %u on cryptodev %u", 1627 qp_conf.nb_descriptors, qp_id, 1628 ts_params->valid_devs[0]); 1629 } 1630 1631 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */ 1632 1633 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1634 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1635 ts_params->valid_devs[0], qp_id, &qp_conf, 1636 rte_cryptodev_socket_id( 1637 ts_params->valid_devs[0])), 1638 "Failed test for " 1639 "rte_cryptodev_queue_pair_setup: num_inflights" 1640 " %u on qp %u on cryptodev %u", 1641 qp_conf.nb_descriptors, qp_id, 1642 ts_params->valid_devs[0]); 1643 } 1644 1645 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 1646 1647 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1648 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1649 ts_params->valid_devs[0], qp_id, &qp_conf, 1650 rte_cryptodev_socket_id( 1651 ts_params->valid_devs[0])), 1652 "Failed test for" 1653 " rte_cryptodev_queue_pair_setup:" 1654 "num_inflights %u on qp %u on cryptodev %u", 1655 qp_conf.nb_descriptors, qp_id, 1656 ts_params->valid_devs[0]); 1657 } 1658 1659 /* test invalid queue pair id */ 1660 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */ 1661 1662 qp_id = ts_params->conf.nb_queue_pairs; /*invalid */ 1663 1664 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1665 ts_params->valid_devs[0], 1666 qp_id, &qp_conf, 1667 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1668 "Failed test for rte_cryptodev_queue_pair_setup:" 1669 "invalid qp %u on cryptodev %u", 1670 qp_id, ts_params->valid_devs[0]); 1671 1672 qp_id = 0xffff; /*invalid*/ 1673 1674 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1675 ts_params->valid_devs[0], 1676 qp_id, &qp_conf, 1677 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1678 "Failed test for rte_cryptodev_queue_pair_setup:" 1679 "invalid qp %u on cryptodev %u", 1680 qp_id, ts_params->valid_devs[0]); 1681 1682 return TEST_SUCCESS; 1683 } 1684 1685 /* ***** Plaintext data for tests ***** */ 1686 1687 const char catch_22_quote_1[] = 1688 "There was only one catch and that was Catch-22, which " 1689 "specified that a concern for one's safety in the face of " 1690 "dangers that were real and immediate was the process of a " 1691 "rational mind. Orr was crazy and could be grounded. All he " 1692 "had to do was ask; and as soon as he did, he would no longer " 1693 "be crazy and would have to fly more missions. Orr would be " 1694 "crazy to fly more missions and sane if he didn't, but if he " 1695 "was sane he had to fly them. If he flew them he was crazy " 1696 "and didn't have to; but if he didn't want to he was sane and " 1697 "had to. Yossarian was moved very deeply by the absolute " 1698 "simplicity of this clause of Catch-22 and let out a " 1699 "respectful whistle. \"That's some catch, that Catch-22\", he " 1700 "observed. \"It's the best there is,\" Doc Daneeka agreed."; 1701 1702 const char catch_22_quote[] = 1703 "What a lousy earth! He wondered how many people were " 1704 "destitute that same night even in his own prosperous country, " 1705 "how many homes were shanties, how many husbands were drunk " 1706 "and wives socked, and how many children were bullied, abused, " 1707 "or abandoned. How many families hungered for food they could " 1708 "not afford to buy? How many hearts were broken? How many " 1709 "suicides would take place that same night, how many people " 1710 "would go insane? How many cockroaches and landlords would " 1711 "triumph? How many winners were losers, successes failures, " 1712 "and rich men poor men? How many wise guys were stupid? How " 1713 "many happy endings were unhappy endings? How many honest men " 1714 "were liars, brave men cowards, loyal men traitors, how many " 1715 "sainted men were corrupt, how many people in positions of " 1716 "trust had sold their souls to bodyguards, how many had never " 1717 "had souls? How many straight-and-narrow paths were crooked " 1718 "paths? How many best families were worst families and how " 1719 "many good people were bad people? When you added them all up " 1720 "and then subtracted, you might be left with only the children, " 1721 "and perhaps with Albert Einstein and an old violinist or " 1722 "sculptor somewhere."; 1723 1724 #define QUOTE_480_BYTES (480) 1725 #define QUOTE_512_BYTES (512) 1726 #define QUOTE_768_BYTES (768) 1727 #define QUOTE_1024_BYTES (1024) 1728 1729 1730 1731 /* ***** SHA1 Hash Tests ***** */ 1732 1733 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1) 1734 1735 static uint8_t hmac_sha1_key[] = { 1736 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 1737 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 1738 0xDE, 0xF4, 0xDE, 0xAD }; 1739 1740 /* ***** SHA224 Hash Tests ***** */ 1741 1742 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224) 1743 1744 1745 /* ***** AES-CBC Cipher Tests ***** */ 1746 1747 #define CIPHER_KEY_LENGTH_AES_CBC (16) 1748 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC) 1749 1750 static uint8_t aes_cbc_key[] = { 1751 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 1752 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A }; 1753 1754 static uint8_t aes_cbc_iv[] = { 1755 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 1756 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; 1757 1758 1759 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */ 1760 1761 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = { 1762 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, 1763 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, 1764 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, 1765 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, 1766 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E, 1767 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08, 1768 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0, 1769 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01, 1770 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57, 1771 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE, 1772 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9, 1773 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9, 1774 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D, 1775 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3, 1776 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46, 1777 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3, 1778 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80, 1779 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92, 1780 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5, 1781 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5, 1782 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2, 1783 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5, 1784 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1785 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76, 1786 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4, 1787 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62, 1788 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4, 1789 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4, 1790 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54, 1791 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61, 1792 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91, 1793 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A, 1794 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF, 1795 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F, 1796 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28, 1797 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E, 1798 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7, 1799 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76, 1800 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6, 1801 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03, 1802 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C, 1803 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2, 1804 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6, 1805 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96, 1806 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6, 1807 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA, 1808 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87, 1809 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55, 1810 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B, 1811 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98, 1812 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53, 1813 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A, 1814 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26, 1815 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36, 1816 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36, 1817 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D, 1818 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E, 1819 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E, 1820 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A, 1821 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6, 1822 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4, 1823 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7, 1824 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1, 1825 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C 1826 }; 1827 1828 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = { 1829 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60, 1830 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1831 0x18, 0x8c, 0x1d, 0x32 1832 }; 1833 1834 1835 /* Multisession Vector context Test */ 1836 /*Begin Session 0 */ 1837 static uint8_t ms_aes_cbc_key0[] = { 1838 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1839 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1840 }; 1841 1842 static uint8_t ms_aes_cbc_iv0[] = { 1843 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1844 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1845 }; 1846 1847 static const uint8_t ms_aes_cbc_cipher0[] = { 1848 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38, 1849 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC, 1850 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB, 1851 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9, 1852 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D, 1853 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4, 1854 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34, 1855 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F, 1856 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99, 1857 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED, 1858 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D, 1859 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24, 1860 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71, 1861 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72, 1862 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E, 1863 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD, 1864 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18, 1865 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6, 1866 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29, 1867 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C, 1868 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96, 1869 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26, 1870 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55, 1871 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46, 1872 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B, 1873 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4, 1874 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7, 1875 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5, 1876 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0, 1877 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E, 1878 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D, 1879 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44, 1880 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76, 1881 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3, 1882 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83, 1883 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85, 1884 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45, 1885 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25, 1886 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A, 1887 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1, 1888 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA, 1889 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3, 1890 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4, 1891 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60, 1892 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A, 1893 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A, 1894 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9, 1895 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55, 1896 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13, 1897 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B, 1898 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1, 1899 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0, 1900 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3, 1901 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23, 1902 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B, 1903 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07, 1904 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB, 1905 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1, 1906 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F, 1907 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F, 1908 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84, 1909 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B, 1910 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17, 1911 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF 1912 }; 1913 1914 1915 static uint8_t ms_hmac_key0[] = { 1916 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1917 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1918 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1919 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1920 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1921 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1922 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1923 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1924 }; 1925 1926 static const uint8_t ms_hmac_digest0[] = { 1927 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51, 1928 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F, 1929 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C, 1930 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4, 1931 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56, 1932 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4, 1933 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23, 1934 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90 1935 }; 1936 1937 /* End Session 0 */ 1938 /* Begin session 1 */ 1939 1940 static uint8_t ms_aes_cbc_key1[] = { 1941 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1942 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1943 }; 1944 1945 static uint8_t ms_aes_cbc_iv1[] = { 1946 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1947 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1948 }; 1949 1950 static const uint8_t ms_aes_cbc_cipher1[] = { 1951 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71, 1952 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23, 1953 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09, 1954 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A, 1955 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C, 1956 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F, 1957 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9, 1958 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66, 1959 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43, 1960 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB, 1961 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23, 1962 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29, 1963 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26, 1964 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F, 1965 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68, 1966 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77, 1967 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8, 1968 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97, 1969 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3, 1970 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90, 1971 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5, 1972 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E, 1973 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45, 1974 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B, 1975 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5, 1976 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D, 1977 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E, 1978 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD, 1979 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE, 1980 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1, 1981 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F, 1982 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25, 1983 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1, 1984 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3, 1985 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE, 1986 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6, 1987 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52, 1988 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA, 1989 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63, 1990 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E, 1991 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA, 1992 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB, 1993 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71, 1994 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF, 1995 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A, 1996 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95, 1997 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73, 1998 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49, 1999 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB, 2000 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B, 2001 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC, 2002 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED, 2003 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02, 2004 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4, 2005 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF, 2006 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82, 2007 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D, 2008 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6, 2009 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9, 2010 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35, 2011 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0, 2012 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53, 2013 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5, 2014 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3 2015 2016 }; 2017 2018 static uint8_t ms_hmac_key1[] = { 2019 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2020 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2021 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2022 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2023 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2024 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2025 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2026 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2027 }; 2028 2029 static const uint8_t ms_hmac_digest1[] = { 2030 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69, 2031 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50, 2032 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20, 2033 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD, 2034 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9, 2035 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4, 2036 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA, 2037 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F 2038 }; 2039 /* End Session 1 */ 2040 /* Begin Session 2 */ 2041 static uint8_t ms_aes_cbc_key2[] = { 2042 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2043 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2044 }; 2045 2046 static uint8_t ms_aes_cbc_iv2[] = { 2047 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2048 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2049 }; 2050 2051 static const uint8_t ms_aes_cbc_cipher2[] = { 2052 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91, 2053 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97, 2054 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8, 2055 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5, 2056 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98, 2057 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69, 2058 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09, 2059 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF, 2060 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44, 2061 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B, 2062 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9, 2063 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34, 2064 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99, 2065 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF, 2066 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC, 2067 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26, 2068 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3, 2069 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF, 2070 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3, 2071 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3, 2072 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA, 2073 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13, 2074 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38, 2075 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71, 2076 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC, 2077 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1, 2078 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E, 2079 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22, 2080 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62, 2081 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72, 2082 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6, 2083 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6, 2084 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44, 2085 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24, 2086 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5, 2087 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E, 2088 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17, 2089 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9, 2090 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D, 2091 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D, 2092 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22, 2093 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9, 2094 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49, 2095 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E, 2096 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B, 2097 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2, 2098 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95, 2099 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07, 2100 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3, 2101 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A, 2102 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57, 2103 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84, 2104 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61, 2105 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF, 2106 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17, 2107 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A, 2108 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1, 2109 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53, 2110 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7, 2111 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2, 2112 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A, 2113 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8, 2114 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70, 2115 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92 2116 }; 2117 2118 static uint8_t ms_hmac_key2[] = { 2119 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2120 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2121 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2122 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2123 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2124 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2125 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2126 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2127 }; 2128 2129 static const uint8_t ms_hmac_digest2[] = { 2130 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF, 2131 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6, 2132 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77, 2133 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27, 2134 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82, 2135 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24, 2136 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E, 2137 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59 2138 }; 2139 2140 /* End Session 2 */ 2141 2142 2143 static int 2144 test_AES_CBC_HMAC_SHA1_encrypt_digest(void) 2145 { 2146 struct crypto_testsuite_params *ts_params = &testsuite_params; 2147 struct crypto_unittest_params *ut_params = &unittest_params; 2148 int status; 2149 2150 /* Verify the capabilities */ 2151 struct rte_cryptodev_sym_capability_idx cap_idx; 2152 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2153 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 2154 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2155 &cap_idx) == NULL) 2156 return TEST_SKIPPED; 2157 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2158 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 2159 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2160 &cap_idx) == NULL) 2161 return TEST_SKIPPED; 2162 2163 /* Generate test mbuf data and space for digest */ 2164 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2165 catch_22_quote, QUOTE_512_BYTES, 0); 2166 2167 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2168 DIGEST_BYTE_LENGTH_SHA1); 2169 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2170 2171 /* Setup Cipher Parameters */ 2172 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2173 ut_params->cipher_xform.next = &ut_params->auth_xform; 2174 2175 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2176 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 2177 ut_params->cipher_xform.cipher.key.data = aes_cbc_key; 2178 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2179 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2180 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2181 2182 /* Setup HMAC Parameters */ 2183 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2184 2185 ut_params->auth_xform.next = NULL; 2186 2187 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 2188 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 2189 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; 2190 ut_params->auth_xform.auth.key.data = hmac_sha1_key; 2191 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; 2192 2193 ut_params->sess = rte_cryptodev_sym_session_create( 2194 ts_params->session_mpool); 2195 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2196 2197 /* Create crypto session*/ 2198 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 2199 ut_params->sess, &ut_params->cipher_xform, 2200 ts_params->session_priv_mpool); 2201 2202 if (status == -ENOTSUP) 2203 return TEST_SKIPPED; 2204 2205 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 2206 2207 /* Generate crypto op data structure */ 2208 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2209 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2210 TEST_ASSERT_NOT_NULL(ut_params->op, 2211 "Failed to allocate symmetric crypto operation struct"); 2212 2213 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2214 2215 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2216 2217 /* set crypto operation source mbuf */ 2218 sym_op->m_src = ut_params->ibuf; 2219 2220 /* Set crypto operation authentication parameters */ 2221 sym_op->auth.digest.data = ut_params->digest; 2222 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2223 ut_params->ibuf, QUOTE_512_BYTES); 2224 2225 sym_op->auth.data.offset = 0; 2226 sym_op->auth.data.length = QUOTE_512_BYTES; 2227 2228 /* Copy IV at the end of the crypto operation */ 2229 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2230 aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC); 2231 2232 /* Set crypto operation cipher parameters */ 2233 sym_op->cipher.data.offset = 0; 2234 sym_op->cipher.data.length = QUOTE_512_BYTES; 2235 2236 /* Process crypto operation */ 2237 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2238 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2239 ut_params->op); 2240 else 2241 TEST_ASSERT_NOT_NULL( 2242 process_crypto_request(ts_params->valid_devs[0], 2243 ut_params->op), 2244 "failed to process sym crypto op"); 2245 2246 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2247 "crypto op processing failed"); 2248 2249 /* Validate obuf */ 2250 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 2251 uint8_t *); 2252 2253 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, 2254 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 2255 QUOTE_512_BYTES, 2256 "ciphertext data not as expected"); 2257 2258 uint8_t *digest = ciphertext + QUOTE_512_BYTES; 2259 2260 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, 2261 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, 2262 gbl_driver_id == rte_cryptodev_driver_id_get( 2263 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ? 2264 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : 2265 DIGEST_BYTE_LENGTH_SHA1, 2266 "Generated digest data not as expected"); 2267 2268 return TEST_SUCCESS; 2269 } 2270 2271 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ 2272 2273 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) 2274 2275 static uint8_t hmac_sha512_key[] = { 2276 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 2277 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2278 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2279 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60, 2280 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1, 2281 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2282 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76, 2283 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 }; 2284 2285 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = { 2286 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8, 2287 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48, 2288 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8, 2289 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70, 2290 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8, 2291 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E, 2292 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D, 2293 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A }; 2294 2295 2296 2297 static int 2298 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2299 struct crypto_unittest_params *ut_params, 2300 uint8_t *cipher_key, 2301 uint8_t *hmac_key); 2302 2303 static int 2304 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 2305 struct crypto_unittest_params *ut_params, 2306 struct crypto_testsuite_params *ts_params, 2307 const uint8_t *cipher, 2308 const uint8_t *digest, 2309 const uint8_t *iv); 2310 2311 2312 static int 2313 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2314 struct crypto_unittest_params *ut_params, 2315 uint8_t *cipher_key, 2316 uint8_t *hmac_key) 2317 { 2318 2319 /* Setup Cipher Parameters */ 2320 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2321 ut_params->cipher_xform.next = NULL; 2322 2323 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2324 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 2325 ut_params->cipher_xform.cipher.key.data = cipher_key; 2326 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2327 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2328 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2329 2330 /* Setup HMAC Parameters */ 2331 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2332 ut_params->auth_xform.next = &ut_params->cipher_xform; 2333 2334 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 2335 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC; 2336 ut_params->auth_xform.auth.key.data = hmac_key; 2337 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512; 2338 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512; 2339 2340 return TEST_SUCCESS; 2341 } 2342 2343 2344 static int 2345 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 2346 struct crypto_unittest_params *ut_params, 2347 struct crypto_testsuite_params *ts_params, 2348 const uint8_t *cipher, 2349 const uint8_t *digest, 2350 const uint8_t *iv) 2351 { 2352 /* Generate test mbuf data and digest */ 2353 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2354 (const char *) 2355 cipher, 2356 QUOTE_512_BYTES, 0); 2357 2358 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2359 DIGEST_BYTE_LENGTH_SHA512); 2360 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2361 2362 rte_memcpy(ut_params->digest, 2363 digest, 2364 DIGEST_BYTE_LENGTH_SHA512); 2365 2366 /* Generate Crypto op data structure */ 2367 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2368 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2369 TEST_ASSERT_NOT_NULL(ut_params->op, 2370 "Failed to allocate symmetric crypto operation struct"); 2371 2372 rte_crypto_op_attach_sym_session(ut_params->op, sess); 2373 2374 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2375 2376 /* set crypto operation source mbuf */ 2377 sym_op->m_src = ut_params->ibuf; 2378 2379 sym_op->auth.digest.data = ut_params->digest; 2380 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2381 ut_params->ibuf, QUOTE_512_BYTES); 2382 2383 sym_op->auth.data.offset = 0; 2384 sym_op->auth.data.length = QUOTE_512_BYTES; 2385 2386 /* Copy IV at the end of the crypto operation */ 2387 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2388 iv, CIPHER_IV_LENGTH_AES_CBC); 2389 2390 sym_op->cipher.data.offset = 0; 2391 sym_op->cipher.data.length = QUOTE_512_BYTES; 2392 2393 /* Process crypto operation */ 2394 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2395 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2396 ut_params->op); 2397 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2398 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2399 ut_params->op, 1, 1, 0, 0); 2400 else 2401 TEST_ASSERT_NOT_NULL( 2402 process_crypto_request(ts_params->valid_devs[0], 2403 ut_params->op), 2404 "failed to process sym crypto op"); 2405 2406 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2407 "crypto op processing failed"); 2408 2409 ut_params->obuf = ut_params->op->sym->m_src; 2410 2411 /* Validate obuf */ 2412 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2413 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 2414 catch_22_quote, 2415 QUOTE_512_BYTES, 2416 "Plaintext data not as expected"); 2417 2418 /* Validate obuf */ 2419 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2420 "Digest verification failed"); 2421 2422 return TEST_SUCCESS; 2423 } 2424 2425 /* ***** SNOW 3G Tests ***** */ 2426 static int 2427 create_wireless_algo_hash_session(uint8_t dev_id, 2428 const uint8_t *key, const uint8_t key_len, 2429 const uint8_t iv_len, const uint8_t auth_len, 2430 enum rte_crypto_auth_operation op, 2431 enum rte_crypto_auth_algorithm algo) 2432 { 2433 uint8_t hash_key[key_len]; 2434 int status; 2435 2436 struct crypto_testsuite_params *ts_params = &testsuite_params; 2437 struct crypto_unittest_params *ut_params = &unittest_params; 2438 2439 memcpy(hash_key, key, key_len); 2440 2441 debug_hexdump(stdout, "key:", key, key_len); 2442 2443 /* Setup Authentication Parameters */ 2444 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2445 ut_params->auth_xform.next = NULL; 2446 2447 ut_params->auth_xform.auth.op = op; 2448 ut_params->auth_xform.auth.algo = algo; 2449 ut_params->auth_xform.auth.key.length = key_len; 2450 ut_params->auth_xform.auth.key.data = hash_key; 2451 ut_params->auth_xform.auth.digest_length = auth_len; 2452 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 2453 ut_params->auth_xform.auth.iv.length = iv_len; 2454 ut_params->sess = rte_cryptodev_sym_session_create( 2455 ts_params->session_mpool); 2456 2457 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2458 &ut_params->auth_xform, 2459 ts_params->session_priv_mpool); 2460 if (status == -ENOTSUP) 2461 return TEST_SKIPPED; 2462 2463 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2464 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2465 return 0; 2466 } 2467 2468 static int 2469 create_wireless_algo_cipher_session(uint8_t dev_id, 2470 enum rte_crypto_cipher_operation op, 2471 enum rte_crypto_cipher_algorithm algo, 2472 const uint8_t *key, const uint8_t key_len, 2473 uint8_t iv_len) 2474 { 2475 uint8_t cipher_key[key_len]; 2476 int status; 2477 struct crypto_testsuite_params *ts_params = &testsuite_params; 2478 struct crypto_unittest_params *ut_params = &unittest_params; 2479 2480 memcpy(cipher_key, key, key_len); 2481 2482 /* Setup Cipher Parameters */ 2483 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2484 ut_params->cipher_xform.next = NULL; 2485 2486 ut_params->cipher_xform.cipher.algo = algo; 2487 ut_params->cipher_xform.cipher.op = op; 2488 ut_params->cipher_xform.cipher.key.data = cipher_key; 2489 ut_params->cipher_xform.cipher.key.length = key_len; 2490 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2491 ut_params->cipher_xform.cipher.iv.length = iv_len; 2492 2493 debug_hexdump(stdout, "key:", key, key_len); 2494 2495 /* Create Crypto session */ 2496 ut_params->sess = rte_cryptodev_sym_session_create( 2497 ts_params->session_mpool); 2498 2499 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2500 &ut_params->cipher_xform, 2501 ts_params->session_priv_mpool); 2502 if (status == -ENOTSUP) 2503 return TEST_SKIPPED; 2504 2505 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2506 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2507 return 0; 2508 } 2509 2510 static int 2511 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len, 2512 unsigned int cipher_len, 2513 unsigned int cipher_offset) 2514 { 2515 struct crypto_testsuite_params *ts_params = &testsuite_params; 2516 struct crypto_unittest_params *ut_params = &unittest_params; 2517 2518 /* Generate Crypto op data structure */ 2519 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2520 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2521 TEST_ASSERT_NOT_NULL(ut_params->op, 2522 "Failed to allocate pktmbuf offload"); 2523 2524 /* Set crypto operation data parameters */ 2525 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2526 2527 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2528 2529 /* set crypto operation source mbuf */ 2530 sym_op->m_src = ut_params->ibuf; 2531 2532 /* iv */ 2533 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2534 iv, iv_len); 2535 sym_op->cipher.data.length = cipher_len; 2536 sym_op->cipher.data.offset = cipher_offset; 2537 return 0; 2538 } 2539 2540 static int 2541 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len, 2542 unsigned int cipher_len, 2543 unsigned int cipher_offset) 2544 { 2545 struct crypto_testsuite_params *ts_params = &testsuite_params; 2546 struct crypto_unittest_params *ut_params = &unittest_params; 2547 2548 /* Generate Crypto op data structure */ 2549 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2550 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2551 TEST_ASSERT_NOT_NULL(ut_params->op, 2552 "Failed to allocate pktmbuf offload"); 2553 2554 /* Set crypto operation data parameters */ 2555 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2556 2557 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2558 2559 /* set crypto operation source mbuf */ 2560 sym_op->m_src = ut_params->ibuf; 2561 sym_op->m_dst = ut_params->obuf; 2562 2563 /* iv */ 2564 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2565 iv, iv_len); 2566 sym_op->cipher.data.length = cipher_len; 2567 sym_op->cipher.data.offset = cipher_offset; 2568 return 0; 2569 } 2570 2571 static int 2572 create_wireless_algo_cipher_auth_session(uint8_t dev_id, 2573 enum rte_crypto_cipher_operation cipher_op, 2574 enum rte_crypto_auth_operation auth_op, 2575 enum rte_crypto_auth_algorithm auth_algo, 2576 enum rte_crypto_cipher_algorithm cipher_algo, 2577 const uint8_t *key, uint8_t key_len, 2578 uint8_t auth_iv_len, uint8_t auth_len, 2579 uint8_t cipher_iv_len) 2580 2581 { 2582 uint8_t cipher_auth_key[key_len]; 2583 int status; 2584 2585 struct crypto_testsuite_params *ts_params = &testsuite_params; 2586 struct crypto_unittest_params *ut_params = &unittest_params; 2587 2588 memcpy(cipher_auth_key, key, key_len); 2589 2590 /* Setup Authentication Parameters */ 2591 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2592 ut_params->auth_xform.next = NULL; 2593 2594 ut_params->auth_xform.auth.op = auth_op; 2595 ut_params->auth_xform.auth.algo = auth_algo; 2596 ut_params->auth_xform.auth.key.length = key_len; 2597 /* Hash key = cipher key */ 2598 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2599 ut_params->auth_xform.auth.digest_length = auth_len; 2600 /* Auth IV will be after cipher IV */ 2601 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2602 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2603 2604 /* Setup Cipher Parameters */ 2605 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2606 ut_params->cipher_xform.next = &ut_params->auth_xform; 2607 2608 ut_params->cipher_xform.cipher.algo = cipher_algo; 2609 ut_params->cipher_xform.cipher.op = cipher_op; 2610 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2611 ut_params->cipher_xform.cipher.key.length = key_len; 2612 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2613 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2614 2615 debug_hexdump(stdout, "key:", key, key_len); 2616 2617 /* Create Crypto session*/ 2618 ut_params->sess = rte_cryptodev_sym_session_create( 2619 ts_params->session_mpool); 2620 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2621 2622 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2623 &ut_params->cipher_xform, 2624 ts_params->session_priv_mpool); 2625 if (status == -ENOTSUP) 2626 return TEST_SKIPPED; 2627 2628 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2629 return 0; 2630 } 2631 2632 static int 2633 create_wireless_cipher_auth_session(uint8_t dev_id, 2634 enum rte_crypto_cipher_operation cipher_op, 2635 enum rte_crypto_auth_operation auth_op, 2636 enum rte_crypto_auth_algorithm auth_algo, 2637 enum rte_crypto_cipher_algorithm cipher_algo, 2638 const struct wireless_test_data *tdata) 2639 { 2640 const uint8_t key_len = tdata->key.len; 2641 uint8_t cipher_auth_key[key_len]; 2642 int status; 2643 2644 struct crypto_testsuite_params *ts_params = &testsuite_params; 2645 struct crypto_unittest_params *ut_params = &unittest_params; 2646 const uint8_t *key = tdata->key.data; 2647 const uint8_t auth_len = tdata->digest.len; 2648 uint8_t cipher_iv_len = tdata->cipher_iv.len; 2649 uint8_t auth_iv_len = tdata->auth_iv.len; 2650 2651 memcpy(cipher_auth_key, key, key_len); 2652 2653 /* Setup Authentication Parameters */ 2654 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2655 ut_params->auth_xform.next = NULL; 2656 2657 ut_params->auth_xform.auth.op = auth_op; 2658 ut_params->auth_xform.auth.algo = auth_algo; 2659 ut_params->auth_xform.auth.key.length = key_len; 2660 /* Hash key = cipher key */ 2661 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2662 ut_params->auth_xform.auth.digest_length = auth_len; 2663 /* Auth IV will be after cipher IV */ 2664 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2665 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2666 2667 /* Setup Cipher Parameters */ 2668 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2669 ut_params->cipher_xform.next = &ut_params->auth_xform; 2670 2671 ut_params->cipher_xform.cipher.algo = cipher_algo; 2672 ut_params->cipher_xform.cipher.op = cipher_op; 2673 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2674 ut_params->cipher_xform.cipher.key.length = key_len; 2675 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2676 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2677 2678 2679 debug_hexdump(stdout, "key:", key, key_len); 2680 2681 /* Create Crypto session*/ 2682 ut_params->sess = rte_cryptodev_sym_session_create( 2683 ts_params->session_mpool); 2684 2685 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2686 &ut_params->cipher_xform, 2687 ts_params->session_priv_mpool); 2688 if (status == -ENOTSUP) 2689 return TEST_SKIPPED; 2690 2691 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2692 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2693 return 0; 2694 } 2695 2696 static int 2697 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id, 2698 const struct wireless_test_data *tdata) 2699 { 2700 return create_wireless_cipher_auth_session(dev_id, 2701 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2702 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3, 2703 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata); 2704 } 2705 2706 static int 2707 create_wireless_algo_auth_cipher_session(uint8_t dev_id, 2708 enum rte_crypto_cipher_operation cipher_op, 2709 enum rte_crypto_auth_operation auth_op, 2710 enum rte_crypto_auth_algorithm auth_algo, 2711 enum rte_crypto_cipher_algorithm cipher_algo, 2712 const uint8_t *key, const uint8_t key_len, 2713 uint8_t auth_iv_len, uint8_t auth_len, 2714 uint8_t cipher_iv_len) 2715 { 2716 uint8_t auth_cipher_key[key_len]; 2717 int status; 2718 struct crypto_testsuite_params *ts_params = &testsuite_params; 2719 struct crypto_unittest_params *ut_params = &unittest_params; 2720 2721 memcpy(auth_cipher_key, key, key_len); 2722 2723 /* Setup Authentication Parameters */ 2724 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2725 ut_params->auth_xform.auth.op = auth_op; 2726 ut_params->auth_xform.next = &ut_params->cipher_xform; 2727 ut_params->auth_xform.auth.algo = auth_algo; 2728 ut_params->auth_xform.auth.key.length = key_len; 2729 ut_params->auth_xform.auth.key.data = auth_cipher_key; 2730 ut_params->auth_xform.auth.digest_length = auth_len; 2731 /* Auth IV will be after cipher IV */ 2732 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2733 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2734 2735 /* Setup Cipher Parameters */ 2736 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2737 ut_params->cipher_xform.next = NULL; 2738 ut_params->cipher_xform.cipher.algo = cipher_algo; 2739 ut_params->cipher_xform.cipher.op = cipher_op; 2740 ut_params->cipher_xform.cipher.key.data = auth_cipher_key; 2741 ut_params->cipher_xform.cipher.key.length = key_len; 2742 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2743 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2744 2745 debug_hexdump(stdout, "key:", key, key_len); 2746 2747 /* Create Crypto session*/ 2748 ut_params->sess = rte_cryptodev_sym_session_create( 2749 ts_params->session_mpool); 2750 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2751 2752 if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 2753 ut_params->auth_xform.next = NULL; 2754 ut_params->cipher_xform.next = &ut_params->auth_xform; 2755 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2756 &ut_params->cipher_xform, 2757 ts_params->session_priv_mpool); 2758 2759 } else 2760 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2761 &ut_params->auth_xform, 2762 ts_params->session_priv_mpool); 2763 2764 if (status == -ENOTSUP) 2765 return TEST_SKIPPED; 2766 2767 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2768 2769 return 0; 2770 } 2771 2772 static int 2773 create_wireless_algo_hash_operation(const uint8_t *auth_tag, 2774 unsigned int auth_tag_len, 2775 const uint8_t *iv, unsigned int iv_len, 2776 unsigned int data_pad_len, 2777 enum rte_crypto_auth_operation op, 2778 unsigned int auth_len, unsigned int auth_offset) 2779 { 2780 struct crypto_testsuite_params *ts_params = &testsuite_params; 2781 2782 struct crypto_unittest_params *ut_params = &unittest_params; 2783 2784 /* Generate Crypto op data structure */ 2785 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2786 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2787 TEST_ASSERT_NOT_NULL(ut_params->op, 2788 "Failed to allocate pktmbuf offload"); 2789 2790 /* Set crypto operation data parameters */ 2791 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2792 2793 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2794 2795 /* set crypto operation source mbuf */ 2796 sym_op->m_src = ut_params->ibuf; 2797 2798 /* iv */ 2799 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2800 iv, iv_len); 2801 /* digest */ 2802 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2803 ut_params->ibuf, auth_tag_len); 2804 2805 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2806 "no room to append auth tag"); 2807 ut_params->digest = sym_op->auth.digest.data; 2808 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2809 ut_params->ibuf, data_pad_len); 2810 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2811 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2812 else 2813 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2814 2815 debug_hexdump(stdout, "digest:", 2816 sym_op->auth.digest.data, 2817 auth_tag_len); 2818 2819 sym_op->auth.data.length = auth_len; 2820 sym_op->auth.data.offset = auth_offset; 2821 2822 return 0; 2823 } 2824 2825 static int 2826 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata, 2827 enum rte_crypto_auth_operation op) 2828 { 2829 struct crypto_testsuite_params *ts_params = &testsuite_params; 2830 struct crypto_unittest_params *ut_params = &unittest_params; 2831 2832 const uint8_t *auth_tag = tdata->digest.data; 2833 const unsigned int auth_tag_len = tdata->digest.len; 2834 unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len); 2835 unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2836 2837 const uint8_t *cipher_iv = tdata->cipher_iv.data; 2838 const uint8_t cipher_iv_len = tdata->cipher_iv.len; 2839 const uint8_t *auth_iv = tdata->auth_iv.data; 2840 const uint8_t auth_iv_len = tdata->auth_iv.len; 2841 const unsigned int cipher_len = tdata->validCipherLenInBits.len; 2842 const unsigned int auth_len = tdata->validAuthLenInBits.len; 2843 2844 /* Generate Crypto op data structure */ 2845 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2846 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2847 TEST_ASSERT_NOT_NULL(ut_params->op, 2848 "Failed to allocate pktmbuf offload"); 2849 /* Set crypto operation data parameters */ 2850 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2851 2852 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2853 2854 /* set crypto operation source mbuf */ 2855 sym_op->m_src = ut_params->ibuf; 2856 2857 /* digest */ 2858 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2859 ut_params->ibuf, auth_tag_len); 2860 2861 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2862 "no room to append auth tag"); 2863 ut_params->digest = sym_op->auth.digest.data; 2864 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2865 ut_params->ibuf, data_pad_len); 2866 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2867 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2868 else 2869 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2870 2871 debug_hexdump(stdout, "digest:", 2872 sym_op->auth.digest.data, 2873 auth_tag_len); 2874 2875 /* Copy cipher and auth IVs at the end of the crypto operation */ 2876 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2877 IV_OFFSET); 2878 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2879 iv_ptr += cipher_iv_len; 2880 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2881 2882 sym_op->cipher.data.length = cipher_len; 2883 sym_op->cipher.data.offset = 0; 2884 sym_op->auth.data.length = auth_len; 2885 sym_op->auth.data.offset = 0; 2886 2887 return 0; 2888 } 2889 2890 static int 2891 create_zuc_cipher_hash_generate_operation( 2892 const struct wireless_test_data *tdata) 2893 { 2894 return create_wireless_cipher_hash_operation(tdata, 2895 RTE_CRYPTO_AUTH_OP_GENERATE); 2896 } 2897 2898 static int 2899 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag, 2900 const unsigned auth_tag_len, 2901 const uint8_t *auth_iv, uint8_t auth_iv_len, 2902 unsigned data_pad_len, 2903 enum rte_crypto_auth_operation op, 2904 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2905 const unsigned cipher_len, const unsigned cipher_offset, 2906 const unsigned auth_len, const unsigned auth_offset) 2907 { 2908 struct crypto_testsuite_params *ts_params = &testsuite_params; 2909 struct crypto_unittest_params *ut_params = &unittest_params; 2910 2911 enum rte_crypto_cipher_algorithm cipher_algo = 2912 ut_params->cipher_xform.cipher.algo; 2913 enum rte_crypto_auth_algorithm auth_algo = 2914 ut_params->auth_xform.auth.algo; 2915 2916 /* Generate Crypto op data structure */ 2917 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2918 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2919 TEST_ASSERT_NOT_NULL(ut_params->op, 2920 "Failed to allocate pktmbuf offload"); 2921 /* Set crypto operation data parameters */ 2922 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2923 2924 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2925 2926 /* set crypto operation source mbuf */ 2927 sym_op->m_src = ut_params->ibuf; 2928 2929 /* digest */ 2930 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2931 ut_params->ibuf, auth_tag_len); 2932 2933 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2934 "no room to append auth tag"); 2935 ut_params->digest = sym_op->auth.digest.data; 2936 2937 if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) { 2938 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2939 ut_params->ibuf, data_pad_len); 2940 } else { 2941 struct rte_mbuf *m = ut_params->ibuf; 2942 unsigned int offset = data_pad_len; 2943 2944 while (offset > m->data_len && m->next != NULL) { 2945 offset -= m->data_len; 2946 m = m->next; 2947 } 2948 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2949 m, offset); 2950 } 2951 2952 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2953 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2954 else 2955 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2956 2957 debug_hexdump(stdout, "digest:", 2958 sym_op->auth.digest.data, 2959 auth_tag_len); 2960 2961 /* Copy cipher and auth IVs at the end of the crypto operation */ 2962 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2963 IV_OFFSET); 2964 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2965 iv_ptr += cipher_iv_len; 2966 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2967 2968 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 2969 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 2970 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 2971 sym_op->cipher.data.length = cipher_len; 2972 sym_op->cipher.data.offset = cipher_offset; 2973 } else { 2974 sym_op->cipher.data.length = cipher_len >> 3; 2975 sym_op->cipher.data.offset = cipher_offset >> 3; 2976 } 2977 2978 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 2979 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 2980 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 2981 sym_op->auth.data.length = auth_len; 2982 sym_op->auth.data.offset = auth_offset; 2983 } else { 2984 sym_op->auth.data.length = auth_len >> 3; 2985 sym_op->auth.data.offset = auth_offset >> 3; 2986 } 2987 2988 return 0; 2989 } 2990 2991 static int 2992 create_wireless_algo_auth_cipher_operation( 2993 const uint8_t *auth_tag, unsigned int auth_tag_len, 2994 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2995 const uint8_t *auth_iv, uint8_t auth_iv_len, 2996 unsigned int data_pad_len, 2997 unsigned int cipher_len, unsigned int cipher_offset, 2998 unsigned int auth_len, unsigned int auth_offset, 2999 uint8_t op_mode, uint8_t do_sgl, uint8_t verify) 3000 { 3001 struct crypto_testsuite_params *ts_params = &testsuite_params; 3002 struct crypto_unittest_params *ut_params = &unittest_params; 3003 3004 enum rte_crypto_cipher_algorithm cipher_algo = 3005 ut_params->cipher_xform.cipher.algo; 3006 enum rte_crypto_auth_algorithm auth_algo = 3007 ut_params->auth_xform.auth.algo; 3008 3009 /* Generate Crypto op data structure */ 3010 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3011 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3012 TEST_ASSERT_NOT_NULL(ut_params->op, 3013 "Failed to allocate pktmbuf offload"); 3014 3015 /* Set crypto operation data parameters */ 3016 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 3017 3018 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3019 3020 /* set crypto operation mbufs */ 3021 sym_op->m_src = ut_params->ibuf; 3022 if (op_mode == OUT_OF_PLACE) 3023 sym_op->m_dst = ut_params->obuf; 3024 3025 /* digest */ 3026 if (!do_sgl) { 3027 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset( 3028 (op_mode == IN_PLACE ? 3029 ut_params->ibuf : ut_params->obuf), 3030 uint8_t *, data_pad_len); 3031 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3032 (op_mode == IN_PLACE ? 3033 ut_params->ibuf : ut_params->obuf), 3034 data_pad_len); 3035 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3036 } else { 3037 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3); 3038 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ? 3039 sym_op->m_src : sym_op->m_dst); 3040 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) { 3041 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 3042 sgl_buf = sgl_buf->next; 3043 } 3044 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf, 3045 uint8_t *, remaining_off); 3046 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf, 3047 remaining_off); 3048 memset(sym_op->auth.digest.data, 0, remaining_off); 3049 while (sgl_buf->next != NULL) { 3050 memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *), 3051 0, rte_pktmbuf_data_len(sgl_buf)); 3052 sgl_buf = sgl_buf->next; 3053 } 3054 } 3055 3056 /* Copy digest for the verification */ 3057 if (verify) 3058 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3059 3060 /* Copy cipher and auth IVs at the end of the crypto operation */ 3061 uint8_t *iv_ptr = rte_crypto_op_ctod_offset( 3062 ut_params->op, uint8_t *, IV_OFFSET); 3063 3064 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 3065 iv_ptr += cipher_iv_len; 3066 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 3067 3068 /* Only copy over the offset data needed from src to dst in OOP, 3069 * if the auth and cipher offsets are not aligned 3070 */ 3071 if (op_mode == OUT_OF_PLACE) { 3072 if (cipher_offset > auth_offset) 3073 rte_memcpy( 3074 rte_pktmbuf_mtod_offset( 3075 sym_op->m_dst, 3076 uint8_t *, auth_offset >> 3), 3077 rte_pktmbuf_mtod_offset( 3078 sym_op->m_src, 3079 uint8_t *, auth_offset >> 3), 3080 ((cipher_offset >> 3) - (auth_offset >> 3))); 3081 } 3082 3083 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 3084 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 3085 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 3086 sym_op->cipher.data.length = cipher_len; 3087 sym_op->cipher.data.offset = cipher_offset; 3088 } else { 3089 sym_op->cipher.data.length = cipher_len >> 3; 3090 sym_op->cipher.data.offset = cipher_offset >> 3; 3091 } 3092 3093 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 3094 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 3095 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 3096 sym_op->auth.data.length = auth_len; 3097 sym_op->auth.data.offset = auth_offset; 3098 } else { 3099 sym_op->auth.data.length = auth_len >> 3; 3100 sym_op->auth.data.offset = auth_offset >> 3; 3101 } 3102 3103 return 0; 3104 } 3105 3106 static int 3107 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) 3108 { 3109 struct crypto_testsuite_params *ts_params = &testsuite_params; 3110 struct crypto_unittest_params *ut_params = &unittest_params; 3111 3112 int retval; 3113 unsigned plaintext_pad_len; 3114 unsigned plaintext_len; 3115 uint8_t *plaintext; 3116 struct rte_cryptodev_info dev_info; 3117 3118 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3119 uint64_t feat_flags = dev_info.feature_flags; 3120 3121 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3122 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3123 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3124 return TEST_SKIPPED; 3125 } 3126 3127 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3128 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3129 printf("Device doesn't support RAW data-path APIs.\n"); 3130 return TEST_SKIPPED; 3131 } 3132 3133 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3134 return TEST_SKIPPED; 3135 3136 /* Verify the capabilities */ 3137 struct rte_cryptodev_sym_capability_idx cap_idx; 3138 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3139 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3140 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3141 &cap_idx) == NULL) 3142 return TEST_SKIPPED; 3143 3144 /* Create SNOW 3G session */ 3145 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3146 tdata->key.data, tdata->key.len, 3147 tdata->auth_iv.len, tdata->digest.len, 3148 RTE_CRYPTO_AUTH_OP_GENERATE, 3149 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3150 if (retval < 0) 3151 return retval; 3152 3153 /* alloc mbuf and set payload */ 3154 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3155 3156 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3157 rte_pktmbuf_tailroom(ut_params->ibuf)); 3158 3159 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3160 /* Append data which is padded to a multiple of */ 3161 /* the algorithms block size */ 3162 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3163 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3164 plaintext_pad_len); 3165 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3166 3167 /* Create SNOW 3G operation */ 3168 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3169 tdata->auth_iv.data, tdata->auth_iv.len, 3170 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3171 tdata->validAuthLenInBits.len, 3172 0); 3173 if (retval < 0) 3174 return retval; 3175 3176 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3177 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3178 ut_params->op, 0, 1, 1, 0); 3179 else 3180 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3181 ut_params->op); 3182 ut_params->obuf = ut_params->op->sym->m_src; 3183 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3184 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3185 + plaintext_pad_len; 3186 3187 /* Validate obuf */ 3188 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3189 ut_params->digest, 3190 tdata->digest.data, 3191 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 3192 "SNOW 3G Generated auth tag not as expected"); 3193 3194 return 0; 3195 } 3196 3197 static int 3198 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) 3199 { 3200 struct crypto_testsuite_params *ts_params = &testsuite_params; 3201 struct crypto_unittest_params *ut_params = &unittest_params; 3202 3203 int retval; 3204 unsigned plaintext_pad_len; 3205 unsigned plaintext_len; 3206 uint8_t *plaintext; 3207 struct rte_cryptodev_info dev_info; 3208 3209 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3210 uint64_t feat_flags = dev_info.feature_flags; 3211 3212 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3213 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3214 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3215 return TEST_SKIPPED; 3216 } 3217 3218 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3219 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3220 printf("Device doesn't support RAW data-path APIs.\n"); 3221 return TEST_SKIPPED; 3222 } 3223 3224 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3225 return TEST_SKIPPED; 3226 3227 /* Verify the capabilities */ 3228 struct rte_cryptodev_sym_capability_idx cap_idx; 3229 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3230 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3231 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3232 &cap_idx) == NULL) 3233 return TEST_SKIPPED; 3234 3235 /* Create SNOW 3G session */ 3236 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3237 tdata->key.data, tdata->key.len, 3238 tdata->auth_iv.len, tdata->digest.len, 3239 RTE_CRYPTO_AUTH_OP_VERIFY, 3240 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3241 if (retval < 0) 3242 return retval; 3243 /* alloc mbuf and set payload */ 3244 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3245 3246 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3247 rte_pktmbuf_tailroom(ut_params->ibuf)); 3248 3249 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3250 /* Append data which is padded to a multiple of */ 3251 /* the algorithms block size */ 3252 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3253 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3254 plaintext_pad_len); 3255 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3256 3257 /* Create SNOW 3G operation */ 3258 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3259 tdata->digest.len, 3260 tdata->auth_iv.data, tdata->auth_iv.len, 3261 plaintext_pad_len, 3262 RTE_CRYPTO_AUTH_OP_VERIFY, 3263 tdata->validAuthLenInBits.len, 3264 0); 3265 if (retval < 0) 3266 return retval; 3267 3268 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3269 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3270 ut_params->op, 0, 1, 1, 0); 3271 else 3272 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3273 ut_params->op); 3274 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3275 ut_params->obuf = ut_params->op->sym->m_src; 3276 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3277 + plaintext_pad_len; 3278 3279 /* Validate obuf */ 3280 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3281 return 0; 3282 else 3283 return -1; 3284 3285 return 0; 3286 } 3287 3288 static int 3289 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata) 3290 { 3291 struct crypto_testsuite_params *ts_params = &testsuite_params; 3292 struct crypto_unittest_params *ut_params = &unittest_params; 3293 3294 int retval; 3295 unsigned plaintext_pad_len; 3296 unsigned plaintext_len; 3297 uint8_t *plaintext; 3298 struct rte_cryptodev_info dev_info; 3299 3300 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3301 uint64_t feat_flags = dev_info.feature_flags; 3302 3303 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3304 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3305 printf("Device doesn't support RAW data-path APIs.\n"); 3306 return TEST_SKIPPED; 3307 } 3308 3309 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3310 return TEST_SKIPPED; 3311 3312 /* Verify the capabilities */ 3313 struct rte_cryptodev_sym_capability_idx cap_idx; 3314 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3315 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3316 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3317 &cap_idx) == NULL) 3318 return TEST_SKIPPED; 3319 3320 /* Create KASUMI session */ 3321 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3322 tdata->key.data, tdata->key.len, 3323 0, tdata->digest.len, 3324 RTE_CRYPTO_AUTH_OP_GENERATE, 3325 RTE_CRYPTO_AUTH_KASUMI_F9); 3326 if (retval < 0) 3327 return retval; 3328 3329 /* alloc mbuf and set payload */ 3330 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3331 3332 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3333 rte_pktmbuf_tailroom(ut_params->ibuf)); 3334 3335 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3336 /* Append data which is padded to a multiple of */ 3337 /* the algorithms block size */ 3338 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3339 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3340 plaintext_pad_len); 3341 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3342 3343 /* Create KASUMI operation */ 3344 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3345 NULL, 0, 3346 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3347 tdata->plaintext.len, 3348 0); 3349 if (retval < 0) 3350 return retval; 3351 3352 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3353 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 3354 ut_params->op); 3355 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3356 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3357 ut_params->op, 0, 1, 1, 0); 3358 else 3359 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3360 ut_params->op); 3361 3362 ut_params->obuf = ut_params->op->sym->m_src; 3363 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3364 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3365 + plaintext_pad_len; 3366 3367 /* Validate obuf */ 3368 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3369 ut_params->digest, 3370 tdata->digest.data, 3371 DIGEST_BYTE_LENGTH_KASUMI_F9, 3372 "KASUMI Generated auth tag not as expected"); 3373 3374 return 0; 3375 } 3376 3377 static int 3378 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata) 3379 { 3380 struct crypto_testsuite_params *ts_params = &testsuite_params; 3381 struct crypto_unittest_params *ut_params = &unittest_params; 3382 3383 int retval; 3384 unsigned plaintext_pad_len; 3385 unsigned plaintext_len; 3386 uint8_t *plaintext; 3387 struct rte_cryptodev_info dev_info; 3388 3389 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3390 uint64_t feat_flags = dev_info.feature_flags; 3391 3392 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3393 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3394 printf("Device doesn't support RAW data-path APIs.\n"); 3395 return TEST_SKIPPED; 3396 } 3397 3398 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3399 return TEST_SKIPPED; 3400 3401 /* Verify the capabilities */ 3402 struct rte_cryptodev_sym_capability_idx cap_idx; 3403 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3404 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3405 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3406 &cap_idx) == NULL) 3407 return TEST_SKIPPED; 3408 3409 /* Create KASUMI session */ 3410 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3411 tdata->key.data, tdata->key.len, 3412 0, tdata->digest.len, 3413 RTE_CRYPTO_AUTH_OP_VERIFY, 3414 RTE_CRYPTO_AUTH_KASUMI_F9); 3415 if (retval < 0) 3416 return retval; 3417 /* alloc mbuf and set payload */ 3418 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3419 3420 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3421 rte_pktmbuf_tailroom(ut_params->ibuf)); 3422 3423 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3424 /* Append data which is padded to a multiple */ 3425 /* of the algorithms block size */ 3426 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3427 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3428 plaintext_pad_len); 3429 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3430 3431 /* Create KASUMI operation */ 3432 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3433 tdata->digest.len, 3434 NULL, 0, 3435 plaintext_pad_len, 3436 RTE_CRYPTO_AUTH_OP_VERIFY, 3437 tdata->plaintext.len, 3438 0); 3439 if (retval < 0) 3440 return retval; 3441 3442 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3443 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3444 ut_params->op, 0, 1, 1, 0); 3445 else 3446 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3447 ut_params->op); 3448 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3449 ut_params->obuf = ut_params->op->sym->m_src; 3450 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3451 + plaintext_pad_len; 3452 3453 /* Validate obuf */ 3454 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3455 return 0; 3456 else 3457 return -1; 3458 3459 return 0; 3460 } 3461 3462 static int 3463 test_snow3g_hash_generate_test_case_1(void) 3464 { 3465 return test_snow3g_authentication(&snow3g_hash_test_case_1); 3466 } 3467 3468 static int 3469 test_snow3g_hash_generate_test_case_2(void) 3470 { 3471 return test_snow3g_authentication(&snow3g_hash_test_case_2); 3472 } 3473 3474 static int 3475 test_snow3g_hash_generate_test_case_3(void) 3476 { 3477 return test_snow3g_authentication(&snow3g_hash_test_case_3); 3478 } 3479 3480 static int 3481 test_snow3g_hash_generate_test_case_4(void) 3482 { 3483 return test_snow3g_authentication(&snow3g_hash_test_case_4); 3484 } 3485 3486 static int 3487 test_snow3g_hash_generate_test_case_5(void) 3488 { 3489 return test_snow3g_authentication(&snow3g_hash_test_case_5); 3490 } 3491 3492 static int 3493 test_snow3g_hash_generate_test_case_6(void) 3494 { 3495 return test_snow3g_authentication(&snow3g_hash_test_case_6); 3496 } 3497 3498 static int 3499 test_snow3g_hash_verify_test_case_1(void) 3500 { 3501 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1); 3502 3503 } 3504 3505 static int 3506 test_snow3g_hash_verify_test_case_2(void) 3507 { 3508 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2); 3509 } 3510 3511 static int 3512 test_snow3g_hash_verify_test_case_3(void) 3513 { 3514 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3); 3515 } 3516 3517 static int 3518 test_snow3g_hash_verify_test_case_4(void) 3519 { 3520 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4); 3521 } 3522 3523 static int 3524 test_snow3g_hash_verify_test_case_5(void) 3525 { 3526 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5); 3527 } 3528 3529 static int 3530 test_snow3g_hash_verify_test_case_6(void) 3531 { 3532 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6); 3533 } 3534 3535 static int 3536 test_kasumi_hash_generate_test_case_1(void) 3537 { 3538 return test_kasumi_authentication(&kasumi_hash_test_case_1); 3539 } 3540 3541 static int 3542 test_kasumi_hash_generate_test_case_2(void) 3543 { 3544 return test_kasumi_authentication(&kasumi_hash_test_case_2); 3545 } 3546 3547 static int 3548 test_kasumi_hash_generate_test_case_3(void) 3549 { 3550 return test_kasumi_authentication(&kasumi_hash_test_case_3); 3551 } 3552 3553 static int 3554 test_kasumi_hash_generate_test_case_4(void) 3555 { 3556 return test_kasumi_authentication(&kasumi_hash_test_case_4); 3557 } 3558 3559 static int 3560 test_kasumi_hash_generate_test_case_5(void) 3561 { 3562 return test_kasumi_authentication(&kasumi_hash_test_case_5); 3563 } 3564 3565 static int 3566 test_kasumi_hash_generate_test_case_6(void) 3567 { 3568 return test_kasumi_authentication(&kasumi_hash_test_case_6); 3569 } 3570 3571 static int 3572 test_kasumi_hash_verify_test_case_1(void) 3573 { 3574 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1); 3575 } 3576 3577 static int 3578 test_kasumi_hash_verify_test_case_2(void) 3579 { 3580 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2); 3581 } 3582 3583 static int 3584 test_kasumi_hash_verify_test_case_3(void) 3585 { 3586 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3); 3587 } 3588 3589 static int 3590 test_kasumi_hash_verify_test_case_4(void) 3591 { 3592 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4); 3593 } 3594 3595 static int 3596 test_kasumi_hash_verify_test_case_5(void) 3597 { 3598 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5); 3599 } 3600 3601 static int 3602 test_kasumi_encryption(const struct kasumi_test_data *tdata) 3603 { 3604 struct crypto_testsuite_params *ts_params = &testsuite_params; 3605 struct crypto_unittest_params *ut_params = &unittest_params; 3606 3607 int retval; 3608 uint8_t *plaintext, *ciphertext; 3609 unsigned plaintext_pad_len; 3610 unsigned plaintext_len; 3611 struct rte_cryptodev_info dev_info; 3612 3613 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3614 uint64_t feat_flags = dev_info.feature_flags; 3615 3616 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3617 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3618 printf("Device doesn't support RAW data-path APIs.\n"); 3619 return TEST_SKIPPED; 3620 } 3621 3622 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3623 return TEST_SKIPPED; 3624 3625 /* Verify the capabilities */ 3626 struct rte_cryptodev_sym_capability_idx cap_idx; 3627 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3628 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3629 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3630 &cap_idx) == NULL) 3631 return TEST_SKIPPED; 3632 3633 /* Create KASUMI session */ 3634 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3635 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3636 RTE_CRYPTO_CIPHER_KASUMI_F8, 3637 tdata->key.data, tdata->key.len, 3638 tdata->cipher_iv.len); 3639 if (retval < 0) 3640 return retval; 3641 3642 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3643 3644 /* Clear mbuf payload */ 3645 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3646 rte_pktmbuf_tailroom(ut_params->ibuf)); 3647 3648 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3649 /* Append data which is padded to a multiple */ 3650 /* of the algorithms block size */ 3651 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3652 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3653 plaintext_pad_len); 3654 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3655 3656 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3657 3658 /* Create KASUMI operation */ 3659 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3660 tdata->cipher_iv.len, 3661 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3662 tdata->validCipherOffsetInBits.len); 3663 if (retval < 0) 3664 return retval; 3665 3666 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3667 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3668 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3669 else 3670 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3671 ut_params->op); 3672 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3673 3674 ut_params->obuf = ut_params->op->sym->m_dst; 3675 if (ut_params->obuf) 3676 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3677 else 3678 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3679 3680 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3681 3682 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3683 (tdata->validCipherOffsetInBits.len >> 3); 3684 /* Validate obuf */ 3685 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3686 ciphertext, 3687 reference_ciphertext, 3688 tdata->validCipherLenInBits.len, 3689 "KASUMI Ciphertext data not as expected"); 3690 return 0; 3691 } 3692 3693 static int 3694 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata) 3695 { 3696 struct crypto_testsuite_params *ts_params = &testsuite_params; 3697 struct crypto_unittest_params *ut_params = &unittest_params; 3698 3699 int retval; 3700 3701 unsigned int plaintext_pad_len; 3702 unsigned int plaintext_len; 3703 3704 uint8_t buffer[10000]; 3705 const uint8_t *ciphertext; 3706 3707 struct rte_cryptodev_info dev_info; 3708 3709 /* Verify the capabilities */ 3710 struct rte_cryptodev_sym_capability_idx cap_idx; 3711 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3712 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3713 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3714 &cap_idx) == NULL) 3715 return TEST_SKIPPED; 3716 3717 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3718 3719 uint64_t feat_flags = dev_info.feature_flags; 3720 3721 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 3722 printf("Device doesn't support in-place scatter-gather. " 3723 "Test Skipped.\n"); 3724 return TEST_SKIPPED; 3725 } 3726 3727 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3728 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3729 printf("Device doesn't support RAW data-path APIs.\n"); 3730 return TEST_SKIPPED; 3731 } 3732 3733 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3734 return TEST_SKIPPED; 3735 3736 /* Create KASUMI session */ 3737 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3738 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3739 RTE_CRYPTO_CIPHER_KASUMI_F8, 3740 tdata->key.data, tdata->key.len, 3741 tdata->cipher_iv.len); 3742 if (retval < 0) 3743 return retval; 3744 3745 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3746 3747 3748 /* Append data which is padded to a multiple */ 3749 /* of the algorithms block size */ 3750 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3751 3752 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3753 plaintext_pad_len, 10, 0); 3754 3755 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3756 3757 /* Create KASUMI operation */ 3758 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3759 tdata->cipher_iv.len, 3760 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3761 tdata->validCipherOffsetInBits.len); 3762 if (retval < 0) 3763 return retval; 3764 3765 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3766 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3767 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3768 else 3769 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3770 ut_params->op); 3771 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3772 3773 ut_params->obuf = ut_params->op->sym->m_dst; 3774 3775 if (ut_params->obuf) 3776 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3777 plaintext_len, buffer); 3778 else 3779 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3780 tdata->validCipherOffsetInBits.len >> 3, 3781 plaintext_len, buffer); 3782 3783 /* Validate obuf */ 3784 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3785 3786 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3787 (tdata->validCipherOffsetInBits.len >> 3); 3788 /* Validate obuf */ 3789 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3790 ciphertext, 3791 reference_ciphertext, 3792 tdata->validCipherLenInBits.len, 3793 "KASUMI Ciphertext data not as expected"); 3794 return 0; 3795 } 3796 3797 static int 3798 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata) 3799 { 3800 struct crypto_testsuite_params *ts_params = &testsuite_params; 3801 struct crypto_unittest_params *ut_params = &unittest_params; 3802 3803 int retval; 3804 uint8_t *plaintext, *ciphertext; 3805 unsigned plaintext_pad_len; 3806 unsigned plaintext_len; 3807 3808 /* Verify the capabilities */ 3809 struct rte_cryptodev_sym_capability_idx cap_idx; 3810 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3811 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3812 /* Data-path service does not support OOP */ 3813 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3814 &cap_idx) == NULL) 3815 return TEST_SKIPPED; 3816 3817 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3818 return TEST_SKIPPED; 3819 3820 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3821 return TEST_SKIPPED; 3822 3823 /* Create KASUMI session */ 3824 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3825 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3826 RTE_CRYPTO_CIPHER_KASUMI_F8, 3827 tdata->key.data, tdata->key.len, 3828 tdata->cipher_iv.len); 3829 if (retval < 0) 3830 return retval; 3831 3832 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3833 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3834 3835 /* Clear mbuf payload */ 3836 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3837 rte_pktmbuf_tailroom(ut_params->ibuf)); 3838 3839 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3840 /* Append data which is padded to a multiple */ 3841 /* of the algorithms block size */ 3842 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3843 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3844 plaintext_pad_len); 3845 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3846 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3847 3848 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3849 3850 /* Create KASUMI operation */ 3851 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3852 tdata->cipher_iv.len, 3853 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3854 tdata->validCipherOffsetInBits.len); 3855 if (retval < 0) 3856 return retval; 3857 3858 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3859 ut_params->op); 3860 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3861 3862 ut_params->obuf = ut_params->op->sym->m_dst; 3863 if (ut_params->obuf) 3864 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3865 else 3866 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3867 3868 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3869 3870 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3871 (tdata->validCipherOffsetInBits.len >> 3); 3872 /* Validate obuf */ 3873 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3874 ciphertext, 3875 reference_ciphertext, 3876 tdata->validCipherLenInBits.len, 3877 "KASUMI Ciphertext data not as expected"); 3878 return 0; 3879 } 3880 3881 static int 3882 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata) 3883 { 3884 struct crypto_testsuite_params *ts_params = &testsuite_params; 3885 struct crypto_unittest_params *ut_params = &unittest_params; 3886 3887 int retval; 3888 unsigned int plaintext_pad_len; 3889 unsigned int plaintext_len; 3890 3891 const uint8_t *ciphertext; 3892 uint8_t buffer[2048]; 3893 3894 struct rte_cryptodev_info dev_info; 3895 3896 /* Verify the capabilities */ 3897 struct rte_cryptodev_sym_capability_idx cap_idx; 3898 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3899 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3900 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3901 &cap_idx) == NULL) 3902 return TEST_SKIPPED; 3903 3904 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3905 return TEST_SKIPPED; 3906 3907 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3908 return TEST_SKIPPED; 3909 3910 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3911 3912 uint64_t feat_flags = dev_info.feature_flags; 3913 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 3914 printf("Device doesn't support out-of-place scatter-gather " 3915 "in both input and output mbufs. " 3916 "Test Skipped.\n"); 3917 return TEST_SKIPPED; 3918 } 3919 3920 /* Create KASUMI session */ 3921 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3922 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3923 RTE_CRYPTO_CIPHER_KASUMI_F8, 3924 tdata->key.data, tdata->key.len, 3925 tdata->cipher_iv.len); 3926 if (retval < 0) 3927 return retval; 3928 3929 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3930 /* Append data which is padded to a multiple */ 3931 /* of the algorithms block size */ 3932 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3933 3934 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3935 plaintext_pad_len, 10, 0); 3936 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 3937 plaintext_pad_len, 3, 0); 3938 3939 /* Append data which is padded to a multiple */ 3940 /* of the algorithms block size */ 3941 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3942 3943 /* Create KASUMI operation */ 3944 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3945 tdata->cipher_iv.len, 3946 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3947 tdata->validCipherOffsetInBits.len); 3948 if (retval < 0) 3949 return retval; 3950 3951 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3952 ut_params->op); 3953 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3954 3955 ut_params->obuf = ut_params->op->sym->m_dst; 3956 if (ut_params->obuf) 3957 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3958 plaintext_pad_len, buffer); 3959 else 3960 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3961 tdata->validCipherOffsetInBits.len >> 3, 3962 plaintext_pad_len, buffer); 3963 3964 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3965 (tdata->validCipherOffsetInBits.len >> 3); 3966 /* Validate obuf */ 3967 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3968 ciphertext, 3969 reference_ciphertext, 3970 tdata->validCipherLenInBits.len, 3971 "KASUMI Ciphertext data not as expected"); 3972 return 0; 3973 } 3974 3975 3976 static int 3977 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata) 3978 { 3979 struct crypto_testsuite_params *ts_params = &testsuite_params; 3980 struct crypto_unittest_params *ut_params = &unittest_params; 3981 3982 int retval; 3983 uint8_t *ciphertext, *plaintext; 3984 unsigned ciphertext_pad_len; 3985 unsigned ciphertext_len; 3986 3987 /* Verify the capabilities */ 3988 struct rte_cryptodev_sym_capability_idx cap_idx; 3989 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3990 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3991 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3992 &cap_idx) == NULL) 3993 return TEST_SKIPPED; 3994 3995 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3996 return TEST_SKIPPED; 3997 3998 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3999 return TEST_SKIPPED; 4000 4001 /* Create KASUMI session */ 4002 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4003 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4004 RTE_CRYPTO_CIPHER_KASUMI_F8, 4005 tdata->key.data, tdata->key.len, 4006 tdata->cipher_iv.len); 4007 if (retval < 0) 4008 return retval; 4009 4010 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4011 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4012 4013 /* Clear mbuf payload */ 4014 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4015 rte_pktmbuf_tailroom(ut_params->ibuf)); 4016 4017 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4018 /* Append data which is padded to a multiple */ 4019 /* of the algorithms block size */ 4020 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4021 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4022 ciphertext_pad_len); 4023 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4024 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4025 4026 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4027 4028 /* Create KASUMI operation */ 4029 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4030 tdata->cipher_iv.len, 4031 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4032 tdata->validCipherOffsetInBits.len); 4033 if (retval < 0) 4034 return retval; 4035 4036 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4037 ut_params->op); 4038 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4039 4040 ut_params->obuf = ut_params->op->sym->m_dst; 4041 if (ut_params->obuf) 4042 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4043 else 4044 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4045 4046 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4047 4048 const uint8_t *reference_plaintext = tdata->plaintext.data + 4049 (tdata->validCipherOffsetInBits.len >> 3); 4050 /* Validate obuf */ 4051 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4052 plaintext, 4053 reference_plaintext, 4054 tdata->validCipherLenInBits.len, 4055 "KASUMI Plaintext data not as expected"); 4056 return 0; 4057 } 4058 4059 static int 4060 test_kasumi_decryption(const struct kasumi_test_data *tdata) 4061 { 4062 struct crypto_testsuite_params *ts_params = &testsuite_params; 4063 struct crypto_unittest_params *ut_params = &unittest_params; 4064 4065 int retval; 4066 uint8_t *ciphertext, *plaintext; 4067 unsigned ciphertext_pad_len; 4068 unsigned ciphertext_len; 4069 struct rte_cryptodev_info dev_info; 4070 4071 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4072 uint64_t feat_flags = dev_info.feature_flags; 4073 4074 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4075 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4076 printf("Device doesn't support RAW data-path APIs.\n"); 4077 return TEST_SKIPPED; 4078 } 4079 4080 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4081 return TEST_SKIPPED; 4082 4083 /* Verify the capabilities */ 4084 struct rte_cryptodev_sym_capability_idx cap_idx; 4085 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4086 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4087 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4088 &cap_idx) == NULL) 4089 return TEST_SKIPPED; 4090 4091 /* Create KASUMI session */ 4092 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4093 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4094 RTE_CRYPTO_CIPHER_KASUMI_F8, 4095 tdata->key.data, tdata->key.len, 4096 tdata->cipher_iv.len); 4097 if (retval < 0) 4098 return retval; 4099 4100 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4101 4102 /* Clear mbuf payload */ 4103 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4104 rte_pktmbuf_tailroom(ut_params->ibuf)); 4105 4106 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4107 /* Append data which is padded to a multiple */ 4108 /* of the algorithms block size */ 4109 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4110 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4111 ciphertext_pad_len); 4112 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4113 4114 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4115 4116 /* Create KASUMI operation */ 4117 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4118 tdata->cipher_iv.len, 4119 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4120 tdata->validCipherOffsetInBits.len); 4121 if (retval < 0) 4122 return retval; 4123 4124 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4125 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4126 ut_params->op, 1, 0, 1, 0); 4127 else 4128 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4129 ut_params->op); 4130 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4131 4132 ut_params->obuf = ut_params->op->sym->m_dst; 4133 if (ut_params->obuf) 4134 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4135 else 4136 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4137 4138 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4139 4140 const uint8_t *reference_plaintext = tdata->plaintext.data + 4141 (tdata->validCipherOffsetInBits.len >> 3); 4142 /* Validate obuf */ 4143 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4144 plaintext, 4145 reference_plaintext, 4146 tdata->validCipherLenInBits.len, 4147 "KASUMI Plaintext data not as expected"); 4148 return 0; 4149 } 4150 4151 static int 4152 test_snow3g_encryption(const struct snow3g_test_data *tdata) 4153 { 4154 struct crypto_testsuite_params *ts_params = &testsuite_params; 4155 struct crypto_unittest_params *ut_params = &unittest_params; 4156 4157 int retval; 4158 uint8_t *plaintext, *ciphertext; 4159 unsigned plaintext_pad_len; 4160 unsigned plaintext_len; 4161 struct rte_cryptodev_info dev_info; 4162 4163 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4164 uint64_t feat_flags = dev_info.feature_flags; 4165 4166 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4167 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4168 printf("Device doesn't support RAW data-path APIs.\n"); 4169 return TEST_SKIPPED; 4170 } 4171 4172 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4173 return TEST_SKIPPED; 4174 4175 /* Verify the capabilities */ 4176 struct rte_cryptodev_sym_capability_idx cap_idx; 4177 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4178 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4179 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4180 &cap_idx) == NULL) 4181 return TEST_SKIPPED; 4182 4183 /* Create SNOW 3G session */ 4184 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4185 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4186 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4187 tdata->key.data, tdata->key.len, 4188 tdata->cipher_iv.len); 4189 if (retval < 0) 4190 return retval; 4191 4192 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4193 4194 /* Clear mbuf payload */ 4195 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4196 rte_pktmbuf_tailroom(ut_params->ibuf)); 4197 4198 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4199 /* Append data which is padded to a multiple of */ 4200 /* the algorithms block size */ 4201 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4202 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4203 plaintext_pad_len); 4204 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4205 4206 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4207 4208 /* Create SNOW 3G operation */ 4209 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4210 tdata->cipher_iv.len, 4211 tdata->validCipherLenInBits.len, 4212 0); 4213 if (retval < 0) 4214 return retval; 4215 4216 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4217 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4218 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4219 else 4220 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4221 ut_params->op); 4222 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4223 4224 ut_params->obuf = ut_params->op->sym->m_dst; 4225 if (ut_params->obuf) 4226 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4227 else 4228 ciphertext = plaintext; 4229 4230 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4231 4232 /* Validate obuf */ 4233 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4234 ciphertext, 4235 tdata->ciphertext.data, 4236 tdata->validDataLenInBits.len, 4237 "SNOW 3G Ciphertext data not as expected"); 4238 return 0; 4239 } 4240 4241 4242 static int 4243 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) 4244 { 4245 struct crypto_testsuite_params *ts_params = &testsuite_params; 4246 struct crypto_unittest_params *ut_params = &unittest_params; 4247 uint8_t *plaintext, *ciphertext; 4248 4249 int retval; 4250 unsigned plaintext_pad_len; 4251 unsigned plaintext_len; 4252 struct rte_cryptodev_info dev_info; 4253 4254 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4255 uint64_t feat_flags = dev_info.feature_flags; 4256 4257 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4258 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4259 printf("Device does not support RAW data-path APIs.\n"); 4260 return -ENOTSUP; 4261 } 4262 4263 /* Verify the capabilities */ 4264 struct rte_cryptodev_sym_capability_idx cap_idx; 4265 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4266 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4267 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4268 &cap_idx) == NULL) 4269 return TEST_SKIPPED; 4270 4271 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4272 return TEST_SKIPPED; 4273 4274 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4275 return TEST_SKIPPED; 4276 4277 /* Create SNOW 3G session */ 4278 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4279 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4280 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4281 tdata->key.data, tdata->key.len, 4282 tdata->cipher_iv.len); 4283 if (retval < 0) 4284 return retval; 4285 4286 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4287 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4288 4289 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4290 "Failed to allocate input buffer in mempool"); 4291 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4292 "Failed to allocate output buffer in mempool"); 4293 4294 /* Clear mbuf payload */ 4295 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4296 rte_pktmbuf_tailroom(ut_params->ibuf)); 4297 4298 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4299 /* Append data which is padded to a multiple of */ 4300 /* the algorithms block size */ 4301 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4302 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4303 plaintext_pad_len); 4304 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4305 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4306 4307 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4308 4309 /* Create SNOW 3G operation */ 4310 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4311 tdata->cipher_iv.len, 4312 tdata->validCipherLenInBits.len, 4313 0); 4314 if (retval < 0) 4315 return retval; 4316 4317 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4318 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4319 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4320 else 4321 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4322 ut_params->op); 4323 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4324 4325 ut_params->obuf = ut_params->op->sym->m_dst; 4326 if (ut_params->obuf) 4327 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4328 else 4329 ciphertext = plaintext; 4330 4331 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4332 4333 /* Validate obuf */ 4334 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4335 ciphertext, 4336 tdata->ciphertext.data, 4337 tdata->validDataLenInBits.len, 4338 "SNOW 3G Ciphertext data not as expected"); 4339 return 0; 4340 } 4341 4342 static int 4343 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata) 4344 { 4345 struct crypto_testsuite_params *ts_params = &testsuite_params; 4346 struct crypto_unittest_params *ut_params = &unittest_params; 4347 4348 int retval; 4349 unsigned int plaintext_pad_len; 4350 unsigned int plaintext_len; 4351 uint8_t buffer[10000]; 4352 const uint8_t *ciphertext; 4353 4354 struct rte_cryptodev_info dev_info; 4355 4356 /* Verify the capabilities */ 4357 struct rte_cryptodev_sym_capability_idx cap_idx; 4358 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4359 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4360 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4361 &cap_idx) == NULL) 4362 return TEST_SKIPPED; 4363 4364 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4365 return TEST_SKIPPED; 4366 4367 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4368 return TEST_SKIPPED; 4369 4370 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4371 4372 uint64_t feat_flags = dev_info.feature_flags; 4373 4374 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 4375 printf("Device doesn't support out-of-place scatter-gather " 4376 "in both input and output mbufs. " 4377 "Test Skipped.\n"); 4378 return TEST_SKIPPED; 4379 } 4380 4381 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4382 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4383 printf("Device does not support RAW data-path APIs.\n"); 4384 return -ENOTSUP; 4385 } 4386 4387 /* Create SNOW 3G session */ 4388 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4389 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4390 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4391 tdata->key.data, tdata->key.len, 4392 tdata->cipher_iv.len); 4393 if (retval < 0) 4394 return retval; 4395 4396 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4397 /* Append data which is padded to a multiple of */ 4398 /* the algorithms block size */ 4399 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4400 4401 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4402 plaintext_pad_len, 10, 0); 4403 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4404 plaintext_pad_len, 3, 0); 4405 4406 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4407 "Failed to allocate input buffer in mempool"); 4408 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4409 "Failed to allocate output buffer in mempool"); 4410 4411 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 4412 4413 /* Create SNOW 3G operation */ 4414 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4415 tdata->cipher_iv.len, 4416 tdata->validCipherLenInBits.len, 4417 0); 4418 if (retval < 0) 4419 return retval; 4420 4421 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4422 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4423 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4424 else 4425 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4426 ut_params->op); 4427 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4428 4429 ut_params->obuf = ut_params->op->sym->m_dst; 4430 if (ut_params->obuf) 4431 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4432 plaintext_len, buffer); 4433 else 4434 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4435 plaintext_len, buffer); 4436 4437 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4438 4439 /* Validate obuf */ 4440 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4441 ciphertext, 4442 tdata->ciphertext.data, 4443 tdata->validDataLenInBits.len, 4444 "SNOW 3G Ciphertext data not as expected"); 4445 4446 return 0; 4447 } 4448 4449 /* Shift right a buffer by "offset" bits, "offset" < 8 */ 4450 static void 4451 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) 4452 { 4453 uint8_t curr_byte, prev_byte; 4454 uint32_t length_in_bytes = ceil_byte_length(length + offset); 4455 uint8_t lower_byte_mask = (1 << offset) - 1; 4456 unsigned i; 4457 4458 prev_byte = buffer[0]; 4459 buffer[0] >>= offset; 4460 4461 for (i = 1; i < length_in_bytes; i++) { 4462 curr_byte = buffer[i]; 4463 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | 4464 (curr_byte >> offset); 4465 prev_byte = curr_byte; 4466 } 4467 } 4468 4469 static int 4470 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) 4471 { 4472 struct crypto_testsuite_params *ts_params = &testsuite_params; 4473 struct crypto_unittest_params *ut_params = &unittest_params; 4474 uint8_t *plaintext, *ciphertext; 4475 int retval; 4476 uint32_t plaintext_len; 4477 uint32_t plaintext_pad_len; 4478 uint8_t extra_offset = 4; 4479 uint8_t *expected_ciphertext_shifted; 4480 struct rte_cryptodev_info dev_info; 4481 4482 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4483 uint64_t feat_flags = dev_info.feature_flags; 4484 4485 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4486 ((tdata->validDataLenInBits.len % 8) != 0)) { 4487 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4488 return TEST_SKIPPED; 4489 } 4490 4491 /* Verify the capabilities */ 4492 struct rte_cryptodev_sym_capability_idx cap_idx; 4493 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4494 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4495 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4496 &cap_idx) == NULL) 4497 return TEST_SKIPPED; 4498 4499 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4500 return TEST_SKIPPED; 4501 4502 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4503 return TEST_SKIPPED; 4504 4505 /* Create SNOW 3G session */ 4506 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4507 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4508 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4509 tdata->key.data, tdata->key.len, 4510 tdata->cipher_iv.len); 4511 if (retval < 0) 4512 return retval; 4513 4514 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4515 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4516 4517 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4518 "Failed to allocate input buffer in mempool"); 4519 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4520 "Failed to allocate output buffer in mempool"); 4521 4522 /* Clear mbuf payload */ 4523 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4524 rte_pktmbuf_tailroom(ut_params->ibuf)); 4525 4526 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset); 4527 /* 4528 * Append data which is padded to a 4529 * multiple of the algorithms block size 4530 */ 4531 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4532 4533 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, 4534 plaintext_pad_len); 4535 4536 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4537 4538 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); 4539 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); 4540 4541 #ifdef RTE_APP_TEST_DEBUG 4542 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); 4543 #endif 4544 /* Create SNOW 3G operation */ 4545 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4546 tdata->cipher_iv.len, 4547 tdata->validCipherLenInBits.len, 4548 extra_offset); 4549 if (retval < 0) 4550 return retval; 4551 4552 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4553 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4554 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4555 else 4556 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4557 ut_params->op); 4558 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4559 4560 ut_params->obuf = ut_params->op->sym->m_dst; 4561 if (ut_params->obuf) 4562 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4563 else 4564 ciphertext = plaintext; 4565 4566 #ifdef RTE_APP_TEST_DEBUG 4567 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4568 #endif 4569 4570 expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8); 4571 4572 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, 4573 "failed to reserve memory for ciphertext shifted\n"); 4574 4575 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, 4576 ceil_byte_length(tdata->ciphertext.len)); 4577 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, 4578 extra_offset); 4579 /* Validate obuf */ 4580 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4581 ciphertext, 4582 expected_ciphertext_shifted, 4583 tdata->validDataLenInBits.len, 4584 extra_offset, 4585 "SNOW 3G Ciphertext data not as expected"); 4586 return 0; 4587 } 4588 4589 static int test_snow3g_decryption(const struct snow3g_test_data *tdata) 4590 { 4591 struct crypto_testsuite_params *ts_params = &testsuite_params; 4592 struct crypto_unittest_params *ut_params = &unittest_params; 4593 4594 int retval; 4595 4596 uint8_t *plaintext, *ciphertext; 4597 unsigned ciphertext_pad_len; 4598 unsigned ciphertext_len; 4599 struct rte_cryptodev_info dev_info; 4600 4601 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4602 uint64_t feat_flags = dev_info.feature_flags; 4603 4604 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4605 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4606 printf("Device doesn't support RAW data-path APIs.\n"); 4607 return TEST_SKIPPED; 4608 } 4609 4610 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4611 return TEST_SKIPPED; 4612 4613 /* Verify the capabilities */ 4614 struct rte_cryptodev_sym_capability_idx cap_idx; 4615 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4616 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4617 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4618 &cap_idx) == NULL) 4619 return TEST_SKIPPED; 4620 4621 /* Create SNOW 3G session */ 4622 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4623 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4624 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4625 tdata->key.data, tdata->key.len, 4626 tdata->cipher_iv.len); 4627 if (retval < 0) 4628 return retval; 4629 4630 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4631 4632 /* Clear mbuf payload */ 4633 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4634 rte_pktmbuf_tailroom(ut_params->ibuf)); 4635 4636 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4637 /* Append data which is padded to a multiple of */ 4638 /* the algorithms block size */ 4639 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4640 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4641 ciphertext_pad_len); 4642 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4643 4644 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4645 4646 /* Create SNOW 3G operation */ 4647 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4648 tdata->cipher_iv.len, 4649 tdata->validCipherLenInBits.len, 4650 tdata->cipher.offset_bits); 4651 if (retval < 0) 4652 return retval; 4653 4654 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4655 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4656 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4657 else 4658 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4659 ut_params->op); 4660 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4661 ut_params->obuf = ut_params->op->sym->m_dst; 4662 if (ut_params->obuf) 4663 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4664 else 4665 plaintext = ciphertext; 4666 4667 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4668 4669 /* Validate obuf */ 4670 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4671 tdata->plaintext.data, 4672 tdata->validDataLenInBits.len, 4673 "SNOW 3G Plaintext data not as expected"); 4674 return 0; 4675 } 4676 4677 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) 4678 { 4679 struct crypto_testsuite_params *ts_params = &testsuite_params; 4680 struct crypto_unittest_params *ut_params = &unittest_params; 4681 4682 int retval; 4683 4684 uint8_t *plaintext, *ciphertext; 4685 unsigned ciphertext_pad_len; 4686 unsigned ciphertext_len; 4687 struct rte_cryptodev_info dev_info; 4688 4689 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4690 uint64_t feat_flags = dev_info.feature_flags; 4691 4692 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4693 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4694 printf("Device does not support RAW data-path APIs.\n"); 4695 return -ENOTSUP; 4696 } 4697 /* Verify the capabilities */ 4698 struct rte_cryptodev_sym_capability_idx cap_idx; 4699 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4700 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4701 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4702 &cap_idx) == NULL) 4703 return TEST_SKIPPED; 4704 4705 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4706 return TEST_SKIPPED; 4707 4708 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4709 return TEST_SKIPPED; 4710 4711 /* Create SNOW 3G session */ 4712 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4713 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4714 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4715 tdata->key.data, tdata->key.len, 4716 tdata->cipher_iv.len); 4717 if (retval < 0) 4718 return retval; 4719 4720 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4721 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4722 4723 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4724 "Failed to allocate input buffer"); 4725 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4726 "Failed to allocate output buffer"); 4727 4728 /* Clear mbuf payload */ 4729 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4730 rte_pktmbuf_tailroom(ut_params->ibuf)); 4731 4732 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4733 rte_pktmbuf_tailroom(ut_params->obuf)); 4734 4735 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4736 /* Append data which is padded to a multiple of */ 4737 /* the algorithms block size */ 4738 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4739 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4740 ciphertext_pad_len); 4741 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4742 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4743 4744 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4745 4746 /* Create SNOW 3G operation */ 4747 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4748 tdata->cipher_iv.len, 4749 tdata->validCipherLenInBits.len, 4750 0); 4751 if (retval < 0) 4752 return retval; 4753 4754 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4755 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4756 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4757 else 4758 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4759 ut_params->op); 4760 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4761 ut_params->obuf = ut_params->op->sym->m_dst; 4762 if (ut_params->obuf) 4763 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4764 else 4765 plaintext = ciphertext; 4766 4767 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4768 4769 /* Validate obuf */ 4770 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4771 tdata->plaintext.data, 4772 tdata->validDataLenInBits.len, 4773 "SNOW 3G Plaintext data not as expected"); 4774 return 0; 4775 } 4776 4777 static int 4778 test_zuc_cipher_auth(const struct wireless_test_data *tdata) 4779 { 4780 struct crypto_testsuite_params *ts_params = &testsuite_params; 4781 struct crypto_unittest_params *ut_params = &unittest_params; 4782 4783 int retval; 4784 4785 uint8_t *plaintext, *ciphertext; 4786 unsigned int plaintext_pad_len; 4787 unsigned int plaintext_len; 4788 4789 struct rte_cryptodev_info dev_info; 4790 struct rte_cryptodev_sym_capability_idx cap_idx; 4791 4792 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4793 uint64_t feat_flags = dev_info.feature_flags; 4794 4795 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4796 ((tdata->validAuthLenInBits.len % 8 != 0) || 4797 (tdata->validDataLenInBits.len % 8 != 0))) { 4798 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4799 return TEST_SKIPPED; 4800 } 4801 4802 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4803 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4804 printf("Device doesn't support RAW data-path APIs.\n"); 4805 return TEST_SKIPPED; 4806 } 4807 4808 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4809 return TEST_SKIPPED; 4810 4811 /* Check if device supports ZUC EEA3 */ 4812 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4813 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 4814 4815 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4816 &cap_idx) == NULL) 4817 return TEST_SKIPPED; 4818 4819 /* Check if device supports ZUC EIA3 */ 4820 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4821 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 4822 4823 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4824 &cap_idx) == NULL) 4825 return TEST_SKIPPED; 4826 4827 /* Create ZUC session */ 4828 retval = create_zuc_cipher_auth_encrypt_generate_session( 4829 ts_params->valid_devs[0], 4830 tdata); 4831 if (retval != 0) 4832 return retval; 4833 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4834 4835 /* clear mbuf payload */ 4836 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4837 rte_pktmbuf_tailroom(ut_params->ibuf)); 4838 4839 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4840 /* Append data which is padded to a multiple of */ 4841 /* the algorithms block size */ 4842 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4843 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4844 plaintext_pad_len); 4845 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4846 4847 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4848 4849 /* Create ZUC operation */ 4850 retval = create_zuc_cipher_hash_generate_operation(tdata); 4851 if (retval < 0) 4852 return retval; 4853 4854 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4855 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4856 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4857 else 4858 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4859 ut_params->op); 4860 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4861 ut_params->obuf = ut_params->op->sym->m_src; 4862 if (ut_params->obuf) 4863 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4864 else 4865 ciphertext = plaintext; 4866 4867 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4868 /* Validate obuf */ 4869 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4870 ciphertext, 4871 tdata->ciphertext.data, 4872 tdata->validDataLenInBits.len, 4873 "ZUC Ciphertext data not as expected"); 4874 4875 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4876 + plaintext_pad_len; 4877 4878 /* Validate obuf */ 4879 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4880 ut_params->digest, 4881 tdata->digest.data, 4882 4, 4883 "ZUC Generated auth tag not as expected"); 4884 return 0; 4885 } 4886 4887 static int 4888 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) 4889 { 4890 struct crypto_testsuite_params *ts_params = &testsuite_params; 4891 struct crypto_unittest_params *ut_params = &unittest_params; 4892 4893 int retval; 4894 4895 uint8_t *plaintext, *ciphertext; 4896 unsigned plaintext_pad_len; 4897 unsigned plaintext_len; 4898 struct rte_cryptodev_info dev_info; 4899 4900 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4901 uint64_t feat_flags = dev_info.feature_flags; 4902 4903 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4904 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4905 printf("Device doesn't support RAW data-path APIs.\n"); 4906 return TEST_SKIPPED; 4907 } 4908 4909 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4910 return TEST_SKIPPED; 4911 4912 /* Verify the capabilities */ 4913 struct rte_cryptodev_sym_capability_idx cap_idx; 4914 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4915 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4916 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4917 &cap_idx) == NULL) 4918 return TEST_SKIPPED; 4919 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4920 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4921 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4922 &cap_idx) == NULL) 4923 return TEST_SKIPPED; 4924 4925 /* Create SNOW 3G session */ 4926 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0], 4927 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4928 RTE_CRYPTO_AUTH_OP_GENERATE, 4929 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4930 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4931 tdata->key.data, tdata->key.len, 4932 tdata->auth_iv.len, tdata->digest.len, 4933 tdata->cipher_iv.len); 4934 if (retval != 0) 4935 return retval; 4936 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4937 4938 /* clear mbuf payload */ 4939 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4940 rte_pktmbuf_tailroom(ut_params->ibuf)); 4941 4942 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4943 /* Append data which is padded to a multiple of */ 4944 /* the algorithms block size */ 4945 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4946 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4947 plaintext_pad_len); 4948 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4949 4950 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4951 4952 /* Create SNOW 3G operation */ 4953 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 4954 tdata->digest.len, tdata->auth_iv.data, 4955 tdata->auth_iv.len, 4956 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 4957 tdata->cipher_iv.data, tdata->cipher_iv.len, 4958 tdata->validCipherLenInBits.len, 4959 0, 4960 tdata->validAuthLenInBits.len, 4961 0 4962 ); 4963 if (retval < 0) 4964 return retval; 4965 4966 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4967 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4968 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4969 else 4970 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4971 ut_params->op); 4972 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4973 ut_params->obuf = ut_params->op->sym->m_src; 4974 if (ut_params->obuf) 4975 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4976 else 4977 ciphertext = plaintext; 4978 4979 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4980 /* Validate obuf */ 4981 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4982 ciphertext, 4983 tdata->ciphertext.data, 4984 tdata->validDataLenInBits.len, 4985 "SNOW 3G Ciphertext data not as expected"); 4986 4987 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4988 + plaintext_pad_len; 4989 4990 /* Validate obuf */ 4991 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4992 ut_params->digest, 4993 tdata->digest.data, 4994 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4995 "SNOW 3G Generated auth tag not as expected"); 4996 return 0; 4997 } 4998 4999 static int 5000 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata, 5001 uint8_t op_mode, uint8_t verify) 5002 { 5003 struct crypto_testsuite_params *ts_params = &testsuite_params; 5004 struct crypto_unittest_params *ut_params = &unittest_params; 5005 5006 int retval; 5007 5008 uint8_t *plaintext = NULL, *ciphertext = NULL; 5009 unsigned int plaintext_pad_len; 5010 unsigned int plaintext_len; 5011 unsigned int ciphertext_pad_len; 5012 unsigned int ciphertext_len; 5013 5014 struct rte_cryptodev_info dev_info; 5015 5016 /* Verify the capabilities */ 5017 struct rte_cryptodev_sym_capability_idx cap_idx; 5018 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5019 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5020 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5021 &cap_idx) == NULL) 5022 return TEST_SKIPPED; 5023 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5024 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5025 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5026 &cap_idx) == NULL) 5027 return TEST_SKIPPED; 5028 5029 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5030 return TEST_SKIPPED; 5031 5032 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5033 5034 uint64_t feat_flags = dev_info.feature_flags; 5035 5036 if (op_mode == OUT_OF_PLACE) { 5037 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5038 printf("Device doesn't support digest encrypted.\n"); 5039 return TEST_SKIPPED; 5040 } 5041 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5042 return TEST_SKIPPED; 5043 } 5044 5045 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5046 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5047 printf("Device doesn't support RAW data-path APIs.\n"); 5048 return TEST_SKIPPED; 5049 } 5050 5051 /* Create SNOW 3G session */ 5052 retval = create_wireless_algo_auth_cipher_session( 5053 ts_params->valid_devs[0], 5054 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5055 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5056 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5057 : RTE_CRYPTO_AUTH_OP_GENERATE), 5058 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5059 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5060 tdata->key.data, tdata->key.len, 5061 tdata->auth_iv.len, tdata->digest.len, 5062 tdata->cipher_iv.len); 5063 if (retval != 0) 5064 return retval; 5065 5066 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5067 if (op_mode == OUT_OF_PLACE) 5068 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5069 5070 /* clear mbuf payload */ 5071 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5072 rte_pktmbuf_tailroom(ut_params->ibuf)); 5073 if (op_mode == OUT_OF_PLACE) 5074 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5075 rte_pktmbuf_tailroom(ut_params->obuf)); 5076 5077 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5078 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5079 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5080 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5081 5082 if (verify) { 5083 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5084 ciphertext_pad_len); 5085 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5086 if (op_mode == OUT_OF_PLACE) 5087 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5088 debug_hexdump(stdout, "ciphertext:", ciphertext, 5089 ciphertext_len); 5090 } else { 5091 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5092 plaintext_pad_len); 5093 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5094 if (op_mode == OUT_OF_PLACE) 5095 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5096 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5097 } 5098 5099 /* Create SNOW 3G operation */ 5100 retval = create_wireless_algo_auth_cipher_operation( 5101 tdata->digest.data, tdata->digest.len, 5102 tdata->cipher_iv.data, tdata->cipher_iv.len, 5103 tdata->auth_iv.data, tdata->auth_iv.len, 5104 (tdata->digest.offset_bytes == 0 ? 5105 (verify ? ciphertext_pad_len : plaintext_pad_len) 5106 : tdata->digest.offset_bytes), 5107 tdata->validCipherLenInBits.len, 5108 tdata->cipher.offset_bits, 5109 tdata->validAuthLenInBits.len, 5110 tdata->auth.offset_bits, 5111 op_mode, 0, verify); 5112 5113 if (retval < 0) 5114 return retval; 5115 5116 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5117 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5118 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5119 else 5120 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5121 ut_params->op); 5122 5123 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5124 5125 ut_params->obuf = (op_mode == IN_PLACE ? 5126 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5127 5128 if (verify) { 5129 if (ut_params->obuf) 5130 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5131 uint8_t *); 5132 else 5133 plaintext = ciphertext + 5134 (tdata->cipher.offset_bits >> 3); 5135 5136 debug_hexdump(stdout, "plaintext:", plaintext, 5137 (tdata->plaintext.len >> 3) - tdata->digest.len); 5138 debug_hexdump(stdout, "plaintext expected:", 5139 tdata->plaintext.data, 5140 (tdata->plaintext.len >> 3) - tdata->digest.len); 5141 } else { 5142 if (ut_params->obuf) 5143 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5144 uint8_t *); 5145 else 5146 ciphertext = plaintext; 5147 5148 debug_hexdump(stdout, "ciphertext:", ciphertext, 5149 ciphertext_len); 5150 debug_hexdump(stdout, "ciphertext expected:", 5151 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5152 5153 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5154 + (tdata->digest.offset_bytes == 0 ? 5155 plaintext_pad_len : tdata->digest.offset_bytes); 5156 5157 debug_hexdump(stdout, "digest:", ut_params->digest, 5158 tdata->digest.len); 5159 debug_hexdump(stdout, "digest expected:", tdata->digest.data, 5160 tdata->digest.len); 5161 } 5162 5163 /* Validate obuf */ 5164 if (verify) { 5165 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5166 plaintext, 5167 tdata->plaintext.data, 5168 (tdata->plaintext.len - tdata->cipher.offset_bits - 5169 (tdata->digest.len << 3)), 5170 tdata->cipher.offset_bits, 5171 "SNOW 3G Plaintext data not as expected"); 5172 } else { 5173 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5174 ciphertext, 5175 tdata->ciphertext.data, 5176 (tdata->validDataLenInBits.len - 5177 tdata->cipher.offset_bits), 5178 tdata->cipher.offset_bits, 5179 "SNOW 3G Ciphertext data not as expected"); 5180 5181 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5182 ut_params->digest, 5183 tdata->digest.data, 5184 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5185 "SNOW 3G Generated auth tag not as expected"); 5186 } 5187 return 0; 5188 } 5189 5190 static int 5191 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata, 5192 uint8_t op_mode, uint8_t verify) 5193 { 5194 struct crypto_testsuite_params *ts_params = &testsuite_params; 5195 struct crypto_unittest_params *ut_params = &unittest_params; 5196 5197 int retval; 5198 5199 const uint8_t *plaintext = NULL; 5200 const uint8_t *ciphertext = NULL; 5201 const uint8_t *digest = NULL; 5202 unsigned int plaintext_pad_len; 5203 unsigned int plaintext_len; 5204 unsigned int ciphertext_pad_len; 5205 unsigned int ciphertext_len; 5206 uint8_t buffer[10000]; 5207 uint8_t digest_buffer[10000]; 5208 5209 struct rte_cryptodev_info dev_info; 5210 5211 /* Verify the capabilities */ 5212 struct rte_cryptodev_sym_capability_idx cap_idx; 5213 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5214 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5215 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5216 &cap_idx) == NULL) 5217 return TEST_SKIPPED; 5218 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5219 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5220 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5221 &cap_idx) == NULL) 5222 return TEST_SKIPPED; 5223 5224 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5225 return TEST_SKIPPED; 5226 5227 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5228 5229 uint64_t feat_flags = dev_info.feature_flags; 5230 5231 if (op_mode == IN_PLACE) { 5232 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5233 printf("Device doesn't support in-place scatter-gather " 5234 "in both input and output mbufs.\n"); 5235 return TEST_SKIPPED; 5236 } 5237 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5238 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5239 printf("Device doesn't support RAW data-path APIs.\n"); 5240 return TEST_SKIPPED; 5241 } 5242 } else { 5243 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5244 return TEST_SKIPPED; 5245 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5246 printf("Device doesn't support out-of-place scatter-gather " 5247 "in both input and output mbufs.\n"); 5248 return TEST_SKIPPED; 5249 } 5250 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5251 printf("Device doesn't support digest encrypted.\n"); 5252 return TEST_SKIPPED; 5253 } 5254 } 5255 5256 /* Create SNOW 3G session */ 5257 retval = create_wireless_algo_auth_cipher_session( 5258 ts_params->valid_devs[0], 5259 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5260 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5261 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5262 : RTE_CRYPTO_AUTH_OP_GENERATE), 5263 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5264 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5265 tdata->key.data, tdata->key.len, 5266 tdata->auth_iv.len, tdata->digest.len, 5267 tdata->cipher_iv.len); 5268 5269 if (retval != 0) 5270 return retval; 5271 5272 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5273 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5274 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5275 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5276 5277 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5278 plaintext_pad_len, 15, 0); 5279 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5280 "Failed to allocate input buffer in mempool"); 5281 5282 if (op_mode == OUT_OF_PLACE) { 5283 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5284 plaintext_pad_len, 15, 0); 5285 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5286 "Failed to allocate output buffer in mempool"); 5287 } 5288 5289 if (verify) { 5290 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5291 tdata->ciphertext.data); 5292 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5293 ciphertext_len, buffer); 5294 debug_hexdump(stdout, "ciphertext:", ciphertext, 5295 ciphertext_len); 5296 } else { 5297 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5298 tdata->plaintext.data); 5299 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5300 plaintext_len, buffer); 5301 debug_hexdump(stdout, "plaintext:", plaintext, 5302 plaintext_len); 5303 } 5304 memset(buffer, 0, sizeof(buffer)); 5305 5306 /* Create SNOW 3G operation */ 5307 retval = create_wireless_algo_auth_cipher_operation( 5308 tdata->digest.data, tdata->digest.len, 5309 tdata->cipher_iv.data, tdata->cipher_iv.len, 5310 tdata->auth_iv.data, tdata->auth_iv.len, 5311 (tdata->digest.offset_bytes == 0 ? 5312 (verify ? ciphertext_pad_len : plaintext_pad_len) 5313 : tdata->digest.offset_bytes), 5314 tdata->validCipherLenInBits.len, 5315 tdata->cipher.offset_bits, 5316 tdata->validAuthLenInBits.len, 5317 tdata->auth.offset_bits, 5318 op_mode, 1, verify); 5319 5320 if (retval < 0) 5321 return retval; 5322 5323 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5324 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5325 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5326 else 5327 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5328 ut_params->op); 5329 5330 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5331 5332 ut_params->obuf = (op_mode == IN_PLACE ? 5333 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5334 5335 if (verify) { 5336 if (ut_params->obuf) 5337 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5338 plaintext_len, buffer); 5339 else 5340 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5341 plaintext_len, buffer); 5342 5343 debug_hexdump(stdout, "plaintext:", plaintext, 5344 (tdata->plaintext.len >> 3) - tdata->digest.len); 5345 debug_hexdump(stdout, "plaintext expected:", 5346 tdata->plaintext.data, 5347 (tdata->plaintext.len >> 3) - tdata->digest.len); 5348 } else { 5349 if (ut_params->obuf) 5350 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5351 ciphertext_len, buffer); 5352 else 5353 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5354 ciphertext_len, buffer); 5355 5356 debug_hexdump(stdout, "ciphertext:", ciphertext, 5357 ciphertext_len); 5358 debug_hexdump(stdout, "ciphertext expected:", 5359 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5360 5361 if (ut_params->obuf) 5362 digest = rte_pktmbuf_read(ut_params->obuf, 5363 (tdata->digest.offset_bytes == 0 ? 5364 plaintext_pad_len : tdata->digest.offset_bytes), 5365 tdata->digest.len, digest_buffer); 5366 else 5367 digest = rte_pktmbuf_read(ut_params->ibuf, 5368 (tdata->digest.offset_bytes == 0 ? 5369 plaintext_pad_len : tdata->digest.offset_bytes), 5370 tdata->digest.len, digest_buffer); 5371 5372 debug_hexdump(stdout, "digest:", digest, 5373 tdata->digest.len); 5374 debug_hexdump(stdout, "digest expected:", 5375 tdata->digest.data, tdata->digest.len); 5376 } 5377 5378 /* Validate obuf */ 5379 if (verify) { 5380 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5381 plaintext, 5382 tdata->plaintext.data, 5383 (tdata->plaintext.len - tdata->cipher.offset_bits - 5384 (tdata->digest.len << 3)), 5385 tdata->cipher.offset_bits, 5386 "SNOW 3G Plaintext data not as expected"); 5387 } else { 5388 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5389 ciphertext, 5390 tdata->ciphertext.data, 5391 (tdata->validDataLenInBits.len - 5392 tdata->cipher.offset_bits), 5393 tdata->cipher.offset_bits, 5394 "SNOW 3G Ciphertext data not as expected"); 5395 5396 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5397 digest, 5398 tdata->digest.data, 5399 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5400 "SNOW 3G Generated auth tag not as expected"); 5401 } 5402 return 0; 5403 } 5404 5405 static int 5406 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata, 5407 uint8_t op_mode, uint8_t verify) 5408 { 5409 struct crypto_testsuite_params *ts_params = &testsuite_params; 5410 struct crypto_unittest_params *ut_params = &unittest_params; 5411 5412 int retval; 5413 5414 uint8_t *plaintext = NULL, *ciphertext = NULL; 5415 unsigned int plaintext_pad_len; 5416 unsigned int plaintext_len; 5417 unsigned int ciphertext_pad_len; 5418 unsigned int ciphertext_len; 5419 5420 struct rte_cryptodev_info dev_info; 5421 5422 /* Verify the capabilities */ 5423 struct rte_cryptodev_sym_capability_idx cap_idx; 5424 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5425 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5426 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5427 &cap_idx) == NULL) 5428 return TEST_SKIPPED; 5429 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5430 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5431 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5432 &cap_idx) == NULL) 5433 return TEST_SKIPPED; 5434 5435 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5436 5437 uint64_t feat_flags = dev_info.feature_flags; 5438 5439 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5440 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5441 printf("Device doesn't support RAW data-path APIs.\n"); 5442 return TEST_SKIPPED; 5443 } 5444 5445 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5446 return TEST_SKIPPED; 5447 5448 if (op_mode == OUT_OF_PLACE) { 5449 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5450 return TEST_SKIPPED; 5451 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5452 printf("Device doesn't support digest encrypted.\n"); 5453 return TEST_SKIPPED; 5454 } 5455 } 5456 5457 /* Create KASUMI session */ 5458 retval = create_wireless_algo_auth_cipher_session( 5459 ts_params->valid_devs[0], 5460 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5461 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5462 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5463 : RTE_CRYPTO_AUTH_OP_GENERATE), 5464 RTE_CRYPTO_AUTH_KASUMI_F9, 5465 RTE_CRYPTO_CIPHER_KASUMI_F8, 5466 tdata->key.data, tdata->key.len, 5467 0, tdata->digest.len, 5468 tdata->cipher_iv.len); 5469 5470 if (retval != 0) 5471 return retval; 5472 5473 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5474 if (op_mode == OUT_OF_PLACE) 5475 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5476 5477 /* clear mbuf payload */ 5478 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5479 rte_pktmbuf_tailroom(ut_params->ibuf)); 5480 if (op_mode == OUT_OF_PLACE) 5481 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5482 rte_pktmbuf_tailroom(ut_params->obuf)); 5483 5484 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5485 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5486 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5487 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5488 5489 if (verify) { 5490 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5491 ciphertext_pad_len); 5492 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5493 if (op_mode == OUT_OF_PLACE) 5494 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5495 debug_hexdump(stdout, "ciphertext:", ciphertext, 5496 ciphertext_len); 5497 } else { 5498 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5499 plaintext_pad_len); 5500 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5501 if (op_mode == OUT_OF_PLACE) 5502 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5503 debug_hexdump(stdout, "plaintext:", plaintext, 5504 plaintext_len); 5505 } 5506 5507 /* Create KASUMI operation */ 5508 retval = create_wireless_algo_auth_cipher_operation( 5509 tdata->digest.data, tdata->digest.len, 5510 tdata->cipher_iv.data, tdata->cipher_iv.len, 5511 NULL, 0, 5512 (tdata->digest.offset_bytes == 0 ? 5513 (verify ? ciphertext_pad_len : plaintext_pad_len) 5514 : tdata->digest.offset_bytes), 5515 tdata->validCipherLenInBits.len, 5516 tdata->validCipherOffsetInBits.len, 5517 tdata->validAuthLenInBits.len, 5518 0, 5519 op_mode, 0, verify); 5520 5521 if (retval < 0) 5522 return retval; 5523 5524 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5525 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5526 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5527 else 5528 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5529 ut_params->op); 5530 5531 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5532 5533 ut_params->obuf = (op_mode == IN_PLACE ? 5534 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5535 5536 5537 if (verify) { 5538 if (ut_params->obuf) 5539 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5540 uint8_t *); 5541 else 5542 plaintext = ciphertext; 5543 5544 debug_hexdump(stdout, "plaintext:", plaintext, 5545 (tdata->plaintext.len >> 3) - tdata->digest.len); 5546 debug_hexdump(stdout, "plaintext expected:", 5547 tdata->plaintext.data, 5548 (tdata->plaintext.len >> 3) - tdata->digest.len); 5549 } else { 5550 if (ut_params->obuf) 5551 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5552 uint8_t *); 5553 else 5554 ciphertext = plaintext; 5555 5556 debug_hexdump(stdout, "ciphertext:", ciphertext, 5557 ciphertext_len); 5558 debug_hexdump(stdout, "ciphertext expected:", 5559 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5560 5561 ut_params->digest = rte_pktmbuf_mtod( 5562 ut_params->obuf, uint8_t *) + 5563 (tdata->digest.offset_bytes == 0 ? 5564 plaintext_pad_len : tdata->digest.offset_bytes); 5565 5566 debug_hexdump(stdout, "digest:", ut_params->digest, 5567 tdata->digest.len); 5568 debug_hexdump(stdout, "digest expected:", 5569 tdata->digest.data, tdata->digest.len); 5570 } 5571 5572 /* Validate obuf */ 5573 if (verify) { 5574 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5575 plaintext, 5576 tdata->plaintext.data, 5577 tdata->plaintext.len >> 3, 5578 "KASUMI Plaintext data not as expected"); 5579 } else { 5580 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5581 ciphertext, 5582 tdata->ciphertext.data, 5583 tdata->ciphertext.len >> 3, 5584 "KASUMI Ciphertext data not as expected"); 5585 5586 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5587 ut_params->digest, 5588 tdata->digest.data, 5589 DIGEST_BYTE_LENGTH_KASUMI_F9, 5590 "KASUMI Generated auth tag not as expected"); 5591 } 5592 return 0; 5593 } 5594 5595 static int 5596 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata, 5597 uint8_t op_mode, uint8_t verify) 5598 { 5599 struct crypto_testsuite_params *ts_params = &testsuite_params; 5600 struct crypto_unittest_params *ut_params = &unittest_params; 5601 5602 int retval; 5603 5604 const uint8_t *plaintext = NULL; 5605 const uint8_t *ciphertext = NULL; 5606 const uint8_t *digest = NULL; 5607 unsigned int plaintext_pad_len; 5608 unsigned int plaintext_len; 5609 unsigned int ciphertext_pad_len; 5610 unsigned int ciphertext_len; 5611 uint8_t buffer[10000]; 5612 uint8_t digest_buffer[10000]; 5613 5614 struct rte_cryptodev_info dev_info; 5615 5616 /* Verify the capabilities */ 5617 struct rte_cryptodev_sym_capability_idx cap_idx; 5618 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5619 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5620 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5621 &cap_idx) == NULL) 5622 return TEST_SKIPPED; 5623 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5624 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5625 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5626 &cap_idx) == NULL) 5627 return TEST_SKIPPED; 5628 5629 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5630 return TEST_SKIPPED; 5631 5632 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5633 5634 uint64_t feat_flags = dev_info.feature_flags; 5635 5636 if (op_mode == IN_PLACE) { 5637 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5638 printf("Device doesn't support in-place scatter-gather " 5639 "in both input and output mbufs.\n"); 5640 return TEST_SKIPPED; 5641 } 5642 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5643 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5644 printf("Device doesn't support RAW data-path APIs.\n"); 5645 return TEST_SKIPPED; 5646 } 5647 } else { 5648 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5649 return TEST_SKIPPED; 5650 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5651 printf("Device doesn't support out-of-place scatter-gather " 5652 "in both input and output mbufs.\n"); 5653 return TEST_SKIPPED; 5654 } 5655 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5656 printf("Device doesn't support digest encrypted.\n"); 5657 return TEST_SKIPPED; 5658 } 5659 } 5660 5661 /* Create KASUMI session */ 5662 retval = create_wireless_algo_auth_cipher_session( 5663 ts_params->valid_devs[0], 5664 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5665 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5666 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5667 : RTE_CRYPTO_AUTH_OP_GENERATE), 5668 RTE_CRYPTO_AUTH_KASUMI_F9, 5669 RTE_CRYPTO_CIPHER_KASUMI_F8, 5670 tdata->key.data, tdata->key.len, 5671 0, tdata->digest.len, 5672 tdata->cipher_iv.len); 5673 5674 if (retval != 0) 5675 return retval; 5676 5677 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5678 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5679 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5680 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5681 5682 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5683 plaintext_pad_len, 15, 0); 5684 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5685 "Failed to allocate input buffer in mempool"); 5686 5687 if (op_mode == OUT_OF_PLACE) { 5688 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5689 plaintext_pad_len, 15, 0); 5690 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5691 "Failed to allocate output buffer in mempool"); 5692 } 5693 5694 if (verify) { 5695 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5696 tdata->ciphertext.data); 5697 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5698 ciphertext_len, buffer); 5699 debug_hexdump(stdout, "ciphertext:", ciphertext, 5700 ciphertext_len); 5701 } else { 5702 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5703 tdata->plaintext.data); 5704 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5705 plaintext_len, buffer); 5706 debug_hexdump(stdout, "plaintext:", plaintext, 5707 plaintext_len); 5708 } 5709 memset(buffer, 0, sizeof(buffer)); 5710 5711 /* Create KASUMI operation */ 5712 retval = create_wireless_algo_auth_cipher_operation( 5713 tdata->digest.data, tdata->digest.len, 5714 tdata->cipher_iv.data, tdata->cipher_iv.len, 5715 NULL, 0, 5716 (tdata->digest.offset_bytes == 0 ? 5717 (verify ? ciphertext_pad_len : plaintext_pad_len) 5718 : tdata->digest.offset_bytes), 5719 tdata->validCipherLenInBits.len, 5720 tdata->validCipherOffsetInBits.len, 5721 tdata->validAuthLenInBits.len, 5722 0, 5723 op_mode, 1, verify); 5724 5725 if (retval < 0) 5726 return retval; 5727 5728 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5729 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5730 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5731 else 5732 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5733 ut_params->op); 5734 5735 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5736 5737 ut_params->obuf = (op_mode == IN_PLACE ? 5738 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5739 5740 if (verify) { 5741 if (ut_params->obuf) 5742 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5743 plaintext_len, buffer); 5744 else 5745 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5746 plaintext_len, buffer); 5747 5748 debug_hexdump(stdout, "plaintext:", plaintext, 5749 (tdata->plaintext.len >> 3) - tdata->digest.len); 5750 debug_hexdump(stdout, "plaintext expected:", 5751 tdata->plaintext.data, 5752 (tdata->plaintext.len >> 3) - tdata->digest.len); 5753 } else { 5754 if (ut_params->obuf) 5755 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5756 ciphertext_len, buffer); 5757 else 5758 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5759 ciphertext_len, buffer); 5760 5761 debug_hexdump(stdout, "ciphertext:", ciphertext, 5762 ciphertext_len); 5763 debug_hexdump(stdout, "ciphertext expected:", 5764 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5765 5766 if (ut_params->obuf) 5767 digest = rte_pktmbuf_read(ut_params->obuf, 5768 (tdata->digest.offset_bytes == 0 ? 5769 plaintext_pad_len : tdata->digest.offset_bytes), 5770 tdata->digest.len, digest_buffer); 5771 else 5772 digest = rte_pktmbuf_read(ut_params->ibuf, 5773 (tdata->digest.offset_bytes == 0 ? 5774 plaintext_pad_len : tdata->digest.offset_bytes), 5775 tdata->digest.len, digest_buffer); 5776 5777 debug_hexdump(stdout, "digest:", digest, 5778 tdata->digest.len); 5779 debug_hexdump(stdout, "digest expected:", 5780 tdata->digest.data, tdata->digest.len); 5781 } 5782 5783 /* Validate obuf */ 5784 if (verify) { 5785 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5786 plaintext, 5787 tdata->plaintext.data, 5788 tdata->plaintext.len >> 3, 5789 "KASUMI Plaintext data not as expected"); 5790 } else { 5791 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5792 ciphertext, 5793 tdata->ciphertext.data, 5794 tdata->validDataLenInBits.len, 5795 "KASUMI Ciphertext data not as expected"); 5796 5797 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5798 digest, 5799 tdata->digest.data, 5800 DIGEST_BYTE_LENGTH_KASUMI_F9, 5801 "KASUMI Generated auth tag not as expected"); 5802 } 5803 return 0; 5804 } 5805 5806 static int 5807 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata) 5808 { 5809 struct crypto_testsuite_params *ts_params = &testsuite_params; 5810 struct crypto_unittest_params *ut_params = &unittest_params; 5811 5812 int retval; 5813 5814 uint8_t *plaintext, *ciphertext; 5815 unsigned plaintext_pad_len; 5816 unsigned plaintext_len; 5817 struct rte_cryptodev_info dev_info; 5818 5819 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5820 uint64_t feat_flags = dev_info.feature_flags; 5821 5822 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5823 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5824 printf("Device doesn't support RAW data-path APIs.\n"); 5825 return TEST_SKIPPED; 5826 } 5827 5828 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5829 return TEST_SKIPPED; 5830 5831 /* Verify the capabilities */ 5832 struct rte_cryptodev_sym_capability_idx cap_idx; 5833 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5834 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5835 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5836 &cap_idx) == NULL) 5837 return TEST_SKIPPED; 5838 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5839 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5840 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5841 &cap_idx) == NULL) 5842 return TEST_SKIPPED; 5843 5844 /* Create KASUMI session */ 5845 retval = create_wireless_algo_cipher_auth_session( 5846 ts_params->valid_devs[0], 5847 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5848 RTE_CRYPTO_AUTH_OP_GENERATE, 5849 RTE_CRYPTO_AUTH_KASUMI_F9, 5850 RTE_CRYPTO_CIPHER_KASUMI_F8, 5851 tdata->key.data, tdata->key.len, 5852 0, tdata->digest.len, 5853 tdata->cipher_iv.len); 5854 if (retval != 0) 5855 return retval; 5856 5857 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5858 5859 /* clear mbuf payload */ 5860 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5861 rte_pktmbuf_tailroom(ut_params->ibuf)); 5862 5863 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5864 /* Append data which is padded to a multiple of */ 5865 /* the algorithms block size */ 5866 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5867 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5868 plaintext_pad_len); 5869 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5870 5871 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5872 5873 /* Create KASUMI operation */ 5874 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 5875 tdata->digest.len, NULL, 0, 5876 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5877 tdata->cipher_iv.data, tdata->cipher_iv.len, 5878 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 5879 tdata->validCipherOffsetInBits.len, 5880 tdata->validAuthLenInBits.len, 5881 0 5882 ); 5883 if (retval < 0) 5884 return retval; 5885 5886 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5887 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5888 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5889 else 5890 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5891 ut_params->op); 5892 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5893 5894 if (ut_params->op->sym->m_dst) 5895 ut_params->obuf = ut_params->op->sym->m_dst; 5896 else 5897 ut_params->obuf = ut_params->op->sym->m_src; 5898 5899 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 5900 tdata->validCipherOffsetInBits.len >> 3); 5901 5902 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5903 + plaintext_pad_len; 5904 5905 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 5906 (tdata->validCipherOffsetInBits.len >> 3); 5907 /* Validate obuf */ 5908 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5909 ciphertext, 5910 reference_ciphertext, 5911 tdata->validCipherLenInBits.len, 5912 "KASUMI Ciphertext data not as expected"); 5913 5914 /* Validate obuf */ 5915 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5916 ut_params->digest, 5917 tdata->digest.data, 5918 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5919 "KASUMI Generated auth tag not as expected"); 5920 return 0; 5921 } 5922 5923 static int 5924 check_cipher_capability(const struct crypto_testsuite_params *ts_params, 5925 const enum rte_crypto_cipher_algorithm cipher_algo, 5926 const uint16_t key_size, const uint16_t iv_size) 5927 { 5928 struct rte_cryptodev_sym_capability_idx cap_idx; 5929 const struct rte_cryptodev_symmetric_capability *cap; 5930 5931 /* Check if device supports the algorithm */ 5932 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5933 cap_idx.algo.cipher = cipher_algo; 5934 5935 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5936 &cap_idx); 5937 5938 if (cap == NULL) 5939 return -1; 5940 5941 /* Check if device supports key size and IV size */ 5942 if (rte_cryptodev_sym_capability_check_cipher(cap, key_size, 5943 iv_size) < 0) { 5944 return -1; 5945 } 5946 5947 return 0; 5948 } 5949 5950 static int 5951 check_auth_capability(const struct crypto_testsuite_params *ts_params, 5952 const enum rte_crypto_auth_algorithm auth_algo, 5953 const uint16_t key_size, const uint16_t iv_size, 5954 const uint16_t tag_size) 5955 { 5956 struct rte_cryptodev_sym_capability_idx cap_idx; 5957 const struct rte_cryptodev_symmetric_capability *cap; 5958 5959 /* Check if device supports the algorithm */ 5960 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5961 cap_idx.algo.auth = auth_algo; 5962 5963 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5964 &cap_idx); 5965 5966 if (cap == NULL) 5967 return -1; 5968 5969 /* Check if device supports key size and IV size */ 5970 if (rte_cryptodev_sym_capability_check_auth(cap, key_size, 5971 tag_size, iv_size) < 0) { 5972 return -1; 5973 } 5974 5975 return 0; 5976 } 5977 5978 static int 5979 test_zuc_encryption(const struct wireless_test_data *tdata) 5980 { 5981 struct crypto_testsuite_params *ts_params = &testsuite_params; 5982 struct crypto_unittest_params *ut_params = &unittest_params; 5983 5984 int retval; 5985 uint8_t *plaintext, *ciphertext; 5986 unsigned plaintext_pad_len; 5987 unsigned plaintext_len; 5988 struct rte_cryptodev_info dev_info; 5989 5990 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5991 uint64_t feat_flags = dev_info.feature_flags; 5992 5993 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5994 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5995 printf("Device doesn't support RAW data-path APIs.\n"); 5996 return TEST_SKIPPED; 5997 } 5998 5999 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6000 return TEST_SKIPPED; 6001 6002 /* Check if device supports ZUC EEA3 */ 6003 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6004 tdata->key.len, tdata->cipher_iv.len) < 0) 6005 return TEST_SKIPPED; 6006 6007 /* Create ZUC session */ 6008 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 6009 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6010 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6011 tdata->key.data, tdata->key.len, 6012 tdata->cipher_iv.len); 6013 if (retval != 0) 6014 return retval; 6015 6016 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6017 6018 /* Clear mbuf payload */ 6019 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6020 rte_pktmbuf_tailroom(ut_params->ibuf)); 6021 6022 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6023 /* Append data which is padded to a multiple */ 6024 /* of the algorithms block size */ 6025 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6026 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6027 plaintext_pad_len); 6028 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6029 6030 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6031 6032 /* Create ZUC operation */ 6033 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6034 tdata->cipher_iv.len, 6035 tdata->plaintext.len, 6036 tdata->validCipherOffsetInBits.len); 6037 if (retval < 0) 6038 return retval; 6039 6040 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6041 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6042 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 6043 else 6044 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6045 ut_params->op); 6046 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6047 6048 ut_params->obuf = ut_params->op->sym->m_dst; 6049 if (ut_params->obuf) 6050 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 6051 else 6052 ciphertext = plaintext; 6053 6054 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6055 6056 /* Validate obuf */ 6057 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6058 ciphertext, 6059 tdata->ciphertext.data, 6060 tdata->validCipherLenInBits.len, 6061 "ZUC Ciphertext data not as expected"); 6062 return 0; 6063 } 6064 6065 static int 6066 test_zuc_encryption_sgl(const struct wireless_test_data *tdata) 6067 { 6068 struct crypto_testsuite_params *ts_params = &testsuite_params; 6069 struct crypto_unittest_params *ut_params = &unittest_params; 6070 6071 int retval; 6072 6073 unsigned int plaintext_pad_len; 6074 unsigned int plaintext_len; 6075 const uint8_t *ciphertext; 6076 uint8_t ciphertext_buffer[2048]; 6077 struct rte_cryptodev_info dev_info; 6078 6079 /* Check if device supports ZUC EEA3 */ 6080 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6081 tdata->key.len, tdata->cipher_iv.len) < 0) 6082 return TEST_SKIPPED; 6083 6084 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6085 return TEST_SKIPPED; 6086 6087 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6088 6089 uint64_t feat_flags = dev_info.feature_flags; 6090 6091 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6092 printf("Device doesn't support in-place scatter-gather. " 6093 "Test Skipped.\n"); 6094 return TEST_SKIPPED; 6095 } 6096 6097 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6098 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6099 printf("Device doesn't support RAW data-path APIs.\n"); 6100 return TEST_SKIPPED; 6101 } 6102 6103 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6104 6105 /* Append data which is padded to a multiple */ 6106 /* of the algorithms block size */ 6107 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6108 6109 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6110 plaintext_pad_len, 10, 0); 6111 6112 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6113 tdata->plaintext.data); 6114 6115 /* Create ZUC session */ 6116 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 6117 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6118 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6119 tdata->key.data, tdata->key.len, 6120 tdata->cipher_iv.len); 6121 if (retval < 0) 6122 return retval; 6123 6124 /* Clear mbuf payload */ 6125 6126 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 6127 6128 /* Create ZUC operation */ 6129 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6130 tdata->cipher_iv.len, tdata->plaintext.len, 6131 tdata->validCipherOffsetInBits.len); 6132 if (retval < 0) 6133 return retval; 6134 6135 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6136 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6137 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 6138 else 6139 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6140 ut_params->op); 6141 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6142 6143 ut_params->obuf = ut_params->op->sym->m_dst; 6144 if (ut_params->obuf) 6145 ciphertext = rte_pktmbuf_read(ut_params->obuf, 6146 0, plaintext_len, ciphertext_buffer); 6147 else 6148 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 6149 0, plaintext_len, ciphertext_buffer); 6150 6151 /* Validate obuf */ 6152 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6153 6154 /* Validate obuf */ 6155 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6156 ciphertext, 6157 tdata->ciphertext.data, 6158 tdata->validCipherLenInBits.len, 6159 "ZUC Ciphertext data not as expected"); 6160 6161 return 0; 6162 } 6163 6164 static int 6165 test_zuc_authentication(const struct wireless_test_data *tdata) 6166 { 6167 struct crypto_testsuite_params *ts_params = &testsuite_params; 6168 struct crypto_unittest_params *ut_params = &unittest_params; 6169 6170 int retval; 6171 unsigned plaintext_pad_len; 6172 unsigned plaintext_len; 6173 uint8_t *plaintext; 6174 6175 struct rte_cryptodev_info dev_info; 6176 6177 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6178 uint64_t feat_flags = dev_info.feature_flags; 6179 6180 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 6181 (tdata->validAuthLenInBits.len % 8 != 0)) { 6182 printf("Device doesn't support NON-Byte Aligned Data.\n"); 6183 return TEST_SKIPPED; 6184 } 6185 6186 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6187 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6188 printf("Device doesn't support RAW data-path APIs.\n"); 6189 return TEST_SKIPPED; 6190 } 6191 6192 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6193 return TEST_SKIPPED; 6194 6195 /* Check if device supports ZUC EIA3 */ 6196 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6197 tdata->key.len, tdata->auth_iv.len, 6198 tdata->digest.len) < 0) 6199 return TEST_SKIPPED; 6200 6201 /* Create ZUC session */ 6202 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 6203 tdata->key.data, tdata->key.len, 6204 tdata->auth_iv.len, tdata->digest.len, 6205 RTE_CRYPTO_AUTH_OP_GENERATE, 6206 RTE_CRYPTO_AUTH_ZUC_EIA3); 6207 if (retval != 0) 6208 return retval; 6209 6210 /* alloc mbuf and set payload */ 6211 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6212 6213 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6214 rte_pktmbuf_tailroom(ut_params->ibuf)); 6215 6216 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6217 /* Append data which is padded to a multiple of */ 6218 /* the algorithms block size */ 6219 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6220 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6221 plaintext_pad_len); 6222 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6223 6224 /* Create ZUC operation */ 6225 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 6226 tdata->auth_iv.data, tdata->auth_iv.len, 6227 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 6228 tdata->validAuthLenInBits.len, 6229 0); 6230 if (retval < 0) 6231 return retval; 6232 6233 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6234 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6235 ut_params->op, 0, 1, 1, 0); 6236 else 6237 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6238 ut_params->op); 6239 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6240 ut_params->obuf = ut_params->op->sym->m_src; 6241 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 6242 + plaintext_pad_len; 6243 6244 /* Validate obuf */ 6245 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6246 ut_params->digest, 6247 tdata->digest.data, 6248 tdata->digest.len, 6249 "ZUC Generated auth tag not as expected"); 6250 6251 return 0; 6252 } 6253 6254 static int 6255 test_zuc_auth_cipher(const struct wireless_test_data *tdata, 6256 uint8_t op_mode, uint8_t verify) 6257 { 6258 struct crypto_testsuite_params *ts_params = &testsuite_params; 6259 struct crypto_unittest_params *ut_params = &unittest_params; 6260 6261 int retval; 6262 6263 uint8_t *plaintext = NULL, *ciphertext = NULL; 6264 unsigned int plaintext_pad_len; 6265 unsigned int plaintext_len; 6266 unsigned int ciphertext_pad_len; 6267 unsigned int ciphertext_len; 6268 6269 struct rte_cryptodev_info dev_info; 6270 6271 /* Check if device supports ZUC EEA3 */ 6272 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6273 tdata->key.len, tdata->cipher_iv.len) < 0) 6274 return TEST_SKIPPED; 6275 6276 /* Check if device supports ZUC EIA3 */ 6277 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6278 tdata->key.len, tdata->auth_iv.len, 6279 tdata->digest.len) < 0) 6280 return TEST_SKIPPED; 6281 6282 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6283 6284 uint64_t feat_flags = dev_info.feature_flags; 6285 6286 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6287 printf("Device doesn't support digest encrypted.\n"); 6288 return TEST_SKIPPED; 6289 } 6290 if (op_mode == IN_PLACE) { 6291 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6292 printf("Device doesn't support in-place scatter-gather " 6293 "in both input and output mbufs.\n"); 6294 return TEST_SKIPPED; 6295 } 6296 6297 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6298 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6299 printf("Device doesn't support RAW data-path APIs.\n"); 6300 return TEST_SKIPPED; 6301 } 6302 } else { 6303 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6304 return TEST_SKIPPED; 6305 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6306 printf("Device doesn't support out-of-place scatter-gather " 6307 "in both input and output mbufs.\n"); 6308 return TEST_SKIPPED; 6309 } 6310 } 6311 6312 /* Create ZUC session */ 6313 retval = create_wireless_algo_auth_cipher_session( 6314 ts_params->valid_devs[0], 6315 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6316 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6317 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6318 : RTE_CRYPTO_AUTH_OP_GENERATE), 6319 RTE_CRYPTO_AUTH_ZUC_EIA3, 6320 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6321 tdata->key.data, tdata->key.len, 6322 tdata->auth_iv.len, tdata->digest.len, 6323 tdata->cipher_iv.len); 6324 6325 if (retval != 0) 6326 return retval; 6327 6328 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6329 if (op_mode == OUT_OF_PLACE) 6330 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6331 6332 /* clear mbuf payload */ 6333 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6334 rte_pktmbuf_tailroom(ut_params->ibuf)); 6335 if (op_mode == OUT_OF_PLACE) 6336 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 6337 rte_pktmbuf_tailroom(ut_params->obuf)); 6338 6339 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6340 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6341 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6342 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6343 6344 if (verify) { 6345 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6346 ciphertext_pad_len); 6347 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6348 debug_hexdump(stdout, "ciphertext:", ciphertext, 6349 ciphertext_len); 6350 } else { 6351 /* make sure enough space to cover partial digest verify case */ 6352 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6353 ciphertext_pad_len); 6354 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6355 debug_hexdump(stdout, "plaintext:", plaintext, 6356 plaintext_len); 6357 } 6358 6359 if (op_mode == OUT_OF_PLACE) 6360 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 6361 6362 /* Create ZUC operation */ 6363 retval = create_wireless_algo_auth_cipher_operation( 6364 tdata->digest.data, tdata->digest.len, 6365 tdata->cipher_iv.data, tdata->cipher_iv.len, 6366 tdata->auth_iv.data, tdata->auth_iv.len, 6367 (tdata->digest.offset_bytes == 0 ? 6368 (verify ? ciphertext_pad_len : plaintext_pad_len) 6369 : tdata->digest.offset_bytes), 6370 tdata->validCipherLenInBits.len, 6371 tdata->validCipherOffsetInBits.len, 6372 tdata->validAuthLenInBits.len, 6373 0, 6374 op_mode, 0, verify); 6375 6376 if (retval < 0) 6377 return retval; 6378 6379 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6380 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6381 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 6382 else 6383 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6384 ut_params->op); 6385 6386 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6387 6388 ut_params->obuf = (op_mode == IN_PLACE ? 6389 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6390 6391 6392 if (verify) { 6393 if (ut_params->obuf) 6394 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 6395 uint8_t *); 6396 else 6397 plaintext = ciphertext; 6398 6399 debug_hexdump(stdout, "plaintext:", plaintext, 6400 (tdata->plaintext.len >> 3) - tdata->digest.len); 6401 debug_hexdump(stdout, "plaintext expected:", 6402 tdata->plaintext.data, 6403 (tdata->plaintext.len >> 3) - tdata->digest.len); 6404 } else { 6405 if (ut_params->obuf) 6406 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 6407 uint8_t *); 6408 else 6409 ciphertext = plaintext; 6410 6411 debug_hexdump(stdout, "ciphertext:", ciphertext, 6412 ciphertext_len); 6413 debug_hexdump(stdout, "ciphertext expected:", 6414 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6415 6416 ut_params->digest = rte_pktmbuf_mtod( 6417 ut_params->obuf, uint8_t *) + 6418 (tdata->digest.offset_bytes == 0 ? 6419 plaintext_pad_len : tdata->digest.offset_bytes); 6420 6421 debug_hexdump(stdout, "digest:", ut_params->digest, 6422 tdata->digest.len); 6423 debug_hexdump(stdout, "digest expected:", 6424 tdata->digest.data, tdata->digest.len); 6425 } 6426 6427 /* Validate obuf */ 6428 if (verify) { 6429 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6430 plaintext, 6431 tdata->plaintext.data, 6432 tdata->plaintext.len >> 3, 6433 "ZUC Plaintext data not as expected"); 6434 } else { 6435 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6436 ciphertext, 6437 tdata->ciphertext.data, 6438 tdata->ciphertext.len >> 3, 6439 "ZUC Ciphertext data not as expected"); 6440 6441 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6442 ut_params->digest, 6443 tdata->digest.data, 6444 DIGEST_BYTE_LENGTH_KASUMI_F9, 6445 "ZUC Generated auth tag not as expected"); 6446 } 6447 return 0; 6448 } 6449 6450 static int 6451 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata, 6452 uint8_t op_mode, uint8_t verify) 6453 { 6454 struct crypto_testsuite_params *ts_params = &testsuite_params; 6455 struct crypto_unittest_params *ut_params = &unittest_params; 6456 6457 int retval; 6458 6459 const uint8_t *plaintext = NULL; 6460 const uint8_t *ciphertext = NULL; 6461 const uint8_t *digest = NULL; 6462 unsigned int plaintext_pad_len; 6463 unsigned int plaintext_len; 6464 unsigned int ciphertext_pad_len; 6465 unsigned int ciphertext_len; 6466 uint8_t buffer[10000]; 6467 uint8_t digest_buffer[10000]; 6468 6469 struct rte_cryptodev_info dev_info; 6470 6471 /* Check if device supports ZUC EEA3 */ 6472 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6473 tdata->key.len, tdata->cipher_iv.len) < 0) 6474 return TEST_SKIPPED; 6475 6476 /* Check if device supports ZUC EIA3 */ 6477 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6478 tdata->key.len, tdata->auth_iv.len, 6479 tdata->digest.len) < 0) 6480 return TEST_SKIPPED; 6481 6482 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6483 6484 uint64_t feat_flags = dev_info.feature_flags; 6485 6486 if (op_mode == IN_PLACE) { 6487 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6488 printf("Device doesn't support in-place scatter-gather " 6489 "in both input and output mbufs.\n"); 6490 return TEST_SKIPPED; 6491 } 6492 6493 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6494 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6495 printf("Device doesn't support RAW data-path APIs.\n"); 6496 return TEST_SKIPPED; 6497 } 6498 } else { 6499 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6500 return TEST_SKIPPED; 6501 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6502 printf("Device doesn't support out-of-place scatter-gather " 6503 "in both input and output mbufs.\n"); 6504 return TEST_SKIPPED; 6505 } 6506 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6507 printf("Device doesn't support digest encrypted.\n"); 6508 return TEST_SKIPPED; 6509 } 6510 } 6511 6512 /* Create ZUC session */ 6513 retval = create_wireless_algo_auth_cipher_session( 6514 ts_params->valid_devs[0], 6515 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6516 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6517 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6518 : RTE_CRYPTO_AUTH_OP_GENERATE), 6519 RTE_CRYPTO_AUTH_ZUC_EIA3, 6520 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6521 tdata->key.data, tdata->key.len, 6522 tdata->auth_iv.len, tdata->digest.len, 6523 tdata->cipher_iv.len); 6524 6525 if (retval != 0) 6526 return retval; 6527 6528 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6529 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6530 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6531 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6532 6533 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6534 plaintext_pad_len, 15, 0); 6535 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6536 "Failed to allocate input buffer in mempool"); 6537 6538 if (op_mode == OUT_OF_PLACE) { 6539 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 6540 plaintext_pad_len, 15, 0); 6541 TEST_ASSERT_NOT_NULL(ut_params->obuf, 6542 "Failed to allocate output buffer in mempool"); 6543 } 6544 6545 if (verify) { 6546 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6547 tdata->ciphertext.data); 6548 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6549 ciphertext_len, buffer); 6550 debug_hexdump(stdout, "ciphertext:", ciphertext, 6551 ciphertext_len); 6552 } else { 6553 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6554 tdata->plaintext.data); 6555 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6556 plaintext_len, buffer); 6557 debug_hexdump(stdout, "plaintext:", plaintext, 6558 plaintext_len); 6559 } 6560 memset(buffer, 0, sizeof(buffer)); 6561 6562 /* Create ZUC operation */ 6563 retval = create_wireless_algo_auth_cipher_operation( 6564 tdata->digest.data, tdata->digest.len, 6565 tdata->cipher_iv.data, tdata->cipher_iv.len, 6566 NULL, 0, 6567 (tdata->digest.offset_bytes == 0 ? 6568 (verify ? ciphertext_pad_len : plaintext_pad_len) 6569 : tdata->digest.offset_bytes), 6570 tdata->validCipherLenInBits.len, 6571 tdata->validCipherOffsetInBits.len, 6572 tdata->validAuthLenInBits.len, 6573 0, 6574 op_mode, 1, verify); 6575 6576 if (retval < 0) 6577 return retval; 6578 6579 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6580 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6581 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 6582 else 6583 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6584 ut_params->op); 6585 6586 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6587 6588 ut_params->obuf = (op_mode == IN_PLACE ? 6589 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6590 6591 if (verify) { 6592 if (ut_params->obuf) 6593 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 6594 plaintext_len, buffer); 6595 else 6596 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6597 plaintext_len, buffer); 6598 6599 debug_hexdump(stdout, "plaintext:", plaintext, 6600 (tdata->plaintext.len >> 3) - tdata->digest.len); 6601 debug_hexdump(stdout, "plaintext expected:", 6602 tdata->plaintext.data, 6603 (tdata->plaintext.len >> 3) - tdata->digest.len); 6604 } else { 6605 if (ut_params->obuf) 6606 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 6607 ciphertext_len, buffer); 6608 else 6609 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6610 ciphertext_len, buffer); 6611 6612 debug_hexdump(stdout, "ciphertext:", ciphertext, 6613 ciphertext_len); 6614 debug_hexdump(stdout, "ciphertext expected:", 6615 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6616 6617 if (ut_params->obuf) 6618 digest = rte_pktmbuf_read(ut_params->obuf, 6619 (tdata->digest.offset_bytes == 0 ? 6620 plaintext_pad_len : tdata->digest.offset_bytes), 6621 tdata->digest.len, digest_buffer); 6622 else 6623 digest = rte_pktmbuf_read(ut_params->ibuf, 6624 (tdata->digest.offset_bytes == 0 ? 6625 plaintext_pad_len : tdata->digest.offset_bytes), 6626 tdata->digest.len, digest_buffer); 6627 6628 debug_hexdump(stdout, "digest:", digest, 6629 tdata->digest.len); 6630 debug_hexdump(stdout, "digest expected:", 6631 tdata->digest.data, tdata->digest.len); 6632 } 6633 6634 /* Validate obuf */ 6635 if (verify) { 6636 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6637 plaintext, 6638 tdata->plaintext.data, 6639 tdata->plaintext.len >> 3, 6640 "ZUC Plaintext data not as expected"); 6641 } else { 6642 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6643 ciphertext, 6644 tdata->ciphertext.data, 6645 tdata->validDataLenInBits.len, 6646 "ZUC Ciphertext data not as expected"); 6647 6648 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6649 digest, 6650 tdata->digest.data, 6651 DIGEST_BYTE_LENGTH_KASUMI_F9, 6652 "ZUC Generated auth tag not as expected"); 6653 } 6654 return 0; 6655 } 6656 6657 static int 6658 test_kasumi_encryption_test_case_1(void) 6659 { 6660 return test_kasumi_encryption(&kasumi_test_case_1); 6661 } 6662 6663 static int 6664 test_kasumi_encryption_test_case_1_sgl(void) 6665 { 6666 return test_kasumi_encryption_sgl(&kasumi_test_case_1); 6667 } 6668 6669 static int 6670 test_kasumi_encryption_test_case_1_oop(void) 6671 { 6672 return test_kasumi_encryption_oop(&kasumi_test_case_1); 6673 } 6674 6675 static int 6676 test_kasumi_encryption_test_case_1_oop_sgl(void) 6677 { 6678 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1); 6679 } 6680 6681 static int 6682 test_kasumi_encryption_test_case_2(void) 6683 { 6684 return test_kasumi_encryption(&kasumi_test_case_2); 6685 } 6686 6687 static int 6688 test_kasumi_encryption_test_case_3(void) 6689 { 6690 return test_kasumi_encryption(&kasumi_test_case_3); 6691 } 6692 6693 static int 6694 test_kasumi_encryption_test_case_4(void) 6695 { 6696 return test_kasumi_encryption(&kasumi_test_case_4); 6697 } 6698 6699 static int 6700 test_kasumi_encryption_test_case_5(void) 6701 { 6702 return test_kasumi_encryption(&kasumi_test_case_5); 6703 } 6704 6705 static int 6706 test_kasumi_decryption_test_case_1(void) 6707 { 6708 return test_kasumi_decryption(&kasumi_test_case_1); 6709 } 6710 6711 static int 6712 test_kasumi_decryption_test_case_1_oop(void) 6713 { 6714 return test_kasumi_decryption_oop(&kasumi_test_case_1); 6715 } 6716 6717 static int 6718 test_kasumi_decryption_test_case_2(void) 6719 { 6720 return test_kasumi_decryption(&kasumi_test_case_2); 6721 } 6722 6723 static int 6724 test_kasumi_decryption_test_case_3(void) 6725 { 6726 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6727 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6728 return TEST_SKIPPED; 6729 return test_kasumi_decryption(&kasumi_test_case_3); 6730 } 6731 6732 static int 6733 test_kasumi_decryption_test_case_4(void) 6734 { 6735 return test_kasumi_decryption(&kasumi_test_case_4); 6736 } 6737 6738 static int 6739 test_kasumi_decryption_test_case_5(void) 6740 { 6741 return test_kasumi_decryption(&kasumi_test_case_5); 6742 } 6743 static int 6744 test_snow3g_encryption_test_case_1(void) 6745 { 6746 return test_snow3g_encryption(&snow3g_test_case_1); 6747 } 6748 6749 static int 6750 test_snow3g_encryption_test_case_1_oop(void) 6751 { 6752 return test_snow3g_encryption_oop(&snow3g_test_case_1); 6753 } 6754 6755 static int 6756 test_snow3g_encryption_test_case_1_oop_sgl(void) 6757 { 6758 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1); 6759 } 6760 6761 6762 static int 6763 test_snow3g_encryption_test_case_1_offset_oop(void) 6764 { 6765 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); 6766 } 6767 6768 static int 6769 test_snow3g_encryption_test_case_2(void) 6770 { 6771 return test_snow3g_encryption(&snow3g_test_case_2); 6772 } 6773 6774 static int 6775 test_snow3g_encryption_test_case_3(void) 6776 { 6777 return test_snow3g_encryption(&snow3g_test_case_3); 6778 } 6779 6780 static int 6781 test_snow3g_encryption_test_case_4(void) 6782 { 6783 return test_snow3g_encryption(&snow3g_test_case_4); 6784 } 6785 6786 static int 6787 test_snow3g_encryption_test_case_5(void) 6788 { 6789 return test_snow3g_encryption(&snow3g_test_case_5); 6790 } 6791 6792 static int 6793 test_snow3g_decryption_test_case_1(void) 6794 { 6795 return test_snow3g_decryption(&snow3g_test_case_1); 6796 } 6797 6798 static int 6799 test_snow3g_decryption_test_case_1_oop(void) 6800 { 6801 return test_snow3g_decryption_oop(&snow3g_test_case_1); 6802 } 6803 6804 static int 6805 test_snow3g_decryption_test_case_2(void) 6806 { 6807 return test_snow3g_decryption(&snow3g_test_case_2); 6808 } 6809 6810 static int 6811 test_snow3g_decryption_test_case_3(void) 6812 { 6813 return test_snow3g_decryption(&snow3g_test_case_3); 6814 } 6815 6816 static int 6817 test_snow3g_decryption_test_case_4(void) 6818 { 6819 return test_snow3g_decryption(&snow3g_test_case_4); 6820 } 6821 6822 static int 6823 test_snow3g_decryption_test_case_5(void) 6824 { 6825 return test_snow3g_decryption(&snow3g_test_case_5); 6826 } 6827 6828 /* 6829 * Function prepares snow3g_hash_test_data from snow3g_test_data. 6830 * Pattern digest from snow3g_test_data must be allocated as 6831 * 4 last bytes in plaintext. 6832 */ 6833 static void 6834 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern, 6835 struct snow3g_hash_test_data *output) 6836 { 6837 if ((pattern != NULL) && (output != NULL)) { 6838 output->key.len = pattern->key.len; 6839 6840 memcpy(output->key.data, 6841 pattern->key.data, pattern->key.len); 6842 6843 output->auth_iv.len = pattern->auth_iv.len; 6844 6845 memcpy(output->auth_iv.data, 6846 pattern->auth_iv.data, pattern->auth_iv.len); 6847 6848 output->plaintext.len = pattern->plaintext.len; 6849 6850 memcpy(output->plaintext.data, 6851 pattern->plaintext.data, pattern->plaintext.len >> 3); 6852 6853 output->digest.len = pattern->digest.len; 6854 6855 memcpy(output->digest.data, 6856 &pattern->plaintext.data[pattern->digest.offset_bytes], 6857 pattern->digest.len); 6858 6859 output->validAuthLenInBits.len = 6860 pattern->validAuthLenInBits.len; 6861 } 6862 } 6863 6864 /* 6865 * Test case verify computed cipher and digest from snow3g_test_case_7 data. 6866 */ 6867 static int 6868 test_snow3g_decryption_with_digest_test_case_1(void) 6869 { 6870 struct snow3g_hash_test_data snow3g_hash_data; 6871 struct rte_cryptodev_info dev_info; 6872 struct crypto_testsuite_params *ts_params = &testsuite_params; 6873 6874 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6875 uint64_t feat_flags = dev_info.feature_flags; 6876 6877 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6878 printf("Device doesn't support encrypted digest operations.\n"); 6879 return TEST_SKIPPED; 6880 } 6881 6882 /* 6883 * Function prepare data for hash verification test case. 6884 * Digest is allocated in 4 last bytes in plaintext, pattern. 6885 */ 6886 snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data); 6887 6888 return test_snow3g_decryption(&snow3g_test_case_7) & 6889 test_snow3g_authentication_verify(&snow3g_hash_data); 6890 } 6891 6892 static int 6893 test_snow3g_cipher_auth_test_case_1(void) 6894 { 6895 return test_snow3g_cipher_auth(&snow3g_test_case_3); 6896 } 6897 6898 static int 6899 test_snow3g_auth_cipher_test_case_1(void) 6900 { 6901 return test_snow3g_auth_cipher( 6902 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0); 6903 } 6904 6905 static int 6906 test_snow3g_auth_cipher_test_case_2(void) 6907 { 6908 return test_snow3g_auth_cipher( 6909 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0); 6910 } 6911 6912 static int 6913 test_snow3g_auth_cipher_test_case_2_oop(void) 6914 { 6915 return test_snow3g_auth_cipher( 6916 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6917 } 6918 6919 static int 6920 test_snow3g_auth_cipher_part_digest_enc(void) 6921 { 6922 return test_snow3g_auth_cipher( 6923 &snow3g_auth_cipher_partial_digest_encryption, 6924 IN_PLACE, 0); 6925 } 6926 6927 static int 6928 test_snow3g_auth_cipher_part_digest_enc_oop(void) 6929 { 6930 return test_snow3g_auth_cipher( 6931 &snow3g_auth_cipher_partial_digest_encryption, 6932 OUT_OF_PLACE, 0); 6933 } 6934 6935 static int 6936 test_snow3g_auth_cipher_test_case_3_sgl(void) 6937 { 6938 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6939 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6940 return TEST_SKIPPED; 6941 return test_snow3g_auth_cipher_sgl( 6942 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0); 6943 } 6944 6945 static int 6946 test_snow3g_auth_cipher_test_case_3_oop_sgl(void) 6947 { 6948 return test_snow3g_auth_cipher_sgl( 6949 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0); 6950 } 6951 6952 static int 6953 test_snow3g_auth_cipher_part_digest_enc_sgl(void) 6954 { 6955 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6956 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6957 return TEST_SKIPPED; 6958 return test_snow3g_auth_cipher_sgl( 6959 &snow3g_auth_cipher_partial_digest_encryption, 6960 IN_PLACE, 0); 6961 } 6962 6963 static int 6964 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void) 6965 { 6966 return test_snow3g_auth_cipher_sgl( 6967 &snow3g_auth_cipher_partial_digest_encryption, 6968 OUT_OF_PLACE, 0); 6969 } 6970 6971 static int 6972 test_snow3g_auth_cipher_verify_test_case_1(void) 6973 { 6974 return test_snow3g_auth_cipher( 6975 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1); 6976 } 6977 6978 static int 6979 test_snow3g_auth_cipher_verify_test_case_2(void) 6980 { 6981 return test_snow3g_auth_cipher( 6982 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1); 6983 } 6984 6985 static int 6986 test_snow3g_auth_cipher_verify_test_case_2_oop(void) 6987 { 6988 return test_snow3g_auth_cipher( 6989 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 6990 } 6991 6992 static int 6993 test_snow3g_auth_cipher_verify_part_digest_enc(void) 6994 { 6995 return test_snow3g_auth_cipher( 6996 &snow3g_auth_cipher_partial_digest_encryption, 6997 IN_PLACE, 1); 6998 } 6999 7000 static int 7001 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void) 7002 { 7003 return test_snow3g_auth_cipher( 7004 &snow3g_auth_cipher_partial_digest_encryption, 7005 OUT_OF_PLACE, 1); 7006 } 7007 7008 static int 7009 test_snow3g_auth_cipher_verify_test_case_3_sgl(void) 7010 { 7011 return test_snow3g_auth_cipher_sgl( 7012 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1); 7013 } 7014 7015 static int 7016 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void) 7017 { 7018 return test_snow3g_auth_cipher_sgl( 7019 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1); 7020 } 7021 7022 static int 7023 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void) 7024 { 7025 return test_snow3g_auth_cipher_sgl( 7026 &snow3g_auth_cipher_partial_digest_encryption, 7027 IN_PLACE, 1); 7028 } 7029 7030 static int 7031 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void) 7032 { 7033 return test_snow3g_auth_cipher_sgl( 7034 &snow3g_auth_cipher_partial_digest_encryption, 7035 OUT_OF_PLACE, 1); 7036 } 7037 7038 static int 7039 test_snow3g_auth_cipher_with_digest_test_case_1(void) 7040 { 7041 return test_snow3g_auth_cipher( 7042 &snow3g_test_case_7, IN_PLACE, 0); 7043 } 7044 7045 static int 7046 test_kasumi_auth_cipher_test_case_1(void) 7047 { 7048 return test_kasumi_auth_cipher( 7049 &kasumi_test_case_3, IN_PLACE, 0); 7050 } 7051 7052 static int 7053 test_kasumi_auth_cipher_test_case_2(void) 7054 { 7055 return test_kasumi_auth_cipher( 7056 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7057 } 7058 7059 static int 7060 test_kasumi_auth_cipher_test_case_2_oop(void) 7061 { 7062 return test_kasumi_auth_cipher( 7063 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7064 } 7065 7066 static int 7067 test_kasumi_auth_cipher_test_case_2_sgl(void) 7068 { 7069 return test_kasumi_auth_cipher_sgl( 7070 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7071 } 7072 7073 static int 7074 test_kasumi_auth_cipher_test_case_2_oop_sgl(void) 7075 { 7076 return test_kasumi_auth_cipher_sgl( 7077 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7078 } 7079 7080 static int 7081 test_kasumi_auth_cipher_verify_test_case_1(void) 7082 { 7083 return test_kasumi_auth_cipher( 7084 &kasumi_test_case_3, IN_PLACE, 1); 7085 } 7086 7087 static int 7088 test_kasumi_auth_cipher_verify_test_case_2(void) 7089 { 7090 return test_kasumi_auth_cipher( 7091 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7092 } 7093 7094 static int 7095 test_kasumi_auth_cipher_verify_test_case_2_oop(void) 7096 { 7097 return test_kasumi_auth_cipher( 7098 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7099 } 7100 7101 static int 7102 test_kasumi_auth_cipher_verify_test_case_2_sgl(void) 7103 { 7104 return test_kasumi_auth_cipher_sgl( 7105 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7106 } 7107 7108 static int 7109 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void) 7110 { 7111 return test_kasumi_auth_cipher_sgl( 7112 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7113 } 7114 7115 static int 7116 test_kasumi_cipher_auth_test_case_1(void) 7117 { 7118 return test_kasumi_cipher_auth(&kasumi_test_case_6); 7119 } 7120 7121 static int 7122 test_zuc_encryption_test_case_1(void) 7123 { 7124 return test_zuc_encryption(&zuc_test_case_cipher_193b); 7125 } 7126 7127 static int 7128 test_zuc_encryption_test_case_2(void) 7129 { 7130 return test_zuc_encryption(&zuc_test_case_cipher_800b); 7131 } 7132 7133 static int 7134 test_zuc_encryption_test_case_3(void) 7135 { 7136 return test_zuc_encryption(&zuc_test_case_cipher_1570b); 7137 } 7138 7139 static int 7140 test_zuc_encryption_test_case_4(void) 7141 { 7142 return test_zuc_encryption(&zuc_test_case_cipher_2798b); 7143 } 7144 7145 static int 7146 test_zuc_encryption_test_case_5(void) 7147 { 7148 return test_zuc_encryption(&zuc_test_case_cipher_4019b); 7149 } 7150 7151 static int 7152 test_zuc_encryption_test_case_6_sgl(void) 7153 { 7154 return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b); 7155 } 7156 7157 static int 7158 test_zuc_hash_generate_test_case_1(void) 7159 { 7160 return test_zuc_authentication(&zuc_test_case_auth_1b); 7161 } 7162 7163 static int 7164 test_zuc_hash_generate_test_case_2(void) 7165 { 7166 return test_zuc_authentication(&zuc_test_case_auth_90b); 7167 } 7168 7169 static int 7170 test_zuc_hash_generate_test_case_3(void) 7171 { 7172 return test_zuc_authentication(&zuc_test_case_auth_577b); 7173 } 7174 7175 static int 7176 test_zuc_hash_generate_test_case_4(void) 7177 { 7178 return test_zuc_authentication(&zuc_test_case_auth_2079b); 7179 } 7180 7181 static int 7182 test_zuc_hash_generate_test_case_5(void) 7183 { 7184 return test_zuc_authentication(&zuc_test_auth_5670b); 7185 } 7186 7187 static int 7188 test_zuc_hash_generate_test_case_6(void) 7189 { 7190 return test_zuc_authentication(&zuc_test_case_auth_128b); 7191 } 7192 7193 static int 7194 test_zuc_hash_generate_test_case_7(void) 7195 { 7196 return test_zuc_authentication(&zuc_test_case_auth_2080b); 7197 } 7198 7199 static int 7200 test_zuc_hash_generate_test_case_8(void) 7201 { 7202 return test_zuc_authentication(&zuc_test_case_auth_584b); 7203 } 7204 7205 static int 7206 test_zuc_hash_generate_test_case_9(void) 7207 { 7208 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b); 7209 } 7210 7211 static int 7212 test_zuc_hash_generate_test_case_10(void) 7213 { 7214 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b); 7215 } 7216 7217 static int 7218 test_zuc_hash_generate_test_case_11(void) 7219 { 7220 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b); 7221 } 7222 7223 static int 7224 test_zuc_cipher_auth_test_case_1(void) 7225 { 7226 return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b); 7227 } 7228 7229 static int 7230 test_zuc_cipher_auth_test_case_2(void) 7231 { 7232 return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b); 7233 } 7234 7235 static int 7236 test_zuc_auth_cipher_test_case_1(void) 7237 { 7238 return test_zuc_auth_cipher( 7239 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7240 } 7241 7242 static int 7243 test_zuc_auth_cipher_test_case_1_oop(void) 7244 { 7245 return test_zuc_auth_cipher( 7246 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7247 } 7248 7249 static int 7250 test_zuc_auth_cipher_test_case_1_sgl(void) 7251 { 7252 return test_zuc_auth_cipher_sgl( 7253 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7254 } 7255 7256 static int 7257 test_zuc_auth_cipher_test_case_1_oop_sgl(void) 7258 { 7259 return test_zuc_auth_cipher_sgl( 7260 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7261 } 7262 7263 static int 7264 test_zuc_auth_cipher_verify_test_case_1(void) 7265 { 7266 return test_zuc_auth_cipher( 7267 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7268 } 7269 7270 static int 7271 test_zuc_auth_cipher_verify_test_case_1_oop(void) 7272 { 7273 return test_zuc_auth_cipher( 7274 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7275 } 7276 7277 static int 7278 test_zuc_auth_cipher_verify_test_case_1_sgl(void) 7279 { 7280 return test_zuc_auth_cipher_sgl( 7281 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7282 } 7283 7284 static int 7285 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void) 7286 { 7287 return test_zuc_auth_cipher_sgl( 7288 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7289 } 7290 7291 static int 7292 test_zuc256_encryption_test_case_1(void) 7293 { 7294 return test_zuc_encryption(&zuc256_test_case_cipher_1); 7295 } 7296 7297 static int 7298 test_zuc256_encryption_test_case_2(void) 7299 { 7300 return test_zuc_encryption(&zuc256_test_case_cipher_2); 7301 } 7302 7303 static int 7304 test_zuc256_authentication_test_case_1(void) 7305 { 7306 return test_zuc_authentication(&zuc256_test_case_auth_1); 7307 } 7308 7309 static int 7310 test_zuc256_authentication_test_case_2(void) 7311 { 7312 return test_zuc_authentication(&zuc256_test_case_auth_2); 7313 } 7314 7315 static int 7316 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata) 7317 { 7318 uint8_t dev_id = testsuite_params.valid_devs[0]; 7319 7320 struct rte_cryptodev_sym_capability_idx cap_idx; 7321 7322 /* Check if device supports particular cipher algorithm */ 7323 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 7324 cap_idx.algo.cipher = tdata->cipher_algo; 7325 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 7326 return TEST_SKIPPED; 7327 7328 /* Check if device supports particular hash algorithm */ 7329 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 7330 cap_idx.algo.auth = tdata->auth_algo; 7331 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 7332 return TEST_SKIPPED; 7333 7334 return 0; 7335 } 7336 7337 static int 7338 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata, 7339 uint8_t op_mode, uint8_t verify) 7340 { 7341 struct crypto_testsuite_params *ts_params = &testsuite_params; 7342 struct crypto_unittest_params *ut_params = &unittest_params; 7343 7344 int retval; 7345 7346 uint8_t *plaintext = NULL, *ciphertext = NULL; 7347 unsigned int plaintext_pad_len; 7348 unsigned int plaintext_len; 7349 unsigned int ciphertext_pad_len; 7350 unsigned int ciphertext_len; 7351 7352 struct rte_cryptodev_info dev_info; 7353 struct rte_crypto_op *op; 7354 7355 /* Check if device supports particular algorithms separately */ 7356 if (test_mixed_check_if_unsupported(tdata)) 7357 return TEST_SKIPPED; 7358 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7359 return TEST_SKIPPED; 7360 7361 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7362 7363 uint64_t feat_flags = dev_info.feature_flags; 7364 7365 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7366 printf("Device doesn't support digest encrypted.\n"); 7367 return TEST_SKIPPED; 7368 } 7369 7370 /* Create the session */ 7371 if (verify) 7372 retval = create_wireless_algo_cipher_auth_session( 7373 ts_params->valid_devs[0], 7374 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7375 RTE_CRYPTO_AUTH_OP_VERIFY, 7376 tdata->auth_algo, 7377 tdata->cipher_algo, 7378 tdata->auth_key.data, tdata->auth_key.len, 7379 tdata->auth_iv.len, tdata->digest_enc.len, 7380 tdata->cipher_iv.len); 7381 else 7382 retval = create_wireless_algo_auth_cipher_session( 7383 ts_params->valid_devs[0], 7384 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7385 RTE_CRYPTO_AUTH_OP_GENERATE, 7386 tdata->auth_algo, 7387 tdata->cipher_algo, 7388 tdata->auth_key.data, tdata->auth_key.len, 7389 tdata->auth_iv.len, tdata->digest_enc.len, 7390 tdata->cipher_iv.len); 7391 if (retval != 0) 7392 return retval; 7393 7394 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7395 if (op_mode == OUT_OF_PLACE) 7396 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7397 7398 /* clear mbuf payload */ 7399 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7400 rte_pktmbuf_tailroom(ut_params->ibuf)); 7401 if (op_mode == OUT_OF_PLACE) { 7402 7403 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 7404 rte_pktmbuf_tailroom(ut_params->obuf)); 7405 } 7406 7407 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 7408 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 7409 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 7410 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 7411 7412 if (verify) { 7413 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7414 ciphertext_pad_len); 7415 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 7416 debug_hexdump(stdout, "ciphertext:", ciphertext, 7417 ciphertext_len); 7418 } else { 7419 /* make sure enough space to cover partial digest verify case */ 7420 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7421 ciphertext_pad_len); 7422 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 7423 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 7424 } 7425 7426 if (op_mode == OUT_OF_PLACE) 7427 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 7428 7429 /* Create the operation */ 7430 retval = create_wireless_algo_auth_cipher_operation( 7431 tdata->digest_enc.data, tdata->digest_enc.len, 7432 tdata->cipher_iv.data, tdata->cipher_iv.len, 7433 tdata->auth_iv.data, tdata->auth_iv.len, 7434 (tdata->digest_enc.offset == 0 ? 7435 plaintext_pad_len 7436 : tdata->digest_enc.offset), 7437 tdata->validCipherLen.len_bits, 7438 tdata->cipher.offset_bits, 7439 tdata->validAuthLen.len_bits, 7440 tdata->auth.offset_bits, 7441 op_mode, 0, verify); 7442 7443 if (retval < 0) 7444 return retval; 7445 7446 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 7447 7448 /* Check if the op failed because the device doesn't */ 7449 /* support this particular combination of algorithms */ 7450 if (op == NULL && ut_params->op->status == 7451 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 7452 printf("Device doesn't support this mixed combination. " 7453 "Test Skipped.\n"); 7454 return TEST_SKIPPED; 7455 } 7456 ut_params->op = op; 7457 7458 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 7459 7460 ut_params->obuf = (op_mode == IN_PLACE ? 7461 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 7462 7463 if (verify) { 7464 if (ut_params->obuf) 7465 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 7466 uint8_t *); 7467 else 7468 plaintext = ciphertext + 7469 (tdata->cipher.offset_bits >> 3); 7470 7471 debug_hexdump(stdout, "plaintext:", plaintext, 7472 tdata->plaintext.len_bits >> 3); 7473 debug_hexdump(stdout, "plaintext expected:", 7474 tdata->plaintext.data, 7475 tdata->plaintext.len_bits >> 3); 7476 } else { 7477 if (ut_params->obuf) 7478 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 7479 uint8_t *); 7480 else 7481 ciphertext = plaintext; 7482 7483 debug_hexdump(stdout, "ciphertext:", ciphertext, 7484 ciphertext_len); 7485 debug_hexdump(stdout, "ciphertext expected:", 7486 tdata->ciphertext.data, 7487 tdata->ciphertext.len_bits >> 3); 7488 7489 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 7490 + (tdata->digest_enc.offset == 0 ? 7491 plaintext_pad_len : tdata->digest_enc.offset); 7492 7493 debug_hexdump(stdout, "digest:", ut_params->digest, 7494 tdata->digest_enc.len); 7495 debug_hexdump(stdout, "digest expected:", 7496 tdata->digest_enc.data, 7497 tdata->digest_enc.len); 7498 } 7499 7500 if (!verify) { 7501 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7502 ut_params->digest, 7503 tdata->digest_enc.data, 7504 tdata->digest_enc.len, 7505 "Generated auth tag not as expected"); 7506 } 7507 7508 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 7509 if (verify) { 7510 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7511 plaintext, 7512 tdata->plaintext.data, 7513 tdata->plaintext.len_bits >> 3, 7514 "Plaintext data not as expected"); 7515 } else { 7516 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7517 ciphertext, 7518 tdata->ciphertext.data, 7519 tdata->validDataLen.len_bits, 7520 "Ciphertext data not as expected"); 7521 } 7522 } 7523 7524 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7525 "crypto op processing failed"); 7526 7527 return 0; 7528 } 7529 7530 static int 7531 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata, 7532 uint8_t op_mode, uint8_t verify) 7533 { 7534 struct crypto_testsuite_params *ts_params = &testsuite_params; 7535 struct crypto_unittest_params *ut_params = &unittest_params; 7536 7537 int retval; 7538 7539 const uint8_t *plaintext = NULL; 7540 const uint8_t *ciphertext = NULL; 7541 const uint8_t *digest = NULL; 7542 unsigned int plaintext_pad_len; 7543 unsigned int plaintext_len; 7544 unsigned int ciphertext_pad_len; 7545 unsigned int ciphertext_len; 7546 uint8_t buffer[10000]; 7547 uint8_t digest_buffer[10000]; 7548 7549 struct rte_cryptodev_info dev_info; 7550 struct rte_crypto_op *op; 7551 7552 /* Check if device supports particular algorithms */ 7553 if (test_mixed_check_if_unsupported(tdata)) 7554 return TEST_SKIPPED; 7555 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7556 return TEST_SKIPPED; 7557 7558 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7559 7560 uint64_t feat_flags = dev_info.feature_flags; 7561 7562 if (op_mode == IN_PLACE) { 7563 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 7564 printf("Device doesn't support in-place scatter-gather " 7565 "in both input and output mbufs.\n"); 7566 return TEST_SKIPPED; 7567 } 7568 } else { 7569 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 7570 printf("Device doesn't support out-of-place scatter-gather " 7571 "in both input and output mbufs.\n"); 7572 return TEST_SKIPPED; 7573 } 7574 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7575 printf("Device doesn't support digest encrypted.\n"); 7576 return TEST_SKIPPED; 7577 } 7578 } 7579 7580 /* Create the session */ 7581 if (verify) 7582 retval = create_wireless_algo_cipher_auth_session( 7583 ts_params->valid_devs[0], 7584 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7585 RTE_CRYPTO_AUTH_OP_VERIFY, 7586 tdata->auth_algo, 7587 tdata->cipher_algo, 7588 tdata->auth_key.data, tdata->auth_key.len, 7589 tdata->auth_iv.len, tdata->digest_enc.len, 7590 tdata->cipher_iv.len); 7591 else 7592 retval = create_wireless_algo_auth_cipher_session( 7593 ts_params->valid_devs[0], 7594 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7595 RTE_CRYPTO_AUTH_OP_GENERATE, 7596 tdata->auth_algo, 7597 tdata->cipher_algo, 7598 tdata->auth_key.data, tdata->auth_key.len, 7599 tdata->auth_iv.len, tdata->digest_enc.len, 7600 tdata->cipher_iv.len); 7601 if (retval != 0) 7602 return retval; 7603 7604 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 7605 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 7606 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 7607 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 7608 7609 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 7610 ciphertext_pad_len, 15, 0); 7611 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 7612 "Failed to allocate input buffer in mempool"); 7613 7614 if (op_mode == OUT_OF_PLACE) { 7615 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 7616 plaintext_pad_len, 15, 0); 7617 TEST_ASSERT_NOT_NULL(ut_params->obuf, 7618 "Failed to allocate output buffer in mempool"); 7619 } 7620 7621 if (verify) { 7622 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 7623 tdata->ciphertext.data); 7624 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7625 ciphertext_len, buffer); 7626 debug_hexdump(stdout, "ciphertext:", ciphertext, 7627 ciphertext_len); 7628 } else { 7629 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 7630 tdata->plaintext.data); 7631 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7632 plaintext_len, buffer); 7633 debug_hexdump(stdout, "plaintext:", plaintext, 7634 plaintext_len); 7635 } 7636 memset(buffer, 0, sizeof(buffer)); 7637 7638 /* Create the operation */ 7639 retval = create_wireless_algo_auth_cipher_operation( 7640 tdata->digest_enc.data, tdata->digest_enc.len, 7641 tdata->cipher_iv.data, tdata->cipher_iv.len, 7642 tdata->auth_iv.data, tdata->auth_iv.len, 7643 (tdata->digest_enc.offset == 0 ? 7644 plaintext_pad_len 7645 : tdata->digest_enc.offset), 7646 tdata->validCipherLen.len_bits, 7647 tdata->cipher.offset_bits, 7648 tdata->validAuthLen.len_bits, 7649 tdata->auth.offset_bits, 7650 op_mode, 1, verify); 7651 7652 if (retval < 0) 7653 return retval; 7654 7655 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 7656 7657 /* Check if the op failed because the device doesn't */ 7658 /* support this particular combination of algorithms */ 7659 if (op == NULL && ut_params->op->status == 7660 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 7661 printf("Device doesn't support this mixed combination. " 7662 "Test Skipped.\n"); 7663 return TEST_SKIPPED; 7664 } 7665 ut_params->op = op; 7666 7667 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 7668 7669 ut_params->obuf = (op_mode == IN_PLACE ? 7670 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 7671 7672 if (verify) { 7673 if (ut_params->obuf) 7674 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 7675 plaintext_len, buffer); 7676 else 7677 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7678 plaintext_len, buffer); 7679 7680 debug_hexdump(stdout, "plaintext:", plaintext, 7681 (tdata->plaintext.len_bits >> 3) - 7682 tdata->digest_enc.len); 7683 debug_hexdump(stdout, "plaintext expected:", 7684 tdata->plaintext.data, 7685 (tdata->plaintext.len_bits >> 3) - 7686 tdata->digest_enc.len); 7687 } else { 7688 if (ut_params->obuf) 7689 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 7690 ciphertext_len, buffer); 7691 else 7692 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7693 ciphertext_len, buffer); 7694 7695 debug_hexdump(stdout, "ciphertext:", ciphertext, 7696 ciphertext_len); 7697 debug_hexdump(stdout, "ciphertext expected:", 7698 tdata->ciphertext.data, 7699 tdata->ciphertext.len_bits >> 3); 7700 7701 if (ut_params->obuf) 7702 digest = rte_pktmbuf_read(ut_params->obuf, 7703 (tdata->digest_enc.offset == 0 ? 7704 plaintext_pad_len : 7705 tdata->digest_enc.offset), 7706 tdata->digest_enc.len, digest_buffer); 7707 else 7708 digest = rte_pktmbuf_read(ut_params->ibuf, 7709 (tdata->digest_enc.offset == 0 ? 7710 plaintext_pad_len : 7711 tdata->digest_enc.offset), 7712 tdata->digest_enc.len, digest_buffer); 7713 7714 debug_hexdump(stdout, "digest:", digest, 7715 tdata->digest_enc.len); 7716 debug_hexdump(stdout, "digest expected:", 7717 tdata->digest_enc.data, tdata->digest_enc.len); 7718 } 7719 7720 if (!verify) { 7721 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7722 digest, 7723 tdata->digest_enc.data, 7724 tdata->digest_enc.len, 7725 "Generated auth tag not as expected"); 7726 } 7727 7728 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 7729 if (verify) { 7730 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7731 plaintext, 7732 tdata->plaintext.data, 7733 tdata->plaintext.len_bits >> 3, 7734 "Plaintext data not as expected"); 7735 } else { 7736 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7737 ciphertext, 7738 tdata->ciphertext.data, 7739 tdata->validDataLen.len_bits, 7740 "Ciphertext data not as expected"); 7741 } 7742 } 7743 7744 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7745 "crypto op processing failed"); 7746 7747 return 0; 7748 } 7749 7750 /** AUTH AES CMAC + CIPHER AES CTR */ 7751 7752 static int 7753 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7754 { 7755 return test_mixed_auth_cipher( 7756 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7757 } 7758 7759 static int 7760 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7761 { 7762 return test_mixed_auth_cipher( 7763 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7764 } 7765 7766 static int 7767 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7768 { 7769 return test_mixed_auth_cipher_sgl( 7770 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7771 } 7772 7773 static int 7774 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7775 { 7776 return test_mixed_auth_cipher_sgl( 7777 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7778 } 7779 7780 static int 7781 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7782 { 7783 return test_mixed_auth_cipher( 7784 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7785 } 7786 7787 static int 7788 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7789 { 7790 return test_mixed_auth_cipher( 7791 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7792 } 7793 7794 static int 7795 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7796 { 7797 return test_mixed_auth_cipher_sgl( 7798 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7799 } 7800 7801 static int 7802 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7803 { 7804 return test_mixed_auth_cipher_sgl( 7805 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7806 } 7807 7808 /** MIXED AUTH + CIPHER */ 7809 7810 static int 7811 test_auth_zuc_cipher_snow_test_case_1(void) 7812 { 7813 return test_mixed_auth_cipher( 7814 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7815 } 7816 7817 static int 7818 test_verify_auth_zuc_cipher_snow_test_case_1(void) 7819 { 7820 return test_mixed_auth_cipher( 7821 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7822 } 7823 7824 static int 7825 test_auth_aes_cmac_cipher_snow_test_case_1(void) 7826 { 7827 return test_mixed_auth_cipher( 7828 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7829 } 7830 7831 static int 7832 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void) 7833 { 7834 return test_mixed_auth_cipher( 7835 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7836 } 7837 7838 static int 7839 test_auth_zuc_cipher_aes_ctr_test_case_1(void) 7840 { 7841 return test_mixed_auth_cipher( 7842 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7843 } 7844 7845 static int 7846 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void) 7847 { 7848 return test_mixed_auth_cipher( 7849 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7850 } 7851 7852 static int 7853 test_auth_snow_cipher_aes_ctr_test_case_1(void) 7854 { 7855 return test_mixed_auth_cipher( 7856 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7857 } 7858 7859 static int 7860 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void) 7861 { 7862 return test_mixed_auth_cipher( 7863 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7864 } 7865 7866 static int 7867 test_auth_snow_cipher_zuc_test_case_1(void) 7868 { 7869 return test_mixed_auth_cipher( 7870 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7871 } 7872 7873 static int 7874 test_verify_auth_snow_cipher_zuc_test_case_1(void) 7875 { 7876 return test_mixed_auth_cipher( 7877 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7878 } 7879 7880 static int 7881 test_auth_aes_cmac_cipher_zuc_test_case_1(void) 7882 { 7883 return test_mixed_auth_cipher( 7884 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7885 } 7886 7887 static int 7888 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void) 7889 { 7890 return test_mixed_auth_cipher( 7891 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7892 } 7893 7894 static int 7895 test_auth_null_cipher_snow_test_case_1(void) 7896 { 7897 return test_mixed_auth_cipher( 7898 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7899 } 7900 7901 static int 7902 test_verify_auth_null_cipher_snow_test_case_1(void) 7903 { 7904 return test_mixed_auth_cipher( 7905 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7906 } 7907 7908 static int 7909 test_auth_null_cipher_zuc_test_case_1(void) 7910 { 7911 return test_mixed_auth_cipher( 7912 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7913 } 7914 7915 static int 7916 test_verify_auth_null_cipher_zuc_test_case_1(void) 7917 { 7918 return test_mixed_auth_cipher( 7919 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7920 } 7921 7922 static int 7923 test_auth_snow_cipher_null_test_case_1(void) 7924 { 7925 return test_mixed_auth_cipher( 7926 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7927 } 7928 7929 static int 7930 test_verify_auth_snow_cipher_null_test_case_1(void) 7931 { 7932 return test_mixed_auth_cipher( 7933 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7934 } 7935 7936 static int 7937 test_auth_zuc_cipher_null_test_case_1(void) 7938 { 7939 return test_mixed_auth_cipher( 7940 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7941 } 7942 7943 static int 7944 test_verify_auth_zuc_cipher_null_test_case_1(void) 7945 { 7946 return test_mixed_auth_cipher( 7947 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7948 } 7949 7950 static int 7951 test_auth_null_cipher_aes_ctr_test_case_1(void) 7952 { 7953 return test_mixed_auth_cipher( 7954 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7955 } 7956 7957 static int 7958 test_verify_auth_null_cipher_aes_ctr_test_case_1(void) 7959 { 7960 return test_mixed_auth_cipher( 7961 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7962 } 7963 7964 static int 7965 test_auth_aes_cmac_cipher_null_test_case_1(void) 7966 { 7967 return test_mixed_auth_cipher( 7968 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7969 } 7970 7971 static int 7972 test_verify_auth_aes_cmac_cipher_null_test_case_1(void) 7973 { 7974 return test_mixed_auth_cipher( 7975 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7976 } 7977 7978 /* ***** AEAD algorithm Tests ***** */ 7979 7980 static int 7981 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo, 7982 enum rte_crypto_aead_operation op, 7983 const uint8_t *key, const uint8_t key_len, 7984 const uint16_t aad_len, const uint8_t auth_len, 7985 uint8_t iv_len) 7986 { 7987 uint8_t aead_key[key_len]; 7988 int status; 7989 7990 struct crypto_testsuite_params *ts_params = &testsuite_params; 7991 struct crypto_unittest_params *ut_params = &unittest_params; 7992 7993 memcpy(aead_key, key, key_len); 7994 7995 /* Setup AEAD Parameters */ 7996 ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 7997 ut_params->aead_xform.next = NULL; 7998 ut_params->aead_xform.aead.algo = algo; 7999 ut_params->aead_xform.aead.op = op; 8000 ut_params->aead_xform.aead.key.data = aead_key; 8001 ut_params->aead_xform.aead.key.length = key_len; 8002 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 8003 ut_params->aead_xform.aead.iv.length = iv_len; 8004 ut_params->aead_xform.aead.digest_length = auth_len; 8005 ut_params->aead_xform.aead.aad_length = aad_len; 8006 8007 debug_hexdump(stdout, "key:", key, key_len); 8008 8009 /* Create Crypto session*/ 8010 ut_params->sess = rte_cryptodev_sym_session_create( 8011 ts_params->session_mpool); 8012 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 8013 8014 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 8015 &ut_params->aead_xform, 8016 ts_params->session_priv_mpool); 8017 8018 return status; 8019 } 8020 8021 static int 8022 create_aead_xform(struct rte_crypto_op *op, 8023 enum rte_crypto_aead_algorithm algo, 8024 enum rte_crypto_aead_operation aead_op, 8025 uint8_t *key, const uint8_t key_len, 8026 const uint8_t aad_len, const uint8_t auth_len, 8027 uint8_t iv_len) 8028 { 8029 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1), 8030 "failed to allocate space for crypto transform"); 8031 8032 struct rte_crypto_sym_op *sym_op = op->sym; 8033 8034 /* Setup AEAD Parameters */ 8035 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD; 8036 sym_op->xform->next = NULL; 8037 sym_op->xform->aead.algo = algo; 8038 sym_op->xform->aead.op = aead_op; 8039 sym_op->xform->aead.key.data = key; 8040 sym_op->xform->aead.key.length = key_len; 8041 sym_op->xform->aead.iv.offset = IV_OFFSET; 8042 sym_op->xform->aead.iv.length = iv_len; 8043 sym_op->xform->aead.digest_length = auth_len; 8044 sym_op->xform->aead.aad_length = aad_len; 8045 8046 debug_hexdump(stdout, "key:", key, key_len); 8047 8048 return 0; 8049 } 8050 8051 static int 8052 create_aead_operation(enum rte_crypto_aead_operation op, 8053 const struct aead_test_data *tdata) 8054 { 8055 struct crypto_testsuite_params *ts_params = &testsuite_params; 8056 struct crypto_unittest_params *ut_params = &unittest_params; 8057 8058 uint8_t *plaintext, *ciphertext; 8059 unsigned int aad_pad_len, plaintext_pad_len; 8060 8061 /* Generate Crypto op data structure */ 8062 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8063 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8064 TEST_ASSERT_NOT_NULL(ut_params->op, 8065 "Failed to allocate symmetric crypto operation struct"); 8066 8067 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 8068 8069 /* Append aad data */ 8070 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 8071 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16); 8072 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8073 aad_pad_len); 8074 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8075 "no room to append aad"); 8076 8077 sym_op->aead.aad.phys_addr = 8078 rte_pktmbuf_iova(ut_params->ibuf); 8079 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 8080 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len); 8081 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 8082 tdata->aad.len); 8083 8084 /* Append IV at the end of the crypto operation*/ 8085 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8086 uint8_t *, IV_OFFSET); 8087 8088 /* Copy IV 1 byte after the IV pointer, according to the API */ 8089 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len); 8090 debug_hexdump(stdout, "iv:", iv_ptr, 8091 tdata->iv.len); 8092 } else { 8093 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 8094 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8095 aad_pad_len); 8096 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8097 "no room to append aad"); 8098 8099 sym_op->aead.aad.phys_addr = 8100 rte_pktmbuf_iova(ut_params->ibuf); 8101 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len); 8102 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 8103 tdata->aad.len); 8104 8105 /* Append IV at the end of the crypto operation*/ 8106 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8107 uint8_t *, IV_OFFSET); 8108 8109 if (tdata->iv.len == 0) { 8110 rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH); 8111 debug_hexdump(stdout, "iv:", iv_ptr, 8112 AES_GCM_J0_LENGTH); 8113 } else { 8114 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 8115 debug_hexdump(stdout, "iv:", iv_ptr, 8116 tdata->iv.len); 8117 } 8118 } 8119 8120 /* Append plaintext/ciphertext */ 8121 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 8122 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 8123 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8124 plaintext_pad_len); 8125 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 8126 8127 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 8128 debug_hexdump(stdout, "plaintext:", plaintext, 8129 tdata->plaintext.len); 8130 8131 if (ut_params->obuf) { 8132 ciphertext = (uint8_t *)rte_pktmbuf_append( 8133 ut_params->obuf, 8134 plaintext_pad_len + aad_pad_len); 8135 TEST_ASSERT_NOT_NULL(ciphertext, 8136 "no room to append ciphertext"); 8137 8138 memset(ciphertext + aad_pad_len, 0, 8139 tdata->ciphertext.len); 8140 } 8141 } else { 8142 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); 8143 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8144 plaintext_pad_len); 8145 TEST_ASSERT_NOT_NULL(ciphertext, 8146 "no room to append ciphertext"); 8147 8148 memcpy(ciphertext, tdata->ciphertext.data, 8149 tdata->ciphertext.len); 8150 debug_hexdump(stdout, "ciphertext:", ciphertext, 8151 tdata->ciphertext.len); 8152 8153 if (ut_params->obuf) { 8154 plaintext = (uint8_t *)rte_pktmbuf_append( 8155 ut_params->obuf, 8156 plaintext_pad_len + aad_pad_len); 8157 TEST_ASSERT_NOT_NULL(plaintext, 8158 "no room to append plaintext"); 8159 8160 memset(plaintext + aad_pad_len, 0, 8161 tdata->plaintext.len); 8162 } 8163 } 8164 8165 /* Append digest data */ 8166 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 8167 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 8168 ut_params->obuf ? ut_params->obuf : 8169 ut_params->ibuf, 8170 tdata->auth_tag.len); 8171 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 8172 "no room to append digest"); 8173 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len); 8174 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 8175 ut_params->obuf ? ut_params->obuf : 8176 ut_params->ibuf, 8177 plaintext_pad_len + 8178 aad_pad_len); 8179 } else { 8180 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 8181 ut_params->ibuf, tdata->auth_tag.len); 8182 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 8183 "no room to append digest"); 8184 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 8185 ut_params->ibuf, 8186 plaintext_pad_len + aad_pad_len); 8187 8188 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 8189 tdata->auth_tag.len); 8190 debug_hexdump(stdout, "digest:", 8191 sym_op->aead.digest.data, 8192 tdata->auth_tag.len); 8193 } 8194 8195 sym_op->aead.data.length = tdata->plaintext.len; 8196 sym_op->aead.data.offset = aad_pad_len; 8197 8198 return 0; 8199 } 8200 8201 static int 8202 test_authenticated_encryption(const struct aead_test_data *tdata) 8203 { 8204 struct crypto_testsuite_params *ts_params = &testsuite_params; 8205 struct crypto_unittest_params *ut_params = &unittest_params; 8206 8207 int retval; 8208 uint8_t *ciphertext, *auth_tag; 8209 uint16_t plaintext_pad_len; 8210 uint32_t i; 8211 struct rte_cryptodev_info dev_info; 8212 8213 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8214 uint64_t feat_flags = dev_info.feature_flags; 8215 8216 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 8217 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 8218 printf("Device doesn't support RAW data-path APIs.\n"); 8219 return TEST_SKIPPED; 8220 } 8221 8222 /* Verify the capabilities */ 8223 struct rte_cryptodev_sym_capability_idx cap_idx; 8224 const struct rte_cryptodev_symmetric_capability *capability; 8225 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 8226 cap_idx.algo.aead = tdata->algo; 8227 capability = rte_cryptodev_sym_capability_get( 8228 ts_params->valid_devs[0], &cap_idx); 8229 if (capability == NULL) 8230 return TEST_SKIPPED; 8231 if (rte_cryptodev_sym_capability_check_aead( 8232 capability, tdata->key.len, tdata->auth_tag.len, 8233 tdata->aad.len, tdata->iv.len)) 8234 return TEST_SKIPPED; 8235 8236 /* Create AEAD session */ 8237 retval = create_aead_session(ts_params->valid_devs[0], 8238 tdata->algo, 8239 RTE_CRYPTO_AEAD_OP_ENCRYPT, 8240 tdata->key.data, tdata->key.len, 8241 tdata->aad.len, tdata->auth_tag.len, 8242 tdata->iv.len); 8243 if (retval < 0) 8244 return retval; 8245 8246 if (tdata->aad.len > MBUF_SIZE) { 8247 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 8248 /* Populate full size of add data */ 8249 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 8250 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 8251 } else 8252 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8253 8254 /* clear mbuf payload */ 8255 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8256 rte_pktmbuf_tailroom(ut_params->ibuf)); 8257 8258 /* Create AEAD operation */ 8259 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 8260 if (retval < 0) 8261 return retval; 8262 8263 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 8264 8265 ut_params->op->sym->m_src = ut_params->ibuf; 8266 8267 /* Process crypto operation */ 8268 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8269 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 8270 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 8271 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 8272 ut_params->op, 0, 0, 0, 0); 8273 else 8274 TEST_ASSERT_NOT_NULL( 8275 process_crypto_request(ts_params->valid_devs[0], 8276 ut_params->op), "failed to process sym crypto op"); 8277 8278 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8279 "crypto op processing failed"); 8280 8281 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 8282 8283 if (ut_params->op->sym->m_dst) { 8284 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8285 uint8_t *); 8286 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 8287 uint8_t *, plaintext_pad_len); 8288 } else { 8289 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 8290 uint8_t *, 8291 ut_params->op->sym->cipher.data.offset); 8292 auth_tag = ciphertext + plaintext_pad_len; 8293 } 8294 8295 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 8296 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 8297 8298 /* Validate obuf */ 8299 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8300 ciphertext, 8301 tdata->ciphertext.data, 8302 tdata->ciphertext.len, 8303 "Ciphertext data not as expected"); 8304 8305 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8306 auth_tag, 8307 tdata->auth_tag.data, 8308 tdata->auth_tag.len, 8309 "Generated auth tag not as expected"); 8310 8311 return 0; 8312 8313 } 8314 8315 #ifdef RTE_LIB_SECURITY 8316 static int 8317 security_proto_supported(enum rte_security_session_action_type action, 8318 enum rte_security_session_protocol proto) 8319 { 8320 struct crypto_testsuite_params *ts_params = &testsuite_params; 8321 8322 const struct rte_security_capability *capabilities; 8323 const struct rte_security_capability *capability; 8324 uint16_t i = 0; 8325 8326 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8327 rte_cryptodev_get_sec_ctx( 8328 ts_params->valid_devs[0]); 8329 8330 8331 capabilities = rte_security_capabilities_get(ctx); 8332 8333 if (capabilities == NULL) 8334 return -ENOTSUP; 8335 8336 while ((capability = &capabilities[i++])->action != 8337 RTE_SECURITY_ACTION_TYPE_NONE) { 8338 if (capability->action == action && 8339 capability->protocol == proto) 8340 return 0; 8341 } 8342 8343 return -ENOTSUP; 8344 } 8345 8346 /* Basic algorithm run function for async inplace mode. 8347 * Creates a session from input parameters and runs one operation 8348 * on input_vec. Checks the output of the crypto operation against 8349 * output_vec. 8350 */ 8351 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc, 8352 enum rte_crypto_auth_operation opa, 8353 const uint8_t *input_vec, unsigned int input_vec_len, 8354 const uint8_t *output_vec, 8355 unsigned int output_vec_len, 8356 enum rte_crypto_cipher_algorithm cipher_alg, 8357 const uint8_t *cipher_key, uint32_t cipher_key_len, 8358 enum rte_crypto_auth_algorithm auth_alg, 8359 const uint8_t *auth_key, uint32_t auth_key_len, 8360 uint8_t bearer, enum rte_security_pdcp_domain domain, 8361 uint8_t packet_direction, uint8_t sn_size, 8362 uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap) 8363 { 8364 struct crypto_testsuite_params *ts_params = &testsuite_params; 8365 struct crypto_unittest_params *ut_params = &unittest_params; 8366 uint8_t *plaintext; 8367 int ret = TEST_SUCCESS; 8368 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8369 rte_cryptodev_get_sec_ctx( 8370 ts_params->valid_devs[0]); 8371 struct rte_cryptodev_info dev_info; 8372 uint64_t feat_flags; 8373 8374 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8375 feat_flags = dev_info.feature_flags; 8376 8377 /* Verify the capabilities */ 8378 struct rte_security_capability_idx sec_cap_idx; 8379 8380 sec_cap_idx.action = ut_params->type; 8381 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 8382 sec_cap_idx.pdcp.domain = domain; 8383 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 8384 return TEST_SKIPPED; 8385 8386 /* Generate test mbuf data */ 8387 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8388 8389 /* clear mbuf payload */ 8390 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8391 rte_pktmbuf_tailroom(ut_params->ibuf)); 8392 8393 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8394 input_vec_len); 8395 memcpy(plaintext, input_vec, input_vec_len); 8396 8397 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 8398 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 8399 printf("Device does not support RAW data-path APIs.\n"); 8400 return TEST_SKIPPED; 8401 } 8402 /* Out of place support */ 8403 if (oop) { 8404 /* 8405 * For out-op-place we need to alloc another mbuf 8406 */ 8407 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8408 rte_pktmbuf_append(ut_params->obuf, output_vec_len); 8409 } 8410 8411 /* Setup Cipher Parameters */ 8412 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8413 ut_params->cipher_xform.cipher.algo = cipher_alg; 8414 ut_params->cipher_xform.cipher.op = opc; 8415 ut_params->cipher_xform.cipher.key.data = cipher_key; 8416 ut_params->cipher_xform.cipher.key.length = cipher_key_len; 8417 ut_params->cipher_xform.cipher.iv.length = 8418 packet_direction ? 4 : 0; 8419 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 8420 8421 /* Setup HMAC Parameters if ICV header is required */ 8422 if (auth_alg != 0) { 8423 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8424 ut_params->auth_xform.next = NULL; 8425 ut_params->auth_xform.auth.algo = auth_alg; 8426 ut_params->auth_xform.auth.op = opa; 8427 ut_params->auth_xform.auth.key.data = auth_key; 8428 ut_params->auth_xform.auth.key.length = auth_key_len; 8429 8430 ut_params->cipher_xform.next = &ut_params->auth_xform; 8431 } else { 8432 ut_params->cipher_xform.next = NULL; 8433 } 8434 8435 struct rte_security_session_conf sess_conf = { 8436 .action_type = ut_params->type, 8437 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 8438 {.pdcp = { 8439 .bearer = bearer, 8440 .domain = domain, 8441 .pkt_dir = packet_direction, 8442 .sn_size = sn_size, 8443 .hfn = packet_direction ? 0 : hfn, 8444 /** 8445 * hfn can be set as pdcp_test_hfn[i] 8446 * if hfn_ovrd is not set. Here, PDCP 8447 * packet direction is just used to 8448 * run half of the cases with session 8449 * HFN and other half with per packet 8450 * HFN. 8451 */ 8452 .hfn_threshold = hfn_threshold, 8453 .hfn_ovrd = packet_direction ? 1 : 0, 8454 .sdap_enabled = sdap, 8455 } }, 8456 .crypto_xform = &ut_params->cipher_xform 8457 }; 8458 8459 /* Create security session */ 8460 ut_params->sec_session = rte_security_session_create(ctx, 8461 &sess_conf, ts_params->session_mpool, 8462 ts_params->session_priv_mpool); 8463 8464 if (!ut_params->sec_session) { 8465 printf("TestCase %s()-%d line %d failed %s: ", 8466 __func__, i, __LINE__, "Failed to allocate session"); 8467 ret = TEST_FAILED; 8468 goto on_err; 8469 } 8470 8471 /* Generate crypto op data structure */ 8472 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8473 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8474 if (!ut_params->op) { 8475 printf("TestCase %s()-%d line %d failed %s: ", 8476 __func__, i, __LINE__, 8477 "Failed to allocate symmetric crypto operation struct"); 8478 ret = TEST_FAILED; 8479 goto on_err; 8480 } 8481 8482 uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op, 8483 uint32_t *, IV_OFFSET); 8484 *per_pkt_hfn = packet_direction ? hfn : 0; 8485 8486 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8487 8488 /* set crypto operation source mbuf */ 8489 ut_params->op->sym->m_src = ut_params->ibuf; 8490 if (oop) 8491 ut_params->op->sym->m_dst = ut_params->obuf; 8492 8493 /* Process crypto operation */ 8494 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 8495 /* filling lengths */ 8496 ut_params->op->sym->cipher.data.length = ut_params->op->sym->m_src->pkt_len; 8497 ut_params->op->sym->auth.data.length = ut_params->op->sym->m_src->pkt_len; 8498 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 8499 ut_params->op, 1, 1, 0, 0); 8500 } else { 8501 ut_params->op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 8502 } 8503 if (ut_params->op == NULL) { 8504 printf("TestCase %s()-%d line %d failed %s: ", 8505 __func__, i, __LINE__, 8506 "failed to process sym crypto op"); 8507 ret = TEST_FAILED; 8508 goto on_err; 8509 } 8510 8511 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8512 printf("TestCase %s()-%d line %d failed %s: ", 8513 __func__, i, __LINE__, "crypto op processing failed"); 8514 ret = TEST_FAILED; 8515 goto on_err; 8516 } 8517 8518 /* Validate obuf */ 8519 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 8520 uint8_t *); 8521 if (oop) { 8522 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8523 uint8_t *); 8524 } 8525 8526 if (memcmp(ciphertext, output_vec, output_vec_len)) { 8527 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8528 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len); 8529 rte_hexdump(stdout, "reference", output_vec, output_vec_len); 8530 ret = TEST_FAILED; 8531 goto on_err; 8532 } 8533 8534 on_err: 8535 rte_crypto_op_free(ut_params->op); 8536 ut_params->op = NULL; 8537 8538 if (ut_params->sec_session) 8539 rte_security_session_destroy(ctx, ut_params->sec_session); 8540 ut_params->sec_session = NULL; 8541 8542 rte_pktmbuf_free(ut_params->ibuf); 8543 ut_params->ibuf = NULL; 8544 if (oop) { 8545 rte_pktmbuf_free(ut_params->obuf); 8546 ut_params->obuf = NULL; 8547 } 8548 8549 return ret; 8550 } 8551 8552 static int 8553 test_pdcp_proto_SGL(int i, int oop, 8554 enum rte_crypto_cipher_operation opc, 8555 enum rte_crypto_auth_operation opa, 8556 uint8_t *input_vec, 8557 unsigned int input_vec_len, 8558 uint8_t *output_vec, 8559 unsigned int output_vec_len, 8560 uint32_t fragsz, 8561 uint32_t fragsz_oop) 8562 { 8563 struct crypto_testsuite_params *ts_params = &testsuite_params; 8564 struct crypto_unittest_params *ut_params = &unittest_params; 8565 uint8_t *plaintext; 8566 struct rte_mbuf *buf, *buf_oop = NULL; 8567 int ret = TEST_SUCCESS; 8568 int to_trn = 0; 8569 int to_trn_tbl[16]; 8570 int segs = 1; 8571 unsigned int trn_data = 0; 8572 struct rte_cryptodev_info dev_info; 8573 uint64_t feat_flags; 8574 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8575 rte_cryptodev_get_sec_ctx( 8576 ts_params->valid_devs[0]); 8577 struct rte_mbuf *temp_mbuf; 8578 8579 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8580 feat_flags = dev_info.feature_flags; 8581 8582 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 8583 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 8584 printf("Device does not support RAW data-path APIs.\n"); 8585 return -ENOTSUP; 8586 } 8587 /* Verify the capabilities */ 8588 struct rte_security_capability_idx sec_cap_idx; 8589 8590 sec_cap_idx.action = ut_params->type; 8591 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 8592 sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain; 8593 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 8594 return TEST_SKIPPED; 8595 8596 if (fragsz > input_vec_len) 8597 fragsz = input_vec_len; 8598 8599 uint16_t plaintext_len = fragsz; 8600 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 8601 8602 if (fragsz_oop > output_vec_len) 8603 frag_size_oop = output_vec_len; 8604 8605 int ecx = 0; 8606 if (input_vec_len % fragsz != 0) { 8607 if (input_vec_len / fragsz + 1 > 16) 8608 return 1; 8609 } else if (input_vec_len / fragsz > 16) 8610 return 1; 8611 8612 /* Out of place support */ 8613 if (oop) { 8614 /* 8615 * For out-op-place we need to alloc another mbuf 8616 */ 8617 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8618 rte_pktmbuf_append(ut_params->obuf, frag_size_oop); 8619 buf_oop = ut_params->obuf; 8620 } 8621 8622 /* Generate test mbuf data */ 8623 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8624 8625 /* clear mbuf payload */ 8626 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8627 rte_pktmbuf_tailroom(ut_params->ibuf)); 8628 8629 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8630 plaintext_len); 8631 memcpy(plaintext, input_vec, plaintext_len); 8632 trn_data += plaintext_len; 8633 8634 buf = ut_params->ibuf; 8635 8636 /* 8637 * Loop until no more fragments 8638 */ 8639 8640 while (trn_data < input_vec_len) { 8641 ++segs; 8642 to_trn = (input_vec_len - trn_data < fragsz) ? 8643 (input_vec_len - trn_data) : fragsz; 8644 8645 to_trn_tbl[ecx++] = to_trn; 8646 8647 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8648 buf = buf->next; 8649 8650 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 8651 rte_pktmbuf_tailroom(buf)); 8652 8653 /* OOP */ 8654 if (oop && !fragsz_oop) { 8655 buf_oop->next = 8656 rte_pktmbuf_alloc(ts_params->mbuf_pool); 8657 buf_oop = buf_oop->next; 8658 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 8659 0, rte_pktmbuf_tailroom(buf_oop)); 8660 rte_pktmbuf_append(buf_oop, to_trn); 8661 } 8662 8663 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 8664 to_trn); 8665 8666 memcpy(plaintext, input_vec + trn_data, to_trn); 8667 trn_data += to_trn; 8668 } 8669 8670 ut_params->ibuf->nb_segs = segs; 8671 8672 segs = 1; 8673 if (fragsz_oop && oop) { 8674 to_trn = 0; 8675 ecx = 0; 8676 8677 trn_data = frag_size_oop; 8678 while (trn_data < output_vec_len) { 8679 ++segs; 8680 to_trn = 8681 (output_vec_len - trn_data < 8682 frag_size_oop) ? 8683 (output_vec_len - trn_data) : 8684 frag_size_oop; 8685 8686 to_trn_tbl[ecx++] = to_trn; 8687 8688 buf_oop->next = 8689 rte_pktmbuf_alloc(ts_params->mbuf_pool); 8690 buf_oop = buf_oop->next; 8691 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 8692 0, rte_pktmbuf_tailroom(buf_oop)); 8693 rte_pktmbuf_append(buf_oop, to_trn); 8694 8695 trn_data += to_trn; 8696 } 8697 ut_params->obuf->nb_segs = segs; 8698 } 8699 8700 /* Setup Cipher Parameters */ 8701 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8702 ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg; 8703 ut_params->cipher_xform.cipher.op = opc; 8704 ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i]; 8705 ut_params->cipher_xform.cipher.key.length = 8706 pdcp_test_params[i].cipher_key_len; 8707 ut_params->cipher_xform.cipher.iv.length = 0; 8708 8709 /* Setup HMAC Parameters if ICV header is required */ 8710 if (pdcp_test_params[i].auth_alg != 0) { 8711 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8712 ut_params->auth_xform.next = NULL; 8713 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg; 8714 ut_params->auth_xform.auth.op = opa; 8715 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i]; 8716 ut_params->auth_xform.auth.key.length = 8717 pdcp_test_params[i].auth_key_len; 8718 8719 ut_params->cipher_xform.next = &ut_params->auth_xform; 8720 } else { 8721 ut_params->cipher_xform.next = NULL; 8722 } 8723 8724 struct rte_security_session_conf sess_conf = { 8725 .action_type = ut_params->type, 8726 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 8727 {.pdcp = { 8728 .bearer = pdcp_test_bearer[i], 8729 .domain = pdcp_test_params[i].domain, 8730 .pkt_dir = pdcp_test_packet_direction[i], 8731 .sn_size = pdcp_test_data_sn_size[i], 8732 .hfn = pdcp_test_hfn[i], 8733 .hfn_threshold = pdcp_test_hfn_threshold[i], 8734 .hfn_ovrd = 0, 8735 } }, 8736 .crypto_xform = &ut_params->cipher_xform 8737 }; 8738 8739 /* Create security session */ 8740 ut_params->sec_session = rte_security_session_create(ctx, 8741 &sess_conf, ts_params->session_mpool, 8742 ts_params->session_priv_mpool); 8743 8744 if (!ut_params->sec_session) { 8745 printf("TestCase %s()-%d line %d failed %s: ", 8746 __func__, i, __LINE__, "Failed to allocate session"); 8747 ret = TEST_FAILED; 8748 goto on_err; 8749 } 8750 8751 /* Generate crypto op data structure */ 8752 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8753 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8754 if (!ut_params->op) { 8755 printf("TestCase %s()-%d line %d failed %s: ", 8756 __func__, i, __LINE__, 8757 "Failed to allocate symmetric crypto operation struct"); 8758 ret = TEST_FAILED; 8759 goto on_err; 8760 } 8761 8762 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8763 8764 /* set crypto operation source mbuf */ 8765 ut_params->op->sym->m_src = ut_params->ibuf; 8766 if (oop) 8767 ut_params->op->sym->m_dst = ut_params->obuf; 8768 8769 /* Process crypto operation */ 8770 temp_mbuf = ut_params->op->sym->m_src; 8771 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 8772 /* filling lengths */ 8773 while (temp_mbuf) { 8774 ut_params->op->sym->cipher.data.length 8775 += temp_mbuf->pkt_len; 8776 ut_params->op->sym->auth.data.length 8777 += temp_mbuf->pkt_len; 8778 temp_mbuf = temp_mbuf->next; 8779 } 8780 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 8781 ut_params->op, 1, 1, 0, 0); 8782 } else { 8783 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 8784 ut_params->op); 8785 } 8786 if (ut_params->op == NULL) { 8787 printf("TestCase %s()-%d line %d failed %s: ", 8788 __func__, i, __LINE__, 8789 "failed to process sym crypto op"); 8790 ret = TEST_FAILED; 8791 goto on_err; 8792 } 8793 8794 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8795 printf("TestCase %s()-%d line %d failed %s: ", 8796 __func__, i, __LINE__, "crypto op processing failed"); 8797 ret = TEST_FAILED; 8798 goto on_err; 8799 } 8800 8801 /* Validate obuf */ 8802 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 8803 uint8_t *); 8804 if (oop) { 8805 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8806 uint8_t *); 8807 } 8808 if (fragsz_oop) 8809 fragsz = frag_size_oop; 8810 if (memcmp(ciphertext, output_vec, fragsz)) { 8811 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8812 rte_hexdump(stdout, "encrypted", ciphertext, fragsz); 8813 rte_hexdump(stdout, "reference", output_vec, fragsz); 8814 ret = TEST_FAILED; 8815 goto on_err; 8816 } 8817 8818 buf = ut_params->op->sym->m_src->next; 8819 if (oop) 8820 buf = ut_params->op->sym->m_dst->next; 8821 8822 unsigned int off = fragsz; 8823 8824 ecx = 0; 8825 while (buf) { 8826 ciphertext = rte_pktmbuf_mtod(buf, 8827 uint8_t *); 8828 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) { 8829 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8830 rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]); 8831 rte_hexdump(stdout, "reference", output_vec + off, 8832 to_trn_tbl[ecx]); 8833 ret = TEST_FAILED; 8834 goto on_err; 8835 } 8836 off += to_trn_tbl[ecx++]; 8837 buf = buf->next; 8838 } 8839 on_err: 8840 rte_crypto_op_free(ut_params->op); 8841 ut_params->op = NULL; 8842 8843 if (ut_params->sec_session) 8844 rte_security_session_destroy(ctx, ut_params->sec_session); 8845 ut_params->sec_session = NULL; 8846 8847 rte_pktmbuf_free(ut_params->ibuf); 8848 ut_params->ibuf = NULL; 8849 if (oop) { 8850 rte_pktmbuf_free(ut_params->obuf); 8851 ut_params->obuf = NULL; 8852 } 8853 8854 return ret; 8855 } 8856 8857 int 8858 test_pdcp_proto_cplane_encap(int i) 8859 { 8860 return test_pdcp_proto( 8861 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8862 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8863 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8864 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8865 pdcp_test_params[i].cipher_key_len, 8866 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8867 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8868 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8869 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8870 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8871 } 8872 8873 int 8874 test_pdcp_proto_uplane_encap(int i) 8875 { 8876 return test_pdcp_proto( 8877 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8878 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8879 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 8880 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8881 pdcp_test_params[i].cipher_key_len, 8882 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8883 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8884 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8885 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8886 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8887 } 8888 8889 int 8890 test_pdcp_proto_uplane_encap_with_int(int i) 8891 { 8892 return test_pdcp_proto( 8893 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8894 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8895 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8896 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8897 pdcp_test_params[i].cipher_key_len, 8898 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8899 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8900 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8901 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8902 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8903 } 8904 8905 int 8906 test_pdcp_proto_cplane_decap(int i) 8907 { 8908 return test_pdcp_proto( 8909 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8910 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8911 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8912 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8913 pdcp_test_params[i].cipher_key_len, 8914 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8915 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8916 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8917 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8918 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8919 } 8920 8921 int 8922 test_pdcp_proto_uplane_decap(int i) 8923 { 8924 return test_pdcp_proto( 8925 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8926 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 8927 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8928 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8929 pdcp_test_params[i].cipher_key_len, 8930 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8931 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8932 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8933 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8934 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8935 } 8936 8937 int 8938 test_pdcp_proto_uplane_decap_with_int(int i) 8939 { 8940 return test_pdcp_proto( 8941 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8942 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8943 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8944 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8945 pdcp_test_params[i].cipher_key_len, 8946 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8947 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8948 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8949 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8950 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8951 } 8952 8953 static int 8954 test_PDCP_PROTO_SGL_in_place_32B(void) 8955 { 8956 /* i can be used for running any PDCP case 8957 * In this case it is uplane 12-bit AES-SNOW DL encap 8958 */ 8959 int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK; 8960 return test_pdcp_proto_SGL(i, IN_PLACE, 8961 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8962 RTE_CRYPTO_AUTH_OP_GENERATE, 8963 pdcp_test_data_in[i], 8964 pdcp_test_data_in_len[i], 8965 pdcp_test_data_out[i], 8966 pdcp_test_data_in_len[i]+4, 8967 32, 0); 8968 } 8969 static int 8970 test_PDCP_PROTO_SGL_oop_32B_128B(void) 8971 { 8972 /* i can be used for running any PDCP case 8973 * In this case it is uplane 18-bit NULL-NULL DL encap 8974 */ 8975 int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK; 8976 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8977 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8978 RTE_CRYPTO_AUTH_OP_GENERATE, 8979 pdcp_test_data_in[i], 8980 pdcp_test_data_in_len[i], 8981 pdcp_test_data_out[i], 8982 pdcp_test_data_in_len[i]+4, 8983 32, 128); 8984 } 8985 static int 8986 test_PDCP_PROTO_SGL_oop_32B_40B(void) 8987 { 8988 /* i can be used for running any PDCP case 8989 * In this case it is uplane 18-bit AES DL encap 8990 */ 8991 int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET 8992 + DOWNLINK; 8993 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8994 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8995 RTE_CRYPTO_AUTH_OP_GENERATE, 8996 pdcp_test_data_in[i], 8997 pdcp_test_data_in_len[i], 8998 pdcp_test_data_out[i], 8999 pdcp_test_data_in_len[i], 9000 32, 40); 9001 } 9002 static int 9003 test_PDCP_PROTO_SGL_oop_128B_32B(void) 9004 { 9005 /* i can be used for running any PDCP case 9006 * In this case it is cplane 12-bit AES-ZUC DL encap 9007 */ 9008 int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK; 9009 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9010 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9011 RTE_CRYPTO_AUTH_OP_GENERATE, 9012 pdcp_test_data_in[i], 9013 pdcp_test_data_in_len[i], 9014 pdcp_test_data_out[i], 9015 pdcp_test_data_in_len[i]+4, 9016 128, 32); 9017 } 9018 9019 static int 9020 test_PDCP_SDAP_PROTO_encap_all(void) 9021 { 9022 int i = 0, size = 0; 9023 int err, all_err = TEST_SUCCESS; 9024 const struct pdcp_sdap_test *cur_test; 9025 9026 size = RTE_DIM(list_pdcp_sdap_tests); 9027 9028 for (i = 0; i < size; i++) { 9029 cur_test = &list_pdcp_sdap_tests[i]; 9030 err = test_pdcp_proto( 9031 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9032 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9033 cur_test->in_len, cur_test->data_out, 9034 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9035 cur_test->param.cipher_alg, cur_test->cipher_key, 9036 cur_test->param.cipher_key_len, 9037 cur_test->param.auth_alg, 9038 cur_test->auth_key, cur_test->param.auth_key_len, 9039 cur_test->bearer, cur_test->param.domain, 9040 cur_test->packet_direction, cur_test->sn_size, 9041 cur_test->hfn, 9042 cur_test->hfn_threshold, SDAP_ENABLED); 9043 if (err) { 9044 printf("\t%d) %s: Encapsulation failed\n", 9045 cur_test->test_idx, 9046 cur_test->param.name); 9047 err = TEST_FAILED; 9048 } else { 9049 printf("\t%d) %s: Encap PASS\n", cur_test->test_idx, 9050 cur_test->param.name); 9051 err = TEST_SUCCESS; 9052 } 9053 all_err += err; 9054 } 9055 9056 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9057 9058 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9059 } 9060 9061 static int 9062 test_PDCP_PROTO_short_mac(void) 9063 { 9064 int i = 0, size = 0; 9065 int err, all_err = TEST_SUCCESS; 9066 const struct pdcp_short_mac_test *cur_test; 9067 9068 size = RTE_DIM(list_pdcp_smac_tests); 9069 9070 for (i = 0; i < size; i++) { 9071 cur_test = &list_pdcp_smac_tests[i]; 9072 err = test_pdcp_proto( 9073 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9074 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9075 cur_test->in_len, cur_test->data_out, 9076 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9077 RTE_CRYPTO_CIPHER_NULL, NULL, 9078 0, cur_test->param.auth_alg, 9079 cur_test->auth_key, cur_test->param.auth_key_len, 9080 0, cur_test->param.domain, 0, 0, 9081 0, 0, 0); 9082 if (err) { 9083 printf("\t%d) %s: Short MAC test failed\n", 9084 cur_test->test_idx, 9085 cur_test->param.name); 9086 err = TEST_FAILED; 9087 } else { 9088 printf("\t%d) %s: Short MAC test PASS\n", 9089 cur_test->test_idx, 9090 cur_test->param.name); 9091 rte_hexdump(stdout, "MAC I", 9092 cur_test->data_out + cur_test->in_len + 2, 9093 2); 9094 err = TEST_SUCCESS; 9095 } 9096 all_err += err; 9097 } 9098 9099 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9100 9101 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9102 9103 } 9104 9105 static int 9106 test_PDCP_SDAP_PROTO_decap_all(void) 9107 { 9108 int i = 0, size = 0; 9109 int err, all_err = TEST_SUCCESS; 9110 const struct pdcp_sdap_test *cur_test; 9111 9112 size = RTE_DIM(list_pdcp_sdap_tests); 9113 9114 for (i = 0; i < size; i++) { 9115 cur_test = &list_pdcp_sdap_tests[i]; 9116 err = test_pdcp_proto( 9117 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, 9118 RTE_CRYPTO_AUTH_OP_VERIFY, 9119 cur_test->data_out, 9120 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9121 cur_test->data_in, cur_test->in_len, 9122 cur_test->param.cipher_alg, 9123 cur_test->cipher_key, cur_test->param.cipher_key_len, 9124 cur_test->param.auth_alg, cur_test->auth_key, 9125 cur_test->param.auth_key_len, cur_test->bearer, 9126 cur_test->param.domain, cur_test->packet_direction, 9127 cur_test->sn_size, cur_test->hfn, 9128 cur_test->hfn_threshold, SDAP_ENABLED); 9129 if (err) { 9130 printf("\t%d) %s: Decapsulation failed\n", 9131 cur_test->test_idx, 9132 cur_test->param.name); 9133 err = TEST_FAILED; 9134 } else { 9135 printf("\t%d) %s: Decap PASS\n", cur_test->test_idx, 9136 cur_test->param.name); 9137 err = TEST_SUCCESS; 9138 } 9139 all_err += err; 9140 } 9141 9142 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9143 9144 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9145 } 9146 9147 static int 9148 test_ipsec_proto_process(const struct ipsec_test_data td[], 9149 struct ipsec_test_data res_d[], 9150 int nb_td, 9151 bool silent, 9152 const struct ipsec_test_flags *flags) 9153 { 9154 uint16_t v6_src[8] = {0x2607, 0xf8b0, 0x400c, 0x0c03, 0x0000, 0x0000, 9155 0x0000, 0x001a}; 9156 uint16_t v6_dst[8] = {0x2001, 0x0470, 0xe5bf, 0xdead, 0x4957, 0x2174, 9157 0xe82c, 0x4887}; 9158 const struct rte_ipv4_hdr *ipv4 = 9159 (const struct rte_ipv4_hdr *)td[0].output_text.data; 9160 struct crypto_testsuite_params *ts_params = &testsuite_params; 9161 struct crypto_unittest_params *ut_params = &unittest_params; 9162 struct rte_security_capability_idx sec_cap_idx; 9163 const struct rte_security_capability *sec_cap; 9164 struct rte_security_ipsec_xform ipsec_xform; 9165 uint8_t dev_id = ts_params->valid_devs[0]; 9166 enum rte_security_ipsec_sa_direction dir; 9167 struct ipsec_test_data *res_d_tmp = NULL; 9168 int salt_len, i, ret = TEST_SUCCESS; 9169 struct rte_security_ctx *ctx; 9170 uint8_t *input_text; 9171 uint32_t src, dst; 9172 uint32_t verify; 9173 9174 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 9175 gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 9176 9177 /* Use first test data to create session */ 9178 9179 /* Copy IPsec xform */ 9180 memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform)); 9181 9182 dir = ipsec_xform.direction; 9183 verify = flags->tunnel_hdr_verify; 9184 9185 memcpy(&src, &ipv4->src_addr, sizeof(ipv4->src_addr)); 9186 memcpy(&dst, &ipv4->dst_addr, sizeof(ipv4->dst_addr)); 9187 9188 if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) { 9189 if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR) 9190 src += 1; 9191 else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR) 9192 dst += 1; 9193 } 9194 9195 if (td->ipsec_xform.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) { 9196 if (td->ipsec_xform.tunnel.type == 9197 RTE_SECURITY_IPSEC_TUNNEL_IPV4) { 9198 memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, 9199 sizeof(src)); 9200 memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, 9201 sizeof(dst)); 9202 9203 if (flags->df == TEST_IPSEC_SET_DF_0_INNER_1) 9204 ipsec_xform.tunnel.ipv4.df = 0; 9205 9206 if (flags->df == TEST_IPSEC_SET_DF_1_INNER_0) 9207 ipsec_xform.tunnel.ipv4.df = 1; 9208 9209 if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1) 9210 ipsec_xform.tunnel.ipv4.dscp = 0; 9211 9212 if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0) 9213 ipsec_xform.tunnel.ipv4.dscp = 9214 TEST_IPSEC_DSCP_VAL; 9215 9216 } else { 9217 if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1) 9218 ipsec_xform.tunnel.ipv6.dscp = 0; 9219 9220 if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0) 9221 ipsec_xform.tunnel.ipv6.dscp = 9222 TEST_IPSEC_DSCP_VAL; 9223 9224 memcpy(&ipsec_xform.tunnel.ipv6.src_addr, &v6_src, 9225 sizeof(v6_src)); 9226 memcpy(&ipsec_xform.tunnel.ipv6.dst_addr, &v6_dst, 9227 sizeof(v6_dst)); 9228 } 9229 } 9230 9231 ctx = rte_cryptodev_get_sec_ctx(dev_id); 9232 9233 sec_cap_idx.action = ut_params->type; 9234 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC; 9235 sec_cap_idx.ipsec.proto = ipsec_xform.proto; 9236 sec_cap_idx.ipsec.mode = ipsec_xform.mode; 9237 sec_cap_idx.ipsec.direction = ipsec_xform.direction; 9238 9239 if (flags->udp_encap) 9240 ipsec_xform.options.udp_encap = 1; 9241 9242 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 9243 if (sec_cap == NULL) 9244 return TEST_SKIPPED; 9245 9246 /* Copy cipher session parameters */ 9247 if (td[0].aead) { 9248 memcpy(&ut_params->aead_xform, &td[0].xform.aead, 9249 sizeof(ut_params->aead_xform)); 9250 ut_params->aead_xform.aead.key.data = td[0].key.data; 9251 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 9252 9253 /* Verify crypto capabilities */ 9254 if (test_ipsec_crypto_caps_aead_verify( 9255 sec_cap, 9256 &ut_params->aead_xform) != 0) { 9257 if (!silent) 9258 RTE_LOG(INFO, USER1, 9259 "Crypto capabilities not supported\n"); 9260 return TEST_SKIPPED; 9261 } 9262 } else if (td[0].auth_only) { 9263 memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth, 9264 sizeof(ut_params->auth_xform)); 9265 ut_params->auth_xform.auth.key.data = td[0].auth_key.data; 9266 9267 if (test_ipsec_crypto_caps_auth_verify( 9268 sec_cap, 9269 &ut_params->auth_xform) != 0) { 9270 if (!silent) 9271 RTE_LOG(INFO, USER1, 9272 "Auth crypto capabilities not supported\n"); 9273 return TEST_SKIPPED; 9274 } 9275 } else { 9276 memcpy(&ut_params->cipher_xform, &td[0].xform.chain.cipher, 9277 sizeof(ut_params->cipher_xform)); 9278 memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth, 9279 sizeof(ut_params->auth_xform)); 9280 ut_params->cipher_xform.cipher.key.data = td[0].key.data; 9281 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 9282 ut_params->auth_xform.auth.key.data = td[0].auth_key.data; 9283 9284 /* Verify crypto capabilities */ 9285 9286 if (test_ipsec_crypto_caps_cipher_verify( 9287 sec_cap, 9288 &ut_params->cipher_xform) != 0) { 9289 if (!silent) 9290 RTE_LOG(INFO, USER1, 9291 "Cipher crypto capabilities not supported\n"); 9292 return TEST_SKIPPED; 9293 } 9294 9295 if (test_ipsec_crypto_caps_auth_verify( 9296 sec_cap, 9297 &ut_params->auth_xform) != 0) { 9298 if (!silent) 9299 RTE_LOG(INFO, USER1, 9300 "Auth crypto capabilities not supported\n"); 9301 return TEST_SKIPPED; 9302 } 9303 } 9304 9305 if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0) 9306 return TEST_SKIPPED; 9307 9308 struct rte_security_session_conf sess_conf = { 9309 .action_type = ut_params->type, 9310 .protocol = RTE_SECURITY_PROTOCOL_IPSEC, 9311 }; 9312 9313 if (td[0].aead || td[0].aes_gmac) { 9314 salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len); 9315 memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len); 9316 } 9317 9318 if (td[0].aead) { 9319 sess_conf.ipsec = ipsec_xform; 9320 sess_conf.crypto_xform = &ut_params->aead_xform; 9321 } else if (td[0].auth_only) { 9322 sess_conf.ipsec = ipsec_xform; 9323 sess_conf.crypto_xform = &ut_params->auth_xform; 9324 } else { 9325 sess_conf.ipsec = ipsec_xform; 9326 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) { 9327 sess_conf.crypto_xform = &ut_params->cipher_xform; 9328 ut_params->cipher_xform.next = &ut_params->auth_xform; 9329 } else { 9330 sess_conf.crypto_xform = &ut_params->auth_xform; 9331 ut_params->auth_xform.next = &ut_params->cipher_xform; 9332 } 9333 } 9334 9335 /* Create security session */ 9336 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 9337 ts_params->session_mpool, 9338 ts_params->session_priv_mpool); 9339 9340 if (ut_params->sec_session == NULL) 9341 return TEST_SKIPPED; 9342 9343 for (i = 0; i < nb_td; i++) { 9344 if (flags->antireplay && 9345 (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)) { 9346 sess_conf.ipsec.esn.value = td[i].ipsec_xform.esn.value; 9347 ret = rte_security_session_update(ctx, 9348 ut_params->sec_session, &sess_conf); 9349 if (ret) { 9350 printf("Could not update sequence number in " 9351 "session\n"); 9352 return TEST_SKIPPED; 9353 } 9354 } 9355 9356 /* Setup source mbuf payload */ 9357 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9358 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9359 rte_pktmbuf_tailroom(ut_params->ibuf)); 9360 9361 input_text = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9362 td[i].input_text.len); 9363 9364 memcpy(input_text, td[i].input_text.data, 9365 td[i].input_text.len); 9366 9367 if (test_ipsec_pkt_update(input_text, flags)) 9368 return TEST_FAILED; 9369 9370 /* Generate crypto op data structure */ 9371 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9372 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9373 if (!ut_params->op) { 9374 printf("TestCase %s line %d: %s\n", 9375 __func__, __LINE__, 9376 "failed to allocate crypto op"); 9377 ret = TEST_FAILED; 9378 goto crypto_op_free; 9379 } 9380 9381 /* Attach session to operation */ 9382 rte_security_attach_session(ut_params->op, 9383 ut_params->sec_session); 9384 9385 /* Set crypto operation mbufs */ 9386 ut_params->op->sym->m_src = ut_params->ibuf; 9387 ut_params->op->sym->m_dst = NULL; 9388 9389 /* Copy IV in crypto operation when IV generation is disabled */ 9390 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS && 9391 ipsec_xform.options.iv_gen_disable == 1) { 9392 uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op, 9393 uint8_t *, 9394 IV_OFFSET); 9395 int len; 9396 9397 if (td[i].aead) 9398 len = td[i].xform.aead.aead.iv.length; 9399 else if (td[i].aes_gmac) 9400 len = td[i].xform.chain.auth.auth.iv.length; 9401 else 9402 len = td[i].xform.chain.cipher.cipher.iv.length; 9403 9404 memcpy(iv, td[i].iv.data, len); 9405 } 9406 9407 /* Process crypto operation */ 9408 process_crypto_request(dev_id, ut_params->op); 9409 9410 ret = test_ipsec_status_check(&td[i], ut_params->op, flags, dir, 9411 i + 1); 9412 if (ret != TEST_SUCCESS) 9413 goto crypto_op_free; 9414 9415 if (res_d != NULL) 9416 res_d_tmp = &res_d[i]; 9417 9418 ret = test_ipsec_post_process(ut_params->ibuf, &td[i], 9419 res_d_tmp, silent, flags); 9420 if (ret != TEST_SUCCESS) 9421 goto crypto_op_free; 9422 9423 ret = test_ipsec_stats_verify(ctx, ut_params->sec_session, 9424 flags, dir); 9425 if (ret != TEST_SUCCESS) 9426 goto crypto_op_free; 9427 9428 rte_crypto_op_free(ut_params->op); 9429 ut_params->op = NULL; 9430 9431 rte_pktmbuf_free(ut_params->ibuf); 9432 ut_params->ibuf = NULL; 9433 } 9434 9435 crypto_op_free: 9436 rte_crypto_op_free(ut_params->op); 9437 ut_params->op = NULL; 9438 9439 rte_pktmbuf_free(ut_params->ibuf); 9440 ut_params->ibuf = NULL; 9441 9442 if (ut_params->sec_session) 9443 rte_security_session_destroy(ctx, ut_params->sec_session); 9444 ut_params->sec_session = NULL; 9445 9446 return ret; 9447 } 9448 9449 static int 9450 test_ipsec_proto_known_vec(const void *test_data) 9451 { 9452 struct ipsec_test_data td_outb; 9453 struct ipsec_test_flags flags; 9454 9455 memset(&flags, 0, sizeof(flags)); 9456 9457 memcpy(&td_outb, test_data, sizeof(td_outb)); 9458 9459 if (td_outb.aes_gmac || td_outb.aead || 9460 ((td_outb.ipsec_xform.proto != RTE_SECURITY_IPSEC_SA_PROTO_AH) && 9461 (td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL))) { 9462 /* Disable IV gen to be able to test with known vectors */ 9463 td_outb.ipsec_xform.options.iv_gen_disable = 1; 9464 } 9465 9466 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 9467 } 9468 9469 static int 9470 test_ipsec_proto_known_vec_inb(const void *test_data) 9471 { 9472 const struct ipsec_test_data *td = test_data; 9473 struct ipsec_test_flags flags; 9474 struct ipsec_test_data td_inb; 9475 9476 memset(&flags, 0, sizeof(flags)); 9477 9478 if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) 9479 test_ipsec_td_in_from_out(td, &td_inb); 9480 else 9481 memcpy(&td_inb, td, sizeof(td_inb)); 9482 9483 return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags); 9484 } 9485 9486 static int 9487 test_ipsec_proto_known_vec_fragmented(const void *test_data) 9488 { 9489 struct ipsec_test_data td_outb; 9490 struct ipsec_test_flags flags; 9491 9492 memset(&flags, 0, sizeof(flags)); 9493 flags.fragment = true; 9494 9495 memcpy(&td_outb, test_data, sizeof(td_outb)); 9496 9497 /* Disable IV gen to be able to test with known vectors */ 9498 td_outb.ipsec_xform.options.iv_gen_disable = 1; 9499 9500 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 9501 } 9502 9503 static int 9504 test_ipsec_proto_all(const struct ipsec_test_flags *flags) 9505 { 9506 struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX]; 9507 struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX]; 9508 unsigned int i, nb_pkts = 1, pass_cnt = 0; 9509 int ret; 9510 9511 if (flags->iv_gen || 9512 flags->sa_expiry_pkts_soft || 9513 flags->sa_expiry_pkts_hard) 9514 nb_pkts = IPSEC_TEST_PACKETS_MAX; 9515 9516 for (i = 0; i < RTE_DIM(alg_list); i++) { 9517 test_ipsec_td_prepare(alg_list[i].param1, 9518 alg_list[i].param2, 9519 flags, 9520 td_outb, 9521 nb_pkts); 9522 9523 if (!td_outb->aead) { 9524 enum rte_crypto_cipher_algorithm cipher_alg; 9525 enum rte_crypto_auth_algorithm auth_alg; 9526 9527 cipher_alg = td_outb->xform.chain.cipher.cipher.algo; 9528 auth_alg = td_outb->xform.chain.auth.auth.algo; 9529 9530 if (td_outb->aes_gmac && cipher_alg != RTE_CRYPTO_CIPHER_NULL) 9531 continue; 9532 9533 /* ICV is not applicable for NULL auth */ 9534 if (flags->icv_corrupt && 9535 auth_alg == RTE_CRYPTO_AUTH_NULL) 9536 continue; 9537 9538 /* IV is not applicable for NULL cipher */ 9539 if (flags->iv_gen && 9540 cipher_alg == RTE_CRYPTO_CIPHER_NULL) 9541 continue; 9542 } 9543 9544 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 9545 flags); 9546 if (ret == TEST_SKIPPED) 9547 continue; 9548 9549 if (ret == TEST_FAILED) 9550 return TEST_FAILED; 9551 9552 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags); 9553 9554 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 9555 flags); 9556 if (ret == TEST_SKIPPED) 9557 continue; 9558 9559 if (ret == TEST_FAILED) 9560 return TEST_FAILED; 9561 9562 if (flags->display_alg) 9563 test_ipsec_display_alg(alg_list[i].param1, 9564 alg_list[i].param2); 9565 9566 pass_cnt++; 9567 } 9568 9569 if (pass_cnt > 0) 9570 return TEST_SUCCESS; 9571 else 9572 return TEST_SKIPPED; 9573 } 9574 9575 static int 9576 test_ipsec_ah_proto_all(const struct ipsec_test_flags *flags) 9577 { 9578 struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX]; 9579 struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX]; 9580 unsigned int i, nb_pkts = 1, pass_cnt = 0; 9581 int ret; 9582 9583 for (i = 0; i < RTE_DIM(ah_alg_list); i++) { 9584 test_ipsec_td_prepare(ah_alg_list[i].param1, 9585 ah_alg_list[i].param2, 9586 flags, 9587 td_outb, 9588 nb_pkts); 9589 9590 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 9591 flags); 9592 if (ret == TEST_SKIPPED) 9593 continue; 9594 9595 if (ret == TEST_FAILED) 9596 return TEST_FAILED; 9597 9598 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags); 9599 9600 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 9601 flags); 9602 if (ret == TEST_SKIPPED) 9603 continue; 9604 9605 if (ret == TEST_FAILED) 9606 return TEST_FAILED; 9607 9608 if (flags->display_alg) 9609 test_ipsec_display_alg(ah_alg_list[i].param1, 9610 ah_alg_list[i].param2); 9611 9612 pass_cnt++; 9613 } 9614 9615 if (pass_cnt > 0) 9616 return TEST_SUCCESS; 9617 else 9618 return TEST_SKIPPED; 9619 } 9620 9621 static int 9622 test_ipsec_proto_display_list(const void *data __rte_unused) 9623 { 9624 struct ipsec_test_flags flags; 9625 9626 memset(&flags, 0, sizeof(flags)); 9627 9628 flags.display_alg = true; 9629 9630 return test_ipsec_proto_all(&flags); 9631 } 9632 9633 static int 9634 test_ipsec_proto_ah_tunnel_ipv4(const void *data __rte_unused) 9635 { 9636 struct ipsec_test_flags flags; 9637 9638 memset(&flags, 0, sizeof(flags)); 9639 9640 flags.ah = true; 9641 flags.display_alg = true; 9642 9643 return test_ipsec_ah_proto_all(&flags); 9644 } 9645 9646 static int 9647 test_ipsec_proto_ah_transport_ipv4(const void *data __rte_unused) 9648 { 9649 struct ipsec_test_flags flags; 9650 9651 memset(&flags, 0, sizeof(flags)); 9652 9653 flags.ah = true; 9654 flags.transport = true; 9655 9656 return test_ipsec_ah_proto_all(&flags); 9657 } 9658 9659 static int 9660 test_ipsec_proto_iv_gen(const void *data __rte_unused) 9661 { 9662 struct ipsec_test_flags flags; 9663 9664 memset(&flags, 0, sizeof(flags)); 9665 9666 flags.iv_gen = true; 9667 9668 return test_ipsec_proto_all(&flags); 9669 } 9670 9671 static int 9672 test_ipsec_proto_sa_exp_pkts_soft(const void *data __rte_unused) 9673 { 9674 struct ipsec_test_flags flags; 9675 9676 memset(&flags, 0, sizeof(flags)); 9677 9678 flags.sa_expiry_pkts_soft = true; 9679 9680 return test_ipsec_proto_all(&flags); 9681 } 9682 9683 static int 9684 test_ipsec_proto_sa_exp_pkts_hard(const void *data __rte_unused) 9685 { 9686 struct ipsec_test_flags flags; 9687 9688 memset(&flags, 0, sizeof(flags)); 9689 9690 flags.sa_expiry_pkts_hard = true; 9691 9692 return test_ipsec_proto_all(&flags); 9693 } 9694 9695 static int 9696 test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused) 9697 { 9698 struct ipsec_test_flags flags; 9699 9700 memset(&flags, 0, sizeof(flags)); 9701 9702 flags.icv_corrupt = true; 9703 9704 return test_ipsec_proto_all(&flags); 9705 } 9706 9707 static int 9708 test_ipsec_proto_udp_encap(const void *data __rte_unused) 9709 { 9710 struct ipsec_test_flags flags; 9711 9712 memset(&flags, 0, sizeof(flags)); 9713 9714 flags.udp_encap = true; 9715 9716 return test_ipsec_proto_all(&flags); 9717 } 9718 9719 static int 9720 test_ipsec_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused) 9721 { 9722 struct ipsec_test_flags flags; 9723 9724 memset(&flags, 0, sizeof(flags)); 9725 9726 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR; 9727 9728 return test_ipsec_proto_all(&flags); 9729 } 9730 9731 static int 9732 test_ipsec_proto_tunnel_dst_addr_verify(const void *data __rte_unused) 9733 { 9734 struct ipsec_test_flags flags; 9735 9736 memset(&flags, 0, sizeof(flags)); 9737 9738 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR; 9739 9740 return test_ipsec_proto_all(&flags); 9741 } 9742 9743 static int 9744 test_ipsec_proto_udp_ports_verify(const void *data __rte_unused) 9745 { 9746 struct ipsec_test_flags flags; 9747 9748 memset(&flags, 0, sizeof(flags)); 9749 9750 flags.udp_encap = true; 9751 flags.udp_ports_verify = true; 9752 9753 return test_ipsec_proto_all(&flags); 9754 } 9755 9756 static int 9757 test_ipsec_proto_inner_ip_csum(const void *data __rte_unused) 9758 { 9759 struct ipsec_test_flags flags; 9760 9761 memset(&flags, 0, sizeof(flags)); 9762 9763 flags.ip_csum = true; 9764 9765 return test_ipsec_proto_all(&flags); 9766 } 9767 9768 static int 9769 test_ipsec_proto_inner_l4_csum(const void *data __rte_unused) 9770 { 9771 struct ipsec_test_flags flags; 9772 9773 memset(&flags, 0, sizeof(flags)); 9774 9775 flags.l4_csum = true; 9776 9777 return test_ipsec_proto_all(&flags); 9778 } 9779 9780 static int 9781 test_ipsec_proto_tunnel_v4_in_v4(const void *data __rte_unused) 9782 { 9783 struct ipsec_test_flags flags; 9784 9785 memset(&flags, 0, sizeof(flags)); 9786 9787 flags.ipv6 = false; 9788 flags.tunnel_ipv6 = false; 9789 9790 return test_ipsec_proto_all(&flags); 9791 } 9792 9793 static int 9794 test_ipsec_proto_tunnel_v6_in_v6(const void *data __rte_unused) 9795 { 9796 struct ipsec_test_flags flags; 9797 9798 memset(&flags, 0, sizeof(flags)); 9799 9800 flags.ipv6 = true; 9801 flags.tunnel_ipv6 = true; 9802 9803 return test_ipsec_proto_all(&flags); 9804 } 9805 9806 static int 9807 test_ipsec_proto_tunnel_v4_in_v6(const void *data __rte_unused) 9808 { 9809 struct ipsec_test_flags flags; 9810 9811 memset(&flags, 0, sizeof(flags)); 9812 9813 flags.ipv6 = false; 9814 flags.tunnel_ipv6 = true; 9815 9816 return test_ipsec_proto_all(&flags); 9817 } 9818 9819 static int 9820 test_ipsec_proto_tunnel_v6_in_v4(const void *data __rte_unused) 9821 { 9822 struct ipsec_test_flags flags; 9823 9824 memset(&flags, 0, sizeof(flags)); 9825 9826 flags.ipv6 = true; 9827 flags.tunnel_ipv6 = false; 9828 9829 return test_ipsec_proto_all(&flags); 9830 } 9831 9832 static int 9833 test_ipsec_proto_transport_v4(const void *data __rte_unused) 9834 { 9835 struct ipsec_test_flags flags; 9836 9837 memset(&flags, 0, sizeof(flags)); 9838 9839 flags.ipv6 = false; 9840 flags.transport = true; 9841 9842 return test_ipsec_proto_all(&flags); 9843 } 9844 9845 static int 9846 test_ipsec_proto_transport_l4_csum(const void *data __rte_unused) 9847 { 9848 struct ipsec_test_flags flags = { 9849 .l4_csum = true, 9850 .transport = true, 9851 }; 9852 9853 return test_ipsec_proto_all(&flags); 9854 } 9855 9856 static int 9857 test_ipsec_proto_stats(const void *data __rte_unused) 9858 { 9859 struct ipsec_test_flags flags; 9860 9861 memset(&flags, 0, sizeof(flags)); 9862 9863 flags.stats_success = true; 9864 9865 return test_ipsec_proto_all(&flags); 9866 } 9867 9868 static int 9869 test_ipsec_proto_pkt_fragment(const void *data __rte_unused) 9870 { 9871 struct ipsec_test_flags flags; 9872 9873 memset(&flags, 0, sizeof(flags)); 9874 9875 flags.fragment = true; 9876 9877 return test_ipsec_proto_all(&flags); 9878 9879 } 9880 9881 static int 9882 test_ipsec_proto_copy_df_inner_0(const void *data __rte_unused) 9883 { 9884 struct ipsec_test_flags flags; 9885 9886 memset(&flags, 0, sizeof(flags)); 9887 9888 flags.df = TEST_IPSEC_COPY_DF_INNER_0; 9889 9890 return test_ipsec_proto_all(&flags); 9891 } 9892 9893 static int 9894 test_ipsec_proto_copy_df_inner_1(const void *data __rte_unused) 9895 { 9896 struct ipsec_test_flags flags; 9897 9898 memset(&flags, 0, sizeof(flags)); 9899 9900 flags.df = TEST_IPSEC_COPY_DF_INNER_1; 9901 9902 return test_ipsec_proto_all(&flags); 9903 } 9904 9905 static int 9906 test_ipsec_proto_set_df_0_inner_1(const void *data __rte_unused) 9907 { 9908 struct ipsec_test_flags flags; 9909 9910 memset(&flags, 0, sizeof(flags)); 9911 9912 flags.df = TEST_IPSEC_SET_DF_0_INNER_1; 9913 9914 return test_ipsec_proto_all(&flags); 9915 } 9916 9917 static int 9918 test_ipsec_proto_set_df_1_inner_0(const void *data __rte_unused) 9919 { 9920 struct ipsec_test_flags flags; 9921 9922 memset(&flags, 0, sizeof(flags)); 9923 9924 flags.df = TEST_IPSEC_SET_DF_1_INNER_0; 9925 9926 return test_ipsec_proto_all(&flags); 9927 } 9928 9929 static int 9930 test_ipsec_proto_ipv4_copy_dscp_inner_0(const void *data __rte_unused) 9931 { 9932 struct ipsec_test_flags flags; 9933 9934 memset(&flags, 0, sizeof(flags)); 9935 9936 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0; 9937 9938 return test_ipsec_proto_all(&flags); 9939 } 9940 9941 static int 9942 test_ipsec_proto_ipv4_copy_dscp_inner_1(const void *data __rte_unused) 9943 { 9944 struct ipsec_test_flags flags; 9945 9946 memset(&flags, 0, sizeof(flags)); 9947 9948 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1; 9949 9950 return test_ipsec_proto_all(&flags); 9951 } 9952 9953 static int 9954 test_ipsec_proto_ipv4_set_dscp_0_inner_1(const void *data __rte_unused) 9955 { 9956 struct ipsec_test_flags flags; 9957 9958 if (gbl_driver_id == rte_cryptodev_driver_id_get( 9959 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 9960 return TEST_SKIPPED; 9961 9962 memset(&flags, 0, sizeof(flags)); 9963 9964 flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1; 9965 9966 return test_ipsec_proto_all(&flags); 9967 } 9968 9969 static int 9970 test_ipsec_proto_ipv4_set_dscp_1_inner_0(const void *data __rte_unused) 9971 { 9972 struct ipsec_test_flags flags; 9973 9974 if (gbl_driver_id == rte_cryptodev_driver_id_get( 9975 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 9976 return TEST_SKIPPED; 9977 9978 memset(&flags, 0, sizeof(flags)); 9979 9980 flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0; 9981 9982 return test_ipsec_proto_all(&flags); 9983 } 9984 9985 static int 9986 test_ipsec_proto_ipv6_copy_dscp_inner_0(const void *data __rte_unused) 9987 { 9988 struct ipsec_test_flags flags; 9989 9990 memset(&flags, 0, sizeof(flags)); 9991 9992 flags.ipv6 = true; 9993 flags.tunnel_ipv6 = true; 9994 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0; 9995 9996 return test_ipsec_proto_all(&flags); 9997 } 9998 9999 static int 10000 test_ipsec_proto_ipv6_copy_dscp_inner_1(const void *data __rte_unused) 10001 { 10002 struct ipsec_test_flags flags; 10003 10004 memset(&flags, 0, sizeof(flags)); 10005 10006 flags.ipv6 = true; 10007 flags.tunnel_ipv6 = true; 10008 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1; 10009 10010 return test_ipsec_proto_all(&flags); 10011 } 10012 10013 static int 10014 test_ipsec_proto_ipv6_set_dscp_0_inner_1(const void *data __rte_unused) 10015 { 10016 struct ipsec_test_flags flags; 10017 10018 if (gbl_driver_id == rte_cryptodev_driver_id_get( 10019 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 10020 return TEST_SKIPPED; 10021 10022 memset(&flags, 0, sizeof(flags)); 10023 10024 flags.ipv6 = true; 10025 flags.tunnel_ipv6 = true; 10026 flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1; 10027 10028 return test_ipsec_proto_all(&flags); 10029 } 10030 10031 static int 10032 test_ipsec_proto_ipv6_set_dscp_1_inner_0(const void *data __rte_unused) 10033 { 10034 struct ipsec_test_flags flags; 10035 10036 if (gbl_driver_id == rte_cryptodev_driver_id_get( 10037 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 10038 return TEST_SKIPPED; 10039 10040 memset(&flags, 0, sizeof(flags)); 10041 10042 flags.ipv6 = true; 10043 flags.tunnel_ipv6 = true; 10044 flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0; 10045 10046 return test_ipsec_proto_all(&flags); 10047 } 10048 10049 static int 10050 test_ipsec_pkt_replay(const void *test_data, const uint64_t esn[], 10051 bool replayed_pkt[], uint32_t nb_pkts, bool esn_en, 10052 uint64_t winsz) 10053 { 10054 struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX]; 10055 struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX]; 10056 struct ipsec_test_flags flags; 10057 uint32_t i = 0, ret = 0; 10058 10059 if (nb_pkts == 0) 10060 return TEST_FAILED; 10061 10062 memset(&flags, 0, sizeof(flags)); 10063 flags.antireplay = true; 10064 10065 for (i = 0; i < nb_pkts; i++) { 10066 memcpy(&td_outb[i], test_data, sizeof(td_outb[i])); 10067 td_outb[i].ipsec_xform.options.iv_gen_disable = 1; 10068 td_outb[i].ipsec_xform.replay_win_sz = winsz; 10069 td_outb[i].ipsec_xform.options.esn = esn_en; 10070 } 10071 10072 for (i = 0; i < nb_pkts; i++) 10073 td_outb[i].ipsec_xform.esn.value = esn[i]; 10074 10075 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 10076 &flags); 10077 if (ret != TEST_SUCCESS) 10078 return ret; 10079 10080 test_ipsec_td_update(td_inb, td_outb, nb_pkts, &flags); 10081 10082 for (i = 0; i < nb_pkts; i++) { 10083 td_inb[i].ipsec_xform.options.esn = esn_en; 10084 /* Set antireplay flag for packets to be dropped */ 10085 td_inb[i].ar_packet = replayed_pkt[i]; 10086 } 10087 10088 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 10089 &flags); 10090 10091 return ret; 10092 } 10093 10094 static int 10095 test_ipsec_proto_pkt_antireplay(const void *test_data, uint64_t winsz) 10096 { 10097 10098 uint32_t nb_pkts = 5; 10099 bool replayed_pkt[5]; 10100 uint64_t esn[5]; 10101 10102 /* 1. Advance the TOP of the window to WS * 2 */ 10103 esn[0] = winsz * 2; 10104 /* 2. Test sequence number within the new window(WS + 1) */ 10105 esn[1] = winsz + 1; 10106 /* 3. Test sequence number less than the window BOTTOM */ 10107 esn[2] = winsz; 10108 /* 4. Test sequence number in the middle of the window */ 10109 esn[3] = winsz + (winsz / 2); 10110 /* 5. Test replay of the packet in the middle of the window */ 10111 esn[4] = winsz + (winsz / 2); 10112 10113 replayed_pkt[0] = false; 10114 replayed_pkt[1] = false; 10115 replayed_pkt[2] = true; 10116 replayed_pkt[3] = false; 10117 replayed_pkt[4] = true; 10118 10119 return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts, 10120 false, winsz); 10121 } 10122 10123 static int 10124 test_ipsec_proto_pkt_antireplay1024(const void *test_data) 10125 { 10126 return test_ipsec_proto_pkt_antireplay(test_data, 1024); 10127 } 10128 10129 static int 10130 test_ipsec_proto_pkt_antireplay2048(const void *test_data) 10131 { 10132 return test_ipsec_proto_pkt_antireplay(test_data, 2048); 10133 } 10134 10135 static int 10136 test_ipsec_proto_pkt_antireplay4096(const void *test_data) 10137 { 10138 return test_ipsec_proto_pkt_antireplay(test_data, 4096); 10139 } 10140 10141 static int 10142 test_ipsec_proto_pkt_esn_antireplay(const void *test_data, uint64_t winsz) 10143 { 10144 10145 uint32_t nb_pkts = 7; 10146 bool replayed_pkt[7]; 10147 uint64_t esn[7]; 10148 10149 /* Set the initial sequence number */ 10150 esn[0] = (uint64_t)(0xFFFFFFFF - winsz); 10151 /* 1. Advance the TOP of the window to (1<<32 + WS/2) */ 10152 esn[1] = (uint64_t)((1ULL << 32) + (winsz / 2)); 10153 /* 2. Test sequence number within new window (1<<32 + WS/2 + 1) */ 10154 esn[2] = (uint64_t)((1ULL << 32) - (winsz / 2) + 1); 10155 /* 3. Test with sequence number within window (1<<32 - 1) */ 10156 esn[3] = (uint64_t)((1ULL << 32) - 1); 10157 /* 4. Test with sequence number within window (1<<32 - 1) */ 10158 esn[4] = (uint64_t)(1ULL << 32); 10159 /* 5. Test with duplicate sequence number within 10160 * new window (1<<32 - 1) 10161 */ 10162 esn[5] = (uint64_t)((1ULL << 32) - 1); 10163 /* 6. Test with duplicate sequence number within new window (1<<32) */ 10164 esn[6] = (uint64_t)(1ULL << 32); 10165 10166 replayed_pkt[0] = false; 10167 replayed_pkt[1] = false; 10168 replayed_pkt[2] = false; 10169 replayed_pkt[3] = false; 10170 replayed_pkt[4] = false; 10171 replayed_pkt[5] = true; 10172 replayed_pkt[6] = true; 10173 10174 return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts, 10175 true, winsz); 10176 } 10177 10178 static int 10179 test_ipsec_proto_pkt_esn_antireplay1024(const void *test_data) 10180 { 10181 return test_ipsec_proto_pkt_esn_antireplay(test_data, 1024); 10182 } 10183 10184 static int 10185 test_ipsec_proto_pkt_esn_antireplay2048(const void *test_data) 10186 { 10187 return test_ipsec_proto_pkt_esn_antireplay(test_data, 2048); 10188 } 10189 10190 static int 10191 test_ipsec_proto_pkt_esn_antireplay4096(const void *test_data) 10192 { 10193 return test_ipsec_proto_pkt_esn_antireplay(test_data, 4096); 10194 } 10195 10196 static int 10197 test_PDCP_PROTO_all(void) 10198 { 10199 struct crypto_testsuite_params *ts_params = &testsuite_params; 10200 struct crypto_unittest_params *ut_params = &unittest_params; 10201 struct rte_cryptodev_info dev_info; 10202 int status; 10203 10204 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10205 uint64_t feat_flags = dev_info.feature_flags; 10206 10207 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 10208 return TEST_SKIPPED; 10209 10210 /* Set action type */ 10211 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 10212 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 10213 gbl_action_type; 10214 10215 if (security_proto_supported(ut_params->type, 10216 RTE_SECURITY_PROTOCOL_PDCP) < 0) 10217 return TEST_SKIPPED; 10218 10219 status = test_PDCP_PROTO_cplane_encap_all(); 10220 status += test_PDCP_PROTO_cplane_decap_all(); 10221 status += test_PDCP_PROTO_uplane_encap_all(); 10222 status += test_PDCP_PROTO_uplane_decap_all(); 10223 status += test_PDCP_PROTO_SGL_in_place_32B(); 10224 status += test_PDCP_PROTO_SGL_oop_32B_128B(); 10225 status += test_PDCP_PROTO_SGL_oop_32B_40B(); 10226 status += test_PDCP_PROTO_SGL_oop_128B_32B(); 10227 status += test_PDCP_SDAP_PROTO_encap_all(); 10228 status += test_PDCP_SDAP_PROTO_decap_all(); 10229 status += test_PDCP_PROTO_short_mac(); 10230 10231 if (status) 10232 return TEST_FAILED; 10233 else 10234 return TEST_SUCCESS; 10235 } 10236 10237 static int 10238 test_ipsec_proto_ipv4_ttl_decrement(const void *data __rte_unused) 10239 { 10240 struct ipsec_test_flags flags = { 10241 .dec_ttl_or_hop_limit = true 10242 }; 10243 10244 return test_ipsec_proto_all(&flags); 10245 } 10246 10247 static int 10248 test_ipsec_proto_ipv6_hop_limit_decrement(const void *data __rte_unused) 10249 { 10250 struct ipsec_test_flags flags = { 10251 .ipv6 = true, 10252 .dec_ttl_or_hop_limit = true 10253 }; 10254 10255 return test_ipsec_proto_all(&flags); 10256 } 10257 10258 static int 10259 test_docsis_proto_uplink(const void *data) 10260 { 10261 const struct docsis_test_data *d_td = data; 10262 struct crypto_testsuite_params *ts_params = &testsuite_params; 10263 struct crypto_unittest_params *ut_params = &unittest_params; 10264 uint8_t *plaintext = NULL; 10265 uint8_t *ciphertext = NULL; 10266 uint8_t *iv_ptr; 10267 int32_t cipher_len, crc_len; 10268 uint32_t crc_data_len; 10269 int ret = TEST_SUCCESS; 10270 10271 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 10272 rte_cryptodev_get_sec_ctx( 10273 ts_params->valid_devs[0]); 10274 10275 /* Verify the capabilities */ 10276 struct rte_security_capability_idx sec_cap_idx; 10277 const struct rte_security_capability *sec_cap; 10278 const struct rte_cryptodev_capabilities *crypto_cap; 10279 const struct rte_cryptodev_symmetric_capability *sym_cap; 10280 int j = 0; 10281 10282 /* Set action type */ 10283 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 10284 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 10285 gbl_action_type; 10286 10287 if (security_proto_supported(ut_params->type, 10288 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 10289 return TEST_SKIPPED; 10290 10291 sec_cap_idx.action = ut_params->type; 10292 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 10293 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK; 10294 10295 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 10296 if (sec_cap == NULL) 10297 return TEST_SKIPPED; 10298 10299 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 10300 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 10301 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 10302 crypto_cap->sym.xform_type == 10303 RTE_CRYPTO_SYM_XFORM_CIPHER && 10304 crypto_cap->sym.cipher.algo == 10305 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 10306 sym_cap = &crypto_cap->sym; 10307 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 10308 d_td->key.len, 10309 d_td->iv.len) == 0) 10310 break; 10311 } 10312 } 10313 10314 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 10315 return TEST_SKIPPED; 10316 10317 /* Setup source mbuf payload */ 10318 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10319 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10320 rte_pktmbuf_tailroom(ut_params->ibuf)); 10321 10322 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10323 d_td->ciphertext.len); 10324 10325 memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len); 10326 10327 /* Setup cipher session parameters */ 10328 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10329 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 10330 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 10331 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 10332 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 10333 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 10334 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 10335 ut_params->cipher_xform.next = NULL; 10336 10337 /* Setup DOCSIS session parameters */ 10338 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK; 10339 10340 struct rte_security_session_conf sess_conf = { 10341 .action_type = ut_params->type, 10342 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 10343 .docsis = ut_params->docsis_xform, 10344 .crypto_xform = &ut_params->cipher_xform, 10345 }; 10346 10347 /* Create security session */ 10348 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 10349 ts_params->session_mpool, 10350 ts_params->session_priv_mpool); 10351 10352 if (!ut_params->sec_session) { 10353 printf("Test function %s line %u: failed to allocate session\n", 10354 __func__, __LINE__); 10355 ret = TEST_FAILED; 10356 goto on_err; 10357 } 10358 10359 /* Generate crypto op data structure */ 10360 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10361 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10362 if (!ut_params->op) { 10363 printf("Test function %s line %u: failed to allocate symmetric " 10364 "crypto operation\n", __func__, __LINE__); 10365 ret = TEST_FAILED; 10366 goto on_err; 10367 } 10368 10369 /* Setup CRC operation parameters */ 10370 crc_len = d_td->ciphertext.no_crc == false ? 10371 (d_td->ciphertext.len - 10372 d_td->ciphertext.crc_offset - 10373 RTE_ETHER_CRC_LEN) : 10374 0; 10375 crc_len = crc_len > 0 ? crc_len : 0; 10376 crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN; 10377 ut_params->op->sym->auth.data.length = crc_len; 10378 ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset; 10379 10380 /* Setup cipher operation parameters */ 10381 cipher_len = d_td->ciphertext.no_cipher == false ? 10382 (d_td->ciphertext.len - 10383 d_td->ciphertext.cipher_offset) : 10384 0; 10385 cipher_len = cipher_len > 0 ? cipher_len : 0; 10386 ut_params->op->sym->cipher.data.length = cipher_len; 10387 ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset; 10388 10389 /* Setup cipher IV */ 10390 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 10391 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 10392 10393 /* Attach session to operation */ 10394 rte_security_attach_session(ut_params->op, ut_params->sec_session); 10395 10396 /* Set crypto operation mbufs */ 10397 ut_params->op->sym->m_src = ut_params->ibuf; 10398 ut_params->op->sym->m_dst = NULL; 10399 10400 /* Process crypto operation */ 10401 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 10402 NULL) { 10403 printf("Test function %s line %u: failed to process security " 10404 "crypto op\n", __func__, __LINE__); 10405 ret = TEST_FAILED; 10406 goto on_err; 10407 } 10408 10409 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 10410 printf("Test function %s line %u: failed to process crypto op\n", 10411 __func__, __LINE__); 10412 ret = TEST_FAILED; 10413 goto on_err; 10414 } 10415 10416 /* Validate plaintext */ 10417 plaintext = ciphertext; 10418 10419 if (memcmp(plaintext, d_td->plaintext.data, 10420 d_td->plaintext.len - crc_data_len)) { 10421 printf("Test function %s line %u: plaintext not as expected\n", 10422 __func__, __LINE__); 10423 rte_hexdump(stdout, "expected", d_td->plaintext.data, 10424 d_td->plaintext.len); 10425 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len); 10426 ret = TEST_FAILED; 10427 goto on_err; 10428 } 10429 10430 on_err: 10431 rte_crypto_op_free(ut_params->op); 10432 ut_params->op = NULL; 10433 10434 if (ut_params->sec_session) 10435 rte_security_session_destroy(ctx, ut_params->sec_session); 10436 ut_params->sec_session = NULL; 10437 10438 rte_pktmbuf_free(ut_params->ibuf); 10439 ut_params->ibuf = NULL; 10440 10441 return ret; 10442 } 10443 10444 static int 10445 test_docsis_proto_downlink(const void *data) 10446 { 10447 const struct docsis_test_data *d_td = data; 10448 struct crypto_testsuite_params *ts_params = &testsuite_params; 10449 struct crypto_unittest_params *ut_params = &unittest_params; 10450 uint8_t *plaintext = NULL; 10451 uint8_t *ciphertext = NULL; 10452 uint8_t *iv_ptr; 10453 int32_t cipher_len, crc_len; 10454 int ret = TEST_SUCCESS; 10455 10456 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 10457 rte_cryptodev_get_sec_ctx( 10458 ts_params->valid_devs[0]); 10459 10460 /* Verify the capabilities */ 10461 struct rte_security_capability_idx sec_cap_idx; 10462 const struct rte_security_capability *sec_cap; 10463 const struct rte_cryptodev_capabilities *crypto_cap; 10464 const struct rte_cryptodev_symmetric_capability *sym_cap; 10465 int j = 0; 10466 10467 /* Set action type */ 10468 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 10469 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 10470 gbl_action_type; 10471 10472 if (security_proto_supported(ut_params->type, 10473 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 10474 return TEST_SKIPPED; 10475 10476 sec_cap_idx.action = ut_params->type; 10477 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 10478 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 10479 10480 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 10481 if (sec_cap == NULL) 10482 return TEST_SKIPPED; 10483 10484 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 10485 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 10486 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 10487 crypto_cap->sym.xform_type == 10488 RTE_CRYPTO_SYM_XFORM_CIPHER && 10489 crypto_cap->sym.cipher.algo == 10490 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 10491 sym_cap = &crypto_cap->sym; 10492 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 10493 d_td->key.len, 10494 d_td->iv.len) == 0) 10495 break; 10496 } 10497 } 10498 10499 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 10500 return TEST_SKIPPED; 10501 10502 /* Setup source mbuf payload */ 10503 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10504 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10505 rte_pktmbuf_tailroom(ut_params->ibuf)); 10506 10507 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10508 d_td->plaintext.len); 10509 10510 memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len); 10511 10512 /* Setup cipher session parameters */ 10513 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10514 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 10515 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 10516 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 10517 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 10518 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 10519 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 10520 ut_params->cipher_xform.next = NULL; 10521 10522 /* Setup DOCSIS session parameters */ 10523 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 10524 10525 struct rte_security_session_conf sess_conf = { 10526 .action_type = ut_params->type, 10527 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 10528 .docsis = ut_params->docsis_xform, 10529 .crypto_xform = &ut_params->cipher_xform, 10530 }; 10531 10532 /* Create security session */ 10533 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 10534 ts_params->session_mpool, 10535 ts_params->session_priv_mpool); 10536 10537 if (!ut_params->sec_session) { 10538 printf("Test function %s line %u: failed to allocate session\n", 10539 __func__, __LINE__); 10540 ret = TEST_FAILED; 10541 goto on_err; 10542 } 10543 10544 /* Generate crypto op data structure */ 10545 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10546 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10547 if (!ut_params->op) { 10548 printf("Test function %s line %u: failed to allocate symmetric " 10549 "crypto operation\n", __func__, __LINE__); 10550 ret = TEST_FAILED; 10551 goto on_err; 10552 } 10553 10554 /* Setup CRC operation parameters */ 10555 crc_len = d_td->plaintext.no_crc == false ? 10556 (d_td->plaintext.len - 10557 d_td->plaintext.crc_offset - 10558 RTE_ETHER_CRC_LEN) : 10559 0; 10560 crc_len = crc_len > 0 ? crc_len : 0; 10561 ut_params->op->sym->auth.data.length = crc_len; 10562 ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset; 10563 10564 /* Setup cipher operation parameters */ 10565 cipher_len = d_td->plaintext.no_cipher == false ? 10566 (d_td->plaintext.len - 10567 d_td->plaintext.cipher_offset) : 10568 0; 10569 cipher_len = cipher_len > 0 ? cipher_len : 0; 10570 ut_params->op->sym->cipher.data.length = cipher_len; 10571 ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset; 10572 10573 /* Setup cipher IV */ 10574 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 10575 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 10576 10577 /* Attach session to operation */ 10578 rte_security_attach_session(ut_params->op, ut_params->sec_session); 10579 10580 /* Set crypto operation mbufs */ 10581 ut_params->op->sym->m_src = ut_params->ibuf; 10582 ut_params->op->sym->m_dst = NULL; 10583 10584 /* Process crypto operation */ 10585 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 10586 NULL) { 10587 printf("Test function %s line %u: failed to process crypto op\n", 10588 __func__, __LINE__); 10589 ret = TEST_FAILED; 10590 goto on_err; 10591 } 10592 10593 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 10594 printf("Test function %s line %u: crypto op processing failed\n", 10595 __func__, __LINE__); 10596 ret = TEST_FAILED; 10597 goto on_err; 10598 } 10599 10600 /* Validate ciphertext */ 10601 ciphertext = plaintext; 10602 10603 if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) { 10604 printf("Test function %s line %u: plaintext not as expected\n", 10605 __func__, __LINE__); 10606 rte_hexdump(stdout, "expected", d_td->ciphertext.data, 10607 d_td->ciphertext.len); 10608 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len); 10609 ret = TEST_FAILED; 10610 goto on_err; 10611 } 10612 10613 on_err: 10614 rte_crypto_op_free(ut_params->op); 10615 ut_params->op = NULL; 10616 10617 if (ut_params->sec_session) 10618 rte_security_session_destroy(ctx, ut_params->sec_session); 10619 ut_params->sec_session = NULL; 10620 10621 rte_pktmbuf_free(ut_params->ibuf); 10622 ut_params->ibuf = NULL; 10623 10624 return ret; 10625 } 10626 #endif 10627 10628 static int 10629 test_AES_GCM_authenticated_encryption_test_case_1(void) 10630 { 10631 return test_authenticated_encryption(&gcm_test_case_1); 10632 } 10633 10634 static int 10635 test_AES_GCM_authenticated_encryption_test_case_2(void) 10636 { 10637 return test_authenticated_encryption(&gcm_test_case_2); 10638 } 10639 10640 static int 10641 test_AES_GCM_authenticated_encryption_test_case_3(void) 10642 { 10643 return test_authenticated_encryption(&gcm_test_case_3); 10644 } 10645 10646 static int 10647 test_AES_GCM_authenticated_encryption_test_case_4(void) 10648 { 10649 return test_authenticated_encryption(&gcm_test_case_4); 10650 } 10651 10652 static int 10653 test_AES_GCM_authenticated_encryption_test_case_5(void) 10654 { 10655 return test_authenticated_encryption(&gcm_test_case_5); 10656 } 10657 10658 static int 10659 test_AES_GCM_authenticated_encryption_test_case_6(void) 10660 { 10661 return test_authenticated_encryption(&gcm_test_case_6); 10662 } 10663 10664 static int 10665 test_AES_GCM_authenticated_encryption_test_case_7(void) 10666 { 10667 return test_authenticated_encryption(&gcm_test_case_7); 10668 } 10669 10670 static int 10671 test_AES_GCM_authenticated_encryption_test_case_8(void) 10672 { 10673 return test_authenticated_encryption(&gcm_test_case_8); 10674 } 10675 10676 static int 10677 test_AES_GCM_J0_authenticated_encryption_test_case_1(void) 10678 { 10679 return test_authenticated_encryption(&gcm_J0_test_case_1); 10680 } 10681 10682 static int 10683 test_AES_GCM_auth_encryption_test_case_192_1(void) 10684 { 10685 return test_authenticated_encryption(&gcm_test_case_192_1); 10686 } 10687 10688 static int 10689 test_AES_GCM_auth_encryption_test_case_192_2(void) 10690 { 10691 return test_authenticated_encryption(&gcm_test_case_192_2); 10692 } 10693 10694 static int 10695 test_AES_GCM_auth_encryption_test_case_192_3(void) 10696 { 10697 return test_authenticated_encryption(&gcm_test_case_192_3); 10698 } 10699 10700 static int 10701 test_AES_GCM_auth_encryption_test_case_192_4(void) 10702 { 10703 return test_authenticated_encryption(&gcm_test_case_192_4); 10704 } 10705 10706 static int 10707 test_AES_GCM_auth_encryption_test_case_192_5(void) 10708 { 10709 return test_authenticated_encryption(&gcm_test_case_192_5); 10710 } 10711 10712 static int 10713 test_AES_GCM_auth_encryption_test_case_192_6(void) 10714 { 10715 return test_authenticated_encryption(&gcm_test_case_192_6); 10716 } 10717 10718 static int 10719 test_AES_GCM_auth_encryption_test_case_192_7(void) 10720 { 10721 return test_authenticated_encryption(&gcm_test_case_192_7); 10722 } 10723 10724 static int 10725 test_AES_GCM_auth_encryption_test_case_256_1(void) 10726 { 10727 return test_authenticated_encryption(&gcm_test_case_256_1); 10728 } 10729 10730 static int 10731 test_AES_GCM_auth_encryption_test_case_256_2(void) 10732 { 10733 return test_authenticated_encryption(&gcm_test_case_256_2); 10734 } 10735 10736 static int 10737 test_AES_GCM_auth_encryption_test_case_256_3(void) 10738 { 10739 return test_authenticated_encryption(&gcm_test_case_256_3); 10740 } 10741 10742 static int 10743 test_AES_GCM_auth_encryption_test_case_256_4(void) 10744 { 10745 return test_authenticated_encryption(&gcm_test_case_256_4); 10746 } 10747 10748 static int 10749 test_AES_GCM_auth_encryption_test_case_256_5(void) 10750 { 10751 return test_authenticated_encryption(&gcm_test_case_256_5); 10752 } 10753 10754 static int 10755 test_AES_GCM_auth_encryption_test_case_256_6(void) 10756 { 10757 return test_authenticated_encryption(&gcm_test_case_256_6); 10758 } 10759 10760 static int 10761 test_AES_GCM_auth_encryption_test_case_256_7(void) 10762 { 10763 return test_authenticated_encryption(&gcm_test_case_256_7); 10764 } 10765 10766 static int 10767 test_AES_GCM_auth_encryption_test_case_aad_1(void) 10768 { 10769 return test_authenticated_encryption(&gcm_test_case_aad_1); 10770 } 10771 10772 static int 10773 test_AES_GCM_auth_encryption_test_case_aad_2(void) 10774 { 10775 return test_authenticated_encryption(&gcm_test_case_aad_2); 10776 } 10777 10778 static int 10779 test_AES_GCM_auth_encryption_fail_iv_corrupt(void) 10780 { 10781 struct aead_test_data tdata; 10782 int res; 10783 10784 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10785 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10786 tdata.iv.data[0] += 1; 10787 res = test_authenticated_encryption(&tdata); 10788 if (res == TEST_SKIPPED) 10789 return res; 10790 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10791 return TEST_SUCCESS; 10792 } 10793 10794 static int 10795 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void) 10796 { 10797 struct aead_test_data tdata; 10798 int res; 10799 10800 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10801 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10802 tdata.plaintext.data[0] += 1; 10803 res = test_authenticated_encryption(&tdata); 10804 if (res == TEST_SKIPPED) 10805 return res; 10806 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10807 return TEST_SUCCESS; 10808 } 10809 10810 static int 10811 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void) 10812 { 10813 struct aead_test_data tdata; 10814 int res; 10815 10816 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10817 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10818 tdata.ciphertext.data[0] += 1; 10819 res = test_authenticated_encryption(&tdata); 10820 if (res == TEST_SKIPPED) 10821 return res; 10822 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10823 return TEST_SUCCESS; 10824 } 10825 10826 static int 10827 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void) 10828 { 10829 struct aead_test_data tdata; 10830 int res; 10831 10832 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10833 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10834 tdata.aad.len += 1; 10835 res = test_authenticated_encryption(&tdata); 10836 if (res == TEST_SKIPPED) 10837 return res; 10838 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10839 return TEST_SUCCESS; 10840 } 10841 10842 static int 10843 test_AES_GCM_auth_encryption_fail_aad_corrupt(void) 10844 { 10845 struct aead_test_data tdata; 10846 uint8_t aad[gcm_test_case_7.aad.len]; 10847 int res; 10848 10849 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10850 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10851 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 10852 aad[0] += 1; 10853 tdata.aad.data = aad; 10854 res = test_authenticated_encryption(&tdata); 10855 if (res == TEST_SKIPPED) 10856 return res; 10857 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10858 return TEST_SUCCESS; 10859 } 10860 10861 static int 10862 test_AES_GCM_auth_encryption_fail_tag_corrupt(void) 10863 { 10864 struct aead_test_data tdata; 10865 int res; 10866 10867 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10868 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10869 tdata.auth_tag.data[0] += 1; 10870 res = test_authenticated_encryption(&tdata); 10871 if (res == TEST_SKIPPED) 10872 return res; 10873 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10874 return TEST_SUCCESS; 10875 } 10876 10877 static int 10878 test_authenticated_decryption(const struct aead_test_data *tdata) 10879 { 10880 struct crypto_testsuite_params *ts_params = &testsuite_params; 10881 struct crypto_unittest_params *ut_params = &unittest_params; 10882 10883 int retval; 10884 uint8_t *plaintext; 10885 uint32_t i; 10886 struct rte_cryptodev_info dev_info; 10887 10888 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10889 uint64_t feat_flags = dev_info.feature_flags; 10890 10891 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10892 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10893 printf("Device doesn't support RAW data-path APIs.\n"); 10894 return TEST_SKIPPED; 10895 } 10896 10897 /* Verify the capabilities */ 10898 struct rte_cryptodev_sym_capability_idx cap_idx; 10899 const struct rte_cryptodev_symmetric_capability *capability; 10900 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10901 cap_idx.algo.aead = tdata->algo; 10902 capability = rte_cryptodev_sym_capability_get( 10903 ts_params->valid_devs[0], &cap_idx); 10904 if (capability == NULL) 10905 return TEST_SKIPPED; 10906 if (rte_cryptodev_sym_capability_check_aead( 10907 capability, tdata->key.len, tdata->auth_tag.len, 10908 tdata->aad.len, tdata->iv.len)) 10909 return TEST_SKIPPED; 10910 10911 /* Create AEAD session */ 10912 retval = create_aead_session(ts_params->valid_devs[0], 10913 tdata->algo, 10914 RTE_CRYPTO_AEAD_OP_DECRYPT, 10915 tdata->key.data, tdata->key.len, 10916 tdata->aad.len, tdata->auth_tag.len, 10917 tdata->iv.len); 10918 if (retval < 0) 10919 return retval; 10920 10921 /* alloc mbuf and set payload */ 10922 if (tdata->aad.len > MBUF_SIZE) { 10923 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 10924 /* Populate full size of add data */ 10925 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 10926 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 10927 } else 10928 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10929 10930 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10931 rte_pktmbuf_tailroom(ut_params->ibuf)); 10932 10933 /* Create AEAD operation */ 10934 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 10935 if (retval < 0) 10936 return retval; 10937 10938 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10939 10940 ut_params->op->sym->m_src = ut_params->ibuf; 10941 10942 /* Process crypto operation */ 10943 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10944 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 10945 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10946 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10947 ut_params->op, 0, 0, 0, 0); 10948 else 10949 TEST_ASSERT_NOT_NULL( 10950 process_crypto_request(ts_params->valid_devs[0], 10951 ut_params->op), "failed to process sym crypto op"); 10952 10953 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10954 "crypto op processing failed"); 10955 10956 if (ut_params->op->sym->m_dst) 10957 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 10958 uint8_t *); 10959 else 10960 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 10961 uint8_t *, 10962 ut_params->op->sym->cipher.data.offset); 10963 10964 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 10965 10966 /* Validate obuf */ 10967 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10968 plaintext, 10969 tdata->plaintext.data, 10970 tdata->plaintext.len, 10971 "Plaintext data not as expected"); 10972 10973 TEST_ASSERT_EQUAL(ut_params->op->status, 10974 RTE_CRYPTO_OP_STATUS_SUCCESS, 10975 "Authentication failed"); 10976 10977 return 0; 10978 } 10979 10980 static int 10981 test_AES_GCM_authenticated_decryption_test_case_1(void) 10982 { 10983 return test_authenticated_decryption(&gcm_test_case_1); 10984 } 10985 10986 static int 10987 test_AES_GCM_authenticated_decryption_test_case_2(void) 10988 { 10989 return test_authenticated_decryption(&gcm_test_case_2); 10990 } 10991 10992 static int 10993 test_AES_GCM_authenticated_decryption_test_case_3(void) 10994 { 10995 return test_authenticated_decryption(&gcm_test_case_3); 10996 } 10997 10998 static int 10999 test_AES_GCM_authenticated_decryption_test_case_4(void) 11000 { 11001 return test_authenticated_decryption(&gcm_test_case_4); 11002 } 11003 11004 static int 11005 test_AES_GCM_authenticated_decryption_test_case_5(void) 11006 { 11007 return test_authenticated_decryption(&gcm_test_case_5); 11008 } 11009 11010 static int 11011 test_AES_GCM_authenticated_decryption_test_case_6(void) 11012 { 11013 return test_authenticated_decryption(&gcm_test_case_6); 11014 } 11015 11016 static int 11017 test_AES_GCM_authenticated_decryption_test_case_7(void) 11018 { 11019 return test_authenticated_decryption(&gcm_test_case_7); 11020 } 11021 11022 static int 11023 test_AES_GCM_authenticated_decryption_test_case_8(void) 11024 { 11025 return test_authenticated_decryption(&gcm_test_case_8); 11026 } 11027 11028 static int 11029 test_AES_GCM_J0_authenticated_decryption_test_case_1(void) 11030 { 11031 return test_authenticated_decryption(&gcm_J0_test_case_1); 11032 } 11033 11034 static int 11035 test_AES_GCM_auth_decryption_test_case_192_1(void) 11036 { 11037 return test_authenticated_decryption(&gcm_test_case_192_1); 11038 } 11039 11040 static int 11041 test_AES_GCM_auth_decryption_test_case_192_2(void) 11042 { 11043 return test_authenticated_decryption(&gcm_test_case_192_2); 11044 } 11045 11046 static int 11047 test_AES_GCM_auth_decryption_test_case_192_3(void) 11048 { 11049 return test_authenticated_decryption(&gcm_test_case_192_3); 11050 } 11051 11052 static int 11053 test_AES_GCM_auth_decryption_test_case_192_4(void) 11054 { 11055 return test_authenticated_decryption(&gcm_test_case_192_4); 11056 } 11057 11058 static int 11059 test_AES_GCM_auth_decryption_test_case_192_5(void) 11060 { 11061 return test_authenticated_decryption(&gcm_test_case_192_5); 11062 } 11063 11064 static int 11065 test_AES_GCM_auth_decryption_test_case_192_6(void) 11066 { 11067 return test_authenticated_decryption(&gcm_test_case_192_6); 11068 } 11069 11070 static int 11071 test_AES_GCM_auth_decryption_test_case_192_7(void) 11072 { 11073 return test_authenticated_decryption(&gcm_test_case_192_7); 11074 } 11075 11076 static int 11077 test_AES_GCM_auth_decryption_test_case_256_1(void) 11078 { 11079 return test_authenticated_decryption(&gcm_test_case_256_1); 11080 } 11081 11082 static int 11083 test_AES_GCM_auth_decryption_test_case_256_2(void) 11084 { 11085 return test_authenticated_decryption(&gcm_test_case_256_2); 11086 } 11087 11088 static int 11089 test_AES_GCM_auth_decryption_test_case_256_3(void) 11090 { 11091 return test_authenticated_decryption(&gcm_test_case_256_3); 11092 } 11093 11094 static int 11095 test_AES_GCM_auth_decryption_test_case_256_4(void) 11096 { 11097 return test_authenticated_decryption(&gcm_test_case_256_4); 11098 } 11099 11100 static int 11101 test_AES_GCM_auth_decryption_test_case_256_5(void) 11102 { 11103 return test_authenticated_decryption(&gcm_test_case_256_5); 11104 } 11105 11106 static int 11107 test_AES_GCM_auth_decryption_test_case_256_6(void) 11108 { 11109 return test_authenticated_decryption(&gcm_test_case_256_6); 11110 } 11111 11112 static int 11113 test_AES_GCM_auth_decryption_test_case_256_7(void) 11114 { 11115 return test_authenticated_decryption(&gcm_test_case_256_7); 11116 } 11117 11118 static int 11119 test_AES_GCM_auth_decryption_test_case_aad_1(void) 11120 { 11121 return test_authenticated_decryption(&gcm_test_case_aad_1); 11122 } 11123 11124 static int 11125 test_AES_GCM_auth_decryption_test_case_aad_2(void) 11126 { 11127 return test_authenticated_decryption(&gcm_test_case_aad_2); 11128 } 11129 11130 static int 11131 test_AES_GCM_auth_decryption_fail_iv_corrupt(void) 11132 { 11133 struct aead_test_data tdata; 11134 int res; 11135 11136 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11137 tdata.iv.data[0] += 1; 11138 res = test_authenticated_decryption(&tdata); 11139 if (res == TEST_SKIPPED) 11140 return res; 11141 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11142 return TEST_SUCCESS; 11143 } 11144 11145 static int 11146 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void) 11147 { 11148 struct aead_test_data tdata; 11149 int res; 11150 11151 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11152 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11153 tdata.plaintext.data[0] += 1; 11154 res = test_authenticated_decryption(&tdata); 11155 if (res == TEST_SKIPPED) 11156 return res; 11157 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11158 return TEST_SUCCESS; 11159 } 11160 11161 static int 11162 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void) 11163 { 11164 struct aead_test_data tdata; 11165 int res; 11166 11167 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11168 tdata.ciphertext.data[0] += 1; 11169 res = test_authenticated_decryption(&tdata); 11170 if (res == TEST_SKIPPED) 11171 return res; 11172 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11173 return TEST_SUCCESS; 11174 } 11175 11176 static int 11177 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void) 11178 { 11179 struct aead_test_data tdata; 11180 int res; 11181 11182 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11183 tdata.aad.len += 1; 11184 res = test_authenticated_decryption(&tdata); 11185 if (res == TEST_SKIPPED) 11186 return res; 11187 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11188 return TEST_SUCCESS; 11189 } 11190 11191 static int 11192 test_AES_GCM_auth_decryption_fail_aad_corrupt(void) 11193 { 11194 struct aead_test_data tdata; 11195 uint8_t aad[gcm_test_case_7.aad.len]; 11196 int res; 11197 11198 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11199 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 11200 aad[0] += 1; 11201 tdata.aad.data = aad; 11202 res = test_authenticated_decryption(&tdata); 11203 if (res == TEST_SKIPPED) 11204 return res; 11205 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11206 return TEST_SUCCESS; 11207 } 11208 11209 static int 11210 test_AES_GCM_auth_decryption_fail_tag_corrupt(void) 11211 { 11212 struct aead_test_data tdata; 11213 int res; 11214 11215 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11216 tdata.auth_tag.data[0] += 1; 11217 res = test_authenticated_decryption(&tdata); 11218 if (res == TEST_SKIPPED) 11219 return res; 11220 TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed"); 11221 return TEST_SUCCESS; 11222 } 11223 11224 static int 11225 test_authenticated_encryption_oop(const struct aead_test_data *tdata) 11226 { 11227 struct crypto_testsuite_params *ts_params = &testsuite_params; 11228 struct crypto_unittest_params *ut_params = &unittest_params; 11229 11230 int retval; 11231 uint8_t *ciphertext, *auth_tag; 11232 uint16_t plaintext_pad_len; 11233 struct rte_cryptodev_info dev_info; 11234 11235 /* Verify the capabilities */ 11236 struct rte_cryptodev_sym_capability_idx cap_idx; 11237 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11238 cap_idx.algo.aead = tdata->algo; 11239 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11240 &cap_idx) == NULL) 11241 return TEST_SKIPPED; 11242 11243 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11244 uint64_t feat_flags = dev_info.feature_flags; 11245 11246 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11247 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) 11248 return TEST_SKIPPED; 11249 11250 /* not supported with CPU crypto */ 11251 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11252 return TEST_SKIPPED; 11253 11254 /* Create AEAD session */ 11255 retval = create_aead_session(ts_params->valid_devs[0], 11256 tdata->algo, 11257 RTE_CRYPTO_AEAD_OP_ENCRYPT, 11258 tdata->key.data, tdata->key.len, 11259 tdata->aad.len, tdata->auth_tag.len, 11260 tdata->iv.len); 11261 if (retval < 0) 11262 return retval; 11263 11264 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11265 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11266 11267 /* clear mbuf payload */ 11268 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11269 rte_pktmbuf_tailroom(ut_params->ibuf)); 11270 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 11271 rte_pktmbuf_tailroom(ut_params->obuf)); 11272 11273 /* Create AEAD operation */ 11274 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 11275 if (retval < 0) 11276 return retval; 11277 11278 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11279 11280 ut_params->op->sym->m_src = ut_params->ibuf; 11281 ut_params->op->sym->m_dst = ut_params->obuf; 11282 11283 /* Process crypto operation */ 11284 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11285 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11286 ut_params->op, 0, 0, 0, 0); 11287 else 11288 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 11289 ut_params->op), "failed to process sym crypto op"); 11290 11291 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11292 "crypto op processing failed"); 11293 11294 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 11295 11296 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 11297 ut_params->op->sym->cipher.data.offset); 11298 auth_tag = ciphertext + plaintext_pad_len; 11299 11300 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 11301 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 11302 11303 /* Validate obuf */ 11304 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11305 ciphertext, 11306 tdata->ciphertext.data, 11307 tdata->ciphertext.len, 11308 "Ciphertext data not as expected"); 11309 11310 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11311 auth_tag, 11312 tdata->auth_tag.data, 11313 tdata->auth_tag.len, 11314 "Generated auth tag not as expected"); 11315 11316 return 0; 11317 11318 } 11319 11320 static int 11321 test_AES_GCM_authenticated_encryption_oop_test_case_1(void) 11322 { 11323 return test_authenticated_encryption_oop(&gcm_test_case_5); 11324 } 11325 11326 static int 11327 test_authenticated_decryption_oop(const struct aead_test_data *tdata) 11328 { 11329 struct crypto_testsuite_params *ts_params = &testsuite_params; 11330 struct crypto_unittest_params *ut_params = &unittest_params; 11331 11332 int retval; 11333 uint8_t *plaintext; 11334 struct rte_cryptodev_info dev_info; 11335 11336 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11337 uint64_t feat_flags = dev_info.feature_flags; 11338 11339 /* Verify the capabilities */ 11340 struct rte_cryptodev_sym_capability_idx cap_idx; 11341 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11342 cap_idx.algo.aead = tdata->algo; 11343 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11344 &cap_idx) == NULL) 11345 return TEST_SKIPPED; 11346 11347 /* not supported with CPU crypto and raw data-path APIs*/ 11348 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO || 11349 global_api_test_type == CRYPTODEV_RAW_API_TEST) 11350 return TEST_SKIPPED; 11351 11352 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11353 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11354 printf("Device does not support RAW data-path APIs.\n"); 11355 return TEST_SKIPPED; 11356 } 11357 11358 /* Create AEAD session */ 11359 retval = create_aead_session(ts_params->valid_devs[0], 11360 tdata->algo, 11361 RTE_CRYPTO_AEAD_OP_DECRYPT, 11362 tdata->key.data, tdata->key.len, 11363 tdata->aad.len, tdata->auth_tag.len, 11364 tdata->iv.len); 11365 if (retval < 0) 11366 return retval; 11367 11368 /* alloc mbuf and set payload */ 11369 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11370 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11371 11372 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11373 rte_pktmbuf_tailroom(ut_params->ibuf)); 11374 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 11375 rte_pktmbuf_tailroom(ut_params->obuf)); 11376 11377 /* Create AEAD operation */ 11378 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 11379 if (retval < 0) 11380 return retval; 11381 11382 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11383 11384 ut_params->op->sym->m_src = ut_params->ibuf; 11385 ut_params->op->sym->m_dst = ut_params->obuf; 11386 11387 /* Process crypto operation */ 11388 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11389 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11390 ut_params->op, 0, 0, 0, 0); 11391 else 11392 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 11393 ut_params->op), "failed to process sym crypto op"); 11394 11395 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11396 "crypto op processing failed"); 11397 11398 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 11399 ut_params->op->sym->cipher.data.offset); 11400 11401 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 11402 11403 /* Validate obuf */ 11404 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11405 plaintext, 11406 tdata->plaintext.data, 11407 tdata->plaintext.len, 11408 "Plaintext data not as expected"); 11409 11410 TEST_ASSERT_EQUAL(ut_params->op->status, 11411 RTE_CRYPTO_OP_STATUS_SUCCESS, 11412 "Authentication failed"); 11413 return 0; 11414 } 11415 11416 static int 11417 test_AES_GCM_authenticated_decryption_oop_test_case_1(void) 11418 { 11419 return test_authenticated_decryption_oop(&gcm_test_case_5); 11420 } 11421 11422 static int 11423 test_authenticated_encryption_sessionless( 11424 const struct aead_test_data *tdata) 11425 { 11426 struct crypto_testsuite_params *ts_params = &testsuite_params; 11427 struct crypto_unittest_params *ut_params = &unittest_params; 11428 11429 int retval; 11430 uint8_t *ciphertext, *auth_tag; 11431 uint16_t plaintext_pad_len; 11432 uint8_t key[tdata->key.len + 1]; 11433 struct rte_cryptodev_info dev_info; 11434 11435 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11436 uint64_t feat_flags = dev_info.feature_flags; 11437 11438 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 11439 printf("Device doesn't support Sessionless ops.\n"); 11440 return TEST_SKIPPED; 11441 } 11442 11443 /* not supported with CPU crypto */ 11444 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11445 return TEST_SKIPPED; 11446 11447 /* Verify the capabilities */ 11448 struct rte_cryptodev_sym_capability_idx cap_idx; 11449 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11450 cap_idx.algo.aead = tdata->algo; 11451 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11452 &cap_idx) == NULL) 11453 return TEST_SKIPPED; 11454 11455 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11456 11457 /* clear mbuf payload */ 11458 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11459 rte_pktmbuf_tailroom(ut_params->ibuf)); 11460 11461 /* Create AEAD operation */ 11462 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 11463 if (retval < 0) 11464 return retval; 11465 11466 /* Create GCM xform */ 11467 memcpy(key, tdata->key.data, tdata->key.len); 11468 retval = create_aead_xform(ut_params->op, 11469 tdata->algo, 11470 RTE_CRYPTO_AEAD_OP_ENCRYPT, 11471 key, tdata->key.len, 11472 tdata->aad.len, tdata->auth_tag.len, 11473 tdata->iv.len); 11474 if (retval < 0) 11475 return retval; 11476 11477 ut_params->op->sym->m_src = ut_params->ibuf; 11478 11479 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 11480 RTE_CRYPTO_OP_SESSIONLESS, 11481 "crypto op session type not sessionless"); 11482 11483 /* Process crypto operation */ 11484 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 11485 ut_params->op), "failed to process sym crypto op"); 11486 11487 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 11488 11489 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11490 "crypto op status not success"); 11491 11492 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 11493 11494 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 11495 ut_params->op->sym->cipher.data.offset); 11496 auth_tag = ciphertext + plaintext_pad_len; 11497 11498 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 11499 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 11500 11501 /* Validate obuf */ 11502 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11503 ciphertext, 11504 tdata->ciphertext.data, 11505 tdata->ciphertext.len, 11506 "Ciphertext data not as expected"); 11507 11508 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11509 auth_tag, 11510 tdata->auth_tag.data, 11511 tdata->auth_tag.len, 11512 "Generated auth tag not as expected"); 11513 11514 return 0; 11515 11516 } 11517 11518 static int 11519 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void) 11520 { 11521 return test_authenticated_encryption_sessionless( 11522 &gcm_test_case_5); 11523 } 11524 11525 static int 11526 test_authenticated_decryption_sessionless( 11527 const struct aead_test_data *tdata) 11528 { 11529 struct crypto_testsuite_params *ts_params = &testsuite_params; 11530 struct crypto_unittest_params *ut_params = &unittest_params; 11531 11532 int retval; 11533 uint8_t *plaintext; 11534 uint8_t key[tdata->key.len + 1]; 11535 struct rte_cryptodev_info dev_info; 11536 11537 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11538 uint64_t feat_flags = dev_info.feature_flags; 11539 11540 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 11541 printf("Device doesn't support Sessionless ops.\n"); 11542 return TEST_SKIPPED; 11543 } 11544 11545 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11546 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11547 printf("Device doesn't support RAW data-path APIs.\n"); 11548 return TEST_SKIPPED; 11549 } 11550 11551 /* not supported with CPU crypto */ 11552 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11553 return TEST_SKIPPED; 11554 11555 /* Verify the capabilities */ 11556 struct rte_cryptodev_sym_capability_idx cap_idx; 11557 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11558 cap_idx.algo.aead = tdata->algo; 11559 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11560 &cap_idx) == NULL) 11561 return TEST_SKIPPED; 11562 11563 /* alloc mbuf and set payload */ 11564 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11565 11566 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11567 rte_pktmbuf_tailroom(ut_params->ibuf)); 11568 11569 /* Create AEAD operation */ 11570 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 11571 if (retval < 0) 11572 return retval; 11573 11574 /* Create AEAD xform */ 11575 memcpy(key, tdata->key.data, tdata->key.len); 11576 retval = create_aead_xform(ut_params->op, 11577 tdata->algo, 11578 RTE_CRYPTO_AEAD_OP_DECRYPT, 11579 key, tdata->key.len, 11580 tdata->aad.len, tdata->auth_tag.len, 11581 tdata->iv.len); 11582 if (retval < 0) 11583 return retval; 11584 11585 ut_params->op->sym->m_src = ut_params->ibuf; 11586 11587 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 11588 RTE_CRYPTO_OP_SESSIONLESS, 11589 "crypto op session type not sessionless"); 11590 11591 /* Process crypto operation */ 11592 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11593 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11594 ut_params->op, 0, 0, 0, 0); 11595 else 11596 TEST_ASSERT_NOT_NULL(process_crypto_request( 11597 ts_params->valid_devs[0], ut_params->op), 11598 "failed to process sym crypto op"); 11599 11600 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 11601 11602 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11603 "crypto op status not success"); 11604 11605 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 11606 ut_params->op->sym->cipher.data.offset); 11607 11608 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 11609 11610 /* Validate obuf */ 11611 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11612 plaintext, 11613 tdata->plaintext.data, 11614 tdata->plaintext.len, 11615 "Plaintext data not as expected"); 11616 11617 TEST_ASSERT_EQUAL(ut_params->op->status, 11618 RTE_CRYPTO_OP_STATUS_SUCCESS, 11619 "Authentication failed"); 11620 return 0; 11621 } 11622 11623 static int 11624 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void) 11625 { 11626 return test_authenticated_decryption_sessionless( 11627 &gcm_test_case_5); 11628 } 11629 11630 static int 11631 test_AES_CCM_authenticated_encryption_test_case_128_1(void) 11632 { 11633 return test_authenticated_encryption(&ccm_test_case_128_1); 11634 } 11635 11636 static int 11637 test_AES_CCM_authenticated_encryption_test_case_128_2(void) 11638 { 11639 return test_authenticated_encryption(&ccm_test_case_128_2); 11640 } 11641 11642 static int 11643 test_AES_CCM_authenticated_encryption_test_case_128_3(void) 11644 { 11645 return test_authenticated_encryption(&ccm_test_case_128_3); 11646 } 11647 11648 static int 11649 test_AES_CCM_authenticated_decryption_test_case_128_1(void) 11650 { 11651 return test_authenticated_decryption(&ccm_test_case_128_1); 11652 } 11653 11654 static int 11655 test_AES_CCM_authenticated_decryption_test_case_128_2(void) 11656 { 11657 return test_authenticated_decryption(&ccm_test_case_128_2); 11658 } 11659 11660 static int 11661 test_AES_CCM_authenticated_decryption_test_case_128_3(void) 11662 { 11663 return test_authenticated_decryption(&ccm_test_case_128_3); 11664 } 11665 11666 static int 11667 test_AES_CCM_authenticated_encryption_test_case_192_1(void) 11668 { 11669 return test_authenticated_encryption(&ccm_test_case_192_1); 11670 } 11671 11672 static int 11673 test_AES_CCM_authenticated_encryption_test_case_192_2(void) 11674 { 11675 return test_authenticated_encryption(&ccm_test_case_192_2); 11676 } 11677 11678 static int 11679 test_AES_CCM_authenticated_encryption_test_case_192_3(void) 11680 { 11681 return test_authenticated_encryption(&ccm_test_case_192_3); 11682 } 11683 11684 static int 11685 test_AES_CCM_authenticated_decryption_test_case_192_1(void) 11686 { 11687 return test_authenticated_decryption(&ccm_test_case_192_1); 11688 } 11689 11690 static int 11691 test_AES_CCM_authenticated_decryption_test_case_192_2(void) 11692 { 11693 return test_authenticated_decryption(&ccm_test_case_192_2); 11694 } 11695 11696 static int 11697 test_AES_CCM_authenticated_decryption_test_case_192_3(void) 11698 { 11699 return test_authenticated_decryption(&ccm_test_case_192_3); 11700 } 11701 11702 static int 11703 test_AES_CCM_authenticated_encryption_test_case_256_1(void) 11704 { 11705 return test_authenticated_encryption(&ccm_test_case_256_1); 11706 } 11707 11708 static int 11709 test_AES_CCM_authenticated_encryption_test_case_256_2(void) 11710 { 11711 return test_authenticated_encryption(&ccm_test_case_256_2); 11712 } 11713 11714 static int 11715 test_AES_CCM_authenticated_encryption_test_case_256_3(void) 11716 { 11717 return test_authenticated_encryption(&ccm_test_case_256_3); 11718 } 11719 11720 static int 11721 test_AES_CCM_authenticated_decryption_test_case_256_1(void) 11722 { 11723 return test_authenticated_decryption(&ccm_test_case_256_1); 11724 } 11725 11726 static int 11727 test_AES_CCM_authenticated_decryption_test_case_256_2(void) 11728 { 11729 return test_authenticated_decryption(&ccm_test_case_256_2); 11730 } 11731 11732 static int 11733 test_AES_CCM_authenticated_decryption_test_case_256_3(void) 11734 { 11735 return test_authenticated_decryption(&ccm_test_case_256_3); 11736 } 11737 11738 static int 11739 test_stats(void) 11740 { 11741 struct crypto_testsuite_params *ts_params = &testsuite_params; 11742 struct rte_cryptodev_stats stats; 11743 11744 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11745 return TEST_SKIPPED; 11746 11747 /* Verify the capabilities */ 11748 struct rte_cryptodev_sym_capability_idx cap_idx; 11749 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11750 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 11751 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11752 &cap_idx) == NULL) 11753 return TEST_SKIPPED; 11754 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11755 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 11756 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11757 &cap_idx) == NULL) 11758 return TEST_SKIPPED; 11759 11760 if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 11761 == -ENOTSUP) 11762 return TEST_SKIPPED; 11763 11764 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 11765 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 11766 &stats) == -ENODEV), 11767 "rte_cryptodev_stats_get invalid dev failed"); 11768 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 11769 "rte_cryptodev_stats_get invalid Param failed"); 11770 11771 /* Test expected values */ 11772 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 11773 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11774 &stats), 11775 "rte_cryptodev_stats_get failed"); 11776 TEST_ASSERT((stats.enqueued_count == 1), 11777 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11778 TEST_ASSERT((stats.dequeued_count == 1), 11779 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11780 TEST_ASSERT((stats.enqueue_err_count == 0), 11781 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11782 TEST_ASSERT((stats.dequeue_err_count == 0), 11783 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11784 11785 /* invalid device but should ignore and not reset device stats*/ 11786 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 11787 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11788 &stats), 11789 "rte_cryptodev_stats_get failed"); 11790 TEST_ASSERT((stats.enqueued_count == 1), 11791 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11792 11793 /* check that a valid reset clears stats */ 11794 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 11795 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11796 &stats), 11797 "rte_cryptodev_stats_get failed"); 11798 TEST_ASSERT((stats.enqueued_count == 0), 11799 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11800 TEST_ASSERT((stats.dequeued_count == 0), 11801 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11802 11803 return TEST_SUCCESS; 11804 } 11805 11806 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 11807 struct crypto_unittest_params *ut_params, 11808 enum rte_crypto_auth_operation op, 11809 const struct HMAC_MD5_vector *test_case) 11810 { 11811 uint8_t key[64]; 11812 int status; 11813 11814 memcpy(key, test_case->key.data, test_case->key.len); 11815 11816 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11817 ut_params->auth_xform.next = NULL; 11818 ut_params->auth_xform.auth.op = op; 11819 11820 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 11821 11822 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 11823 ut_params->auth_xform.auth.key.length = test_case->key.len; 11824 ut_params->auth_xform.auth.key.data = key; 11825 11826 ut_params->sess = rte_cryptodev_sym_session_create( 11827 ts_params->session_mpool); 11828 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11829 if (ut_params->sess == NULL) 11830 return TEST_FAILED; 11831 11832 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11833 ut_params->sess, &ut_params->auth_xform, 11834 ts_params->session_priv_mpool); 11835 if (status == -ENOTSUP) 11836 return TEST_SKIPPED; 11837 11838 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11839 11840 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11841 rte_pktmbuf_tailroom(ut_params->ibuf)); 11842 11843 return 0; 11844 } 11845 11846 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 11847 const struct HMAC_MD5_vector *test_case, 11848 uint8_t **plaintext) 11849 { 11850 uint16_t plaintext_pad_len; 11851 11852 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 11853 11854 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 11855 16); 11856 11857 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11858 plaintext_pad_len); 11859 memcpy(*plaintext, test_case->plaintext.data, 11860 test_case->plaintext.len); 11861 11862 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11863 ut_params->ibuf, MD5_DIGEST_LEN); 11864 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11865 "no room to append digest"); 11866 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11867 ut_params->ibuf, plaintext_pad_len); 11868 11869 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 11870 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 11871 test_case->auth_tag.len); 11872 } 11873 11874 sym_op->auth.data.offset = 0; 11875 sym_op->auth.data.length = test_case->plaintext.len; 11876 11877 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11878 ut_params->op->sym->m_src = ut_params->ibuf; 11879 11880 return 0; 11881 } 11882 11883 static int 11884 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 11885 { 11886 uint16_t plaintext_pad_len; 11887 uint8_t *plaintext, *auth_tag; 11888 11889 struct crypto_testsuite_params *ts_params = &testsuite_params; 11890 struct crypto_unittest_params *ut_params = &unittest_params; 11891 struct rte_cryptodev_info dev_info; 11892 11893 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11894 uint64_t feat_flags = dev_info.feature_flags; 11895 11896 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11897 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11898 printf("Device doesn't support RAW data-path APIs.\n"); 11899 return TEST_SKIPPED; 11900 } 11901 11902 /* Verify the capabilities */ 11903 struct rte_cryptodev_sym_capability_idx cap_idx; 11904 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11905 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 11906 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11907 &cap_idx) == NULL) 11908 return TEST_SKIPPED; 11909 11910 if (MD5_HMAC_create_session(ts_params, ut_params, 11911 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 11912 return TEST_FAILED; 11913 11914 /* Generate Crypto op data structure */ 11915 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11916 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11917 TEST_ASSERT_NOT_NULL(ut_params->op, 11918 "Failed to allocate symmetric crypto operation struct"); 11919 11920 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 11921 16); 11922 11923 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 11924 return TEST_FAILED; 11925 11926 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11927 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11928 ut_params->op); 11929 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11930 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11931 ut_params->op, 0, 1, 0, 0); 11932 else 11933 TEST_ASSERT_NOT_NULL( 11934 process_crypto_request(ts_params->valid_devs[0], 11935 ut_params->op), 11936 "failed to process sym crypto op"); 11937 11938 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11939 "crypto op processing failed"); 11940 11941 if (ut_params->op->sym->m_dst) { 11942 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 11943 uint8_t *, plaintext_pad_len); 11944 } else { 11945 auth_tag = plaintext + plaintext_pad_len; 11946 } 11947 11948 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11949 auth_tag, 11950 test_case->auth_tag.data, 11951 test_case->auth_tag.len, 11952 "HMAC_MD5 generated tag not as expected"); 11953 11954 return TEST_SUCCESS; 11955 } 11956 11957 static int 11958 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 11959 { 11960 uint8_t *plaintext; 11961 11962 struct crypto_testsuite_params *ts_params = &testsuite_params; 11963 struct crypto_unittest_params *ut_params = &unittest_params; 11964 struct rte_cryptodev_info dev_info; 11965 11966 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11967 uint64_t feat_flags = dev_info.feature_flags; 11968 11969 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11970 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11971 printf("Device doesn't support RAW data-path APIs.\n"); 11972 return TEST_SKIPPED; 11973 } 11974 11975 /* Verify the capabilities */ 11976 struct rte_cryptodev_sym_capability_idx cap_idx; 11977 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11978 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 11979 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11980 &cap_idx) == NULL) 11981 return TEST_SKIPPED; 11982 11983 if (MD5_HMAC_create_session(ts_params, ut_params, 11984 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 11985 return TEST_FAILED; 11986 } 11987 11988 /* Generate Crypto op data structure */ 11989 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11990 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11991 TEST_ASSERT_NOT_NULL(ut_params->op, 11992 "Failed to allocate symmetric crypto operation struct"); 11993 11994 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 11995 return TEST_FAILED; 11996 11997 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11998 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11999 ut_params->op); 12000 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12001 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12002 ut_params->op, 0, 1, 0, 0); 12003 else 12004 TEST_ASSERT_NOT_NULL( 12005 process_crypto_request(ts_params->valid_devs[0], 12006 ut_params->op), 12007 "failed to process sym crypto op"); 12008 12009 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12010 "HMAC_MD5 crypto op processing failed"); 12011 12012 return TEST_SUCCESS; 12013 } 12014 12015 static int 12016 test_MD5_HMAC_generate_case_1(void) 12017 { 12018 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 12019 } 12020 12021 static int 12022 test_MD5_HMAC_verify_case_1(void) 12023 { 12024 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 12025 } 12026 12027 static int 12028 test_MD5_HMAC_generate_case_2(void) 12029 { 12030 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 12031 } 12032 12033 static int 12034 test_MD5_HMAC_verify_case_2(void) 12035 { 12036 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 12037 } 12038 12039 static int 12040 test_multi_session(void) 12041 { 12042 struct crypto_testsuite_params *ts_params = &testsuite_params; 12043 struct crypto_unittest_params *ut_params = &unittest_params; 12044 12045 struct rte_cryptodev_info dev_info; 12046 struct rte_cryptodev_sym_session **sessions; 12047 12048 uint16_t i; 12049 int status; 12050 12051 /* Verify the capabilities */ 12052 struct rte_cryptodev_sym_capability_idx cap_idx; 12053 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12054 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 12055 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12056 &cap_idx) == NULL) 12057 return TEST_SKIPPED; 12058 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12059 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 12060 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12061 &cap_idx) == NULL) 12062 return TEST_SKIPPED; 12063 12064 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 12065 aes_cbc_key, hmac_sha512_key); 12066 12067 12068 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12069 12070 sessions = rte_malloc(NULL, 12071 sizeof(struct rte_cryptodev_sym_session *) * 12072 (MAX_NB_SESSIONS + 1), 0); 12073 12074 /* Create multiple crypto sessions*/ 12075 for (i = 0; i < MAX_NB_SESSIONS; i++) { 12076 12077 sessions[i] = rte_cryptodev_sym_session_create( 12078 ts_params->session_mpool); 12079 TEST_ASSERT_NOT_NULL(sessions[i], 12080 "Session creation failed at session number %u", 12081 i); 12082 12083 status = rte_cryptodev_sym_session_init( 12084 ts_params->valid_devs[0], 12085 sessions[i], &ut_params->auth_xform, 12086 ts_params->session_priv_mpool); 12087 if (status == -ENOTSUP) 12088 return TEST_SKIPPED; 12089 12090 /* Attempt to send a request on each session */ 12091 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform( 12092 sessions[i], 12093 ut_params, 12094 ts_params, 12095 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 12096 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 12097 aes_cbc_iv), 12098 "Failed to perform decrypt on request number %u.", i); 12099 /* free crypto operation structure */ 12100 if (ut_params->op) 12101 rte_crypto_op_free(ut_params->op); 12102 12103 /* 12104 * free mbuf - both obuf and ibuf are usually the same, 12105 * so check if they point at the same address is necessary, 12106 * to avoid freeing the mbuf twice. 12107 */ 12108 if (ut_params->obuf) { 12109 rte_pktmbuf_free(ut_params->obuf); 12110 if (ut_params->ibuf == ut_params->obuf) 12111 ut_params->ibuf = 0; 12112 ut_params->obuf = 0; 12113 } 12114 if (ut_params->ibuf) { 12115 rte_pktmbuf_free(ut_params->ibuf); 12116 ut_params->ibuf = 0; 12117 } 12118 } 12119 12120 sessions[i] = NULL; 12121 /* Next session create should fail */ 12122 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12123 sessions[i], &ut_params->auth_xform, 12124 ts_params->session_priv_mpool); 12125 TEST_ASSERT_NULL(sessions[i], 12126 "Session creation succeeded unexpectedly!"); 12127 12128 for (i = 0; i < MAX_NB_SESSIONS; i++) { 12129 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 12130 sessions[i]); 12131 rte_cryptodev_sym_session_free(sessions[i]); 12132 } 12133 12134 rte_free(sessions); 12135 12136 return TEST_SUCCESS; 12137 } 12138 12139 struct multi_session_params { 12140 struct crypto_unittest_params ut_params; 12141 uint8_t *cipher_key; 12142 uint8_t *hmac_key; 12143 const uint8_t *cipher; 12144 const uint8_t *digest; 12145 uint8_t *iv; 12146 }; 12147 12148 #define MB_SESSION_NUMBER 3 12149 12150 static int 12151 test_multi_session_random_usage(void) 12152 { 12153 struct crypto_testsuite_params *ts_params = &testsuite_params; 12154 struct rte_cryptodev_info dev_info; 12155 struct rte_cryptodev_sym_session **sessions; 12156 uint32_t i, j; 12157 struct multi_session_params ut_paramz[] = { 12158 12159 { 12160 .cipher_key = ms_aes_cbc_key0, 12161 .hmac_key = ms_hmac_key0, 12162 .cipher = ms_aes_cbc_cipher0, 12163 .digest = ms_hmac_digest0, 12164 .iv = ms_aes_cbc_iv0 12165 }, 12166 { 12167 .cipher_key = ms_aes_cbc_key1, 12168 .hmac_key = ms_hmac_key1, 12169 .cipher = ms_aes_cbc_cipher1, 12170 .digest = ms_hmac_digest1, 12171 .iv = ms_aes_cbc_iv1 12172 }, 12173 { 12174 .cipher_key = ms_aes_cbc_key2, 12175 .hmac_key = ms_hmac_key2, 12176 .cipher = ms_aes_cbc_cipher2, 12177 .digest = ms_hmac_digest2, 12178 .iv = ms_aes_cbc_iv2 12179 }, 12180 12181 }; 12182 int status; 12183 12184 /* Verify the capabilities */ 12185 struct rte_cryptodev_sym_capability_idx cap_idx; 12186 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12187 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 12188 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12189 &cap_idx) == NULL) 12190 return TEST_SKIPPED; 12191 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12192 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 12193 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12194 &cap_idx) == NULL) 12195 return TEST_SKIPPED; 12196 12197 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12198 12199 sessions = rte_malloc(NULL, 12200 (sizeof(struct rte_cryptodev_sym_session *) 12201 * MAX_NB_SESSIONS) + 1, 0); 12202 12203 for (i = 0; i < MB_SESSION_NUMBER; i++) { 12204 sessions[i] = rte_cryptodev_sym_session_create( 12205 ts_params->session_mpool); 12206 TEST_ASSERT_NOT_NULL(sessions[i], 12207 "Session creation failed at session number %u", 12208 i); 12209 12210 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params, 12211 sizeof(struct crypto_unittest_params)); 12212 12213 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 12214 &ut_paramz[i].ut_params, 12215 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 12216 12217 /* Create multiple crypto sessions*/ 12218 status = rte_cryptodev_sym_session_init( 12219 ts_params->valid_devs[0], 12220 sessions[i], 12221 &ut_paramz[i].ut_params.auth_xform, 12222 ts_params->session_priv_mpool); 12223 12224 if (status == -ENOTSUP) 12225 return TEST_SKIPPED; 12226 12227 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 12228 } 12229 12230 srand(time(NULL)); 12231 for (i = 0; i < 40000; i++) { 12232 12233 j = rand() % MB_SESSION_NUMBER; 12234 12235 TEST_ASSERT_SUCCESS( 12236 test_AES_CBC_HMAC_SHA512_decrypt_perform( 12237 sessions[j], 12238 &ut_paramz[j].ut_params, 12239 ts_params, ut_paramz[j].cipher, 12240 ut_paramz[j].digest, 12241 ut_paramz[j].iv), 12242 "Failed to perform decrypt on request number %u.", i); 12243 12244 if (ut_paramz[j].ut_params.op) 12245 rte_crypto_op_free(ut_paramz[j].ut_params.op); 12246 12247 /* 12248 * free mbuf - both obuf and ibuf are usually the same, 12249 * so check if they point at the same address is necessary, 12250 * to avoid freeing the mbuf twice. 12251 */ 12252 if (ut_paramz[j].ut_params.obuf) { 12253 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 12254 if (ut_paramz[j].ut_params.ibuf 12255 == ut_paramz[j].ut_params.obuf) 12256 ut_paramz[j].ut_params.ibuf = 0; 12257 ut_paramz[j].ut_params.obuf = 0; 12258 } 12259 if (ut_paramz[j].ut_params.ibuf) { 12260 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 12261 ut_paramz[j].ut_params.ibuf = 0; 12262 } 12263 } 12264 12265 for (i = 0; i < MB_SESSION_NUMBER; i++) { 12266 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 12267 sessions[i]); 12268 rte_cryptodev_sym_session_free(sessions[i]); 12269 } 12270 12271 rte_free(sessions); 12272 12273 return TEST_SUCCESS; 12274 } 12275 12276 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab, 12277 0xab, 0xab, 0xab, 0xab, 12278 0xab, 0xab, 0xab, 0xab, 12279 0xab, 0xab, 0xab, 0xab}; 12280 12281 static int 12282 test_null_invalid_operation(void) 12283 { 12284 struct crypto_testsuite_params *ts_params = &testsuite_params; 12285 struct crypto_unittest_params *ut_params = &unittest_params; 12286 int ret; 12287 12288 /* This test is for NULL PMD only */ 12289 if (gbl_driver_id != rte_cryptodev_driver_id_get( 12290 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 12291 return TEST_SKIPPED; 12292 12293 /* Setup Cipher Parameters */ 12294 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12295 ut_params->cipher_xform.next = NULL; 12296 12297 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 12298 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 12299 12300 ut_params->sess = rte_cryptodev_sym_session_create( 12301 ts_params->session_mpool); 12302 12303 /* Create Crypto session*/ 12304 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12305 ut_params->sess, &ut_params->cipher_xform, 12306 ts_params->session_priv_mpool); 12307 TEST_ASSERT(ret < 0, 12308 "Session creation succeeded unexpectedly"); 12309 12310 12311 /* Setup HMAC Parameters */ 12312 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12313 ut_params->auth_xform.next = NULL; 12314 12315 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 12316 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 12317 12318 ut_params->sess = rte_cryptodev_sym_session_create( 12319 ts_params->session_mpool); 12320 12321 /* Create Crypto session*/ 12322 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12323 ut_params->sess, &ut_params->auth_xform, 12324 ts_params->session_priv_mpool); 12325 TEST_ASSERT(ret < 0, 12326 "Session creation succeeded unexpectedly"); 12327 12328 return TEST_SUCCESS; 12329 } 12330 12331 12332 #define NULL_BURST_LENGTH (32) 12333 12334 static int 12335 test_null_burst_operation(void) 12336 { 12337 struct crypto_testsuite_params *ts_params = &testsuite_params; 12338 struct crypto_unittest_params *ut_params = &unittest_params; 12339 int status; 12340 12341 unsigned i, burst_len = NULL_BURST_LENGTH; 12342 12343 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 12344 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 12345 12346 /* This test is for NULL PMD only */ 12347 if (gbl_driver_id != rte_cryptodev_driver_id_get( 12348 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 12349 return TEST_SKIPPED; 12350 12351 /* Setup Cipher Parameters */ 12352 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12353 ut_params->cipher_xform.next = &ut_params->auth_xform; 12354 12355 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 12356 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 12357 12358 /* Setup HMAC Parameters */ 12359 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12360 ut_params->auth_xform.next = NULL; 12361 12362 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 12363 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 12364 12365 ut_params->sess = rte_cryptodev_sym_session_create( 12366 ts_params->session_mpool); 12367 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12368 12369 /* Create Crypto session*/ 12370 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12371 ut_params->sess, &ut_params->cipher_xform, 12372 ts_params->session_priv_mpool); 12373 12374 if (status == -ENOTSUP) 12375 return TEST_SKIPPED; 12376 12377 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 12378 12379 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 12380 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 12381 burst_len, "failed to generate burst of crypto ops"); 12382 12383 /* Generate an operation for each mbuf in burst */ 12384 for (i = 0; i < burst_len; i++) { 12385 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12386 12387 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 12388 12389 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 12390 sizeof(unsigned)); 12391 *data = i; 12392 12393 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 12394 12395 burst[i]->sym->m_src = m; 12396 } 12397 12398 /* Process crypto operation */ 12399 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 12400 0, burst, burst_len), 12401 burst_len, 12402 "Error enqueuing burst"); 12403 12404 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 12405 0, burst_dequeued, burst_len), 12406 burst_len, 12407 "Error dequeuing burst"); 12408 12409 12410 for (i = 0; i < burst_len; i++) { 12411 TEST_ASSERT_EQUAL( 12412 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 12413 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 12414 uint32_t *), 12415 "data not as expected"); 12416 12417 rte_pktmbuf_free(burst[i]->sym->m_src); 12418 rte_crypto_op_free(burst[i]); 12419 } 12420 12421 return TEST_SUCCESS; 12422 } 12423 12424 static uint16_t 12425 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 12426 uint16_t nb_ops, void *user_param) 12427 { 12428 RTE_SET_USED(dev_id); 12429 RTE_SET_USED(qp_id); 12430 RTE_SET_USED(ops); 12431 RTE_SET_USED(user_param); 12432 12433 printf("crypto enqueue callback called\n"); 12434 return nb_ops; 12435 } 12436 12437 static uint16_t 12438 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 12439 uint16_t nb_ops, void *user_param) 12440 { 12441 RTE_SET_USED(dev_id); 12442 RTE_SET_USED(qp_id); 12443 RTE_SET_USED(ops); 12444 RTE_SET_USED(user_param); 12445 12446 printf("crypto dequeue callback called\n"); 12447 return nb_ops; 12448 } 12449 12450 /* 12451 * Thread using enqueue/dequeue callback with RCU. 12452 */ 12453 static int 12454 test_enqdeq_callback_thread(void *arg) 12455 { 12456 RTE_SET_USED(arg); 12457 /* DP thread calls rte_cryptodev_enqueue_burst()/ 12458 * rte_cryptodev_dequeue_burst() and invokes callback. 12459 */ 12460 test_null_burst_operation(); 12461 return 0; 12462 } 12463 12464 static int 12465 test_enq_callback_setup(void) 12466 { 12467 struct crypto_testsuite_params *ts_params = &testsuite_params; 12468 struct rte_cryptodev_info dev_info; 12469 struct rte_cryptodev_qp_conf qp_conf = { 12470 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 12471 }; 12472 12473 struct rte_cryptodev_cb *cb; 12474 uint16_t qp_id = 0; 12475 12476 /* Stop the device in case it's started so it can be configured */ 12477 rte_cryptodev_stop(ts_params->valid_devs[0]); 12478 12479 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12480 12481 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 12482 &ts_params->conf), 12483 "Failed to configure cryptodev %u", 12484 ts_params->valid_devs[0]); 12485 12486 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 12487 qp_conf.mp_session = ts_params->session_mpool; 12488 qp_conf.mp_session_private = ts_params->session_priv_mpool; 12489 12490 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 12491 ts_params->valid_devs[0], qp_id, &qp_conf, 12492 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 12493 "Failed test for " 12494 "rte_cryptodev_queue_pair_setup: num_inflights " 12495 "%u on qp %u on cryptodev %u", 12496 qp_conf.nb_descriptors, qp_id, 12497 ts_params->valid_devs[0]); 12498 12499 /* Test with invalid crypto device */ 12500 cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS, 12501 qp_id, test_enq_callback, NULL); 12502 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12503 "cryptodev %u did not fail", 12504 qp_id, RTE_CRYPTO_MAX_DEVS); 12505 12506 /* Test with invalid queue pair */ 12507 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 12508 dev_info.max_nb_queue_pairs + 1, 12509 test_enq_callback, NULL); 12510 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12511 "cryptodev %u did not fail", 12512 dev_info.max_nb_queue_pairs + 1, 12513 ts_params->valid_devs[0]); 12514 12515 /* Test with NULL callback */ 12516 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 12517 qp_id, NULL, NULL); 12518 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12519 "cryptodev %u did not fail", 12520 qp_id, ts_params->valid_devs[0]); 12521 12522 /* Test with valid configuration */ 12523 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 12524 qp_id, test_enq_callback, NULL); 12525 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 12526 "qp %u on cryptodev %u", 12527 qp_id, ts_params->valid_devs[0]); 12528 12529 rte_cryptodev_start(ts_params->valid_devs[0]); 12530 12531 /* Launch a thread */ 12532 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 12533 rte_get_next_lcore(-1, 1, 0)); 12534 12535 /* Wait until reader exited. */ 12536 rte_eal_mp_wait_lcore(); 12537 12538 /* Test with invalid crypto device */ 12539 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 12540 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 12541 "Expected call to fail as crypto device is invalid"); 12542 12543 /* Test with invalid queue pair */ 12544 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 12545 ts_params->valid_devs[0], 12546 dev_info.max_nb_queue_pairs + 1, cb), 12547 "Expected call to fail as queue pair is invalid"); 12548 12549 /* Test with NULL callback */ 12550 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 12551 ts_params->valid_devs[0], qp_id, NULL), 12552 "Expected call to fail as callback is NULL"); 12553 12554 /* Test with valid configuration */ 12555 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback( 12556 ts_params->valid_devs[0], qp_id, cb), 12557 "Failed test to remove callback on " 12558 "qp %u on cryptodev %u", 12559 qp_id, ts_params->valid_devs[0]); 12560 12561 return TEST_SUCCESS; 12562 } 12563 12564 static int 12565 test_deq_callback_setup(void) 12566 { 12567 struct crypto_testsuite_params *ts_params = &testsuite_params; 12568 struct rte_cryptodev_info dev_info; 12569 struct rte_cryptodev_qp_conf qp_conf = { 12570 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 12571 }; 12572 12573 struct rte_cryptodev_cb *cb; 12574 uint16_t qp_id = 0; 12575 12576 /* Stop the device in case it's started so it can be configured */ 12577 rte_cryptodev_stop(ts_params->valid_devs[0]); 12578 12579 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12580 12581 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 12582 &ts_params->conf), 12583 "Failed to configure cryptodev %u", 12584 ts_params->valid_devs[0]); 12585 12586 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 12587 qp_conf.mp_session = ts_params->session_mpool; 12588 qp_conf.mp_session_private = ts_params->session_priv_mpool; 12589 12590 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 12591 ts_params->valid_devs[0], qp_id, &qp_conf, 12592 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 12593 "Failed test for " 12594 "rte_cryptodev_queue_pair_setup: num_inflights " 12595 "%u on qp %u on cryptodev %u", 12596 qp_conf.nb_descriptors, qp_id, 12597 ts_params->valid_devs[0]); 12598 12599 /* Test with invalid crypto device */ 12600 cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS, 12601 qp_id, test_deq_callback, NULL); 12602 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12603 "cryptodev %u did not fail", 12604 qp_id, RTE_CRYPTO_MAX_DEVS); 12605 12606 /* Test with invalid queue pair */ 12607 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 12608 dev_info.max_nb_queue_pairs + 1, 12609 test_deq_callback, NULL); 12610 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12611 "cryptodev %u did not fail", 12612 dev_info.max_nb_queue_pairs + 1, 12613 ts_params->valid_devs[0]); 12614 12615 /* Test with NULL callback */ 12616 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 12617 qp_id, NULL, NULL); 12618 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12619 "cryptodev %u did not fail", 12620 qp_id, ts_params->valid_devs[0]); 12621 12622 /* Test with valid configuration */ 12623 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 12624 qp_id, test_deq_callback, NULL); 12625 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 12626 "qp %u on cryptodev %u", 12627 qp_id, ts_params->valid_devs[0]); 12628 12629 rte_cryptodev_start(ts_params->valid_devs[0]); 12630 12631 /* Launch a thread */ 12632 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 12633 rte_get_next_lcore(-1, 1, 0)); 12634 12635 /* Wait until reader exited. */ 12636 rte_eal_mp_wait_lcore(); 12637 12638 /* Test with invalid crypto device */ 12639 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 12640 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 12641 "Expected call to fail as crypto device is invalid"); 12642 12643 /* Test with invalid queue pair */ 12644 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 12645 ts_params->valid_devs[0], 12646 dev_info.max_nb_queue_pairs + 1, cb), 12647 "Expected call to fail as queue pair is invalid"); 12648 12649 /* Test with NULL callback */ 12650 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 12651 ts_params->valid_devs[0], qp_id, NULL), 12652 "Expected call to fail as callback is NULL"); 12653 12654 /* Test with valid configuration */ 12655 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback( 12656 ts_params->valid_devs[0], qp_id, cb), 12657 "Failed test to remove callback on " 12658 "qp %u on cryptodev %u", 12659 qp_id, ts_params->valid_devs[0]); 12660 12661 return TEST_SUCCESS; 12662 } 12663 12664 static void 12665 generate_gmac_large_plaintext(uint8_t *data) 12666 { 12667 uint16_t i; 12668 12669 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 12670 memcpy(&data[i], &data[0], 32); 12671 } 12672 12673 static int 12674 create_gmac_operation(enum rte_crypto_auth_operation op, 12675 const struct gmac_test_data *tdata) 12676 { 12677 struct crypto_testsuite_params *ts_params = &testsuite_params; 12678 struct crypto_unittest_params *ut_params = &unittest_params; 12679 struct rte_crypto_sym_op *sym_op; 12680 12681 uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12682 12683 /* Generate Crypto op data structure */ 12684 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12685 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12686 TEST_ASSERT_NOT_NULL(ut_params->op, 12687 "Failed to allocate symmetric crypto operation struct"); 12688 12689 sym_op = ut_params->op->sym; 12690 12691 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12692 ut_params->ibuf, tdata->gmac_tag.len); 12693 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12694 "no room to append digest"); 12695 12696 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12697 ut_params->ibuf, plaintext_pad_len); 12698 12699 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 12700 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 12701 tdata->gmac_tag.len); 12702 debug_hexdump(stdout, "digest:", 12703 sym_op->auth.digest.data, 12704 tdata->gmac_tag.len); 12705 } 12706 12707 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12708 uint8_t *, IV_OFFSET); 12709 12710 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 12711 12712 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 12713 12714 sym_op->cipher.data.length = 0; 12715 sym_op->cipher.data.offset = 0; 12716 12717 sym_op->auth.data.offset = 0; 12718 sym_op->auth.data.length = tdata->plaintext.len; 12719 12720 return 0; 12721 } 12722 12723 static int 12724 create_gmac_operation_sgl(enum rte_crypto_auth_operation op, 12725 const struct gmac_test_data *tdata, 12726 void *digest_mem, uint64_t digest_phys) 12727 { 12728 struct crypto_testsuite_params *ts_params = &testsuite_params; 12729 struct crypto_unittest_params *ut_params = &unittest_params; 12730 struct rte_crypto_sym_op *sym_op; 12731 12732 /* Generate Crypto op data structure */ 12733 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12734 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12735 TEST_ASSERT_NOT_NULL(ut_params->op, 12736 "Failed to allocate symmetric crypto operation struct"); 12737 12738 sym_op = ut_params->op->sym; 12739 12740 sym_op->auth.digest.data = digest_mem; 12741 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12742 "no room to append digest"); 12743 12744 sym_op->auth.digest.phys_addr = digest_phys; 12745 12746 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 12747 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 12748 tdata->gmac_tag.len); 12749 debug_hexdump(stdout, "digest:", 12750 sym_op->auth.digest.data, 12751 tdata->gmac_tag.len); 12752 } 12753 12754 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12755 uint8_t *, IV_OFFSET); 12756 12757 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 12758 12759 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 12760 12761 sym_op->cipher.data.length = 0; 12762 sym_op->cipher.data.offset = 0; 12763 12764 sym_op->auth.data.offset = 0; 12765 sym_op->auth.data.length = tdata->plaintext.len; 12766 12767 return 0; 12768 } 12769 12770 static int create_gmac_session(uint8_t dev_id, 12771 const struct gmac_test_data *tdata, 12772 enum rte_crypto_auth_operation auth_op) 12773 { 12774 uint8_t auth_key[tdata->key.len]; 12775 int status; 12776 12777 struct crypto_testsuite_params *ts_params = &testsuite_params; 12778 struct crypto_unittest_params *ut_params = &unittest_params; 12779 12780 memcpy(auth_key, tdata->key.data, tdata->key.len); 12781 12782 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12783 ut_params->auth_xform.next = NULL; 12784 12785 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 12786 ut_params->auth_xform.auth.op = auth_op; 12787 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 12788 ut_params->auth_xform.auth.key.length = tdata->key.len; 12789 ut_params->auth_xform.auth.key.data = auth_key; 12790 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 12791 ut_params->auth_xform.auth.iv.length = tdata->iv.len; 12792 12793 12794 ut_params->sess = rte_cryptodev_sym_session_create( 12795 ts_params->session_mpool); 12796 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12797 12798 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 12799 &ut_params->auth_xform, 12800 ts_params->session_priv_mpool); 12801 12802 return status; 12803 } 12804 12805 static int 12806 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 12807 { 12808 struct crypto_testsuite_params *ts_params = &testsuite_params; 12809 struct crypto_unittest_params *ut_params = &unittest_params; 12810 struct rte_cryptodev_info dev_info; 12811 12812 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12813 uint64_t feat_flags = dev_info.feature_flags; 12814 12815 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12816 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12817 printf("Device doesn't support RAW data-path APIs.\n"); 12818 return TEST_SKIPPED; 12819 } 12820 12821 int retval; 12822 12823 uint8_t *auth_tag, *plaintext; 12824 uint16_t plaintext_pad_len; 12825 12826 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 12827 "No GMAC length in the source data"); 12828 12829 /* Verify the capabilities */ 12830 struct rte_cryptodev_sym_capability_idx cap_idx; 12831 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12832 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 12833 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12834 &cap_idx) == NULL) 12835 return TEST_SKIPPED; 12836 12837 retval = create_gmac_session(ts_params->valid_devs[0], 12838 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 12839 12840 if (retval == -ENOTSUP) 12841 return TEST_SKIPPED; 12842 if (retval < 0) 12843 return retval; 12844 12845 if (tdata->plaintext.len > MBUF_SIZE) 12846 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 12847 else 12848 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12849 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12850 "Failed to allocate input buffer in mempool"); 12851 12852 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12853 rte_pktmbuf_tailroom(ut_params->ibuf)); 12854 12855 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12856 /* 12857 * Runtime generate the large plain text instead of use hard code 12858 * plain text vector. It is done to avoid create huge source file 12859 * with the test vector. 12860 */ 12861 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 12862 generate_gmac_large_plaintext(tdata->plaintext.data); 12863 12864 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12865 plaintext_pad_len); 12866 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12867 12868 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 12869 debug_hexdump(stdout, "plaintext:", plaintext, 12870 tdata->plaintext.len); 12871 12872 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 12873 tdata); 12874 12875 if (retval < 0) 12876 return retval; 12877 12878 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12879 12880 ut_params->op->sym->m_src = ut_params->ibuf; 12881 12882 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12883 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12884 ut_params->op); 12885 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12886 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12887 ut_params->op, 0, 1, 0, 0); 12888 else 12889 TEST_ASSERT_NOT_NULL( 12890 process_crypto_request(ts_params->valid_devs[0], 12891 ut_params->op), "failed to process sym crypto op"); 12892 12893 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12894 "crypto op processing failed"); 12895 12896 if (ut_params->op->sym->m_dst) { 12897 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 12898 uint8_t *, plaintext_pad_len); 12899 } else { 12900 auth_tag = plaintext + plaintext_pad_len; 12901 } 12902 12903 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 12904 12905 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12906 auth_tag, 12907 tdata->gmac_tag.data, 12908 tdata->gmac_tag.len, 12909 "GMAC Generated auth tag not as expected"); 12910 12911 return 0; 12912 } 12913 12914 static int 12915 test_AES_GMAC_authentication_test_case_1(void) 12916 { 12917 return test_AES_GMAC_authentication(&gmac_test_case_1); 12918 } 12919 12920 static int 12921 test_AES_GMAC_authentication_test_case_2(void) 12922 { 12923 return test_AES_GMAC_authentication(&gmac_test_case_2); 12924 } 12925 12926 static int 12927 test_AES_GMAC_authentication_test_case_3(void) 12928 { 12929 return test_AES_GMAC_authentication(&gmac_test_case_3); 12930 } 12931 12932 static int 12933 test_AES_GMAC_authentication_test_case_4(void) 12934 { 12935 return test_AES_GMAC_authentication(&gmac_test_case_4); 12936 } 12937 12938 static int 12939 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 12940 { 12941 struct crypto_testsuite_params *ts_params = &testsuite_params; 12942 struct crypto_unittest_params *ut_params = &unittest_params; 12943 int retval; 12944 uint32_t plaintext_pad_len; 12945 uint8_t *plaintext; 12946 struct rte_cryptodev_info dev_info; 12947 12948 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12949 uint64_t feat_flags = dev_info.feature_flags; 12950 12951 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12952 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12953 printf("Device doesn't support RAW data-path APIs.\n"); 12954 return TEST_SKIPPED; 12955 } 12956 12957 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 12958 "No GMAC length in the source data"); 12959 12960 /* Verify the capabilities */ 12961 struct rte_cryptodev_sym_capability_idx cap_idx; 12962 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12963 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 12964 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12965 &cap_idx) == NULL) 12966 return TEST_SKIPPED; 12967 12968 retval = create_gmac_session(ts_params->valid_devs[0], 12969 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 12970 12971 if (retval == -ENOTSUP) 12972 return TEST_SKIPPED; 12973 if (retval < 0) 12974 return retval; 12975 12976 if (tdata->plaintext.len > MBUF_SIZE) 12977 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 12978 else 12979 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12980 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12981 "Failed to allocate input buffer in mempool"); 12982 12983 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12984 rte_pktmbuf_tailroom(ut_params->ibuf)); 12985 12986 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12987 12988 /* 12989 * Runtime generate the large plain text instead of use hard code 12990 * plain text vector. It is done to avoid create huge source file 12991 * with the test vector. 12992 */ 12993 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 12994 generate_gmac_large_plaintext(tdata->plaintext.data); 12995 12996 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12997 plaintext_pad_len); 12998 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12999 13000 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 13001 debug_hexdump(stdout, "plaintext:", plaintext, 13002 tdata->plaintext.len); 13003 13004 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 13005 tdata); 13006 13007 if (retval < 0) 13008 return retval; 13009 13010 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13011 13012 ut_params->op->sym->m_src = ut_params->ibuf; 13013 13014 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13015 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13016 ut_params->op); 13017 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13018 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13019 ut_params->op, 0, 1, 0, 0); 13020 else 13021 TEST_ASSERT_NOT_NULL( 13022 process_crypto_request(ts_params->valid_devs[0], 13023 ut_params->op), "failed to process sym crypto op"); 13024 13025 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13026 "crypto op processing failed"); 13027 13028 return 0; 13029 13030 } 13031 13032 static int 13033 test_AES_GMAC_authentication_verify_test_case_1(void) 13034 { 13035 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 13036 } 13037 13038 static int 13039 test_AES_GMAC_authentication_verify_test_case_2(void) 13040 { 13041 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 13042 } 13043 13044 static int 13045 test_AES_GMAC_authentication_verify_test_case_3(void) 13046 { 13047 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 13048 } 13049 13050 static int 13051 test_AES_GMAC_authentication_verify_test_case_4(void) 13052 { 13053 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 13054 } 13055 13056 static int 13057 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata, 13058 uint32_t fragsz) 13059 { 13060 struct crypto_testsuite_params *ts_params = &testsuite_params; 13061 struct crypto_unittest_params *ut_params = &unittest_params; 13062 struct rte_cryptodev_info dev_info; 13063 uint64_t feature_flags; 13064 unsigned int trn_data = 0; 13065 void *digest_mem = NULL; 13066 uint32_t segs = 1; 13067 unsigned int to_trn = 0; 13068 struct rte_mbuf *buf = NULL; 13069 uint8_t *auth_tag, *plaintext; 13070 int retval; 13071 13072 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 13073 "No GMAC length in the source data"); 13074 13075 /* Verify the capabilities */ 13076 struct rte_cryptodev_sym_capability_idx cap_idx; 13077 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13078 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 13079 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13080 &cap_idx) == NULL) 13081 return TEST_SKIPPED; 13082 13083 /* Check for any input SGL support */ 13084 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13085 feature_flags = dev_info.feature_flags; 13086 13087 if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) || 13088 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) || 13089 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))) 13090 return TEST_SKIPPED; 13091 13092 if (fragsz > tdata->plaintext.len) 13093 fragsz = tdata->plaintext.len; 13094 13095 uint16_t plaintext_len = fragsz; 13096 13097 retval = create_gmac_session(ts_params->valid_devs[0], 13098 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 13099 13100 if (retval == -ENOTSUP) 13101 return TEST_SKIPPED; 13102 if (retval < 0) 13103 return retval; 13104 13105 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13106 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13107 "Failed to allocate input buffer in mempool"); 13108 13109 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13110 rte_pktmbuf_tailroom(ut_params->ibuf)); 13111 13112 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13113 plaintext_len); 13114 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13115 13116 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 13117 13118 trn_data += plaintext_len; 13119 13120 buf = ut_params->ibuf; 13121 13122 /* 13123 * Loop until no more fragments 13124 */ 13125 13126 while (trn_data < tdata->plaintext.len) { 13127 ++segs; 13128 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 13129 (tdata->plaintext.len - trn_data) : fragsz; 13130 13131 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13132 buf = buf->next; 13133 13134 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 13135 rte_pktmbuf_tailroom(buf)); 13136 13137 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 13138 to_trn); 13139 13140 memcpy(plaintext, tdata->plaintext.data + trn_data, 13141 to_trn); 13142 trn_data += to_trn; 13143 if (trn_data == tdata->plaintext.len) 13144 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 13145 tdata->gmac_tag.len); 13146 } 13147 ut_params->ibuf->nb_segs = segs; 13148 13149 /* 13150 * Place digest at the end of the last buffer 13151 */ 13152 uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn; 13153 13154 if (!digest_mem) { 13155 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13156 + tdata->gmac_tag.len); 13157 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 13158 tdata->plaintext.len); 13159 } 13160 13161 retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE, 13162 tdata, digest_mem, digest_phys); 13163 13164 if (retval < 0) 13165 return retval; 13166 13167 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13168 13169 ut_params->op->sym->m_src = ut_params->ibuf; 13170 13171 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13172 return TEST_SKIPPED; 13173 13174 TEST_ASSERT_NOT_NULL( 13175 process_crypto_request(ts_params->valid_devs[0], 13176 ut_params->op), "failed to process sym crypto op"); 13177 13178 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13179 "crypto op processing failed"); 13180 13181 auth_tag = digest_mem; 13182 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 13183 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13184 auth_tag, 13185 tdata->gmac_tag.data, 13186 tdata->gmac_tag.len, 13187 "GMAC Generated auth tag not as expected"); 13188 13189 return 0; 13190 } 13191 13192 /* Segment size not multiple of block size (16B) */ 13193 static int 13194 test_AES_GMAC_authentication_SGL_40B(void) 13195 { 13196 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40); 13197 } 13198 13199 static int 13200 test_AES_GMAC_authentication_SGL_80B(void) 13201 { 13202 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80); 13203 } 13204 13205 static int 13206 test_AES_GMAC_authentication_SGL_2048B(void) 13207 { 13208 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048); 13209 } 13210 13211 /* Segment size not multiple of block size (16B) */ 13212 static int 13213 test_AES_GMAC_authentication_SGL_2047B(void) 13214 { 13215 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047); 13216 } 13217 13218 struct test_crypto_vector { 13219 enum rte_crypto_cipher_algorithm crypto_algo; 13220 unsigned int cipher_offset; 13221 unsigned int cipher_len; 13222 13223 struct { 13224 uint8_t data[64]; 13225 unsigned int len; 13226 } cipher_key; 13227 13228 struct { 13229 uint8_t data[64]; 13230 unsigned int len; 13231 } iv; 13232 13233 struct { 13234 const uint8_t *data; 13235 unsigned int len; 13236 } plaintext; 13237 13238 struct { 13239 const uint8_t *data; 13240 unsigned int len; 13241 } ciphertext; 13242 13243 enum rte_crypto_auth_algorithm auth_algo; 13244 unsigned int auth_offset; 13245 13246 struct { 13247 uint8_t data[128]; 13248 unsigned int len; 13249 } auth_key; 13250 13251 struct { 13252 const uint8_t *data; 13253 unsigned int len; 13254 } aad; 13255 13256 struct { 13257 uint8_t data[128]; 13258 unsigned int len; 13259 } digest; 13260 }; 13261 13262 static const struct test_crypto_vector 13263 hmac_sha1_test_crypto_vector = { 13264 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 13265 .plaintext = { 13266 .data = plaintext_hash, 13267 .len = 512 13268 }, 13269 .auth_key = { 13270 .data = { 13271 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 13272 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 13273 0xDE, 0xF4, 0xDE, 0xAD 13274 }, 13275 .len = 20 13276 }, 13277 .digest = { 13278 .data = { 13279 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 13280 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 13281 0x3F, 0x91, 0x64, 0x59 13282 }, 13283 .len = 20 13284 } 13285 }; 13286 13287 static const struct test_crypto_vector 13288 aes128_gmac_test_vector = { 13289 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 13290 .plaintext = { 13291 .data = plaintext_hash, 13292 .len = 512 13293 }, 13294 .iv = { 13295 .data = { 13296 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 13297 0x08, 0x09, 0x0A, 0x0B 13298 }, 13299 .len = 12 13300 }, 13301 .auth_key = { 13302 .data = { 13303 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 13304 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 13305 }, 13306 .len = 16 13307 }, 13308 .digest = { 13309 .data = { 13310 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 13311 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 13312 }, 13313 .len = 16 13314 } 13315 }; 13316 13317 static const struct test_crypto_vector 13318 aes128cbc_hmac_sha1_test_vector = { 13319 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 13320 .cipher_offset = 0, 13321 .cipher_len = 512, 13322 .cipher_key = { 13323 .data = { 13324 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 13325 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 13326 }, 13327 .len = 16 13328 }, 13329 .iv = { 13330 .data = { 13331 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 13332 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 13333 }, 13334 .len = 16 13335 }, 13336 .plaintext = { 13337 .data = plaintext_hash, 13338 .len = 512 13339 }, 13340 .ciphertext = { 13341 .data = ciphertext512_aes128cbc, 13342 .len = 512 13343 }, 13344 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 13345 .auth_offset = 0, 13346 .auth_key = { 13347 .data = { 13348 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 13349 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 13350 0xDE, 0xF4, 0xDE, 0xAD 13351 }, 13352 .len = 20 13353 }, 13354 .digest = { 13355 .data = { 13356 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 13357 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 13358 0x18, 0x8C, 0x1D, 0x32 13359 }, 13360 .len = 20 13361 } 13362 }; 13363 13364 static const struct test_crypto_vector 13365 aes128cbc_hmac_sha1_aad_test_vector = { 13366 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 13367 .cipher_offset = 8, 13368 .cipher_len = 496, 13369 .cipher_key = { 13370 .data = { 13371 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 13372 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 13373 }, 13374 .len = 16 13375 }, 13376 .iv = { 13377 .data = { 13378 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 13379 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 13380 }, 13381 .len = 16 13382 }, 13383 .plaintext = { 13384 .data = plaintext_hash, 13385 .len = 512 13386 }, 13387 .ciphertext = { 13388 .data = ciphertext512_aes128cbc_aad, 13389 .len = 512 13390 }, 13391 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 13392 .auth_offset = 0, 13393 .auth_key = { 13394 .data = { 13395 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 13396 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 13397 0xDE, 0xF4, 0xDE, 0xAD 13398 }, 13399 .len = 20 13400 }, 13401 .digest = { 13402 .data = { 13403 0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F, 13404 0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B, 13405 0x62, 0x0F, 0xFB, 0x10 13406 }, 13407 .len = 20 13408 } 13409 }; 13410 13411 static void 13412 data_corruption(uint8_t *data) 13413 { 13414 data[0] += 1; 13415 } 13416 13417 static void 13418 tag_corruption(uint8_t *data, unsigned int tag_offset) 13419 { 13420 data[tag_offset] += 1; 13421 } 13422 13423 static int 13424 create_auth_session(struct crypto_unittest_params *ut_params, 13425 uint8_t dev_id, 13426 const struct test_crypto_vector *reference, 13427 enum rte_crypto_auth_operation auth_op) 13428 { 13429 struct crypto_testsuite_params *ts_params = &testsuite_params; 13430 uint8_t auth_key[reference->auth_key.len + 1]; 13431 int status; 13432 13433 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 13434 13435 /* Setup Authentication Parameters */ 13436 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13437 ut_params->auth_xform.auth.op = auth_op; 13438 ut_params->auth_xform.next = NULL; 13439 ut_params->auth_xform.auth.algo = reference->auth_algo; 13440 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 13441 ut_params->auth_xform.auth.key.data = auth_key; 13442 ut_params->auth_xform.auth.digest_length = reference->digest.len; 13443 13444 /* Create Crypto session*/ 13445 ut_params->sess = rte_cryptodev_sym_session_create( 13446 ts_params->session_mpool); 13447 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13448 13449 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 13450 &ut_params->auth_xform, 13451 ts_params->session_priv_mpool); 13452 13453 return status; 13454 } 13455 13456 static int 13457 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 13458 uint8_t dev_id, 13459 const struct test_crypto_vector *reference, 13460 enum rte_crypto_auth_operation auth_op, 13461 enum rte_crypto_cipher_operation cipher_op) 13462 { 13463 struct crypto_testsuite_params *ts_params = &testsuite_params; 13464 uint8_t cipher_key[reference->cipher_key.len + 1]; 13465 uint8_t auth_key[reference->auth_key.len + 1]; 13466 int status; 13467 13468 memcpy(cipher_key, reference->cipher_key.data, 13469 reference->cipher_key.len); 13470 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 13471 13472 /* Setup Authentication Parameters */ 13473 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13474 ut_params->auth_xform.auth.op = auth_op; 13475 ut_params->auth_xform.auth.algo = reference->auth_algo; 13476 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 13477 ut_params->auth_xform.auth.key.data = auth_key; 13478 ut_params->auth_xform.auth.digest_length = reference->digest.len; 13479 13480 if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) { 13481 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 13482 ut_params->auth_xform.auth.iv.length = reference->iv.len; 13483 } else { 13484 ut_params->auth_xform.next = &ut_params->cipher_xform; 13485 13486 /* Setup Cipher Parameters */ 13487 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13488 ut_params->cipher_xform.next = NULL; 13489 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 13490 ut_params->cipher_xform.cipher.op = cipher_op; 13491 ut_params->cipher_xform.cipher.key.data = cipher_key; 13492 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 13493 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 13494 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 13495 } 13496 13497 /* Create Crypto session*/ 13498 ut_params->sess = rte_cryptodev_sym_session_create( 13499 ts_params->session_mpool); 13500 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13501 13502 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 13503 &ut_params->auth_xform, 13504 ts_params->session_priv_mpool); 13505 13506 return status; 13507 } 13508 13509 static int 13510 create_auth_operation(struct crypto_testsuite_params *ts_params, 13511 struct crypto_unittest_params *ut_params, 13512 const struct test_crypto_vector *reference, 13513 unsigned int auth_generate) 13514 { 13515 /* Generate Crypto op data structure */ 13516 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13517 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13518 TEST_ASSERT_NOT_NULL(ut_params->op, 13519 "Failed to allocate pktmbuf offload"); 13520 13521 /* Set crypto operation data parameters */ 13522 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13523 13524 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 13525 13526 /* set crypto operation source mbuf */ 13527 sym_op->m_src = ut_params->ibuf; 13528 13529 /* digest */ 13530 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 13531 ut_params->ibuf, reference->digest.len); 13532 13533 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13534 "no room to append auth tag"); 13535 13536 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 13537 ut_params->ibuf, reference->plaintext.len); 13538 13539 if (auth_generate) 13540 memset(sym_op->auth.digest.data, 0, reference->digest.len); 13541 else 13542 memcpy(sym_op->auth.digest.data, 13543 reference->digest.data, 13544 reference->digest.len); 13545 13546 debug_hexdump(stdout, "digest:", 13547 sym_op->auth.digest.data, 13548 reference->digest.len); 13549 13550 sym_op->auth.data.length = reference->plaintext.len; 13551 sym_op->auth.data.offset = 0; 13552 13553 return 0; 13554 } 13555 13556 static int 13557 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 13558 struct crypto_unittest_params *ut_params, 13559 const struct test_crypto_vector *reference, 13560 unsigned int auth_generate) 13561 { 13562 /* Generate Crypto op data structure */ 13563 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13564 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13565 TEST_ASSERT_NOT_NULL(ut_params->op, 13566 "Failed to allocate pktmbuf offload"); 13567 13568 /* Set crypto operation data parameters */ 13569 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13570 13571 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 13572 13573 /* set crypto operation source mbuf */ 13574 sym_op->m_src = ut_params->ibuf; 13575 13576 /* digest */ 13577 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 13578 ut_params->ibuf, reference->digest.len); 13579 13580 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13581 "no room to append auth tag"); 13582 13583 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 13584 ut_params->ibuf, reference->ciphertext.len); 13585 13586 if (auth_generate) 13587 memset(sym_op->auth.digest.data, 0, reference->digest.len); 13588 else 13589 memcpy(sym_op->auth.digest.data, 13590 reference->digest.data, 13591 reference->digest.len); 13592 13593 debug_hexdump(stdout, "digest:", 13594 sym_op->auth.digest.data, 13595 reference->digest.len); 13596 13597 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 13598 reference->iv.data, reference->iv.len); 13599 13600 sym_op->cipher.data.length = 0; 13601 sym_op->cipher.data.offset = 0; 13602 13603 sym_op->auth.data.length = reference->plaintext.len; 13604 sym_op->auth.data.offset = 0; 13605 13606 return 0; 13607 } 13608 13609 static int 13610 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 13611 struct crypto_unittest_params *ut_params, 13612 const struct test_crypto_vector *reference, 13613 unsigned int auth_generate) 13614 { 13615 /* Generate Crypto op data structure */ 13616 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13617 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13618 TEST_ASSERT_NOT_NULL(ut_params->op, 13619 "Failed to allocate pktmbuf offload"); 13620 13621 /* Set crypto operation data parameters */ 13622 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13623 13624 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 13625 13626 /* set crypto operation source mbuf */ 13627 sym_op->m_src = ut_params->ibuf; 13628 13629 /* digest */ 13630 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 13631 ut_params->ibuf, reference->digest.len); 13632 13633 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13634 "no room to append auth tag"); 13635 13636 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 13637 ut_params->ibuf, reference->ciphertext.len); 13638 13639 if (auth_generate) 13640 memset(sym_op->auth.digest.data, 0, reference->digest.len); 13641 else 13642 memcpy(sym_op->auth.digest.data, 13643 reference->digest.data, 13644 reference->digest.len); 13645 13646 debug_hexdump(stdout, "digest:", 13647 sym_op->auth.digest.data, 13648 reference->digest.len); 13649 13650 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 13651 reference->iv.data, reference->iv.len); 13652 13653 sym_op->cipher.data.length = reference->cipher_len; 13654 sym_op->cipher.data.offset = reference->cipher_offset; 13655 13656 sym_op->auth.data.length = reference->plaintext.len; 13657 sym_op->auth.data.offset = reference->auth_offset; 13658 13659 return 0; 13660 } 13661 13662 static int 13663 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 13664 struct crypto_unittest_params *ut_params, 13665 const struct test_crypto_vector *reference) 13666 { 13667 return create_auth_operation(ts_params, ut_params, reference, 0); 13668 } 13669 13670 static int 13671 create_auth_verify_GMAC_operation( 13672 struct crypto_testsuite_params *ts_params, 13673 struct crypto_unittest_params *ut_params, 13674 const struct test_crypto_vector *reference) 13675 { 13676 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 13677 } 13678 13679 static int 13680 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params, 13681 struct crypto_unittest_params *ut_params, 13682 const struct test_crypto_vector *reference) 13683 { 13684 return create_cipher_auth_operation(ts_params, ut_params, reference, 0); 13685 } 13686 13687 static int 13688 test_authentication_verify_fail_when_data_corruption( 13689 struct crypto_testsuite_params *ts_params, 13690 struct crypto_unittest_params *ut_params, 13691 const struct test_crypto_vector *reference, 13692 unsigned int data_corrupted) 13693 { 13694 int retval; 13695 13696 uint8_t *plaintext; 13697 struct rte_cryptodev_info dev_info; 13698 13699 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13700 uint64_t feat_flags = dev_info.feature_flags; 13701 13702 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13703 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13704 printf("Device doesn't support RAW data-path APIs.\n"); 13705 return TEST_SKIPPED; 13706 } 13707 13708 /* Verify the capabilities */ 13709 struct rte_cryptodev_sym_capability_idx cap_idx; 13710 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13711 cap_idx.algo.auth = reference->auth_algo; 13712 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13713 &cap_idx) == NULL) 13714 return TEST_SKIPPED; 13715 13716 13717 /* Create session */ 13718 retval = create_auth_session(ut_params, 13719 ts_params->valid_devs[0], 13720 reference, 13721 RTE_CRYPTO_AUTH_OP_VERIFY); 13722 13723 if (retval == -ENOTSUP) 13724 return TEST_SKIPPED; 13725 if (retval < 0) 13726 return retval; 13727 13728 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13729 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13730 "Failed to allocate input buffer in mempool"); 13731 13732 /* clear mbuf payload */ 13733 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13734 rte_pktmbuf_tailroom(ut_params->ibuf)); 13735 13736 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13737 reference->plaintext.len); 13738 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13739 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 13740 13741 debug_hexdump(stdout, "plaintext:", plaintext, 13742 reference->plaintext.len); 13743 13744 /* Create operation */ 13745 retval = create_auth_verify_operation(ts_params, ut_params, reference); 13746 13747 if (retval < 0) 13748 return retval; 13749 13750 if (data_corrupted) 13751 data_corruption(plaintext); 13752 else 13753 tag_corruption(plaintext, reference->plaintext.len); 13754 13755 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13756 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13757 ut_params->op); 13758 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13759 RTE_CRYPTO_OP_STATUS_SUCCESS, 13760 "authentication not failed"); 13761 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13762 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13763 ut_params->op, 0, 1, 0, 0); 13764 else { 13765 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13766 ut_params->op); 13767 } 13768 if (ut_params->op == NULL) 13769 return 0; 13770 else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) 13771 return 0; 13772 13773 return -1; 13774 } 13775 13776 static int 13777 test_authentication_verify_GMAC_fail_when_corruption( 13778 struct crypto_testsuite_params *ts_params, 13779 struct crypto_unittest_params *ut_params, 13780 const struct test_crypto_vector *reference, 13781 unsigned int data_corrupted) 13782 { 13783 int retval; 13784 uint8_t *plaintext; 13785 struct rte_cryptodev_info dev_info; 13786 13787 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13788 uint64_t feat_flags = dev_info.feature_flags; 13789 13790 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13791 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13792 printf("Device doesn't support RAW data-path APIs.\n"); 13793 return TEST_SKIPPED; 13794 } 13795 13796 /* Verify the capabilities */ 13797 struct rte_cryptodev_sym_capability_idx cap_idx; 13798 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13799 cap_idx.algo.auth = reference->auth_algo; 13800 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13801 &cap_idx) == NULL) 13802 return TEST_SKIPPED; 13803 13804 /* Create session */ 13805 retval = create_auth_cipher_session(ut_params, 13806 ts_params->valid_devs[0], 13807 reference, 13808 RTE_CRYPTO_AUTH_OP_VERIFY, 13809 RTE_CRYPTO_CIPHER_OP_DECRYPT); 13810 if (retval < 0) 13811 return retval; 13812 13813 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13814 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13815 "Failed to allocate input buffer in mempool"); 13816 13817 /* clear mbuf payload */ 13818 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13819 rte_pktmbuf_tailroom(ut_params->ibuf)); 13820 13821 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13822 reference->plaintext.len); 13823 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13824 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 13825 13826 debug_hexdump(stdout, "plaintext:", plaintext, 13827 reference->plaintext.len); 13828 13829 /* Create operation */ 13830 retval = create_auth_verify_GMAC_operation(ts_params, 13831 ut_params, 13832 reference); 13833 13834 if (retval < 0) 13835 return retval; 13836 13837 if (data_corrupted) 13838 data_corruption(plaintext); 13839 else 13840 tag_corruption(plaintext, reference->aad.len); 13841 13842 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13843 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13844 ut_params->op); 13845 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13846 RTE_CRYPTO_OP_STATUS_SUCCESS, 13847 "authentication not failed"); 13848 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13849 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13850 ut_params->op, 0, 1, 0, 0); 13851 else { 13852 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13853 ut_params->op); 13854 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 13855 } 13856 13857 return 0; 13858 } 13859 13860 static int 13861 test_authenticated_decryption_fail_when_corruption( 13862 struct crypto_testsuite_params *ts_params, 13863 struct crypto_unittest_params *ut_params, 13864 const struct test_crypto_vector *reference, 13865 unsigned int data_corrupted) 13866 { 13867 int retval; 13868 13869 uint8_t *ciphertext; 13870 struct rte_cryptodev_info dev_info; 13871 13872 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13873 uint64_t feat_flags = dev_info.feature_flags; 13874 13875 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13876 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13877 printf("Device doesn't support RAW data-path APIs.\n"); 13878 return TEST_SKIPPED; 13879 } 13880 13881 /* Verify the capabilities */ 13882 struct rte_cryptodev_sym_capability_idx cap_idx; 13883 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13884 cap_idx.algo.auth = reference->auth_algo; 13885 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13886 &cap_idx) == NULL) 13887 return TEST_SKIPPED; 13888 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13889 cap_idx.algo.cipher = reference->crypto_algo; 13890 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13891 &cap_idx) == NULL) 13892 return TEST_SKIPPED; 13893 13894 /* Create session */ 13895 retval = create_auth_cipher_session(ut_params, 13896 ts_params->valid_devs[0], 13897 reference, 13898 RTE_CRYPTO_AUTH_OP_VERIFY, 13899 RTE_CRYPTO_CIPHER_OP_DECRYPT); 13900 13901 if (retval == -ENOTSUP) 13902 return TEST_SKIPPED; 13903 if (retval < 0) 13904 return retval; 13905 13906 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13907 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13908 "Failed to allocate input buffer in mempool"); 13909 13910 /* clear mbuf payload */ 13911 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13912 rte_pktmbuf_tailroom(ut_params->ibuf)); 13913 13914 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13915 reference->ciphertext.len); 13916 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 13917 memcpy(ciphertext, reference->ciphertext.data, 13918 reference->ciphertext.len); 13919 13920 /* Create operation */ 13921 retval = create_cipher_auth_verify_operation(ts_params, 13922 ut_params, 13923 reference); 13924 13925 if (retval < 0) 13926 return retval; 13927 13928 if (data_corrupted) 13929 data_corruption(ciphertext); 13930 else 13931 tag_corruption(ciphertext, reference->ciphertext.len); 13932 13933 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13934 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13935 ut_params->op); 13936 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13937 RTE_CRYPTO_OP_STATUS_SUCCESS, 13938 "authentication not failed"); 13939 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13940 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13941 ut_params->op, 1, 1, 0, 0); 13942 else { 13943 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13944 ut_params->op); 13945 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 13946 } 13947 13948 return 0; 13949 } 13950 13951 static int 13952 test_authenticated_encrypt_with_esn( 13953 struct crypto_testsuite_params *ts_params, 13954 struct crypto_unittest_params *ut_params, 13955 const struct test_crypto_vector *reference) 13956 { 13957 int retval; 13958 13959 uint8_t *authciphertext, *plaintext, *auth_tag; 13960 uint16_t plaintext_pad_len; 13961 uint8_t cipher_key[reference->cipher_key.len + 1]; 13962 uint8_t auth_key[reference->auth_key.len + 1]; 13963 struct rte_cryptodev_info dev_info; 13964 int status; 13965 13966 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13967 uint64_t feat_flags = dev_info.feature_flags; 13968 13969 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13970 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13971 printf("Device doesn't support RAW data-path APIs.\n"); 13972 return TEST_SKIPPED; 13973 } 13974 13975 /* Verify the capabilities */ 13976 struct rte_cryptodev_sym_capability_idx cap_idx; 13977 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13978 cap_idx.algo.auth = reference->auth_algo; 13979 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13980 &cap_idx) == NULL) 13981 return TEST_SKIPPED; 13982 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13983 cap_idx.algo.cipher = reference->crypto_algo; 13984 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13985 &cap_idx) == NULL) 13986 return TEST_SKIPPED; 13987 13988 /* Create session */ 13989 memcpy(cipher_key, reference->cipher_key.data, 13990 reference->cipher_key.len); 13991 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 13992 13993 /* Setup Cipher Parameters */ 13994 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13995 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 13996 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 13997 ut_params->cipher_xform.cipher.key.data = cipher_key; 13998 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 13999 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 14000 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 14001 14002 ut_params->cipher_xform.next = &ut_params->auth_xform; 14003 14004 /* Setup Authentication Parameters */ 14005 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14006 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 14007 ut_params->auth_xform.auth.algo = reference->auth_algo; 14008 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 14009 ut_params->auth_xform.auth.key.data = auth_key; 14010 ut_params->auth_xform.auth.digest_length = reference->digest.len; 14011 ut_params->auth_xform.next = NULL; 14012 14013 /* Create Crypto session*/ 14014 ut_params->sess = rte_cryptodev_sym_session_create( 14015 ts_params->session_mpool); 14016 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 14017 14018 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 14019 ut_params->sess, 14020 &ut_params->cipher_xform, 14021 ts_params->session_priv_mpool); 14022 14023 if (status == -ENOTSUP) 14024 return TEST_SKIPPED; 14025 14026 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 14027 14028 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14029 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14030 "Failed to allocate input buffer in mempool"); 14031 14032 /* clear mbuf payload */ 14033 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14034 rte_pktmbuf_tailroom(ut_params->ibuf)); 14035 14036 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14037 reference->plaintext.len); 14038 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14039 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 14040 14041 /* Create operation */ 14042 retval = create_cipher_auth_operation(ts_params, 14043 ut_params, 14044 reference, 0); 14045 14046 if (retval < 0) 14047 return retval; 14048 14049 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14050 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14051 ut_params->op); 14052 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14053 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 14054 ut_params->op, 1, 1, 0, 0); 14055 else 14056 ut_params->op = process_crypto_request( 14057 ts_params->valid_devs[0], ut_params->op); 14058 14059 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 14060 14061 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14062 "crypto op processing failed"); 14063 14064 plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16); 14065 14066 authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 14067 ut_params->op->sym->auth.data.offset); 14068 auth_tag = authciphertext + plaintext_pad_len; 14069 debug_hexdump(stdout, "ciphertext:", authciphertext, 14070 reference->ciphertext.len); 14071 debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len); 14072 14073 /* Validate obuf */ 14074 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14075 authciphertext, 14076 reference->ciphertext.data, 14077 reference->ciphertext.len, 14078 "Ciphertext data not as expected"); 14079 14080 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14081 auth_tag, 14082 reference->digest.data, 14083 reference->digest.len, 14084 "Generated digest not as expected"); 14085 14086 return TEST_SUCCESS; 14087 14088 } 14089 14090 static int 14091 test_authenticated_decrypt_with_esn( 14092 struct crypto_testsuite_params *ts_params, 14093 struct crypto_unittest_params *ut_params, 14094 const struct test_crypto_vector *reference) 14095 { 14096 int retval; 14097 14098 uint8_t *ciphertext; 14099 uint8_t cipher_key[reference->cipher_key.len + 1]; 14100 uint8_t auth_key[reference->auth_key.len + 1]; 14101 struct rte_cryptodev_info dev_info; 14102 14103 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14104 uint64_t feat_flags = dev_info.feature_flags; 14105 14106 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14107 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14108 printf("Device doesn't support RAW data-path APIs.\n"); 14109 return TEST_SKIPPED; 14110 } 14111 14112 /* Verify the capabilities */ 14113 struct rte_cryptodev_sym_capability_idx cap_idx; 14114 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14115 cap_idx.algo.auth = reference->auth_algo; 14116 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14117 &cap_idx) == NULL) 14118 return TEST_SKIPPED; 14119 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 14120 cap_idx.algo.cipher = reference->crypto_algo; 14121 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14122 &cap_idx) == NULL) 14123 return TEST_SKIPPED; 14124 14125 /* Create session */ 14126 memcpy(cipher_key, reference->cipher_key.data, 14127 reference->cipher_key.len); 14128 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 14129 14130 /* Setup Authentication Parameters */ 14131 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14132 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 14133 ut_params->auth_xform.auth.algo = reference->auth_algo; 14134 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 14135 ut_params->auth_xform.auth.key.data = auth_key; 14136 ut_params->auth_xform.auth.digest_length = reference->digest.len; 14137 ut_params->auth_xform.next = &ut_params->cipher_xform; 14138 14139 /* Setup Cipher Parameters */ 14140 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 14141 ut_params->cipher_xform.next = NULL; 14142 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 14143 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 14144 ut_params->cipher_xform.cipher.key.data = cipher_key; 14145 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 14146 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 14147 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 14148 14149 /* Create Crypto session*/ 14150 ut_params->sess = rte_cryptodev_sym_session_create( 14151 ts_params->session_mpool); 14152 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 14153 14154 retval = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 14155 ut_params->sess, 14156 &ut_params->auth_xform, 14157 ts_params->session_priv_mpool); 14158 14159 if (retval == -ENOTSUP) 14160 return TEST_SKIPPED; 14161 14162 TEST_ASSERT_EQUAL(retval, 0, "Session init failed"); 14163 14164 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14165 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14166 "Failed to allocate input buffer in mempool"); 14167 14168 /* clear mbuf payload */ 14169 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14170 rte_pktmbuf_tailroom(ut_params->ibuf)); 14171 14172 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14173 reference->ciphertext.len); 14174 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 14175 memcpy(ciphertext, reference->ciphertext.data, 14176 reference->ciphertext.len); 14177 14178 /* Create operation */ 14179 retval = create_cipher_auth_verify_operation(ts_params, 14180 ut_params, 14181 reference); 14182 14183 if (retval < 0) 14184 return retval; 14185 14186 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14187 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14188 ut_params->op); 14189 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14190 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 14191 ut_params->op, 1, 1, 0, 0); 14192 else 14193 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 14194 ut_params->op); 14195 14196 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 14197 TEST_ASSERT_EQUAL(ut_params->op->status, 14198 RTE_CRYPTO_OP_STATUS_SUCCESS, 14199 "crypto op processing passed"); 14200 14201 ut_params->obuf = ut_params->op->sym->m_src; 14202 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 14203 14204 return 0; 14205 } 14206 14207 static int 14208 create_aead_operation_SGL(enum rte_crypto_aead_operation op, 14209 const struct aead_test_data *tdata, 14210 void *digest_mem, uint64_t digest_phys) 14211 { 14212 struct crypto_testsuite_params *ts_params = &testsuite_params; 14213 struct crypto_unittest_params *ut_params = &unittest_params; 14214 14215 const unsigned int auth_tag_len = tdata->auth_tag.len; 14216 const unsigned int iv_len = tdata->iv.len; 14217 unsigned int aad_len = tdata->aad.len; 14218 unsigned int aad_len_pad = 0; 14219 14220 /* Generate Crypto op data structure */ 14221 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 14222 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 14223 TEST_ASSERT_NOT_NULL(ut_params->op, 14224 "Failed to allocate symmetric crypto operation struct"); 14225 14226 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 14227 14228 sym_op->aead.digest.data = digest_mem; 14229 14230 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 14231 "no room to append digest"); 14232 14233 sym_op->aead.digest.phys_addr = digest_phys; 14234 14235 if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) { 14236 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 14237 auth_tag_len); 14238 debug_hexdump(stdout, "digest:", 14239 sym_op->aead.digest.data, 14240 auth_tag_len); 14241 } 14242 14243 /* Append aad data */ 14244 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 14245 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 14246 uint8_t *, IV_OFFSET); 14247 14248 /* Copy IV 1 byte after the IV pointer, according to the API */ 14249 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len); 14250 14251 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16); 14252 14253 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 14254 ut_params->ibuf, aad_len); 14255 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 14256 "no room to prepend aad"); 14257 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 14258 ut_params->ibuf); 14259 14260 memset(sym_op->aead.aad.data, 0, aad_len); 14261 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 14262 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 14263 14264 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 14265 debug_hexdump(stdout, "aad:", 14266 sym_op->aead.aad.data, aad_len); 14267 } else { 14268 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 14269 uint8_t *, IV_OFFSET); 14270 14271 rte_memcpy(iv_ptr, tdata->iv.data, iv_len); 14272 14273 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16); 14274 14275 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 14276 ut_params->ibuf, aad_len_pad); 14277 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 14278 "no room to prepend aad"); 14279 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 14280 ut_params->ibuf); 14281 14282 memset(sym_op->aead.aad.data, 0, aad_len); 14283 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 14284 14285 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 14286 debug_hexdump(stdout, "aad:", 14287 sym_op->aead.aad.data, aad_len); 14288 } 14289 14290 sym_op->aead.data.length = tdata->plaintext.len; 14291 sym_op->aead.data.offset = aad_len_pad; 14292 14293 return 0; 14294 } 14295 14296 #define SGL_MAX_NO 16 14297 14298 static int 14299 test_authenticated_encryption_SGL(const struct aead_test_data *tdata, 14300 const int oop, uint32_t fragsz, uint32_t fragsz_oop) 14301 { 14302 struct crypto_testsuite_params *ts_params = &testsuite_params; 14303 struct crypto_unittest_params *ut_params = &unittest_params; 14304 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL; 14305 int retval; 14306 int to_trn = 0; 14307 int to_trn_tbl[SGL_MAX_NO]; 14308 int segs = 1; 14309 unsigned int trn_data = 0; 14310 uint8_t *plaintext, *ciphertext, *auth_tag; 14311 struct rte_cryptodev_info dev_info; 14312 14313 /* Verify the capabilities */ 14314 struct rte_cryptodev_sym_capability_idx cap_idx; 14315 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 14316 cap_idx.algo.aead = tdata->algo; 14317 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14318 &cap_idx) == NULL) 14319 return TEST_SKIPPED; 14320 14321 /* OOP not supported with CPU crypto */ 14322 if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14323 return TEST_SKIPPED; 14324 14325 /* Detailed check for the particular SGL support flag */ 14326 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14327 if (!oop) { 14328 unsigned int sgl_in = fragsz < tdata->plaintext.len; 14329 if (sgl_in && (!(dev_info.feature_flags & 14330 RTE_CRYPTODEV_FF_IN_PLACE_SGL))) 14331 return TEST_SKIPPED; 14332 14333 uint64_t feat_flags = dev_info.feature_flags; 14334 14335 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14336 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14337 printf("Device doesn't support RAW data-path APIs.\n"); 14338 return TEST_SKIPPED; 14339 } 14340 } else { 14341 unsigned int sgl_in = fragsz < tdata->plaintext.len; 14342 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) < 14343 tdata->plaintext.len; 14344 /* Raw data path API does not support OOP */ 14345 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14346 return TEST_SKIPPED; 14347 if (sgl_in && !sgl_out) { 14348 if (!(dev_info.feature_flags & 14349 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) 14350 return TEST_SKIPPED; 14351 } else if (!sgl_in && sgl_out) { 14352 if (!(dev_info.feature_flags & 14353 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 14354 return TEST_SKIPPED; 14355 } else if (sgl_in && sgl_out) { 14356 if (!(dev_info.feature_flags & 14357 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 14358 return TEST_SKIPPED; 14359 } 14360 } 14361 14362 if (fragsz > tdata->plaintext.len) 14363 fragsz = tdata->plaintext.len; 14364 14365 uint16_t plaintext_len = fragsz; 14366 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 14367 14368 if (fragsz_oop > tdata->plaintext.len) 14369 frag_size_oop = tdata->plaintext.len; 14370 14371 int ecx = 0; 14372 void *digest_mem = NULL; 14373 14374 uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 14375 14376 if (tdata->plaintext.len % fragsz != 0) { 14377 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO) 14378 return 1; 14379 } else { 14380 if (tdata->plaintext.len / fragsz > SGL_MAX_NO) 14381 return 1; 14382 } 14383 14384 /* 14385 * For out-op-place we need to alloc another mbuf 14386 */ 14387 if (oop) { 14388 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14389 rte_pktmbuf_append(ut_params->obuf, 14390 frag_size_oop + prepend_len); 14391 buf_oop = ut_params->obuf; 14392 } 14393 14394 /* Create AEAD session */ 14395 retval = create_aead_session(ts_params->valid_devs[0], 14396 tdata->algo, 14397 RTE_CRYPTO_AEAD_OP_ENCRYPT, 14398 tdata->key.data, tdata->key.len, 14399 tdata->aad.len, tdata->auth_tag.len, 14400 tdata->iv.len); 14401 if (retval < 0) 14402 return retval; 14403 14404 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14405 14406 /* clear mbuf payload */ 14407 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14408 rte_pktmbuf_tailroom(ut_params->ibuf)); 14409 14410 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14411 plaintext_len); 14412 14413 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 14414 14415 trn_data += plaintext_len; 14416 14417 buf = ut_params->ibuf; 14418 14419 /* 14420 * Loop until no more fragments 14421 */ 14422 14423 while (trn_data < tdata->plaintext.len) { 14424 ++segs; 14425 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 14426 (tdata->plaintext.len - trn_data) : fragsz; 14427 14428 to_trn_tbl[ecx++] = to_trn; 14429 14430 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14431 buf = buf->next; 14432 14433 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 14434 rte_pktmbuf_tailroom(buf)); 14435 14436 /* OOP */ 14437 if (oop && !fragsz_oop) { 14438 buf_last_oop = buf_oop->next = 14439 rte_pktmbuf_alloc(ts_params->mbuf_pool); 14440 buf_oop = buf_oop->next; 14441 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 14442 0, rte_pktmbuf_tailroom(buf_oop)); 14443 rte_pktmbuf_append(buf_oop, to_trn); 14444 } 14445 14446 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 14447 to_trn); 14448 14449 memcpy(plaintext, tdata->plaintext.data + trn_data, 14450 to_trn); 14451 trn_data += to_trn; 14452 if (trn_data == tdata->plaintext.len) { 14453 if (oop) { 14454 if (!fragsz_oop) 14455 digest_mem = rte_pktmbuf_append(buf_oop, 14456 tdata->auth_tag.len); 14457 } else 14458 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 14459 tdata->auth_tag.len); 14460 } 14461 } 14462 14463 uint64_t digest_phys = 0; 14464 14465 ut_params->ibuf->nb_segs = segs; 14466 14467 segs = 1; 14468 if (fragsz_oop && oop) { 14469 to_trn = 0; 14470 ecx = 0; 14471 14472 if (frag_size_oop == tdata->plaintext.len) { 14473 digest_mem = rte_pktmbuf_append(ut_params->obuf, 14474 tdata->auth_tag.len); 14475 14476 digest_phys = rte_pktmbuf_iova_offset( 14477 ut_params->obuf, 14478 tdata->plaintext.len + prepend_len); 14479 } 14480 14481 trn_data = frag_size_oop; 14482 while (trn_data < tdata->plaintext.len) { 14483 ++segs; 14484 to_trn = 14485 (tdata->plaintext.len - trn_data < 14486 frag_size_oop) ? 14487 (tdata->plaintext.len - trn_data) : 14488 frag_size_oop; 14489 14490 to_trn_tbl[ecx++] = to_trn; 14491 14492 buf_last_oop = buf_oop->next = 14493 rte_pktmbuf_alloc(ts_params->mbuf_pool); 14494 buf_oop = buf_oop->next; 14495 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 14496 0, rte_pktmbuf_tailroom(buf_oop)); 14497 rte_pktmbuf_append(buf_oop, to_trn); 14498 14499 trn_data += to_trn; 14500 14501 if (trn_data == tdata->plaintext.len) { 14502 digest_mem = rte_pktmbuf_append(buf_oop, 14503 tdata->auth_tag.len); 14504 } 14505 } 14506 14507 ut_params->obuf->nb_segs = segs; 14508 } 14509 14510 /* 14511 * Place digest at the end of the last buffer 14512 */ 14513 if (!digest_phys) 14514 digest_phys = rte_pktmbuf_iova(buf) + to_trn; 14515 if (oop && buf_last_oop) 14516 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn; 14517 14518 if (!digest_mem && !oop) { 14519 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14520 + tdata->auth_tag.len); 14521 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 14522 tdata->plaintext.len); 14523 } 14524 14525 /* Create AEAD operation */ 14526 retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT, 14527 tdata, digest_mem, digest_phys); 14528 14529 if (retval < 0) 14530 return retval; 14531 14532 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14533 14534 ut_params->op->sym->m_src = ut_params->ibuf; 14535 if (oop) 14536 ut_params->op->sym->m_dst = ut_params->obuf; 14537 14538 /* Process crypto operation */ 14539 if (oop == IN_PLACE && 14540 gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14541 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 14542 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14543 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 14544 ut_params->op, 0, 0, 0, 0); 14545 else 14546 TEST_ASSERT_NOT_NULL( 14547 process_crypto_request(ts_params->valid_devs[0], 14548 ut_params->op), "failed to process sym crypto op"); 14549 14550 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14551 "crypto op processing failed"); 14552 14553 14554 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 14555 uint8_t *, prepend_len); 14556 if (oop) { 14557 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 14558 uint8_t *, prepend_len); 14559 } 14560 14561 if (fragsz_oop) 14562 fragsz = fragsz_oop; 14563 14564 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14565 ciphertext, 14566 tdata->ciphertext.data, 14567 fragsz, 14568 "Ciphertext data not as expected"); 14569 14570 buf = ut_params->op->sym->m_src->next; 14571 if (oop) 14572 buf = ut_params->op->sym->m_dst->next; 14573 14574 unsigned int off = fragsz; 14575 14576 ecx = 0; 14577 while (buf) { 14578 ciphertext = rte_pktmbuf_mtod(buf, 14579 uint8_t *); 14580 14581 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14582 ciphertext, 14583 tdata->ciphertext.data + off, 14584 to_trn_tbl[ecx], 14585 "Ciphertext data not as expected"); 14586 14587 off += to_trn_tbl[ecx++]; 14588 buf = buf->next; 14589 } 14590 14591 auth_tag = digest_mem; 14592 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14593 auth_tag, 14594 tdata->auth_tag.data, 14595 tdata->auth_tag.len, 14596 "Generated auth tag not as expected"); 14597 14598 return 0; 14599 } 14600 14601 static int 14602 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) 14603 { 14604 return test_authenticated_encryption_SGL( 14605 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400); 14606 } 14607 14608 static int 14609 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void) 14610 { 14611 return test_authenticated_encryption_SGL( 14612 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000); 14613 } 14614 14615 static int 14616 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void) 14617 { 14618 return test_authenticated_encryption_SGL( 14619 &gcm_test_case_8, OUT_OF_PLACE, 400, 14620 gcm_test_case_8.plaintext.len); 14621 } 14622 14623 static int 14624 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void) 14625 { 14626 /* This test is not for OPENSSL PMD */ 14627 if (gbl_driver_id == rte_cryptodev_driver_id_get( 14628 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) 14629 return TEST_SKIPPED; 14630 14631 return test_authenticated_encryption_SGL( 14632 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0); 14633 } 14634 14635 static int 14636 test_authentication_verify_fail_when_data_corrupted( 14637 struct crypto_testsuite_params *ts_params, 14638 struct crypto_unittest_params *ut_params, 14639 const struct test_crypto_vector *reference) 14640 { 14641 return test_authentication_verify_fail_when_data_corruption( 14642 ts_params, ut_params, reference, 1); 14643 } 14644 14645 static int 14646 test_authentication_verify_fail_when_tag_corrupted( 14647 struct crypto_testsuite_params *ts_params, 14648 struct crypto_unittest_params *ut_params, 14649 const struct test_crypto_vector *reference) 14650 { 14651 return test_authentication_verify_fail_when_data_corruption( 14652 ts_params, ut_params, reference, 0); 14653 } 14654 14655 static int 14656 test_authentication_verify_GMAC_fail_when_data_corrupted( 14657 struct crypto_testsuite_params *ts_params, 14658 struct crypto_unittest_params *ut_params, 14659 const struct test_crypto_vector *reference) 14660 { 14661 return test_authentication_verify_GMAC_fail_when_corruption( 14662 ts_params, ut_params, reference, 1); 14663 } 14664 14665 static int 14666 test_authentication_verify_GMAC_fail_when_tag_corrupted( 14667 struct crypto_testsuite_params *ts_params, 14668 struct crypto_unittest_params *ut_params, 14669 const struct test_crypto_vector *reference) 14670 { 14671 return test_authentication_verify_GMAC_fail_when_corruption( 14672 ts_params, ut_params, reference, 0); 14673 } 14674 14675 static int 14676 test_authenticated_decryption_fail_when_data_corrupted( 14677 struct crypto_testsuite_params *ts_params, 14678 struct crypto_unittest_params *ut_params, 14679 const struct test_crypto_vector *reference) 14680 { 14681 return test_authenticated_decryption_fail_when_corruption( 14682 ts_params, ut_params, reference, 1); 14683 } 14684 14685 static int 14686 test_authenticated_decryption_fail_when_tag_corrupted( 14687 struct crypto_testsuite_params *ts_params, 14688 struct crypto_unittest_params *ut_params, 14689 const struct test_crypto_vector *reference) 14690 { 14691 return test_authenticated_decryption_fail_when_corruption( 14692 ts_params, ut_params, reference, 0); 14693 } 14694 14695 static int 14696 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 14697 { 14698 return test_authentication_verify_fail_when_data_corrupted( 14699 &testsuite_params, &unittest_params, 14700 &hmac_sha1_test_crypto_vector); 14701 } 14702 14703 static int 14704 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 14705 { 14706 return test_authentication_verify_fail_when_tag_corrupted( 14707 &testsuite_params, &unittest_params, 14708 &hmac_sha1_test_crypto_vector); 14709 } 14710 14711 static int 14712 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 14713 { 14714 return test_authentication_verify_GMAC_fail_when_data_corrupted( 14715 &testsuite_params, &unittest_params, 14716 &aes128_gmac_test_vector); 14717 } 14718 14719 static int 14720 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 14721 { 14722 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 14723 &testsuite_params, &unittest_params, 14724 &aes128_gmac_test_vector); 14725 } 14726 14727 static int 14728 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 14729 { 14730 return test_authenticated_decryption_fail_when_data_corrupted( 14731 &testsuite_params, 14732 &unittest_params, 14733 &aes128cbc_hmac_sha1_test_vector); 14734 } 14735 14736 static int 14737 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 14738 { 14739 return test_authenticated_decryption_fail_when_tag_corrupted( 14740 &testsuite_params, 14741 &unittest_params, 14742 &aes128cbc_hmac_sha1_test_vector); 14743 } 14744 14745 static int 14746 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void) 14747 { 14748 return test_authenticated_encrypt_with_esn( 14749 &testsuite_params, 14750 &unittest_params, 14751 &aes128cbc_hmac_sha1_aad_test_vector); 14752 } 14753 14754 static int 14755 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void) 14756 { 14757 return test_authenticated_decrypt_with_esn( 14758 &testsuite_params, 14759 &unittest_params, 14760 &aes128cbc_hmac_sha1_aad_test_vector); 14761 } 14762 14763 static int 14764 test_chacha20_poly1305_encrypt_test_case_rfc8439(void) 14765 { 14766 return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439); 14767 } 14768 14769 static int 14770 test_chacha20_poly1305_decrypt_test_case_rfc8439(void) 14771 { 14772 return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439); 14773 } 14774 14775 static int 14776 test_chacha20_poly1305_encrypt_SGL_out_of_place(void) 14777 { 14778 return test_authenticated_encryption_SGL( 14779 &chacha20_poly1305_case_2, OUT_OF_PLACE, 32, 14780 chacha20_poly1305_case_2.plaintext.len); 14781 } 14782 14783 #ifdef RTE_CRYPTO_SCHEDULER 14784 14785 /* global AESNI worker IDs for the scheduler test */ 14786 uint8_t aesni_ids[2]; 14787 14788 static int 14789 scheduler_testsuite_setup(void) 14790 { 14791 uint32_t i = 0; 14792 int32_t nb_devs, ret; 14793 char vdev_args[VDEV_ARGS_SIZE] = {""}; 14794 char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core," 14795 "ordering=enable,name=cryptodev_test_scheduler,corelist="}; 14796 uint16_t worker_core_count = 0; 14797 uint16_t socket_id = 0; 14798 14799 if (gbl_driver_id == rte_cryptodev_driver_id_get( 14800 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) { 14801 14802 /* Identify the Worker Cores 14803 * Use 2 worker cores for the device args 14804 */ 14805 RTE_LCORE_FOREACH_WORKER(i) { 14806 if (worker_core_count > 1) 14807 break; 14808 snprintf(vdev_args, sizeof(vdev_args), 14809 "%s%d", temp_str, i); 14810 strcpy(temp_str, vdev_args); 14811 strlcat(temp_str, ";", sizeof(temp_str)); 14812 worker_core_count++; 14813 socket_id = rte_lcore_to_socket_id(i); 14814 } 14815 if (worker_core_count != 2) { 14816 RTE_LOG(ERR, USER1, 14817 "Cryptodev scheduler test require at least " 14818 "two worker cores to run. " 14819 "Please use the correct coremask.\n"); 14820 return TEST_FAILED; 14821 } 14822 strcpy(temp_str, vdev_args); 14823 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", 14824 temp_str, socket_id); 14825 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args); 14826 nb_devs = rte_cryptodev_device_count_by_driver( 14827 rte_cryptodev_driver_id_get( 14828 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))); 14829 if (nb_devs < 1) { 14830 ret = rte_vdev_init( 14831 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD), 14832 vdev_args); 14833 TEST_ASSERT(ret == 0, 14834 "Failed to create instance %u of pmd : %s", 14835 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 14836 } 14837 } 14838 return testsuite_setup(); 14839 } 14840 14841 static int 14842 test_scheduler_attach_worker_op(void) 14843 { 14844 struct crypto_testsuite_params *ts_params = &testsuite_params; 14845 uint8_t sched_id = ts_params->valid_devs[0]; 14846 uint32_t i, nb_devs_attached = 0; 14847 int ret; 14848 char vdev_name[32]; 14849 unsigned int count = rte_cryptodev_count(); 14850 14851 /* create 2 AESNI_MB vdevs on top of existing devices */ 14852 for (i = count; i < count + 2; i++) { 14853 snprintf(vdev_name, sizeof(vdev_name), "%s_%u", 14854 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), 14855 i); 14856 ret = rte_vdev_init(vdev_name, NULL); 14857 14858 TEST_ASSERT(ret == 0, 14859 "Failed to create instance %u of" 14860 " pmd : %s", 14861 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 14862 14863 if (ret < 0) { 14864 RTE_LOG(ERR, USER1, 14865 "Failed to create 2 AESNI MB PMDs.\n"); 14866 return TEST_SKIPPED; 14867 } 14868 } 14869 14870 /* attach 2 AESNI_MB cdevs */ 14871 for (i = count; i < count + 2; i++) { 14872 struct rte_cryptodev_info info; 14873 unsigned int session_size; 14874 14875 rte_cryptodev_info_get(i, &info); 14876 if (info.driver_id != rte_cryptodev_driver_id_get( 14877 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) 14878 continue; 14879 14880 session_size = rte_cryptodev_sym_get_private_session_size(i); 14881 /* 14882 * Create the session mempool again, since now there are new devices 14883 * to use the mempool. 14884 */ 14885 if (ts_params->session_mpool) { 14886 rte_mempool_free(ts_params->session_mpool); 14887 ts_params->session_mpool = NULL; 14888 } 14889 if (ts_params->session_priv_mpool) { 14890 rte_mempool_free(ts_params->session_priv_mpool); 14891 ts_params->session_priv_mpool = NULL; 14892 } 14893 14894 if (info.sym.max_nb_sessions != 0 && 14895 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 14896 RTE_LOG(ERR, USER1, 14897 "Device does not support " 14898 "at least %u sessions\n", 14899 MAX_NB_SESSIONS); 14900 return TEST_FAILED; 14901 } 14902 /* 14903 * Create mempool with maximum number of sessions, 14904 * to include the session headers 14905 */ 14906 if (ts_params->session_mpool == NULL) { 14907 ts_params->session_mpool = 14908 rte_cryptodev_sym_session_pool_create( 14909 "test_sess_mp", 14910 MAX_NB_SESSIONS, 0, 0, 0, 14911 SOCKET_ID_ANY); 14912 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 14913 "session mempool allocation failed"); 14914 } 14915 14916 /* 14917 * Create mempool with maximum number of sessions, 14918 * to include device specific session private data 14919 */ 14920 if (ts_params->session_priv_mpool == NULL) { 14921 ts_params->session_priv_mpool = rte_mempool_create( 14922 "test_sess_mp_priv", 14923 MAX_NB_SESSIONS, 14924 session_size, 14925 0, 0, NULL, NULL, NULL, 14926 NULL, SOCKET_ID_ANY, 14927 0); 14928 14929 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 14930 "session mempool allocation failed"); 14931 } 14932 14933 ts_params->qp_conf.mp_session = ts_params->session_mpool; 14934 ts_params->qp_conf.mp_session_private = 14935 ts_params->session_priv_mpool; 14936 14937 ret = rte_cryptodev_scheduler_worker_attach(sched_id, 14938 (uint8_t)i); 14939 14940 TEST_ASSERT(ret == 0, 14941 "Failed to attach device %u of pmd : %s", i, 14942 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 14943 14944 aesni_ids[nb_devs_attached] = (uint8_t)i; 14945 14946 nb_devs_attached++; 14947 } 14948 14949 return 0; 14950 } 14951 14952 static int 14953 test_scheduler_detach_worker_op(void) 14954 { 14955 struct crypto_testsuite_params *ts_params = &testsuite_params; 14956 uint8_t sched_id = ts_params->valid_devs[0]; 14957 uint32_t i; 14958 int ret; 14959 14960 for (i = 0; i < 2; i++) { 14961 ret = rte_cryptodev_scheduler_worker_detach(sched_id, 14962 aesni_ids[i]); 14963 TEST_ASSERT(ret == 0, 14964 "Failed to detach device %u", aesni_ids[i]); 14965 } 14966 14967 return 0; 14968 } 14969 14970 static int 14971 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode) 14972 { 14973 struct crypto_testsuite_params *ts_params = &testsuite_params; 14974 uint8_t sched_id = ts_params->valid_devs[0]; 14975 /* set mode */ 14976 return rte_cryptodev_scheduler_mode_set(sched_id, 14977 scheduler_mode); 14978 } 14979 14980 static int 14981 test_scheduler_mode_roundrobin_op(void) 14982 { 14983 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) == 14984 0, "Failed to set roundrobin mode"); 14985 return 0; 14986 14987 } 14988 14989 static int 14990 test_scheduler_mode_multicore_op(void) 14991 { 14992 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) == 14993 0, "Failed to set multicore mode"); 14994 14995 return 0; 14996 } 14997 14998 static int 14999 test_scheduler_mode_failover_op(void) 15000 { 15001 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) == 15002 0, "Failed to set failover mode"); 15003 15004 return 0; 15005 } 15006 15007 static int 15008 test_scheduler_mode_pkt_size_distr_op(void) 15009 { 15010 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) == 15011 0, "Failed to set pktsize mode"); 15012 15013 return 0; 15014 } 15015 15016 static int 15017 scheduler_multicore_testsuite_setup(void) 15018 { 15019 if (test_scheduler_attach_worker_op() < 0) 15020 return TEST_SKIPPED; 15021 if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0) 15022 return TEST_SKIPPED; 15023 return 0; 15024 } 15025 15026 static int 15027 scheduler_roundrobin_testsuite_setup(void) 15028 { 15029 if (test_scheduler_attach_worker_op() < 0) 15030 return TEST_SKIPPED; 15031 if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0) 15032 return TEST_SKIPPED; 15033 return 0; 15034 } 15035 15036 static int 15037 scheduler_failover_testsuite_setup(void) 15038 { 15039 if (test_scheduler_attach_worker_op() < 0) 15040 return TEST_SKIPPED; 15041 if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0) 15042 return TEST_SKIPPED; 15043 return 0; 15044 } 15045 15046 static int 15047 scheduler_pkt_size_distr_testsuite_setup(void) 15048 { 15049 if (test_scheduler_attach_worker_op() < 0) 15050 return TEST_SKIPPED; 15051 if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0) 15052 return TEST_SKIPPED; 15053 return 0; 15054 } 15055 15056 static void 15057 scheduler_mode_testsuite_teardown(void) 15058 { 15059 test_scheduler_detach_worker_op(); 15060 } 15061 15062 #endif /* RTE_CRYPTO_SCHEDULER */ 15063 15064 static struct unit_test_suite end_testsuite = { 15065 .suite_name = NULL, 15066 .setup = NULL, 15067 .teardown = NULL, 15068 .unit_test_suites = NULL 15069 }; 15070 15071 #ifdef RTE_LIB_SECURITY 15072 static struct unit_test_suite ipsec_proto_testsuite = { 15073 .suite_name = "IPsec Proto Unit Test Suite", 15074 .setup = ipsec_proto_testsuite_setup, 15075 .unit_test_cases = { 15076 TEST_CASE_NAMED_WITH_DATA( 15077 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 15078 ut_setup_security, ut_teardown, 15079 test_ipsec_proto_known_vec, &pkt_aes_128_gcm), 15080 TEST_CASE_NAMED_WITH_DATA( 15081 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 15082 ut_setup_security, ut_teardown, 15083 test_ipsec_proto_known_vec, &pkt_aes_192_gcm), 15084 TEST_CASE_NAMED_WITH_DATA( 15085 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 15086 ut_setup_security, ut_teardown, 15087 test_ipsec_proto_known_vec, &pkt_aes_256_gcm), 15088 TEST_CASE_NAMED_WITH_DATA( 15089 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])", 15090 ut_setup_security, ut_teardown, 15091 test_ipsec_proto_known_vec, 15092 &pkt_aes_128_cbc_hmac_sha256), 15093 TEST_CASE_NAMED_WITH_DATA( 15094 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])", 15095 ut_setup_security, ut_teardown, 15096 test_ipsec_proto_known_vec, 15097 &pkt_aes_128_cbc_hmac_sha384), 15098 TEST_CASE_NAMED_WITH_DATA( 15099 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])", 15100 ut_setup_security, ut_teardown, 15101 test_ipsec_proto_known_vec, 15102 &pkt_aes_128_cbc_hmac_sha512), 15103 TEST_CASE_NAMED_WITH_DATA( 15104 "Outbound known vector (ESP tunnel mode IPv6 AES-GCM 128)", 15105 ut_setup_security, ut_teardown, 15106 test_ipsec_proto_known_vec, &pkt_aes_256_gcm_v6), 15107 TEST_CASE_NAMED_WITH_DATA( 15108 "Outbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])", 15109 ut_setup_security, ut_teardown, 15110 test_ipsec_proto_known_vec, 15111 &pkt_aes_128_cbc_hmac_sha256_v6), 15112 TEST_CASE_NAMED_WITH_DATA( 15113 "Outbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])", 15114 ut_setup_security, ut_teardown, 15115 test_ipsec_proto_known_vec, 15116 &pkt_null_aes_xcbc), 15117 TEST_CASE_NAMED_WITH_DATA( 15118 "Outbound known vector (AH tunnel mode IPv4 HMAC-SHA256)", 15119 ut_setup_security, ut_teardown, 15120 test_ipsec_proto_known_vec, 15121 &pkt_ah_tunnel_sha256), 15122 TEST_CASE_NAMED_WITH_DATA( 15123 "Outbound known vector (AH transport mode IPv4 HMAC-SHA256)", 15124 ut_setup_security, ut_teardown, 15125 test_ipsec_proto_known_vec, 15126 &pkt_ah_transport_sha256), 15127 TEST_CASE_NAMED_WITH_DATA( 15128 "Outbound known vector (AH transport mode IPv4 AES-GMAC 128)", 15129 ut_setup_security, ut_teardown, 15130 test_ipsec_proto_known_vec, 15131 &pkt_ah_ipv4_aes_gmac_128), 15132 TEST_CASE_NAMED_WITH_DATA( 15133 "Outbound fragmented packet", 15134 ut_setup_security, ut_teardown, 15135 test_ipsec_proto_known_vec_fragmented, 15136 &pkt_aes_128_gcm_frag), 15137 TEST_CASE_NAMED_WITH_DATA( 15138 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 15139 ut_setup_security, ut_teardown, 15140 test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm), 15141 TEST_CASE_NAMED_WITH_DATA( 15142 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 15143 ut_setup_security, ut_teardown, 15144 test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm), 15145 TEST_CASE_NAMED_WITH_DATA( 15146 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 15147 ut_setup_security, ut_teardown, 15148 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm), 15149 TEST_CASE_NAMED_WITH_DATA( 15150 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)", 15151 ut_setup_security, ut_teardown, 15152 test_ipsec_proto_known_vec_inb, &pkt_aes_128_cbc_null), 15153 TEST_CASE_NAMED_WITH_DATA( 15154 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])", 15155 ut_setup_security, ut_teardown, 15156 test_ipsec_proto_known_vec_inb, 15157 &pkt_aes_128_cbc_hmac_sha256), 15158 TEST_CASE_NAMED_WITH_DATA( 15159 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])", 15160 ut_setup_security, ut_teardown, 15161 test_ipsec_proto_known_vec_inb, 15162 &pkt_aes_128_cbc_hmac_sha384), 15163 TEST_CASE_NAMED_WITH_DATA( 15164 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])", 15165 ut_setup_security, ut_teardown, 15166 test_ipsec_proto_known_vec_inb, 15167 &pkt_aes_128_cbc_hmac_sha512), 15168 TEST_CASE_NAMED_WITH_DATA( 15169 "Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)", 15170 ut_setup_security, ut_teardown, 15171 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm_v6), 15172 TEST_CASE_NAMED_WITH_DATA( 15173 "Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])", 15174 ut_setup_security, ut_teardown, 15175 test_ipsec_proto_known_vec_inb, 15176 &pkt_aes_128_cbc_hmac_sha256_v6), 15177 TEST_CASE_NAMED_WITH_DATA( 15178 "Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])", 15179 ut_setup_security, ut_teardown, 15180 test_ipsec_proto_known_vec_inb, 15181 &pkt_null_aes_xcbc), 15182 TEST_CASE_NAMED_WITH_DATA( 15183 "Inbound known vector (AH tunnel mode IPv4 HMAC-SHA256)", 15184 ut_setup_security, ut_teardown, 15185 test_ipsec_proto_known_vec_inb, 15186 &pkt_ah_tunnel_sha256), 15187 TEST_CASE_NAMED_WITH_DATA( 15188 "Inbound known vector (AH transport mode IPv4 HMAC-SHA256)", 15189 ut_setup_security, ut_teardown, 15190 test_ipsec_proto_known_vec_inb, 15191 &pkt_ah_transport_sha256), 15192 TEST_CASE_NAMED_WITH_DATA( 15193 "Inbound known vector (AH transport mode IPv4 AES-GMAC 128)", 15194 ut_setup_security, ut_teardown, 15195 test_ipsec_proto_known_vec_inb, 15196 &pkt_ah_ipv4_aes_gmac_128), 15197 TEST_CASE_NAMED_ST( 15198 "Combined test alg list", 15199 ut_setup_security, ut_teardown, 15200 test_ipsec_proto_display_list), 15201 TEST_CASE_NAMED_ST( 15202 "Combined test alg list (AH)", 15203 ut_setup_security, ut_teardown, 15204 test_ipsec_proto_ah_tunnel_ipv4), 15205 TEST_CASE_NAMED_ST( 15206 "IV generation", 15207 ut_setup_security, ut_teardown, 15208 test_ipsec_proto_iv_gen), 15209 TEST_CASE_NAMED_ST( 15210 "UDP encapsulation", 15211 ut_setup_security, ut_teardown, 15212 test_ipsec_proto_udp_encap), 15213 TEST_CASE_NAMED_ST( 15214 "UDP encapsulation ports verification test", 15215 ut_setup_security, ut_teardown, 15216 test_ipsec_proto_udp_ports_verify), 15217 TEST_CASE_NAMED_ST( 15218 "SA expiry packets soft", 15219 ut_setup_security, ut_teardown, 15220 test_ipsec_proto_sa_exp_pkts_soft), 15221 TEST_CASE_NAMED_ST( 15222 "SA expiry packets hard", 15223 ut_setup_security, ut_teardown, 15224 test_ipsec_proto_sa_exp_pkts_hard), 15225 TEST_CASE_NAMED_ST( 15226 "Negative test: ICV corruption", 15227 ut_setup_security, ut_teardown, 15228 test_ipsec_proto_err_icv_corrupt), 15229 TEST_CASE_NAMED_ST( 15230 "Tunnel dst addr verification", 15231 ut_setup_security, ut_teardown, 15232 test_ipsec_proto_tunnel_dst_addr_verify), 15233 TEST_CASE_NAMED_ST( 15234 "Tunnel src and dst addr verification", 15235 ut_setup_security, ut_teardown, 15236 test_ipsec_proto_tunnel_src_dst_addr_verify), 15237 TEST_CASE_NAMED_ST( 15238 "Inner IP checksum", 15239 ut_setup_security, ut_teardown, 15240 test_ipsec_proto_inner_ip_csum), 15241 TEST_CASE_NAMED_ST( 15242 "Inner L4 checksum", 15243 ut_setup_security, ut_teardown, 15244 test_ipsec_proto_inner_l4_csum), 15245 TEST_CASE_NAMED_ST( 15246 "Tunnel IPv4 in IPv4", 15247 ut_setup_security, ut_teardown, 15248 test_ipsec_proto_tunnel_v4_in_v4), 15249 TEST_CASE_NAMED_ST( 15250 "Tunnel IPv6 in IPv6", 15251 ut_setup_security, ut_teardown, 15252 test_ipsec_proto_tunnel_v6_in_v6), 15253 TEST_CASE_NAMED_ST( 15254 "Tunnel IPv4 in IPv6", 15255 ut_setup_security, ut_teardown, 15256 test_ipsec_proto_tunnel_v4_in_v6), 15257 TEST_CASE_NAMED_ST( 15258 "Tunnel IPv6 in IPv4", 15259 ut_setup_security, ut_teardown, 15260 test_ipsec_proto_tunnel_v6_in_v4), 15261 TEST_CASE_NAMED_ST( 15262 "Transport IPv4", 15263 ut_setup_security, ut_teardown, 15264 test_ipsec_proto_transport_v4), 15265 TEST_CASE_NAMED_ST( 15266 "AH transport IPv4", 15267 ut_setup_security, ut_teardown, 15268 test_ipsec_proto_ah_transport_ipv4), 15269 TEST_CASE_NAMED_ST( 15270 "Transport l4 checksum", 15271 ut_setup_security, ut_teardown, 15272 test_ipsec_proto_transport_l4_csum), 15273 TEST_CASE_NAMED_ST( 15274 "Statistics: success", 15275 ut_setup_security, ut_teardown, 15276 test_ipsec_proto_stats), 15277 TEST_CASE_NAMED_ST( 15278 "Fragmented packet", 15279 ut_setup_security, ut_teardown, 15280 test_ipsec_proto_pkt_fragment), 15281 TEST_CASE_NAMED_ST( 15282 "Tunnel header copy DF (inner 0)", 15283 ut_setup_security, ut_teardown, 15284 test_ipsec_proto_copy_df_inner_0), 15285 TEST_CASE_NAMED_ST( 15286 "Tunnel header copy DF (inner 1)", 15287 ut_setup_security, ut_teardown, 15288 test_ipsec_proto_copy_df_inner_1), 15289 TEST_CASE_NAMED_ST( 15290 "Tunnel header set DF 0 (inner 1)", 15291 ut_setup_security, ut_teardown, 15292 test_ipsec_proto_set_df_0_inner_1), 15293 TEST_CASE_NAMED_ST( 15294 "Tunnel header set DF 1 (inner 0)", 15295 ut_setup_security, ut_teardown, 15296 test_ipsec_proto_set_df_1_inner_0), 15297 TEST_CASE_NAMED_ST( 15298 "Tunnel header IPv4 copy DSCP (inner 0)", 15299 ut_setup_security, ut_teardown, 15300 test_ipsec_proto_ipv4_copy_dscp_inner_0), 15301 TEST_CASE_NAMED_ST( 15302 "Tunnel header IPv4 copy DSCP (inner 1)", 15303 ut_setup_security, ut_teardown, 15304 test_ipsec_proto_ipv4_copy_dscp_inner_1), 15305 TEST_CASE_NAMED_ST( 15306 "Tunnel header IPv4 set DSCP 0 (inner 1)", 15307 ut_setup_security, ut_teardown, 15308 test_ipsec_proto_ipv4_set_dscp_0_inner_1), 15309 TEST_CASE_NAMED_ST( 15310 "Tunnel header IPv4 set DSCP 1 (inner 0)", 15311 ut_setup_security, ut_teardown, 15312 test_ipsec_proto_ipv4_set_dscp_1_inner_0), 15313 TEST_CASE_NAMED_ST( 15314 "Tunnel header IPv6 copy DSCP (inner 0)", 15315 ut_setup_security, ut_teardown, 15316 test_ipsec_proto_ipv6_copy_dscp_inner_0), 15317 TEST_CASE_NAMED_ST( 15318 "Tunnel header IPv6 copy DSCP (inner 1)", 15319 ut_setup_security, ut_teardown, 15320 test_ipsec_proto_ipv6_copy_dscp_inner_1), 15321 TEST_CASE_NAMED_ST( 15322 "Tunnel header IPv6 set DSCP 0 (inner 1)", 15323 ut_setup_security, ut_teardown, 15324 test_ipsec_proto_ipv6_set_dscp_0_inner_1), 15325 TEST_CASE_NAMED_ST( 15326 "Tunnel header IPv6 set DSCP 1 (inner 0)", 15327 ut_setup_security, ut_teardown, 15328 test_ipsec_proto_ipv6_set_dscp_1_inner_0), 15329 TEST_CASE_NAMED_WITH_DATA( 15330 "Antireplay with window size 1024", 15331 ut_setup_security, ut_teardown, 15332 test_ipsec_proto_pkt_antireplay1024, &pkt_aes_128_gcm), 15333 TEST_CASE_NAMED_WITH_DATA( 15334 "Antireplay with window size 2048", 15335 ut_setup_security, ut_teardown, 15336 test_ipsec_proto_pkt_antireplay2048, &pkt_aes_128_gcm), 15337 TEST_CASE_NAMED_WITH_DATA( 15338 "Antireplay with window size 4096", 15339 ut_setup_security, ut_teardown, 15340 test_ipsec_proto_pkt_antireplay4096, &pkt_aes_128_gcm), 15341 TEST_CASE_NAMED_WITH_DATA( 15342 "ESN and Antireplay with window size 1024", 15343 ut_setup_security, ut_teardown, 15344 test_ipsec_proto_pkt_esn_antireplay1024, 15345 &pkt_aes_128_gcm), 15346 TEST_CASE_NAMED_WITH_DATA( 15347 "ESN and Antireplay with window size 2048", 15348 ut_setup_security, ut_teardown, 15349 test_ipsec_proto_pkt_esn_antireplay2048, 15350 &pkt_aes_128_gcm), 15351 TEST_CASE_NAMED_WITH_DATA( 15352 "ESN and Antireplay with window size 4096", 15353 ut_setup_security, ut_teardown, 15354 test_ipsec_proto_pkt_esn_antireplay4096, 15355 &pkt_aes_128_gcm), 15356 TEST_CASE_NAMED_ST( 15357 "Tunnel header IPv4 decrement inner TTL", 15358 ut_setup_security, ut_teardown, 15359 test_ipsec_proto_ipv4_ttl_decrement), 15360 TEST_CASE_NAMED_ST( 15361 "Tunnel header IPv6 decrement inner hop limit", 15362 ut_setup_security, ut_teardown, 15363 test_ipsec_proto_ipv6_hop_limit_decrement), 15364 TEST_CASES_END() /**< NULL terminate unit test array */ 15365 } 15366 }; 15367 15368 static struct unit_test_suite pdcp_proto_testsuite = { 15369 .suite_name = "PDCP Proto Unit Test Suite", 15370 .setup = pdcp_proto_testsuite_setup, 15371 .unit_test_cases = { 15372 TEST_CASE_ST(ut_setup_security, ut_teardown, 15373 test_PDCP_PROTO_all), 15374 TEST_CASES_END() /**< NULL terminate unit test array */ 15375 } 15376 }; 15377 15378 #define ADD_UPLINK_TESTCASE(data) \ 15379 TEST_CASE_NAMED_WITH_DATA(data.test_descr_uplink, ut_setup_security, \ 15380 ut_teardown, test_docsis_proto_uplink, (const void *) &data), \ 15381 15382 #define ADD_DOWNLINK_TESTCASE(data) \ 15383 TEST_CASE_NAMED_WITH_DATA(data.test_descr_downlink, ut_setup_security, \ 15384 ut_teardown, test_docsis_proto_downlink, (const void *) &data), \ 15385 15386 static struct unit_test_suite docsis_proto_testsuite = { 15387 .suite_name = "DOCSIS Proto Unit Test Suite", 15388 .setup = docsis_proto_testsuite_setup, 15389 .unit_test_cases = { 15390 /* Uplink */ 15391 ADD_UPLINK_TESTCASE(docsis_test_case_1) 15392 ADD_UPLINK_TESTCASE(docsis_test_case_2) 15393 ADD_UPLINK_TESTCASE(docsis_test_case_3) 15394 ADD_UPLINK_TESTCASE(docsis_test_case_4) 15395 ADD_UPLINK_TESTCASE(docsis_test_case_5) 15396 ADD_UPLINK_TESTCASE(docsis_test_case_6) 15397 ADD_UPLINK_TESTCASE(docsis_test_case_7) 15398 ADD_UPLINK_TESTCASE(docsis_test_case_8) 15399 ADD_UPLINK_TESTCASE(docsis_test_case_9) 15400 ADD_UPLINK_TESTCASE(docsis_test_case_10) 15401 ADD_UPLINK_TESTCASE(docsis_test_case_11) 15402 ADD_UPLINK_TESTCASE(docsis_test_case_12) 15403 ADD_UPLINK_TESTCASE(docsis_test_case_13) 15404 ADD_UPLINK_TESTCASE(docsis_test_case_14) 15405 ADD_UPLINK_TESTCASE(docsis_test_case_15) 15406 ADD_UPLINK_TESTCASE(docsis_test_case_16) 15407 ADD_UPLINK_TESTCASE(docsis_test_case_17) 15408 ADD_UPLINK_TESTCASE(docsis_test_case_18) 15409 ADD_UPLINK_TESTCASE(docsis_test_case_19) 15410 ADD_UPLINK_TESTCASE(docsis_test_case_20) 15411 ADD_UPLINK_TESTCASE(docsis_test_case_21) 15412 ADD_UPLINK_TESTCASE(docsis_test_case_22) 15413 ADD_UPLINK_TESTCASE(docsis_test_case_23) 15414 ADD_UPLINK_TESTCASE(docsis_test_case_24) 15415 ADD_UPLINK_TESTCASE(docsis_test_case_25) 15416 ADD_UPLINK_TESTCASE(docsis_test_case_26) 15417 /* Downlink */ 15418 ADD_DOWNLINK_TESTCASE(docsis_test_case_1) 15419 ADD_DOWNLINK_TESTCASE(docsis_test_case_2) 15420 ADD_DOWNLINK_TESTCASE(docsis_test_case_3) 15421 ADD_DOWNLINK_TESTCASE(docsis_test_case_4) 15422 ADD_DOWNLINK_TESTCASE(docsis_test_case_5) 15423 ADD_DOWNLINK_TESTCASE(docsis_test_case_6) 15424 ADD_DOWNLINK_TESTCASE(docsis_test_case_7) 15425 ADD_DOWNLINK_TESTCASE(docsis_test_case_8) 15426 ADD_DOWNLINK_TESTCASE(docsis_test_case_9) 15427 ADD_DOWNLINK_TESTCASE(docsis_test_case_10) 15428 ADD_DOWNLINK_TESTCASE(docsis_test_case_11) 15429 ADD_DOWNLINK_TESTCASE(docsis_test_case_12) 15430 ADD_DOWNLINK_TESTCASE(docsis_test_case_13) 15431 ADD_DOWNLINK_TESTCASE(docsis_test_case_14) 15432 ADD_DOWNLINK_TESTCASE(docsis_test_case_15) 15433 ADD_DOWNLINK_TESTCASE(docsis_test_case_16) 15434 ADD_DOWNLINK_TESTCASE(docsis_test_case_17) 15435 ADD_DOWNLINK_TESTCASE(docsis_test_case_18) 15436 ADD_DOWNLINK_TESTCASE(docsis_test_case_19) 15437 ADD_DOWNLINK_TESTCASE(docsis_test_case_20) 15438 ADD_DOWNLINK_TESTCASE(docsis_test_case_21) 15439 ADD_DOWNLINK_TESTCASE(docsis_test_case_22) 15440 ADD_DOWNLINK_TESTCASE(docsis_test_case_23) 15441 ADD_DOWNLINK_TESTCASE(docsis_test_case_24) 15442 ADD_DOWNLINK_TESTCASE(docsis_test_case_25) 15443 ADD_DOWNLINK_TESTCASE(docsis_test_case_26) 15444 TEST_CASES_END() /**< NULL terminate unit test array */ 15445 } 15446 }; 15447 #endif 15448 15449 static struct unit_test_suite cryptodev_gen_testsuite = { 15450 .suite_name = "Crypto General Unit Test Suite", 15451 .setup = crypto_gen_testsuite_setup, 15452 .unit_test_cases = { 15453 TEST_CASE_ST(ut_setup, ut_teardown, 15454 test_device_configure_invalid_dev_id), 15455 TEST_CASE_ST(ut_setup, ut_teardown, 15456 test_queue_pair_descriptor_setup), 15457 TEST_CASE_ST(ut_setup, ut_teardown, 15458 test_device_configure_invalid_queue_pair_ids), 15459 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 15460 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup), 15461 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup), 15462 TEST_CASES_END() /**< NULL terminate unit test array */ 15463 } 15464 }; 15465 15466 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = { 15467 .suite_name = "Negative HMAC SHA1 Unit Test Suite", 15468 .setup = negative_hmac_sha1_testsuite_setup, 15469 .unit_test_cases = { 15470 /** Negative tests */ 15471 TEST_CASE_ST(ut_setup, ut_teardown, 15472 authentication_verify_HMAC_SHA1_fail_data_corrupt), 15473 TEST_CASE_ST(ut_setup, ut_teardown, 15474 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 15475 TEST_CASE_ST(ut_setup, ut_teardown, 15476 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 15477 TEST_CASE_ST(ut_setup, ut_teardown, 15478 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 15479 15480 TEST_CASES_END() /**< NULL terminate unit test array */ 15481 } 15482 }; 15483 15484 static struct unit_test_suite cryptodev_multi_session_testsuite = { 15485 .suite_name = "Multi Session Unit Test Suite", 15486 .setup = multi_session_testsuite_setup, 15487 .unit_test_cases = { 15488 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 15489 TEST_CASE_ST(ut_setup, ut_teardown, 15490 test_multi_session_random_usage), 15491 15492 TEST_CASES_END() /**< NULL terminate unit test array */ 15493 } 15494 }; 15495 15496 static struct unit_test_suite cryptodev_null_testsuite = { 15497 .suite_name = "NULL Test Suite", 15498 .setup = null_testsuite_setup, 15499 .unit_test_cases = { 15500 TEST_CASE_ST(ut_setup, ut_teardown, 15501 test_null_invalid_operation), 15502 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation), 15503 TEST_CASES_END() 15504 } 15505 }; 15506 15507 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite = { 15508 .suite_name = "AES CCM Authenticated Test Suite", 15509 .setup = aes_ccm_auth_testsuite_setup, 15510 .unit_test_cases = { 15511 /** AES CCM Authenticated Encryption 128 bits key*/ 15512 TEST_CASE_ST(ut_setup, ut_teardown, 15513 test_AES_CCM_authenticated_encryption_test_case_128_1), 15514 TEST_CASE_ST(ut_setup, ut_teardown, 15515 test_AES_CCM_authenticated_encryption_test_case_128_2), 15516 TEST_CASE_ST(ut_setup, ut_teardown, 15517 test_AES_CCM_authenticated_encryption_test_case_128_3), 15518 15519 /** AES CCM Authenticated Decryption 128 bits key*/ 15520 TEST_CASE_ST(ut_setup, ut_teardown, 15521 test_AES_CCM_authenticated_decryption_test_case_128_1), 15522 TEST_CASE_ST(ut_setup, ut_teardown, 15523 test_AES_CCM_authenticated_decryption_test_case_128_2), 15524 TEST_CASE_ST(ut_setup, ut_teardown, 15525 test_AES_CCM_authenticated_decryption_test_case_128_3), 15526 15527 /** AES CCM Authenticated Encryption 192 bits key */ 15528 TEST_CASE_ST(ut_setup, ut_teardown, 15529 test_AES_CCM_authenticated_encryption_test_case_192_1), 15530 TEST_CASE_ST(ut_setup, ut_teardown, 15531 test_AES_CCM_authenticated_encryption_test_case_192_2), 15532 TEST_CASE_ST(ut_setup, ut_teardown, 15533 test_AES_CCM_authenticated_encryption_test_case_192_3), 15534 15535 /** AES CCM Authenticated Decryption 192 bits key*/ 15536 TEST_CASE_ST(ut_setup, ut_teardown, 15537 test_AES_CCM_authenticated_decryption_test_case_192_1), 15538 TEST_CASE_ST(ut_setup, ut_teardown, 15539 test_AES_CCM_authenticated_decryption_test_case_192_2), 15540 TEST_CASE_ST(ut_setup, ut_teardown, 15541 test_AES_CCM_authenticated_decryption_test_case_192_3), 15542 15543 /** AES CCM Authenticated Encryption 256 bits key */ 15544 TEST_CASE_ST(ut_setup, ut_teardown, 15545 test_AES_CCM_authenticated_encryption_test_case_256_1), 15546 TEST_CASE_ST(ut_setup, ut_teardown, 15547 test_AES_CCM_authenticated_encryption_test_case_256_2), 15548 TEST_CASE_ST(ut_setup, ut_teardown, 15549 test_AES_CCM_authenticated_encryption_test_case_256_3), 15550 15551 /** AES CCM Authenticated Decryption 256 bits key*/ 15552 TEST_CASE_ST(ut_setup, ut_teardown, 15553 test_AES_CCM_authenticated_decryption_test_case_256_1), 15554 TEST_CASE_ST(ut_setup, ut_teardown, 15555 test_AES_CCM_authenticated_decryption_test_case_256_2), 15556 TEST_CASE_ST(ut_setup, ut_teardown, 15557 test_AES_CCM_authenticated_decryption_test_case_256_3), 15558 TEST_CASES_END() 15559 } 15560 }; 15561 15562 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite = { 15563 .suite_name = "AES GCM Authenticated Test Suite", 15564 .setup = aes_gcm_auth_testsuite_setup, 15565 .unit_test_cases = { 15566 /** AES GCM Authenticated Encryption */ 15567 TEST_CASE_ST(ut_setup, ut_teardown, 15568 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 15569 TEST_CASE_ST(ut_setup, ut_teardown, 15570 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 15571 TEST_CASE_ST(ut_setup, ut_teardown, 15572 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 15573 TEST_CASE_ST(ut_setup, ut_teardown, 15574 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 15575 TEST_CASE_ST(ut_setup, ut_teardown, 15576 test_AES_GCM_authenticated_encryption_test_case_1), 15577 TEST_CASE_ST(ut_setup, ut_teardown, 15578 test_AES_GCM_authenticated_encryption_test_case_2), 15579 TEST_CASE_ST(ut_setup, ut_teardown, 15580 test_AES_GCM_authenticated_encryption_test_case_3), 15581 TEST_CASE_ST(ut_setup, ut_teardown, 15582 test_AES_GCM_authenticated_encryption_test_case_4), 15583 TEST_CASE_ST(ut_setup, ut_teardown, 15584 test_AES_GCM_authenticated_encryption_test_case_5), 15585 TEST_CASE_ST(ut_setup, ut_teardown, 15586 test_AES_GCM_authenticated_encryption_test_case_6), 15587 TEST_CASE_ST(ut_setup, ut_teardown, 15588 test_AES_GCM_authenticated_encryption_test_case_7), 15589 TEST_CASE_ST(ut_setup, ut_teardown, 15590 test_AES_GCM_authenticated_encryption_test_case_8), 15591 TEST_CASE_ST(ut_setup, ut_teardown, 15592 test_AES_GCM_J0_authenticated_encryption_test_case_1), 15593 15594 /** AES GCM Authenticated Decryption */ 15595 TEST_CASE_ST(ut_setup, ut_teardown, 15596 test_AES_GCM_authenticated_decryption_test_case_1), 15597 TEST_CASE_ST(ut_setup, ut_teardown, 15598 test_AES_GCM_authenticated_decryption_test_case_2), 15599 TEST_CASE_ST(ut_setup, ut_teardown, 15600 test_AES_GCM_authenticated_decryption_test_case_3), 15601 TEST_CASE_ST(ut_setup, ut_teardown, 15602 test_AES_GCM_authenticated_decryption_test_case_4), 15603 TEST_CASE_ST(ut_setup, ut_teardown, 15604 test_AES_GCM_authenticated_decryption_test_case_5), 15605 TEST_CASE_ST(ut_setup, ut_teardown, 15606 test_AES_GCM_authenticated_decryption_test_case_6), 15607 TEST_CASE_ST(ut_setup, ut_teardown, 15608 test_AES_GCM_authenticated_decryption_test_case_7), 15609 TEST_CASE_ST(ut_setup, ut_teardown, 15610 test_AES_GCM_authenticated_decryption_test_case_8), 15611 TEST_CASE_ST(ut_setup, ut_teardown, 15612 test_AES_GCM_J0_authenticated_decryption_test_case_1), 15613 15614 /** AES GCM Authenticated Encryption 192 bits key */ 15615 TEST_CASE_ST(ut_setup, ut_teardown, 15616 test_AES_GCM_auth_encryption_test_case_192_1), 15617 TEST_CASE_ST(ut_setup, ut_teardown, 15618 test_AES_GCM_auth_encryption_test_case_192_2), 15619 TEST_CASE_ST(ut_setup, ut_teardown, 15620 test_AES_GCM_auth_encryption_test_case_192_3), 15621 TEST_CASE_ST(ut_setup, ut_teardown, 15622 test_AES_GCM_auth_encryption_test_case_192_4), 15623 TEST_CASE_ST(ut_setup, ut_teardown, 15624 test_AES_GCM_auth_encryption_test_case_192_5), 15625 TEST_CASE_ST(ut_setup, ut_teardown, 15626 test_AES_GCM_auth_encryption_test_case_192_6), 15627 TEST_CASE_ST(ut_setup, ut_teardown, 15628 test_AES_GCM_auth_encryption_test_case_192_7), 15629 15630 /** AES GCM Authenticated Decryption 192 bits key */ 15631 TEST_CASE_ST(ut_setup, ut_teardown, 15632 test_AES_GCM_auth_decryption_test_case_192_1), 15633 TEST_CASE_ST(ut_setup, ut_teardown, 15634 test_AES_GCM_auth_decryption_test_case_192_2), 15635 TEST_CASE_ST(ut_setup, ut_teardown, 15636 test_AES_GCM_auth_decryption_test_case_192_3), 15637 TEST_CASE_ST(ut_setup, ut_teardown, 15638 test_AES_GCM_auth_decryption_test_case_192_4), 15639 TEST_CASE_ST(ut_setup, ut_teardown, 15640 test_AES_GCM_auth_decryption_test_case_192_5), 15641 TEST_CASE_ST(ut_setup, ut_teardown, 15642 test_AES_GCM_auth_decryption_test_case_192_6), 15643 TEST_CASE_ST(ut_setup, ut_teardown, 15644 test_AES_GCM_auth_decryption_test_case_192_7), 15645 15646 /** AES GCM Authenticated Encryption 256 bits key */ 15647 TEST_CASE_ST(ut_setup, ut_teardown, 15648 test_AES_GCM_auth_encryption_test_case_256_1), 15649 TEST_CASE_ST(ut_setup, ut_teardown, 15650 test_AES_GCM_auth_encryption_test_case_256_2), 15651 TEST_CASE_ST(ut_setup, ut_teardown, 15652 test_AES_GCM_auth_encryption_test_case_256_3), 15653 TEST_CASE_ST(ut_setup, ut_teardown, 15654 test_AES_GCM_auth_encryption_test_case_256_4), 15655 TEST_CASE_ST(ut_setup, ut_teardown, 15656 test_AES_GCM_auth_encryption_test_case_256_5), 15657 TEST_CASE_ST(ut_setup, ut_teardown, 15658 test_AES_GCM_auth_encryption_test_case_256_6), 15659 TEST_CASE_ST(ut_setup, ut_teardown, 15660 test_AES_GCM_auth_encryption_test_case_256_7), 15661 15662 /** AES GCM Authenticated Decryption 256 bits key */ 15663 TEST_CASE_ST(ut_setup, ut_teardown, 15664 test_AES_GCM_auth_decryption_test_case_256_1), 15665 TEST_CASE_ST(ut_setup, ut_teardown, 15666 test_AES_GCM_auth_decryption_test_case_256_2), 15667 TEST_CASE_ST(ut_setup, ut_teardown, 15668 test_AES_GCM_auth_decryption_test_case_256_3), 15669 TEST_CASE_ST(ut_setup, ut_teardown, 15670 test_AES_GCM_auth_decryption_test_case_256_4), 15671 TEST_CASE_ST(ut_setup, ut_teardown, 15672 test_AES_GCM_auth_decryption_test_case_256_5), 15673 TEST_CASE_ST(ut_setup, ut_teardown, 15674 test_AES_GCM_auth_decryption_test_case_256_6), 15675 TEST_CASE_ST(ut_setup, ut_teardown, 15676 test_AES_GCM_auth_decryption_test_case_256_7), 15677 15678 /** AES GCM Authenticated Encryption big aad size */ 15679 TEST_CASE_ST(ut_setup, ut_teardown, 15680 test_AES_GCM_auth_encryption_test_case_aad_1), 15681 TEST_CASE_ST(ut_setup, ut_teardown, 15682 test_AES_GCM_auth_encryption_test_case_aad_2), 15683 15684 /** AES GCM Authenticated Decryption big aad size */ 15685 TEST_CASE_ST(ut_setup, ut_teardown, 15686 test_AES_GCM_auth_decryption_test_case_aad_1), 15687 TEST_CASE_ST(ut_setup, ut_teardown, 15688 test_AES_GCM_auth_decryption_test_case_aad_2), 15689 15690 /** Out of place tests */ 15691 TEST_CASE_ST(ut_setup, ut_teardown, 15692 test_AES_GCM_authenticated_encryption_oop_test_case_1), 15693 TEST_CASE_ST(ut_setup, ut_teardown, 15694 test_AES_GCM_authenticated_decryption_oop_test_case_1), 15695 15696 /** Session-less tests */ 15697 TEST_CASE_ST(ut_setup, ut_teardown, 15698 test_AES_GCM_authenticated_encryption_sessionless_test_case_1), 15699 TEST_CASE_ST(ut_setup, ut_teardown, 15700 test_AES_GCM_authenticated_decryption_sessionless_test_case_1), 15701 15702 TEST_CASES_END() 15703 } 15704 }; 15705 15706 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite = { 15707 .suite_name = "AES GMAC Authentication Test Suite", 15708 .setup = aes_gmac_auth_testsuite_setup, 15709 .unit_test_cases = { 15710 TEST_CASE_ST(ut_setup, ut_teardown, 15711 test_AES_GMAC_authentication_test_case_1), 15712 TEST_CASE_ST(ut_setup, ut_teardown, 15713 test_AES_GMAC_authentication_verify_test_case_1), 15714 TEST_CASE_ST(ut_setup, ut_teardown, 15715 test_AES_GMAC_authentication_test_case_2), 15716 TEST_CASE_ST(ut_setup, ut_teardown, 15717 test_AES_GMAC_authentication_verify_test_case_2), 15718 TEST_CASE_ST(ut_setup, ut_teardown, 15719 test_AES_GMAC_authentication_test_case_3), 15720 TEST_CASE_ST(ut_setup, ut_teardown, 15721 test_AES_GMAC_authentication_verify_test_case_3), 15722 TEST_CASE_ST(ut_setup, ut_teardown, 15723 test_AES_GMAC_authentication_test_case_4), 15724 TEST_CASE_ST(ut_setup, ut_teardown, 15725 test_AES_GMAC_authentication_verify_test_case_4), 15726 TEST_CASE_ST(ut_setup, ut_teardown, 15727 test_AES_GMAC_authentication_SGL_40B), 15728 TEST_CASE_ST(ut_setup, ut_teardown, 15729 test_AES_GMAC_authentication_SGL_80B), 15730 TEST_CASE_ST(ut_setup, ut_teardown, 15731 test_AES_GMAC_authentication_SGL_2048B), 15732 TEST_CASE_ST(ut_setup, ut_teardown, 15733 test_AES_GMAC_authentication_SGL_2047B), 15734 15735 TEST_CASES_END() 15736 } 15737 }; 15738 15739 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite = { 15740 .suite_name = "Chacha20-Poly1305 Test Suite", 15741 .setup = chacha20_poly1305_testsuite_setup, 15742 .unit_test_cases = { 15743 TEST_CASE_ST(ut_setup, ut_teardown, 15744 test_chacha20_poly1305_encrypt_test_case_rfc8439), 15745 TEST_CASE_ST(ut_setup, ut_teardown, 15746 test_chacha20_poly1305_decrypt_test_case_rfc8439), 15747 TEST_CASE_ST(ut_setup, ut_teardown, 15748 test_chacha20_poly1305_encrypt_SGL_out_of_place), 15749 TEST_CASES_END() 15750 } 15751 }; 15752 15753 static struct unit_test_suite cryptodev_snow3g_testsuite = { 15754 .suite_name = "SNOW 3G Test Suite", 15755 .setup = snow3g_testsuite_setup, 15756 .unit_test_cases = { 15757 /** SNOW 3G encrypt only (UEA2) */ 15758 TEST_CASE_ST(ut_setup, ut_teardown, 15759 test_snow3g_encryption_test_case_1), 15760 TEST_CASE_ST(ut_setup, ut_teardown, 15761 test_snow3g_encryption_test_case_2), 15762 TEST_CASE_ST(ut_setup, ut_teardown, 15763 test_snow3g_encryption_test_case_3), 15764 TEST_CASE_ST(ut_setup, ut_teardown, 15765 test_snow3g_encryption_test_case_4), 15766 TEST_CASE_ST(ut_setup, ut_teardown, 15767 test_snow3g_encryption_test_case_5), 15768 15769 TEST_CASE_ST(ut_setup, ut_teardown, 15770 test_snow3g_encryption_test_case_1_oop), 15771 TEST_CASE_ST(ut_setup, ut_teardown, 15772 test_snow3g_encryption_test_case_1_oop_sgl), 15773 TEST_CASE_ST(ut_setup, ut_teardown, 15774 test_snow3g_encryption_test_case_1_offset_oop), 15775 TEST_CASE_ST(ut_setup, ut_teardown, 15776 test_snow3g_decryption_test_case_1_oop), 15777 15778 /** SNOW 3G generate auth, then encrypt (UEA2) */ 15779 TEST_CASE_ST(ut_setup, ut_teardown, 15780 test_snow3g_auth_cipher_test_case_1), 15781 TEST_CASE_ST(ut_setup, ut_teardown, 15782 test_snow3g_auth_cipher_test_case_2), 15783 TEST_CASE_ST(ut_setup, ut_teardown, 15784 test_snow3g_auth_cipher_test_case_2_oop), 15785 TEST_CASE_ST(ut_setup, ut_teardown, 15786 test_snow3g_auth_cipher_part_digest_enc), 15787 TEST_CASE_ST(ut_setup, ut_teardown, 15788 test_snow3g_auth_cipher_part_digest_enc_oop), 15789 TEST_CASE_ST(ut_setup, ut_teardown, 15790 test_snow3g_auth_cipher_test_case_3_sgl), 15791 TEST_CASE_ST(ut_setup, ut_teardown, 15792 test_snow3g_auth_cipher_test_case_3_oop_sgl), 15793 TEST_CASE_ST(ut_setup, ut_teardown, 15794 test_snow3g_auth_cipher_part_digest_enc_sgl), 15795 TEST_CASE_ST(ut_setup, ut_teardown, 15796 test_snow3g_auth_cipher_part_digest_enc_oop_sgl), 15797 15798 /** SNOW 3G decrypt (UEA2), then verify auth */ 15799 TEST_CASE_ST(ut_setup, ut_teardown, 15800 test_snow3g_auth_cipher_verify_test_case_1), 15801 TEST_CASE_ST(ut_setup, ut_teardown, 15802 test_snow3g_auth_cipher_verify_test_case_2), 15803 TEST_CASE_ST(ut_setup, ut_teardown, 15804 test_snow3g_auth_cipher_verify_test_case_2_oop), 15805 TEST_CASE_ST(ut_setup, ut_teardown, 15806 test_snow3g_auth_cipher_verify_part_digest_enc), 15807 TEST_CASE_ST(ut_setup, ut_teardown, 15808 test_snow3g_auth_cipher_verify_part_digest_enc_oop), 15809 TEST_CASE_ST(ut_setup, ut_teardown, 15810 test_snow3g_auth_cipher_verify_test_case_3_sgl), 15811 TEST_CASE_ST(ut_setup, ut_teardown, 15812 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl), 15813 TEST_CASE_ST(ut_setup, ut_teardown, 15814 test_snow3g_auth_cipher_verify_part_digest_enc_sgl), 15815 TEST_CASE_ST(ut_setup, ut_teardown, 15816 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl), 15817 15818 /** SNOW 3G decrypt only (UEA2) */ 15819 TEST_CASE_ST(ut_setup, ut_teardown, 15820 test_snow3g_decryption_test_case_1), 15821 TEST_CASE_ST(ut_setup, ut_teardown, 15822 test_snow3g_decryption_test_case_2), 15823 TEST_CASE_ST(ut_setup, ut_teardown, 15824 test_snow3g_decryption_test_case_3), 15825 TEST_CASE_ST(ut_setup, ut_teardown, 15826 test_snow3g_decryption_test_case_4), 15827 TEST_CASE_ST(ut_setup, ut_teardown, 15828 test_snow3g_decryption_test_case_5), 15829 TEST_CASE_ST(ut_setup, ut_teardown, 15830 test_snow3g_decryption_with_digest_test_case_1), 15831 TEST_CASE_ST(ut_setup, ut_teardown, 15832 test_snow3g_hash_generate_test_case_1), 15833 TEST_CASE_ST(ut_setup, ut_teardown, 15834 test_snow3g_hash_generate_test_case_2), 15835 TEST_CASE_ST(ut_setup, ut_teardown, 15836 test_snow3g_hash_generate_test_case_3), 15837 15838 /* Tests with buffers which length is not byte-aligned */ 15839 TEST_CASE_ST(ut_setup, ut_teardown, 15840 test_snow3g_hash_generate_test_case_4), 15841 TEST_CASE_ST(ut_setup, ut_teardown, 15842 test_snow3g_hash_generate_test_case_5), 15843 TEST_CASE_ST(ut_setup, ut_teardown, 15844 test_snow3g_hash_generate_test_case_6), 15845 TEST_CASE_ST(ut_setup, ut_teardown, 15846 test_snow3g_hash_verify_test_case_1), 15847 TEST_CASE_ST(ut_setup, ut_teardown, 15848 test_snow3g_hash_verify_test_case_2), 15849 TEST_CASE_ST(ut_setup, ut_teardown, 15850 test_snow3g_hash_verify_test_case_3), 15851 15852 /* Tests with buffers which length is not byte-aligned */ 15853 TEST_CASE_ST(ut_setup, ut_teardown, 15854 test_snow3g_hash_verify_test_case_4), 15855 TEST_CASE_ST(ut_setup, ut_teardown, 15856 test_snow3g_hash_verify_test_case_5), 15857 TEST_CASE_ST(ut_setup, ut_teardown, 15858 test_snow3g_hash_verify_test_case_6), 15859 TEST_CASE_ST(ut_setup, ut_teardown, 15860 test_snow3g_cipher_auth_test_case_1), 15861 TEST_CASE_ST(ut_setup, ut_teardown, 15862 test_snow3g_auth_cipher_with_digest_test_case_1), 15863 TEST_CASES_END() 15864 } 15865 }; 15866 15867 static struct unit_test_suite cryptodev_zuc_testsuite = { 15868 .suite_name = "ZUC Test Suite", 15869 .setup = zuc_testsuite_setup, 15870 .unit_test_cases = { 15871 /** ZUC encrypt only (EEA3) */ 15872 TEST_CASE_ST(ut_setup, ut_teardown, 15873 test_zuc_encryption_test_case_1), 15874 TEST_CASE_ST(ut_setup, ut_teardown, 15875 test_zuc_encryption_test_case_2), 15876 TEST_CASE_ST(ut_setup, ut_teardown, 15877 test_zuc_encryption_test_case_3), 15878 TEST_CASE_ST(ut_setup, ut_teardown, 15879 test_zuc_encryption_test_case_4), 15880 TEST_CASE_ST(ut_setup, ut_teardown, 15881 test_zuc_encryption_test_case_5), 15882 TEST_CASE_ST(ut_setup, ut_teardown, 15883 test_zuc_encryption_test_case_6_sgl), 15884 15885 /** ZUC authenticate (EIA3) */ 15886 TEST_CASE_ST(ut_setup, ut_teardown, 15887 test_zuc_hash_generate_test_case_1), 15888 TEST_CASE_ST(ut_setup, ut_teardown, 15889 test_zuc_hash_generate_test_case_2), 15890 TEST_CASE_ST(ut_setup, ut_teardown, 15891 test_zuc_hash_generate_test_case_3), 15892 TEST_CASE_ST(ut_setup, ut_teardown, 15893 test_zuc_hash_generate_test_case_4), 15894 TEST_CASE_ST(ut_setup, ut_teardown, 15895 test_zuc_hash_generate_test_case_5), 15896 TEST_CASE_ST(ut_setup, ut_teardown, 15897 test_zuc_hash_generate_test_case_6), 15898 TEST_CASE_ST(ut_setup, ut_teardown, 15899 test_zuc_hash_generate_test_case_7), 15900 TEST_CASE_ST(ut_setup, ut_teardown, 15901 test_zuc_hash_generate_test_case_8), 15902 TEST_CASE_ST(ut_setup, ut_teardown, 15903 test_zuc_hash_generate_test_case_9), 15904 TEST_CASE_ST(ut_setup, ut_teardown, 15905 test_zuc_hash_generate_test_case_10), 15906 TEST_CASE_ST(ut_setup, ut_teardown, 15907 test_zuc_hash_generate_test_case_11), 15908 15909 15910 /** ZUC alg-chain (EEA3/EIA3) */ 15911 TEST_CASE_ST(ut_setup, ut_teardown, 15912 test_zuc_cipher_auth_test_case_1), 15913 TEST_CASE_ST(ut_setup, ut_teardown, 15914 test_zuc_cipher_auth_test_case_2), 15915 15916 /** ZUC generate auth, then encrypt (EEA3) */ 15917 TEST_CASE_ST(ut_setup, ut_teardown, 15918 test_zuc_auth_cipher_test_case_1), 15919 TEST_CASE_ST(ut_setup, ut_teardown, 15920 test_zuc_auth_cipher_test_case_1_oop), 15921 TEST_CASE_ST(ut_setup, ut_teardown, 15922 test_zuc_auth_cipher_test_case_1_sgl), 15923 TEST_CASE_ST(ut_setup, ut_teardown, 15924 test_zuc_auth_cipher_test_case_1_oop_sgl), 15925 15926 /** ZUC decrypt (EEA3), then verify auth */ 15927 TEST_CASE_ST(ut_setup, ut_teardown, 15928 test_zuc_auth_cipher_verify_test_case_1), 15929 TEST_CASE_ST(ut_setup, ut_teardown, 15930 test_zuc_auth_cipher_verify_test_case_1_oop), 15931 TEST_CASE_ST(ut_setup, ut_teardown, 15932 test_zuc_auth_cipher_verify_test_case_1_sgl), 15933 TEST_CASE_ST(ut_setup, ut_teardown, 15934 test_zuc_auth_cipher_verify_test_case_1_oop_sgl), 15935 15936 /** ZUC-256 encrypt only **/ 15937 TEST_CASE_ST(ut_setup, ut_teardown, 15938 test_zuc256_encryption_test_case_1), 15939 TEST_CASE_ST(ut_setup, ut_teardown, 15940 test_zuc256_encryption_test_case_2), 15941 15942 /** ZUC-256 authentication only **/ 15943 TEST_CASE_ST(ut_setup, ut_teardown, 15944 test_zuc256_authentication_test_case_1), 15945 TEST_CASE_ST(ut_setup, ut_teardown, 15946 test_zuc256_authentication_test_case_2), 15947 15948 TEST_CASES_END() 15949 } 15950 }; 15951 15952 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite = { 15953 .suite_name = "HMAC_MD5 Authentication Test Suite", 15954 .setup = hmac_md5_auth_testsuite_setup, 15955 .unit_test_cases = { 15956 TEST_CASE_ST(ut_setup, ut_teardown, 15957 test_MD5_HMAC_generate_case_1), 15958 TEST_CASE_ST(ut_setup, ut_teardown, 15959 test_MD5_HMAC_verify_case_1), 15960 TEST_CASE_ST(ut_setup, ut_teardown, 15961 test_MD5_HMAC_generate_case_2), 15962 TEST_CASE_ST(ut_setup, ut_teardown, 15963 test_MD5_HMAC_verify_case_2), 15964 TEST_CASES_END() 15965 } 15966 }; 15967 15968 static struct unit_test_suite cryptodev_kasumi_testsuite = { 15969 .suite_name = "Kasumi Test Suite", 15970 .setup = kasumi_testsuite_setup, 15971 .unit_test_cases = { 15972 /** KASUMI hash only (UIA1) */ 15973 TEST_CASE_ST(ut_setup, ut_teardown, 15974 test_kasumi_hash_generate_test_case_1), 15975 TEST_CASE_ST(ut_setup, ut_teardown, 15976 test_kasumi_hash_generate_test_case_2), 15977 TEST_CASE_ST(ut_setup, ut_teardown, 15978 test_kasumi_hash_generate_test_case_3), 15979 TEST_CASE_ST(ut_setup, ut_teardown, 15980 test_kasumi_hash_generate_test_case_4), 15981 TEST_CASE_ST(ut_setup, ut_teardown, 15982 test_kasumi_hash_generate_test_case_5), 15983 TEST_CASE_ST(ut_setup, ut_teardown, 15984 test_kasumi_hash_generate_test_case_6), 15985 15986 TEST_CASE_ST(ut_setup, ut_teardown, 15987 test_kasumi_hash_verify_test_case_1), 15988 TEST_CASE_ST(ut_setup, ut_teardown, 15989 test_kasumi_hash_verify_test_case_2), 15990 TEST_CASE_ST(ut_setup, ut_teardown, 15991 test_kasumi_hash_verify_test_case_3), 15992 TEST_CASE_ST(ut_setup, ut_teardown, 15993 test_kasumi_hash_verify_test_case_4), 15994 TEST_CASE_ST(ut_setup, ut_teardown, 15995 test_kasumi_hash_verify_test_case_5), 15996 15997 /** KASUMI encrypt only (UEA1) */ 15998 TEST_CASE_ST(ut_setup, ut_teardown, 15999 test_kasumi_encryption_test_case_1), 16000 TEST_CASE_ST(ut_setup, ut_teardown, 16001 test_kasumi_encryption_test_case_1_sgl), 16002 TEST_CASE_ST(ut_setup, ut_teardown, 16003 test_kasumi_encryption_test_case_1_oop), 16004 TEST_CASE_ST(ut_setup, ut_teardown, 16005 test_kasumi_encryption_test_case_1_oop_sgl), 16006 TEST_CASE_ST(ut_setup, ut_teardown, 16007 test_kasumi_encryption_test_case_2), 16008 TEST_CASE_ST(ut_setup, ut_teardown, 16009 test_kasumi_encryption_test_case_3), 16010 TEST_CASE_ST(ut_setup, ut_teardown, 16011 test_kasumi_encryption_test_case_4), 16012 TEST_CASE_ST(ut_setup, ut_teardown, 16013 test_kasumi_encryption_test_case_5), 16014 16015 /** KASUMI decrypt only (UEA1) */ 16016 TEST_CASE_ST(ut_setup, ut_teardown, 16017 test_kasumi_decryption_test_case_1), 16018 TEST_CASE_ST(ut_setup, ut_teardown, 16019 test_kasumi_decryption_test_case_2), 16020 TEST_CASE_ST(ut_setup, ut_teardown, 16021 test_kasumi_decryption_test_case_3), 16022 TEST_CASE_ST(ut_setup, ut_teardown, 16023 test_kasumi_decryption_test_case_4), 16024 TEST_CASE_ST(ut_setup, ut_teardown, 16025 test_kasumi_decryption_test_case_5), 16026 TEST_CASE_ST(ut_setup, ut_teardown, 16027 test_kasumi_decryption_test_case_1_oop), 16028 TEST_CASE_ST(ut_setup, ut_teardown, 16029 test_kasumi_cipher_auth_test_case_1), 16030 16031 /** KASUMI generate auth, then encrypt (F8) */ 16032 TEST_CASE_ST(ut_setup, ut_teardown, 16033 test_kasumi_auth_cipher_test_case_1), 16034 TEST_CASE_ST(ut_setup, ut_teardown, 16035 test_kasumi_auth_cipher_test_case_2), 16036 TEST_CASE_ST(ut_setup, ut_teardown, 16037 test_kasumi_auth_cipher_test_case_2_oop), 16038 TEST_CASE_ST(ut_setup, ut_teardown, 16039 test_kasumi_auth_cipher_test_case_2_sgl), 16040 TEST_CASE_ST(ut_setup, ut_teardown, 16041 test_kasumi_auth_cipher_test_case_2_oop_sgl), 16042 16043 /** KASUMI decrypt (F8), then verify auth */ 16044 TEST_CASE_ST(ut_setup, ut_teardown, 16045 test_kasumi_auth_cipher_verify_test_case_1), 16046 TEST_CASE_ST(ut_setup, ut_teardown, 16047 test_kasumi_auth_cipher_verify_test_case_2), 16048 TEST_CASE_ST(ut_setup, ut_teardown, 16049 test_kasumi_auth_cipher_verify_test_case_2_oop), 16050 TEST_CASE_ST(ut_setup, ut_teardown, 16051 test_kasumi_auth_cipher_verify_test_case_2_sgl), 16052 TEST_CASE_ST(ut_setup, ut_teardown, 16053 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl), 16054 16055 TEST_CASES_END() 16056 } 16057 }; 16058 16059 static struct unit_test_suite cryptodev_esn_testsuite = { 16060 .suite_name = "ESN Test Suite", 16061 .setup = esn_testsuite_setup, 16062 .unit_test_cases = { 16063 TEST_CASE_ST(ut_setup, ut_teardown, 16064 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 16065 TEST_CASE_ST(ut_setup, ut_teardown, 16066 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 16067 TEST_CASES_END() 16068 } 16069 }; 16070 16071 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite = { 16072 .suite_name = "Negative AES GCM Test Suite", 16073 .setup = negative_aes_gcm_testsuite_setup, 16074 .unit_test_cases = { 16075 TEST_CASE_ST(ut_setup, ut_teardown, 16076 test_AES_GCM_auth_encryption_fail_iv_corrupt), 16077 TEST_CASE_ST(ut_setup, ut_teardown, 16078 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 16079 TEST_CASE_ST(ut_setup, ut_teardown, 16080 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 16081 TEST_CASE_ST(ut_setup, ut_teardown, 16082 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 16083 TEST_CASE_ST(ut_setup, ut_teardown, 16084 test_AES_GCM_auth_encryption_fail_aad_corrupt), 16085 TEST_CASE_ST(ut_setup, ut_teardown, 16086 test_AES_GCM_auth_encryption_fail_tag_corrupt), 16087 TEST_CASE_ST(ut_setup, ut_teardown, 16088 test_AES_GCM_auth_decryption_fail_iv_corrupt), 16089 TEST_CASE_ST(ut_setup, ut_teardown, 16090 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 16091 TEST_CASE_ST(ut_setup, ut_teardown, 16092 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 16093 TEST_CASE_ST(ut_setup, ut_teardown, 16094 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 16095 TEST_CASE_ST(ut_setup, ut_teardown, 16096 test_AES_GCM_auth_decryption_fail_aad_corrupt), 16097 TEST_CASE_ST(ut_setup, ut_teardown, 16098 test_AES_GCM_auth_decryption_fail_tag_corrupt), 16099 16100 TEST_CASES_END() 16101 } 16102 }; 16103 16104 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite = { 16105 .suite_name = "Negative AES GMAC Test Suite", 16106 .setup = negative_aes_gmac_testsuite_setup, 16107 .unit_test_cases = { 16108 TEST_CASE_ST(ut_setup, ut_teardown, 16109 authentication_verify_AES128_GMAC_fail_data_corrupt), 16110 TEST_CASE_ST(ut_setup, ut_teardown, 16111 authentication_verify_AES128_GMAC_fail_tag_corrupt), 16112 16113 TEST_CASES_END() 16114 } 16115 }; 16116 16117 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite = { 16118 .suite_name = "Mixed CIPHER + HASH algorithms Test Suite", 16119 .setup = mixed_cipher_hash_testsuite_setup, 16120 .unit_test_cases = { 16121 /** AUTH AES CMAC + CIPHER AES CTR */ 16122 TEST_CASE_ST(ut_setup, ut_teardown, 16123 test_aes_cmac_aes_ctr_digest_enc_test_case_1), 16124 TEST_CASE_ST(ut_setup, ut_teardown, 16125 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 16126 TEST_CASE_ST(ut_setup, ut_teardown, 16127 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 16128 TEST_CASE_ST(ut_setup, ut_teardown, 16129 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 16130 TEST_CASE_ST(ut_setup, ut_teardown, 16131 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1), 16132 TEST_CASE_ST(ut_setup, ut_teardown, 16133 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 16134 TEST_CASE_ST(ut_setup, ut_teardown, 16135 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 16136 TEST_CASE_ST(ut_setup, ut_teardown, 16137 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 16138 16139 /** AUTH ZUC + CIPHER SNOW3G */ 16140 TEST_CASE_ST(ut_setup, ut_teardown, 16141 test_auth_zuc_cipher_snow_test_case_1), 16142 TEST_CASE_ST(ut_setup, ut_teardown, 16143 test_verify_auth_zuc_cipher_snow_test_case_1), 16144 /** AUTH AES CMAC + CIPHER SNOW3G */ 16145 TEST_CASE_ST(ut_setup, ut_teardown, 16146 test_auth_aes_cmac_cipher_snow_test_case_1), 16147 TEST_CASE_ST(ut_setup, ut_teardown, 16148 test_verify_auth_aes_cmac_cipher_snow_test_case_1), 16149 /** AUTH ZUC + CIPHER AES CTR */ 16150 TEST_CASE_ST(ut_setup, ut_teardown, 16151 test_auth_zuc_cipher_aes_ctr_test_case_1), 16152 TEST_CASE_ST(ut_setup, ut_teardown, 16153 test_verify_auth_zuc_cipher_aes_ctr_test_case_1), 16154 /** AUTH SNOW3G + CIPHER AES CTR */ 16155 TEST_CASE_ST(ut_setup, ut_teardown, 16156 test_auth_snow_cipher_aes_ctr_test_case_1), 16157 TEST_CASE_ST(ut_setup, ut_teardown, 16158 test_verify_auth_snow_cipher_aes_ctr_test_case_1), 16159 /** AUTH SNOW3G + CIPHER ZUC */ 16160 TEST_CASE_ST(ut_setup, ut_teardown, 16161 test_auth_snow_cipher_zuc_test_case_1), 16162 TEST_CASE_ST(ut_setup, ut_teardown, 16163 test_verify_auth_snow_cipher_zuc_test_case_1), 16164 /** AUTH AES CMAC + CIPHER ZUC */ 16165 TEST_CASE_ST(ut_setup, ut_teardown, 16166 test_auth_aes_cmac_cipher_zuc_test_case_1), 16167 TEST_CASE_ST(ut_setup, ut_teardown, 16168 test_verify_auth_aes_cmac_cipher_zuc_test_case_1), 16169 16170 /** AUTH NULL + CIPHER SNOW3G */ 16171 TEST_CASE_ST(ut_setup, ut_teardown, 16172 test_auth_null_cipher_snow_test_case_1), 16173 TEST_CASE_ST(ut_setup, ut_teardown, 16174 test_verify_auth_null_cipher_snow_test_case_1), 16175 /** AUTH NULL + CIPHER ZUC */ 16176 TEST_CASE_ST(ut_setup, ut_teardown, 16177 test_auth_null_cipher_zuc_test_case_1), 16178 TEST_CASE_ST(ut_setup, ut_teardown, 16179 test_verify_auth_null_cipher_zuc_test_case_1), 16180 /** AUTH SNOW3G + CIPHER NULL */ 16181 TEST_CASE_ST(ut_setup, ut_teardown, 16182 test_auth_snow_cipher_null_test_case_1), 16183 TEST_CASE_ST(ut_setup, ut_teardown, 16184 test_verify_auth_snow_cipher_null_test_case_1), 16185 /** AUTH ZUC + CIPHER NULL */ 16186 TEST_CASE_ST(ut_setup, ut_teardown, 16187 test_auth_zuc_cipher_null_test_case_1), 16188 TEST_CASE_ST(ut_setup, ut_teardown, 16189 test_verify_auth_zuc_cipher_null_test_case_1), 16190 /** AUTH NULL + CIPHER AES CTR */ 16191 TEST_CASE_ST(ut_setup, ut_teardown, 16192 test_auth_null_cipher_aes_ctr_test_case_1), 16193 TEST_CASE_ST(ut_setup, ut_teardown, 16194 test_verify_auth_null_cipher_aes_ctr_test_case_1), 16195 /** AUTH AES CMAC + CIPHER NULL */ 16196 TEST_CASE_ST(ut_setup, ut_teardown, 16197 test_auth_aes_cmac_cipher_null_test_case_1), 16198 TEST_CASE_ST(ut_setup, ut_teardown, 16199 test_verify_auth_aes_cmac_cipher_null_test_case_1), 16200 TEST_CASES_END() 16201 } 16202 }; 16203 16204 static int 16205 run_cryptodev_testsuite(const char *pmd_name) 16206 { 16207 uint8_t ret, j, i = 0, blk_start_idx = 0; 16208 const enum blockcipher_test_type blk_suites[] = { 16209 BLKCIPHER_AES_CHAIN_TYPE, 16210 BLKCIPHER_AES_CIPHERONLY_TYPE, 16211 BLKCIPHER_AES_DOCSIS_TYPE, 16212 BLKCIPHER_3DES_CHAIN_TYPE, 16213 BLKCIPHER_3DES_CIPHERONLY_TYPE, 16214 BLKCIPHER_DES_CIPHERONLY_TYPE, 16215 BLKCIPHER_DES_DOCSIS_TYPE, 16216 BLKCIPHER_AUTHONLY_TYPE}; 16217 struct unit_test_suite *static_suites[] = { 16218 &cryptodev_multi_session_testsuite, 16219 &cryptodev_null_testsuite, 16220 &cryptodev_aes_ccm_auth_testsuite, 16221 &cryptodev_aes_gcm_auth_testsuite, 16222 &cryptodev_aes_gmac_auth_testsuite, 16223 &cryptodev_snow3g_testsuite, 16224 &cryptodev_chacha20_poly1305_testsuite, 16225 &cryptodev_zuc_testsuite, 16226 &cryptodev_hmac_md5_auth_testsuite, 16227 &cryptodev_kasumi_testsuite, 16228 &cryptodev_esn_testsuite, 16229 &cryptodev_negative_aes_gcm_testsuite, 16230 &cryptodev_negative_aes_gmac_testsuite, 16231 &cryptodev_mixed_cipher_hash_testsuite, 16232 &cryptodev_negative_hmac_sha1_testsuite, 16233 &cryptodev_gen_testsuite, 16234 #ifdef RTE_LIB_SECURITY 16235 &ipsec_proto_testsuite, 16236 &pdcp_proto_testsuite, 16237 &docsis_proto_testsuite, 16238 #endif 16239 &end_testsuite 16240 }; 16241 static struct unit_test_suite ts = { 16242 .suite_name = "Cryptodev Unit Test Suite", 16243 .setup = testsuite_setup, 16244 .teardown = testsuite_teardown, 16245 .unit_test_cases = {TEST_CASES_END()} 16246 }; 16247 16248 gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name); 16249 16250 if (gbl_driver_id == -1) { 16251 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name); 16252 return TEST_SKIPPED; 16253 } 16254 16255 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 16256 (RTE_DIM(blk_suites) + RTE_DIM(static_suites))); 16257 16258 ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites)); 16259 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 16260 ret = unit_test_suite_runner(&ts); 16261 16262 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites)); 16263 free(ts.unit_test_suites); 16264 return ret; 16265 } 16266 16267 static int 16268 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name) 16269 { 16270 struct rte_cryptodev_info dev_info; 16271 uint8_t i, nb_devs; 16272 int driver_id; 16273 16274 driver_id = rte_cryptodev_driver_id_get(pmd_name); 16275 if (driver_id == -1) { 16276 RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name); 16277 return TEST_SKIPPED; 16278 } 16279 16280 nb_devs = rte_cryptodev_count(); 16281 if (nb_devs < 1) { 16282 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 16283 return TEST_SKIPPED; 16284 } 16285 16286 for (i = 0; i < nb_devs; i++) { 16287 rte_cryptodev_info_get(i, &dev_info); 16288 if (dev_info.driver_id == driver_id) { 16289 if (!(dev_info.feature_flags & flag)) { 16290 RTE_LOG(INFO, USER1, "%s not supported\n", 16291 flag_name); 16292 return TEST_SKIPPED; 16293 } 16294 return 0; /* found */ 16295 } 16296 } 16297 16298 RTE_LOG(INFO, USER1, "%s not supported\n", flag_name); 16299 return TEST_SKIPPED; 16300 } 16301 16302 static int 16303 test_cryptodev_qat(void) 16304 { 16305 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 16306 } 16307 16308 static int 16309 test_cryptodev_virtio(void) 16310 { 16311 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)); 16312 } 16313 16314 static int 16315 test_cryptodev_aesni_mb(void) 16316 { 16317 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 16318 } 16319 16320 static int 16321 test_cryptodev_cpu_aesni_mb(void) 16322 { 16323 int32_t rc; 16324 enum rte_security_session_action_type at = gbl_action_type; 16325 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 16326 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 16327 gbl_action_type = at; 16328 return rc; 16329 } 16330 16331 static int 16332 test_cryptodev_chacha_poly_mb(void) 16333 { 16334 int32_t rc; 16335 enum rte_security_session_action_type at = gbl_action_type; 16336 rc = run_cryptodev_testsuite( 16337 RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD)); 16338 gbl_action_type = at; 16339 return rc; 16340 } 16341 16342 static int 16343 test_cryptodev_openssl(void) 16344 { 16345 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 16346 } 16347 16348 static int 16349 test_cryptodev_aesni_gcm(void) 16350 { 16351 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 16352 } 16353 16354 static int 16355 test_cryptodev_cpu_aesni_gcm(void) 16356 { 16357 int32_t rc; 16358 enum rte_security_session_action_type at = gbl_action_type; 16359 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 16360 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 16361 gbl_action_type = at; 16362 return rc; 16363 } 16364 16365 static int 16366 test_cryptodev_mlx5(void) 16367 { 16368 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD)); 16369 } 16370 16371 static int 16372 test_cryptodev_null(void) 16373 { 16374 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 16375 } 16376 16377 static int 16378 test_cryptodev_sw_snow3g(void) 16379 { 16380 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 16381 } 16382 16383 static int 16384 test_cryptodev_sw_kasumi(void) 16385 { 16386 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 16387 } 16388 16389 static int 16390 test_cryptodev_sw_zuc(void) 16391 { 16392 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 16393 } 16394 16395 static int 16396 test_cryptodev_armv8(void) 16397 { 16398 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 16399 } 16400 16401 static int 16402 test_cryptodev_mrvl(void) 16403 { 16404 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 16405 } 16406 16407 #ifdef RTE_CRYPTO_SCHEDULER 16408 16409 static int 16410 test_cryptodev_scheduler(void) 16411 { 16412 uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0; 16413 const enum blockcipher_test_type blk_suites[] = { 16414 BLKCIPHER_AES_CHAIN_TYPE, 16415 BLKCIPHER_AES_CIPHERONLY_TYPE, 16416 BLKCIPHER_AUTHONLY_TYPE 16417 }; 16418 static struct unit_test_suite scheduler_multicore = { 16419 .suite_name = "Scheduler Multicore Unit Test Suite", 16420 .setup = scheduler_multicore_testsuite_setup, 16421 .teardown = scheduler_mode_testsuite_teardown, 16422 .unit_test_cases = {TEST_CASES_END()} 16423 }; 16424 static struct unit_test_suite scheduler_round_robin = { 16425 .suite_name = "Scheduler Round Robin Unit Test Suite", 16426 .setup = scheduler_roundrobin_testsuite_setup, 16427 .teardown = scheduler_mode_testsuite_teardown, 16428 .unit_test_cases = {TEST_CASES_END()} 16429 }; 16430 static struct unit_test_suite scheduler_failover = { 16431 .suite_name = "Scheduler Failover Unit Test Suite", 16432 .setup = scheduler_failover_testsuite_setup, 16433 .teardown = scheduler_mode_testsuite_teardown, 16434 .unit_test_cases = {TEST_CASES_END()} 16435 }; 16436 static struct unit_test_suite scheduler_pkt_size_distr = { 16437 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite", 16438 .setup = scheduler_pkt_size_distr_testsuite_setup, 16439 .teardown = scheduler_mode_testsuite_teardown, 16440 .unit_test_cases = {TEST_CASES_END()} 16441 }; 16442 struct unit_test_suite *sched_mode_suites[] = { 16443 &scheduler_multicore, 16444 &scheduler_round_robin, 16445 &scheduler_failover, 16446 &scheduler_pkt_size_distr 16447 }; 16448 static struct unit_test_suite scheduler_config = { 16449 .suite_name = "Crypto Device Scheduler Config Unit Test Suite", 16450 .unit_test_cases = { 16451 TEST_CASE(test_scheduler_attach_worker_op), 16452 TEST_CASE(test_scheduler_mode_multicore_op), 16453 TEST_CASE(test_scheduler_mode_roundrobin_op), 16454 TEST_CASE(test_scheduler_mode_failover_op), 16455 TEST_CASE(test_scheduler_mode_pkt_size_distr_op), 16456 TEST_CASE(test_scheduler_detach_worker_op), 16457 16458 TEST_CASES_END() /**< NULL terminate array */ 16459 } 16460 }; 16461 struct unit_test_suite *static_suites[] = { 16462 &scheduler_config, 16463 &end_testsuite 16464 }; 16465 static struct unit_test_suite ts = { 16466 .suite_name = "Scheduler Unit Test Suite", 16467 .setup = scheduler_testsuite_setup, 16468 .teardown = testsuite_teardown, 16469 .unit_test_cases = {TEST_CASES_END()} 16470 }; 16471 16472 gbl_driver_id = rte_cryptodev_driver_id_get( 16473 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 16474 16475 if (gbl_driver_id == -1) { 16476 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n"); 16477 return TEST_SKIPPED; 16478 } 16479 16480 if (rte_cryptodev_driver_id_get( 16481 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) { 16482 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 16483 return TEST_SKIPPED; 16484 } 16485 16486 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 16487 uint8_t blk_i = 0; 16488 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof 16489 (struct unit_test_suite *) * 16490 (RTE_DIM(blk_suites) + 1)); 16491 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]), 16492 blk_suites, RTE_DIM(blk_suites)); 16493 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite; 16494 } 16495 16496 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 16497 (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites))); 16498 ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites, 16499 RTE_DIM(sched_mode_suites)); 16500 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 16501 ret = unit_test_suite_runner(&ts); 16502 16503 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 16504 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, 16505 (*sched_mode_suites[sched_i]), 16506 RTE_DIM(blk_suites)); 16507 free(sched_mode_suites[sched_i]->unit_test_suites); 16508 } 16509 free(ts.unit_test_suites); 16510 return ret; 16511 } 16512 16513 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler); 16514 16515 #endif 16516 16517 static int 16518 test_cryptodev_dpaa2_sec(void) 16519 { 16520 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 16521 } 16522 16523 static int 16524 test_cryptodev_dpaa_sec(void) 16525 { 16526 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 16527 } 16528 16529 static int 16530 test_cryptodev_ccp(void) 16531 { 16532 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 16533 } 16534 16535 static int 16536 test_cryptodev_octeontx(void) 16537 { 16538 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)); 16539 } 16540 16541 static int 16542 test_cryptodev_caam_jr(void) 16543 { 16544 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)); 16545 } 16546 16547 static int 16548 test_cryptodev_nitrox(void) 16549 { 16550 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD)); 16551 } 16552 16553 static int 16554 test_cryptodev_bcmfs(void) 16555 { 16556 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD)); 16557 } 16558 16559 static int 16560 test_cryptodev_qat_raw_api(void) 16561 { 16562 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD); 16563 int ret; 16564 16565 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 16566 "RAW API"); 16567 if (ret) 16568 return ret; 16569 16570 global_api_test_type = CRYPTODEV_RAW_API_TEST; 16571 ret = run_cryptodev_testsuite(pmd_name); 16572 global_api_test_type = CRYPTODEV_API_TEST; 16573 16574 return ret; 16575 } 16576 16577 static int 16578 test_cryptodev_cn9k(void) 16579 { 16580 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD)); 16581 } 16582 16583 static int 16584 test_cryptodev_cn10k(void) 16585 { 16586 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD)); 16587 } 16588 16589 static int 16590 test_cryptodev_dpaa2_sec_raw_api(void) 16591 { 16592 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD); 16593 int ret; 16594 16595 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 16596 "RAW API"); 16597 if (ret) 16598 return ret; 16599 16600 global_api_test_type = CRYPTODEV_RAW_API_TEST; 16601 ret = run_cryptodev_testsuite(pmd_name); 16602 global_api_test_type = CRYPTODEV_API_TEST; 16603 16604 return ret; 16605 } 16606 16607 static int 16608 test_cryptodev_dpaa_sec_raw_api(void) 16609 { 16610 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD); 16611 int ret; 16612 16613 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 16614 "RAW API"); 16615 if (ret) 16616 return ret; 16617 16618 global_api_test_type = CRYPTODEV_RAW_API_TEST; 16619 ret = run_cryptodev_testsuite(pmd_name); 16620 global_api_test_type = CRYPTODEV_API_TEST; 16621 16622 return ret; 16623 } 16624 16625 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_raw_api_autotest, 16626 test_cryptodev_dpaa2_sec_raw_api); 16627 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_raw_api_autotest, 16628 test_cryptodev_dpaa_sec_raw_api); 16629 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest, 16630 test_cryptodev_qat_raw_api); 16631 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat); 16632 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 16633 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest, 16634 test_cryptodev_cpu_aesni_mb); 16635 REGISTER_TEST_COMMAND(cryptodev_chacha_poly_mb_autotest, 16636 test_cryptodev_chacha_poly_mb); 16637 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl); 16638 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 16639 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest, 16640 test_cryptodev_cpu_aesni_gcm); 16641 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5); 16642 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null); 16643 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 16644 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 16645 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 16646 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8); 16647 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl); 16648 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec); 16649 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec); 16650 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp); 16651 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio); 16652 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx); 16653 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr); 16654 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox); 16655 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs); 16656 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k); 16657 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k); 16658