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 0); 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 0); 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 memset(&flags, 0, sizeof(flags)); 10060 flags.antireplay = true; 10061 10062 for (i = 0; i < nb_pkts; i++) { 10063 memcpy(&td_outb[i], test_data, sizeof(td_outb[i])); 10064 td_outb[i].ipsec_xform.options.iv_gen_disable = 1; 10065 td_outb[i].ipsec_xform.replay_win_sz = winsz; 10066 td_outb[i].ipsec_xform.options.esn = esn_en; 10067 } 10068 10069 for (i = 0; i < nb_pkts; i++) 10070 td_outb[i].ipsec_xform.esn.value = esn[i]; 10071 10072 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 10073 &flags); 10074 if (ret != TEST_SUCCESS) 10075 return ret; 10076 10077 test_ipsec_td_update(td_inb, td_outb, nb_pkts, &flags); 10078 10079 for (i = 0; i < nb_pkts; i++) { 10080 td_inb[i].ipsec_xform.options.esn = esn_en; 10081 /* Set antireplay flag for packets to be dropped */ 10082 td_inb[i].ar_packet = replayed_pkt[i]; 10083 } 10084 10085 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 10086 &flags); 10087 10088 return ret; 10089 } 10090 10091 static int 10092 test_ipsec_proto_pkt_antireplay(const void *test_data, uint64_t winsz) 10093 { 10094 10095 uint32_t nb_pkts = 5; 10096 bool replayed_pkt[5]; 10097 uint64_t esn[5]; 10098 10099 /* 1. Advance the TOP of the window to WS * 2 */ 10100 esn[0] = winsz * 2; 10101 /* 2. Test sequence number within the new window(WS + 1) */ 10102 esn[1] = winsz + 1; 10103 /* 3. Test sequence number less than the window BOTTOM */ 10104 esn[2] = winsz; 10105 /* 4. Test sequence number in the middle of the window */ 10106 esn[3] = winsz + (winsz / 2); 10107 /* 5. Test replay of the packet in the middle of the window */ 10108 esn[4] = winsz + (winsz / 2); 10109 10110 replayed_pkt[0] = false; 10111 replayed_pkt[1] = false; 10112 replayed_pkt[2] = true; 10113 replayed_pkt[3] = false; 10114 replayed_pkt[4] = true; 10115 10116 return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts, 10117 false, winsz); 10118 } 10119 10120 static int 10121 test_ipsec_proto_pkt_antireplay1024(const void *test_data) 10122 { 10123 return test_ipsec_proto_pkt_antireplay(test_data, 1024); 10124 } 10125 10126 static int 10127 test_ipsec_proto_pkt_antireplay2048(const void *test_data) 10128 { 10129 return test_ipsec_proto_pkt_antireplay(test_data, 2048); 10130 } 10131 10132 static int 10133 test_ipsec_proto_pkt_antireplay4096(const void *test_data) 10134 { 10135 return test_ipsec_proto_pkt_antireplay(test_data, 4096); 10136 } 10137 10138 static int 10139 test_ipsec_proto_pkt_esn_antireplay(const void *test_data, uint64_t winsz) 10140 { 10141 10142 uint32_t nb_pkts = 7; 10143 bool replayed_pkt[7]; 10144 uint64_t esn[7]; 10145 10146 /* Set the initial sequence number */ 10147 esn[0] = (uint64_t)(0xFFFFFFFF - winsz); 10148 /* 1. Advance the TOP of the window to (1<<32 + WS/2) */ 10149 esn[1] = (uint64_t)((1ULL << 32) + (winsz / 2)); 10150 /* 2. Test sequence number within new window (1<<32 + WS/2 + 1) */ 10151 esn[2] = (uint64_t)((1ULL << 32) - (winsz / 2) + 1); 10152 /* 3. Test with sequence number within window (1<<32 - 1) */ 10153 esn[3] = (uint64_t)((1ULL << 32) - 1); 10154 /* 4. Test with sequence number within window (1<<32 - 1) */ 10155 esn[4] = (uint64_t)(1ULL << 32); 10156 /* 5. Test with duplicate sequence number within 10157 * new window (1<<32 - 1) 10158 */ 10159 esn[5] = (uint64_t)((1ULL << 32) - 1); 10160 /* 6. Test with duplicate sequence number within new window (1<<32) */ 10161 esn[6] = (uint64_t)(1ULL << 32); 10162 10163 replayed_pkt[0] = false; 10164 replayed_pkt[1] = false; 10165 replayed_pkt[2] = false; 10166 replayed_pkt[3] = false; 10167 replayed_pkt[4] = false; 10168 replayed_pkt[5] = true; 10169 replayed_pkt[6] = true; 10170 10171 return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts, 10172 true, winsz); 10173 } 10174 10175 static int 10176 test_ipsec_proto_pkt_esn_antireplay1024(const void *test_data) 10177 { 10178 return test_ipsec_proto_pkt_esn_antireplay(test_data, 1024); 10179 } 10180 10181 static int 10182 test_ipsec_proto_pkt_esn_antireplay2048(const void *test_data) 10183 { 10184 return test_ipsec_proto_pkt_esn_antireplay(test_data, 2048); 10185 } 10186 10187 static int 10188 test_ipsec_proto_pkt_esn_antireplay4096(const void *test_data) 10189 { 10190 return test_ipsec_proto_pkt_esn_antireplay(test_data, 4096); 10191 } 10192 10193 static int 10194 test_PDCP_PROTO_all(void) 10195 { 10196 struct crypto_testsuite_params *ts_params = &testsuite_params; 10197 struct crypto_unittest_params *ut_params = &unittest_params; 10198 struct rte_cryptodev_info dev_info; 10199 int status; 10200 10201 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10202 uint64_t feat_flags = dev_info.feature_flags; 10203 10204 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 10205 return TEST_SKIPPED; 10206 10207 /* Set action type */ 10208 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 10209 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 10210 gbl_action_type; 10211 10212 if (security_proto_supported(ut_params->type, 10213 RTE_SECURITY_PROTOCOL_PDCP) < 0) 10214 return TEST_SKIPPED; 10215 10216 status = test_PDCP_PROTO_cplane_encap_all(); 10217 status += test_PDCP_PROTO_cplane_decap_all(); 10218 status += test_PDCP_PROTO_uplane_encap_all(); 10219 status += test_PDCP_PROTO_uplane_decap_all(); 10220 status += test_PDCP_PROTO_SGL_in_place_32B(); 10221 status += test_PDCP_PROTO_SGL_oop_32B_128B(); 10222 status += test_PDCP_PROTO_SGL_oop_32B_40B(); 10223 status += test_PDCP_PROTO_SGL_oop_128B_32B(); 10224 status += test_PDCP_SDAP_PROTO_encap_all(); 10225 status += test_PDCP_SDAP_PROTO_decap_all(); 10226 status += test_PDCP_PROTO_short_mac(); 10227 10228 if (status) 10229 return TEST_FAILED; 10230 else 10231 return TEST_SUCCESS; 10232 } 10233 10234 static int 10235 test_ipsec_proto_ipv4_ttl_decrement(const void *data __rte_unused) 10236 { 10237 struct ipsec_test_flags flags = { 10238 .dec_ttl_or_hop_limit = true 10239 }; 10240 10241 return test_ipsec_proto_all(&flags); 10242 } 10243 10244 static int 10245 test_ipsec_proto_ipv6_hop_limit_decrement(const void *data __rte_unused) 10246 { 10247 struct ipsec_test_flags flags = { 10248 .ipv6 = true, 10249 .dec_ttl_or_hop_limit = true 10250 }; 10251 10252 return test_ipsec_proto_all(&flags); 10253 } 10254 10255 static int 10256 test_docsis_proto_uplink(const void *data) 10257 { 10258 const struct docsis_test_data *d_td = data; 10259 struct crypto_testsuite_params *ts_params = &testsuite_params; 10260 struct crypto_unittest_params *ut_params = &unittest_params; 10261 uint8_t *plaintext = NULL; 10262 uint8_t *ciphertext = NULL; 10263 uint8_t *iv_ptr; 10264 int32_t cipher_len, crc_len; 10265 uint32_t crc_data_len; 10266 int ret = TEST_SUCCESS; 10267 10268 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 10269 rte_cryptodev_get_sec_ctx( 10270 ts_params->valid_devs[0]); 10271 10272 /* Verify the capabilities */ 10273 struct rte_security_capability_idx sec_cap_idx; 10274 const struct rte_security_capability *sec_cap; 10275 const struct rte_cryptodev_capabilities *crypto_cap; 10276 const struct rte_cryptodev_symmetric_capability *sym_cap; 10277 int j = 0; 10278 10279 /* Set action type */ 10280 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 10281 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 10282 gbl_action_type; 10283 10284 if (security_proto_supported(ut_params->type, 10285 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 10286 return TEST_SKIPPED; 10287 10288 sec_cap_idx.action = ut_params->type; 10289 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 10290 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK; 10291 10292 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 10293 if (sec_cap == NULL) 10294 return TEST_SKIPPED; 10295 10296 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 10297 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 10298 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 10299 crypto_cap->sym.xform_type == 10300 RTE_CRYPTO_SYM_XFORM_CIPHER && 10301 crypto_cap->sym.cipher.algo == 10302 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 10303 sym_cap = &crypto_cap->sym; 10304 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 10305 d_td->key.len, 10306 d_td->iv.len) == 0) 10307 break; 10308 } 10309 } 10310 10311 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 10312 return TEST_SKIPPED; 10313 10314 /* Setup source mbuf payload */ 10315 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10316 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10317 rte_pktmbuf_tailroom(ut_params->ibuf)); 10318 10319 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10320 d_td->ciphertext.len); 10321 10322 memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len); 10323 10324 /* Setup cipher session parameters */ 10325 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10326 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 10327 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 10328 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 10329 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 10330 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 10331 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 10332 ut_params->cipher_xform.next = NULL; 10333 10334 /* Setup DOCSIS session parameters */ 10335 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK; 10336 10337 struct rte_security_session_conf sess_conf = { 10338 .action_type = ut_params->type, 10339 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 10340 .docsis = ut_params->docsis_xform, 10341 .crypto_xform = &ut_params->cipher_xform, 10342 }; 10343 10344 /* Create security session */ 10345 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 10346 ts_params->session_mpool, 10347 ts_params->session_priv_mpool); 10348 10349 if (!ut_params->sec_session) { 10350 printf("Test function %s line %u: failed to allocate session\n", 10351 __func__, __LINE__); 10352 ret = TEST_FAILED; 10353 goto on_err; 10354 } 10355 10356 /* Generate crypto op data structure */ 10357 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10358 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10359 if (!ut_params->op) { 10360 printf("Test function %s line %u: failed to allocate symmetric " 10361 "crypto operation\n", __func__, __LINE__); 10362 ret = TEST_FAILED; 10363 goto on_err; 10364 } 10365 10366 /* Setup CRC operation parameters */ 10367 crc_len = d_td->ciphertext.no_crc == false ? 10368 (d_td->ciphertext.len - 10369 d_td->ciphertext.crc_offset - 10370 RTE_ETHER_CRC_LEN) : 10371 0; 10372 crc_len = crc_len > 0 ? crc_len : 0; 10373 crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN; 10374 ut_params->op->sym->auth.data.length = crc_len; 10375 ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset; 10376 10377 /* Setup cipher operation parameters */ 10378 cipher_len = d_td->ciphertext.no_cipher == false ? 10379 (d_td->ciphertext.len - 10380 d_td->ciphertext.cipher_offset) : 10381 0; 10382 cipher_len = cipher_len > 0 ? cipher_len : 0; 10383 ut_params->op->sym->cipher.data.length = cipher_len; 10384 ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset; 10385 10386 /* Setup cipher IV */ 10387 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 10388 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 10389 10390 /* Attach session to operation */ 10391 rte_security_attach_session(ut_params->op, ut_params->sec_session); 10392 10393 /* Set crypto operation mbufs */ 10394 ut_params->op->sym->m_src = ut_params->ibuf; 10395 ut_params->op->sym->m_dst = NULL; 10396 10397 /* Process crypto operation */ 10398 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 10399 NULL) { 10400 printf("Test function %s line %u: failed to process security " 10401 "crypto op\n", __func__, __LINE__); 10402 ret = TEST_FAILED; 10403 goto on_err; 10404 } 10405 10406 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 10407 printf("Test function %s line %u: failed to process crypto op\n", 10408 __func__, __LINE__); 10409 ret = TEST_FAILED; 10410 goto on_err; 10411 } 10412 10413 /* Validate plaintext */ 10414 plaintext = ciphertext; 10415 10416 if (memcmp(plaintext, d_td->plaintext.data, 10417 d_td->plaintext.len - crc_data_len)) { 10418 printf("Test function %s line %u: plaintext not as expected\n", 10419 __func__, __LINE__); 10420 rte_hexdump(stdout, "expected", d_td->plaintext.data, 10421 d_td->plaintext.len); 10422 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len); 10423 ret = TEST_FAILED; 10424 goto on_err; 10425 } 10426 10427 on_err: 10428 rte_crypto_op_free(ut_params->op); 10429 ut_params->op = NULL; 10430 10431 if (ut_params->sec_session) 10432 rte_security_session_destroy(ctx, ut_params->sec_session); 10433 ut_params->sec_session = NULL; 10434 10435 rte_pktmbuf_free(ut_params->ibuf); 10436 ut_params->ibuf = NULL; 10437 10438 return ret; 10439 } 10440 10441 static int 10442 test_docsis_proto_downlink(const void *data) 10443 { 10444 const struct docsis_test_data *d_td = data; 10445 struct crypto_testsuite_params *ts_params = &testsuite_params; 10446 struct crypto_unittest_params *ut_params = &unittest_params; 10447 uint8_t *plaintext = NULL; 10448 uint8_t *ciphertext = NULL; 10449 uint8_t *iv_ptr; 10450 int32_t cipher_len, crc_len; 10451 int ret = TEST_SUCCESS; 10452 10453 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 10454 rte_cryptodev_get_sec_ctx( 10455 ts_params->valid_devs[0]); 10456 10457 /* Verify the capabilities */ 10458 struct rte_security_capability_idx sec_cap_idx; 10459 const struct rte_security_capability *sec_cap; 10460 const struct rte_cryptodev_capabilities *crypto_cap; 10461 const struct rte_cryptodev_symmetric_capability *sym_cap; 10462 int j = 0; 10463 10464 /* Set action type */ 10465 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 10466 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 10467 gbl_action_type; 10468 10469 if (security_proto_supported(ut_params->type, 10470 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 10471 return TEST_SKIPPED; 10472 10473 sec_cap_idx.action = ut_params->type; 10474 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 10475 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 10476 10477 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 10478 if (sec_cap == NULL) 10479 return TEST_SKIPPED; 10480 10481 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 10482 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 10483 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 10484 crypto_cap->sym.xform_type == 10485 RTE_CRYPTO_SYM_XFORM_CIPHER && 10486 crypto_cap->sym.cipher.algo == 10487 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 10488 sym_cap = &crypto_cap->sym; 10489 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 10490 d_td->key.len, 10491 d_td->iv.len) == 0) 10492 break; 10493 } 10494 } 10495 10496 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 10497 return TEST_SKIPPED; 10498 10499 /* Setup source mbuf payload */ 10500 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10501 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10502 rte_pktmbuf_tailroom(ut_params->ibuf)); 10503 10504 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10505 d_td->plaintext.len); 10506 10507 memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len); 10508 10509 /* Setup cipher session parameters */ 10510 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10511 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 10512 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 10513 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 10514 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 10515 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 10516 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 10517 ut_params->cipher_xform.next = NULL; 10518 10519 /* Setup DOCSIS session parameters */ 10520 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 10521 10522 struct rte_security_session_conf sess_conf = { 10523 .action_type = ut_params->type, 10524 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 10525 .docsis = ut_params->docsis_xform, 10526 .crypto_xform = &ut_params->cipher_xform, 10527 }; 10528 10529 /* Create security session */ 10530 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 10531 ts_params->session_mpool, 10532 ts_params->session_priv_mpool); 10533 10534 if (!ut_params->sec_session) { 10535 printf("Test function %s line %u: failed to allocate session\n", 10536 __func__, __LINE__); 10537 ret = TEST_FAILED; 10538 goto on_err; 10539 } 10540 10541 /* Generate crypto op data structure */ 10542 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10543 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10544 if (!ut_params->op) { 10545 printf("Test function %s line %u: failed to allocate symmetric " 10546 "crypto operation\n", __func__, __LINE__); 10547 ret = TEST_FAILED; 10548 goto on_err; 10549 } 10550 10551 /* Setup CRC operation parameters */ 10552 crc_len = d_td->plaintext.no_crc == false ? 10553 (d_td->plaintext.len - 10554 d_td->plaintext.crc_offset - 10555 RTE_ETHER_CRC_LEN) : 10556 0; 10557 crc_len = crc_len > 0 ? crc_len : 0; 10558 ut_params->op->sym->auth.data.length = crc_len; 10559 ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset; 10560 10561 /* Setup cipher operation parameters */ 10562 cipher_len = d_td->plaintext.no_cipher == false ? 10563 (d_td->plaintext.len - 10564 d_td->plaintext.cipher_offset) : 10565 0; 10566 cipher_len = cipher_len > 0 ? cipher_len : 0; 10567 ut_params->op->sym->cipher.data.length = cipher_len; 10568 ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset; 10569 10570 /* Setup cipher IV */ 10571 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 10572 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 10573 10574 /* Attach session to operation */ 10575 rte_security_attach_session(ut_params->op, ut_params->sec_session); 10576 10577 /* Set crypto operation mbufs */ 10578 ut_params->op->sym->m_src = ut_params->ibuf; 10579 ut_params->op->sym->m_dst = NULL; 10580 10581 /* Process crypto operation */ 10582 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 10583 NULL) { 10584 printf("Test function %s line %u: failed to process crypto op\n", 10585 __func__, __LINE__); 10586 ret = TEST_FAILED; 10587 goto on_err; 10588 } 10589 10590 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 10591 printf("Test function %s line %u: crypto op processing failed\n", 10592 __func__, __LINE__); 10593 ret = TEST_FAILED; 10594 goto on_err; 10595 } 10596 10597 /* Validate ciphertext */ 10598 ciphertext = plaintext; 10599 10600 if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) { 10601 printf("Test function %s line %u: plaintext not as expected\n", 10602 __func__, __LINE__); 10603 rte_hexdump(stdout, "expected", d_td->ciphertext.data, 10604 d_td->ciphertext.len); 10605 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len); 10606 ret = TEST_FAILED; 10607 goto on_err; 10608 } 10609 10610 on_err: 10611 rte_crypto_op_free(ut_params->op); 10612 ut_params->op = NULL; 10613 10614 if (ut_params->sec_session) 10615 rte_security_session_destroy(ctx, ut_params->sec_session); 10616 ut_params->sec_session = NULL; 10617 10618 rte_pktmbuf_free(ut_params->ibuf); 10619 ut_params->ibuf = NULL; 10620 10621 return ret; 10622 } 10623 #endif 10624 10625 static int 10626 test_AES_GCM_authenticated_encryption_test_case_1(void) 10627 { 10628 return test_authenticated_encryption(&gcm_test_case_1); 10629 } 10630 10631 static int 10632 test_AES_GCM_authenticated_encryption_test_case_2(void) 10633 { 10634 return test_authenticated_encryption(&gcm_test_case_2); 10635 } 10636 10637 static int 10638 test_AES_GCM_authenticated_encryption_test_case_3(void) 10639 { 10640 return test_authenticated_encryption(&gcm_test_case_3); 10641 } 10642 10643 static int 10644 test_AES_GCM_authenticated_encryption_test_case_4(void) 10645 { 10646 return test_authenticated_encryption(&gcm_test_case_4); 10647 } 10648 10649 static int 10650 test_AES_GCM_authenticated_encryption_test_case_5(void) 10651 { 10652 return test_authenticated_encryption(&gcm_test_case_5); 10653 } 10654 10655 static int 10656 test_AES_GCM_authenticated_encryption_test_case_6(void) 10657 { 10658 return test_authenticated_encryption(&gcm_test_case_6); 10659 } 10660 10661 static int 10662 test_AES_GCM_authenticated_encryption_test_case_7(void) 10663 { 10664 return test_authenticated_encryption(&gcm_test_case_7); 10665 } 10666 10667 static int 10668 test_AES_GCM_authenticated_encryption_test_case_8(void) 10669 { 10670 return test_authenticated_encryption(&gcm_test_case_8); 10671 } 10672 10673 static int 10674 test_AES_GCM_J0_authenticated_encryption_test_case_1(void) 10675 { 10676 return test_authenticated_encryption(&gcm_J0_test_case_1); 10677 } 10678 10679 static int 10680 test_AES_GCM_auth_encryption_test_case_192_1(void) 10681 { 10682 return test_authenticated_encryption(&gcm_test_case_192_1); 10683 } 10684 10685 static int 10686 test_AES_GCM_auth_encryption_test_case_192_2(void) 10687 { 10688 return test_authenticated_encryption(&gcm_test_case_192_2); 10689 } 10690 10691 static int 10692 test_AES_GCM_auth_encryption_test_case_192_3(void) 10693 { 10694 return test_authenticated_encryption(&gcm_test_case_192_3); 10695 } 10696 10697 static int 10698 test_AES_GCM_auth_encryption_test_case_192_4(void) 10699 { 10700 return test_authenticated_encryption(&gcm_test_case_192_4); 10701 } 10702 10703 static int 10704 test_AES_GCM_auth_encryption_test_case_192_5(void) 10705 { 10706 return test_authenticated_encryption(&gcm_test_case_192_5); 10707 } 10708 10709 static int 10710 test_AES_GCM_auth_encryption_test_case_192_6(void) 10711 { 10712 return test_authenticated_encryption(&gcm_test_case_192_6); 10713 } 10714 10715 static int 10716 test_AES_GCM_auth_encryption_test_case_192_7(void) 10717 { 10718 return test_authenticated_encryption(&gcm_test_case_192_7); 10719 } 10720 10721 static int 10722 test_AES_GCM_auth_encryption_test_case_256_1(void) 10723 { 10724 return test_authenticated_encryption(&gcm_test_case_256_1); 10725 } 10726 10727 static int 10728 test_AES_GCM_auth_encryption_test_case_256_2(void) 10729 { 10730 return test_authenticated_encryption(&gcm_test_case_256_2); 10731 } 10732 10733 static int 10734 test_AES_GCM_auth_encryption_test_case_256_3(void) 10735 { 10736 return test_authenticated_encryption(&gcm_test_case_256_3); 10737 } 10738 10739 static int 10740 test_AES_GCM_auth_encryption_test_case_256_4(void) 10741 { 10742 return test_authenticated_encryption(&gcm_test_case_256_4); 10743 } 10744 10745 static int 10746 test_AES_GCM_auth_encryption_test_case_256_5(void) 10747 { 10748 return test_authenticated_encryption(&gcm_test_case_256_5); 10749 } 10750 10751 static int 10752 test_AES_GCM_auth_encryption_test_case_256_6(void) 10753 { 10754 return test_authenticated_encryption(&gcm_test_case_256_6); 10755 } 10756 10757 static int 10758 test_AES_GCM_auth_encryption_test_case_256_7(void) 10759 { 10760 return test_authenticated_encryption(&gcm_test_case_256_7); 10761 } 10762 10763 static int 10764 test_AES_GCM_auth_encryption_test_case_aad_1(void) 10765 { 10766 return test_authenticated_encryption(&gcm_test_case_aad_1); 10767 } 10768 10769 static int 10770 test_AES_GCM_auth_encryption_test_case_aad_2(void) 10771 { 10772 return test_authenticated_encryption(&gcm_test_case_aad_2); 10773 } 10774 10775 static int 10776 test_AES_GCM_auth_encryption_fail_iv_corrupt(void) 10777 { 10778 struct aead_test_data tdata; 10779 int res; 10780 10781 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10782 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10783 tdata.iv.data[0] += 1; 10784 res = test_authenticated_encryption(&tdata); 10785 if (res == TEST_SKIPPED) 10786 return res; 10787 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10788 return TEST_SUCCESS; 10789 } 10790 10791 static int 10792 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void) 10793 { 10794 struct aead_test_data tdata; 10795 int res; 10796 10797 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10798 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10799 tdata.plaintext.data[0] += 1; 10800 res = test_authenticated_encryption(&tdata); 10801 if (res == TEST_SKIPPED) 10802 return res; 10803 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10804 return TEST_SUCCESS; 10805 } 10806 10807 static int 10808 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void) 10809 { 10810 struct aead_test_data tdata; 10811 int res; 10812 10813 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10814 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10815 tdata.ciphertext.data[0] += 1; 10816 res = test_authenticated_encryption(&tdata); 10817 if (res == TEST_SKIPPED) 10818 return res; 10819 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10820 return TEST_SUCCESS; 10821 } 10822 10823 static int 10824 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void) 10825 { 10826 struct aead_test_data tdata; 10827 int res; 10828 10829 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10830 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10831 tdata.aad.len += 1; 10832 res = test_authenticated_encryption(&tdata); 10833 if (res == TEST_SKIPPED) 10834 return res; 10835 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10836 return TEST_SUCCESS; 10837 } 10838 10839 static int 10840 test_AES_GCM_auth_encryption_fail_aad_corrupt(void) 10841 { 10842 struct aead_test_data tdata; 10843 uint8_t aad[gcm_test_case_7.aad.len]; 10844 int res; 10845 10846 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10847 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10848 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 10849 aad[0] += 1; 10850 tdata.aad.data = aad; 10851 res = test_authenticated_encryption(&tdata); 10852 if (res == TEST_SKIPPED) 10853 return res; 10854 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10855 return TEST_SUCCESS; 10856 } 10857 10858 static int 10859 test_AES_GCM_auth_encryption_fail_tag_corrupt(void) 10860 { 10861 struct aead_test_data tdata; 10862 int res; 10863 10864 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 10865 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 10866 tdata.auth_tag.data[0] += 1; 10867 res = test_authenticated_encryption(&tdata); 10868 if (res == TEST_SKIPPED) 10869 return res; 10870 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 10871 return TEST_SUCCESS; 10872 } 10873 10874 static int 10875 test_authenticated_decryption(const struct aead_test_data *tdata) 10876 { 10877 struct crypto_testsuite_params *ts_params = &testsuite_params; 10878 struct crypto_unittest_params *ut_params = &unittest_params; 10879 10880 int retval; 10881 uint8_t *plaintext; 10882 uint32_t i; 10883 struct rte_cryptodev_info dev_info; 10884 10885 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10886 uint64_t feat_flags = dev_info.feature_flags; 10887 10888 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10889 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10890 printf("Device doesn't support RAW data-path APIs.\n"); 10891 return TEST_SKIPPED; 10892 } 10893 10894 /* Verify the capabilities */ 10895 struct rte_cryptodev_sym_capability_idx cap_idx; 10896 const struct rte_cryptodev_symmetric_capability *capability; 10897 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 10898 cap_idx.algo.aead = tdata->algo; 10899 capability = rte_cryptodev_sym_capability_get( 10900 ts_params->valid_devs[0], &cap_idx); 10901 if (capability == NULL) 10902 return TEST_SKIPPED; 10903 if (rte_cryptodev_sym_capability_check_aead( 10904 capability, tdata->key.len, tdata->auth_tag.len, 10905 tdata->aad.len, tdata->iv.len)) 10906 return TEST_SKIPPED; 10907 10908 /* Create AEAD session */ 10909 retval = create_aead_session(ts_params->valid_devs[0], 10910 tdata->algo, 10911 RTE_CRYPTO_AEAD_OP_DECRYPT, 10912 tdata->key.data, tdata->key.len, 10913 tdata->aad.len, tdata->auth_tag.len, 10914 tdata->iv.len); 10915 if (retval < 0) 10916 return retval; 10917 10918 /* alloc mbuf and set payload */ 10919 if (tdata->aad.len > MBUF_SIZE) { 10920 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 10921 /* Populate full size of add data */ 10922 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 10923 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 10924 } else 10925 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10926 10927 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10928 rte_pktmbuf_tailroom(ut_params->ibuf)); 10929 10930 /* Create AEAD operation */ 10931 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 10932 if (retval < 0) 10933 return retval; 10934 10935 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10936 10937 ut_params->op->sym->m_src = ut_params->ibuf; 10938 10939 /* Process crypto operation */ 10940 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10941 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 10942 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10943 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10944 ut_params->op, 0, 0, 0, 0); 10945 else 10946 TEST_ASSERT_NOT_NULL( 10947 process_crypto_request(ts_params->valid_devs[0], 10948 ut_params->op), "failed to process sym crypto op"); 10949 10950 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10951 "crypto op processing failed"); 10952 10953 if (ut_params->op->sym->m_dst) 10954 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 10955 uint8_t *); 10956 else 10957 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 10958 uint8_t *, 10959 ut_params->op->sym->cipher.data.offset); 10960 10961 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 10962 10963 /* Validate obuf */ 10964 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10965 plaintext, 10966 tdata->plaintext.data, 10967 tdata->plaintext.len, 10968 "Plaintext data not as expected"); 10969 10970 TEST_ASSERT_EQUAL(ut_params->op->status, 10971 RTE_CRYPTO_OP_STATUS_SUCCESS, 10972 "Authentication failed"); 10973 10974 return 0; 10975 } 10976 10977 static int 10978 test_AES_GCM_authenticated_decryption_test_case_1(void) 10979 { 10980 return test_authenticated_decryption(&gcm_test_case_1); 10981 } 10982 10983 static int 10984 test_AES_GCM_authenticated_decryption_test_case_2(void) 10985 { 10986 return test_authenticated_decryption(&gcm_test_case_2); 10987 } 10988 10989 static int 10990 test_AES_GCM_authenticated_decryption_test_case_3(void) 10991 { 10992 return test_authenticated_decryption(&gcm_test_case_3); 10993 } 10994 10995 static int 10996 test_AES_GCM_authenticated_decryption_test_case_4(void) 10997 { 10998 return test_authenticated_decryption(&gcm_test_case_4); 10999 } 11000 11001 static int 11002 test_AES_GCM_authenticated_decryption_test_case_5(void) 11003 { 11004 return test_authenticated_decryption(&gcm_test_case_5); 11005 } 11006 11007 static int 11008 test_AES_GCM_authenticated_decryption_test_case_6(void) 11009 { 11010 return test_authenticated_decryption(&gcm_test_case_6); 11011 } 11012 11013 static int 11014 test_AES_GCM_authenticated_decryption_test_case_7(void) 11015 { 11016 return test_authenticated_decryption(&gcm_test_case_7); 11017 } 11018 11019 static int 11020 test_AES_GCM_authenticated_decryption_test_case_8(void) 11021 { 11022 return test_authenticated_decryption(&gcm_test_case_8); 11023 } 11024 11025 static int 11026 test_AES_GCM_J0_authenticated_decryption_test_case_1(void) 11027 { 11028 return test_authenticated_decryption(&gcm_J0_test_case_1); 11029 } 11030 11031 static int 11032 test_AES_GCM_auth_decryption_test_case_192_1(void) 11033 { 11034 return test_authenticated_decryption(&gcm_test_case_192_1); 11035 } 11036 11037 static int 11038 test_AES_GCM_auth_decryption_test_case_192_2(void) 11039 { 11040 return test_authenticated_decryption(&gcm_test_case_192_2); 11041 } 11042 11043 static int 11044 test_AES_GCM_auth_decryption_test_case_192_3(void) 11045 { 11046 return test_authenticated_decryption(&gcm_test_case_192_3); 11047 } 11048 11049 static int 11050 test_AES_GCM_auth_decryption_test_case_192_4(void) 11051 { 11052 return test_authenticated_decryption(&gcm_test_case_192_4); 11053 } 11054 11055 static int 11056 test_AES_GCM_auth_decryption_test_case_192_5(void) 11057 { 11058 return test_authenticated_decryption(&gcm_test_case_192_5); 11059 } 11060 11061 static int 11062 test_AES_GCM_auth_decryption_test_case_192_6(void) 11063 { 11064 return test_authenticated_decryption(&gcm_test_case_192_6); 11065 } 11066 11067 static int 11068 test_AES_GCM_auth_decryption_test_case_192_7(void) 11069 { 11070 return test_authenticated_decryption(&gcm_test_case_192_7); 11071 } 11072 11073 static int 11074 test_AES_GCM_auth_decryption_test_case_256_1(void) 11075 { 11076 return test_authenticated_decryption(&gcm_test_case_256_1); 11077 } 11078 11079 static int 11080 test_AES_GCM_auth_decryption_test_case_256_2(void) 11081 { 11082 return test_authenticated_decryption(&gcm_test_case_256_2); 11083 } 11084 11085 static int 11086 test_AES_GCM_auth_decryption_test_case_256_3(void) 11087 { 11088 return test_authenticated_decryption(&gcm_test_case_256_3); 11089 } 11090 11091 static int 11092 test_AES_GCM_auth_decryption_test_case_256_4(void) 11093 { 11094 return test_authenticated_decryption(&gcm_test_case_256_4); 11095 } 11096 11097 static int 11098 test_AES_GCM_auth_decryption_test_case_256_5(void) 11099 { 11100 return test_authenticated_decryption(&gcm_test_case_256_5); 11101 } 11102 11103 static int 11104 test_AES_GCM_auth_decryption_test_case_256_6(void) 11105 { 11106 return test_authenticated_decryption(&gcm_test_case_256_6); 11107 } 11108 11109 static int 11110 test_AES_GCM_auth_decryption_test_case_256_7(void) 11111 { 11112 return test_authenticated_decryption(&gcm_test_case_256_7); 11113 } 11114 11115 static int 11116 test_AES_GCM_auth_decryption_test_case_aad_1(void) 11117 { 11118 return test_authenticated_decryption(&gcm_test_case_aad_1); 11119 } 11120 11121 static int 11122 test_AES_GCM_auth_decryption_test_case_aad_2(void) 11123 { 11124 return test_authenticated_decryption(&gcm_test_case_aad_2); 11125 } 11126 11127 static int 11128 test_AES_GCM_auth_decryption_fail_iv_corrupt(void) 11129 { 11130 struct aead_test_data tdata; 11131 int res; 11132 11133 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11134 tdata.iv.data[0] += 1; 11135 res = test_authenticated_decryption(&tdata); 11136 if (res == TEST_SKIPPED) 11137 return res; 11138 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11139 return TEST_SUCCESS; 11140 } 11141 11142 static int 11143 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void) 11144 { 11145 struct aead_test_data tdata; 11146 int res; 11147 11148 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11149 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11150 tdata.plaintext.data[0] += 1; 11151 res = test_authenticated_decryption(&tdata); 11152 if (res == TEST_SKIPPED) 11153 return res; 11154 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11155 return TEST_SUCCESS; 11156 } 11157 11158 static int 11159 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void) 11160 { 11161 struct aead_test_data tdata; 11162 int res; 11163 11164 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11165 tdata.ciphertext.data[0] += 1; 11166 res = test_authenticated_decryption(&tdata); 11167 if (res == TEST_SKIPPED) 11168 return res; 11169 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11170 return TEST_SUCCESS; 11171 } 11172 11173 static int 11174 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void) 11175 { 11176 struct aead_test_data tdata; 11177 int res; 11178 11179 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11180 tdata.aad.len += 1; 11181 res = test_authenticated_decryption(&tdata); 11182 if (res == TEST_SKIPPED) 11183 return res; 11184 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11185 return TEST_SUCCESS; 11186 } 11187 11188 static int 11189 test_AES_GCM_auth_decryption_fail_aad_corrupt(void) 11190 { 11191 struct aead_test_data tdata; 11192 uint8_t aad[gcm_test_case_7.aad.len]; 11193 int res; 11194 11195 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11196 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 11197 aad[0] += 1; 11198 tdata.aad.data = aad; 11199 res = test_authenticated_decryption(&tdata); 11200 if (res == TEST_SKIPPED) 11201 return res; 11202 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 11203 return TEST_SUCCESS; 11204 } 11205 11206 static int 11207 test_AES_GCM_auth_decryption_fail_tag_corrupt(void) 11208 { 11209 struct aead_test_data tdata; 11210 int res; 11211 11212 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11213 tdata.auth_tag.data[0] += 1; 11214 res = test_authenticated_decryption(&tdata); 11215 if (res == TEST_SKIPPED) 11216 return res; 11217 TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed"); 11218 return TEST_SUCCESS; 11219 } 11220 11221 static int 11222 test_authenticated_encryption_oop(const struct aead_test_data *tdata) 11223 { 11224 struct crypto_testsuite_params *ts_params = &testsuite_params; 11225 struct crypto_unittest_params *ut_params = &unittest_params; 11226 11227 int retval; 11228 uint8_t *ciphertext, *auth_tag; 11229 uint16_t plaintext_pad_len; 11230 struct rte_cryptodev_info dev_info; 11231 11232 /* Verify the capabilities */ 11233 struct rte_cryptodev_sym_capability_idx cap_idx; 11234 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11235 cap_idx.algo.aead = tdata->algo; 11236 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11237 &cap_idx) == NULL) 11238 return TEST_SKIPPED; 11239 11240 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11241 uint64_t feat_flags = dev_info.feature_flags; 11242 11243 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11244 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) 11245 return TEST_SKIPPED; 11246 11247 /* not supported with CPU crypto */ 11248 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11249 return TEST_SKIPPED; 11250 11251 /* Create AEAD session */ 11252 retval = create_aead_session(ts_params->valid_devs[0], 11253 tdata->algo, 11254 RTE_CRYPTO_AEAD_OP_ENCRYPT, 11255 tdata->key.data, tdata->key.len, 11256 tdata->aad.len, tdata->auth_tag.len, 11257 tdata->iv.len); 11258 if (retval < 0) 11259 return retval; 11260 11261 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11262 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11263 11264 /* clear mbuf payload */ 11265 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11266 rte_pktmbuf_tailroom(ut_params->ibuf)); 11267 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 11268 rte_pktmbuf_tailroom(ut_params->obuf)); 11269 11270 /* Create AEAD operation */ 11271 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 11272 if (retval < 0) 11273 return retval; 11274 11275 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11276 11277 ut_params->op->sym->m_src = ut_params->ibuf; 11278 ut_params->op->sym->m_dst = ut_params->obuf; 11279 11280 /* Process crypto operation */ 11281 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11282 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11283 ut_params->op, 0, 0, 0, 0); 11284 else 11285 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 11286 ut_params->op), "failed to process sym crypto op"); 11287 11288 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11289 "crypto op processing failed"); 11290 11291 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 11292 11293 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 11294 ut_params->op->sym->cipher.data.offset); 11295 auth_tag = ciphertext + plaintext_pad_len; 11296 11297 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 11298 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 11299 11300 /* Validate obuf */ 11301 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11302 ciphertext, 11303 tdata->ciphertext.data, 11304 tdata->ciphertext.len, 11305 "Ciphertext data not as expected"); 11306 11307 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11308 auth_tag, 11309 tdata->auth_tag.data, 11310 tdata->auth_tag.len, 11311 "Generated auth tag not as expected"); 11312 11313 return 0; 11314 11315 } 11316 11317 static int 11318 test_AES_GCM_authenticated_encryption_oop_test_case_1(void) 11319 { 11320 return test_authenticated_encryption_oop(&gcm_test_case_5); 11321 } 11322 11323 static int 11324 test_authenticated_decryption_oop(const struct aead_test_data *tdata) 11325 { 11326 struct crypto_testsuite_params *ts_params = &testsuite_params; 11327 struct crypto_unittest_params *ut_params = &unittest_params; 11328 11329 int retval; 11330 uint8_t *plaintext; 11331 struct rte_cryptodev_info dev_info; 11332 11333 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11334 uint64_t feat_flags = dev_info.feature_flags; 11335 11336 /* Verify the capabilities */ 11337 struct rte_cryptodev_sym_capability_idx cap_idx; 11338 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11339 cap_idx.algo.aead = tdata->algo; 11340 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11341 &cap_idx) == NULL) 11342 return TEST_SKIPPED; 11343 11344 /* not supported with CPU crypto and raw data-path APIs*/ 11345 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO || 11346 global_api_test_type == CRYPTODEV_RAW_API_TEST) 11347 return TEST_SKIPPED; 11348 11349 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11350 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11351 printf("Device does not support RAW data-path APIs.\n"); 11352 return TEST_SKIPPED; 11353 } 11354 11355 /* Create AEAD session */ 11356 retval = create_aead_session(ts_params->valid_devs[0], 11357 tdata->algo, 11358 RTE_CRYPTO_AEAD_OP_DECRYPT, 11359 tdata->key.data, tdata->key.len, 11360 tdata->aad.len, tdata->auth_tag.len, 11361 tdata->iv.len); 11362 if (retval < 0) 11363 return retval; 11364 11365 /* alloc mbuf and set payload */ 11366 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11367 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11368 11369 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11370 rte_pktmbuf_tailroom(ut_params->ibuf)); 11371 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 11372 rte_pktmbuf_tailroom(ut_params->obuf)); 11373 11374 /* Create AEAD operation */ 11375 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 11376 if (retval < 0) 11377 return retval; 11378 11379 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11380 11381 ut_params->op->sym->m_src = ut_params->ibuf; 11382 ut_params->op->sym->m_dst = ut_params->obuf; 11383 11384 /* Process crypto operation */ 11385 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11386 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11387 ut_params->op, 0, 0, 0, 0); 11388 else 11389 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 11390 ut_params->op), "failed to process sym crypto op"); 11391 11392 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11393 "crypto op processing failed"); 11394 11395 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 11396 ut_params->op->sym->cipher.data.offset); 11397 11398 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 11399 11400 /* Validate obuf */ 11401 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11402 plaintext, 11403 tdata->plaintext.data, 11404 tdata->plaintext.len, 11405 "Plaintext data not as expected"); 11406 11407 TEST_ASSERT_EQUAL(ut_params->op->status, 11408 RTE_CRYPTO_OP_STATUS_SUCCESS, 11409 "Authentication failed"); 11410 return 0; 11411 } 11412 11413 static int 11414 test_AES_GCM_authenticated_decryption_oop_test_case_1(void) 11415 { 11416 return test_authenticated_decryption_oop(&gcm_test_case_5); 11417 } 11418 11419 static int 11420 test_authenticated_encryption_sessionless( 11421 const struct aead_test_data *tdata) 11422 { 11423 struct crypto_testsuite_params *ts_params = &testsuite_params; 11424 struct crypto_unittest_params *ut_params = &unittest_params; 11425 11426 int retval; 11427 uint8_t *ciphertext, *auth_tag; 11428 uint16_t plaintext_pad_len; 11429 uint8_t key[tdata->key.len + 1]; 11430 struct rte_cryptodev_info dev_info; 11431 11432 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11433 uint64_t feat_flags = dev_info.feature_flags; 11434 11435 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 11436 printf("Device doesn't support Sessionless ops.\n"); 11437 return TEST_SKIPPED; 11438 } 11439 11440 /* not supported with CPU crypto */ 11441 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11442 return TEST_SKIPPED; 11443 11444 /* Verify the capabilities */ 11445 struct rte_cryptodev_sym_capability_idx cap_idx; 11446 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11447 cap_idx.algo.aead = tdata->algo; 11448 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11449 &cap_idx) == NULL) 11450 return TEST_SKIPPED; 11451 11452 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11453 11454 /* clear mbuf payload */ 11455 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11456 rte_pktmbuf_tailroom(ut_params->ibuf)); 11457 11458 /* Create AEAD operation */ 11459 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 11460 if (retval < 0) 11461 return retval; 11462 11463 /* Create GCM xform */ 11464 memcpy(key, tdata->key.data, tdata->key.len); 11465 retval = create_aead_xform(ut_params->op, 11466 tdata->algo, 11467 RTE_CRYPTO_AEAD_OP_ENCRYPT, 11468 key, tdata->key.len, 11469 tdata->aad.len, tdata->auth_tag.len, 11470 tdata->iv.len); 11471 if (retval < 0) 11472 return retval; 11473 11474 ut_params->op->sym->m_src = ut_params->ibuf; 11475 11476 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 11477 RTE_CRYPTO_OP_SESSIONLESS, 11478 "crypto op session type not sessionless"); 11479 11480 /* Process crypto operation */ 11481 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 11482 ut_params->op), "failed to process sym crypto op"); 11483 11484 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 11485 11486 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11487 "crypto op status not success"); 11488 11489 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 11490 11491 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 11492 ut_params->op->sym->cipher.data.offset); 11493 auth_tag = ciphertext + plaintext_pad_len; 11494 11495 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 11496 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 11497 11498 /* Validate obuf */ 11499 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11500 ciphertext, 11501 tdata->ciphertext.data, 11502 tdata->ciphertext.len, 11503 "Ciphertext data not as expected"); 11504 11505 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11506 auth_tag, 11507 tdata->auth_tag.data, 11508 tdata->auth_tag.len, 11509 "Generated auth tag not as expected"); 11510 11511 return 0; 11512 11513 } 11514 11515 static int 11516 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void) 11517 { 11518 return test_authenticated_encryption_sessionless( 11519 &gcm_test_case_5); 11520 } 11521 11522 static int 11523 test_authenticated_decryption_sessionless( 11524 const struct aead_test_data *tdata) 11525 { 11526 struct crypto_testsuite_params *ts_params = &testsuite_params; 11527 struct crypto_unittest_params *ut_params = &unittest_params; 11528 11529 int retval; 11530 uint8_t *plaintext; 11531 uint8_t key[tdata->key.len + 1]; 11532 struct rte_cryptodev_info dev_info; 11533 11534 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11535 uint64_t feat_flags = dev_info.feature_flags; 11536 11537 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 11538 printf("Device doesn't support Sessionless ops.\n"); 11539 return TEST_SKIPPED; 11540 } 11541 11542 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11543 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11544 printf("Device doesn't support RAW data-path APIs.\n"); 11545 return TEST_SKIPPED; 11546 } 11547 11548 /* not supported with CPU crypto */ 11549 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11550 return TEST_SKIPPED; 11551 11552 /* Verify the capabilities */ 11553 struct rte_cryptodev_sym_capability_idx cap_idx; 11554 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11555 cap_idx.algo.aead = tdata->algo; 11556 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11557 &cap_idx) == NULL) 11558 return TEST_SKIPPED; 11559 11560 /* alloc mbuf and set payload */ 11561 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11562 11563 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11564 rte_pktmbuf_tailroom(ut_params->ibuf)); 11565 11566 /* Create AEAD operation */ 11567 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 11568 if (retval < 0) 11569 return retval; 11570 11571 /* Create AEAD xform */ 11572 memcpy(key, tdata->key.data, tdata->key.len); 11573 retval = create_aead_xform(ut_params->op, 11574 tdata->algo, 11575 RTE_CRYPTO_AEAD_OP_DECRYPT, 11576 key, tdata->key.len, 11577 tdata->aad.len, tdata->auth_tag.len, 11578 tdata->iv.len); 11579 if (retval < 0) 11580 return retval; 11581 11582 ut_params->op->sym->m_src = ut_params->ibuf; 11583 11584 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 11585 RTE_CRYPTO_OP_SESSIONLESS, 11586 "crypto op session type not sessionless"); 11587 11588 /* Process crypto operation */ 11589 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11590 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11591 ut_params->op, 0, 0, 0, 0); 11592 else 11593 TEST_ASSERT_NOT_NULL(process_crypto_request( 11594 ts_params->valid_devs[0], ut_params->op), 11595 "failed to process sym crypto op"); 11596 11597 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 11598 11599 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11600 "crypto op status not success"); 11601 11602 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 11603 ut_params->op->sym->cipher.data.offset); 11604 11605 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 11606 11607 /* Validate obuf */ 11608 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11609 plaintext, 11610 tdata->plaintext.data, 11611 tdata->plaintext.len, 11612 "Plaintext data not as expected"); 11613 11614 TEST_ASSERT_EQUAL(ut_params->op->status, 11615 RTE_CRYPTO_OP_STATUS_SUCCESS, 11616 "Authentication failed"); 11617 return 0; 11618 } 11619 11620 static int 11621 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void) 11622 { 11623 return test_authenticated_decryption_sessionless( 11624 &gcm_test_case_5); 11625 } 11626 11627 static int 11628 test_AES_CCM_authenticated_encryption_test_case_128_1(void) 11629 { 11630 return test_authenticated_encryption(&ccm_test_case_128_1); 11631 } 11632 11633 static int 11634 test_AES_CCM_authenticated_encryption_test_case_128_2(void) 11635 { 11636 return test_authenticated_encryption(&ccm_test_case_128_2); 11637 } 11638 11639 static int 11640 test_AES_CCM_authenticated_encryption_test_case_128_3(void) 11641 { 11642 return test_authenticated_encryption(&ccm_test_case_128_3); 11643 } 11644 11645 static int 11646 test_AES_CCM_authenticated_decryption_test_case_128_1(void) 11647 { 11648 return test_authenticated_decryption(&ccm_test_case_128_1); 11649 } 11650 11651 static int 11652 test_AES_CCM_authenticated_decryption_test_case_128_2(void) 11653 { 11654 return test_authenticated_decryption(&ccm_test_case_128_2); 11655 } 11656 11657 static int 11658 test_AES_CCM_authenticated_decryption_test_case_128_3(void) 11659 { 11660 return test_authenticated_decryption(&ccm_test_case_128_3); 11661 } 11662 11663 static int 11664 test_AES_CCM_authenticated_encryption_test_case_192_1(void) 11665 { 11666 return test_authenticated_encryption(&ccm_test_case_192_1); 11667 } 11668 11669 static int 11670 test_AES_CCM_authenticated_encryption_test_case_192_2(void) 11671 { 11672 return test_authenticated_encryption(&ccm_test_case_192_2); 11673 } 11674 11675 static int 11676 test_AES_CCM_authenticated_encryption_test_case_192_3(void) 11677 { 11678 return test_authenticated_encryption(&ccm_test_case_192_3); 11679 } 11680 11681 static int 11682 test_AES_CCM_authenticated_decryption_test_case_192_1(void) 11683 { 11684 return test_authenticated_decryption(&ccm_test_case_192_1); 11685 } 11686 11687 static int 11688 test_AES_CCM_authenticated_decryption_test_case_192_2(void) 11689 { 11690 return test_authenticated_decryption(&ccm_test_case_192_2); 11691 } 11692 11693 static int 11694 test_AES_CCM_authenticated_decryption_test_case_192_3(void) 11695 { 11696 return test_authenticated_decryption(&ccm_test_case_192_3); 11697 } 11698 11699 static int 11700 test_AES_CCM_authenticated_encryption_test_case_256_1(void) 11701 { 11702 return test_authenticated_encryption(&ccm_test_case_256_1); 11703 } 11704 11705 static int 11706 test_AES_CCM_authenticated_encryption_test_case_256_2(void) 11707 { 11708 return test_authenticated_encryption(&ccm_test_case_256_2); 11709 } 11710 11711 static int 11712 test_AES_CCM_authenticated_encryption_test_case_256_3(void) 11713 { 11714 return test_authenticated_encryption(&ccm_test_case_256_3); 11715 } 11716 11717 static int 11718 test_AES_CCM_authenticated_decryption_test_case_256_1(void) 11719 { 11720 return test_authenticated_decryption(&ccm_test_case_256_1); 11721 } 11722 11723 static int 11724 test_AES_CCM_authenticated_decryption_test_case_256_2(void) 11725 { 11726 return test_authenticated_decryption(&ccm_test_case_256_2); 11727 } 11728 11729 static int 11730 test_AES_CCM_authenticated_decryption_test_case_256_3(void) 11731 { 11732 return test_authenticated_decryption(&ccm_test_case_256_3); 11733 } 11734 11735 static int 11736 test_stats(void) 11737 { 11738 struct crypto_testsuite_params *ts_params = &testsuite_params; 11739 struct rte_cryptodev_stats stats; 11740 11741 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11742 return TEST_SKIPPED; 11743 11744 /* Verify the capabilities */ 11745 struct rte_cryptodev_sym_capability_idx cap_idx; 11746 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11747 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 11748 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11749 &cap_idx) == NULL) 11750 return TEST_SKIPPED; 11751 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11752 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 11753 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11754 &cap_idx) == NULL) 11755 return TEST_SKIPPED; 11756 11757 if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 11758 == -ENOTSUP) 11759 return TEST_SKIPPED; 11760 11761 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 11762 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 11763 &stats) == -ENODEV), 11764 "rte_cryptodev_stats_get invalid dev failed"); 11765 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 11766 "rte_cryptodev_stats_get invalid Param failed"); 11767 11768 /* Test expected values */ 11769 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 11770 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11771 &stats), 11772 "rte_cryptodev_stats_get failed"); 11773 TEST_ASSERT((stats.enqueued_count == 1), 11774 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11775 TEST_ASSERT((stats.dequeued_count == 1), 11776 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11777 TEST_ASSERT((stats.enqueue_err_count == 0), 11778 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11779 TEST_ASSERT((stats.dequeue_err_count == 0), 11780 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11781 11782 /* invalid device but should ignore and not reset device stats*/ 11783 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 11784 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11785 &stats), 11786 "rte_cryptodev_stats_get failed"); 11787 TEST_ASSERT((stats.enqueued_count == 1), 11788 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11789 11790 /* check that a valid reset clears stats */ 11791 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 11792 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 11793 &stats), 11794 "rte_cryptodev_stats_get failed"); 11795 TEST_ASSERT((stats.enqueued_count == 0), 11796 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11797 TEST_ASSERT((stats.dequeued_count == 0), 11798 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 11799 11800 return TEST_SUCCESS; 11801 } 11802 11803 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 11804 struct crypto_unittest_params *ut_params, 11805 enum rte_crypto_auth_operation op, 11806 const struct HMAC_MD5_vector *test_case) 11807 { 11808 uint8_t key[64]; 11809 int status; 11810 11811 memcpy(key, test_case->key.data, test_case->key.len); 11812 11813 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11814 ut_params->auth_xform.next = NULL; 11815 ut_params->auth_xform.auth.op = op; 11816 11817 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 11818 11819 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 11820 ut_params->auth_xform.auth.key.length = test_case->key.len; 11821 ut_params->auth_xform.auth.key.data = key; 11822 11823 ut_params->sess = rte_cryptodev_sym_session_create( 11824 ts_params->session_mpool); 11825 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11826 if (ut_params->sess == NULL) 11827 return TEST_FAILED; 11828 11829 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11830 ut_params->sess, &ut_params->auth_xform, 11831 ts_params->session_priv_mpool); 11832 if (status == -ENOTSUP) 11833 return TEST_SKIPPED; 11834 11835 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11836 11837 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11838 rte_pktmbuf_tailroom(ut_params->ibuf)); 11839 11840 return 0; 11841 } 11842 11843 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 11844 const struct HMAC_MD5_vector *test_case, 11845 uint8_t **plaintext) 11846 { 11847 uint16_t plaintext_pad_len; 11848 11849 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 11850 11851 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 11852 16); 11853 11854 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11855 plaintext_pad_len); 11856 memcpy(*plaintext, test_case->plaintext.data, 11857 test_case->plaintext.len); 11858 11859 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11860 ut_params->ibuf, MD5_DIGEST_LEN); 11861 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11862 "no room to append digest"); 11863 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11864 ut_params->ibuf, plaintext_pad_len); 11865 11866 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 11867 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 11868 test_case->auth_tag.len); 11869 } 11870 11871 sym_op->auth.data.offset = 0; 11872 sym_op->auth.data.length = test_case->plaintext.len; 11873 11874 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11875 ut_params->op->sym->m_src = ut_params->ibuf; 11876 11877 return 0; 11878 } 11879 11880 static int 11881 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 11882 { 11883 uint16_t plaintext_pad_len; 11884 uint8_t *plaintext, *auth_tag; 11885 11886 struct crypto_testsuite_params *ts_params = &testsuite_params; 11887 struct crypto_unittest_params *ut_params = &unittest_params; 11888 struct rte_cryptodev_info dev_info; 11889 11890 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11891 uint64_t feat_flags = dev_info.feature_flags; 11892 11893 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11894 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11895 printf("Device doesn't support RAW data-path APIs.\n"); 11896 return TEST_SKIPPED; 11897 } 11898 11899 /* Verify the capabilities */ 11900 struct rte_cryptodev_sym_capability_idx cap_idx; 11901 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11902 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 11903 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11904 &cap_idx) == NULL) 11905 return TEST_SKIPPED; 11906 11907 if (MD5_HMAC_create_session(ts_params, ut_params, 11908 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 11909 return TEST_FAILED; 11910 11911 /* Generate Crypto op data structure */ 11912 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11913 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11914 TEST_ASSERT_NOT_NULL(ut_params->op, 11915 "Failed to allocate symmetric crypto operation struct"); 11916 11917 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 11918 16); 11919 11920 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 11921 return TEST_FAILED; 11922 11923 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11924 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11925 ut_params->op); 11926 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11927 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11928 ut_params->op, 0, 1, 0, 0); 11929 else 11930 TEST_ASSERT_NOT_NULL( 11931 process_crypto_request(ts_params->valid_devs[0], 11932 ut_params->op), 11933 "failed to process sym crypto op"); 11934 11935 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11936 "crypto op processing failed"); 11937 11938 if (ut_params->op->sym->m_dst) { 11939 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 11940 uint8_t *, plaintext_pad_len); 11941 } else { 11942 auth_tag = plaintext + plaintext_pad_len; 11943 } 11944 11945 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11946 auth_tag, 11947 test_case->auth_tag.data, 11948 test_case->auth_tag.len, 11949 "HMAC_MD5 generated tag not as expected"); 11950 11951 return TEST_SUCCESS; 11952 } 11953 11954 static int 11955 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 11956 { 11957 uint8_t *plaintext; 11958 11959 struct crypto_testsuite_params *ts_params = &testsuite_params; 11960 struct crypto_unittest_params *ut_params = &unittest_params; 11961 struct rte_cryptodev_info dev_info; 11962 11963 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11964 uint64_t feat_flags = dev_info.feature_flags; 11965 11966 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11967 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11968 printf("Device doesn't support RAW data-path APIs.\n"); 11969 return TEST_SKIPPED; 11970 } 11971 11972 /* Verify the capabilities */ 11973 struct rte_cryptodev_sym_capability_idx cap_idx; 11974 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11975 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 11976 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11977 &cap_idx) == NULL) 11978 return TEST_SKIPPED; 11979 11980 if (MD5_HMAC_create_session(ts_params, ut_params, 11981 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 11982 return TEST_FAILED; 11983 } 11984 11985 /* Generate Crypto op data structure */ 11986 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11987 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11988 TEST_ASSERT_NOT_NULL(ut_params->op, 11989 "Failed to allocate symmetric crypto operation struct"); 11990 11991 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 11992 return TEST_FAILED; 11993 11994 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11995 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11996 ut_params->op); 11997 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11998 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11999 ut_params->op, 0, 1, 0, 0); 12000 else 12001 TEST_ASSERT_NOT_NULL( 12002 process_crypto_request(ts_params->valid_devs[0], 12003 ut_params->op), 12004 "failed to process sym crypto op"); 12005 12006 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12007 "HMAC_MD5 crypto op processing failed"); 12008 12009 return TEST_SUCCESS; 12010 } 12011 12012 static int 12013 test_MD5_HMAC_generate_case_1(void) 12014 { 12015 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 12016 } 12017 12018 static int 12019 test_MD5_HMAC_verify_case_1(void) 12020 { 12021 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 12022 } 12023 12024 static int 12025 test_MD5_HMAC_generate_case_2(void) 12026 { 12027 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 12028 } 12029 12030 static int 12031 test_MD5_HMAC_verify_case_2(void) 12032 { 12033 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 12034 } 12035 12036 static int 12037 test_multi_session(void) 12038 { 12039 struct crypto_testsuite_params *ts_params = &testsuite_params; 12040 struct crypto_unittest_params *ut_params = &unittest_params; 12041 12042 struct rte_cryptodev_info dev_info; 12043 struct rte_cryptodev_sym_session **sessions; 12044 12045 uint16_t i; 12046 int status; 12047 12048 /* Verify the capabilities */ 12049 struct rte_cryptodev_sym_capability_idx cap_idx; 12050 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12051 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 12052 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12053 &cap_idx) == NULL) 12054 return TEST_SKIPPED; 12055 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12056 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 12057 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12058 &cap_idx) == NULL) 12059 return TEST_SKIPPED; 12060 12061 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 12062 aes_cbc_key, hmac_sha512_key); 12063 12064 12065 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12066 12067 sessions = rte_malloc(NULL, 12068 sizeof(struct rte_cryptodev_sym_session *) * 12069 (MAX_NB_SESSIONS + 1), 0); 12070 12071 /* Create multiple crypto sessions*/ 12072 for (i = 0; i < MAX_NB_SESSIONS; i++) { 12073 12074 sessions[i] = rte_cryptodev_sym_session_create( 12075 ts_params->session_mpool); 12076 TEST_ASSERT_NOT_NULL(sessions[i], 12077 "Session creation failed at session number %u", 12078 i); 12079 12080 status = rte_cryptodev_sym_session_init( 12081 ts_params->valid_devs[0], 12082 sessions[i], &ut_params->auth_xform, 12083 ts_params->session_priv_mpool); 12084 if (status == -ENOTSUP) 12085 return TEST_SKIPPED; 12086 12087 /* Attempt to send a request on each session */ 12088 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform( 12089 sessions[i], 12090 ut_params, 12091 ts_params, 12092 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 12093 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 12094 aes_cbc_iv), 12095 "Failed to perform decrypt on request number %u.", i); 12096 /* free crypto operation structure */ 12097 if (ut_params->op) 12098 rte_crypto_op_free(ut_params->op); 12099 12100 /* 12101 * free mbuf - both obuf and ibuf are usually the same, 12102 * so check if they point at the same address is necessary, 12103 * to avoid freeing the mbuf twice. 12104 */ 12105 if (ut_params->obuf) { 12106 rte_pktmbuf_free(ut_params->obuf); 12107 if (ut_params->ibuf == ut_params->obuf) 12108 ut_params->ibuf = 0; 12109 ut_params->obuf = 0; 12110 } 12111 if (ut_params->ibuf) { 12112 rte_pktmbuf_free(ut_params->ibuf); 12113 ut_params->ibuf = 0; 12114 } 12115 } 12116 12117 sessions[i] = NULL; 12118 /* Next session create should fail */ 12119 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12120 sessions[i], &ut_params->auth_xform, 12121 ts_params->session_priv_mpool); 12122 TEST_ASSERT_NULL(sessions[i], 12123 "Session creation succeeded unexpectedly!"); 12124 12125 for (i = 0; i < MAX_NB_SESSIONS; i++) { 12126 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 12127 sessions[i]); 12128 rte_cryptodev_sym_session_free(sessions[i]); 12129 } 12130 12131 rte_free(sessions); 12132 12133 return TEST_SUCCESS; 12134 } 12135 12136 struct multi_session_params { 12137 struct crypto_unittest_params ut_params; 12138 uint8_t *cipher_key; 12139 uint8_t *hmac_key; 12140 const uint8_t *cipher; 12141 const uint8_t *digest; 12142 uint8_t *iv; 12143 }; 12144 12145 #define MB_SESSION_NUMBER 3 12146 12147 static int 12148 test_multi_session_random_usage(void) 12149 { 12150 struct crypto_testsuite_params *ts_params = &testsuite_params; 12151 struct rte_cryptodev_info dev_info; 12152 struct rte_cryptodev_sym_session **sessions; 12153 uint32_t i, j; 12154 struct multi_session_params ut_paramz[] = { 12155 12156 { 12157 .cipher_key = ms_aes_cbc_key0, 12158 .hmac_key = ms_hmac_key0, 12159 .cipher = ms_aes_cbc_cipher0, 12160 .digest = ms_hmac_digest0, 12161 .iv = ms_aes_cbc_iv0 12162 }, 12163 { 12164 .cipher_key = ms_aes_cbc_key1, 12165 .hmac_key = ms_hmac_key1, 12166 .cipher = ms_aes_cbc_cipher1, 12167 .digest = ms_hmac_digest1, 12168 .iv = ms_aes_cbc_iv1 12169 }, 12170 { 12171 .cipher_key = ms_aes_cbc_key2, 12172 .hmac_key = ms_hmac_key2, 12173 .cipher = ms_aes_cbc_cipher2, 12174 .digest = ms_hmac_digest2, 12175 .iv = ms_aes_cbc_iv2 12176 }, 12177 12178 }; 12179 int status; 12180 12181 /* Verify the capabilities */ 12182 struct rte_cryptodev_sym_capability_idx cap_idx; 12183 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12184 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 12185 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12186 &cap_idx) == NULL) 12187 return TEST_SKIPPED; 12188 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12189 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 12190 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12191 &cap_idx) == NULL) 12192 return TEST_SKIPPED; 12193 12194 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12195 12196 sessions = rte_malloc(NULL, 12197 (sizeof(struct rte_cryptodev_sym_session *) 12198 * MAX_NB_SESSIONS) + 1, 0); 12199 12200 for (i = 0; i < MB_SESSION_NUMBER; i++) { 12201 sessions[i] = rte_cryptodev_sym_session_create( 12202 ts_params->session_mpool); 12203 TEST_ASSERT_NOT_NULL(sessions[i], 12204 "Session creation failed at session number %u", 12205 i); 12206 12207 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params, 12208 sizeof(struct crypto_unittest_params)); 12209 12210 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 12211 &ut_paramz[i].ut_params, 12212 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 12213 12214 /* Create multiple crypto sessions*/ 12215 status = rte_cryptodev_sym_session_init( 12216 ts_params->valid_devs[0], 12217 sessions[i], 12218 &ut_paramz[i].ut_params.auth_xform, 12219 ts_params->session_priv_mpool); 12220 12221 if (status == -ENOTSUP) 12222 return TEST_SKIPPED; 12223 12224 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 12225 } 12226 12227 srand(time(NULL)); 12228 for (i = 0; i < 40000; i++) { 12229 12230 j = rand() % MB_SESSION_NUMBER; 12231 12232 TEST_ASSERT_SUCCESS( 12233 test_AES_CBC_HMAC_SHA512_decrypt_perform( 12234 sessions[j], 12235 &ut_paramz[j].ut_params, 12236 ts_params, ut_paramz[j].cipher, 12237 ut_paramz[j].digest, 12238 ut_paramz[j].iv), 12239 "Failed to perform decrypt on request number %u.", i); 12240 12241 if (ut_paramz[j].ut_params.op) 12242 rte_crypto_op_free(ut_paramz[j].ut_params.op); 12243 12244 /* 12245 * free mbuf - both obuf and ibuf are usually the same, 12246 * so check if they point at the same address is necessary, 12247 * to avoid freeing the mbuf twice. 12248 */ 12249 if (ut_paramz[j].ut_params.obuf) { 12250 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 12251 if (ut_paramz[j].ut_params.ibuf 12252 == ut_paramz[j].ut_params.obuf) 12253 ut_paramz[j].ut_params.ibuf = 0; 12254 ut_paramz[j].ut_params.obuf = 0; 12255 } 12256 if (ut_paramz[j].ut_params.ibuf) { 12257 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 12258 ut_paramz[j].ut_params.ibuf = 0; 12259 } 12260 } 12261 12262 for (i = 0; i < MB_SESSION_NUMBER; i++) { 12263 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 12264 sessions[i]); 12265 rte_cryptodev_sym_session_free(sessions[i]); 12266 } 12267 12268 rte_free(sessions); 12269 12270 return TEST_SUCCESS; 12271 } 12272 12273 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab, 12274 0xab, 0xab, 0xab, 0xab, 12275 0xab, 0xab, 0xab, 0xab, 12276 0xab, 0xab, 0xab, 0xab}; 12277 12278 static int 12279 test_null_invalid_operation(void) 12280 { 12281 struct crypto_testsuite_params *ts_params = &testsuite_params; 12282 struct crypto_unittest_params *ut_params = &unittest_params; 12283 int ret; 12284 12285 /* This test is for NULL PMD only */ 12286 if (gbl_driver_id != rte_cryptodev_driver_id_get( 12287 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 12288 return TEST_SKIPPED; 12289 12290 /* Setup Cipher Parameters */ 12291 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12292 ut_params->cipher_xform.next = NULL; 12293 12294 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 12295 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 12296 12297 ut_params->sess = rte_cryptodev_sym_session_create( 12298 ts_params->session_mpool); 12299 12300 /* Create Crypto session*/ 12301 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12302 ut_params->sess, &ut_params->cipher_xform, 12303 ts_params->session_priv_mpool); 12304 TEST_ASSERT(ret < 0, 12305 "Session creation succeeded unexpectedly"); 12306 12307 12308 /* Setup HMAC Parameters */ 12309 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12310 ut_params->auth_xform.next = NULL; 12311 12312 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 12313 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 12314 12315 ut_params->sess = rte_cryptodev_sym_session_create( 12316 ts_params->session_mpool); 12317 12318 /* Create Crypto session*/ 12319 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12320 ut_params->sess, &ut_params->auth_xform, 12321 ts_params->session_priv_mpool); 12322 TEST_ASSERT(ret < 0, 12323 "Session creation succeeded unexpectedly"); 12324 12325 return TEST_SUCCESS; 12326 } 12327 12328 12329 #define NULL_BURST_LENGTH (32) 12330 12331 static int 12332 test_null_burst_operation(void) 12333 { 12334 struct crypto_testsuite_params *ts_params = &testsuite_params; 12335 struct crypto_unittest_params *ut_params = &unittest_params; 12336 int status; 12337 12338 unsigned i, burst_len = NULL_BURST_LENGTH; 12339 12340 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 12341 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 12342 12343 /* This test is for NULL PMD only */ 12344 if (gbl_driver_id != rte_cryptodev_driver_id_get( 12345 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 12346 return TEST_SKIPPED; 12347 12348 /* Setup Cipher Parameters */ 12349 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12350 ut_params->cipher_xform.next = &ut_params->auth_xform; 12351 12352 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 12353 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 12354 12355 /* Setup HMAC Parameters */ 12356 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12357 ut_params->auth_xform.next = NULL; 12358 12359 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 12360 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 12361 12362 ut_params->sess = rte_cryptodev_sym_session_create( 12363 ts_params->session_mpool); 12364 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12365 12366 /* Create Crypto session*/ 12367 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12368 ut_params->sess, &ut_params->cipher_xform, 12369 ts_params->session_priv_mpool); 12370 12371 if (status == -ENOTSUP) 12372 return TEST_SKIPPED; 12373 12374 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 12375 12376 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 12377 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 12378 burst_len, "failed to generate burst of crypto ops"); 12379 12380 /* Generate an operation for each mbuf in burst */ 12381 for (i = 0; i < burst_len; i++) { 12382 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12383 12384 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 12385 12386 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 12387 sizeof(unsigned)); 12388 *data = i; 12389 12390 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 12391 12392 burst[i]->sym->m_src = m; 12393 } 12394 12395 /* Process crypto operation */ 12396 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 12397 0, burst, burst_len), 12398 burst_len, 12399 "Error enqueuing burst"); 12400 12401 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 12402 0, burst_dequeued, burst_len), 12403 burst_len, 12404 "Error dequeuing burst"); 12405 12406 12407 for (i = 0; i < burst_len; i++) { 12408 TEST_ASSERT_EQUAL( 12409 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 12410 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 12411 uint32_t *), 12412 "data not as expected"); 12413 12414 rte_pktmbuf_free(burst[i]->sym->m_src); 12415 rte_crypto_op_free(burst[i]); 12416 } 12417 12418 return TEST_SUCCESS; 12419 } 12420 12421 static uint16_t 12422 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 12423 uint16_t nb_ops, void *user_param) 12424 { 12425 RTE_SET_USED(dev_id); 12426 RTE_SET_USED(qp_id); 12427 RTE_SET_USED(ops); 12428 RTE_SET_USED(user_param); 12429 12430 printf("crypto enqueue callback called\n"); 12431 return nb_ops; 12432 } 12433 12434 static uint16_t 12435 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 12436 uint16_t nb_ops, void *user_param) 12437 { 12438 RTE_SET_USED(dev_id); 12439 RTE_SET_USED(qp_id); 12440 RTE_SET_USED(ops); 12441 RTE_SET_USED(user_param); 12442 12443 printf("crypto dequeue callback called\n"); 12444 return nb_ops; 12445 } 12446 12447 /* 12448 * Thread using enqueue/dequeue callback with RCU. 12449 */ 12450 static int 12451 test_enqdeq_callback_thread(void *arg) 12452 { 12453 RTE_SET_USED(arg); 12454 /* DP thread calls rte_cryptodev_enqueue_burst()/ 12455 * rte_cryptodev_dequeue_burst() and invokes callback. 12456 */ 12457 test_null_burst_operation(); 12458 return 0; 12459 } 12460 12461 static int 12462 test_enq_callback_setup(void) 12463 { 12464 struct crypto_testsuite_params *ts_params = &testsuite_params; 12465 struct rte_cryptodev_info dev_info; 12466 struct rte_cryptodev_qp_conf qp_conf = { 12467 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 12468 }; 12469 12470 struct rte_cryptodev_cb *cb; 12471 uint16_t qp_id = 0; 12472 12473 /* Stop the device in case it's started so it can be configured */ 12474 rte_cryptodev_stop(ts_params->valid_devs[0]); 12475 12476 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12477 12478 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 12479 &ts_params->conf), 12480 "Failed to configure cryptodev %u", 12481 ts_params->valid_devs[0]); 12482 12483 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 12484 qp_conf.mp_session = ts_params->session_mpool; 12485 qp_conf.mp_session_private = ts_params->session_priv_mpool; 12486 12487 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 12488 ts_params->valid_devs[0], qp_id, &qp_conf, 12489 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 12490 "Failed test for " 12491 "rte_cryptodev_queue_pair_setup: num_inflights " 12492 "%u on qp %u on cryptodev %u", 12493 qp_conf.nb_descriptors, qp_id, 12494 ts_params->valid_devs[0]); 12495 12496 /* Test with invalid crypto device */ 12497 cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS, 12498 qp_id, test_enq_callback, NULL); 12499 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12500 "cryptodev %u did not fail", 12501 qp_id, RTE_CRYPTO_MAX_DEVS); 12502 12503 /* Test with invalid queue pair */ 12504 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 12505 dev_info.max_nb_queue_pairs + 1, 12506 test_enq_callback, NULL); 12507 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12508 "cryptodev %u did not fail", 12509 dev_info.max_nb_queue_pairs + 1, 12510 ts_params->valid_devs[0]); 12511 12512 /* Test with NULL callback */ 12513 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 12514 qp_id, NULL, NULL); 12515 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12516 "cryptodev %u did not fail", 12517 qp_id, ts_params->valid_devs[0]); 12518 12519 /* Test with valid configuration */ 12520 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 12521 qp_id, test_enq_callback, NULL); 12522 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 12523 "qp %u on cryptodev %u", 12524 qp_id, ts_params->valid_devs[0]); 12525 12526 rte_cryptodev_start(ts_params->valid_devs[0]); 12527 12528 /* Launch a thread */ 12529 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 12530 rte_get_next_lcore(-1, 1, 0)); 12531 12532 /* Wait until reader exited. */ 12533 rte_eal_mp_wait_lcore(); 12534 12535 /* Test with invalid crypto device */ 12536 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 12537 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 12538 "Expected call to fail as crypto device is invalid"); 12539 12540 /* Test with invalid queue pair */ 12541 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 12542 ts_params->valid_devs[0], 12543 dev_info.max_nb_queue_pairs + 1, cb), 12544 "Expected call to fail as queue pair is invalid"); 12545 12546 /* Test with NULL callback */ 12547 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 12548 ts_params->valid_devs[0], qp_id, NULL), 12549 "Expected call to fail as callback is NULL"); 12550 12551 /* Test with valid configuration */ 12552 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback( 12553 ts_params->valid_devs[0], qp_id, cb), 12554 "Failed test to remove callback on " 12555 "qp %u on cryptodev %u", 12556 qp_id, ts_params->valid_devs[0]); 12557 12558 return TEST_SUCCESS; 12559 } 12560 12561 static int 12562 test_deq_callback_setup(void) 12563 { 12564 struct crypto_testsuite_params *ts_params = &testsuite_params; 12565 struct rte_cryptodev_info dev_info; 12566 struct rte_cryptodev_qp_conf qp_conf = { 12567 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 12568 }; 12569 12570 struct rte_cryptodev_cb *cb; 12571 uint16_t qp_id = 0; 12572 12573 /* Stop the device in case it's started so it can be configured */ 12574 rte_cryptodev_stop(ts_params->valid_devs[0]); 12575 12576 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12577 12578 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 12579 &ts_params->conf), 12580 "Failed to configure cryptodev %u", 12581 ts_params->valid_devs[0]); 12582 12583 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 12584 qp_conf.mp_session = ts_params->session_mpool; 12585 qp_conf.mp_session_private = ts_params->session_priv_mpool; 12586 12587 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 12588 ts_params->valid_devs[0], qp_id, &qp_conf, 12589 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 12590 "Failed test for " 12591 "rte_cryptodev_queue_pair_setup: num_inflights " 12592 "%u on qp %u on cryptodev %u", 12593 qp_conf.nb_descriptors, qp_id, 12594 ts_params->valid_devs[0]); 12595 12596 /* Test with invalid crypto device */ 12597 cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS, 12598 qp_id, test_deq_callback, NULL); 12599 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12600 "cryptodev %u did not fail", 12601 qp_id, RTE_CRYPTO_MAX_DEVS); 12602 12603 /* Test with invalid queue pair */ 12604 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 12605 dev_info.max_nb_queue_pairs + 1, 12606 test_deq_callback, NULL); 12607 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12608 "cryptodev %u did not fail", 12609 dev_info.max_nb_queue_pairs + 1, 12610 ts_params->valid_devs[0]); 12611 12612 /* Test with NULL callback */ 12613 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 12614 qp_id, NULL, NULL); 12615 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 12616 "cryptodev %u did not fail", 12617 qp_id, ts_params->valid_devs[0]); 12618 12619 /* Test with valid configuration */ 12620 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 12621 qp_id, test_deq_callback, NULL); 12622 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 12623 "qp %u on cryptodev %u", 12624 qp_id, ts_params->valid_devs[0]); 12625 12626 rte_cryptodev_start(ts_params->valid_devs[0]); 12627 12628 /* Launch a thread */ 12629 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 12630 rte_get_next_lcore(-1, 1, 0)); 12631 12632 /* Wait until reader exited. */ 12633 rte_eal_mp_wait_lcore(); 12634 12635 /* Test with invalid crypto device */ 12636 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 12637 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 12638 "Expected call to fail as crypto device is invalid"); 12639 12640 /* Test with invalid queue pair */ 12641 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 12642 ts_params->valid_devs[0], 12643 dev_info.max_nb_queue_pairs + 1, cb), 12644 "Expected call to fail as queue pair is invalid"); 12645 12646 /* Test with NULL callback */ 12647 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 12648 ts_params->valid_devs[0], qp_id, NULL), 12649 "Expected call to fail as callback is NULL"); 12650 12651 /* Test with valid configuration */ 12652 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback( 12653 ts_params->valid_devs[0], qp_id, cb), 12654 "Failed test to remove callback on " 12655 "qp %u on cryptodev %u", 12656 qp_id, ts_params->valid_devs[0]); 12657 12658 return TEST_SUCCESS; 12659 } 12660 12661 static void 12662 generate_gmac_large_plaintext(uint8_t *data) 12663 { 12664 uint16_t i; 12665 12666 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 12667 memcpy(&data[i], &data[0], 32); 12668 } 12669 12670 static int 12671 create_gmac_operation(enum rte_crypto_auth_operation op, 12672 const struct gmac_test_data *tdata) 12673 { 12674 struct crypto_testsuite_params *ts_params = &testsuite_params; 12675 struct crypto_unittest_params *ut_params = &unittest_params; 12676 struct rte_crypto_sym_op *sym_op; 12677 12678 uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12679 12680 /* Generate Crypto op data structure */ 12681 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12682 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12683 TEST_ASSERT_NOT_NULL(ut_params->op, 12684 "Failed to allocate symmetric crypto operation struct"); 12685 12686 sym_op = ut_params->op->sym; 12687 12688 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12689 ut_params->ibuf, tdata->gmac_tag.len); 12690 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12691 "no room to append digest"); 12692 12693 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 12694 ut_params->ibuf, plaintext_pad_len); 12695 12696 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 12697 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 12698 tdata->gmac_tag.len); 12699 debug_hexdump(stdout, "digest:", 12700 sym_op->auth.digest.data, 12701 tdata->gmac_tag.len); 12702 } 12703 12704 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12705 uint8_t *, IV_OFFSET); 12706 12707 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 12708 12709 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 12710 12711 sym_op->cipher.data.length = 0; 12712 sym_op->cipher.data.offset = 0; 12713 12714 sym_op->auth.data.offset = 0; 12715 sym_op->auth.data.length = tdata->plaintext.len; 12716 12717 return 0; 12718 } 12719 12720 static int 12721 create_gmac_operation_sgl(enum rte_crypto_auth_operation op, 12722 const struct gmac_test_data *tdata, 12723 void *digest_mem, uint64_t digest_phys) 12724 { 12725 struct crypto_testsuite_params *ts_params = &testsuite_params; 12726 struct crypto_unittest_params *ut_params = &unittest_params; 12727 struct rte_crypto_sym_op *sym_op; 12728 12729 /* Generate Crypto op data structure */ 12730 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12731 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12732 TEST_ASSERT_NOT_NULL(ut_params->op, 12733 "Failed to allocate symmetric crypto operation struct"); 12734 12735 sym_op = ut_params->op->sym; 12736 12737 sym_op->auth.digest.data = digest_mem; 12738 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 12739 "no room to append digest"); 12740 12741 sym_op->auth.digest.phys_addr = digest_phys; 12742 12743 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 12744 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 12745 tdata->gmac_tag.len); 12746 debug_hexdump(stdout, "digest:", 12747 sym_op->auth.digest.data, 12748 tdata->gmac_tag.len); 12749 } 12750 12751 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12752 uint8_t *, IV_OFFSET); 12753 12754 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 12755 12756 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 12757 12758 sym_op->cipher.data.length = 0; 12759 sym_op->cipher.data.offset = 0; 12760 12761 sym_op->auth.data.offset = 0; 12762 sym_op->auth.data.length = tdata->plaintext.len; 12763 12764 return 0; 12765 } 12766 12767 static int create_gmac_session(uint8_t dev_id, 12768 const struct gmac_test_data *tdata, 12769 enum rte_crypto_auth_operation auth_op) 12770 { 12771 uint8_t auth_key[tdata->key.len]; 12772 int status; 12773 12774 struct crypto_testsuite_params *ts_params = &testsuite_params; 12775 struct crypto_unittest_params *ut_params = &unittest_params; 12776 12777 memcpy(auth_key, tdata->key.data, tdata->key.len); 12778 12779 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12780 ut_params->auth_xform.next = NULL; 12781 12782 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 12783 ut_params->auth_xform.auth.op = auth_op; 12784 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 12785 ut_params->auth_xform.auth.key.length = tdata->key.len; 12786 ut_params->auth_xform.auth.key.data = auth_key; 12787 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 12788 ut_params->auth_xform.auth.iv.length = tdata->iv.len; 12789 12790 12791 ut_params->sess = rte_cryptodev_sym_session_create( 12792 ts_params->session_mpool); 12793 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12794 12795 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 12796 &ut_params->auth_xform, 12797 ts_params->session_priv_mpool); 12798 12799 return status; 12800 } 12801 12802 static int 12803 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 12804 { 12805 struct crypto_testsuite_params *ts_params = &testsuite_params; 12806 struct crypto_unittest_params *ut_params = &unittest_params; 12807 struct rte_cryptodev_info dev_info; 12808 12809 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12810 uint64_t feat_flags = dev_info.feature_flags; 12811 12812 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12813 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12814 printf("Device doesn't support RAW data-path APIs.\n"); 12815 return TEST_SKIPPED; 12816 } 12817 12818 int retval; 12819 12820 uint8_t *auth_tag, *plaintext; 12821 uint16_t plaintext_pad_len; 12822 12823 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 12824 "No GMAC length in the source data"); 12825 12826 /* Verify the capabilities */ 12827 struct rte_cryptodev_sym_capability_idx cap_idx; 12828 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12829 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 12830 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12831 &cap_idx) == NULL) 12832 return TEST_SKIPPED; 12833 12834 retval = create_gmac_session(ts_params->valid_devs[0], 12835 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 12836 12837 if (retval == -ENOTSUP) 12838 return TEST_SKIPPED; 12839 if (retval < 0) 12840 return retval; 12841 12842 if (tdata->plaintext.len > MBUF_SIZE) 12843 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 12844 else 12845 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12846 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12847 "Failed to allocate input buffer in mempool"); 12848 12849 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12850 rte_pktmbuf_tailroom(ut_params->ibuf)); 12851 12852 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12853 /* 12854 * Runtime generate the large plain text instead of use hard code 12855 * plain text vector. It is done to avoid create huge source file 12856 * with the test vector. 12857 */ 12858 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 12859 generate_gmac_large_plaintext(tdata->plaintext.data); 12860 12861 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12862 plaintext_pad_len); 12863 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12864 12865 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 12866 debug_hexdump(stdout, "plaintext:", plaintext, 12867 tdata->plaintext.len); 12868 12869 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 12870 tdata); 12871 12872 if (retval < 0) 12873 return retval; 12874 12875 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12876 12877 ut_params->op->sym->m_src = ut_params->ibuf; 12878 12879 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12880 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12881 ut_params->op); 12882 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12883 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12884 ut_params->op, 0, 1, 0, 0); 12885 else 12886 TEST_ASSERT_NOT_NULL( 12887 process_crypto_request(ts_params->valid_devs[0], 12888 ut_params->op), "failed to process sym crypto op"); 12889 12890 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12891 "crypto op processing failed"); 12892 12893 if (ut_params->op->sym->m_dst) { 12894 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 12895 uint8_t *, plaintext_pad_len); 12896 } else { 12897 auth_tag = plaintext + plaintext_pad_len; 12898 } 12899 12900 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 12901 12902 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12903 auth_tag, 12904 tdata->gmac_tag.data, 12905 tdata->gmac_tag.len, 12906 "GMAC Generated auth tag not as expected"); 12907 12908 return 0; 12909 } 12910 12911 static int 12912 test_AES_GMAC_authentication_test_case_1(void) 12913 { 12914 return test_AES_GMAC_authentication(&gmac_test_case_1); 12915 } 12916 12917 static int 12918 test_AES_GMAC_authentication_test_case_2(void) 12919 { 12920 return test_AES_GMAC_authentication(&gmac_test_case_2); 12921 } 12922 12923 static int 12924 test_AES_GMAC_authentication_test_case_3(void) 12925 { 12926 return test_AES_GMAC_authentication(&gmac_test_case_3); 12927 } 12928 12929 static int 12930 test_AES_GMAC_authentication_test_case_4(void) 12931 { 12932 return test_AES_GMAC_authentication(&gmac_test_case_4); 12933 } 12934 12935 static int 12936 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 12937 { 12938 struct crypto_testsuite_params *ts_params = &testsuite_params; 12939 struct crypto_unittest_params *ut_params = &unittest_params; 12940 int retval; 12941 uint32_t plaintext_pad_len; 12942 uint8_t *plaintext; 12943 struct rte_cryptodev_info dev_info; 12944 12945 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12946 uint64_t feat_flags = dev_info.feature_flags; 12947 12948 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12949 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12950 printf("Device doesn't support RAW data-path APIs.\n"); 12951 return TEST_SKIPPED; 12952 } 12953 12954 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 12955 "No GMAC length in the source data"); 12956 12957 /* Verify the capabilities */ 12958 struct rte_cryptodev_sym_capability_idx cap_idx; 12959 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12960 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 12961 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12962 &cap_idx) == NULL) 12963 return TEST_SKIPPED; 12964 12965 retval = create_gmac_session(ts_params->valid_devs[0], 12966 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 12967 12968 if (retval == -ENOTSUP) 12969 return TEST_SKIPPED; 12970 if (retval < 0) 12971 return retval; 12972 12973 if (tdata->plaintext.len > MBUF_SIZE) 12974 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 12975 else 12976 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12977 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12978 "Failed to allocate input buffer in mempool"); 12979 12980 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12981 rte_pktmbuf_tailroom(ut_params->ibuf)); 12982 12983 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12984 12985 /* 12986 * Runtime generate the large plain text instead of use hard code 12987 * plain text vector. It is done to avoid create huge source file 12988 * with the test vector. 12989 */ 12990 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 12991 generate_gmac_large_plaintext(tdata->plaintext.data); 12992 12993 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12994 plaintext_pad_len); 12995 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12996 12997 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 12998 debug_hexdump(stdout, "plaintext:", plaintext, 12999 tdata->plaintext.len); 13000 13001 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 13002 tdata); 13003 13004 if (retval < 0) 13005 return retval; 13006 13007 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13008 13009 ut_params->op->sym->m_src = ut_params->ibuf; 13010 13011 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13012 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13013 ut_params->op); 13014 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13015 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13016 ut_params->op, 0, 1, 0, 0); 13017 else 13018 TEST_ASSERT_NOT_NULL( 13019 process_crypto_request(ts_params->valid_devs[0], 13020 ut_params->op), "failed to process sym crypto op"); 13021 13022 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13023 "crypto op processing failed"); 13024 13025 return 0; 13026 13027 } 13028 13029 static int 13030 test_AES_GMAC_authentication_verify_test_case_1(void) 13031 { 13032 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 13033 } 13034 13035 static int 13036 test_AES_GMAC_authentication_verify_test_case_2(void) 13037 { 13038 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 13039 } 13040 13041 static int 13042 test_AES_GMAC_authentication_verify_test_case_3(void) 13043 { 13044 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 13045 } 13046 13047 static int 13048 test_AES_GMAC_authentication_verify_test_case_4(void) 13049 { 13050 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 13051 } 13052 13053 static int 13054 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata, 13055 uint32_t fragsz) 13056 { 13057 struct crypto_testsuite_params *ts_params = &testsuite_params; 13058 struct crypto_unittest_params *ut_params = &unittest_params; 13059 struct rte_cryptodev_info dev_info; 13060 uint64_t feature_flags; 13061 unsigned int trn_data = 0; 13062 void *digest_mem = NULL; 13063 uint32_t segs = 1; 13064 unsigned int to_trn = 0; 13065 struct rte_mbuf *buf = NULL; 13066 uint8_t *auth_tag, *plaintext; 13067 int retval; 13068 13069 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 13070 "No GMAC length in the source data"); 13071 13072 /* Verify the capabilities */ 13073 struct rte_cryptodev_sym_capability_idx cap_idx; 13074 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13075 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 13076 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13077 &cap_idx) == NULL) 13078 return TEST_SKIPPED; 13079 13080 /* Check for any input SGL support */ 13081 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13082 feature_flags = dev_info.feature_flags; 13083 13084 if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) || 13085 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) || 13086 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))) 13087 return TEST_SKIPPED; 13088 13089 if (fragsz > tdata->plaintext.len) 13090 fragsz = tdata->plaintext.len; 13091 13092 uint16_t plaintext_len = fragsz; 13093 13094 retval = create_gmac_session(ts_params->valid_devs[0], 13095 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 13096 13097 if (retval == -ENOTSUP) 13098 return TEST_SKIPPED; 13099 if (retval < 0) 13100 return retval; 13101 13102 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13103 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13104 "Failed to allocate input buffer in mempool"); 13105 13106 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13107 rte_pktmbuf_tailroom(ut_params->ibuf)); 13108 13109 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13110 plaintext_len); 13111 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13112 13113 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 13114 13115 trn_data += plaintext_len; 13116 13117 buf = ut_params->ibuf; 13118 13119 /* 13120 * Loop until no more fragments 13121 */ 13122 13123 while (trn_data < tdata->plaintext.len) { 13124 ++segs; 13125 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 13126 (tdata->plaintext.len - trn_data) : fragsz; 13127 13128 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13129 buf = buf->next; 13130 13131 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 13132 rte_pktmbuf_tailroom(buf)); 13133 13134 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 13135 to_trn); 13136 13137 memcpy(plaintext, tdata->plaintext.data + trn_data, 13138 to_trn); 13139 trn_data += to_trn; 13140 if (trn_data == tdata->plaintext.len) 13141 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 13142 tdata->gmac_tag.len); 13143 } 13144 ut_params->ibuf->nb_segs = segs; 13145 13146 /* 13147 * Place digest at the end of the last buffer 13148 */ 13149 uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn; 13150 13151 if (!digest_mem) { 13152 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13153 + tdata->gmac_tag.len); 13154 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 13155 tdata->plaintext.len); 13156 } 13157 13158 retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE, 13159 tdata, digest_mem, digest_phys); 13160 13161 if (retval < 0) 13162 return retval; 13163 13164 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13165 13166 ut_params->op->sym->m_src = ut_params->ibuf; 13167 13168 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13169 return TEST_SKIPPED; 13170 13171 TEST_ASSERT_NOT_NULL( 13172 process_crypto_request(ts_params->valid_devs[0], 13173 ut_params->op), "failed to process sym crypto op"); 13174 13175 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13176 "crypto op processing failed"); 13177 13178 auth_tag = digest_mem; 13179 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 13180 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13181 auth_tag, 13182 tdata->gmac_tag.data, 13183 tdata->gmac_tag.len, 13184 "GMAC Generated auth tag not as expected"); 13185 13186 return 0; 13187 } 13188 13189 /* Segment size not multiple of block size (16B) */ 13190 static int 13191 test_AES_GMAC_authentication_SGL_40B(void) 13192 { 13193 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40); 13194 } 13195 13196 static int 13197 test_AES_GMAC_authentication_SGL_80B(void) 13198 { 13199 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80); 13200 } 13201 13202 static int 13203 test_AES_GMAC_authentication_SGL_2048B(void) 13204 { 13205 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048); 13206 } 13207 13208 /* Segment size not multiple of block size (16B) */ 13209 static int 13210 test_AES_GMAC_authentication_SGL_2047B(void) 13211 { 13212 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047); 13213 } 13214 13215 struct test_crypto_vector { 13216 enum rte_crypto_cipher_algorithm crypto_algo; 13217 unsigned int cipher_offset; 13218 unsigned int cipher_len; 13219 13220 struct { 13221 uint8_t data[64]; 13222 unsigned int len; 13223 } cipher_key; 13224 13225 struct { 13226 uint8_t data[64]; 13227 unsigned int len; 13228 } iv; 13229 13230 struct { 13231 const uint8_t *data; 13232 unsigned int len; 13233 } plaintext; 13234 13235 struct { 13236 const uint8_t *data; 13237 unsigned int len; 13238 } ciphertext; 13239 13240 enum rte_crypto_auth_algorithm auth_algo; 13241 unsigned int auth_offset; 13242 13243 struct { 13244 uint8_t data[128]; 13245 unsigned int len; 13246 } auth_key; 13247 13248 struct { 13249 const uint8_t *data; 13250 unsigned int len; 13251 } aad; 13252 13253 struct { 13254 uint8_t data[128]; 13255 unsigned int len; 13256 } digest; 13257 }; 13258 13259 static const struct test_crypto_vector 13260 hmac_sha1_test_crypto_vector = { 13261 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 13262 .plaintext = { 13263 .data = plaintext_hash, 13264 .len = 512 13265 }, 13266 .auth_key = { 13267 .data = { 13268 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 13269 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 13270 0xDE, 0xF4, 0xDE, 0xAD 13271 }, 13272 .len = 20 13273 }, 13274 .digest = { 13275 .data = { 13276 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 13277 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 13278 0x3F, 0x91, 0x64, 0x59 13279 }, 13280 .len = 20 13281 } 13282 }; 13283 13284 static const struct test_crypto_vector 13285 aes128_gmac_test_vector = { 13286 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 13287 .plaintext = { 13288 .data = plaintext_hash, 13289 .len = 512 13290 }, 13291 .iv = { 13292 .data = { 13293 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 13294 0x08, 0x09, 0x0A, 0x0B 13295 }, 13296 .len = 12 13297 }, 13298 .auth_key = { 13299 .data = { 13300 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 13301 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 13302 }, 13303 .len = 16 13304 }, 13305 .digest = { 13306 .data = { 13307 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 13308 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 13309 }, 13310 .len = 16 13311 } 13312 }; 13313 13314 static const struct test_crypto_vector 13315 aes128cbc_hmac_sha1_test_vector = { 13316 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 13317 .cipher_offset = 0, 13318 .cipher_len = 512, 13319 .cipher_key = { 13320 .data = { 13321 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 13322 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 13323 }, 13324 .len = 16 13325 }, 13326 .iv = { 13327 .data = { 13328 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 13329 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 13330 }, 13331 .len = 16 13332 }, 13333 .plaintext = { 13334 .data = plaintext_hash, 13335 .len = 512 13336 }, 13337 .ciphertext = { 13338 .data = ciphertext512_aes128cbc, 13339 .len = 512 13340 }, 13341 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 13342 .auth_offset = 0, 13343 .auth_key = { 13344 .data = { 13345 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 13346 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 13347 0xDE, 0xF4, 0xDE, 0xAD 13348 }, 13349 .len = 20 13350 }, 13351 .digest = { 13352 .data = { 13353 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 13354 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 13355 0x18, 0x8C, 0x1D, 0x32 13356 }, 13357 .len = 20 13358 } 13359 }; 13360 13361 static const struct test_crypto_vector 13362 aes128cbc_hmac_sha1_aad_test_vector = { 13363 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 13364 .cipher_offset = 8, 13365 .cipher_len = 496, 13366 .cipher_key = { 13367 .data = { 13368 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 13369 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 13370 }, 13371 .len = 16 13372 }, 13373 .iv = { 13374 .data = { 13375 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 13376 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 13377 }, 13378 .len = 16 13379 }, 13380 .plaintext = { 13381 .data = plaintext_hash, 13382 .len = 512 13383 }, 13384 .ciphertext = { 13385 .data = ciphertext512_aes128cbc_aad, 13386 .len = 512 13387 }, 13388 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 13389 .auth_offset = 0, 13390 .auth_key = { 13391 .data = { 13392 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 13393 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 13394 0xDE, 0xF4, 0xDE, 0xAD 13395 }, 13396 .len = 20 13397 }, 13398 .digest = { 13399 .data = { 13400 0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F, 13401 0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B, 13402 0x62, 0x0F, 0xFB, 0x10 13403 }, 13404 .len = 20 13405 } 13406 }; 13407 13408 static void 13409 data_corruption(uint8_t *data) 13410 { 13411 data[0] += 1; 13412 } 13413 13414 static void 13415 tag_corruption(uint8_t *data, unsigned int tag_offset) 13416 { 13417 data[tag_offset] += 1; 13418 } 13419 13420 static int 13421 create_auth_session(struct crypto_unittest_params *ut_params, 13422 uint8_t dev_id, 13423 const struct test_crypto_vector *reference, 13424 enum rte_crypto_auth_operation auth_op) 13425 { 13426 struct crypto_testsuite_params *ts_params = &testsuite_params; 13427 uint8_t auth_key[reference->auth_key.len + 1]; 13428 int status; 13429 13430 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 13431 13432 /* Setup Authentication Parameters */ 13433 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13434 ut_params->auth_xform.auth.op = auth_op; 13435 ut_params->auth_xform.next = NULL; 13436 ut_params->auth_xform.auth.algo = reference->auth_algo; 13437 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 13438 ut_params->auth_xform.auth.key.data = auth_key; 13439 ut_params->auth_xform.auth.digest_length = reference->digest.len; 13440 13441 /* Create Crypto session*/ 13442 ut_params->sess = rte_cryptodev_sym_session_create( 13443 ts_params->session_mpool); 13444 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13445 13446 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 13447 &ut_params->auth_xform, 13448 ts_params->session_priv_mpool); 13449 13450 return status; 13451 } 13452 13453 static int 13454 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 13455 uint8_t dev_id, 13456 const struct test_crypto_vector *reference, 13457 enum rte_crypto_auth_operation auth_op, 13458 enum rte_crypto_cipher_operation cipher_op) 13459 { 13460 struct crypto_testsuite_params *ts_params = &testsuite_params; 13461 uint8_t cipher_key[reference->cipher_key.len + 1]; 13462 uint8_t auth_key[reference->auth_key.len + 1]; 13463 int status; 13464 13465 memcpy(cipher_key, reference->cipher_key.data, 13466 reference->cipher_key.len); 13467 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 13468 13469 /* Setup Authentication Parameters */ 13470 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13471 ut_params->auth_xform.auth.op = auth_op; 13472 ut_params->auth_xform.auth.algo = reference->auth_algo; 13473 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 13474 ut_params->auth_xform.auth.key.data = auth_key; 13475 ut_params->auth_xform.auth.digest_length = reference->digest.len; 13476 13477 if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) { 13478 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 13479 ut_params->auth_xform.auth.iv.length = reference->iv.len; 13480 } else { 13481 ut_params->auth_xform.next = &ut_params->cipher_xform; 13482 13483 /* Setup Cipher Parameters */ 13484 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13485 ut_params->cipher_xform.next = NULL; 13486 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 13487 ut_params->cipher_xform.cipher.op = cipher_op; 13488 ut_params->cipher_xform.cipher.key.data = cipher_key; 13489 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 13490 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 13491 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 13492 } 13493 13494 /* Create Crypto session*/ 13495 ut_params->sess = rte_cryptodev_sym_session_create( 13496 ts_params->session_mpool); 13497 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13498 13499 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 13500 &ut_params->auth_xform, 13501 ts_params->session_priv_mpool); 13502 13503 return status; 13504 } 13505 13506 static int 13507 create_auth_operation(struct crypto_testsuite_params *ts_params, 13508 struct crypto_unittest_params *ut_params, 13509 const struct test_crypto_vector *reference, 13510 unsigned int auth_generate) 13511 { 13512 /* Generate Crypto op data structure */ 13513 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13514 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13515 TEST_ASSERT_NOT_NULL(ut_params->op, 13516 "Failed to allocate pktmbuf offload"); 13517 13518 /* Set crypto operation data parameters */ 13519 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13520 13521 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 13522 13523 /* set crypto operation source mbuf */ 13524 sym_op->m_src = ut_params->ibuf; 13525 13526 /* digest */ 13527 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 13528 ut_params->ibuf, reference->digest.len); 13529 13530 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13531 "no room to append auth tag"); 13532 13533 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 13534 ut_params->ibuf, reference->plaintext.len); 13535 13536 if (auth_generate) 13537 memset(sym_op->auth.digest.data, 0, reference->digest.len); 13538 else 13539 memcpy(sym_op->auth.digest.data, 13540 reference->digest.data, 13541 reference->digest.len); 13542 13543 debug_hexdump(stdout, "digest:", 13544 sym_op->auth.digest.data, 13545 reference->digest.len); 13546 13547 sym_op->auth.data.length = reference->plaintext.len; 13548 sym_op->auth.data.offset = 0; 13549 13550 return 0; 13551 } 13552 13553 static int 13554 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 13555 struct crypto_unittest_params *ut_params, 13556 const struct test_crypto_vector *reference, 13557 unsigned int auth_generate) 13558 { 13559 /* Generate Crypto op data structure */ 13560 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13561 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13562 TEST_ASSERT_NOT_NULL(ut_params->op, 13563 "Failed to allocate pktmbuf offload"); 13564 13565 /* Set crypto operation data parameters */ 13566 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13567 13568 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 13569 13570 /* set crypto operation source mbuf */ 13571 sym_op->m_src = ut_params->ibuf; 13572 13573 /* digest */ 13574 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 13575 ut_params->ibuf, reference->digest.len); 13576 13577 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13578 "no room to append auth tag"); 13579 13580 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 13581 ut_params->ibuf, reference->ciphertext.len); 13582 13583 if (auth_generate) 13584 memset(sym_op->auth.digest.data, 0, reference->digest.len); 13585 else 13586 memcpy(sym_op->auth.digest.data, 13587 reference->digest.data, 13588 reference->digest.len); 13589 13590 debug_hexdump(stdout, "digest:", 13591 sym_op->auth.digest.data, 13592 reference->digest.len); 13593 13594 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 13595 reference->iv.data, reference->iv.len); 13596 13597 sym_op->cipher.data.length = 0; 13598 sym_op->cipher.data.offset = 0; 13599 13600 sym_op->auth.data.length = reference->plaintext.len; 13601 sym_op->auth.data.offset = 0; 13602 13603 return 0; 13604 } 13605 13606 static int 13607 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 13608 struct crypto_unittest_params *ut_params, 13609 const struct test_crypto_vector *reference, 13610 unsigned int auth_generate) 13611 { 13612 /* Generate Crypto op data structure */ 13613 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13614 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13615 TEST_ASSERT_NOT_NULL(ut_params->op, 13616 "Failed to allocate pktmbuf offload"); 13617 13618 /* Set crypto operation data parameters */ 13619 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13620 13621 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 13622 13623 /* set crypto operation source mbuf */ 13624 sym_op->m_src = ut_params->ibuf; 13625 13626 /* digest */ 13627 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 13628 ut_params->ibuf, reference->digest.len); 13629 13630 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13631 "no room to append auth tag"); 13632 13633 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 13634 ut_params->ibuf, reference->ciphertext.len); 13635 13636 if (auth_generate) 13637 memset(sym_op->auth.digest.data, 0, reference->digest.len); 13638 else 13639 memcpy(sym_op->auth.digest.data, 13640 reference->digest.data, 13641 reference->digest.len); 13642 13643 debug_hexdump(stdout, "digest:", 13644 sym_op->auth.digest.data, 13645 reference->digest.len); 13646 13647 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 13648 reference->iv.data, reference->iv.len); 13649 13650 sym_op->cipher.data.length = reference->cipher_len; 13651 sym_op->cipher.data.offset = reference->cipher_offset; 13652 13653 sym_op->auth.data.length = reference->plaintext.len; 13654 sym_op->auth.data.offset = reference->auth_offset; 13655 13656 return 0; 13657 } 13658 13659 static int 13660 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 13661 struct crypto_unittest_params *ut_params, 13662 const struct test_crypto_vector *reference) 13663 { 13664 return create_auth_operation(ts_params, ut_params, reference, 0); 13665 } 13666 13667 static int 13668 create_auth_verify_GMAC_operation( 13669 struct crypto_testsuite_params *ts_params, 13670 struct crypto_unittest_params *ut_params, 13671 const struct test_crypto_vector *reference) 13672 { 13673 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 13674 } 13675 13676 static int 13677 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params, 13678 struct crypto_unittest_params *ut_params, 13679 const struct test_crypto_vector *reference) 13680 { 13681 return create_cipher_auth_operation(ts_params, ut_params, reference, 0); 13682 } 13683 13684 static int 13685 test_authentication_verify_fail_when_data_corruption( 13686 struct crypto_testsuite_params *ts_params, 13687 struct crypto_unittest_params *ut_params, 13688 const struct test_crypto_vector *reference, 13689 unsigned int data_corrupted) 13690 { 13691 int retval; 13692 13693 uint8_t *plaintext; 13694 struct rte_cryptodev_info dev_info; 13695 13696 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13697 uint64_t feat_flags = dev_info.feature_flags; 13698 13699 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13700 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13701 printf("Device doesn't support RAW data-path APIs.\n"); 13702 return TEST_SKIPPED; 13703 } 13704 13705 /* Verify the capabilities */ 13706 struct rte_cryptodev_sym_capability_idx cap_idx; 13707 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13708 cap_idx.algo.auth = reference->auth_algo; 13709 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13710 &cap_idx) == NULL) 13711 return TEST_SKIPPED; 13712 13713 13714 /* Create session */ 13715 retval = create_auth_session(ut_params, 13716 ts_params->valid_devs[0], 13717 reference, 13718 RTE_CRYPTO_AUTH_OP_VERIFY); 13719 13720 if (retval == -ENOTSUP) 13721 return TEST_SKIPPED; 13722 if (retval < 0) 13723 return retval; 13724 13725 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13726 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13727 "Failed to allocate input buffer in mempool"); 13728 13729 /* clear mbuf payload */ 13730 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13731 rte_pktmbuf_tailroom(ut_params->ibuf)); 13732 13733 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13734 reference->plaintext.len); 13735 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13736 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 13737 13738 debug_hexdump(stdout, "plaintext:", plaintext, 13739 reference->plaintext.len); 13740 13741 /* Create operation */ 13742 retval = create_auth_verify_operation(ts_params, ut_params, reference); 13743 13744 if (retval < 0) 13745 return retval; 13746 13747 if (data_corrupted) 13748 data_corruption(plaintext); 13749 else 13750 tag_corruption(plaintext, reference->plaintext.len); 13751 13752 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13753 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13754 ut_params->op); 13755 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13756 RTE_CRYPTO_OP_STATUS_SUCCESS, 13757 "authentication not failed"); 13758 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13759 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13760 ut_params->op, 0, 1, 0, 0); 13761 else { 13762 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13763 ut_params->op); 13764 } 13765 if (ut_params->op == NULL) 13766 return 0; 13767 else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) 13768 return 0; 13769 13770 return -1; 13771 } 13772 13773 static int 13774 test_authentication_verify_GMAC_fail_when_corruption( 13775 struct crypto_testsuite_params *ts_params, 13776 struct crypto_unittest_params *ut_params, 13777 const struct test_crypto_vector *reference, 13778 unsigned int data_corrupted) 13779 { 13780 int retval; 13781 uint8_t *plaintext; 13782 struct rte_cryptodev_info dev_info; 13783 13784 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13785 uint64_t feat_flags = dev_info.feature_flags; 13786 13787 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13788 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13789 printf("Device doesn't support RAW data-path APIs.\n"); 13790 return TEST_SKIPPED; 13791 } 13792 13793 /* Verify the capabilities */ 13794 struct rte_cryptodev_sym_capability_idx cap_idx; 13795 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13796 cap_idx.algo.auth = reference->auth_algo; 13797 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13798 &cap_idx) == NULL) 13799 return TEST_SKIPPED; 13800 13801 /* Create session */ 13802 retval = create_auth_cipher_session(ut_params, 13803 ts_params->valid_devs[0], 13804 reference, 13805 RTE_CRYPTO_AUTH_OP_VERIFY, 13806 RTE_CRYPTO_CIPHER_OP_DECRYPT); 13807 if (retval < 0) 13808 return retval; 13809 13810 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13811 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13812 "Failed to allocate input buffer in mempool"); 13813 13814 /* clear mbuf payload */ 13815 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13816 rte_pktmbuf_tailroom(ut_params->ibuf)); 13817 13818 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13819 reference->plaintext.len); 13820 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13821 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 13822 13823 debug_hexdump(stdout, "plaintext:", plaintext, 13824 reference->plaintext.len); 13825 13826 /* Create operation */ 13827 retval = create_auth_verify_GMAC_operation(ts_params, 13828 ut_params, 13829 reference); 13830 13831 if (retval < 0) 13832 return retval; 13833 13834 if (data_corrupted) 13835 data_corruption(plaintext); 13836 else 13837 tag_corruption(plaintext, reference->aad.len); 13838 13839 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13840 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13841 ut_params->op); 13842 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13843 RTE_CRYPTO_OP_STATUS_SUCCESS, 13844 "authentication not failed"); 13845 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13846 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13847 ut_params->op, 0, 1, 0, 0); 13848 else { 13849 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13850 ut_params->op); 13851 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 13852 } 13853 13854 return 0; 13855 } 13856 13857 static int 13858 test_authenticated_decryption_fail_when_corruption( 13859 struct crypto_testsuite_params *ts_params, 13860 struct crypto_unittest_params *ut_params, 13861 const struct test_crypto_vector *reference, 13862 unsigned int data_corrupted) 13863 { 13864 int retval; 13865 13866 uint8_t *ciphertext; 13867 struct rte_cryptodev_info dev_info; 13868 13869 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13870 uint64_t feat_flags = dev_info.feature_flags; 13871 13872 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13873 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13874 printf("Device doesn't support RAW data-path APIs.\n"); 13875 return TEST_SKIPPED; 13876 } 13877 13878 /* Verify the capabilities */ 13879 struct rte_cryptodev_sym_capability_idx cap_idx; 13880 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13881 cap_idx.algo.auth = reference->auth_algo; 13882 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13883 &cap_idx) == NULL) 13884 return TEST_SKIPPED; 13885 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13886 cap_idx.algo.cipher = reference->crypto_algo; 13887 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13888 &cap_idx) == NULL) 13889 return TEST_SKIPPED; 13890 13891 /* Create session */ 13892 retval = create_auth_cipher_session(ut_params, 13893 ts_params->valid_devs[0], 13894 reference, 13895 RTE_CRYPTO_AUTH_OP_VERIFY, 13896 RTE_CRYPTO_CIPHER_OP_DECRYPT); 13897 13898 if (retval == -ENOTSUP) 13899 return TEST_SKIPPED; 13900 if (retval < 0) 13901 return retval; 13902 13903 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13904 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13905 "Failed to allocate input buffer in mempool"); 13906 13907 /* clear mbuf payload */ 13908 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13909 rte_pktmbuf_tailroom(ut_params->ibuf)); 13910 13911 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13912 reference->ciphertext.len); 13913 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 13914 memcpy(ciphertext, reference->ciphertext.data, 13915 reference->ciphertext.len); 13916 13917 /* Create operation */ 13918 retval = create_cipher_auth_verify_operation(ts_params, 13919 ut_params, 13920 reference); 13921 13922 if (retval < 0) 13923 return retval; 13924 13925 if (data_corrupted) 13926 data_corruption(ciphertext); 13927 else 13928 tag_corruption(ciphertext, reference->ciphertext.len); 13929 13930 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 13931 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13932 ut_params->op); 13933 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 13934 RTE_CRYPTO_OP_STATUS_SUCCESS, 13935 "authentication not failed"); 13936 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 13937 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 13938 ut_params->op, 1, 1, 0, 0); 13939 else { 13940 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 13941 ut_params->op); 13942 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 13943 } 13944 13945 return 0; 13946 } 13947 13948 static int 13949 test_authenticated_encrypt_with_esn( 13950 struct crypto_testsuite_params *ts_params, 13951 struct crypto_unittest_params *ut_params, 13952 const struct test_crypto_vector *reference) 13953 { 13954 int retval; 13955 13956 uint8_t *authciphertext, *plaintext, *auth_tag; 13957 uint16_t plaintext_pad_len; 13958 uint8_t cipher_key[reference->cipher_key.len + 1]; 13959 uint8_t auth_key[reference->auth_key.len + 1]; 13960 struct rte_cryptodev_info dev_info; 13961 int status; 13962 13963 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13964 uint64_t feat_flags = dev_info.feature_flags; 13965 13966 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13967 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13968 printf("Device doesn't support RAW data-path APIs.\n"); 13969 return TEST_SKIPPED; 13970 } 13971 13972 /* Verify the capabilities */ 13973 struct rte_cryptodev_sym_capability_idx cap_idx; 13974 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13975 cap_idx.algo.auth = reference->auth_algo; 13976 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13977 &cap_idx) == NULL) 13978 return TEST_SKIPPED; 13979 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13980 cap_idx.algo.cipher = reference->crypto_algo; 13981 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13982 &cap_idx) == NULL) 13983 return TEST_SKIPPED; 13984 13985 /* Create session */ 13986 memcpy(cipher_key, reference->cipher_key.data, 13987 reference->cipher_key.len); 13988 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 13989 13990 /* Setup Cipher Parameters */ 13991 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13992 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 13993 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 13994 ut_params->cipher_xform.cipher.key.data = cipher_key; 13995 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 13996 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 13997 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 13998 13999 ut_params->cipher_xform.next = &ut_params->auth_xform; 14000 14001 /* Setup Authentication Parameters */ 14002 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14003 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 14004 ut_params->auth_xform.auth.algo = reference->auth_algo; 14005 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 14006 ut_params->auth_xform.auth.key.data = auth_key; 14007 ut_params->auth_xform.auth.digest_length = reference->digest.len; 14008 ut_params->auth_xform.next = NULL; 14009 14010 /* Create Crypto session*/ 14011 ut_params->sess = rte_cryptodev_sym_session_create( 14012 ts_params->session_mpool); 14013 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 14014 14015 status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 14016 ut_params->sess, 14017 &ut_params->cipher_xform, 14018 ts_params->session_priv_mpool); 14019 14020 if (status == -ENOTSUP) 14021 return TEST_SKIPPED; 14022 14023 TEST_ASSERT_EQUAL(status, 0, "Session init failed"); 14024 14025 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14026 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14027 "Failed to allocate input buffer in mempool"); 14028 14029 /* clear mbuf payload */ 14030 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14031 rte_pktmbuf_tailroom(ut_params->ibuf)); 14032 14033 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14034 reference->plaintext.len); 14035 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14036 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 14037 14038 /* Create operation */ 14039 retval = create_cipher_auth_operation(ts_params, 14040 ut_params, 14041 reference, 0); 14042 14043 if (retval < 0) 14044 return retval; 14045 14046 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14047 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14048 ut_params->op); 14049 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14050 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 14051 ut_params->op, 1, 1, 0, 0); 14052 else 14053 ut_params->op = process_crypto_request( 14054 ts_params->valid_devs[0], ut_params->op); 14055 14056 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 14057 14058 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14059 "crypto op processing failed"); 14060 14061 plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16); 14062 14063 authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 14064 ut_params->op->sym->auth.data.offset); 14065 auth_tag = authciphertext + plaintext_pad_len; 14066 debug_hexdump(stdout, "ciphertext:", authciphertext, 14067 reference->ciphertext.len); 14068 debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len); 14069 14070 /* Validate obuf */ 14071 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14072 authciphertext, 14073 reference->ciphertext.data, 14074 reference->ciphertext.len, 14075 "Ciphertext data not as expected"); 14076 14077 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14078 auth_tag, 14079 reference->digest.data, 14080 reference->digest.len, 14081 "Generated digest not as expected"); 14082 14083 return TEST_SUCCESS; 14084 14085 } 14086 14087 static int 14088 test_authenticated_decrypt_with_esn( 14089 struct crypto_testsuite_params *ts_params, 14090 struct crypto_unittest_params *ut_params, 14091 const struct test_crypto_vector *reference) 14092 { 14093 int retval; 14094 14095 uint8_t *ciphertext; 14096 uint8_t cipher_key[reference->cipher_key.len + 1]; 14097 uint8_t auth_key[reference->auth_key.len + 1]; 14098 struct rte_cryptodev_info dev_info; 14099 14100 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14101 uint64_t feat_flags = dev_info.feature_flags; 14102 14103 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14104 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14105 printf("Device doesn't support RAW data-path APIs.\n"); 14106 return TEST_SKIPPED; 14107 } 14108 14109 /* Verify the capabilities */ 14110 struct rte_cryptodev_sym_capability_idx cap_idx; 14111 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14112 cap_idx.algo.auth = reference->auth_algo; 14113 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14114 &cap_idx) == NULL) 14115 return TEST_SKIPPED; 14116 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 14117 cap_idx.algo.cipher = reference->crypto_algo; 14118 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14119 &cap_idx) == NULL) 14120 return TEST_SKIPPED; 14121 14122 /* Create session */ 14123 memcpy(cipher_key, reference->cipher_key.data, 14124 reference->cipher_key.len); 14125 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 14126 14127 /* Setup Authentication Parameters */ 14128 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14129 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 14130 ut_params->auth_xform.auth.algo = reference->auth_algo; 14131 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 14132 ut_params->auth_xform.auth.key.data = auth_key; 14133 ut_params->auth_xform.auth.digest_length = reference->digest.len; 14134 ut_params->auth_xform.next = &ut_params->cipher_xform; 14135 14136 /* Setup Cipher Parameters */ 14137 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 14138 ut_params->cipher_xform.next = NULL; 14139 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 14140 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 14141 ut_params->cipher_xform.cipher.key.data = cipher_key; 14142 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 14143 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 14144 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 14145 14146 /* Create Crypto session*/ 14147 ut_params->sess = rte_cryptodev_sym_session_create( 14148 ts_params->session_mpool); 14149 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 14150 14151 retval = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 14152 ut_params->sess, 14153 &ut_params->auth_xform, 14154 ts_params->session_priv_mpool); 14155 14156 if (retval == -ENOTSUP) 14157 return TEST_SKIPPED; 14158 14159 TEST_ASSERT_EQUAL(retval, 0, "Session init failed"); 14160 14161 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14162 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14163 "Failed to allocate input buffer in mempool"); 14164 14165 /* clear mbuf payload */ 14166 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14167 rte_pktmbuf_tailroom(ut_params->ibuf)); 14168 14169 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14170 reference->ciphertext.len); 14171 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 14172 memcpy(ciphertext, reference->ciphertext.data, 14173 reference->ciphertext.len); 14174 14175 /* Create operation */ 14176 retval = create_cipher_auth_verify_operation(ts_params, 14177 ut_params, 14178 reference); 14179 14180 if (retval < 0) 14181 return retval; 14182 14183 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14184 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14185 ut_params->op); 14186 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14187 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 14188 ut_params->op, 1, 1, 0, 0); 14189 else 14190 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 14191 ut_params->op); 14192 14193 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 14194 TEST_ASSERT_EQUAL(ut_params->op->status, 14195 RTE_CRYPTO_OP_STATUS_SUCCESS, 14196 "crypto op processing passed"); 14197 14198 ut_params->obuf = ut_params->op->sym->m_src; 14199 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 14200 14201 return 0; 14202 } 14203 14204 static int 14205 create_aead_operation_SGL(enum rte_crypto_aead_operation op, 14206 const struct aead_test_data *tdata, 14207 void *digest_mem, uint64_t digest_phys) 14208 { 14209 struct crypto_testsuite_params *ts_params = &testsuite_params; 14210 struct crypto_unittest_params *ut_params = &unittest_params; 14211 14212 const unsigned int auth_tag_len = tdata->auth_tag.len; 14213 const unsigned int iv_len = tdata->iv.len; 14214 unsigned int aad_len = tdata->aad.len; 14215 unsigned int aad_len_pad = 0; 14216 14217 /* Generate Crypto op data structure */ 14218 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 14219 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 14220 TEST_ASSERT_NOT_NULL(ut_params->op, 14221 "Failed to allocate symmetric crypto operation struct"); 14222 14223 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 14224 14225 sym_op->aead.digest.data = digest_mem; 14226 14227 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 14228 "no room to append digest"); 14229 14230 sym_op->aead.digest.phys_addr = digest_phys; 14231 14232 if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) { 14233 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 14234 auth_tag_len); 14235 debug_hexdump(stdout, "digest:", 14236 sym_op->aead.digest.data, 14237 auth_tag_len); 14238 } 14239 14240 /* Append aad data */ 14241 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 14242 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 14243 uint8_t *, IV_OFFSET); 14244 14245 /* Copy IV 1 byte after the IV pointer, according to the API */ 14246 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len); 14247 14248 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16); 14249 14250 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 14251 ut_params->ibuf, aad_len); 14252 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 14253 "no room to prepend aad"); 14254 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 14255 ut_params->ibuf); 14256 14257 memset(sym_op->aead.aad.data, 0, aad_len); 14258 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 14259 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 14260 14261 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 14262 debug_hexdump(stdout, "aad:", 14263 sym_op->aead.aad.data, aad_len); 14264 } else { 14265 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 14266 uint8_t *, IV_OFFSET); 14267 14268 rte_memcpy(iv_ptr, tdata->iv.data, iv_len); 14269 14270 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16); 14271 14272 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 14273 ut_params->ibuf, aad_len_pad); 14274 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 14275 "no room to prepend aad"); 14276 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 14277 ut_params->ibuf); 14278 14279 memset(sym_op->aead.aad.data, 0, aad_len); 14280 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 14281 14282 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 14283 debug_hexdump(stdout, "aad:", 14284 sym_op->aead.aad.data, aad_len); 14285 } 14286 14287 sym_op->aead.data.length = tdata->plaintext.len; 14288 sym_op->aead.data.offset = aad_len_pad; 14289 14290 return 0; 14291 } 14292 14293 #define SGL_MAX_NO 16 14294 14295 static int 14296 test_authenticated_encryption_SGL(const struct aead_test_data *tdata, 14297 const int oop, uint32_t fragsz, uint32_t fragsz_oop) 14298 { 14299 struct crypto_testsuite_params *ts_params = &testsuite_params; 14300 struct crypto_unittest_params *ut_params = &unittest_params; 14301 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL; 14302 int retval; 14303 int to_trn = 0; 14304 int to_trn_tbl[SGL_MAX_NO]; 14305 int segs = 1; 14306 unsigned int trn_data = 0; 14307 uint8_t *plaintext, *ciphertext, *auth_tag; 14308 struct rte_cryptodev_info dev_info; 14309 14310 /* Verify the capabilities */ 14311 struct rte_cryptodev_sym_capability_idx cap_idx; 14312 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 14313 cap_idx.algo.aead = tdata->algo; 14314 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14315 &cap_idx) == NULL) 14316 return TEST_SKIPPED; 14317 14318 /* OOP not supported with CPU crypto */ 14319 if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14320 return TEST_SKIPPED; 14321 14322 /* Detailed check for the particular SGL support flag */ 14323 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14324 if (!oop) { 14325 unsigned int sgl_in = fragsz < tdata->plaintext.len; 14326 if (sgl_in && (!(dev_info.feature_flags & 14327 RTE_CRYPTODEV_FF_IN_PLACE_SGL))) 14328 return TEST_SKIPPED; 14329 14330 uint64_t feat_flags = dev_info.feature_flags; 14331 14332 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14333 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14334 printf("Device doesn't support RAW data-path APIs.\n"); 14335 return TEST_SKIPPED; 14336 } 14337 } else { 14338 unsigned int sgl_in = fragsz < tdata->plaintext.len; 14339 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) < 14340 tdata->plaintext.len; 14341 /* Raw data path API does not support OOP */ 14342 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14343 return TEST_SKIPPED; 14344 if (sgl_in && !sgl_out) { 14345 if (!(dev_info.feature_flags & 14346 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) 14347 return TEST_SKIPPED; 14348 } else if (!sgl_in && sgl_out) { 14349 if (!(dev_info.feature_flags & 14350 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 14351 return TEST_SKIPPED; 14352 } else if (sgl_in && sgl_out) { 14353 if (!(dev_info.feature_flags & 14354 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 14355 return TEST_SKIPPED; 14356 } 14357 } 14358 14359 if (fragsz > tdata->plaintext.len) 14360 fragsz = tdata->plaintext.len; 14361 14362 uint16_t plaintext_len = fragsz; 14363 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 14364 14365 if (fragsz_oop > tdata->plaintext.len) 14366 frag_size_oop = tdata->plaintext.len; 14367 14368 int ecx = 0; 14369 void *digest_mem = NULL; 14370 14371 uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 14372 14373 if (tdata->plaintext.len % fragsz != 0) { 14374 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO) 14375 return 1; 14376 } else { 14377 if (tdata->plaintext.len / fragsz > SGL_MAX_NO) 14378 return 1; 14379 } 14380 14381 /* 14382 * For out-op-place we need to alloc another mbuf 14383 */ 14384 if (oop) { 14385 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14386 rte_pktmbuf_append(ut_params->obuf, 14387 frag_size_oop + prepend_len); 14388 buf_oop = ut_params->obuf; 14389 } 14390 14391 /* Create AEAD session */ 14392 retval = create_aead_session(ts_params->valid_devs[0], 14393 tdata->algo, 14394 RTE_CRYPTO_AEAD_OP_ENCRYPT, 14395 tdata->key.data, tdata->key.len, 14396 tdata->aad.len, tdata->auth_tag.len, 14397 tdata->iv.len); 14398 if (retval < 0) 14399 return retval; 14400 14401 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14402 14403 /* clear mbuf payload */ 14404 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14405 rte_pktmbuf_tailroom(ut_params->ibuf)); 14406 14407 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14408 plaintext_len); 14409 14410 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 14411 14412 trn_data += plaintext_len; 14413 14414 buf = ut_params->ibuf; 14415 14416 /* 14417 * Loop until no more fragments 14418 */ 14419 14420 while (trn_data < tdata->plaintext.len) { 14421 ++segs; 14422 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 14423 (tdata->plaintext.len - trn_data) : fragsz; 14424 14425 to_trn_tbl[ecx++] = to_trn; 14426 14427 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14428 buf = buf->next; 14429 14430 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 14431 rte_pktmbuf_tailroom(buf)); 14432 14433 /* OOP */ 14434 if (oop && !fragsz_oop) { 14435 buf_last_oop = buf_oop->next = 14436 rte_pktmbuf_alloc(ts_params->mbuf_pool); 14437 buf_oop = buf_oop->next; 14438 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 14439 0, rte_pktmbuf_tailroom(buf_oop)); 14440 rte_pktmbuf_append(buf_oop, to_trn); 14441 } 14442 14443 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 14444 to_trn); 14445 14446 memcpy(plaintext, tdata->plaintext.data + trn_data, 14447 to_trn); 14448 trn_data += to_trn; 14449 if (trn_data == tdata->plaintext.len) { 14450 if (oop) { 14451 if (!fragsz_oop) 14452 digest_mem = rte_pktmbuf_append(buf_oop, 14453 tdata->auth_tag.len); 14454 } else 14455 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 14456 tdata->auth_tag.len); 14457 } 14458 } 14459 14460 uint64_t digest_phys = 0; 14461 14462 ut_params->ibuf->nb_segs = segs; 14463 14464 segs = 1; 14465 if (fragsz_oop && oop) { 14466 to_trn = 0; 14467 ecx = 0; 14468 14469 if (frag_size_oop == tdata->plaintext.len) { 14470 digest_mem = rte_pktmbuf_append(ut_params->obuf, 14471 tdata->auth_tag.len); 14472 14473 digest_phys = rte_pktmbuf_iova_offset( 14474 ut_params->obuf, 14475 tdata->plaintext.len + prepend_len); 14476 } 14477 14478 trn_data = frag_size_oop; 14479 while (trn_data < tdata->plaintext.len) { 14480 ++segs; 14481 to_trn = 14482 (tdata->plaintext.len - trn_data < 14483 frag_size_oop) ? 14484 (tdata->plaintext.len - trn_data) : 14485 frag_size_oop; 14486 14487 to_trn_tbl[ecx++] = to_trn; 14488 14489 buf_last_oop = buf_oop->next = 14490 rte_pktmbuf_alloc(ts_params->mbuf_pool); 14491 buf_oop = buf_oop->next; 14492 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 14493 0, rte_pktmbuf_tailroom(buf_oop)); 14494 rte_pktmbuf_append(buf_oop, to_trn); 14495 14496 trn_data += to_trn; 14497 14498 if (trn_data == tdata->plaintext.len) { 14499 digest_mem = rte_pktmbuf_append(buf_oop, 14500 tdata->auth_tag.len); 14501 } 14502 } 14503 14504 ut_params->obuf->nb_segs = segs; 14505 } 14506 14507 /* 14508 * Place digest at the end of the last buffer 14509 */ 14510 if (!digest_phys) 14511 digest_phys = rte_pktmbuf_iova(buf) + to_trn; 14512 if (oop && buf_last_oop) 14513 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn; 14514 14515 if (!digest_mem && !oop) { 14516 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14517 + tdata->auth_tag.len); 14518 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 14519 tdata->plaintext.len); 14520 } 14521 14522 /* Create AEAD operation */ 14523 retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT, 14524 tdata, digest_mem, digest_phys); 14525 14526 if (retval < 0) 14527 return retval; 14528 14529 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14530 14531 ut_params->op->sym->m_src = ut_params->ibuf; 14532 if (oop) 14533 ut_params->op->sym->m_dst = ut_params->obuf; 14534 14535 /* Process crypto operation */ 14536 if (oop == IN_PLACE && 14537 gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14538 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 14539 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 14540 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 14541 ut_params->op, 0, 0, 0, 0); 14542 else 14543 TEST_ASSERT_NOT_NULL( 14544 process_crypto_request(ts_params->valid_devs[0], 14545 ut_params->op), "failed to process sym crypto op"); 14546 14547 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14548 "crypto op processing failed"); 14549 14550 14551 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 14552 uint8_t *, prepend_len); 14553 if (oop) { 14554 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 14555 uint8_t *, prepend_len); 14556 } 14557 14558 if (fragsz_oop) 14559 fragsz = fragsz_oop; 14560 14561 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14562 ciphertext, 14563 tdata->ciphertext.data, 14564 fragsz, 14565 "Ciphertext data not as expected"); 14566 14567 buf = ut_params->op->sym->m_src->next; 14568 if (oop) 14569 buf = ut_params->op->sym->m_dst->next; 14570 14571 unsigned int off = fragsz; 14572 14573 ecx = 0; 14574 while (buf) { 14575 ciphertext = rte_pktmbuf_mtod(buf, 14576 uint8_t *); 14577 14578 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14579 ciphertext, 14580 tdata->ciphertext.data + off, 14581 to_trn_tbl[ecx], 14582 "Ciphertext data not as expected"); 14583 14584 off += to_trn_tbl[ecx++]; 14585 buf = buf->next; 14586 } 14587 14588 auth_tag = digest_mem; 14589 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14590 auth_tag, 14591 tdata->auth_tag.data, 14592 tdata->auth_tag.len, 14593 "Generated auth tag not as expected"); 14594 14595 return 0; 14596 } 14597 14598 static int 14599 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) 14600 { 14601 return test_authenticated_encryption_SGL( 14602 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400); 14603 } 14604 14605 static int 14606 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void) 14607 { 14608 return test_authenticated_encryption_SGL( 14609 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000); 14610 } 14611 14612 static int 14613 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void) 14614 { 14615 return test_authenticated_encryption_SGL( 14616 &gcm_test_case_8, OUT_OF_PLACE, 400, 14617 gcm_test_case_8.plaintext.len); 14618 } 14619 14620 static int 14621 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void) 14622 { 14623 /* This test is not for OPENSSL PMD */ 14624 if (gbl_driver_id == rte_cryptodev_driver_id_get( 14625 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) 14626 return TEST_SKIPPED; 14627 14628 return test_authenticated_encryption_SGL( 14629 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0); 14630 } 14631 14632 static int 14633 test_authentication_verify_fail_when_data_corrupted( 14634 struct crypto_testsuite_params *ts_params, 14635 struct crypto_unittest_params *ut_params, 14636 const struct test_crypto_vector *reference) 14637 { 14638 return test_authentication_verify_fail_when_data_corruption( 14639 ts_params, ut_params, reference, 1); 14640 } 14641 14642 static int 14643 test_authentication_verify_fail_when_tag_corrupted( 14644 struct crypto_testsuite_params *ts_params, 14645 struct crypto_unittest_params *ut_params, 14646 const struct test_crypto_vector *reference) 14647 { 14648 return test_authentication_verify_fail_when_data_corruption( 14649 ts_params, ut_params, reference, 0); 14650 } 14651 14652 static int 14653 test_authentication_verify_GMAC_fail_when_data_corrupted( 14654 struct crypto_testsuite_params *ts_params, 14655 struct crypto_unittest_params *ut_params, 14656 const struct test_crypto_vector *reference) 14657 { 14658 return test_authentication_verify_GMAC_fail_when_corruption( 14659 ts_params, ut_params, reference, 1); 14660 } 14661 14662 static int 14663 test_authentication_verify_GMAC_fail_when_tag_corrupted( 14664 struct crypto_testsuite_params *ts_params, 14665 struct crypto_unittest_params *ut_params, 14666 const struct test_crypto_vector *reference) 14667 { 14668 return test_authentication_verify_GMAC_fail_when_corruption( 14669 ts_params, ut_params, reference, 0); 14670 } 14671 14672 static int 14673 test_authenticated_decryption_fail_when_data_corrupted( 14674 struct crypto_testsuite_params *ts_params, 14675 struct crypto_unittest_params *ut_params, 14676 const struct test_crypto_vector *reference) 14677 { 14678 return test_authenticated_decryption_fail_when_corruption( 14679 ts_params, ut_params, reference, 1); 14680 } 14681 14682 static int 14683 test_authenticated_decryption_fail_when_tag_corrupted( 14684 struct crypto_testsuite_params *ts_params, 14685 struct crypto_unittest_params *ut_params, 14686 const struct test_crypto_vector *reference) 14687 { 14688 return test_authenticated_decryption_fail_when_corruption( 14689 ts_params, ut_params, reference, 0); 14690 } 14691 14692 static int 14693 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 14694 { 14695 return test_authentication_verify_fail_when_data_corrupted( 14696 &testsuite_params, &unittest_params, 14697 &hmac_sha1_test_crypto_vector); 14698 } 14699 14700 static int 14701 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 14702 { 14703 return test_authentication_verify_fail_when_tag_corrupted( 14704 &testsuite_params, &unittest_params, 14705 &hmac_sha1_test_crypto_vector); 14706 } 14707 14708 static int 14709 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 14710 { 14711 return test_authentication_verify_GMAC_fail_when_data_corrupted( 14712 &testsuite_params, &unittest_params, 14713 &aes128_gmac_test_vector); 14714 } 14715 14716 static int 14717 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 14718 { 14719 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 14720 &testsuite_params, &unittest_params, 14721 &aes128_gmac_test_vector); 14722 } 14723 14724 static int 14725 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 14726 { 14727 return test_authenticated_decryption_fail_when_data_corrupted( 14728 &testsuite_params, 14729 &unittest_params, 14730 &aes128cbc_hmac_sha1_test_vector); 14731 } 14732 14733 static int 14734 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 14735 { 14736 return test_authenticated_decryption_fail_when_tag_corrupted( 14737 &testsuite_params, 14738 &unittest_params, 14739 &aes128cbc_hmac_sha1_test_vector); 14740 } 14741 14742 static int 14743 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void) 14744 { 14745 return test_authenticated_encrypt_with_esn( 14746 &testsuite_params, 14747 &unittest_params, 14748 &aes128cbc_hmac_sha1_aad_test_vector); 14749 } 14750 14751 static int 14752 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void) 14753 { 14754 return test_authenticated_decrypt_with_esn( 14755 &testsuite_params, 14756 &unittest_params, 14757 &aes128cbc_hmac_sha1_aad_test_vector); 14758 } 14759 14760 static int 14761 test_chacha20_poly1305_encrypt_test_case_rfc8439(void) 14762 { 14763 return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439); 14764 } 14765 14766 static int 14767 test_chacha20_poly1305_decrypt_test_case_rfc8439(void) 14768 { 14769 return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439); 14770 } 14771 14772 static int 14773 test_chacha20_poly1305_encrypt_SGL_out_of_place(void) 14774 { 14775 return test_authenticated_encryption_SGL( 14776 &chacha20_poly1305_case_2, OUT_OF_PLACE, 32, 14777 chacha20_poly1305_case_2.plaintext.len); 14778 } 14779 14780 #ifdef RTE_CRYPTO_SCHEDULER 14781 14782 /* global AESNI worker IDs for the scheduler test */ 14783 uint8_t aesni_ids[2]; 14784 14785 static int 14786 scheduler_testsuite_setup(void) 14787 { 14788 uint32_t i = 0; 14789 int32_t nb_devs, ret; 14790 char vdev_args[VDEV_ARGS_SIZE] = {""}; 14791 char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core," 14792 "ordering=enable,name=cryptodev_test_scheduler,corelist="}; 14793 uint16_t worker_core_count = 0; 14794 uint16_t socket_id = 0; 14795 14796 if (gbl_driver_id == rte_cryptodev_driver_id_get( 14797 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) { 14798 14799 /* Identify the Worker Cores 14800 * Use 2 worker cores for the device args 14801 */ 14802 RTE_LCORE_FOREACH_WORKER(i) { 14803 if (worker_core_count > 1) 14804 break; 14805 snprintf(vdev_args, sizeof(vdev_args), 14806 "%s%d", temp_str, i); 14807 strcpy(temp_str, vdev_args); 14808 strlcat(temp_str, ";", sizeof(temp_str)); 14809 worker_core_count++; 14810 socket_id = rte_lcore_to_socket_id(i); 14811 } 14812 if (worker_core_count != 2) { 14813 RTE_LOG(ERR, USER1, 14814 "Cryptodev scheduler test require at least " 14815 "two worker cores to run. " 14816 "Please use the correct coremask.\n"); 14817 return TEST_FAILED; 14818 } 14819 strcpy(temp_str, vdev_args); 14820 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", 14821 temp_str, socket_id); 14822 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args); 14823 nb_devs = rte_cryptodev_device_count_by_driver( 14824 rte_cryptodev_driver_id_get( 14825 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))); 14826 if (nb_devs < 1) { 14827 ret = rte_vdev_init( 14828 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD), 14829 vdev_args); 14830 TEST_ASSERT(ret == 0, 14831 "Failed to create instance %u of pmd : %s", 14832 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 14833 } 14834 } 14835 return testsuite_setup(); 14836 } 14837 14838 static int 14839 test_scheduler_attach_worker_op(void) 14840 { 14841 struct crypto_testsuite_params *ts_params = &testsuite_params; 14842 uint8_t sched_id = ts_params->valid_devs[0]; 14843 uint32_t i, nb_devs_attached = 0; 14844 int ret; 14845 char vdev_name[32]; 14846 unsigned int count = rte_cryptodev_count(); 14847 14848 /* create 2 AESNI_MB vdevs on top of existing devices */ 14849 for (i = count; i < count + 2; i++) { 14850 snprintf(vdev_name, sizeof(vdev_name), "%s_%u", 14851 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), 14852 i); 14853 ret = rte_vdev_init(vdev_name, NULL); 14854 14855 TEST_ASSERT(ret == 0, 14856 "Failed to create instance %u of" 14857 " pmd : %s", 14858 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 14859 14860 if (ret < 0) { 14861 RTE_LOG(ERR, USER1, 14862 "Failed to create 2 AESNI MB PMDs.\n"); 14863 return TEST_SKIPPED; 14864 } 14865 } 14866 14867 /* attach 2 AESNI_MB cdevs */ 14868 for (i = count; i < count + 2; i++) { 14869 struct rte_cryptodev_info info; 14870 unsigned int session_size; 14871 14872 rte_cryptodev_info_get(i, &info); 14873 if (info.driver_id != rte_cryptodev_driver_id_get( 14874 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) 14875 continue; 14876 14877 session_size = rte_cryptodev_sym_get_private_session_size(i); 14878 /* 14879 * Create the session mempool again, since now there are new devices 14880 * to use the mempool. 14881 */ 14882 if (ts_params->session_mpool) { 14883 rte_mempool_free(ts_params->session_mpool); 14884 ts_params->session_mpool = NULL; 14885 } 14886 if (ts_params->session_priv_mpool) { 14887 rte_mempool_free(ts_params->session_priv_mpool); 14888 ts_params->session_priv_mpool = NULL; 14889 } 14890 14891 if (info.sym.max_nb_sessions != 0 && 14892 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 14893 RTE_LOG(ERR, USER1, 14894 "Device does not support " 14895 "at least %u sessions\n", 14896 MAX_NB_SESSIONS); 14897 return TEST_FAILED; 14898 } 14899 /* 14900 * Create mempool with maximum number of sessions, 14901 * to include the session headers 14902 */ 14903 if (ts_params->session_mpool == NULL) { 14904 ts_params->session_mpool = 14905 rte_cryptodev_sym_session_pool_create( 14906 "test_sess_mp", 14907 MAX_NB_SESSIONS, 0, 0, 0, 14908 SOCKET_ID_ANY); 14909 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 14910 "session mempool allocation failed"); 14911 } 14912 14913 /* 14914 * Create mempool with maximum number of sessions, 14915 * to include device specific session private data 14916 */ 14917 if (ts_params->session_priv_mpool == NULL) { 14918 ts_params->session_priv_mpool = rte_mempool_create( 14919 "test_sess_mp_priv", 14920 MAX_NB_SESSIONS, 14921 session_size, 14922 0, 0, NULL, NULL, NULL, 14923 NULL, SOCKET_ID_ANY, 14924 0); 14925 14926 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 14927 "session mempool allocation failed"); 14928 } 14929 14930 ts_params->qp_conf.mp_session = ts_params->session_mpool; 14931 ts_params->qp_conf.mp_session_private = 14932 ts_params->session_priv_mpool; 14933 14934 ret = rte_cryptodev_scheduler_worker_attach(sched_id, 14935 (uint8_t)i); 14936 14937 TEST_ASSERT(ret == 0, 14938 "Failed to attach device %u of pmd : %s", i, 14939 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 14940 14941 aesni_ids[nb_devs_attached] = (uint8_t)i; 14942 14943 nb_devs_attached++; 14944 } 14945 14946 return 0; 14947 } 14948 14949 static int 14950 test_scheduler_detach_worker_op(void) 14951 { 14952 struct crypto_testsuite_params *ts_params = &testsuite_params; 14953 uint8_t sched_id = ts_params->valid_devs[0]; 14954 uint32_t i; 14955 int ret; 14956 14957 for (i = 0; i < 2; i++) { 14958 ret = rte_cryptodev_scheduler_worker_detach(sched_id, 14959 aesni_ids[i]); 14960 TEST_ASSERT(ret == 0, 14961 "Failed to detach device %u", aesni_ids[i]); 14962 } 14963 14964 return 0; 14965 } 14966 14967 static int 14968 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode) 14969 { 14970 struct crypto_testsuite_params *ts_params = &testsuite_params; 14971 uint8_t sched_id = ts_params->valid_devs[0]; 14972 /* set mode */ 14973 return rte_cryptodev_scheduler_mode_set(sched_id, 14974 scheduler_mode); 14975 } 14976 14977 static int 14978 test_scheduler_mode_roundrobin_op(void) 14979 { 14980 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) == 14981 0, "Failed to set roundrobin mode"); 14982 return 0; 14983 14984 } 14985 14986 static int 14987 test_scheduler_mode_multicore_op(void) 14988 { 14989 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) == 14990 0, "Failed to set multicore mode"); 14991 14992 return 0; 14993 } 14994 14995 static int 14996 test_scheduler_mode_failover_op(void) 14997 { 14998 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) == 14999 0, "Failed to set failover mode"); 15000 15001 return 0; 15002 } 15003 15004 static int 15005 test_scheduler_mode_pkt_size_distr_op(void) 15006 { 15007 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) == 15008 0, "Failed to set pktsize mode"); 15009 15010 return 0; 15011 } 15012 15013 static int 15014 scheduler_multicore_testsuite_setup(void) 15015 { 15016 if (test_scheduler_attach_worker_op() < 0) 15017 return TEST_SKIPPED; 15018 if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0) 15019 return TEST_SKIPPED; 15020 return 0; 15021 } 15022 15023 static int 15024 scheduler_roundrobin_testsuite_setup(void) 15025 { 15026 if (test_scheduler_attach_worker_op() < 0) 15027 return TEST_SKIPPED; 15028 if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0) 15029 return TEST_SKIPPED; 15030 return 0; 15031 } 15032 15033 static int 15034 scheduler_failover_testsuite_setup(void) 15035 { 15036 if (test_scheduler_attach_worker_op() < 0) 15037 return TEST_SKIPPED; 15038 if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0) 15039 return TEST_SKIPPED; 15040 return 0; 15041 } 15042 15043 static int 15044 scheduler_pkt_size_distr_testsuite_setup(void) 15045 { 15046 if (test_scheduler_attach_worker_op() < 0) 15047 return TEST_SKIPPED; 15048 if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0) 15049 return TEST_SKIPPED; 15050 return 0; 15051 } 15052 15053 static void 15054 scheduler_mode_testsuite_teardown(void) 15055 { 15056 test_scheduler_detach_worker_op(); 15057 } 15058 15059 #endif /* RTE_CRYPTO_SCHEDULER */ 15060 15061 static struct unit_test_suite end_testsuite = { 15062 .suite_name = NULL, 15063 .setup = NULL, 15064 .teardown = NULL, 15065 .unit_test_suites = NULL 15066 }; 15067 15068 #ifdef RTE_LIB_SECURITY 15069 static struct unit_test_suite ipsec_proto_testsuite = { 15070 .suite_name = "IPsec Proto Unit Test Suite", 15071 .setup = ipsec_proto_testsuite_setup, 15072 .unit_test_cases = { 15073 TEST_CASE_NAMED_WITH_DATA( 15074 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 15075 ut_setup_security, ut_teardown, 15076 test_ipsec_proto_known_vec, &pkt_aes_128_gcm), 15077 TEST_CASE_NAMED_WITH_DATA( 15078 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 15079 ut_setup_security, ut_teardown, 15080 test_ipsec_proto_known_vec, &pkt_aes_192_gcm), 15081 TEST_CASE_NAMED_WITH_DATA( 15082 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 15083 ut_setup_security, ut_teardown, 15084 test_ipsec_proto_known_vec, &pkt_aes_256_gcm), 15085 TEST_CASE_NAMED_WITH_DATA( 15086 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])", 15087 ut_setup_security, ut_teardown, 15088 test_ipsec_proto_known_vec, 15089 &pkt_aes_128_cbc_hmac_sha256), 15090 TEST_CASE_NAMED_WITH_DATA( 15091 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])", 15092 ut_setup_security, ut_teardown, 15093 test_ipsec_proto_known_vec, 15094 &pkt_aes_128_cbc_hmac_sha384), 15095 TEST_CASE_NAMED_WITH_DATA( 15096 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])", 15097 ut_setup_security, ut_teardown, 15098 test_ipsec_proto_known_vec, 15099 &pkt_aes_128_cbc_hmac_sha512), 15100 TEST_CASE_NAMED_WITH_DATA( 15101 "Outbound known vector (ESP tunnel mode IPv6 AES-GCM 128)", 15102 ut_setup_security, ut_teardown, 15103 test_ipsec_proto_known_vec, &pkt_aes_256_gcm_v6), 15104 TEST_CASE_NAMED_WITH_DATA( 15105 "Outbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])", 15106 ut_setup_security, ut_teardown, 15107 test_ipsec_proto_known_vec, 15108 &pkt_aes_128_cbc_hmac_sha256_v6), 15109 TEST_CASE_NAMED_WITH_DATA( 15110 "Outbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])", 15111 ut_setup_security, ut_teardown, 15112 test_ipsec_proto_known_vec, 15113 &pkt_null_aes_xcbc), 15114 TEST_CASE_NAMED_WITH_DATA( 15115 "Outbound known vector (AH tunnel mode IPv4 HMAC-SHA256)", 15116 ut_setup_security, ut_teardown, 15117 test_ipsec_proto_known_vec, 15118 &pkt_ah_tunnel_sha256), 15119 TEST_CASE_NAMED_WITH_DATA( 15120 "Outbound known vector (AH transport mode IPv4 HMAC-SHA256)", 15121 ut_setup_security, ut_teardown, 15122 test_ipsec_proto_known_vec, 15123 &pkt_ah_transport_sha256), 15124 TEST_CASE_NAMED_WITH_DATA( 15125 "Outbound known vector (AH transport mode IPv4 AES-GMAC 128)", 15126 ut_setup_security, ut_teardown, 15127 test_ipsec_proto_known_vec, 15128 &pkt_ah_ipv4_aes_gmac_128), 15129 TEST_CASE_NAMED_WITH_DATA( 15130 "Outbound fragmented packet", 15131 ut_setup_security, ut_teardown, 15132 test_ipsec_proto_known_vec_fragmented, 15133 &pkt_aes_128_gcm_frag), 15134 TEST_CASE_NAMED_WITH_DATA( 15135 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 15136 ut_setup_security, ut_teardown, 15137 test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm), 15138 TEST_CASE_NAMED_WITH_DATA( 15139 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 15140 ut_setup_security, ut_teardown, 15141 test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm), 15142 TEST_CASE_NAMED_WITH_DATA( 15143 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 15144 ut_setup_security, ut_teardown, 15145 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm), 15146 TEST_CASE_NAMED_WITH_DATA( 15147 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)", 15148 ut_setup_security, ut_teardown, 15149 test_ipsec_proto_known_vec_inb, &pkt_aes_128_cbc_null), 15150 TEST_CASE_NAMED_WITH_DATA( 15151 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])", 15152 ut_setup_security, ut_teardown, 15153 test_ipsec_proto_known_vec_inb, 15154 &pkt_aes_128_cbc_hmac_sha256), 15155 TEST_CASE_NAMED_WITH_DATA( 15156 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])", 15157 ut_setup_security, ut_teardown, 15158 test_ipsec_proto_known_vec_inb, 15159 &pkt_aes_128_cbc_hmac_sha384), 15160 TEST_CASE_NAMED_WITH_DATA( 15161 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])", 15162 ut_setup_security, ut_teardown, 15163 test_ipsec_proto_known_vec_inb, 15164 &pkt_aes_128_cbc_hmac_sha512), 15165 TEST_CASE_NAMED_WITH_DATA( 15166 "Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)", 15167 ut_setup_security, ut_teardown, 15168 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm_v6), 15169 TEST_CASE_NAMED_WITH_DATA( 15170 "Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])", 15171 ut_setup_security, ut_teardown, 15172 test_ipsec_proto_known_vec_inb, 15173 &pkt_aes_128_cbc_hmac_sha256_v6), 15174 TEST_CASE_NAMED_WITH_DATA( 15175 "Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])", 15176 ut_setup_security, ut_teardown, 15177 test_ipsec_proto_known_vec_inb, 15178 &pkt_null_aes_xcbc), 15179 TEST_CASE_NAMED_WITH_DATA( 15180 "Inbound known vector (AH tunnel mode IPv4 HMAC-SHA256)", 15181 ut_setup_security, ut_teardown, 15182 test_ipsec_proto_known_vec_inb, 15183 &pkt_ah_tunnel_sha256), 15184 TEST_CASE_NAMED_WITH_DATA( 15185 "Inbound known vector (AH transport mode IPv4 HMAC-SHA256)", 15186 ut_setup_security, ut_teardown, 15187 test_ipsec_proto_known_vec_inb, 15188 &pkt_ah_transport_sha256), 15189 TEST_CASE_NAMED_WITH_DATA( 15190 "Inbound known vector (AH transport mode IPv4 AES-GMAC 128)", 15191 ut_setup_security, ut_teardown, 15192 test_ipsec_proto_known_vec_inb, 15193 &pkt_ah_ipv4_aes_gmac_128), 15194 TEST_CASE_NAMED_ST( 15195 "Combined test alg list", 15196 ut_setup_security, ut_teardown, 15197 test_ipsec_proto_display_list), 15198 TEST_CASE_NAMED_ST( 15199 "Combined test alg list (AH)", 15200 ut_setup_security, ut_teardown, 15201 test_ipsec_proto_ah_tunnel_ipv4), 15202 TEST_CASE_NAMED_ST( 15203 "IV generation", 15204 ut_setup_security, ut_teardown, 15205 test_ipsec_proto_iv_gen), 15206 TEST_CASE_NAMED_ST( 15207 "UDP encapsulation", 15208 ut_setup_security, ut_teardown, 15209 test_ipsec_proto_udp_encap), 15210 TEST_CASE_NAMED_ST( 15211 "UDP encapsulation ports verification test", 15212 ut_setup_security, ut_teardown, 15213 test_ipsec_proto_udp_ports_verify), 15214 TEST_CASE_NAMED_ST( 15215 "SA expiry packets soft", 15216 ut_setup_security, ut_teardown, 15217 test_ipsec_proto_sa_exp_pkts_soft), 15218 TEST_CASE_NAMED_ST( 15219 "SA expiry packets hard", 15220 ut_setup_security, ut_teardown, 15221 test_ipsec_proto_sa_exp_pkts_hard), 15222 TEST_CASE_NAMED_ST( 15223 "Negative test: ICV corruption", 15224 ut_setup_security, ut_teardown, 15225 test_ipsec_proto_err_icv_corrupt), 15226 TEST_CASE_NAMED_ST( 15227 "Tunnel dst addr verification", 15228 ut_setup_security, ut_teardown, 15229 test_ipsec_proto_tunnel_dst_addr_verify), 15230 TEST_CASE_NAMED_ST( 15231 "Tunnel src and dst addr verification", 15232 ut_setup_security, ut_teardown, 15233 test_ipsec_proto_tunnel_src_dst_addr_verify), 15234 TEST_CASE_NAMED_ST( 15235 "Inner IP checksum", 15236 ut_setup_security, ut_teardown, 15237 test_ipsec_proto_inner_ip_csum), 15238 TEST_CASE_NAMED_ST( 15239 "Inner L4 checksum", 15240 ut_setup_security, ut_teardown, 15241 test_ipsec_proto_inner_l4_csum), 15242 TEST_CASE_NAMED_ST( 15243 "Tunnel IPv4 in IPv4", 15244 ut_setup_security, ut_teardown, 15245 test_ipsec_proto_tunnel_v4_in_v4), 15246 TEST_CASE_NAMED_ST( 15247 "Tunnel IPv6 in IPv6", 15248 ut_setup_security, ut_teardown, 15249 test_ipsec_proto_tunnel_v6_in_v6), 15250 TEST_CASE_NAMED_ST( 15251 "Tunnel IPv4 in IPv6", 15252 ut_setup_security, ut_teardown, 15253 test_ipsec_proto_tunnel_v4_in_v6), 15254 TEST_CASE_NAMED_ST( 15255 "Tunnel IPv6 in IPv4", 15256 ut_setup_security, ut_teardown, 15257 test_ipsec_proto_tunnel_v6_in_v4), 15258 TEST_CASE_NAMED_ST( 15259 "Transport IPv4", 15260 ut_setup_security, ut_teardown, 15261 test_ipsec_proto_transport_v4), 15262 TEST_CASE_NAMED_ST( 15263 "AH transport IPv4", 15264 ut_setup_security, ut_teardown, 15265 test_ipsec_proto_ah_transport_ipv4), 15266 TEST_CASE_NAMED_ST( 15267 "Transport l4 checksum", 15268 ut_setup_security, ut_teardown, 15269 test_ipsec_proto_transport_l4_csum), 15270 TEST_CASE_NAMED_ST( 15271 "Statistics: success", 15272 ut_setup_security, ut_teardown, 15273 test_ipsec_proto_stats), 15274 TEST_CASE_NAMED_ST( 15275 "Fragmented packet", 15276 ut_setup_security, ut_teardown, 15277 test_ipsec_proto_pkt_fragment), 15278 TEST_CASE_NAMED_ST( 15279 "Tunnel header copy DF (inner 0)", 15280 ut_setup_security, ut_teardown, 15281 test_ipsec_proto_copy_df_inner_0), 15282 TEST_CASE_NAMED_ST( 15283 "Tunnel header copy DF (inner 1)", 15284 ut_setup_security, ut_teardown, 15285 test_ipsec_proto_copy_df_inner_1), 15286 TEST_CASE_NAMED_ST( 15287 "Tunnel header set DF 0 (inner 1)", 15288 ut_setup_security, ut_teardown, 15289 test_ipsec_proto_set_df_0_inner_1), 15290 TEST_CASE_NAMED_ST( 15291 "Tunnel header set DF 1 (inner 0)", 15292 ut_setup_security, ut_teardown, 15293 test_ipsec_proto_set_df_1_inner_0), 15294 TEST_CASE_NAMED_ST( 15295 "Tunnel header IPv4 copy DSCP (inner 0)", 15296 ut_setup_security, ut_teardown, 15297 test_ipsec_proto_ipv4_copy_dscp_inner_0), 15298 TEST_CASE_NAMED_ST( 15299 "Tunnel header IPv4 copy DSCP (inner 1)", 15300 ut_setup_security, ut_teardown, 15301 test_ipsec_proto_ipv4_copy_dscp_inner_1), 15302 TEST_CASE_NAMED_ST( 15303 "Tunnel header IPv4 set DSCP 0 (inner 1)", 15304 ut_setup_security, ut_teardown, 15305 test_ipsec_proto_ipv4_set_dscp_0_inner_1), 15306 TEST_CASE_NAMED_ST( 15307 "Tunnel header IPv4 set DSCP 1 (inner 0)", 15308 ut_setup_security, ut_teardown, 15309 test_ipsec_proto_ipv4_set_dscp_1_inner_0), 15310 TEST_CASE_NAMED_ST( 15311 "Tunnel header IPv6 copy DSCP (inner 0)", 15312 ut_setup_security, ut_teardown, 15313 test_ipsec_proto_ipv6_copy_dscp_inner_0), 15314 TEST_CASE_NAMED_ST( 15315 "Tunnel header IPv6 copy DSCP (inner 1)", 15316 ut_setup_security, ut_teardown, 15317 test_ipsec_proto_ipv6_copy_dscp_inner_1), 15318 TEST_CASE_NAMED_ST( 15319 "Tunnel header IPv6 set DSCP 0 (inner 1)", 15320 ut_setup_security, ut_teardown, 15321 test_ipsec_proto_ipv6_set_dscp_0_inner_1), 15322 TEST_CASE_NAMED_ST( 15323 "Tunnel header IPv6 set DSCP 1 (inner 0)", 15324 ut_setup_security, ut_teardown, 15325 test_ipsec_proto_ipv6_set_dscp_1_inner_0), 15326 TEST_CASE_NAMED_WITH_DATA( 15327 "Antireplay with window size 1024", 15328 ut_setup_security, ut_teardown, 15329 test_ipsec_proto_pkt_antireplay1024, &pkt_aes_128_gcm), 15330 TEST_CASE_NAMED_WITH_DATA( 15331 "Antireplay with window size 2048", 15332 ut_setup_security, ut_teardown, 15333 test_ipsec_proto_pkt_antireplay2048, &pkt_aes_128_gcm), 15334 TEST_CASE_NAMED_WITH_DATA( 15335 "Antireplay with window size 4096", 15336 ut_setup_security, ut_teardown, 15337 test_ipsec_proto_pkt_antireplay4096, &pkt_aes_128_gcm), 15338 TEST_CASE_NAMED_WITH_DATA( 15339 "ESN and Antireplay with window size 1024", 15340 ut_setup_security, ut_teardown, 15341 test_ipsec_proto_pkt_esn_antireplay1024, 15342 &pkt_aes_128_gcm), 15343 TEST_CASE_NAMED_WITH_DATA( 15344 "ESN and Antireplay with window size 2048", 15345 ut_setup_security, ut_teardown, 15346 test_ipsec_proto_pkt_esn_antireplay2048, 15347 &pkt_aes_128_gcm), 15348 TEST_CASE_NAMED_WITH_DATA( 15349 "ESN and Antireplay with window size 4096", 15350 ut_setup_security, ut_teardown, 15351 test_ipsec_proto_pkt_esn_antireplay4096, 15352 &pkt_aes_128_gcm), 15353 TEST_CASE_NAMED_ST( 15354 "Tunnel header IPv4 decrement inner TTL", 15355 ut_setup_security, ut_teardown, 15356 test_ipsec_proto_ipv4_ttl_decrement), 15357 TEST_CASE_NAMED_ST( 15358 "Tunnel header IPv6 decrement inner hop limit", 15359 ut_setup_security, ut_teardown, 15360 test_ipsec_proto_ipv6_hop_limit_decrement), 15361 TEST_CASES_END() /**< NULL terminate unit test array */ 15362 } 15363 }; 15364 15365 static struct unit_test_suite pdcp_proto_testsuite = { 15366 .suite_name = "PDCP Proto Unit Test Suite", 15367 .setup = pdcp_proto_testsuite_setup, 15368 .unit_test_cases = { 15369 TEST_CASE_ST(ut_setup_security, ut_teardown, 15370 test_PDCP_PROTO_all), 15371 TEST_CASES_END() /**< NULL terminate unit test array */ 15372 } 15373 }; 15374 15375 #define ADD_UPLINK_TESTCASE(data) \ 15376 TEST_CASE_NAMED_WITH_DATA(data.test_descr_uplink, ut_setup_security, \ 15377 ut_teardown, test_docsis_proto_uplink, (const void *) &data), \ 15378 15379 #define ADD_DOWNLINK_TESTCASE(data) \ 15380 TEST_CASE_NAMED_WITH_DATA(data.test_descr_downlink, ut_setup_security, \ 15381 ut_teardown, test_docsis_proto_downlink, (const void *) &data), \ 15382 15383 static struct unit_test_suite docsis_proto_testsuite = { 15384 .suite_name = "DOCSIS Proto Unit Test Suite", 15385 .setup = docsis_proto_testsuite_setup, 15386 .unit_test_cases = { 15387 /* Uplink */ 15388 ADD_UPLINK_TESTCASE(docsis_test_case_1) 15389 ADD_UPLINK_TESTCASE(docsis_test_case_2) 15390 ADD_UPLINK_TESTCASE(docsis_test_case_3) 15391 ADD_UPLINK_TESTCASE(docsis_test_case_4) 15392 ADD_UPLINK_TESTCASE(docsis_test_case_5) 15393 ADD_UPLINK_TESTCASE(docsis_test_case_6) 15394 ADD_UPLINK_TESTCASE(docsis_test_case_7) 15395 ADD_UPLINK_TESTCASE(docsis_test_case_8) 15396 ADD_UPLINK_TESTCASE(docsis_test_case_9) 15397 ADD_UPLINK_TESTCASE(docsis_test_case_10) 15398 ADD_UPLINK_TESTCASE(docsis_test_case_11) 15399 ADD_UPLINK_TESTCASE(docsis_test_case_12) 15400 ADD_UPLINK_TESTCASE(docsis_test_case_13) 15401 ADD_UPLINK_TESTCASE(docsis_test_case_14) 15402 ADD_UPLINK_TESTCASE(docsis_test_case_15) 15403 ADD_UPLINK_TESTCASE(docsis_test_case_16) 15404 ADD_UPLINK_TESTCASE(docsis_test_case_17) 15405 ADD_UPLINK_TESTCASE(docsis_test_case_18) 15406 ADD_UPLINK_TESTCASE(docsis_test_case_19) 15407 ADD_UPLINK_TESTCASE(docsis_test_case_20) 15408 ADD_UPLINK_TESTCASE(docsis_test_case_21) 15409 ADD_UPLINK_TESTCASE(docsis_test_case_22) 15410 ADD_UPLINK_TESTCASE(docsis_test_case_23) 15411 ADD_UPLINK_TESTCASE(docsis_test_case_24) 15412 ADD_UPLINK_TESTCASE(docsis_test_case_25) 15413 ADD_UPLINK_TESTCASE(docsis_test_case_26) 15414 /* Downlink */ 15415 ADD_DOWNLINK_TESTCASE(docsis_test_case_1) 15416 ADD_DOWNLINK_TESTCASE(docsis_test_case_2) 15417 ADD_DOWNLINK_TESTCASE(docsis_test_case_3) 15418 ADD_DOWNLINK_TESTCASE(docsis_test_case_4) 15419 ADD_DOWNLINK_TESTCASE(docsis_test_case_5) 15420 ADD_DOWNLINK_TESTCASE(docsis_test_case_6) 15421 ADD_DOWNLINK_TESTCASE(docsis_test_case_7) 15422 ADD_DOWNLINK_TESTCASE(docsis_test_case_8) 15423 ADD_DOWNLINK_TESTCASE(docsis_test_case_9) 15424 ADD_DOWNLINK_TESTCASE(docsis_test_case_10) 15425 ADD_DOWNLINK_TESTCASE(docsis_test_case_11) 15426 ADD_DOWNLINK_TESTCASE(docsis_test_case_12) 15427 ADD_DOWNLINK_TESTCASE(docsis_test_case_13) 15428 ADD_DOWNLINK_TESTCASE(docsis_test_case_14) 15429 ADD_DOWNLINK_TESTCASE(docsis_test_case_15) 15430 ADD_DOWNLINK_TESTCASE(docsis_test_case_16) 15431 ADD_DOWNLINK_TESTCASE(docsis_test_case_17) 15432 ADD_DOWNLINK_TESTCASE(docsis_test_case_18) 15433 ADD_DOWNLINK_TESTCASE(docsis_test_case_19) 15434 ADD_DOWNLINK_TESTCASE(docsis_test_case_20) 15435 ADD_DOWNLINK_TESTCASE(docsis_test_case_21) 15436 ADD_DOWNLINK_TESTCASE(docsis_test_case_22) 15437 ADD_DOWNLINK_TESTCASE(docsis_test_case_23) 15438 ADD_DOWNLINK_TESTCASE(docsis_test_case_24) 15439 ADD_DOWNLINK_TESTCASE(docsis_test_case_25) 15440 ADD_DOWNLINK_TESTCASE(docsis_test_case_26) 15441 TEST_CASES_END() /**< NULL terminate unit test array */ 15442 } 15443 }; 15444 #endif 15445 15446 static struct unit_test_suite cryptodev_gen_testsuite = { 15447 .suite_name = "Crypto General Unit Test Suite", 15448 .setup = crypto_gen_testsuite_setup, 15449 .unit_test_cases = { 15450 TEST_CASE_ST(ut_setup, ut_teardown, 15451 test_device_configure_invalid_dev_id), 15452 TEST_CASE_ST(ut_setup, ut_teardown, 15453 test_queue_pair_descriptor_setup), 15454 TEST_CASE_ST(ut_setup, ut_teardown, 15455 test_device_configure_invalid_queue_pair_ids), 15456 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 15457 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup), 15458 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup), 15459 TEST_CASES_END() /**< NULL terminate unit test array */ 15460 } 15461 }; 15462 15463 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = { 15464 .suite_name = "Negative HMAC SHA1 Unit Test Suite", 15465 .setup = negative_hmac_sha1_testsuite_setup, 15466 .unit_test_cases = { 15467 /** Negative tests */ 15468 TEST_CASE_ST(ut_setup, ut_teardown, 15469 authentication_verify_HMAC_SHA1_fail_data_corrupt), 15470 TEST_CASE_ST(ut_setup, ut_teardown, 15471 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 15472 TEST_CASE_ST(ut_setup, ut_teardown, 15473 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 15474 TEST_CASE_ST(ut_setup, ut_teardown, 15475 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 15476 15477 TEST_CASES_END() /**< NULL terminate unit test array */ 15478 } 15479 }; 15480 15481 static struct unit_test_suite cryptodev_multi_session_testsuite = { 15482 .suite_name = "Multi Session Unit Test Suite", 15483 .setup = multi_session_testsuite_setup, 15484 .unit_test_cases = { 15485 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 15486 TEST_CASE_ST(ut_setup, ut_teardown, 15487 test_multi_session_random_usage), 15488 15489 TEST_CASES_END() /**< NULL terminate unit test array */ 15490 } 15491 }; 15492 15493 static struct unit_test_suite cryptodev_null_testsuite = { 15494 .suite_name = "NULL Test Suite", 15495 .setup = null_testsuite_setup, 15496 .unit_test_cases = { 15497 TEST_CASE_ST(ut_setup, ut_teardown, 15498 test_null_invalid_operation), 15499 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation), 15500 TEST_CASES_END() 15501 } 15502 }; 15503 15504 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite = { 15505 .suite_name = "AES CCM Authenticated Test Suite", 15506 .setup = aes_ccm_auth_testsuite_setup, 15507 .unit_test_cases = { 15508 /** AES CCM Authenticated Encryption 128 bits key*/ 15509 TEST_CASE_ST(ut_setup, ut_teardown, 15510 test_AES_CCM_authenticated_encryption_test_case_128_1), 15511 TEST_CASE_ST(ut_setup, ut_teardown, 15512 test_AES_CCM_authenticated_encryption_test_case_128_2), 15513 TEST_CASE_ST(ut_setup, ut_teardown, 15514 test_AES_CCM_authenticated_encryption_test_case_128_3), 15515 15516 /** AES CCM Authenticated Decryption 128 bits key*/ 15517 TEST_CASE_ST(ut_setup, ut_teardown, 15518 test_AES_CCM_authenticated_decryption_test_case_128_1), 15519 TEST_CASE_ST(ut_setup, ut_teardown, 15520 test_AES_CCM_authenticated_decryption_test_case_128_2), 15521 TEST_CASE_ST(ut_setup, ut_teardown, 15522 test_AES_CCM_authenticated_decryption_test_case_128_3), 15523 15524 /** AES CCM Authenticated Encryption 192 bits key */ 15525 TEST_CASE_ST(ut_setup, ut_teardown, 15526 test_AES_CCM_authenticated_encryption_test_case_192_1), 15527 TEST_CASE_ST(ut_setup, ut_teardown, 15528 test_AES_CCM_authenticated_encryption_test_case_192_2), 15529 TEST_CASE_ST(ut_setup, ut_teardown, 15530 test_AES_CCM_authenticated_encryption_test_case_192_3), 15531 15532 /** AES CCM Authenticated Decryption 192 bits key*/ 15533 TEST_CASE_ST(ut_setup, ut_teardown, 15534 test_AES_CCM_authenticated_decryption_test_case_192_1), 15535 TEST_CASE_ST(ut_setup, ut_teardown, 15536 test_AES_CCM_authenticated_decryption_test_case_192_2), 15537 TEST_CASE_ST(ut_setup, ut_teardown, 15538 test_AES_CCM_authenticated_decryption_test_case_192_3), 15539 15540 /** AES CCM Authenticated Encryption 256 bits key */ 15541 TEST_CASE_ST(ut_setup, ut_teardown, 15542 test_AES_CCM_authenticated_encryption_test_case_256_1), 15543 TEST_CASE_ST(ut_setup, ut_teardown, 15544 test_AES_CCM_authenticated_encryption_test_case_256_2), 15545 TEST_CASE_ST(ut_setup, ut_teardown, 15546 test_AES_CCM_authenticated_encryption_test_case_256_3), 15547 15548 /** AES CCM Authenticated Decryption 256 bits key*/ 15549 TEST_CASE_ST(ut_setup, ut_teardown, 15550 test_AES_CCM_authenticated_decryption_test_case_256_1), 15551 TEST_CASE_ST(ut_setup, ut_teardown, 15552 test_AES_CCM_authenticated_decryption_test_case_256_2), 15553 TEST_CASE_ST(ut_setup, ut_teardown, 15554 test_AES_CCM_authenticated_decryption_test_case_256_3), 15555 TEST_CASES_END() 15556 } 15557 }; 15558 15559 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite = { 15560 .suite_name = "AES GCM Authenticated Test Suite", 15561 .setup = aes_gcm_auth_testsuite_setup, 15562 .unit_test_cases = { 15563 /** AES GCM Authenticated Encryption */ 15564 TEST_CASE_ST(ut_setup, ut_teardown, 15565 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 15566 TEST_CASE_ST(ut_setup, ut_teardown, 15567 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 15568 TEST_CASE_ST(ut_setup, ut_teardown, 15569 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 15570 TEST_CASE_ST(ut_setup, ut_teardown, 15571 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 15572 TEST_CASE_ST(ut_setup, ut_teardown, 15573 test_AES_GCM_authenticated_encryption_test_case_1), 15574 TEST_CASE_ST(ut_setup, ut_teardown, 15575 test_AES_GCM_authenticated_encryption_test_case_2), 15576 TEST_CASE_ST(ut_setup, ut_teardown, 15577 test_AES_GCM_authenticated_encryption_test_case_3), 15578 TEST_CASE_ST(ut_setup, ut_teardown, 15579 test_AES_GCM_authenticated_encryption_test_case_4), 15580 TEST_CASE_ST(ut_setup, ut_teardown, 15581 test_AES_GCM_authenticated_encryption_test_case_5), 15582 TEST_CASE_ST(ut_setup, ut_teardown, 15583 test_AES_GCM_authenticated_encryption_test_case_6), 15584 TEST_CASE_ST(ut_setup, ut_teardown, 15585 test_AES_GCM_authenticated_encryption_test_case_7), 15586 TEST_CASE_ST(ut_setup, ut_teardown, 15587 test_AES_GCM_authenticated_encryption_test_case_8), 15588 TEST_CASE_ST(ut_setup, ut_teardown, 15589 test_AES_GCM_J0_authenticated_encryption_test_case_1), 15590 15591 /** AES GCM Authenticated Decryption */ 15592 TEST_CASE_ST(ut_setup, ut_teardown, 15593 test_AES_GCM_authenticated_decryption_test_case_1), 15594 TEST_CASE_ST(ut_setup, ut_teardown, 15595 test_AES_GCM_authenticated_decryption_test_case_2), 15596 TEST_CASE_ST(ut_setup, ut_teardown, 15597 test_AES_GCM_authenticated_decryption_test_case_3), 15598 TEST_CASE_ST(ut_setup, ut_teardown, 15599 test_AES_GCM_authenticated_decryption_test_case_4), 15600 TEST_CASE_ST(ut_setup, ut_teardown, 15601 test_AES_GCM_authenticated_decryption_test_case_5), 15602 TEST_CASE_ST(ut_setup, ut_teardown, 15603 test_AES_GCM_authenticated_decryption_test_case_6), 15604 TEST_CASE_ST(ut_setup, ut_teardown, 15605 test_AES_GCM_authenticated_decryption_test_case_7), 15606 TEST_CASE_ST(ut_setup, ut_teardown, 15607 test_AES_GCM_authenticated_decryption_test_case_8), 15608 TEST_CASE_ST(ut_setup, ut_teardown, 15609 test_AES_GCM_J0_authenticated_decryption_test_case_1), 15610 15611 /** AES GCM Authenticated Encryption 192 bits key */ 15612 TEST_CASE_ST(ut_setup, ut_teardown, 15613 test_AES_GCM_auth_encryption_test_case_192_1), 15614 TEST_CASE_ST(ut_setup, ut_teardown, 15615 test_AES_GCM_auth_encryption_test_case_192_2), 15616 TEST_CASE_ST(ut_setup, ut_teardown, 15617 test_AES_GCM_auth_encryption_test_case_192_3), 15618 TEST_CASE_ST(ut_setup, ut_teardown, 15619 test_AES_GCM_auth_encryption_test_case_192_4), 15620 TEST_CASE_ST(ut_setup, ut_teardown, 15621 test_AES_GCM_auth_encryption_test_case_192_5), 15622 TEST_CASE_ST(ut_setup, ut_teardown, 15623 test_AES_GCM_auth_encryption_test_case_192_6), 15624 TEST_CASE_ST(ut_setup, ut_teardown, 15625 test_AES_GCM_auth_encryption_test_case_192_7), 15626 15627 /** AES GCM Authenticated Decryption 192 bits key */ 15628 TEST_CASE_ST(ut_setup, ut_teardown, 15629 test_AES_GCM_auth_decryption_test_case_192_1), 15630 TEST_CASE_ST(ut_setup, ut_teardown, 15631 test_AES_GCM_auth_decryption_test_case_192_2), 15632 TEST_CASE_ST(ut_setup, ut_teardown, 15633 test_AES_GCM_auth_decryption_test_case_192_3), 15634 TEST_CASE_ST(ut_setup, ut_teardown, 15635 test_AES_GCM_auth_decryption_test_case_192_4), 15636 TEST_CASE_ST(ut_setup, ut_teardown, 15637 test_AES_GCM_auth_decryption_test_case_192_5), 15638 TEST_CASE_ST(ut_setup, ut_teardown, 15639 test_AES_GCM_auth_decryption_test_case_192_6), 15640 TEST_CASE_ST(ut_setup, ut_teardown, 15641 test_AES_GCM_auth_decryption_test_case_192_7), 15642 15643 /** AES GCM Authenticated Encryption 256 bits key */ 15644 TEST_CASE_ST(ut_setup, ut_teardown, 15645 test_AES_GCM_auth_encryption_test_case_256_1), 15646 TEST_CASE_ST(ut_setup, ut_teardown, 15647 test_AES_GCM_auth_encryption_test_case_256_2), 15648 TEST_CASE_ST(ut_setup, ut_teardown, 15649 test_AES_GCM_auth_encryption_test_case_256_3), 15650 TEST_CASE_ST(ut_setup, ut_teardown, 15651 test_AES_GCM_auth_encryption_test_case_256_4), 15652 TEST_CASE_ST(ut_setup, ut_teardown, 15653 test_AES_GCM_auth_encryption_test_case_256_5), 15654 TEST_CASE_ST(ut_setup, ut_teardown, 15655 test_AES_GCM_auth_encryption_test_case_256_6), 15656 TEST_CASE_ST(ut_setup, ut_teardown, 15657 test_AES_GCM_auth_encryption_test_case_256_7), 15658 15659 /** AES GCM Authenticated Decryption 256 bits key */ 15660 TEST_CASE_ST(ut_setup, ut_teardown, 15661 test_AES_GCM_auth_decryption_test_case_256_1), 15662 TEST_CASE_ST(ut_setup, ut_teardown, 15663 test_AES_GCM_auth_decryption_test_case_256_2), 15664 TEST_CASE_ST(ut_setup, ut_teardown, 15665 test_AES_GCM_auth_decryption_test_case_256_3), 15666 TEST_CASE_ST(ut_setup, ut_teardown, 15667 test_AES_GCM_auth_decryption_test_case_256_4), 15668 TEST_CASE_ST(ut_setup, ut_teardown, 15669 test_AES_GCM_auth_decryption_test_case_256_5), 15670 TEST_CASE_ST(ut_setup, ut_teardown, 15671 test_AES_GCM_auth_decryption_test_case_256_6), 15672 TEST_CASE_ST(ut_setup, ut_teardown, 15673 test_AES_GCM_auth_decryption_test_case_256_7), 15674 15675 /** AES GCM Authenticated Encryption big aad size */ 15676 TEST_CASE_ST(ut_setup, ut_teardown, 15677 test_AES_GCM_auth_encryption_test_case_aad_1), 15678 TEST_CASE_ST(ut_setup, ut_teardown, 15679 test_AES_GCM_auth_encryption_test_case_aad_2), 15680 15681 /** AES GCM Authenticated Decryption big aad size */ 15682 TEST_CASE_ST(ut_setup, ut_teardown, 15683 test_AES_GCM_auth_decryption_test_case_aad_1), 15684 TEST_CASE_ST(ut_setup, ut_teardown, 15685 test_AES_GCM_auth_decryption_test_case_aad_2), 15686 15687 /** Out of place tests */ 15688 TEST_CASE_ST(ut_setup, ut_teardown, 15689 test_AES_GCM_authenticated_encryption_oop_test_case_1), 15690 TEST_CASE_ST(ut_setup, ut_teardown, 15691 test_AES_GCM_authenticated_decryption_oop_test_case_1), 15692 15693 /** Session-less tests */ 15694 TEST_CASE_ST(ut_setup, ut_teardown, 15695 test_AES_GCM_authenticated_encryption_sessionless_test_case_1), 15696 TEST_CASE_ST(ut_setup, ut_teardown, 15697 test_AES_GCM_authenticated_decryption_sessionless_test_case_1), 15698 15699 TEST_CASES_END() 15700 } 15701 }; 15702 15703 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite = { 15704 .suite_name = "AES GMAC Authentication Test Suite", 15705 .setup = aes_gmac_auth_testsuite_setup, 15706 .unit_test_cases = { 15707 TEST_CASE_ST(ut_setup, ut_teardown, 15708 test_AES_GMAC_authentication_test_case_1), 15709 TEST_CASE_ST(ut_setup, ut_teardown, 15710 test_AES_GMAC_authentication_verify_test_case_1), 15711 TEST_CASE_ST(ut_setup, ut_teardown, 15712 test_AES_GMAC_authentication_test_case_2), 15713 TEST_CASE_ST(ut_setup, ut_teardown, 15714 test_AES_GMAC_authentication_verify_test_case_2), 15715 TEST_CASE_ST(ut_setup, ut_teardown, 15716 test_AES_GMAC_authentication_test_case_3), 15717 TEST_CASE_ST(ut_setup, ut_teardown, 15718 test_AES_GMAC_authentication_verify_test_case_3), 15719 TEST_CASE_ST(ut_setup, ut_teardown, 15720 test_AES_GMAC_authentication_test_case_4), 15721 TEST_CASE_ST(ut_setup, ut_teardown, 15722 test_AES_GMAC_authentication_verify_test_case_4), 15723 TEST_CASE_ST(ut_setup, ut_teardown, 15724 test_AES_GMAC_authentication_SGL_40B), 15725 TEST_CASE_ST(ut_setup, ut_teardown, 15726 test_AES_GMAC_authentication_SGL_80B), 15727 TEST_CASE_ST(ut_setup, ut_teardown, 15728 test_AES_GMAC_authentication_SGL_2048B), 15729 TEST_CASE_ST(ut_setup, ut_teardown, 15730 test_AES_GMAC_authentication_SGL_2047B), 15731 15732 TEST_CASES_END() 15733 } 15734 }; 15735 15736 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite = { 15737 .suite_name = "Chacha20-Poly1305 Test Suite", 15738 .setup = chacha20_poly1305_testsuite_setup, 15739 .unit_test_cases = { 15740 TEST_CASE_ST(ut_setup, ut_teardown, 15741 test_chacha20_poly1305_encrypt_test_case_rfc8439), 15742 TEST_CASE_ST(ut_setup, ut_teardown, 15743 test_chacha20_poly1305_decrypt_test_case_rfc8439), 15744 TEST_CASE_ST(ut_setup, ut_teardown, 15745 test_chacha20_poly1305_encrypt_SGL_out_of_place), 15746 TEST_CASES_END() 15747 } 15748 }; 15749 15750 static struct unit_test_suite cryptodev_snow3g_testsuite = { 15751 .suite_name = "SNOW 3G Test Suite", 15752 .setup = snow3g_testsuite_setup, 15753 .unit_test_cases = { 15754 /** SNOW 3G encrypt only (UEA2) */ 15755 TEST_CASE_ST(ut_setup, ut_teardown, 15756 test_snow3g_encryption_test_case_1), 15757 TEST_CASE_ST(ut_setup, ut_teardown, 15758 test_snow3g_encryption_test_case_2), 15759 TEST_CASE_ST(ut_setup, ut_teardown, 15760 test_snow3g_encryption_test_case_3), 15761 TEST_CASE_ST(ut_setup, ut_teardown, 15762 test_snow3g_encryption_test_case_4), 15763 TEST_CASE_ST(ut_setup, ut_teardown, 15764 test_snow3g_encryption_test_case_5), 15765 15766 TEST_CASE_ST(ut_setup, ut_teardown, 15767 test_snow3g_encryption_test_case_1_oop), 15768 TEST_CASE_ST(ut_setup, ut_teardown, 15769 test_snow3g_encryption_test_case_1_oop_sgl), 15770 TEST_CASE_ST(ut_setup, ut_teardown, 15771 test_snow3g_encryption_test_case_1_offset_oop), 15772 TEST_CASE_ST(ut_setup, ut_teardown, 15773 test_snow3g_decryption_test_case_1_oop), 15774 15775 /** SNOW 3G generate auth, then encrypt (UEA2) */ 15776 TEST_CASE_ST(ut_setup, ut_teardown, 15777 test_snow3g_auth_cipher_test_case_1), 15778 TEST_CASE_ST(ut_setup, ut_teardown, 15779 test_snow3g_auth_cipher_test_case_2), 15780 TEST_CASE_ST(ut_setup, ut_teardown, 15781 test_snow3g_auth_cipher_test_case_2_oop), 15782 TEST_CASE_ST(ut_setup, ut_teardown, 15783 test_snow3g_auth_cipher_part_digest_enc), 15784 TEST_CASE_ST(ut_setup, ut_teardown, 15785 test_snow3g_auth_cipher_part_digest_enc_oop), 15786 TEST_CASE_ST(ut_setup, ut_teardown, 15787 test_snow3g_auth_cipher_test_case_3_sgl), 15788 TEST_CASE_ST(ut_setup, ut_teardown, 15789 test_snow3g_auth_cipher_test_case_3_oop_sgl), 15790 TEST_CASE_ST(ut_setup, ut_teardown, 15791 test_snow3g_auth_cipher_part_digest_enc_sgl), 15792 TEST_CASE_ST(ut_setup, ut_teardown, 15793 test_snow3g_auth_cipher_part_digest_enc_oop_sgl), 15794 15795 /** SNOW 3G decrypt (UEA2), then verify auth */ 15796 TEST_CASE_ST(ut_setup, ut_teardown, 15797 test_snow3g_auth_cipher_verify_test_case_1), 15798 TEST_CASE_ST(ut_setup, ut_teardown, 15799 test_snow3g_auth_cipher_verify_test_case_2), 15800 TEST_CASE_ST(ut_setup, ut_teardown, 15801 test_snow3g_auth_cipher_verify_test_case_2_oop), 15802 TEST_CASE_ST(ut_setup, ut_teardown, 15803 test_snow3g_auth_cipher_verify_part_digest_enc), 15804 TEST_CASE_ST(ut_setup, ut_teardown, 15805 test_snow3g_auth_cipher_verify_part_digest_enc_oop), 15806 TEST_CASE_ST(ut_setup, ut_teardown, 15807 test_snow3g_auth_cipher_verify_test_case_3_sgl), 15808 TEST_CASE_ST(ut_setup, ut_teardown, 15809 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl), 15810 TEST_CASE_ST(ut_setup, ut_teardown, 15811 test_snow3g_auth_cipher_verify_part_digest_enc_sgl), 15812 TEST_CASE_ST(ut_setup, ut_teardown, 15813 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl), 15814 15815 /** SNOW 3G decrypt only (UEA2) */ 15816 TEST_CASE_ST(ut_setup, ut_teardown, 15817 test_snow3g_decryption_test_case_1), 15818 TEST_CASE_ST(ut_setup, ut_teardown, 15819 test_snow3g_decryption_test_case_2), 15820 TEST_CASE_ST(ut_setup, ut_teardown, 15821 test_snow3g_decryption_test_case_3), 15822 TEST_CASE_ST(ut_setup, ut_teardown, 15823 test_snow3g_decryption_test_case_4), 15824 TEST_CASE_ST(ut_setup, ut_teardown, 15825 test_snow3g_decryption_test_case_5), 15826 TEST_CASE_ST(ut_setup, ut_teardown, 15827 test_snow3g_decryption_with_digest_test_case_1), 15828 TEST_CASE_ST(ut_setup, ut_teardown, 15829 test_snow3g_hash_generate_test_case_1), 15830 TEST_CASE_ST(ut_setup, ut_teardown, 15831 test_snow3g_hash_generate_test_case_2), 15832 TEST_CASE_ST(ut_setup, ut_teardown, 15833 test_snow3g_hash_generate_test_case_3), 15834 15835 /* Tests with buffers which length is not byte-aligned */ 15836 TEST_CASE_ST(ut_setup, ut_teardown, 15837 test_snow3g_hash_generate_test_case_4), 15838 TEST_CASE_ST(ut_setup, ut_teardown, 15839 test_snow3g_hash_generate_test_case_5), 15840 TEST_CASE_ST(ut_setup, ut_teardown, 15841 test_snow3g_hash_generate_test_case_6), 15842 TEST_CASE_ST(ut_setup, ut_teardown, 15843 test_snow3g_hash_verify_test_case_1), 15844 TEST_CASE_ST(ut_setup, ut_teardown, 15845 test_snow3g_hash_verify_test_case_2), 15846 TEST_CASE_ST(ut_setup, ut_teardown, 15847 test_snow3g_hash_verify_test_case_3), 15848 15849 /* Tests with buffers which length is not byte-aligned */ 15850 TEST_CASE_ST(ut_setup, ut_teardown, 15851 test_snow3g_hash_verify_test_case_4), 15852 TEST_CASE_ST(ut_setup, ut_teardown, 15853 test_snow3g_hash_verify_test_case_5), 15854 TEST_CASE_ST(ut_setup, ut_teardown, 15855 test_snow3g_hash_verify_test_case_6), 15856 TEST_CASE_ST(ut_setup, ut_teardown, 15857 test_snow3g_cipher_auth_test_case_1), 15858 TEST_CASE_ST(ut_setup, ut_teardown, 15859 test_snow3g_auth_cipher_with_digest_test_case_1), 15860 TEST_CASES_END() 15861 } 15862 }; 15863 15864 static struct unit_test_suite cryptodev_zuc_testsuite = { 15865 .suite_name = "ZUC Test Suite", 15866 .setup = zuc_testsuite_setup, 15867 .unit_test_cases = { 15868 /** ZUC encrypt only (EEA3) */ 15869 TEST_CASE_ST(ut_setup, ut_teardown, 15870 test_zuc_encryption_test_case_1), 15871 TEST_CASE_ST(ut_setup, ut_teardown, 15872 test_zuc_encryption_test_case_2), 15873 TEST_CASE_ST(ut_setup, ut_teardown, 15874 test_zuc_encryption_test_case_3), 15875 TEST_CASE_ST(ut_setup, ut_teardown, 15876 test_zuc_encryption_test_case_4), 15877 TEST_CASE_ST(ut_setup, ut_teardown, 15878 test_zuc_encryption_test_case_5), 15879 TEST_CASE_ST(ut_setup, ut_teardown, 15880 test_zuc_encryption_test_case_6_sgl), 15881 15882 /** ZUC authenticate (EIA3) */ 15883 TEST_CASE_ST(ut_setup, ut_teardown, 15884 test_zuc_hash_generate_test_case_1), 15885 TEST_CASE_ST(ut_setup, ut_teardown, 15886 test_zuc_hash_generate_test_case_2), 15887 TEST_CASE_ST(ut_setup, ut_teardown, 15888 test_zuc_hash_generate_test_case_3), 15889 TEST_CASE_ST(ut_setup, ut_teardown, 15890 test_zuc_hash_generate_test_case_4), 15891 TEST_CASE_ST(ut_setup, ut_teardown, 15892 test_zuc_hash_generate_test_case_5), 15893 TEST_CASE_ST(ut_setup, ut_teardown, 15894 test_zuc_hash_generate_test_case_6), 15895 TEST_CASE_ST(ut_setup, ut_teardown, 15896 test_zuc_hash_generate_test_case_7), 15897 TEST_CASE_ST(ut_setup, ut_teardown, 15898 test_zuc_hash_generate_test_case_8), 15899 TEST_CASE_ST(ut_setup, ut_teardown, 15900 test_zuc_hash_generate_test_case_9), 15901 TEST_CASE_ST(ut_setup, ut_teardown, 15902 test_zuc_hash_generate_test_case_10), 15903 TEST_CASE_ST(ut_setup, ut_teardown, 15904 test_zuc_hash_generate_test_case_11), 15905 15906 15907 /** ZUC alg-chain (EEA3/EIA3) */ 15908 TEST_CASE_ST(ut_setup, ut_teardown, 15909 test_zuc_cipher_auth_test_case_1), 15910 TEST_CASE_ST(ut_setup, ut_teardown, 15911 test_zuc_cipher_auth_test_case_2), 15912 15913 /** ZUC generate auth, then encrypt (EEA3) */ 15914 TEST_CASE_ST(ut_setup, ut_teardown, 15915 test_zuc_auth_cipher_test_case_1), 15916 TEST_CASE_ST(ut_setup, ut_teardown, 15917 test_zuc_auth_cipher_test_case_1_oop), 15918 TEST_CASE_ST(ut_setup, ut_teardown, 15919 test_zuc_auth_cipher_test_case_1_sgl), 15920 TEST_CASE_ST(ut_setup, ut_teardown, 15921 test_zuc_auth_cipher_test_case_1_oop_sgl), 15922 15923 /** ZUC decrypt (EEA3), then verify auth */ 15924 TEST_CASE_ST(ut_setup, ut_teardown, 15925 test_zuc_auth_cipher_verify_test_case_1), 15926 TEST_CASE_ST(ut_setup, ut_teardown, 15927 test_zuc_auth_cipher_verify_test_case_1_oop), 15928 TEST_CASE_ST(ut_setup, ut_teardown, 15929 test_zuc_auth_cipher_verify_test_case_1_sgl), 15930 TEST_CASE_ST(ut_setup, ut_teardown, 15931 test_zuc_auth_cipher_verify_test_case_1_oop_sgl), 15932 15933 /** ZUC-256 encrypt only **/ 15934 TEST_CASE_ST(ut_setup, ut_teardown, 15935 test_zuc256_encryption_test_case_1), 15936 TEST_CASE_ST(ut_setup, ut_teardown, 15937 test_zuc256_encryption_test_case_2), 15938 15939 /** ZUC-256 authentication only **/ 15940 TEST_CASE_ST(ut_setup, ut_teardown, 15941 test_zuc256_authentication_test_case_1), 15942 TEST_CASE_ST(ut_setup, ut_teardown, 15943 test_zuc256_authentication_test_case_2), 15944 15945 TEST_CASES_END() 15946 } 15947 }; 15948 15949 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite = { 15950 .suite_name = "HMAC_MD5 Authentication Test Suite", 15951 .setup = hmac_md5_auth_testsuite_setup, 15952 .unit_test_cases = { 15953 TEST_CASE_ST(ut_setup, ut_teardown, 15954 test_MD5_HMAC_generate_case_1), 15955 TEST_CASE_ST(ut_setup, ut_teardown, 15956 test_MD5_HMAC_verify_case_1), 15957 TEST_CASE_ST(ut_setup, ut_teardown, 15958 test_MD5_HMAC_generate_case_2), 15959 TEST_CASE_ST(ut_setup, ut_teardown, 15960 test_MD5_HMAC_verify_case_2), 15961 TEST_CASES_END() 15962 } 15963 }; 15964 15965 static struct unit_test_suite cryptodev_kasumi_testsuite = { 15966 .suite_name = "Kasumi Test Suite", 15967 .setup = kasumi_testsuite_setup, 15968 .unit_test_cases = { 15969 /** KASUMI hash only (UIA1) */ 15970 TEST_CASE_ST(ut_setup, ut_teardown, 15971 test_kasumi_hash_generate_test_case_1), 15972 TEST_CASE_ST(ut_setup, ut_teardown, 15973 test_kasumi_hash_generate_test_case_2), 15974 TEST_CASE_ST(ut_setup, ut_teardown, 15975 test_kasumi_hash_generate_test_case_3), 15976 TEST_CASE_ST(ut_setup, ut_teardown, 15977 test_kasumi_hash_generate_test_case_4), 15978 TEST_CASE_ST(ut_setup, ut_teardown, 15979 test_kasumi_hash_generate_test_case_5), 15980 TEST_CASE_ST(ut_setup, ut_teardown, 15981 test_kasumi_hash_generate_test_case_6), 15982 15983 TEST_CASE_ST(ut_setup, ut_teardown, 15984 test_kasumi_hash_verify_test_case_1), 15985 TEST_CASE_ST(ut_setup, ut_teardown, 15986 test_kasumi_hash_verify_test_case_2), 15987 TEST_CASE_ST(ut_setup, ut_teardown, 15988 test_kasumi_hash_verify_test_case_3), 15989 TEST_CASE_ST(ut_setup, ut_teardown, 15990 test_kasumi_hash_verify_test_case_4), 15991 TEST_CASE_ST(ut_setup, ut_teardown, 15992 test_kasumi_hash_verify_test_case_5), 15993 15994 /** KASUMI encrypt only (UEA1) */ 15995 TEST_CASE_ST(ut_setup, ut_teardown, 15996 test_kasumi_encryption_test_case_1), 15997 TEST_CASE_ST(ut_setup, ut_teardown, 15998 test_kasumi_encryption_test_case_1_sgl), 15999 TEST_CASE_ST(ut_setup, ut_teardown, 16000 test_kasumi_encryption_test_case_1_oop), 16001 TEST_CASE_ST(ut_setup, ut_teardown, 16002 test_kasumi_encryption_test_case_1_oop_sgl), 16003 TEST_CASE_ST(ut_setup, ut_teardown, 16004 test_kasumi_encryption_test_case_2), 16005 TEST_CASE_ST(ut_setup, ut_teardown, 16006 test_kasumi_encryption_test_case_3), 16007 TEST_CASE_ST(ut_setup, ut_teardown, 16008 test_kasumi_encryption_test_case_4), 16009 TEST_CASE_ST(ut_setup, ut_teardown, 16010 test_kasumi_encryption_test_case_5), 16011 16012 /** KASUMI decrypt only (UEA1) */ 16013 TEST_CASE_ST(ut_setup, ut_teardown, 16014 test_kasumi_decryption_test_case_1), 16015 TEST_CASE_ST(ut_setup, ut_teardown, 16016 test_kasumi_decryption_test_case_2), 16017 TEST_CASE_ST(ut_setup, ut_teardown, 16018 test_kasumi_decryption_test_case_3), 16019 TEST_CASE_ST(ut_setup, ut_teardown, 16020 test_kasumi_decryption_test_case_4), 16021 TEST_CASE_ST(ut_setup, ut_teardown, 16022 test_kasumi_decryption_test_case_5), 16023 TEST_CASE_ST(ut_setup, ut_teardown, 16024 test_kasumi_decryption_test_case_1_oop), 16025 TEST_CASE_ST(ut_setup, ut_teardown, 16026 test_kasumi_cipher_auth_test_case_1), 16027 16028 /** KASUMI generate auth, then encrypt (F8) */ 16029 TEST_CASE_ST(ut_setup, ut_teardown, 16030 test_kasumi_auth_cipher_test_case_1), 16031 TEST_CASE_ST(ut_setup, ut_teardown, 16032 test_kasumi_auth_cipher_test_case_2), 16033 TEST_CASE_ST(ut_setup, ut_teardown, 16034 test_kasumi_auth_cipher_test_case_2_oop), 16035 TEST_CASE_ST(ut_setup, ut_teardown, 16036 test_kasumi_auth_cipher_test_case_2_sgl), 16037 TEST_CASE_ST(ut_setup, ut_teardown, 16038 test_kasumi_auth_cipher_test_case_2_oop_sgl), 16039 16040 /** KASUMI decrypt (F8), then verify auth */ 16041 TEST_CASE_ST(ut_setup, ut_teardown, 16042 test_kasumi_auth_cipher_verify_test_case_1), 16043 TEST_CASE_ST(ut_setup, ut_teardown, 16044 test_kasumi_auth_cipher_verify_test_case_2), 16045 TEST_CASE_ST(ut_setup, ut_teardown, 16046 test_kasumi_auth_cipher_verify_test_case_2_oop), 16047 TEST_CASE_ST(ut_setup, ut_teardown, 16048 test_kasumi_auth_cipher_verify_test_case_2_sgl), 16049 TEST_CASE_ST(ut_setup, ut_teardown, 16050 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl), 16051 16052 TEST_CASES_END() 16053 } 16054 }; 16055 16056 static struct unit_test_suite cryptodev_esn_testsuite = { 16057 .suite_name = "ESN Test Suite", 16058 .setup = esn_testsuite_setup, 16059 .unit_test_cases = { 16060 TEST_CASE_ST(ut_setup, ut_teardown, 16061 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 16062 TEST_CASE_ST(ut_setup, ut_teardown, 16063 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 16064 TEST_CASES_END() 16065 } 16066 }; 16067 16068 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite = { 16069 .suite_name = "Negative AES GCM Test Suite", 16070 .setup = negative_aes_gcm_testsuite_setup, 16071 .unit_test_cases = { 16072 TEST_CASE_ST(ut_setup, ut_teardown, 16073 test_AES_GCM_auth_encryption_fail_iv_corrupt), 16074 TEST_CASE_ST(ut_setup, ut_teardown, 16075 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 16076 TEST_CASE_ST(ut_setup, ut_teardown, 16077 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 16078 TEST_CASE_ST(ut_setup, ut_teardown, 16079 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 16080 TEST_CASE_ST(ut_setup, ut_teardown, 16081 test_AES_GCM_auth_encryption_fail_aad_corrupt), 16082 TEST_CASE_ST(ut_setup, ut_teardown, 16083 test_AES_GCM_auth_encryption_fail_tag_corrupt), 16084 TEST_CASE_ST(ut_setup, ut_teardown, 16085 test_AES_GCM_auth_decryption_fail_iv_corrupt), 16086 TEST_CASE_ST(ut_setup, ut_teardown, 16087 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 16088 TEST_CASE_ST(ut_setup, ut_teardown, 16089 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 16090 TEST_CASE_ST(ut_setup, ut_teardown, 16091 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 16092 TEST_CASE_ST(ut_setup, ut_teardown, 16093 test_AES_GCM_auth_decryption_fail_aad_corrupt), 16094 TEST_CASE_ST(ut_setup, ut_teardown, 16095 test_AES_GCM_auth_decryption_fail_tag_corrupt), 16096 16097 TEST_CASES_END() 16098 } 16099 }; 16100 16101 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite = { 16102 .suite_name = "Negative AES GMAC Test Suite", 16103 .setup = negative_aes_gmac_testsuite_setup, 16104 .unit_test_cases = { 16105 TEST_CASE_ST(ut_setup, ut_teardown, 16106 authentication_verify_AES128_GMAC_fail_data_corrupt), 16107 TEST_CASE_ST(ut_setup, ut_teardown, 16108 authentication_verify_AES128_GMAC_fail_tag_corrupt), 16109 16110 TEST_CASES_END() 16111 } 16112 }; 16113 16114 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite = { 16115 .suite_name = "Mixed CIPHER + HASH algorithms Test Suite", 16116 .setup = mixed_cipher_hash_testsuite_setup, 16117 .unit_test_cases = { 16118 /** AUTH AES CMAC + CIPHER AES CTR */ 16119 TEST_CASE_ST(ut_setup, ut_teardown, 16120 test_aes_cmac_aes_ctr_digest_enc_test_case_1), 16121 TEST_CASE_ST(ut_setup, ut_teardown, 16122 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 16123 TEST_CASE_ST(ut_setup, ut_teardown, 16124 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 16125 TEST_CASE_ST(ut_setup, ut_teardown, 16126 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 16127 TEST_CASE_ST(ut_setup, ut_teardown, 16128 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1), 16129 TEST_CASE_ST(ut_setup, ut_teardown, 16130 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 16131 TEST_CASE_ST(ut_setup, ut_teardown, 16132 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 16133 TEST_CASE_ST(ut_setup, ut_teardown, 16134 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 16135 16136 /** AUTH ZUC + CIPHER SNOW3G */ 16137 TEST_CASE_ST(ut_setup, ut_teardown, 16138 test_auth_zuc_cipher_snow_test_case_1), 16139 TEST_CASE_ST(ut_setup, ut_teardown, 16140 test_verify_auth_zuc_cipher_snow_test_case_1), 16141 /** AUTH AES CMAC + CIPHER SNOW3G */ 16142 TEST_CASE_ST(ut_setup, ut_teardown, 16143 test_auth_aes_cmac_cipher_snow_test_case_1), 16144 TEST_CASE_ST(ut_setup, ut_teardown, 16145 test_verify_auth_aes_cmac_cipher_snow_test_case_1), 16146 /** AUTH ZUC + CIPHER AES CTR */ 16147 TEST_CASE_ST(ut_setup, ut_teardown, 16148 test_auth_zuc_cipher_aes_ctr_test_case_1), 16149 TEST_CASE_ST(ut_setup, ut_teardown, 16150 test_verify_auth_zuc_cipher_aes_ctr_test_case_1), 16151 /** AUTH SNOW3G + CIPHER AES CTR */ 16152 TEST_CASE_ST(ut_setup, ut_teardown, 16153 test_auth_snow_cipher_aes_ctr_test_case_1), 16154 TEST_CASE_ST(ut_setup, ut_teardown, 16155 test_verify_auth_snow_cipher_aes_ctr_test_case_1), 16156 /** AUTH SNOW3G + CIPHER ZUC */ 16157 TEST_CASE_ST(ut_setup, ut_teardown, 16158 test_auth_snow_cipher_zuc_test_case_1), 16159 TEST_CASE_ST(ut_setup, ut_teardown, 16160 test_verify_auth_snow_cipher_zuc_test_case_1), 16161 /** AUTH AES CMAC + CIPHER ZUC */ 16162 TEST_CASE_ST(ut_setup, ut_teardown, 16163 test_auth_aes_cmac_cipher_zuc_test_case_1), 16164 TEST_CASE_ST(ut_setup, ut_teardown, 16165 test_verify_auth_aes_cmac_cipher_zuc_test_case_1), 16166 16167 /** AUTH NULL + CIPHER SNOW3G */ 16168 TEST_CASE_ST(ut_setup, ut_teardown, 16169 test_auth_null_cipher_snow_test_case_1), 16170 TEST_CASE_ST(ut_setup, ut_teardown, 16171 test_verify_auth_null_cipher_snow_test_case_1), 16172 /** AUTH NULL + CIPHER ZUC */ 16173 TEST_CASE_ST(ut_setup, ut_teardown, 16174 test_auth_null_cipher_zuc_test_case_1), 16175 TEST_CASE_ST(ut_setup, ut_teardown, 16176 test_verify_auth_null_cipher_zuc_test_case_1), 16177 /** AUTH SNOW3G + CIPHER NULL */ 16178 TEST_CASE_ST(ut_setup, ut_teardown, 16179 test_auth_snow_cipher_null_test_case_1), 16180 TEST_CASE_ST(ut_setup, ut_teardown, 16181 test_verify_auth_snow_cipher_null_test_case_1), 16182 /** AUTH ZUC + CIPHER NULL */ 16183 TEST_CASE_ST(ut_setup, ut_teardown, 16184 test_auth_zuc_cipher_null_test_case_1), 16185 TEST_CASE_ST(ut_setup, ut_teardown, 16186 test_verify_auth_zuc_cipher_null_test_case_1), 16187 /** AUTH NULL + CIPHER AES CTR */ 16188 TEST_CASE_ST(ut_setup, ut_teardown, 16189 test_auth_null_cipher_aes_ctr_test_case_1), 16190 TEST_CASE_ST(ut_setup, ut_teardown, 16191 test_verify_auth_null_cipher_aes_ctr_test_case_1), 16192 /** AUTH AES CMAC + CIPHER NULL */ 16193 TEST_CASE_ST(ut_setup, ut_teardown, 16194 test_auth_aes_cmac_cipher_null_test_case_1), 16195 TEST_CASE_ST(ut_setup, ut_teardown, 16196 test_verify_auth_aes_cmac_cipher_null_test_case_1), 16197 TEST_CASES_END() 16198 } 16199 }; 16200 16201 static int 16202 run_cryptodev_testsuite(const char *pmd_name) 16203 { 16204 uint8_t ret, j, i = 0, blk_start_idx = 0; 16205 const enum blockcipher_test_type blk_suites[] = { 16206 BLKCIPHER_AES_CHAIN_TYPE, 16207 BLKCIPHER_AES_CIPHERONLY_TYPE, 16208 BLKCIPHER_AES_DOCSIS_TYPE, 16209 BLKCIPHER_3DES_CHAIN_TYPE, 16210 BLKCIPHER_3DES_CIPHERONLY_TYPE, 16211 BLKCIPHER_DES_CIPHERONLY_TYPE, 16212 BLKCIPHER_DES_DOCSIS_TYPE, 16213 BLKCIPHER_AUTHONLY_TYPE}; 16214 struct unit_test_suite *static_suites[] = { 16215 &cryptodev_multi_session_testsuite, 16216 &cryptodev_null_testsuite, 16217 &cryptodev_aes_ccm_auth_testsuite, 16218 &cryptodev_aes_gcm_auth_testsuite, 16219 &cryptodev_aes_gmac_auth_testsuite, 16220 &cryptodev_snow3g_testsuite, 16221 &cryptodev_chacha20_poly1305_testsuite, 16222 &cryptodev_zuc_testsuite, 16223 &cryptodev_hmac_md5_auth_testsuite, 16224 &cryptodev_kasumi_testsuite, 16225 &cryptodev_esn_testsuite, 16226 &cryptodev_negative_aes_gcm_testsuite, 16227 &cryptodev_negative_aes_gmac_testsuite, 16228 &cryptodev_mixed_cipher_hash_testsuite, 16229 &cryptodev_negative_hmac_sha1_testsuite, 16230 &cryptodev_gen_testsuite, 16231 #ifdef RTE_LIB_SECURITY 16232 &ipsec_proto_testsuite, 16233 &pdcp_proto_testsuite, 16234 &docsis_proto_testsuite, 16235 #endif 16236 &end_testsuite 16237 }; 16238 static struct unit_test_suite ts = { 16239 .suite_name = "Cryptodev Unit Test Suite", 16240 .setup = testsuite_setup, 16241 .teardown = testsuite_teardown, 16242 .unit_test_cases = {TEST_CASES_END()} 16243 }; 16244 16245 gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name); 16246 16247 if (gbl_driver_id == -1) { 16248 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name); 16249 return TEST_SKIPPED; 16250 } 16251 16252 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 16253 (RTE_DIM(blk_suites) + RTE_DIM(static_suites))); 16254 16255 ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites)); 16256 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 16257 ret = unit_test_suite_runner(&ts); 16258 16259 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites)); 16260 free(ts.unit_test_suites); 16261 return ret; 16262 } 16263 16264 static int 16265 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name) 16266 { 16267 struct rte_cryptodev_info dev_info; 16268 uint8_t i, nb_devs; 16269 int driver_id; 16270 16271 driver_id = rte_cryptodev_driver_id_get(pmd_name); 16272 if (driver_id == -1) { 16273 RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name); 16274 return TEST_SKIPPED; 16275 } 16276 16277 nb_devs = rte_cryptodev_count(); 16278 if (nb_devs < 1) { 16279 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 16280 return TEST_SKIPPED; 16281 } 16282 16283 for (i = 0; i < nb_devs; i++) { 16284 rte_cryptodev_info_get(i, &dev_info); 16285 if (dev_info.driver_id == driver_id) { 16286 if (!(dev_info.feature_flags & flag)) { 16287 RTE_LOG(INFO, USER1, "%s not supported\n", 16288 flag_name); 16289 return TEST_SKIPPED; 16290 } 16291 return 0; /* found */ 16292 } 16293 } 16294 16295 RTE_LOG(INFO, USER1, "%s not supported\n", flag_name); 16296 return TEST_SKIPPED; 16297 } 16298 16299 static int 16300 test_cryptodev_qat(void) 16301 { 16302 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 16303 } 16304 16305 static int 16306 test_cryptodev_virtio(void) 16307 { 16308 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)); 16309 } 16310 16311 static int 16312 test_cryptodev_aesni_mb(void) 16313 { 16314 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 16315 } 16316 16317 static int 16318 test_cryptodev_cpu_aesni_mb(void) 16319 { 16320 int32_t rc; 16321 enum rte_security_session_action_type at = gbl_action_type; 16322 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 16323 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 16324 gbl_action_type = at; 16325 return rc; 16326 } 16327 16328 static int 16329 test_cryptodev_chacha_poly_mb(void) 16330 { 16331 int32_t rc; 16332 enum rte_security_session_action_type at = gbl_action_type; 16333 rc = run_cryptodev_testsuite( 16334 RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD)); 16335 gbl_action_type = at; 16336 return rc; 16337 } 16338 16339 static int 16340 test_cryptodev_openssl(void) 16341 { 16342 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 16343 } 16344 16345 static int 16346 test_cryptodev_aesni_gcm(void) 16347 { 16348 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 16349 } 16350 16351 static int 16352 test_cryptodev_cpu_aesni_gcm(void) 16353 { 16354 int32_t rc; 16355 enum rte_security_session_action_type at = gbl_action_type; 16356 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 16357 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 16358 gbl_action_type = at; 16359 return rc; 16360 } 16361 16362 static int 16363 test_cryptodev_mlx5(void) 16364 { 16365 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD)); 16366 } 16367 16368 static int 16369 test_cryptodev_null(void) 16370 { 16371 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 16372 } 16373 16374 static int 16375 test_cryptodev_sw_snow3g(void) 16376 { 16377 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 16378 } 16379 16380 static int 16381 test_cryptodev_sw_kasumi(void) 16382 { 16383 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 16384 } 16385 16386 static int 16387 test_cryptodev_sw_zuc(void) 16388 { 16389 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 16390 } 16391 16392 static int 16393 test_cryptodev_armv8(void) 16394 { 16395 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 16396 } 16397 16398 static int 16399 test_cryptodev_mrvl(void) 16400 { 16401 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 16402 } 16403 16404 #ifdef RTE_CRYPTO_SCHEDULER 16405 16406 static int 16407 test_cryptodev_scheduler(void) 16408 { 16409 uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0; 16410 const enum blockcipher_test_type blk_suites[] = { 16411 BLKCIPHER_AES_CHAIN_TYPE, 16412 BLKCIPHER_AES_CIPHERONLY_TYPE, 16413 BLKCIPHER_AUTHONLY_TYPE 16414 }; 16415 static struct unit_test_suite scheduler_multicore = { 16416 .suite_name = "Scheduler Multicore Unit Test Suite", 16417 .setup = scheduler_multicore_testsuite_setup, 16418 .teardown = scheduler_mode_testsuite_teardown, 16419 .unit_test_cases = {TEST_CASES_END()} 16420 }; 16421 static struct unit_test_suite scheduler_round_robin = { 16422 .suite_name = "Scheduler Round Robin Unit Test Suite", 16423 .setup = scheduler_roundrobin_testsuite_setup, 16424 .teardown = scheduler_mode_testsuite_teardown, 16425 .unit_test_cases = {TEST_CASES_END()} 16426 }; 16427 static struct unit_test_suite scheduler_failover = { 16428 .suite_name = "Scheduler Failover Unit Test Suite", 16429 .setup = scheduler_failover_testsuite_setup, 16430 .teardown = scheduler_mode_testsuite_teardown, 16431 .unit_test_cases = {TEST_CASES_END()} 16432 }; 16433 static struct unit_test_suite scheduler_pkt_size_distr = { 16434 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite", 16435 .setup = scheduler_pkt_size_distr_testsuite_setup, 16436 .teardown = scheduler_mode_testsuite_teardown, 16437 .unit_test_cases = {TEST_CASES_END()} 16438 }; 16439 struct unit_test_suite *sched_mode_suites[] = { 16440 &scheduler_multicore, 16441 &scheduler_round_robin, 16442 &scheduler_failover, 16443 &scheduler_pkt_size_distr 16444 }; 16445 static struct unit_test_suite scheduler_config = { 16446 .suite_name = "Crypto Device Scheduler Config Unit Test Suite", 16447 .unit_test_cases = { 16448 TEST_CASE(test_scheduler_attach_worker_op), 16449 TEST_CASE(test_scheduler_mode_multicore_op), 16450 TEST_CASE(test_scheduler_mode_roundrobin_op), 16451 TEST_CASE(test_scheduler_mode_failover_op), 16452 TEST_CASE(test_scheduler_mode_pkt_size_distr_op), 16453 TEST_CASE(test_scheduler_detach_worker_op), 16454 16455 TEST_CASES_END() /**< NULL terminate array */ 16456 } 16457 }; 16458 struct unit_test_suite *static_suites[] = { 16459 &scheduler_config, 16460 &end_testsuite 16461 }; 16462 static struct unit_test_suite ts = { 16463 .suite_name = "Scheduler Unit Test Suite", 16464 .setup = scheduler_testsuite_setup, 16465 .teardown = testsuite_teardown, 16466 .unit_test_cases = {TEST_CASES_END()} 16467 }; 16468 16469 gbl_driver_id = rte_cryptodev_driver_id_get( 16470 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 16471 16472 if (gbl_driver_id == -1) { 16473 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n"); 16474 return TEST_SKIPPED; 16475 } 16476 16477 if (rte_cryptodev_driver_id_get( 16478 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) { 16479 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 16480 return TEST_SKIPPED; 16481 } 16482 16483 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 16484 uint8_t blk_i = 0; 16485 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof 16486 (struct unit_test_suite *) * 16487 (RTE_DIM(blk_suites) + 1)); 16488 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]), 16489 blk_suites, RTE_DIM(blk_suites)); 16490 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite; 16491 } 16492 16493 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 16494 (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites))); 16495 ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites, 16496 RTE_DIM(sched_mode_suites)); 16497 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 16498 ret = unit_test_suite_runner(&ts); 16499 16500 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 16501 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, 16502 (*sched_mode_suites[sched_i]), 16503 RTE_DIM(blk_suites)); 16504 free(sched_mode_suites[sched_i]->unit_test_suites); 16505 } 16506 free(ts.unit_test_suites); 16507 return ret; 16508 } 16509 16510 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler); 16511 16512 #endif 16513 16514 static int 16515 test_cryptodev_dpaa2_sec(void) 16516 { 16517 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 16518 } 16519 16520 static int 16521 test_cryptodev_dpaa_sec(void) 16522 { 16523 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 16524 } 16525 16526 static int 16527 test_cryptodev_ccp(void) 16528 { 16529 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 16530 } 16531 16532 static int 16533 test_cryptodev_octeontx(void) 16534 { 16535 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)); 16536 } 16537 16538 static int 16539 test_cryptodev_caam_jr(void) 16540 { 16541 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)); 16542 } 16543 16544 static int 16545 test_cryptodev_nitrox(void) 16546 { 16547 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD)); 16548 } 16549 16550 static int 16551 test_cryptodev_bcmfs(void) 16552 { 16553 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD)); 16554 } 16555 16556 static int 16557 test_cryptodev_qat_raw_api(void) 16558 { 16559 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD); 16560 int ret; 16561 16562 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 16563 "RAW API"); 16564 if (ret) 16565 return ret; 16566 16567 global_api_test_type = CRYPTODEV_RAW_API_TEST; 16568 ret = run_cryptodev_testsuite(pmd_name); 16569 global_api_test_type = CRYPTODEV_API_TEST; 16570 16571 return ret; 16572 } 16573 16574 static int 16575 test_cryptodev_cn9k(void) 16576 { 16577 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD)); 16578 } 16579 16580 static int 16581 test_cryptodev_cn10k(void) 16582 { 16583 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD)); 16584 } 16585 16586 static int 16587 test_cryptodev_dpaa2_sec_raw_api(void) 16588 { 16589 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD); 16590 int ret; 16591 16592 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 16593 "RAW API"); 16594 if (ret) 16595 return ret; 16596 16597 global_api_test_type = CRYPTODEV_RAW_API_TEST; 16598 ret = run_cryptodev_testsuite(pmd_name); 16599 global_api_test_type = CRYPTODEV_API_TEST; 16600 16601 return ret; 16602 } 16603 16604 static int 16605 test_cryptodev_dpaa_sec_raw_api(void) 16606 { 16607 static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD); 16608 int ret; 16609 16610 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, 16611 "RAW API"); 16612 if (ret) 16613 return ret; 16614 16615 global_api_test_type = CRYPTODEV_RAW_API_TEST; 16616 ret = run_cryptodev_testsuite(pmd_name); 16617 global_api_test_type = CRYPTODEV_API_TEST; 16618 16619 return ret; 16620 } 16621 16622 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_raw_api_autotest, 16623 test_cryptodev_dpaa2_sec_raw_api); 16624 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_raw_api_autotest, 16625 test_cryptodev_dpaa_sec_raw_api); 16626 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest, 16627 test_cryptodev_qat_raw_api); 16628 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat); 16629 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 16630 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest, 16631 test_cryptodev_cpu_aesni_mb); 16632 REGISTER_TEST_COMMAND(cryptodev_chacha_poly_mb_autotest, 16633 test_cryptodev_chacha_poly_mb); 16634 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl); 16635 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 16636 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest, 16637 test_cryptodev_cpu_aesni_gcm); 16638 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5); 16639 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null); 16640 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 16641 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 16642 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 16643 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8); 16644 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl); 16645 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec); 16646 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec); 16647 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp); 16648 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio); 16649 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx); 16650 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr); 16651 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox); 16652 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs); 16653 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k); 16654 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k); 16655