1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2015-2020 Intel Corporation 3 * Copyright 2020 NXP 4 */ 5 6 #include <time.h> 7 8 #include <rte_common.h> 9 #include <rte_hexdump.h> 10 #include <rte_mbuf.h> 11 #include <rte_malloc.h> 12 #include <rte_memcpy.h> 13 #include <rte_pause.h> 14 #include <rte_bus_vdev.h> 15 #include <rte_ether.h> 16 #include <rte_errno.h> 17 18 #include <rte_crypto.h> 19 #include <rte_cryptodev.h> 20 #include <rte_ethdev.h> 21 #include <rte_ip.h> 22 #include <rte_string_fns.h> 23 #include <rte_tcp.h> 24 #include <rte_udp.h> 25 26 #ifdef RTE_CRYPTO_SCHEDULER 27 #include <rte_cryptodev_scheduler.h> 28 #include <rte_cryptodev_scheduler_operations.h> 29 #endif 30 31 #include <rte_lcore.h> 32 33 #include "test.h" 34 #include "test_cryptodev.h" 35 36 #include "test_cryptodev_blockcipher.h" 37 #include "test_cryptodev_aes_test_vectors.h" 38 #include "test_cryptodev_des_test_vectors.h" 39 #include "test_cryptodev_hash_test_vectors.h" 40 #include "test_cryptodev_kasumi_test_vectors.h" 41 #include "test_cryptodev_kasumi_hash_test_vectors.h" 42 #include "test_cryptodev_snow3g_test_vectors.h" 43 #include "test_cryptodev_snow3g_hash_test_vectors.h" 44 #include "test_cryptodev_zuc_test_vectors.h" 45 #include "test_cryptodev_aead_test_vectors.h" 46 #include "test_cryptodev_hmac_test_vectors.h" 47 #include "test_cryptodev_mixed_test_vectors.h" 48 #include "test_cryptodev_sm4_test_vectors.h" 49 #ifdef RTE_LIB_SECURITY 50 #include "test_cryptodev_security_ipsec.h" 51 #include "test_cryptodev_security_ipsec_test_vectors.h" 52 #include "test_cryptodev_security_pdcp_test_vectors.h" 53 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h" 54 #include "test_cryptodev_security_pdcp_test_func.h" 55 #include "test_cryptodev_security_docsis_test_vectors.h" 56 #include "test_security_proto.h" 57 58 #define SDAP_DISABLED 0 59 #define SDAP_ENABLED 1 60 #endif 61 62 #define VDEV_ARGS_SIZE 100 63 #define MAX_NB_SESSIONS 4 64 65 #define MAX_DRV_SERVICE_CTX_SIZE 256 66 67 #define MAX_RAW_DEQUEUE_COUNT 65535 68 69 #define IN_PLACE 0 70 #define OUT_OF_PLACE 1 71 72 static int gbl_driver_id; 73 74 static enum rte_security_session_action_type gbl_action_type = 75 RTE_SECURITY_ACTION_TYPE_NONE; 76 77 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST; 78 79 struct crypto_unittest_params { 80 struct rte_crypto_sym_xform cipher_xform; 81 struct rte_crypto_sym_xform auth_xform; 82 struct rte_crypto_sym_xform aead_xform; 83 #ifdef RTE_LIB_SECURITY 84 struct rte_security_docsis_xform docsis_xform; 85 #endif 86 87 union { 88 void *sess; 89 #ifdef RTE_LIB_SECURITY 90 void *sec_session; 91 #endif 92 }; 93 #ifdef RTE_LIB_SECURITY 94 enum rte_security_session_action_type type; 95 #endif 96 struct rte_crypto_op *op; 97 98 struct rte_mbuf *obuf, *ibuf; 99 100 uint8_t *digest; 101 }; 102 103 #define ALIGN_POW2_ROUNDUP(num, align) \ 104 (((num) + (align) - 1) & ~((align) - 1)) 105 106 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts) \ 107 for (j = 0; j < num_child_ts; index++, j++) \ 108 parent_ts.unit_test_suites[index] = child_ts[j] 109 110 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types) \ 111 for (j = 0; j < num_blk_types; index++, j++) \ 112 parent_ts.unit_test_suites[index] = \ 113 build_blockcipher_test_suite(blk_types[j]) 114 115 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types) \ 116 for (j = index; j < index + num_blk_types; j++) \ 117 free_blockcipher_test_suite(parent_ts.unit_test_suites[j]) 118 119 /* 120 * Forward declarations. 121 */ 122 static int 123 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 124 struct crypto_unittest_params *ut_params, uint8_t *cipher_key, 125 uint8_t *hmac_key); 126 127 static int 128 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess, 129 struct crypto_unittest_params *ut_params, 130 struct crypto_testsuite_params *ts_param, 131 const uint8_t *cipher, 132 const uint8_t *digest, 133 const uint8_t *iv); 134 135 static int 136 security_proto_supported(enum rte_security_session_action_type action, 137 enum rte_security_session_protocol proto); 138 139 static int 140 dev_configure_and_start(uint64_t ff_disable); 141 142 static int 143 check_cipher_capability(const struct crypto_testsuite_params *ts_params, 144 const enum rte_crypto_cipher_algorithm cipher_algo, 145 const uint16_t key_size, const uint16_t iv_size); 146 147 static int 148 check_auth_capability(const struct crypto_testsuite_params *ts_params, 149 const enum rte_crypto_auth_algorithm auth_algo, 150 const uint16_t key_size, const uint16_t iv_size, 151 const uint16_t tag_size); 152 153 static struct rte_mbuf * 154 setup_test_string(struct rte_mempool *mpool, 155 const char *string, size_t len, uint8_t blocksize) 156 { 157 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool); 158 size_t t_len = len - (blocksize ? (len % blocksize) : 0); 159 160 if (m) { 161 char *dst; 162 163 memset(m->buf_addr, 0, m->buf_len); 164 dst = rte_pktmbuf_append(m, t_len); 165 if (!dst) { 166 rte_pktmbuf_free(m); 167 return NULL; 168 } 169 if (string != NULL) 170 rte_memcpy(dst, string, t_len); 171 else 172 memset(dst, 0, t_len); 173 } 174 175 return m; 176 } 177 178 /* Get number of bytes in X bits (rounding up) */ 179 static uint32_t 180 ceil_byte_length(uint32_t num_bits) 181 { 182 if (num_bits % 8) 183 return ((num_bits >> 3) + 1); 184 else 185 return (num_bits >> 3); 186 } 187 188 static void 189 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused, 190 uint8_t is_op_success) 191 { 192 struct rte_crypto_op *op = user_data; 193 op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS : 194 RTE_CRYPTO_OP_STATUS_ERROR; 195 } 196 197 static struct crypto_testsuite_params testsuite_params = { NULL }; 198 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params; 199 static struct crypto_unittest_params unittest_params; 200 201 int 202 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id, 203 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth, 204 uint8_t len_in_bits, uint8_t cipher_iv_len) 205 { 206 struct rte_crypto_sym_op *sop = op->sym; 207 struct rte_crypto_op *ret_op = NULL; 208 struct rte_crypto_vec data_vec[UINT8_MAX], dest_data_vec[UINT8_MAX]; 209 struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv; 210 union rte_crypto_sym_ofs ofs; 211 struct rte_crypto_sym_vec vec; 212 struct rte_crypto_sgl sgl, dest_sgl; 213 uint32_t max_len; 214 union rte_cryptodev_session_ctx sess; 215 uint64_t auth_end_iova; 216 uint32_t count = 0; 217 struct rte_crypto_raw_dp_ctx *ctx; 218 uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0, 219 auth_len = 0; 220 int32_t n; 221 uint32_t n_success; 222 int ctx_service_size; 223 int32_t status = 0; 224 int enqueue_status, dequeue_status; 225 struct crypto_unittest_params *ut_params = &unittest_params; 226 int is_sgl = sop->m_src->nb_segs > 1; 227 int ret = TEST_SUCCESS, is_oop = 0; 228 229 ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id); 230 if (ctx_service_size < 0) 231 return TEST_SKIPPED; 232 233 ctx = malloc(ctx_service_size); 234 if (ctx == NULL) 235 return TEST_FAILED; 236 237 /* Both are enums, setting crypto_sess will suit any session type */ 238 sess.crypto_sess = op->sym->session; 239 240 ret = rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx, op->sess_type, sess, 0); 241 if (ret == -ENOTSUP) { 242 ret = TEST_SKIPPED; 243 goto exit; 244 } else if (ret) { 245 ret = TEST_FAILED; 246 goto exit; 247 } 248 249 cipher_iv.iova = 0; 250 cipher_iv.va = NULL; 251 aad_auth_iv.iova = 0; 252 aad_auth_iv.va = NULL; 253 digest.iova = 0; 254 digest.va = NULL; 255 sgl.vec = data_vec; 256 vec.num = 1; 257 vec.src_sgl = &sgl; 258 vec.iv = &cipher_iv; 259 vec.digest = &digest; 260 vec.aad = &aad_auth_iv; 261 vec.status = &status; 262 263 ofs.raw = 0; 264 265 if ((sop->m_dst != NULL) && (sop->m_dst != sop->m_src)) 266 is_oop = 1; 267 268 if (is_cipher && is_auth) { 269 cipher_offset = sop->cipher.data.offset; 270 cipher_len = sop->cipher.data.length; 271 auth_offset = sop->auth.data.offset; 272 auth_len = sop->auth.data.length; 273 max_len = RTE_MAX(cipher_offset + cipher_len, 274 auth_offset + auth_len); 275 if (len_in_bits) { 276 max_len = max_len >> 3; 277 cipher_offset = cipher_offset >> 3; 278 auth_offset = auth_offset >> 3; 279 cipher_len = cipher_len >> 3; 280 auth_len = auth_len >> 3; 281 } 282 ofs.ofs.cipher.head = cipher_offset; 283 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 284 ofs.ofs.auth.head = auth_offset; 285 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 286 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 287 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 288 aad_auth_iv.va = rte_crypto_op_ctod_offset( 289 op, void *, IV_OFFSET + cipher_iv_len); 290 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 291 cipher_iv_len); 292 digest.va = (void *)sop->auth.digest.data; 293 digest.iova = sop->auth.digest.phys_addr; 294 295 if (is_sgl) { 296 uint32_t remaining_off = auth_offset + auth_len; 297 struct rte_mbuf *sgl_buf = sop->m_src; 298 if (is_oop) 299 sgl_buf = sop->m_dst; 300 301 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf) 302 && sgl_buf->next != NULL) { 303 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 304 sgl_buf = sgl_buf->next; 305 } 306 307 auth_end_iova = (uint64_t)rte_pktmbuf_iova_offset( 308 sgl_buf, remaining_off); 309 } else { 310 auth_end_iova = rte_pktmbuf_iova(op->sym->m_src) + 311 auth_offset + auth_len; 312 } 313 /* Then check if digest-encrypted conditions are met */ 314 if ((auth_offset + auth_len < cipher_offset + cipher_len) && 315 (digest.iova == auth_end_iova) && is_sgl) 316 max_len = RTE_MAX(max_len, 317 auth_offset + auth_len + 318 ut_params->auth_xform.auth.digest_length); 319 320 } else if (is_cipher) { 321 cipher_offset = sop->cipher.data.offset; 322 cipher_len = sop->cipher.data.length; 323 max_len = cipher_len + cipher_offset; 324 if (len_in_bits) { 325 max_len = max_len >> 3; 326 cipher_offset = cipher_offset >> 3; 327 cipher_len = cipher_len >> 3; 328 } 329 ofs.ofs.cipher.head = cipher_offset; 330 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 331 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 332 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 333 334 } else if (is_auth) { 335 auth_offset = sop->auth.data.offset; 336 auth_len = sop->auth.data.length; 337 max_len = auth_len + auth_offset; 338 if (len_in_bits) { 339 max_len = max_len >> 3; 340 auth_offset = auth_offset >> 3; 341 auth_len = auth_len >> 3; 342 } 343 ofs.ofs.auth.head = auth_offset; 344 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 345 aad_auth_iv.va = rte_crypto_op_ctod_offset( 346 op, void *, IV_OFFSET + cipher_iv_len); 347 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 348 cipher_iv_len); 349 digest.va = (void *)sop->auth.digest.data; 350 digest.iova = sop->auth.digest.phys_addr; 351 352 } else { /* aead */ 353 cipher_offset = sop->aead.data.offset; 354 cipher_len = sop->aead.data.length; 355 max_len = cipher_len + cipher_offset; 356 if (len_in_bits) { 357 max_len = max_len >> 3; 358 cipher_offset = cipher_offset >> 3; 359 cipher_len = cipher_len >> 3; 360 } 361 ofs.ofs.cipher.head = cipher_offset; 362 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 363 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 364 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 365 aad_auth_iv.va = (void *)sop->aead.aad.data; 366 aad_auth_iv.iova = sop->aead.aad.phys_addr; 367 digest.va = (void *)sop->aead.digest.data; 368 digest.iova = sop->aead.digest.phys_addr; 369 } 370 371 n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len, 372 data_vec, RTE_DIM(data_vec)); 373 if (n < 0 || n > sop->m_src->nb_segs) { 374 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 375 goto exit; 376 } 377 378 sgl.num = n; 379 /* Out of place */ 380 if (is_oop) { 381 dest_sgl.vec = dest_data_vec; 382 vec.dest_sgl = &dest_sgl; 383 n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len, 384 dest_data_vec, RTE_DIM(dest_data_vec)); 385 if (n < 0 || n > sop->m_dst->nb_segs) { 386 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 387 goto exit; 388 } 389 dest_sgl.num = n; 390 } else 391 vec.dest_sgl = NULL; 392 393 if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op, 394 &enqueue_status) < 1) { 395 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 396 goto exit; 397 } 398 399 if (enqueue_status == 0) { 400 status = rte_cryptodev_raw_enqueue_done(ctx, 1); 401 if (status < 0) { 402 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 403 goto exit; 404 } 405 } else if (enqueue_status < 0) { 406 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 407 goto exit; 408 } 409 410 n = n_success = 0; 411 while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) { 412 n = rte_cryptodev_raw_dequeue_burst(ctx, 413 NULL, 1, post_process_raw_dp_op, 414 (void **)&ret_op, 0, &n_success, 415 &dequeue_status); 416 if (dequeue_status < 0) { 417 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 418 goto exit; 419 } 420 if (n == 0) 421 rte_pause(); 422 } 423 424 if (n == 1 && dequeue_status == 0) { 425 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) { 426 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 427 goto exit; 428 } 429 } 430 431 op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op || 432 ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR || 433 n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR : 434 RTE_CRYPTO_OP_STATUS_SUCCESS; 435 436 exit: 437 free(ctx); 438 return ret; 439 } 440 441 static void 442 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op) 443 { 444 int32_t n, st; 445 struct rte_crypto_sym_op *sop; 446 union rte_crypto_sym_ofs ofs; 447 struct rte_crypto_sgl sgl; 448 struct rte_crypto_sym_vec symvec; 449 struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr; 450 struct rte_crypto_vec vec[UINT8_MAX]; 451 452 sop = op->sym; 453 454 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset, 455 sop->aead.data.length, vec, RTE_DIM(vec)); 456 457 if (n < 0 || n != sop->m_src->nb_segs) { 458 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 459 return; 460 } 461 462 sgl.vec = vec; 463 sgl.num = n; 464 symvec.src_sgl = &sgl; 465 symvec.iv = &iv_ptr; 466 symvec.digest = &digest_ptr; 467 symvec.aad = &aad_ptr; 468 symvec.status = &st; 469 symvec.num = 1; 470 471 /* for CPU crypto the IOVA address is not required */ 472 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 473 digest_ptr.va = (void *)sop->aead.digest.data; 474 aad_ptr.va = (void *)sop->aead.aad.data; 475 476 ofs.raw = 0; 477 478 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 479 &symvec); 480 481 if (n != 1) 482 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 483 else 484 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 485 } 486 487 static void 488 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op) 489 { 490 int32_t n, st; 491 struct rte_crypto_sym_op *sop; 492 union rte_crypto_sym_ofs ofs; 493 struct rte_crypto_sgl sgl; 494 struct rte_crypto_sym_vec symvec; 495 struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr; 496 struct rte_crypto_vec vec[UINT8_MAX]; 497 498 sop = op->sym; 499 500 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset, 501 sop->auth.data.length, vec, RTE_DIM(vec)); 502 503 if (n < 0 || n != sop->m_src->nb_segs) { 504 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 505 return; 506 } 507 508 sgl.vec = vec; 509 sgl.num = n; 510 symvec.src_sgl = &sgl; 511 symvec.iv = &iv_ptr; 512 symvec.digest = &digest_ptr; 513 symvec.status = &st; 514 symvec.num = 1; 515 516 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 517 digest_ptr.va = (void *)sop->auth.digest.data; 518 519 ofs.raw = 0; 520 ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset; 521 ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) - 522 (sop->cipher.data.offset + sop->cipher.data.length); 523 524 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 525 &symvec); 526 527 if (n != 1) 528 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 529 else 530 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 531 } 532 533 static struct rte_crypto_op * 534 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op) 535 { 536 537 RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO); 538 539 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 540 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n"); 541 return NULL; 542 } 543 544 op = NULL; 545 546 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 547 rte_pause(); 548 549 if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 550 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status); 551 return NULL; 552 } 553 554 return op; 555 } 556 557 static int 558 testsuite_setup(void) 559 { 560 struct crypto_testsuite_params *ts_params = &testsuite_params; 561 struct rte_cryptodev_info info; 562 uint32_t i = 0, nb_devs, dev_id; 563 uint16_t qp_id; 564 565 memset(ts_params, 0, sizeof(*ts_params)); 566 567 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 568 if (ts_params->mbuf_pool == NULL) { 569 /* Not already created so create */ 570 ts_params->mbuf_pool = rte_pktmbuf_pool_create( 571 "CRYPTO_MBUFPOOL", 572 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE, 573 rte_socket_id()); 574 if (ts_params->mbuf_pool == NULL) { 575 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n"); 576 return TEST_FAILED; 577 } 578 } 579 580 ts_params->large_mbuf_pool = rte_mempool_lookup( 581 "CRYPTO_LARGE_MBUFPOOL"); 582 if (ts_params->large_mbuf_pool == NULL) { 583 /* Not already created so create */ 584 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create( 585 "CRYPTO_LARGE_MBUFPOOL", 586 1, 0, 0, UINT16_MAX, 587 rte_socket_id()); 588 if (ts_params->large_mbuf_pool == NULL) { 589 RTE_LOG(ERR, USER1, 590 "Can't create CRYPTO_LARGE_MBUFPOOL\n"); 591 return TEST_FAILED; 592 } 593 } 594 595 ts_params->op_mpool = rte_crypto_op_pool_create( 596 "MBUF_CRYPTO_SYM_OP_POOL", 597 RTE_CRYPTO_OP_TYPE_SYMMETRIC, 598 NUM_MBUFS, MBUF_CACHE_SIZE, 599 DEFAULT_NUM_XFORMS * 600 sizeof(struct rte_crypto_sym_xform) + 601 MAXIMUM_IV_LENGTH, 602 rte_socket_id()); 603 if (ts_params->op_mpool == NULL) { 604 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n"); 605 return TEST_FAILED; 606 } 607 608 nb_devs = rte_cryptodev_count(); 609 if (nb_devs < 1) { 610 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 611 return TEST_SKIPPED; 612 } 613 614 if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) { 615 RTE_LOG(WARNING, USER1, "No %s devices found?\n", 616 rte_cryptodev_driver_name_get(gbl_driver_id)); 617 return TEST_SKIPPED; 618 } 619 620 /* Create list of valid crypto devs */ 621 for (i = 0; i < nb_devs; i++) { 622 rte_cryptodev_info_get(i, &info); 623 if (info.driver_id == gbl_driver_id) 624 ts_params->valid_devs[ts_params->valid_dev_count++] = i; 625 } 626 627 if (ts_params->valid_dev_count < 1) 628 return TEST_FAILED; 629 630 /* Set up all the qps on the first of the valid devices found */ 631 632 dev_id = ts_params->valid_devs[0]; 633 634 rte_cryptodev_info_get(dev_id, &info); 635 636 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; 637 ts_params->conf.socket_id = SOCKET_ID_ANY; 638 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY; 639 640 unsigned int session_size = 641 rte_cryptodev_sym_get_private_session_size(dev_id); 642 643 #ifdef RTE_LIB_SECURITY 644 unsigned int security_session_size = rte_security_session_get_size( 645 rte_cryptodev_get_sec_ctx(dev_id)); 646 647 if (session_size < security_session_size) 648 session_size = security_session_size; 649 #endif 650 /* 651 * Create mempool with maximum number of sessions. 652 */ 653 if (info.sym.max_nb_sessions != 0 && 654 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 655 RTE_LOG(ERR, USER1, "Device does not support " 656 "at least %u sessions\n", 657 MAX_NB_SESSIONS); 658 return TEST_FAILED; 659 } 660 661 ts_params->session_mpool = rte_cryptodev_sym_session_pool_create( 662 "test_sess_mp", MAX_NB_SESSIONS, session_size, 0, 0, 663 SOCKET_ID_ANY); 664 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 665 "session mempool allocation failed"); 666 667 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, 668 &ts_params->conf), 669 "Failed to configure cryptodev %u with %u qps", 670 dev_id, ts_params->conf.nb_queue_pairs); 671 672 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 673 ts_params->qp_conf.mp_session = ts_params->session_mpool; 674 675 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 676 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 677 dev_id, qp_id, &ts_params->qp_conf, 678 rte_cryptodev_socket_id(dev_id)), 679 "Failed to setup queue pair %u on cryptodev %u", 680 qp_id, dev_id); 681 } 682 683 return TEST_SUCCESS; 684 } 685 686 static void 687 testsuite_teardown(void) 688 { 689 struct crypto_testsuite_params *ts_params = &testsuite_params; 690 int res; 691 692 if (ts_params->mbuf_pool != NULL) { 693 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 694 rte_mempool_avail_count(ts_params->mbuf_pool)); 695 } 696 697 if (ts_params->op_mpool != NULL) { 698 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", 699 rte_mempool_avail_count(ts_params->op_mpool)); 700 } 701 702 if (ts_params->session_mpool != NULL) { 703 rte_mempool_free(ts_params->session_mpool); 704 ts_params->session_mpool = NULL; 705 } 706 707 res = rte_cryptodev_close(ts_params->valid_devs[0]); 708 if (res) 709 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res); 710 } 711 712 static int 713 check_capabilities_supported(enum rte_crypto_sym_xform_type type, 714 const int *algs, uint16_t num_algs) 715 { 716 uint8_t dev_id = testsuite_params.valid_devs[0]; 717 bool some_alg_supported = FALSE; 718 uint16_t i; 719 720 for (i = 0; i < num_algs && !some_alg_supported; i++) { 721 struct rte_cryptodev_sym_capability_idx alg = { 722 type, {algs[i]} 723 }; 724 if (rte_cryptodev_sym_capability_get(dev_id, 725 &alg) != NULL) 726 some_alg_supported = TRUE; 727 } 728 if (!some_alg_supported) 729 return TEST_SKIPPED; 730 731 return 0; 732 } 733 734 int 735 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers, 736 uint16_t num_ciphers) 737 { 738 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER, 739 (const int *) ciphers, num_ciphers); 740 } 741 742 int 743 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths, 744 uint16_t num_auths) 745 { 746 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH, 747 (const int *) auths, num_auths); 748 } 749 750 int 751 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads, 752 uint16_t num_aeads) 753 { 754 return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD, 755 (const int *) aeads, num_aeads); 756 } 757 758 static int 759 null_testsuite_setup(void) 760 { 761 struct crypto_testsuite_params *ts_params = &testsuite_params; 762 uint8_t dev_id = ts_params->valid_devs[0]; 763 struct rte_cryptodev_info dev_info; 764 const enum rte_crypto_cipher_algorithm ciphers[] = { 765 RTE_CRYPTO_CIPHER_NULL 766 }; 767 const enum rte_crypto_auth_algorithm auths[] = { 768 RTE_CRYPTO_AUTH_NULL 769 }; 770 771 rte_cryptodev_info_get(dev_id, &dev_info); 772 773 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 774 RTE_LOG(INFO, USER1, "Feature flag requirements for NULL " 775 "testsuite not met\n"); 776 return TEST_SKIPPED; 777 } 778 779 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 780 && check_auth_capabilities_supported(auths, 781 RTE_DIM(auths)) != 0) { 782 RTE_LOG(INFO, USER1, "Capability requirements for NULL " 783 "testsuite not met\n"); 784 return TEST_SKIPPED; 785 } 786 787 return 0; 788 } 789 790 static int 791 crypto_gen_testsuite_setup(void) 792 { 793 struct crypto_testsuite_params *ts_params = &testsuite_params; 794 uint8_t dev_id = ts_params->valid_devs[0]; 795 struct rte_cryptodev_info dev_info; 796 797 rte_cryptodev_info_get(dev_id, &dev_info); 798 799 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 800 RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen " 801 "testsuite not met\n"); 802 return TEST_SKIPPED; 803 } 804 805 return 0; 806 } 807 808 #ifdef RTE_LIB_SECURITY 809 static int 810 ipsec_proto_testsuite_setup(void) 811 { 812 struct crypto_testsuite_params *ts_params = &testsuite_params; 813 struct crypto_unittest_params *ut_params = &unittest_params; 814 struct rte_cryptodev_info dev_info; 815 int ret = 0; 816 817 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 818 819 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) { 820 RTE_LOG(INFO, USER1, "Feature flag requirements for IPsec Proto " 821 "testsuite not met\n"); 822 return TEST_SKIPPED; 823 } 824 825 /* Reconfigure to enable security */ 826 ret = dev_configure_and_start(0); 827 if (ret != TEST_SUCCESS) 828 return ret; 829 830 /* Set action type */ 831 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 832 833 if (security_proto_supported( 834 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 835 RTE_SECURITY_PROTOCOL_IPSEC) < 0) { 836 RTE_LOG(INFO, USER1, "Capability requirements for IPsec Proto " 837 "test not met\n"); 838 ret = TEST_SKIPPED; 839 } 840 841 test_ipsec_alg_list_populate(); 842 test_ipsec_ah_alg_list_populate(); 843 844 /* 845 * Stop the device. Device would be started again by individual test 846 * case setup routine. 847 */ 848 rte_cryptodev_stop(ts_params->valid_devs[0]); 849 850 return ret; 851 } 852 853 static int 854 pdcp_proto_testsuite_setup(void) 855 { 856 struct crypto_testsuite_params *ts_params = &testsuite_params; 857 uint8_t dev_id = ts_params->valid_devs[0]; 858 struct rte_cryptodev_info dev_info; 859 const enum rte_crypto_cipher_algorithm ciphers[] = { 860 RTE_CRYPTO_CIPHER_NULL, 861 RTE_CRYPTO_CIPHER_AES_CTR, 862 RTE_CRYPTO_CIPHER_ZUC_EEA3, 863 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 864 }; 865 const enum rte_crypto_auth_algorithm auths[] = { 866 RTE_CRYPTO_AUTH_NULL, 867 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 868 RTE_CRYPTO_AUTH_AES_CMAC, 869 RTE_CRYPTO_AUTH_ZUC_EIA3 870 }; 871 872 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_auth_key)); 873 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_bearer)); 874 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_crypto_key)); 875 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_in)); 876 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_in_len)); 877 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_out)); 878 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_sn_size)); 879 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_hfn)); 880 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_hfn_threshold)); 881 RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_packet_direction)); 882 883 rte_cryptodev_info_get(dev_id, &dev_info); 884 885 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 886 !(dev_info.feature_flags & 887 RTE_CRYPTODEV_FF_SECURITY)) { 888 RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto " 889 "testsuite not met\n"); 890 return TEST_SKIPPED; 891 } 892 893 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 894 && check_auth_capabilities_supported(auths, 895 RTE_DIM(auths)) != 0) { 896 RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto " 897 "testsuite not met\n"); 898 return TEST_SKIPPED; 899 } 900 901 return 0; 902 } 903 904 static int 905 docsis_proto_testsuite_setup(void) 906 { 907 struct crypto_testsuite_params *ts_params = &testsuite_params; 908 uint8_t dev_id = ts_params->valid_devs[0]; 909 struct rte_cryptodev_info dev_info; 910 const enum rte_crypto_cipher_algorithm ciphers[] = { 911 RTE_CRYPTO_CIPHER_AES_DOCSISBPI 912 }; 913 914 rte_cryptodev_info_get(dev_id, &dev_info); 915 916 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 917 !(dev_info.feature_flags & 918 RTE_CRYPTODEV_FF_SECURITY)) { 919 RTE_LOG(INFO, USER1, "Feature flag requirements for DOCSIS " 920 "Proto testsuite not met\n"); 921 return TEST_SKIPPED; 922 } 923 924 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { 925 RTE_LOG(INFO, USER1, "Capability requirements for DOCSIS Proto " 926 "testsuite not met\n"); 927 return TEST_SKIPPED; 928 } 929 930 return 0; 931 } 932 #endif 933 934 static int 935 aes_ccm_auth_testsuite_setup(void) 936 { 937 struct crypto_testsuite_params *ts_params = &testsuite_params; 938 uint8_t dev_id = ts_params->valid_devs[0]; 939 struct rte_cryptodev_info dev_info; 940 const enum rte_crypto_aead_algorithm aeads[] = { 941 RTE_CRYPTO_AEAD_AES_CCM 942 }; 943 944 rte_cryptodev_info_get(dev_id, &dev_info); 945 946 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 947 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 948 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 949 RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM " 950 "testsuite not met\n"); 951 return TEST_SKIPPED; 952 } 953 954 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 955 RTE_LOG(INFO, USER1, "Capability requirements for AES CCM " 956 "testsuite not met\n"); 957 return TEST_SKIPPED; 958 } 959 960 return 0; 961 } 962 963 static int 964 aes_gcm_auth_testsuite_setup(void) 965 { 966 struct crypto_testsuite_params *ts_params = &testsuite_params; 967 uint8_t dev_id = ts_params->valid_devs[0]; 968 struct rte_cryptodev_info dev_info; 969 const enum rte_crypto_aead_algorithm aeads[] = { 970 RTE_CRYPTO_AEAD_AES_GCM 971 }; 972 973 rte_cryptodev_info_get(dev_id, &dev_info); 974 975 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 976 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM " 977 "testsuite not met\n"); 978 return TEST_SKIPPED; 979 } 980 981 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 982 RTE_LOG(INFO, USER1, "Capability requirements for AES GCM " 983 "testsuite not met\n"); 984 return TEST_SKIPPED; 985 } 986 987 return 0; 988 } 989 990 static int 991 aes_gmac_auth_testsuite_setup(void) 992 { 993 struct crypto_testsuite_params *ts_params = &testsuite_params; 994 uint8_t dev_id = ts_params->valid_devs[0]; 995 struct rte_cryptodev_info dev_info; 996 const enum rte_crypto_auth_algorithm auths[] = { 997 RTE_CRYPTO_AUTH_AES_GMAC 998 }; 999 1000 rte_cryptodev_info_get(dev_id, &dev_info); 1001 1002 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1003 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1004 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1005 RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC " 1006 "testsuite not met\n"); 1007 return TEST_SKIPPED; 1008 } 1009 1010 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1011 RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC " 1012 "testsuite not met\n"); 1013 return TEST_SKIPPED; 1014 } 1015 1016 return 0; 1017 } 1018 1019 static int 1020 chacha20_poly1305_testsuite_setup(void) 1021 { 1022 struct crypto_testsuite_params *ts_params = &testsuite_params; 1023 uint8_t dev_id = ts_params->valid_devs[0]; 1024 struct rte_cryptodev_info dev_info; 1025 const enum rte_crypto_aead_algorithm aeads[] = { 1026 RTE_CRYPTO_AEAD_CHACHA20_POLY1305 1027 }; 1028 1029 rte_cryptodev_info_get(dev_id, &dev_info); 1030 1031 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1032 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1033 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1034 RTE_LOG(INFO, USER1, "Feature flag requirements for " 1035 "Chacha20-Poly1305 testsuite not met\n"); 1036 return TEST_SKIPPED; 1037 } 1038 1039 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1040 RTE_LOG(INFO, USER1, "Capability requirements for " 1041 "Chacha20-Poly1305 testsuite not met\n"); 1042 return TEST_SKIPPED; 1043 } 1044 1045 return 0; 1046 } 1047 1048 static int 1049 snow3g_testsuite_setup(void) 1050 { 1051 struct crypto_testsuite_params *ts_params = &testsuite_params; 1052 uint8_t dev_id = ts_params->valid_devs[0]; 1053 struct rte_cryptodev_info dev_info; 1054 const enum rte_crypto_cipher_algorithm ciphers[] = { 1055 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1056 1057 }; 1058 const enum rte_crypto_auth_algorithm auths[] = { 1059 RTE_CRYPTO_AUTH_SNOW3G_UIA2 1060 }; 1061 1062 rte_cryptodev_info_get(dev_id, &dev_info); 1063 1064 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1065 RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G " 1066 "testsuite not met\n"); 1067 return TEST_SKIPPED; 1068 } 1069 1070 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1071 && check_auth_capabilities_supported(auths, 1072 RTE_DIM(auths)) != 0) { 1073 RTE_LOG(INFO, USER1, "Capability requirements for Snow3G " 1074 "testsuite not met\n"); 1075 return TEST_SKIPPED; 1076 } 1077 1078 return 0; 1079 } 1080 1081 static int 1082 zuc_testsuite_setup(void) 1083 { 1084 struct crypto_testsuite_params *ts_params = &testsuite_params; 1085 uint8_t dev_id = ts_params->valid_devs[0]; 1086 struct rte_cryptodev_info dev_info; 1087 const enum rte_crypto_cipher_algorithm ciphers[] = { 1088 RTE_CRYPTO_CIPHER_ZUC_EEA3 1089 }; 1090 const enum rte_crypto_auth_algorithm auths[] = { 1091 RTE_CRYPTO_AUTH_ZUC_EIA3 1092 }; 1093 1094 rte_cryptodev_info_get(dev_id, &dev_info); 1095 1096 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1097 RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC " 1098 "testsuite not met\n"); 1099 return TEST_SKIPPED; 1100 } 1101 1102 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1103 && check_auth_capabilities_supported(auths, 1104 RTE_DIM(auths)) != 0) { 1105 RTE_LOG(INFO, USER1, "Capability requirements for ZUC " 1106 "testsuite not met\n"); 1107 return TEST_SKIPPED; 1108 } 1109 1110 return 0; 1111 } 1112 1113 static int 1114 hmac_md5_auth_testsuite_setup(void) 1115 { 1116 struct crypto_testsuite_params *ts_params = &testsuite_params; 1117 uint8_t dev_id = ts_params->valid_devs[0]; 1118 struct rte_cryptodev_info dev_info; 1119 const enum rte_crypto_auth_algorithm auths[] = { 1120 RTE_CRYPTO_AUTH_MD5_HMAC 1121 }; 1122 1123 rte_cryptodev_info_get(dev_id, &dev_info); 1124 1125 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1126 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1127 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1128 RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 " 1129 "Auth testsuite not met\n"); 1130 return TEST_SKIPPED; 1131 } 1132 1133 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1134 RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 " 1135 "testsuite not met\n"); 1136 return TEST_SKIPPED; 1137 } 1138 1139 return 0; 1140 } 1141 1142 static int 1143 kasumi_testsuite_setup(void) 1144 { 1145 struct crypto_testsuite_params *ts_params = &testsuite_params; 1146 uint8_t dev_id = ts_params->valid_devs[0]; 1147 struct rte_cryptodev_info dev_info; 1148 const enum rte_crypto_cipher_algorithm ciphers[] = { 1149 RTE_CRYPTO_CIPHER_KASUMI_F8 1150 }; 1151 const enum rte_crypto_auth_algorithm auths[] = { 1152 RTE_CRYPTO_AUTH_KASUMI_F9 1153 }; 1154 1155 rte_cryptodev_info_get(dev_id, &dev_info); 1156 1157 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1158 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1159 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1160 RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi " 1161 "testsuite not met\n"); 1162 return TEST_SKIPPED; 1163 } 1164 1165 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1166 && check_auth_capabilities_supported(auths, 1167 RTE_DIM(auths)) != 0) { 1168 RTE_LOG(INFO, USER1, "Capability requirements for Kasumi " 1169 "testsuite not met\n"); 1170 return TEST_SKIPPED; 1171 } 1172 1173 return 0; 1174 } 1175 1176 static int 1177 negative_aes_gcm_testsuite_setup(void) 1178 { 1179 struct crypto_testsuite_params *ts_params = &testsuite_params; 1180 uint8_t dev_id = ts_params->valid_devs[0]; 1181 struct rte_cryptodev_info dev_info; 1182 const enum rte_crypto_aead_algorithm aeads[] = { 1183 RTE_CRYPTO_AEAD_AES_GCM 1184 }; 1185 1186 rte_cryptodev_info_get(dev_id, &dev_info); 1187 1188 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1189 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1190 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1191 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1192 "AES GCM testsuite not met\n"); 1193 return TEST_SKIPPED; 1194 } 1195 1196 if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) { 1197 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1198 "AES GCM testsuite not met\n"); 1199 return TEST_SKIPPED; 1200 } 1201 1202 return 0; 1203 } 1204 1205 static int 1206 negative_aes_gmac_testsuite_setup(void) 1207 { 1208 struct crypto_testsuite_params *ts_params = &testsuite_params; 1209 uint8_t dev_id = ts_params->valid_devs[0]; 1210 struct rte_cryptodev_info dev_info; 1211 const enum rte_crypto_auth_algorithm auths[] = { 1212 RTE_CRYPTO_AUTH_AES_GMAC 1213 }; 1214 1215 rte_cryptodev_info_get(dev_id, &dev_info); 1216 1217 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1218 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1219 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1220 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1221 "AES GMAC testsuite not met\n"); 1222 return TEST_SKIPPED; 1223 } 1224 1225 if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { 1226 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1227 "AES GMAC testsuite not met\n"); 1228 return TEST_SKIPPED; 1229 } 1230 1231 return 0; 1232 } 1233 1234 static int 1235 mixed_cipher_hash_testsuite_setup(void) 1236 { 1237 struct crypto_testsuite_params *ts_params = &testsuite_params; 1238 uint8_t dev_id = ts_params->valid_devs[0]; 1239 struct rte_cryptodev_info dev_info; 1240 uint64_t feat_flags; 1241 const enum rte_crypto_cipher_algorithm ciphers[] = { 1242 RTE_CRYPTO_CIPHER_NULL, 1243 RTE_CRYPTO_CIPHER_AES_CTR, 1244 RTE_CRYPTO_CIPHER_ZUC_EEA3, 1245 RTE_CRYPTO_CIPHER_SNOW3G_UEA2 1246 }; 1247 const enum rte_crypto_auth_algorithm auths[] = { 1248 RTE_CRYPTO_AUTH_NULL, 1249 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 1250 RTE_CRYPTO_AUTH_AES_CMAC, 1251 RTE_CRYPTO_AUTH_ZUC_EIA3 1252 }; 1253 1254 rte_cryptodev_info_get(dev_id, &dev_info); 1255 feat_flags = dev_info.feature_flags; 1256 1257 if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1258 (global_api_test_type == CRYPTODEV_RAW_API_TEST)) { 1259 RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed " 1260 "Cipher Hash testsuite not met\n"); 1261 return TEST_SKIPPED; 1262 } 1263 1264 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1265 && check_auth_capabilities_supported(auths, 1266 RTE_DIM(auths)) != 0) { 1267 RTE_LOG(INFO, USER1, "Capability requirements for Mixed " 1268 "Cipher Hash testsuite not met\n"); 1269 return TEST_SKIPPED; 1270 } 1271 1272 return 0; 1273 } 1274 1275 static int 1276 esn_testsuite_setup(void) 1277 { 1278 struct crypto_testsuite_params *ts_params = &testsuite_params; 1279 uint8_t dev_id = ts_params->valid_devs[0]; 1280 struct rte_cryptodev_info dev_info; 1281 const enum rte_crypto_cipher_algorithm ciphers[] = { 1282 RTE_CRYPTO_CIPHER_AES_CBC 1283 }; 1284 const enum rte_crypto_auth_algorithm auths[] = { 1285 RTE_CRYPTO_AUTH_SHA1_HMAC 1286 }; 1287 1288 rte_cryptodev_info_get(dev_id, &dev_info); 1289 1290 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1291 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1292 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1293 RTE_LOG(INFO, USER1, "Feature flag requirements for ESN " 1294 "testsuite not met\n"); 1295 return TEST_SKIPPED; 1296 } 1297 1298 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1299 && check_auth_capabilities_supported(auths, 1300 RTE_DIM(auths)) != 0) { 1301 RTE_LOG(INFO, USER1, "Capability requirements for ESN " 1302 "testsuite not met\n"); 1303 return TEST_SKIPPED; 1304 } 1305 1306 return 0; 1307 } 1308 1309 static int 1310 multi_session_testsuite_setup(void) 1311 { 1312 struct crypto_testsuite_params *ts_params = &testsuite_params; 1313 uint8_t dev_id = ts_params->valid_devs[0]; 1314 struct rte_cryptodev_info dev_info; 1315 const enum rte_crypto_cipher_algorithm ciphers[] = { 1316 RTE_CRYPTO_CIPHER_AES_CBC 1317 }; 1318 const enum rte_crypto_auth_algorithm auths[] = { 1319 RTE_CRYPTO_AUTH_SHA512_HMAC 1320 }; 1321 1322 rte_cryptodev_info_get(dev_id, &dev_info); 1323 1324 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) { 1325 RTE_LOG(INFO, USER1, "Feature flag requirements for Multi " 1326 "Session testsuite not met\n"); 1327 return TEST_SKIPPED; 1328 } 1329 1330 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1331 && check_auth_capabilities_supported(auths, 1332 RTE_DIM(auths)) != 0) { 1333 RTE_LOG(INFO, USER1, "Capability requirements for Multi " 1334 "Session testsuite not met\n"); 1335 return TEST_SKIPPED; 1336 } 1337 1338 return 0; 1339 } 1340 1341 static int 1342 negative_hmac_sha1_testsuite_setup(void) 1343 { 1344 struct crypto_testsuite_params *ts_params = &testsuite_params; 1345 uint8_t dev_id = ts_params->valid_devs[0]; 1346 struct rte_cryptodev_info dev_info; 1347 const enum rte_crypto_cipher_algorithm ciphers[] = { 1348 RTE_CRYPTO_CIPHER_AES_CBC 1349 }; 1350 const enum rte_crypto_auth_algorithm auths[] = { 1351 RTE_CRYPTO_AUTH_SHA1_HMAC 1352 }; 1353 1354 rte_cryptodev_info_get(dev_id, &dev_info); 1355 1356 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || 1357 ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 1358 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 1359 RTE_LOG(INFO, USER1, "Feature flag requirements for Negative " 1360 "HMAC SHA1 testsuite not met\n"); 1361 return TEST_SKIPPED; 1362 } 1363 1364 if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 1365 && check_auth_capabilities_supported(auths, 1366 RTE_DIM(auths)) != 0) { 1367 RTE_LOG(INFO, USER1, "Capability requirements for Negative " 1368 "HMAC SHA1 testsuite not met\n"); 1369 return TEST_SKIPPED; 1370 } 1371 1372 return 0; 1373 } 1374 1375 static int 1376 dev_configure_and_start(uint64_t ff_disable) 1377 { 1378 struct crypto_testsuite_params *ts_params = &testsuite_params; 1379 struct crypto_unittest_params *ut_params = &unittest_params; 1380 1381 uint16_t qp_id; 1382 1383 /* Clear unit test parameters before running test */ 1384 memset(ut_params, 0, sizeof(*ut_params)); 1385 1386 /* Reconfigure device to default parameters */ 1387 ts_params->conf.socket_id = SOCKET_ID_ANY; 1388 ts_params->conf.ff_disable = ff_disable; 1389 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 1390 ts_params->qp_conf.mp_session = ts_params->session_mpool; 1391 1392 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1393 &ts_params->conf), 1394 "Failed to configure cryptodev %u", 1395 ts_params->valid_devs[0]); 1396 1397 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { 1398 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1399 ts_params->valid_devs[0], qp_id, 1400 &ts_params->qp_conf, 1401 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1402 "Failed to setup queue pair %u on cryptodev %u", 1403 qp_id, ts_params->valid_devs[0]); 1404 } 1405 1406 1407 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 1408 1409 /* Start the device */ 1410 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 1411 "Failed to start cryptodev %u", 1412 ts_params->valid_devs[0]); 1413 1414 return TEST_SUCCESS; 1415 } 1416 1417 int 1418 ut_setup(void) 1419 { 1420 /* Configure and start the device with security feature disabled */ 1421 return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY); 1422 } 1423 1424 static int 1425 ut_setup_security(void) 1426 { 1427 /* Configure and start the device with no features disabled */ 1428 return dev_configure_and_start(0); 1429 } 1430 1431 static int 1432 ut_setup_security_rx_inject(void) 1433 { 1434 struct rte_mempool *mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 1435 struct crypto_testsuite_params *ts_params = &testsuite_params; 1436 struct rte_eth_conf port_conf = { 1437 .rxmode = { 1438 .offloads = RTE_ETH_RX_OFFLOAD_CHECKSUM | 1439 RTE_ETH_RX_OFFLOAD_SECURITY, 1440 }, 1441 .txmode = { 1442 .offloads = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE, 1443 }, 1444 .lpbk_mode = 1, /* Enable loopback */ 1445 }; 1446 struct rte_cryptodev_info dev_info; 1447 struct rte_eth_rxconf rx_conf = { 1448 .rx_thresh = { 1449 .pthresh = 8, 1450 .hthresh = 8, 1451 .wthresh = 8, 1452 }, 1453 .rx_free_thresh = 32, 1454 }; 1455 uint16_t nb_ports; 1456 void *sec_ctx; 1457 int ret; 1458 1459 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 1460 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY_RX_INJECT) || 1461 !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) { 1462 RTE_LOG(INFO, USER1, 1463 "Feature requirements for IPsec Rx inject test case not met\n"); 1464 return TEST_SKIPPED; 1465 } 1466 1467 sec_ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 1468 if (sec_ctx == NULL) 1469 return TEST_SKIPPED; 1470 1471 nb_ports = rte_eth_dev_count_avail(); 1472 if (nb_ports == 0) 1473 return TEST_SKIPPED; 1474 1475 ret = rte_eth_dev_configure(0 /* port_id */, 1476 1 /* nb_rx_queue */, 1477 0 /* nb_tx_queue */, 1478 &port_conf); 1479 if (ret) { 1480 printf("Could not configure ethdev port 0 [err=%d]\n", ret); 1481 return TEST_SKIPPED; 1482 } 1483 1484 /* Rx queue setup */ 1485 ret = rte_eth_rx_queue_setup(0 /* port_id */, 1486 0 /* rx_queue_id */, 1487 1024 /* nb_rx_desc */, 1488 SOCKET_ID_ANY, 1489 &rx_conf, 1490 mbuf_pool); 1491 if (ret) { 1492 printf("Could not setup eth port 0 queue 0\n"); 1493 return TEST_SKIPPED; 1494 } 1495 1496 ret = rte_security_rx_inject_configure(sec_ctx, 0, true); 1497 if (ret) { 1498 printf("Could not enable Rx inject offload"); 1499 return TEST_SKIPPED; 1500 } 1501 1502 ret = rte_eth_dev_start(0); 1503 if (ret) { 1504 printf("Could not start ethdev"); 1505 return TEST_SKIPPED; 1506 } 1507 1508 ret = rte_eth_promiscuous_enable(0); 1509 if (ret) { 1510 printf("Could not enable promiscuous mode"); 1511 return TEST_SKIPPED; 1512 } 1513 1514 /* Configure and start cryptodev with no features disabled */ 1515 return dev_configure_and_start(0); 1516 } 1517 1518 void 1519 ut_teardown(void) 1520 { 1521 struct crypto_testsuite_params *ts_params = &testsuite_params; 1522 struct crypto_unittest_params *ut_params = &unittest_params; 1523 1524 /* free crypto session structure */ 1525 #ifdef RTE_LIB_SECURITY 1526 if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) { 1527 if (ut_params->sec_session) { 1528 rte_security_session_destroy(rte_cryptodev_get_sec_ctx 1529 (ts_params->valid_devs[0]), 1530 ut_params->sec_session); 1531 ut_params->sec_session = NULL; 1532 } 1533 } else 1534 #endif 1535 { 1536 if (ut_params->sess) { 1537 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 1538 ut_params->sess); 1539 ut_params->sess = NULL; 1540 } 1541 } 1542 1543 /* free crypto operation structure */ 1544 rte_crypto_op_free(ut_params->op); 1545 1546 /* 1547 * free mbuf - both obuf and ibuf are usually the same, 1548 * so check if they point at the same address is necessary, 1549 * to avoid freeing the mbuf twice. 1550 */ 1551 if (ut_params->obuf) { 1552 rte_pktmbuf_free(ut_params->obuf); 1553 if (ut_params->ibuf == ut_params->obuf) 1554 ut_params->ibuf = 0; 1555 ut_params->obuf = 0; 1556 } 1557 if (ut_params->ibuf) { 1558 rte_pktmbuf_free(ut_params->ibuf); 1559 ut_params->ibuf = 0; 1560 } 1561 1562 if (ts_params->mbuf_pool != NULL) 1563 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 1564 rte_mempool_avail_count(ts_params->mbuf_pool)); 1565 1566 /* Stop the device */ 1567 rte_cryptodev_stop(ts_params->valid_devs[0]); 1568 } 1569 1570 static void 1571 ut_teardown_rx_inject(void) 1572 { 1573 struct crypto_testsuite_params *ts_params = &testsuite_params; 1574 void *sec_ctx; 1575 int ret; 1576 1577 if (rte_eth_dev_count_avail() != 0) { 1578 ret = rte_eth_dev_reset(0); 1579 if (ret) 1580 printf("Could not reset eth port 0"); 1581 1582 } 1583 1584 ut_teardown(); 1585 1586 sec_ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 1587 if (sec_ctx == NULL) 1588 return; 1589 1590 ret = rte_security_rx_inject_configure(sec_ctx, 0, false); 1591 if (ret) { 1592 printf("Could not disable Rx inject offload"); 1593 return; 1594 } 1595 } 1596 1597 static int 1598 test_device_configure_invalid_dev_id(void) 1599 { 1600 struct crypto_testsuite_params *ts_params = &testsuite_params; 1601 uint16_t dev_id, num_devs = 0; 1602 1603 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 1604 "Need at least %d devices for test", 1); 1605 1606 /* valid dev_id values */ 1607 dev_id = ts_params->valid_devs[0]; 1608 1609 /* Stop the device in case it's started so it can be configured */ 1610 rte_cryptodev_stop(dev_id); 1611 1612 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 1613 "Failed test for rte_cryptodev_configure: " 1614 "invalid dev_num %u", dev_id); 1615 1616 /* invalid dev_id values */ 1617 dev_id = num_devs; 1618 1619 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1620 "Failed test for rte_cryptodev_configure: " 1621 "invalid dev_num %u", dev_id); 1622 1623 dev_id = 0xff; 1624 1625 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1626 "Failed test for rte_cryptodev_configure:" 1627 "invalid dev_num %u", dev_id); 1628 1629 return TEST_SUCCESS; 1630 } 1631 1632 static int 1633 test_device_configure_invalid_queue_pair_ids(void) 1634 { 1635 struct crypto_testsuite_params *ts_params = &testsuite_params; 1636 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 1637 1638 /* Stop the device in case it's started so it can be configured */ 1639 rte_cryptodev_stop(ts_params->valid_devs[0]); 1640 1641 /* valid - max value queue pairs */ 1642 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1643 1644 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1645 &ts_params->conf), 1646 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1647 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 1648 1649 /* valid - one queue pairs */ 1650 ts_params->conf.nb_queue_pairs = 1; 1651 1652 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1653 &ts_params->conf), 1654 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1655 ts_params->valid_devs[0], 1656 ts_params->conf.nb_queue_pairs); 1657 1658 1659 /* invalid - zero queue pairs */ 1660 ts_params->conf.nb_queue_pairs = 0; 1661 1662 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1663 &ts_params->conf), 1664 "Failed test for rte_cryptodev_configure, dev_id %u," 1665 " invalid qps: %u", 1666 ts_params->valid_devs[0], 1667 ts_params->conf.nb_queue_pairs); 1668 1669 1670 /* invalid - max value supported by field queue pairs */ 1671 ts_params->conf.nb_queue_pairs = UINT16_MAX; 1672 1673 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1674 &ts_params->conf), 1675 "Failed test for rte_cryptodev_configure, dev_id %u," 1676 " invalid qps: %u", 1677 ts_params->valid_devs[0], 1678 ts_params->conf.nb_queue_pairs); 1679 1680 1681 /* invalid - max value + 1 queue pairs */ 1682 ts_params->conf.nb_queue_pairs = orig_nb_qps + 1; 1683 1684 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1685 &ts_params->conf), 1686 "Failed test for rte_cryptodev_configure, dev_id %u," 1687 " invalid qps: %u", 1688 ts_params->valid_devs[0], 1689 ts_params->conf.nb_queue_pairs); 1690 1691 /* revert to original testsuite value */ 1692 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1693 1694 return TEST_SUCCESS; 1695 } 1696 1697 static int 1698 test_queue_pair_descriptor_setup(void) 1699 { 1700 struct crypto_testsuite_params *ts_params = &testsuite_params; 1701 struct rte_cryptodev_qp_conf qp_conf = { 1702 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 1703 }; 1704 uint16_t qp_id; 1705 1706 /* Stop the device in case it's started so it can be configured */ 1707 rte_cryptodev_stop(ts_params->valid_devs[0]); 1708 1709 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1710 &ts_params->conf), 1711 "Failed to configure cryptodev %u", 1712 ts_params->valid_devs[0]); 1713 1714 /* 1715 * Test various ring sizes on this device. memzones can't be 1716 * freed so are re-used if ring is released and re-created. 1717 */ 1718 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/ 1719 qp_conf.mp_session = ts_params->session_mpool; 1720 1721 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1722 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1723 ts_params->valid_devs[0], qp_id, &qp_conf, 1724 rte_cryptodev_socket_id( 1725 ts_params->valid_devs[0])), 1726 "Failed test for " 1727 "rte_cryptodev_queue_pair_setup: num_inflights " 1728 "%u on qp %u on cryptodev %u", 1729 qp_conf.nb_descriptors, qp_id, 1730 ts_params->valid_devs[0]); 1731 } 1732 1733 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2); 1734 1735 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1736 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1737 ts_params->valid_devs[0], qp_id, &qp_conf, 1738 rte_cryptodev_socket_id( 1739 ts_params->valid_devs[0])), 1740 "Failed test for" 1741 " rte_cryptodev_queue_pair_setup: num_inflights" 1742 " %u on qp %u on cryptodev %u", 1743 qp_conf.nb_descriptors, qp_id, 1744 ts_params->valid_devs[0]); 1745 } 1746 1747 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */ 1748 1749 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1750 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1751 ts_params->valid_devs[0], qp_id, &qp_conf, 1752 rte_cryptodev_socket_id( 1753 ts_params->valid_devs[0])), 1754 "Failed test for " 1755 "rte_cryptodev_queue_pair_setup: num_inflights" 1756 " %u on qp %u on cryptodev %u", 1757 qp_conf.nb_descriptors, qp_id, 1758 ts_params->valid_devs[0]); 1759 } 1760 1761 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 1762 1763 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1764 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1765 ts_params->valid_devs[0], qp_id, &qp_conf, 1766 rte_cryptodev_socket_id( 1767 ts_params->valid_devs[0])), 1768 "Failed test for" 1769 " rte_cryptodev_queue_pair_setup:" 1770 "num_inflights %u on qp %u on cryptodev %u", 1771 qp_conf.nb_descriptors, qp_id, 1772 ts_params->valid_devs[0]); 1773 } 1774 1775 /* test invalid queue pair id */ 1776 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */ 1777 1778 qp_id = ts_params->conf.nb_queue_pairs; /*invalid */ 1779 1780 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1781 ts_params->valid_devs[0], 1782 qp_id, &qp_conf, 1783 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1784 "Failed test for rte_cryptodev_queue_pair_setup:" 1785 "invalid qp %u on cryptodev %u", 1786 qp_id, ts_params->valid_devs[0]); 1787 1788 qp_id = 0xffff; /*invalid*/ 1789 1790 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1791 ts_params->valid_devs[0], 1792 qp_id, &qp_conf, 1793 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1794 "Failed test for rte_cryptodev_queue_pair_setup:" 1795 "invalid qp %u on cryptodev %u", 1796 qp_id, ts_params->valid_devs[0]); 1797 1798 return TEST_SUCCESS; 1799 } 1800 1801 /* ***** Plaintext data for tests ***** */ 1802 1803 const char catch_22_quote_1[] = 1804 "There was only one catch and that was Catch-22, which " 1805 "specified that a concern for one's safety in the face of " 1806 "dangers that were real and immediate was the process of a " 1807 "rational mind. Orr was crazy and could be grounded. All he " 1808 "had to do was ask; and as soon as he did, he would no longer " 1809 "be crazy and would have to fly more missions. Orr would be " 1810 "crazy to fly more missions and sane if he didn't, but if he " 1811 "was sane he had to fly them. If he flew them he was crazy " 1812 "and didn't have to; but if he didn't want to he was sane and " 1813 "had to. Yossarian was moved very deeply by the absolute " 1814 "simplicity of this clause of Catch-22 and let out a " 1815 "respectful whistle. \"That's some catch, that Catch-22\", he " 1816 "observed. \"It's the best there is,\" Doc Daneeka agreed."; 1817 1818 const char catch_22_quote[] = 1819 "What a lousy earth! He wondered how many people were " 1820 "destitute that same night even in his own prosperous country, " 1821 "how many homes were shanties, how many husbands were drunk " 1822 "and wives socked, and how many children were bullied, abused, " 1823 "or abandoned. How many families hungered for food they could " 1824 "not afford to buy? How many hearts were broken? How many " 1825 "suicides would take place that same night, how many people " 1826 "would go insane? How many cockroaches and landlords would " 1827 "triumph? How many winners were losers, successes failures, " 1828 "and rich men poor men? How many wise guys were stupid? How " 1829 "many happy endings were unhappy endings? How many honest men " 1830 "were liars, brave men cowards, loyal men traitors, how many " 1831 "sainted men were corrupt, how many people in positions of " 1832 "trust had sold their souls to bodyguards, how many had never " 1833 "had souls? How many straight-and-narrow paths were crooked " 1834 "paths? How many best families were worst families and how " 1835 "many good people were bad people? When you added them all up " 1836 "and then subtracted, you might be left with only the children, " 1837 "and perhaps with Albert Einstein and an old violinist or " 1838 "sculptor somewhere."; 1839 1840 #define QUOTE_480_BYTES (480) 1841 #define QUOTE_512_BYTES (512) 1842 #define QUOTE_768_BYTES (768) 1843 #define QUOTE_1024_BYTES (1024) 1844 1845 1846 1847 /* ***** SHA1 Hash Tests ***** */ 1848 1849 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1) 1850 1851 static uint8_t hmac_sha1_key[] = { 1852 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 1853 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 1854 0xDE, 0xF4, 0xDE, 0xAD }; 1855 1856 /* ***** SHA224 Hash Tests ***** */ 1857 1858 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224) 1859 1860 1861 /* ***** AES-CBC Cipher Tests ***** */ 1862 1863 #define CIPHER_KEY_LENGTH_AES_CBC (16) 1864 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC) 1865 1866 static uint8_t aes_cbc_key[] = { 1867 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 1868 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A }; 1869 1870 static uint8_t aes_cbc_iv[] = { 1871 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 1872 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; 1873 1874 1875 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */ 1876 1877 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = { 1878 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, 1879 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, 1880 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, 1881 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, 1882 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E, 1883 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08, 1884 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0, 1885 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01, 1886 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57, 1887 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE, 1888 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9, 1889 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9, 1890 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D, 1891 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3, 1892 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46, 1893 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3, 1894 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80, 1895 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92, 1896 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5, 1897 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5, 1898 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2, 1899 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5, 1900 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1901 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76, 1902 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4, 1903 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62, 1904 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4, 1905 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4, 1906 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54, 1907 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61, 1908 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91, 1909 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A, 1910 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF, 1911 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F, 1912 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28, 1913 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E, 1914 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7, 1915 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76, 1916 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6, 1917 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03, 1918 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C, 1919 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2, 1920 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6, 1921 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96, 1922 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6, 1923 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA, 1924 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87, 1925 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55, 1926 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B, 1927 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98, 1928 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53, 1929 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A, 1930 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26, 1931 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36, 1932 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36, 1933 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D, 1934 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E, 1935 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E, 1936 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A, 1937 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6, 1938 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4, 1939 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7, 1940 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1, 1941 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C 1942 }; 1943 1944 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = { 1945 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60, 1946 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1947 0x18, 0x8c, 0x1d, 0x32 1948 }; 1949 1950 1951 /* Multisession Vector context Test */ 1952 /*Begin Session 0 */ 1953 static uint8_t ms_aes_cbc_key0[] = { 1954 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1955 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1956 }; 1957 1958 static uint8_t ms_aes_cbc_iv0[] = { 1959 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1960 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1961 }; 1962 1963 static const uint8_t ms_aes_cbc_cipher0[] = { 1964 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38, 1965 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC, 1966 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB, 1967 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9, 1968 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D, 1969 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4, 1970 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34, 1971 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F, 1972 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99, 1973 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED, 1974 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D, 1975 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24, 1976 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71, 1977 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72, 1978 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E, 1979 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD, 1980 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18, 1981 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6, 1982 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29, 1983 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C, 1984 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96, 1985 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26, 1986 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55, 1987 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46, 1988 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B, 1989 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4, 1990 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7, 1991 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5, 1992 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0, 1993 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E, 1994 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D, 1995 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44, 1996 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76, 1997 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3, 1998 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83, 1999 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85, 2000 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45, 2001 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25, 2002 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A, 2003 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1, 2004 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA, 2005 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3, 2006 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4, 2007 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60, 2008 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A, 2009 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A, 2010 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9, 2011 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55, 2012 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13, 2013 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B, 2014 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1, 2015 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0, 2016 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3, 2017 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23, 2018 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B, 2019 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07, 2020 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB, 2021 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1, 2022 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F, 2023 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F, 2024 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84, 2025 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B, 2026 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17, 2027 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF 2028 }; 2029 2030 2031 static uint8_t ms_hmac_key0[] = { 2032 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2033 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2034 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2035 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2036 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2037 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2038 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2039 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2040 }; 2041 2042 static const uint8_t ms_hmac_digest0[] = { 2043 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51, 2044 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F, 2045 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C, 2046 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4, 2047 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56, 2048 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4, 2049 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23, 2050 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90 2051 }; 2052 2053 /* End Session 0 */ 2054 /* Begin session 1 */ 2055 2056 static uint8_t ms_aes_cbc_key1[] = { 2057 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2058 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2059 }; 2060 2061 static uint8_t ms_aes_cbc_iv1[] = { 2062 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2063 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2064 }; 2065 2066 static const uint8_t ms_aes_cbc_cipher1[] = { 2067 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71, 2068 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23, 2069 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09, 2070 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A, 2071 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C, 2072 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F, 2073 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9, 2074 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66, 2075 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43, 2076 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB, 2077 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23, 2078 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29, 2079 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26, 2080 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F, 2081 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68, 2082 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77, 2083 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8, 2084 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97, 2085 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3, 2086 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90, 2087 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5, 2088 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E, 2089 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45, 2090 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B, 2091 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5, 2092 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D, 2093 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E, 2094 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD, 2095 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE, 2096 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1, 2097 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F, 2098 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25, 2099 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1, 2100 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3, 2101 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE, 2102 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6, 2103 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52, 2104 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA, 2105 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63, 2106 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E, 2107 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA, 2108 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB, 2109 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71, 2110 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF, 2111 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A, 2112 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95, 2113 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73, 2114 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49, 2115 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB, 2116 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B, 2117 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC, 2118 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED, 2119 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02, 2120 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4, 2121 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF, 2122 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82, 2123 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D, 2124 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6, 2125 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9, 2126 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35, 2127 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0, 2128 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53, 2129 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5, 2130 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3 2131 2132 }; 2133 2134 static uint8_t ms_hmac_key1[] = { 2135 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2136 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2137 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2138 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2139 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2140 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2141 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2142 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2143 }; 2144 2145 static const uint8_t ms_hmac_digest1[] = { 2146 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69, 2147 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50, 2148 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20, 2149 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD, 2150 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9, 2151 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4, 2152 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA, 2153 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F 2154 }; 2155 /* End Session 1 */ 2156 /* Begin Session 2 */ 2157 static uint8_t ms_aes_cbc_key2[] = { 2158 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2159 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2160 }; 2161 2162 static uint8_t ms_aes_cbc_iv2[] = { 2163 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 2164 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 2165 }; 2166 2167 static const uint8_t ms_aes_cbc_cipher2[] = { 2168 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91, 2169 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97, 2170 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8, 2171 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5, 2172 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98, 2173 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69, 2174 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09, 2175 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF, 2176 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44, 2177 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B, 2178 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9, 2179 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34, 2180 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99, 2181 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF, 2182 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC, 2183 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26, 2184 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3, 2185 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF, 2186 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3, 2187 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3, 2188 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA, 2189 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13, 2190 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38, 2191 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71, 2192 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC, 2193 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1, 2194 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E, 2195 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22, 2196 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62, 2197 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72, 2198 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6, 2199 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6, 2200 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44, 2201 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24, 2202 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5, 2203 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E, 2204 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17, 2205 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9, 2206 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D, 2207 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D, 2208 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22, 2209 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9, 2210 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49, 2211 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E, 2212 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B, 2213 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2, 2214 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95, 2215 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07, 2216 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3, 2217 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A, 2218 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57, 2219 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84, 2220 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61, 2221 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF, 2222 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17, 2223 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A, 2224 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1, 2225 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53, 2226 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7, 2227 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2, 2228 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A, 2229 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8, 2230 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70, 2231 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92 2232 }; 2233 2234 static uint8_t ms_hmac_key2[] = { 2235 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 2236 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2237 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2238 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 2239 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 2240 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2241 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 2242 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 2243 }; 2244 2245 static const uint8_t ms_hmac_digest2[] = { 2246 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF, 2247 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6, 2248 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77, 2249 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27, 2250 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82, 2251 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24, 2252 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E, 2253 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59 2254 }; 2255 2256 /* End Session 2 */ 2257 2258 2259 static int 2260 test_AES_CBC_HMAC_SHA1_encrypt_digest(void) 2261 { 2262 struct crypto_testsuite_params *ts_params = &testsuite_params; 2263 struct crypto_unittest_params *ut_params = &unittest_params; 2264 /* Verify the capabilities */ 2265 struct rte_cryptodev_sym_capability_idx cap_idx; 2266 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2267 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 2268 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2269 &cap_idx) == NULL) 2270 return TEST_SKIPPED; 2271 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2272 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 2273 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2274 &cap_idx) == NULL) 2275 return TEST_SKIPPED; 2276 2277 /* Generate test mbuf data and space for digest */ 2278 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2279 catch_22_quote, QUOTE_512_BYTES, 0); 2280 2281 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2282 DIGEST_BYTE_LENGTH_SHA1); 2283 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2284 2285 /* Setup Cipher Parameters */ 2286 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2287 ut_params->cipher_xform.next = &ut_params->auth_xform; 2288 2289 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2290 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 2291 ut_params->cipher_xform.cipher.key.data = aes_cbc_key; 2292 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2293 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2294 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2295 2296 /* Setup HMAC Parameters */ 2297 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2298 2299 ut_params->auth_xform.next = NULL; 2300 2301 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 2302 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 2303 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; 2304 ut_params->auth_xform.auth.key.data = hmac_sha1_key; 2305 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; 2306 2307 rte_errno = 0; 2308 ut_params->sess = rte_cryptodev_sym_session_create( 2309 ts_params->valid_devs[0], &ut_params->cipher_xform, 2310 ts_params->session_mpool); 2311 if (rte_errno == ENOTSUP) 2312 return TEST_SKIPPED; 2313 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2314 2315 /* Generate crypto op data structure */ 2316 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2317 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2318 TEST_ASSERT_NOT_NULL(ut_params->op, 2319 "Failed to allocate symmetric crypto operation struct"); 2320 2321 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2322 2323 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2324 2325 /* set crypto operation source mbuf */ 2326 sym_op->m_src = ut_params->ibuf; 2327 2328 /* Set crypto operation authentication parameters */ 2329 sym_op->auth.digest.data = ut_params->digest; 2330 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2331 ut_params->ibuf, QUOTE_512_BYTES); 2332 2333 sym_op->auth.data.offset = 0; 2334 sym_op->auth.data.length = QUOTE_512_BYTES; 2335 2336 /* Copy IV at the end of the crypto operation */ 2337 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2338 aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC); 2339 2340 /* Set crypto operation cipher parameters */ 2341 sym_op->cipher.data.offset = 0; 2342 sym_op->cipher.data.length = QUOTE_512_BYTES; 2343 2344 /* Process crypto operation */ 2345 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2346 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2347 ut_params->op); 2348 else 2349 TEST_ASSERT_NOT_NULL( 2350 process_crypto_request(ts_params->valid_devs[0], 2351 ut_params->op), 2352 "failed to process sym crypto op"); 2353 2354 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2355 "crypto op processing failed"); 2356 2357 /* Validate obuf */ 2358 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 2359 uint8_t *); 2360 2361 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, 2362 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 2363 QUOTE_512_BYTES, 2364 "ciphertext data not as expected"); 2365 2366 uint8_t *digest = ciphertext + QUOTE_512_BYTES; 2367 2368 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, 2369 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, 2370 gbl_driver_id == rte_cryptodev_driver_id_get( 2371 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ? 2372 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : 2373 DIGEST_BYTE_LENGTH_SHA1, 2374 "Generated digest data not as expected"); 2375 2376 return TEST_SUCCESS; 2377 } 2378 2379 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ 2380 2381 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) 2382 2383 static uint8_t hmac_sha512_key[] = { 2384 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 2385 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 2386 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 2387 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60, 2388 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1, 2389 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 2390 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76, 2391 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 }; 2392 2393 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = { 2394 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8, 2395 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48, 2396 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8, 2397 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70, 2398 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8, 2399 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E, 2400 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D, 2401 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A }; 2402 2403 2404 2405 static int 2406 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2407 struct crypto_unittest_params *ut_params, 2408 uint8_t *cipher_key, 2409 uint8_t *hmac_key); 2410 2411 static int 2412 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess, 2413 struct crypto_unittest_params *ut_params, 2414 struct crypto_testsuite_params *ts_params, 2415 const uint8_t *cipher, 2416 const uint8_t *digest, 2417 const uint8_t *iv); 2418 2419 2420 static int 2421 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 2422 struct crypto_unittest_params *ut_params, 2423 uint8_t *cipher_key, 2424 uint8_t *hmac_key) 2425 { 2426 2427 /* Setup Cipher Parameters */ 2428 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2429 ut_params->cipher_xform.next = NULL; 2430 2431 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 2432 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 2433 ut_params->cipher_xform.cipher.key.data = cipher_key; 2434 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 2435 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2436 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 2437 2438 /* Setup HMAC Parameters */ 2439 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2440 ut_params->auth_xform.next = &ut_params->cipher_xform; 2441 2442 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 2443 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC; 2444 ut_params->auth_xform.auth.key.data = hmac_key; 2445 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512; 2446 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512; 2447 2448 return TEST_SUCCESS; 2449 } 2450 2451 2452 static int 2453 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess, 2454 struct crypto_unittest_params *ut_params, 2455 struct crypto_testsuite_params *ts_params, 2456 const uint8_t *cipher, 2457 const uint8_t *digest, 2458 const uint8_t *iv) 2459 { 2460 int ret; 2461 2462 /* Generate test mbuf data and digest */ 2463 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 2464 (const char *) 2465 cipher, 2466 QUOTE_512_BYTES, 0); 2467 2468 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2469 DIGEST_BYTE_LENGTH_SHA512); 2470 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 2471 2472 rte_memcpy(ut_params->digest, 2473 digest, 2474 DIGEST_BYTE_LENGTH_SHA512); 2475 2476 /* Generate Crypto op data structure */ 2477 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2478 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2479 TEST_ASSERT_NOT_NULL(ut_params->op, 2480 "Failed to allocate symmetric crypto operation struct"); 2481 2482 rte_crypto_op_attach_sym_session(ut_params->op, sess); 2483 2484 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2485 2486 /* set crypto operation source mbuf */ 2487 sym_op->m_src = ut_params->ibuf; 2488 2489 sym_op->auth.digest.data = ut_params->digest; 2490 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2491 ut_params->ibuf, QUOTE_512_BYTES); 2492 2493 sym_op->auth.data.offset = 0; 2494 sym_op->auth.data.length = QUOTE_512_BYTES; 2495 2496 /* Copy IV at the end of the crypto operation */ 2497 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2498 iv, CIPHER_IV_LENGTH_AES_CBC); 2499 2500 sym_op->cipher.data.offset = 0; 2501 sym_op->cipher.data.length = QUOTE_512_BYTES; 2502 2503 /* Process crypto operation */ 2504 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2505 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2506 ut_params->op); 2507 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 2508 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 0); 2509 if (ret != TEST_SUCCESS) 2510 return ret; 2511 } else 2512 TEST_ASSERT_NOT_NULL( 2513 process_crypto_request(ts_params->valid_devs[0], 2514 ut_params->op), 2515 "failed to process sym crypto op"); 2516 2517 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2518 "crypto op processing failed"); 2519 2520 ut_params->obuf = ut_params->op->sym->m_src; 2521 2522 /* Validate obuf */ 2523 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2524 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 2525 catch_22_quote, 2526 QUOTE_512_BYTES, 2527 "Plaintext data not as expected"); 2528 2529 /* Validate obuf */ 2530 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 2531 "Digest verification failed"); 2532 2533 return TEST_SUCCESS; 2534 } 2535 2536 /* ***** SNOW 3G Tests ***** */ 2537 static int 2538 create_wireless_algo_hash_session(uint8_t dev_id, 2539 const uint8_t *key, const uint8_t key_len, 2540 const uint8_t iv_len, const uint8_t auth_len, 2541 enum rte_crypto_auth_operation op, 2542 enum rte_crypto_auth_algorithm algo) 2543 { 2544 uint8_t hash_key[key_len]; 2545 2546 struct crypto_testsuite_params *ts_params = &testsuite_params; 2547 struct crypto_unittest_params *ut_params = &unittest_params; 2548 2549 memcpy(hash_key, key, key_len); 2550 2551 debug_hexdump(stdout, "key:", key, key_len); 2552 2553 /* Setup Authentication Parameters */ 2554 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2555 ut_params->auth_xform.next = NULL; 2556 2557 ut_params->auth_xform.auth.op = op; 2558 ut_params->auth_xform.auth.algo = algo; 2559 ut_params->auth_xform.auth.key.length = key_len; 2560 ut_params->auth_xform.auth.key.data = hash_key; 2561 ut_params->auth_xform.auth.digest_length = auth_len; 2562 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 2563 ut_params->auth_xform.auth.iv.length = iv_len; 2564 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2565 &ut_params->auth_xform, ts_params->session_mpool); 2566 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2567 return TEST_SKIPPED; 2568 2569 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2570 return 0; 2571 } 2572 2573 static int 2574 create_wireless_algo_cipher_session(uint8_t dev_id, 2575 enum rte_crypto_cipher_operation op, 2576 enum rte_crypto_cipher_algorithm algo, 2577 const uint8_t *key, const uint8_t key_len, 2578 uint8_t iv_len) 2579 { 2580 uint8_t cipher_key[key_len]; 2581 struct crypto_testsuite_params *ts_params = &testsuite_params; 2582 struct crypto_unittest_params *ut_params = &unittest_params; 2583 2584 memcpy(cipher_key, key, key_len); 2585 2586 /* Setup Cipher Parameters */ 2587 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2588 ut_params->cipher_xform.next = NULL; 2589 2590 ut_params->cipher_xform.cipher.algo = algo; 2591 ut_params->cipher_xform.cipher.op = op; 2592 ut_params->cipher_xform.cipher.key.data = cipher_key; 2593 ut_params->cipher_xform.cipher.key.length = key_len; 2594 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2595 ut_params->cipher_xform.cipher.iv.length = iv_len; 2596 2597 debug_hexdump(stdout, "key:", key, key_len); 2598 2599 /* Create Crypto session */ 2600 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2601 &ut_params->cipher_xform, ts_params->session_mpool); 2602 2603 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2604 return TEST_SKIPPED; 2605 2606 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2607 return 0; 2608 } 2609 2610 static int 2611 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len, 2612 unsigned int cipher_len, 2613 unsigned int cipher_offset) 2614 { 2615 struct crypto_testsuite_params *ts_params = &testsuite_params; 2616 struct crypto_unittest_params *ut_params = &unittest_params; 2617 2618 /* Generate Crypto op data structure */ 2619 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2620 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2621 TEST_ASSERT_NOT_NULL(ut_params->op, 2622 "Failed to allocate pktmbuf offload"); 2623 2624 /* Set crypto operation data parameters */ 2625 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2626 2627 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2628 2629 /* set crypto operation source mbuf */ 2630 sym_op->m_src = ut_params->ibuf; 2631 2632 /* iv */ 2633 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2634 iv, iv_len); 2635 sym_op->cipher.data.length = cipher_len; 2636 sym_op->cipher.data.offset = cipher_offset; 2637 return 0; 2638 } 2639 2640 static int 2641 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len, 2642 unsigned int cipher_len, 2643 unsigned int cipher_offset) 2644 { 2645 struct crypto_testsuite_params *ts_params = &testsuite_params; 2646 struct crypto_unittest_params *ut_params = &unittest_params; 2647 2648 /* Generate Crypto op data structure */ 2649 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2650 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2651 TEST_ASSERT_NOT_NULL(ut_params->op, 2652 "Failed to allocate pktmbuf offload"); 2653 2654 /* Set crypto operation data parameters */ 2655 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2656 2657 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2658 2659 /* set crypto operation source mbuf */ 2660 sym_op->m_src = ut_params->ibuf; 2661 sym_op->m_dst = ut_params->obuf; 2662 2663 /* iv */ 2664 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2665 iv, iv_len); 2666 sym_op->cipher.data.length = cipher_len; 2667 sym_op->cipher.data.offset = cipher_offset; 2668 return 0; 2669 } 2670 2671 static int 2672 create_wireless_algo_cipher_auth_session(uint8_t dev_id, 2673 enum rte_crypto_cipher_operation cipher_op, 2674 enum rte_crypto_auth_operation auth_op, 2675 enum rte_crypto_auth_algorithm auth_algo, 2676 enum rte_crypto_cipher_algorithm cipher_algo, 2677 const uint8_t *a_key, uint8_t a_key_len, 2678 const uint8_t *c_key, uint8_t c_key_len, 2679 uint8_t auth_iv_len, uint8_t auth_len, 2680 uint8_t cipher_iv_len) 2681 2682 { 2683 struct crypto_testsuite_params *ts_params = &testsuite_params; 2684 struct crypto_unittest_params *ut_params = &unittest_params; 2685 2686 /* Setup Authentication Parameters */ 2687 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2688 ut_params->auth_xform.next = NULL; 2689 2690 ut_params->auth_xform.auth.op = auth_op; 2691 ut_params->auth_xform.auth.algo = auth_algo; 2692 ut_params->auth_xform.auth.key.length = a_key_len; 2693 ut_params->auth_xform.auth.key.data = a_key; 2694 ut_params->auth_xform.auth.digest_length = auth_len; 2695 /* Auth IV will be after cipher IV */ 2696 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2697 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2698 2699 /* Setup Cipher Parameters */ 2700 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2701 ut_params->cipher_xform.next = &ut_params->auth_xform; 2702 2703 ut_params->cipher_xform.cipher.algo = cipher_algo; 2704 ut_params->cipher_xform.cipher.op = cipher_op; 2705 ut_params->cipher_xform.cipher.key.data = c_key; 2706 ut_params->cipher_xform.cipher.key.length = c_key_len; 2707 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2708 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2709 2710 debug_hexdump(stdout, "Auth key:", a_key, c_key_len); 2711 debug_hexdump(stdout, "Cipher key:", c_key, c_key_len); 2712 2713 /* Create Crypto session*/ 2714 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2715 &ut_params->cipher_xform, ts_params->session_mpool); 2716 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2717 return TEST_SKIPPED; 2718 2719 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2720 return 0; 2721 } 2722 2723 static int 2724 create_wireless_cipher_auth_session(uint8_t dev_id, 2725 enum rte_crypto_cipher_operation cipher_op, 2726 enum rte_crypto_auth_operation auth_op, 2727 enum rte_crypto_auth_algorithm auth_algo, 2728 enum rte_crypto_cipher_algorithm cipher_algo, 2729 const struct wireless_test_data *tdata) 2730 { 2731 const uint8_t key_len = tdata->key.len; 2732 uint8_t cipher_auth_key[key_len]; 2733 2734 struct crypto_testsuite_params *ts_params = &testsuite_params; 2735 struct crypto_unittest_params *ut_params = &unittest_params; 2736 const uint8_t *key = tdata->key.data; 2737 const uint8_t auth_len = tdata->digest.len; 2738 uint8_t cipher_iv_len = tdata->cipher_iv.len; 2739 uint8_t auth_iv_len = tdata->auth_iv.len; 2740 2741 memcpy(cipher_auth_key, key, key_len); 2742 2743 /* Setup Authentication Parameters */ 2744 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2745 ut_params->auth_xform.next = NULL; 2746 2747 ut_params->auth_xform.auth.op = auth_op; 2748 ut_params->auth_xform.auth.algo = auth_algo; 2749 ut_params->auth_xform.auth.key.length = key_len; 2750 /* Hash key = cipher key */ 2751 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2752 ut_params->auth_xform.auth.digest_length = auth_len; 2753 /* Auth IV will be after cipher IV */ 2754 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2755 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2756 2757 /* Setup Cipher Parameters */ 2758 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2759 ut_params->cipher_xform.next = &ut_params->auth_xform; 2760 2761 ut_params->cipher_xform.cipher.algo = cipher_algo; 2762 ut_params->cipher_xform.cipher.op = cipher_op; 2763 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2764 ut_params->cipher_xform.cipher.key.length = key_len; 2765 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2766 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2767 2768 2769 debug_hexdump(stdout, "key:", key, key_len); 2770 2771 /* Create Crypto session*/ 2772 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2773 &ut_params->cipher_xform, ts_params->session_mpool); 2774 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2775 return TEST_SKIPPED; 2776 2777 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2778 return 0; 2779 } 2780 2781 static int 2782 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id, 2783 const struct wireless_test_data *tdata) 2784 { 2785 return create_wireless_cipher_auth_session(dev_id, 2786 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2787 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3, 2788 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata); 2789 } 2790 2791 static int 2792 create_wireless_algo_auth_cipher_session(uint8_t dev_id, 2793 enum rte_crypto_cipher_operation cipher_op, 2794 enum rte_crypto_auth_operation auth_op, 2795 enum rte_crypto_auth_algorithm auth_algo, 2796 enum rte_crypto_cipher_algorithm cipher_algo, 2797 const uint8_t *a_key, const uint8_t a_key_len, 2798 const uint8_t *c_key, const uint8_t c_key_len, 2799 uint8_t auth_iv_len, uint8_t auth_len, 2800 uint8_t cipher_iv_len) 2801 { 2802 struct crypto_testsuite_params *ts_params = &testsuite_params; 2803 struct crypto_unittest_params *ut_params = &unittest_params; 2804 2805 /* Setup Authentication Parameters */ 2806 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2807 ut_params->auth_xform.auth.op = auth_op; 2808 ut_params->auth_xform.next = &ut_params->cipher_xform; 2809 ut_params->auth_xform.auth.algo = auth_algo; 2810 ut_params->auth_xform.auth.key.length = a_key_len; 2811 ut_params->auth_xform.auth.key.data = a_key; 2812 ut_params->auth_xform.auth.digest_length = auth_len; 2813 /* Auth IV will be after cipher IV */ 2814 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2815 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2816 2817 /* Setup Cipher Parameters */ 2818 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2819 ut_params->cipher_xform.next = NULL; 2820 ut_params->cipher_xform.cipher.algo = cipher_algo; 2821 ut_params->cipher_xform.cipher.op = cipher_op; 2822 ut_params->cipher_xform.cipher.key.data = c_key; 2823 ut_params->cipher_xform.cipher.key.length = c_key_len; 2824 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2825 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2826 2827 debug_hexdump(stdout, "Auth key:", a_key, a_key_len); 2828 debug_hexdump(stdout, "Cipher key:", c_key, c_key_len); 2829 2830 /* Create Crypto session*/ 2831 if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 2832 ut_params->auth_xform.next = NULL; 2833 ut_params->cipher_xform.next = &ut_params->auth_xform; 2834 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2835 &ut_params->cipher_xform, ts_params->session_mpool); 2836 } else 2837 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 2838 &ut_params->auth_xform, ts_params->session_mpool); 2839 2840 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 2841 return TEST_SKIPPED; 2842 2843 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2844 2845 return 0; 2846 } 2847 2848 static int 2849 create_wireless_algo_hash_operation(const uint8_t *auth_tag, 2850 unsigned int auth_tag_len, 2851 const uint8_t *iv, unsigned int iv_len, 2852 unsigned int data_pad_len, 2853 enum rte_crypto_auth_operation op, 2854 unsigned int auth_len, unsigned int auth_offset) 2855 { 2856 struct crypto_testsuite_params *ts_params = &testsuite_params; 2857 2858 struct crypto_unittest_params *ut_params = &unittest_params; 2859 2860 /* Generate Crypto op data structure */ 2861 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2862 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2863 TEST_ASSERT_NOT_NULL(ut_params->op, 2864 "Failed to allocate pktmbuf offload"); 2865 2866 /* Set crypto operation data parameters */ 2867 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2868 2869 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2870 2871 /* set crypto operation source mbuf */ 2872 sym_op->m_src = ut_params->ibuf; 2873 2874 /* iv */ 2875 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2876 iv, iv_len); 2877 /* digest */ 2878 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2879 ut_params->ibuf, auth_tag_len); 2880 2881 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2882 "no room to append auth tag"); 2883 ut_params->digest = sym_op->auth.digest.data; 2884 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2885 ut_params->ibuf, data_pad_len); 2886 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2887 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2888 else 2889 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2890 2891 debug_hexdump(stdout, "digest:", 2892 sym_op->auth.digest.data, 2893 auth_tag_len); 2894 2895 sym_op->auth.data.length = auth_len; 2896 sym_op->auth.data.offset = auth_offset; 2897 2898 return 0; 2899 } 2900 2901 static int 2902 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata, 2903 enum rte_crypto_auth_operation op) 2904 { 2905 struct crypto_testsuite_params *ts_params = &testsuite_params; 2906 struct crypto_unittest_params *ut_params = &unittest_params; 2907 2908 const uint8_t *auth_tag = tdata->digest.data; 2909 const unsigned int auth_tag_len = tdata->digest.len; 2910 unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len); 2911 unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2912 2913 const uint8_t *cipher_iv = tdata->cipher_iv.data; 2914 const uint8_t cipher_iv_len = tdata->cipher_iv.len; 2915 const uint8_t *auth_iv = tdata->auth_iv.data; 2916 const uint8_t auth_iv_len = tdata->auth_iv.len; 2917 const unsigned int cipher_len = tdata->validCipherLenInBits.len; 2918 const unsigned int auth_len = tdata->validAuthLenInBits.len; 2919 2920 /* Generate Crypto op data structure */ 2921 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2922 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2923 TEST_ASSERT_NOT_NULL(ut_params->op, 2924 "Failed to allocate pktmbuf offload"); 2925 /* Set crypto operation data parameters */ 2926 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2927 2928 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2929 2930 /* set crypto operation source mbuf */ 2931 sym_op->m_src = ut_params->ibuf; 2932 2933 /* digest */ 2934 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2935 ut_params->ibuf, auth_tag_len); 2936 2937 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2938 "no room to append auth tag"); 2939 ut_params->digest = sym_op->auth.digest.data; 2940 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2941 ut_params->ibuf, data_pad_len); 2942 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2943 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2944 else 2945 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2946 2947 debug_hexdump(stdout, "digest:", 2948 sym_op->auth.digest.data, 2949 auth_tag_len); 2950 2951 /* Copy cipher and auth IVs at the end of the crypto operation */ 2952 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2953 IV_OFFSET); 2954 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2955 iv_ptr += cipher_iv_len; 2956 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2957 2958 sym_op->cipher.data.length = cipher_len; 2959 sym_op->cipher.data.offset = 0; 2960 sym_op->auth.data.length = auth_len; 2961 sym_op->auth.data.offset = 0; 2962 2963 return 0; 2964 } 2965 2966 static int 2967 create_zuc_cipher_hash_generate_operation( 2968 const struct wireless_test_data *tdata) 2969 { 2970 return create_wireless_cipher_hash_operation(tdata, 2971 RTE_CRYPTO_AUTH_OP_GENERATE); 2972 } 2973 2974 static int 2975 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag, 2976 const unsigned auth_tag_len, 2977 const uint8_t *auth_iv, uint8_t auth_iv_len, 2978 unsigned data_pad_len, 2979 enum rte_crypto_auth_operation op, 2980 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2981 const unsigned cipher_len, const unsigned cipher_offset, 2982 const unsigned auth_len, const unsigned auth_offset) 2983 { 2984 struct crypto_testsuite_params *ts_params = &testsuite_params; 2985 struct crypto_unittest_params *ut_params = &unittest_params; 2986 2987 enum rte_crypto_cipher_algorithm cipher_algo = 2988 ut_params->cipher_xform.cipher.algo; 2989 enum rte_crypto_auth_algorithm auth_algo = 2990 ut_params->auth_xform.auth.algo; 2991 2992 /* Generate Crypto op data structure */ 2993 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2994 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2995 TEST_ASSERT_NOT_NULL(ut_params->op, 2996 "Failed to allocate pktmbuf offload"); 2997 /* Set crypto operation data parameters */ 2998 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2999 3000 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3001 3002 /* set crypto operation source mbuf */ 3003 sym_op->m_src = ut_params->ibuf; 3004 3005 /* digest */ 3006 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 3007 ut_params->ibuf, auth_tag_len); 3008 3009 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 3010 "no room to append auth tag"); 3011 ut_params->digest = sym_op->auth.digest.data; 3012 3013 if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) { 3014 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3015 ut_params->ibuf, data_pad_len); 3016 } else { 3017 struct rte_mbuf *m = ut_params->ibuf; 3018 unsigned int offset = data_pad_len; 3019 3020 while (offset > m->data_len && m->next != NULL) { 3021 offset -= m->data_len; 3022 m = m->next; 3023 } 3024 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3025 m, offset); 3026 } 3027 3028 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 3029 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3030 else 3031 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3032 3033 debug_hexdump(stdout, "digest:", 3034 sym_op->auth.digest.data, 3035 auth_tag_len); 3036 3037 /* Copy cipher and auth IVs at the end of the crypto operation */ 3038 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 3039 IV_OFFSET); 3040 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 3041 iv_ptr += cipher_iv_len; 3042 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 3043 3044 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 3045 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 3046 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 3047 sym_op->cipher.data.length = cipher_len; 3048 sym_op->cipher.data.offset = cipher_offset; 3049 } else { 3050 sym_op->cipher.data.length = cipher_len >> 3; 3051 sym_op->cipher.data.offset = cipher_offset >> 3; 3052 } 3053 3054 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 3055 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 3056 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 3057 sym_op->auth.data.length = auth_len; 3058 sym_op->auth.data.offset = auth_offset; 3059 } else { 3060 sym_op->auth.data.length = auth_len >> 3; 3061 sym_op->auth.data.offset = auth_offset >> 3; 3062 } 3063 3064 return 0; 3065 } 3066 3067 static int 3068 create_wireless_algo_auth_cipher_operation( 3069 const uint8_t *auth_tag, unsigned int auth_tag_len, 3070 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 3071 const uint8_t *auth_iv, uint8_t auth_iv_len, 3072 unsigned int data_pad_len, 3073 unsigned int cipher_len, unsigned int cipher_offset, 3074 unsigned int auth_len, unsigned int auth_offset, 3075 uint8_t op_mode, uint8_t do_sgl, uint8_t verify) 3076 { 3077 struct crypto_testsuite_params *ts_params = &testsuite_params; 3078 struct crypto_unittest_params *ut_params = &unittest_params; 3079 3080 enum rte_crypto_cipher_algorithm cipher_algo = 3081 ut_params->cipher_xform.cipher.algo; 3082 enum rte_crypto_auth_algorithm auth_algo = 3083 ut_params->auth_xform.auth.algo; 3084 3085 /* Generate Crypto op data structure */ 3086 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 3087 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 3088 TEST_ASSERT_NOT_NULL(ut_params->op, 3089 "Failed to allocate pktmbuf offload"); 3090 3091 /* Set crypto operation data parameters */ 3092 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 3093 3094 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 3095 3096 /* set crypto operation mbufs */ 3097 sym_op->m_src = ut_params->ibuf; 3098 if (op_mode == OUT_OF_PLACE) 3099 sym_op->m_dst = ut_params->obuf; 3100 3101 /* digest */ 3102 if (!do_sgl) { 3103 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset( 3104 (op_mode == IN_PLACE ? 3105 ut_params->ibuf : ut_params->obuf), 3106 uint8_t *, data_pad_len); 3107 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 3108 (op_mode == IN_PLACE ? 3109 ut_params->ibuf : ut_params->obuf), 3110 data_pad_len); 3111 memset(sym_op->auth.digest.data, 0, auth_tag_len); 3112 } else { 3113 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3); 3114 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ? 3115 sym_op->m_src : sym_op->m_dst); 3116 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) { 3117 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 3118 sgl_buf = sgl_buf->next; 3119 } 3120 3121 /* The last segment should be large enough to hold full digest */ 3122 if (sgl_buf->data_len < auth_tag_len) { 3123 rte_pktmbuf_free(sgl_buf->next); 3124 sgl_buf->next = NULL; 3125 TEST_ASSERT_NOT_NULL(rte_pktmbuf_append(sgl_buf, 3126 auth_tag_len - sgl_buf->data_len), 3127 "No room to append auth tag"); 3128 } 3129 3130 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf, 3131 uint8_t *, remaining_off); 3132 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf, 3133 remaining_off); 3134 memset(sym_op->auth.digest.data, 0, remaining_off); 3135 while (sgl_buf->next != NULL) { 3136 memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *), 3137 0, rte_pktmbuf_data_len(sgl_buf)); 3138 sgl_buf = sgl_buf->next; 3139 } 3140 } 3141 3142 /* Copy digest for the verification */ 3143 if (verify) 3144 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 3145 3146 /* Copy cipher and auth IVs at the end of the crypto operation */ 3147 uint8_t *iv_ptr = rte_crypto_op_ctod_offset( 3148 ut_params->op, uint8_t *, IV_OFFSET); 3149 3150 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 3151 iv_ptr += cipher_iv_len; 3152 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 3153 3154 /* Only copy over the offset data needed from src to dst in OOP, 3155 * if the auth and cipher offsets are not aligned 3156 */ 3157 if (op_mode == OUT_OF_PLACE) { 3158 if (cipher_offset > auth_offset) 3159 rte_memcpy( 3160 rte_pktmbuf_mtod_offset( 3161 sym_op->m_dst, 3162 uint8_t *, auth_offset >> 3), 3163 rte_pktmbuf_mtod_offset( 3164 sym_op->m_src, 3165 uint8_t *, auth_offset >> 3), 3166 ((cipher_offset >> 3) - (auth_offset >> 3))); 3167 } 3168 3169 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 3170 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 3171 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 3172 sym_op->cipher.data.length = cipher_len; 3173 sym_op->cipher.data.offset = cipher_offset; 3174 } else { 3175 sym_op->cipher.data.length = cipher_len >> 3; 3176 sym_op->cipher.data.offset = cipher_offset >> 3; 3177 } 3178 3179 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 3180 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 3181 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 3182 sym_op->auth.data.length = auth_len; 3183 sym_op->auth.data.offset = auth_offset; 3184 } else { 3185 sym_op->auth.data.length = auth_len >> 3; 3186 sym_op->auth.data.offset = auth_offset >> 3; 3187 } 3188 3189 return 0; 3190 } 3191 3192 static int 3193 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) 3194 { 3195 struct crypto_testsuite_params *ts_params = &testsuite_params; 3196 struct crypto_unittest_params *ut_params = &unittest_params; 3197 3198 int retval; 3199 unsigned plaintext_pad_len; 3200 unsigned plaintext_len; 3201 uint8_t *plaintext; 3202 struct rte_cryptodev_info dev_info; 3203 3204 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3205 uint64_t feat_flags = dev_info.feature_flags; 3206 3207 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3208 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3209 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3210 return TEST_SKIPPED; 3211 } 3212 3213 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3214 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3215 printf("Device doesn't support RAW data-path APIs.\n"); 3216 return TEST_SKIPPED; 3217 } 3218 3219 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3220 return TEST_SKIPPED; 3221 3222 /* Verify the capabilities */ 3223 struct rte_cryptodev_sym_capability_idx cap_idx; 3224 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3225 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3226 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3227 &cap_idx) == NULL) 3228 return TEST_SKIPPED; 3229 3230 /* Create SNOW 3G session */ 3231 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3232 tdata->key.data, tdata->key.len, 3233 tdata->auth_iv.len, tdata->digest.len, 3234 RTE_CRYPTO_AUTH_OP_GENERATE, 3235 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3236 if (retval < 0) 3237 return retval; 3238 3239 /* alloc mbuf and set payload */ 3240 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3241 3242 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3243 rte_pktmbuf_tailroom(ut_params->ibuf)); 3244 3245 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3246 /* Append data which is padded to a multiple of */ 3247 /* the algorithms block size */ 3248 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3249 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3250 plaintext_pad_len); 3251 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3252 3253 /* Create SNOW 3G operation */ 3254 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3255 tdata->auth_iv.data, tdata->auth_iv.len, 3256 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3257 tdata->validAuthLenInBits.len, 3258 0); 3259 if (retval < 0) 3260 return retval; 3261 3262 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3263 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 3264 0); 3265 if (retval != TEST_SUCCESS) 3266 return retval; 3267 } else 3268 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3269 ut_params->op); 3270 ut_params->obuf = ut_params->op->sym->m_src; 3271 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3272 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 3273 uint8_t *, 3274 plaintext_pad_len); 3275 3276 /* Validate obuf */ 3277 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3278 ut_params->digest, 3279 tdata->digest.data, 3280 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 3281 "SNOW 3G Generated auth tag not as expected"); 3282 3283 return 0; 3284 } 3285 3286 static int 3287 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) 3288 { 3289 struct crypto_testsuite_params *ts_params = &testsuite_params; 3290 struct crypto_unittest_params *ut_params = &unittest_params; 3291 3292 int retval; 3293 unsigned plaintext_pad_len; 3294 unsigned plaintext_len; 3295 uint8_t *plaintext; 3296 struct rte_cryptodev_info dev_info; 3297 3298 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3299 uint64_t feat_flags = dev_info.feature_flags; 3300 3301 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3302 ((tdata->validAuthLenInBits.len % 8) != 0)) { 3303 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3304 return TEST_SKIPPED; 3305 } 3306 3307 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3308 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3309 printf("Device doesn't support RAW data-path APIs.\n"); 3310 return TEST_SKIPPED; 3311 } 3312 3313 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3314 return TEST_SKIPPED; 3315 3316 /* Verify the capabilities */ 3317 struct rte_cryptodev_sym_capability_idx cap_idx; 3318 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3319 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 3320 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3321 &cap_idx) == NULL) 3322 return TEST_SKIPPED; 3323 3324 /* Create SNOW 3G session */ 3325 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3326 tdata->key.data, tdata->key.len, 3327 tdata->auth_iv.len, tdata->digest.len, 3328 RTE_CRYPTO_AUTH_OP_VERIFY, 3329 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 3330 if (retval < 0) 3331 return retval; 3332 /* alloc mbuf and set payload */ 3333 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3334 3335 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3336 rte_pktmbuf_tailroom(ut_params->ibuf)); 3337 3338 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3339 /* Append data which is padded to a multiple of */ 3340 /* the algorithms block size */ 3341 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3342 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3343 plaintext_pad_len); 3344 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3345 3346 /* Create SNOW 3G operation */ 3347 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3348 tdata->digest.len, 3349 tdata->auth_iv.data, tdata->auth_iv.len, 3350 plaintext_pad_len, 3351 RTE_CRYPTO_AUTH_OP_VERIFY, 3352 tdata->validAuthLenInBits.len, 3353 0); 3354 if (retval < 0) 3355 return retval; 3356 3357 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3358 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 3359 0); 3360 if (retval != TEST_SUCCESS) 3361 return retval; 3362 } else 3363 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3364 ut_params->op); 3365 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3366 ut_params->obuf = ut_params->op->sym->m_src; 3367 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 3368 uint8_t *, 3369 plaintext_pad_len); 3370 3371 /* Validate obuf */ 3372 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3373 return 0; 3374 else 3375 return -1; 3376 3377 return 0; 3378 } 3379 3380 static int 3381 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata) 3382 { 3383 struct crypto_testsuite_params *ts_params = &testsuite_params; 3384 struct crypto_unittest_params *ut_params = &unittest_params; 3385 3386 int retval; 3387 unsigned plaintext_pad_len; 3388 unsigned plaintext_len; 3389 uint8_t *plaintext; 3390 struct rte_cryptodev_info dev_info; 3391 3392 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3393 uint64_t feat_flags = dev_info.feature_flags; 3394 3395 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3396 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3397 printf("Device doesn't support RAW data-path APIs.\n"); 3398 return TEST_SKIPPED; 3399 } 3400 3401 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3402 return TEST_SKIPPED; 3403 3404 /* Verify the capabilities */ 3405 struct rte_cryptodev_sym_capability_idx cap_idx; 3406 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3407 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3408 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3409 &cap_idx) == NULL) 3410 return TEST_SKIPPED; 3411 3412 /* Create KASUMI session */ 3413 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3414 tdata->key.data, tdata->key.len, 3415 0, tdata->digest.len, 3416 RTE_CRYPTO_AUTH_OP_GENERATE, 3417 RTE_CRYPTO_AUTH_KASUMI_F9); 3418 if (retval < 0) 3419 return retval; 3420 3421 /* alloc mbuf and set payload */ 3422 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3423 3424 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3425 rte_pktmbuf_tailroom(ut_params->ibuf)); 3426 3427 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3428 /* Append data which is padded to a multiple of */ 3429 /* the algorithms block size */ 3430 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3431 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3432 plaintext_pad_len); 3433 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3434 3435 /* Create KASUMI operation */ 3436 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 3437 NULL, 0, 3438 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 3439 tdata->plaintext.len, 3440 0); 3441 if (retval < 0) 3442 return retval; 3443 3444 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3445 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 3446 ut_params->op); 3447 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3448 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 3449 0); 3450 if (retval != TEST_SUCCESS) 3451 return retval; 3452 } else 3453 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3454 ut_params->op); 3455 3456 ut_params->obuf = ut_params->op->sym->m_src; 3457 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3458 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 3459 uint8_t *, 3460 plaintext_pad_len); 3461 3462 /* Validate obuf */ 3463 TEST_ASSERT_BUFFERS_ARE_EQUAL( 3464 ut_params->digest, 3465 tdata->digest.data, 3466 DIGEST_BYTE_LENGTH_KASUMI_F9, 3467 "KASUMI Generated auth tag not as expected"); 3468 3469 return 0; 3470 } 3471 3472 static int 3473 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata) 3474 { 3475 struct crypto_testsuite_params *ts_params = &testsuite_params; 3476 struct crypto_unittest_params *ut_params = &unittest_params; 3477 3478 int retval; 3479 unsigned plaintext_pad_len; 3480 unsigned plaintext_len; 3481 uint8_t *plaintext; 3482 struct rte_cryptodev_info dev_info; 3483 3484 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3485 uint64_t feat_flags = dev_info.feature_flags; 3486 3487 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3488 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3489 printf("Device doesn't support RAW data-path APIs.\n"); 3490 return TEST_SKIPPED; 3491 } 3492 3493 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3494 return TEST_SKIPPED; 3495 3496 /* Verify the capabilities */ 3497 struct rte_cryptodev_sym_capability_idx cap_idx; 3498 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 3499 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 3500 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3501 &cap_idx) == NULL) 3502 return TEST_SKIPPED; 3503 3504 /* Create KASUMI session */ 3505 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 3506 tdata->key.data, tdata->key.len, 3507 0, tdata->digest.len, 3508 RTE_CRYPTO_AUTH_OP_VERIFY, 3509 RTE_CRYPTO_AUTH_KASUMI_F9); 3510 if (retval < 0) 3511 return retval; 3512 /* alloc mbuf and set payload */ 3513 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3514 3515 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3516 rte_pktmbuf_tailroom(ut_params->ibuf)); 3517 3518 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3519 /* Append data which is padded to a multiple */ 3520 /* of the algorithms block size */ 3521 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3522 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3523 plaintext_pad_len); 3524 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3525 3526 /* Create KASUMI operation */ 3527 retval = create_wireless_algo_hash_operation(tdata->digest.data, 3528 tdata->digest.len, 3529 NULL, 0, 3530 plaintext_pad_len, 3531 RTE_CRYPTO_AUTH_OP_VERIFY, 3532 tdata->plaintext.len, 3533 0); 3534 if (retval < 0) 3535 return retval; 3536 3537 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3538 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 3539 0); 3540 if (retval != TEST_SUCCESS) 3541 return retval; 3542 } else 3543 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3544 ut_params->op); 3545 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3546 ut_params->obuf = ut_params->op->sym->m_src; 3547 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 3548 uint8_t *, 3549 plaintext_pad_len); 3550 3551 /* Validate obuf */ 3552 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3553 return 0; 3554 else 3555 return -1; 3556 3557 return 0; 3558 } 3559 3560 static int 3561 test_snow3g_hash_generate_test_case_1(void) 3562 { 3563 return test_snow3g_authentication(&snow3g_hash_test_case_1); 3564 } 3565 3566 static int 3567 test_snow3g_hash_generate_test_case_2(void) 3568 { 3569 return test_snow3g_authentication(&snow3g_hash_test_case_2); 3570 } 3571 3572 static int 3573 test_snow3g_hash_generate_test_case_3(void) 3574 { 3575 return test_snow3g_authentication(&snow3g_hash_test_case_3); 3576 } 3577 3578 static int 3579 test_snow3g_hash_generate_test_case_4(void) 3580 { 3581 return test_snow3g_authentication(&snow3g_hash_test_case_4); 3582 } 3583 3584 static int 3585 test_snow3g_hash_generate_test_case_5(void) 3586 { 3587 return test_snow3g_authentication(&snow3g_hash_test_case_5); 3588 } 3589 3590 static int 3591 test_snow3g_hash_generate_test_case_6(void) 3592 { 3593 return test_snow3g_authentication(&snow3g_hash_test_case_6); 3594 } 3595 3596 static int 3597 test_snow3g_hash_verify_test_case_1(void) 3598 { 3599 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1); 3600 3601 } 3602 3603 static int 3604 test_snow3g_hash_verify_test_case_2(void) 3605 { 3606 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2); 3607 } 3608 3609 static int 3610 test_snow3g_hash_verify_test_case_3(void) 3611 { 3612 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3); 3613 } 3614 3615 static int 3616 test_snow3g_hash_verify_test_case_4(void) 3617 { 3618 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4); 3619 } 3620 3621 static int 3622 test_snow3g_hash_verify_test_case_5(void) 3623 { 3624 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5); 3625 } 3626 3627 static int 3628 test_snow3g_hash_verify_test_case_6(void) 3629 { 3630 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6); 3631 } 3632 3633 static int 3634 test_kasumi_hash_generate_test_case_1(void) 3635 { 3636 return test_kasumi_authentication(&kasumi_hash_test_case_1); 3637 } 3638 3639 static int 3640 test_kasumi_hash_generate_test_case_2(void) 3641 { 3642 return test_kasumi_authentication(&kasumi_hash_test_case_2); 3643 } 3644 3645 static int 3646 test_kasumi_hash_generate_test_case_3(void) 3647 { 3648 return test_kasumi_authentication(&kasumi_hash_test_case_3); 3649 } 3650 3651 static int 3652 test_kasumi_hash_generate_test_case_4(void) 3653 { 3654 return test_kasumi_authentication(&kasumi_hash_test_case_4); 3655 } 3656 3657 static int 3658 test_kasumi_hash_generate_test_case_5(void) 3659 { 3660 return test_kasumi_authentication(&kasumi_hash_test_case_5); 3661 } 3662 3663 static int 3664 test_kasumi_hash_generate_test_case_6(void) 3665 { 3666 return test_kasumi_authentication(&kasumi_hash_test_case_6); 3667 } 3668 3669 static int 3670 test_kasumi_hash_verify_test_case_1(void) 3671 { 3672 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1); 3673 } 3674 3675 static int 3676 test_kasumi_hash_verify_test_case_2(void) 3677 { 3678 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2); 3679 } 3680 3681 static int 3682 test_kasumi_hash_verify_test_case_3(void) 3683 { 3684 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3); 3685 } 3686 3687 static int 3688 test_kasumi_hash_verify_test_case_4(void) 3689 { 3690 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4); 3691 } 3692 3693 static int 3694 test_kasumi_hash_verify_test_case_5(void) 3695 { 3696 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5); 3697 } 3698 3699 static int 3700 test_kasumi_encryption(const struct kasumi_test_data *tdata) 3701 { 3702 struct crypto_testsuite_params *ts_params = &testsuite_params; 3703 struct crypto_unittest_params *ut_params = &unittest_params; 3704 3705 int retval; 3706 uint8_t *plaintext, *ciphertext; 3707 unsigned plaintext_pad_len; 3708 unsigned plaintext_len; 3709 struct rte_cryptodev_info dev_info; 3710 3711 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3712 uint64_t feat_flags = dev_info.feature_flags; 3713 3714 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3715 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3716 printf("Device doesn't support RAW data-path APIs.\n"); 3717 return TEST_SKIPPED; 3718 } 3719 3720 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3721 return TEST_SKIPPED; 3722 3723 /* Verify the capabilities */ 3724 struct rte_cryptodev_sym_capability_idx cap_idx; 3725 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3726 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3727 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3728 &cap_idx) == NULL) 3729 return TEST_SKIPPED; 3730 3731 /* Create KASUMI session */ 3732 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3733 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3734 RTE_CRYPTO_CIPHER_KASUMI_F8, 3735 tdata->key.data, tdata->key.len, 3736 tdata->cipher_iv.len); 3737 if (retval < 0) 3738 return retval; 3739 3740 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3741 3742 /* Clear mbuf payload */ 3743 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3744 rte_pktmbuf_tailroom(ut_params->ibuf)); 3745 3746 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3747 /* Append data which is padded to a multiple */ 3748 /* of the algorithms block size */ 3749 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3750 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3751 plaintext_pad_len); 3752 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3753 3754 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3755 3756 /* Create KASUMI operation */ 3757 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3758 tdata->cipher_iv.len, 3759 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3760 tdata->validCipherOffsetInBits.len); 3761 if (retval < 0) 3762 return retval; 3763 3764 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3765 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 3766 tdata->cipher_iv.len); 3767 if (retval != TEST_SUCCESS) 3768 return retval; 3769 } else 3770 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3771 ut_params->op); 3772 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3773 3774 ut_params->obuf = ut_params->op->sym->m_dst; 3775 if (ut_params->obuf) 3776 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3777 else 3778 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3779 3780 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3781 3782 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3783 (tdata->validCipherOffsetInBits.len >> 3); 3784 /* Validate obuf */ 3785 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3786 ciphertext, 3787 reference_ciphertext, 3788 tdata->validCipherLenInBits.len, 3789 "KASUMI Ciphertext data not as expected"); 3790 return 0; 3791 } 3792 3793 static int 3794 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata) 3795 { 3796 struct crypto_testsuite_params *ts_params = &testsuite_params; 3797 struct crypto_unittest_params *ut_params = &unittest_params; 3798 3799 int retval; 3800 3801 unsigned int plaintext_pad_len; 3802 unsigned int plaintext_len; 3803 3804 uint8_t buffer[10000]; 3805 const uint8_t *ciphertext; 3806 3807 struct rte_cryptodev_info dev_info; 3808 3809 /* Verify the capabilities */ 3810 struct rte_cryptodev_sym_capability_idx cap_idx; 3811 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3812 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3813 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3814 &cap_idx) == NULL) 3815 return TEST_SKIPPED; 3816 3817 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3818 3819 uint64_t feat_flags = dev_info.feature_flags; 3820 3821 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 3822 printf("Device doesn't support in-place scatter-gather. " 3823 "Test Skipped.\n"); 3824 return TEST_SKIPPED; 3825 } 3826 3827 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3828 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3829 printf("Device doesn't support RAW data-path APIs.\n"); 3830 return TEST_SKIPPED; 3831 } 3832 3833 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3834 return TEST_SKIPPED; 3835 3836 /* Create KASUMI session */ 3837 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3838 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3839 RTE_CRYPTO_CIPHER_KASUMI_F8, 3840 tdata->key.data, tdata->key.len, 3841 tdata->cipher_iv.len); 3842 if (retval < 0) 3843 return retval; 3844 3845 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3846 3847 3848 /* Append data which is padded to a multiple */ 3849 /* of the algorithms block size */ 3850 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3851 3852 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3853 plaintext_pad_len, 10, 0); 3854 3855 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3856 3857 /* Create KASUMI operation */ 3858 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3859 tdata->cipher_iv.len, 3860 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3861 tdata->validCipherOffsetInBits.len); 3862 if (retval < 0) 3863 return retval; 3864 3865 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 3866 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 3867 tdata->cipher_iv.len); 3868 if (retval != TEST_SUCCESS) 3869 return retval; 3870 } else 3871 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3872 ut_params->op); 3873 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3874 3875 ut_params->obuf = ut_params->op->sym->m_dst; 3876 3877 if (ut_params->obuf) 3878 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3879 plaintext_len, buffer); 3880 else 3881 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3882 tdata->validCipherOffsetInBits.len >> 3, 3883 plaintext_len, buffer); 3884 3885 /* Validate obuf */ 3886 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3887 3888 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3889 (tdata->validCipherOffsetInBits.len >> 3); 3890 /* Validate obuf */ 3891 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3892 ciphertext, 3893 reference_ciphertext, 3894 tdata->validCipherLenInBits.len, 3895 "KASUMI Ciphertext data not as expected"); 3896 return 0; 3897 } 3898 3899 static int 3900 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata) 3901 { 3902 struct crypto_testsuite_params *ts_params = &testsuite_params; 3903 struct crypto_unittest_params *ut_params = &unittest_params; 3904 3905 int retval; 3906 uint8_t *plaintext, *ciphertext; 3907 unsigned plaintext_pad_len; 3908 unsigned plaintext_len; 3909 3910 /* Verify the capabilities */ 3911 struct rte_cryptodev_sym_capability_idx cap_idx; 3912 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3913 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3914 /* Data-path service does not support OOP */ 3915 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3916 &cap_idx) == NULL) 3917 return TEST_SKIPPED; 3918 3919 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3920 return TEST_SKIPPED; 3921 3922 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3923 return TEST_SKIPPED; 3924 3925 /* Create KASUMI session */ 3926 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3927 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3928 RTE_CRYPTO_CIPHER_KASUMI_F8, 3929 tdata->key.data, tdata->key.len, 3930 tdata->cipher_iv.len); 3931 if (retval < 0) 3932 return retval; 3933 3934 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3935 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3936 3937 /* Clear mbuf payload */ 3938 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3939 rte_pktmbuf_tailroom(ut_params->ibuf)); 3940 3941 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3942 /* Append data which is padded to a multiple */ 3943 /* of the algorithms block size */ 3944 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3945 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3946 plaintext_pad_len); 3947 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3948 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3949 3950 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3951 3952 /* Create KASUMI operation */ 3953 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3954 tdata->cipher_iv.len, 3955 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3956 tdata->validCipherOffsetInBits.len); 3957 if (retval < 0) 3958 return retval; 3959 3960 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3961 ut_params->op); 3962 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3963 3964 ut_params->obuf = ut_params->op->sym->m_dst; 3965 if (ut_params->obuf) 3966 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3967 else 3968 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3969 3970 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3971 3972 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3973 (tdata->validCipherOffsetInBits.len >> 3); 3974 /* Validate obuf */ 3975 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3976 ciphertext, 3977 reference_ciphertext, 3978 tdata->validCipherLenInBits.len, 3979 "KASUMI Ciphertext data not as expected"); 3980 return 0; 3981 } 3982 3983 static int 3984 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata) 3985 { 3986 struct crypto_testsuite_params *ts_params = &testsuite_params; 3987 struct crypto_unittest_params *ut_params = &unittest_params; 3988 3989 int retval; 3990 unsigned int plaintext_pad_len; 3991 unsigned int plaintext_len; 3992 3993 const uint8_t *ciphertext; 3994 uint8_t buffer[2048]; 3995 3996 struct rte_cryptodev_info dev_info; 3997 3998 /* Verify the capabilities */ 3999 struct rte_cryptodev_sym_capability_idx cap_idx; 4000 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4001 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4002 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4003 &cap_idx) == NULL) 4004 return TEST_SKIPPED; 4005 4006 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4007 return TEST_SKIPPED; 4008 4009 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4010 return TEST_SKIPPED; 4011 4012 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4013 4014 uint64_t feat_flags = dev_info.feature_flags; 4015 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 4016 printf("Device doesn't support out-of-place scatter-gather " 4017 "in both input and output mbufs. " 4018 "Test Skipped.\n"); 4019 return TEST_SKIPPED; 4020 } 4021 4022 /* Create KASUMI session */ 4023 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4024 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4025 RTE_CRYPTO_CIPHER_KASUMI_F8, 4026 tdata->key.data, tdata->key.len, 4027 tdata->cipher_iv.len); 4028 if (retval < 0) 4029 return retval; 4030 4031 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4032 /* Append data which is padded to a multiple */ 4033 /* of the algorithms block size */ 4034 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 4035 4036 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4037 plaintext_pad_len, 10, 0); 4038 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4039 plaintext_pad_len, 3, 0); 4040 4041 /* Append data which is padded to a multiple */ 4042 /* of the algorithms block size */ 4043 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 4044 4045 /* Create KASUMI operation */ 4046 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4047 tdata->cipher_iv.len, 4048 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4049 tdata->validCipherOffsetInBits.len); 4050 if (retval < 0) 4051 return retval; 4052 4053 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4054 ut_params->op); 4055 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4056 4057 ut_params->obuf = ut_params->op->sym->m_dst; 4058 if (ut_params->obuf) 4059 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4060 plaintext_pad_len, buffer); 4061 else 4062 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 4063 tdata->validCipherOffsetInBits.len >> 3, 4064 plaintext_pad_len, buffer); 4065 4066 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 4067 (tdata->validCipherOffsetInBits.len >> 3); 4068 /* Validate obuf */ 4069 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4070 ciphertext, 4071 reference_ciphertext, 4072 tdata->validCipherLenInBits.len, 4073 "KASUMI Ciphertext data not as expected"); 4074 return 0; 4075 } 4076 4077 4078 static int 4079 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata) 4080 { 4081 struct crypto_testsuite_params *ts_params = &testsuite_params; 4082 struct crypto_unittest_params *ut_params = &unittest_params; 4083 4084 int retval; 4085 uint8_t *ciphertext, *plaintext; 4086 unsigned ciphertext_pad_len; 4087 unsigned ciphertext_len; 4088 4089 /* Verify the capabilities */ 4090 struct rte_cryptodev_sym_capability_idx cap_idx; 4091 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4092 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4093 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4094 &cap_idx) == NULL) 4095 return TEST_SKIPPED; 4096 4097 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4098 return TEST_SKIPPED; 4099 4100 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4101 return TEST_SKIPPED; 4102 4103 /* Create KASUMI session */ 4104 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4105 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4106 RTE_CRYPTO_CIPHER_KASUMI_F8, 4107 tdata->key.data, tdata->key.len, 4108 tdata->cipher_iv.len); 4109 if (retval < 0) 4110 return retval; 4111 4112 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4113 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4114 4115 /* Clear mbuf payload */ 4116 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4117 rte_pktmbuf_tailroom(ut_params->ibuf)); 4118 4119 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4120 /* Append data which is padded to a multiple */ 4121 /* of the algorithms block size */ 4122 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4123 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4124 ciphertext_pad_len); 4125 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4126 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4127 4128 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4129 4130 /* Create KASUMI operation */ 4131 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4132 tdata->cipher_iv.len, 4133 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4134 tdata->validCipherOffsetInBits.len); 4135 if (retval < 0) 4136 return retval; 4137 4138 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4139 ut_params->op); 4140 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4141 4142 ut_params->obuf = ut_params->op->sym->m_dst; 4143 if (ut_params->obuf) 4144 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4145 else 4146 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4147 4148 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4149 4150 const uint8_t *reference_plaintext = tdata->plaintext.data + 4151 (tdata->validCipherOffsetInBits.len >> 3); 4152 /* Validate obuf */ 4153 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4154 plaintext, 4155 reference_plaintext, 4156 tdata->validCipherLenInBits.len, 4157 "KASUMI Plaintext data not as expected"); 4158 return 0; 4159 } 4160 4161 static int 4162 test_kasumi_decryption(const struct kasumi_test_data *tdata) 4163 { 4164 struct crypto_testsuite_params *ts_params = &testsuite_params; 4165 struct crypto_unittest_params *ut_params = &unittest_params; 4166 4167 int retval; 4168 uint8_t *ciphertext, *plaintext; 4169 unsigned ciphertext_pad_len; 4170 unsigned ciphertext_len; 4171 struct rte_cryptodev_info dev_info; 4172 4173 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4174 uint64_t feat_flags = dev_info.feature_flags; 4175 4176 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4177 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4178 printf("Device doesn't support RAW data-path APIs.\n"); 4179 return TEST_SKIPPED; 4180 } 4181 4182 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4183 return TEST_SKIPPED; 4184 4185 /* Verify the capabilities */ 4186 struct rte_cryptodev_sym_capability_idx cap_idx; 4187 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4188 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4189 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4190 &cap_idx) == NULL) 4191 return TEST_SKIPPED; 4192 4193 /* Create KASUMI session */ 4194 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4195 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4196 RTE_CRYPTO_CIPHER_KASUMI_F8, 4197 tdata->key.data, tdata->key.len, 4198 tdata->cipher_iv.len); 4199 if (retval < 0) 4200 return retval; 4201 4202 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4203 4204 /* Clear mbuf payload */ 4205 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4206 rte_pktmbuf_tailroom(ut_params->ibuf)); 4207 4208 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4209 /* Append data which is padded to a multiple */ 4210 /* of the algorithms block size */ 4211 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 4212 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4213 ciphertext_pad_len); 4214 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4215 4216 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4217 4218 /* Create KASUMI operation */ 4219 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4220 tdata->cipher_iv.len, 4221 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 4222 tdata->validCipherOffsetInBits.len); 4223 if (retval < 0) 4224 return retval; 4225 4226 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4227 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4228 0); 4229 if (retval != TEST_SUCCESS) 4230 return retval; 4231 } else 4232 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4233 ut_params->op); 4234 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4235 4236 ut_params->obuf = ut_params->op->sym->m_dst; 4237 if (ut_params->obuf) 4238 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4239 else 4240 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 4241 4242 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4243 4244 const uint8_t *reference_plaintext = tdata->plaintext.data + 4245 (tdata->validCipherOffsetInBits.len >> 3); 4246 /* Validate obuf */ 4247 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4248 plaintext, 4249 reference_plaintext, 4250 tdata->validCipherLenInBits.len, 4251 "KASUMI Plaintext data not as expected"); 4252 return 0; 4253 } 4254 4255 static int 4256 test_snow3g_encryption(const struct snow3g_test_data *tdata) 4257 { 4258 struct crypto_testsuite_params *ts_params = &testsuite_params; 4259 struct crypto_unittest_params *ut_params = &unittest_params; 4260 4261 int retval; 4262 uint8_t *plaintext, *ciphertext; 4263 unsigned plaintext_pad_len; 4264 unsigned plaintext_len; 4265 struct rte_cryptodev_info dev_info; 4266 4267 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4268 uint64_t feat_flags = dev_info.feature_flags; 4269 4270 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4271 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4272 printf("Device doesn't support RAW data-path APIs.\n"); 4273 return TEST_SKIPPED; 4274 } 4275 4276 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4277 return TEST_SKIPPED; 4278 4279 /* Verify the capabilities */ 4280 struct rte_cryptodev_sym_capability_idx cap_idx; 4281 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4282 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4283 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4284 &cap_idx) == NULL) 4285 return TEST_SKIPPED; 4286 4287 /* Create SNOW 3G session */ 4288 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4289 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4290 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4291 tdata->key.data, tdata->key.len, 4292 tdata->cipher_iv.len); 4293 if (retval < 0) 4294 return retval; 4295 4296 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4297 4298 /* Clear mbuf payload */ 4299 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4300 rte_pktmbuf_tailroom(ut_params->ibuf)); 4301 4302 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4303 /* Append data which is padded to a multiple of */ 4304 /* the algorithms block size */ 4305 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4306 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4307 plaintext_pad_len); 4308 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4309 4310 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4311 4312 /* Create SNOW 3G operation */ 4313 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4314 tdata->cipher_iv.len, 4315 tdata->validCipherLenInBits.len, 4316 0); 4317 if (retval < 0) 4318 return retval; 4319 4320 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4321 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4322 tdata->cipher_iv.len); 4323 if (retval != TEST_SUCCESS) 4324 return retval; 4325 } else 4326 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4327 ut_params->op); 4328 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4329 4330 ut_params->obuf = ut_params->op->sym->m_dst; 4331 if (ut_params->obuf) 4332 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4333 else 4334 ciphertext = plaintext; 4335 4336 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4337 4338 /* Validate obuf */ 4339 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4340 ciphertext, 4341 tdata->ciphertext.data, 4342 tdata->validDataLenInBits.len, 4343 "SNOW 3G Ciphertext data not as expected"); 4344 return 0; 4345 } 4346 4347 4348 static int 4349 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) 4350 { 4351 struct crypto_testsuite_params *ts_params = &testsuite_params; 4352 struct crypto_unittest_params *ut_params = &unittest_params; 4353 uint8_t *plaintext, *ciphertext; 4354 4355 int retval; 4356 unsigned plaintext_pad_len; 4357 unsigned plaintext_len; 4358 struct rte_cryptodev_info dev_info; 4359 4360 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4361 uint64_t feat_flags = dev_info.feature_flags; 4362 4363 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4364 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4365 printf("Device does not support RAW data-path APIs.\n"); 4366 return -ENOTSUP; 4367 } 4368 4369 /* Verify the capabilities */ 4370 struct rte_cryptodev_sym_capability_idx cap_idx; 4371 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4372 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4373 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4374 &cap_idx) == NULL) 4375 return TEST_SKIPPED; 4376 4377 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4378 return TEST_SKIPPED; 4379 4380 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4381 return TEST_SKIPPED; 4382 4383 /* Create SNOW 3G session */ 4384 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4385 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4386 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4387 tdata->key.data, tdata->key.len, 4388 tdata->cipher_iv.len); 4389 if (retval < 0) 4390 return retval; 4391 4392 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4393 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4394 4395 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4396 "Failed to allocate input buffer in mempool"); 4397 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4398 "Failed to allocate output buffer in mempool"); 4399 4400 /* Clear mbuf payload */ 4401 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4402 rte_pktmbuf_tailroom(ut_params->ibuf)); 4403 4404 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4405 /* Append data which is padded to a multiple of */ 4406 /* the algorithms block size */ 4407 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4408 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4409 plaintext_pad_len); 4410 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4411 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4412 4413 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4414 4415 /* Create SNOW 3G operation */ 4416 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4417 tdata->cipher_iv.len, 4418 tdata->validCipherLenInBits.len, 4419 0); 4420 if (retval < 0) 4421 return retval; 4422 4423 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4424 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4425 tdata->cipher_iv.len); 4426 if (retval != TEST_SUCCESS) 4427 return retval; 4428 } else 4429 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4430 ut_params->op); 4431 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4432 4433 ut_params->obuf = ut_params->op->sym->m_dst; 4434 if (ut_params->obuf) 4435 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4436 else 4437 ciphertext = plaintext; 4438 4439 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4440 4441 /* Validate obuf */ 4442 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4443 ciphertext, 4444 tdata->ciphertext.data, 4445 tdata->validDataLenInBits.len, 4446 "SNOW 3G Ciphertext data not as expected"); 4447 return 0; 4448 } 4449 4450 static int 4451 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata, 4452 uint8_t sgl_in, uint8_t sgl_out) 4453 { 4454 struct crypto_testsuite_params *ts_params = &testsuite_params; 4455 struct crypto_unittest_params *ut_params = &unittest_params; 4456 4457 int retval; 4458 unsigned int plaintext_pad_len; 4459 unsigned int plaintext_len; 4460 uint8_t buffer[10000]; 4461 const uint8_t *ciphertext; 4462 4463 struct rte_cryptodev_info dev_info; 4464 4465 /* Verify the capabilities */ 4466 struct rte_cryptodev_sym_capability_idx cap_idx; 4467 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4468 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4469 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4470 &cap_idx) == NULL) 4471 return TEST_SKIPPED; 4472 4473 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4474 return TEST_SKIPPED; 4475 4476 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4477 return TEST_SKIPPED; 4478 4479 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4480 4481 uint64_t feat_flags = dev_info.feature_flags; 4482 4483 if (((sgl_in && sgl_out) && !(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 4484 || ((!sgl_in && sgl_out) && 4485 !(feat_flags & RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 4486 || ((sgl_in && !sgl_out) && 4487 !(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))) { 4488 printf("Device doesn't support out-of-place scatter gather type. " 4489 "Test Skipped.\n"); 4490 return TEST_SKIPPED; 4491 } 4492 4493 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4494 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4495 printf("Device does not support RAW data-path APIs.\n"); 4496 return -ENOTSUP; 4497 } 4498 4499 /* Create SNOW 3G session */ 4500 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4501 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4502 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4503 tdata->key.data, tdata->key.len, 4504 tdata->cipher_iv.len); 4505 if (retval < 0) 4506 return retval; 4507 4508 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4509 /* Append data which is padded to a multiple of */ 4510 /* the algorithms block size */ 4511 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4512 4513 if (sgl_in) 4514 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4515 plaintext_pad_len, 10, 0); 4516 else { 4517 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4518 rte_pktmbuf_append(ut_params->ibuf, plaintext_pad_len); 4519 } 4520 4521 if (sgl_out) 4522 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4523 plaintext_pad_len, 3, 0); 4524 else { 4525 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4526 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4527 } 4528 4529 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4530 "Failed to allocate input buffer in mempool"); 4531 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4532 "Failed to allocate output buffer in mempool"); 4533 4534 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 4535 4536 /* Create SNOW 3G operation */ 4537 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4538 tdata->cipher_iv.len, 4539 tdata->validCipherLenInBits.len, 4540 0); 4541 if (retval < 0) 4542 return retval; 4543 4544 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4545 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4546 tdata->cipher_iv.len); 4547 if (retval != TEST_SUCCESS) 4548 return retval; 4549 } else 4550 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4551 ut_params->op); 4552 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4553 4554 ut_params->obuf = ut_params->op->sym->m_dst; 4555 if (ut_params->obuf) 4556 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4557 plaintext_len, buffer); 4558 else 4559 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4560 plaintext_len, buffer); 4561 4562 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4563 4564 /* Validate obuf */ 4565 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4566 ciphertext, 4567 tdata->ciphertext.data, 4568 tdata->validDataLenInBits.len, 4569 "SNOW 3G Ciphertext data not as expected"); 4570 4571 return 0; 4572 } 4573 4574 /* Shift right a buffer by "offset" bits, "offset" < 8 */ 4575 static void 4576 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) 4577 { 4578 uint8_t curr_byte, prev_byte; 4579 uint32_t length_in_bytes = ceil_byte_length(length + offset); 4580 uint8_t lower_byte_mask = (1 << offset) - 1; 4581 unsigned i; 4582 4583 prev_byte = buffer[0]; 4584 buffer[0] >>= offset; 4585 4586 for (i = 1; i < length_in_bytes; i++) { 4587 curr_byte = buffer[i]; 4588 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | 4589 (curr_byte >> offset); 4590 prev_byte = curr_byte; 4591 } 4592 } 4593 4594 static int 4595 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) 4596 { 4597 struct crypto_testsuite_params *ts_params = &testsuite_params; 4598 struct crypto_unittest_params *ut_params = &unittest_params; 4599 uint8_t *plaintext, *ciphertext; 4600 int retval; 4601 uint32_t plaintext_len; 4602 uint32_t plaintext_pad_len; 4603 uint8_t extra_offset = 4; 4604 uint8_t *expected_ciphertext_shifted; 4605 struct rte_cryptodev_info dev_info; 4606 4607 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4608 uint64_t feat_flags = dev_info.feature_flags; 4609 4610 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4611 ((tdata->validDataLenInBits.len % 8) != 0)) { 4612 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4613 return TEST_SKIPPED; 4614 } 4615 4616 /* Verify the capabilities */ 4617 struct rte_cryptodev_sym_capability_idx cap_idx; 4618 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4619 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4620 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4621 &cap_idx) == NULL) 4622 return TEST_SKIPPED; 4623 4624 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4625 return TEST_SKIPPED; 4626 4627 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4628 return TEST_SKIPPED; 4629 4630 /* Create SNOW 3G session */ 4631 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4632 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4633 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4634 tdata->key.data, tdata->key.len, 4635 tdata->cipher_iv.len); 4636 if (retval < 0) 4637 return retval; 4638 4639 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4640 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4641 4642 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4643 "Failed to allocate input buffer in mempool"); 4644 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4645 "Failed to allocate output buffer in mempool"); 4646 4647 /* Clear mbuf payload */ 4648 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4649 rte_pktmbuf_tailroom(ut_params->ibuf)); 4650 4651 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset); 4652 /* 4653 * Append data which is padded to a 4654 * multiple of the algorithms block size 4655 */ 4656 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4657 4658 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, 4659 plaintext_pad_len); 4660 4661 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4662 4663 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); 4664 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); 4665 4666 #ifdef RTE_APP_TEST_DEBUG 4667 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); 4668 #endif 4669 /* Create SNOW 3G operation */ 4670 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4671 tdata->cipher_iv.len, 4672 tdata->validCipherLenInBits.len, 4673 extra_offset); 4674 if (retval < 0) 4675 return retval; 4676 4677 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4678 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4679 tdata->cipher_iv.len); 4680 if (retval != TEST_SUCCESS) 4681 return retval; 4682 } else 4683 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4684 ut_params->op); 4685 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4686 4687 ut_params->obuf = ut_params->op->sym->m_dst; 4688 if (ut_params->obuf) 4689 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4690 else 4691 ciphertext = plaintext; 4692 4693 #ifdef RTE_APP_TEST_DEBUG 4694 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4695 #endif 4696 4697 expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8); 4698 4699 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, 4700 "failed to reserve memory for ciphertext shifted\n"); 4701 4702 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, 4703 ceil_byte_length(tdata->ciphertext.len)); 4704 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, 4705 extra_offset); 4706 /* Validate obuf */ 4707 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4708 ciphertext, 4709 expected_ciphertext_shifted, 4710 tdata->validDataLenInBits.len, 4711 extra_offset, 4712 "SNOW 3G Ciphertext data not as expected"); 4713 return 0; 4714 } 4715 4716 static int test_snow3g_decryption(const struct snow3g_test_data *tdata) 4717 { 4718 struct crypto_testsuite_params *ts_params = &testsuite_params; 4719 struct crypto_unittest_params *ut_params = &unittest_params; 4720 4721 int retval; 4722 4723 uint8_t *plaintext, *ciphertext; 4724 unsigned ciphertext_pad_len; 4725 unsigned ciphertext_len; 4726 struct rte_cryptodev_info dev_info; 4727 4728 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4729 uint64_t feat_flags = dev_info.feature_flags; 4730 4731 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4732 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4733 printf("Device doesn't support RAW data-path APIs.\n"); 4734 return TEST_SKIPPED; 4735 } 4736 4737 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4738 return TEST_SKIPPED; 4739 4740 /* Verify the capabilities */ 4741 struct rte_cryptodev_sym_capability_idx cap_idx; 4742 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4743 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4744 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4745 &cap_idx) == NULL) 4746 return TEST_SKIPPED; 4747 4748 /* Create SNOW 3G session */ 4749 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4750 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4751 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4752 tdata->key.data, tdata->key.len, 4753 tdata->cipher_iv.len); 4754 if (retval < 0) 4755 return retval; 4756 4757 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4758 4759 /* Clear mbuf payload */ 4760 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4761 rte_pktmbuf_tailroom(ut_params->ibuf)); 4762 4763 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4764 /* Append data which is padded to a multiple of */ 4765 /* the algorithms block size */ 4766 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4767 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4768 ciphertext_pad_len); 4769 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4770 4771 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4772 4773 /* Create SNOW 3G operation */ 4774 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4775 tdata->cipher_iv.len, 4776 tdata->validCipherLenInBits.len, 4777 tdata->cipher.offset_bits); 4778 if (retval < 0) 4779 return retval; 4780 4781 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4782 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4783 tdata->cipher_iv.len); 4784 if (retval != TEST_SUCCESS) 4785 return retval; 4786 } else 4787 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4788 ut_params->op); 4789 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4790 ut_params->obuf = ut_params->op->sym->m_dst; 4791 if (ut_params->obuf) 4792 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4793 else 4794 plaintext = ciphertext; 4795 4796 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4797 4798 /* Validate obuf */ 4799 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4800 tdata->plaintext.data, 4801 tdata->validDataLenInBits.len, 4802 "SNOW 3G Plaintext data not as expected"); 4803 return 0; 4804 } 4805 4806 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) 4807 { 4808 struct crypto_testsuite_params *ts_params = &testsuite_params; 4809 struct crypto_unittest_params *ut_params = &unittest_params; 4810 4811 int retval; 4812 4813 uint8_t *plaintext, *ciphertext; 4814 unsigned ciphertext_pad_len; 4815 unsigned ciphertext_len; 4816 struct rte_cryptodev_info dev_info; 4817 4818 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4819 uint64_t feat_flags = dev_info.feature_flags; 4820 4821 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4822 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4823 printf("Device does not support RAW data-path APIs.\n"); 4824 return -ENOTSUP; 4825 } 4826 /* Verify the capabilities */ 4827 struct rte_cryptodev_sym_capability_idx cap_idx; 4828 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4829 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4830 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4831 &cap_idx) == NULL) 4832 return TEST_SKIPPED; 4833 4834 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4835 return TEST_SKIPPED; 4836 4837 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4838 return TEST_SKIPPED; 4839 4840 /* Create SNOW 3G session */ 4841 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4842 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4843 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4844 tdata->key.data, tdata->key.len, 4845 tdata->cipher_iv.len); 4846 if (retval < 0) 4847 return retval; 4848 4849 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4850 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4851 4852 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4853 "Failed to allocate input buffer"); 4854 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4855 "Failed to allocate output buffer"); 4856 4857 /* Clear mbuf payload */ 4858 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4859 rte_pktmbuf_tailroom(ut_params->ibuf)); 4860 4861 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4862 rte_pktmbuf_tailroom(ut_params->obuf)); 4863 4864 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4865 /* Append data which is padded to a multiple of */ 4866 /* the algorithms block size */ 4867 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4868 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4869 ciphertext_pad_len); 4870 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4871 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4872 4873 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4874 4875 /* Create SNOW 3G operation */ 4876 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4877 tdata->cipher_iv.len, 4878 tdata->validCipherLenInBits.len, 4879 0); 4880 if (retval < 0) 4881 return retval; 4882 4883 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4884 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 4885 tdata->cipher_iv.len); 4886 if (retval != TEST_SUCCESS) 4887 return retval; 4888 } else 4889 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4890 ut_params->op); 4891 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4892 ut_params->obuf = ut_params->op->sym->m_dst; 4893 if (ut_params->obuf) 4894 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4895 else 4896 plaintext = ciphertext; 4897 4898 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4899 4900 /* Validate obuf */ 4901 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4902 tdata->plaintext.data, 4903 tdata->validDataLenInBits.len, 4904 "SNOW 3G Plaintext data not as expected"); 4905 return 0; 4906 } 4907 4908 static int 4909 test_zuc_cipher_auth(const struct wireless_test_data *tdata) 4910 { 4911 struct crypto_testsuite_params *ts_params = &testsuite_params; 4912 struct crypto_unittest_params *ut_params = &unittest_params; 4913 4914 int retval; 4915 4916 uint8_t *plaintext, *ciphertext; 4917 unsigned int plaintext_pad_len; 4918 unsigned int plaintext_len; 4919 4920 struct rte_cryptodev_info dev_info; 4921 4922 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4923 uint64_t feat_flags = dev_info.feature_flags; 4924 4925 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4926 ((tdata->validAuthLenInBits.len % 8 != 0) || 4927 (tdata->validDataLenInBits.len % 8 != 0))) { 4928 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4929 return TEST_SKIPPED; 4930 } 4931 4932 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4933 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4934 printf("Device doesn't support RAW data-path APIs.\n"); 4935 return TEST_SKIPPED; 4936 } 4937 4938 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4939 return TEST_SKIPPED; 4940 4941 /* Check if device supports ZUC EEA3 */ 4942 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 4943 tdata->key.len, tdata->cipher_iv.len) < 0) 4944 return TEST_SKIPPED; 4945 4946 /* Check if device supports ZUC EIA3 */ 4947 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 4948 tdata->key.len, tdata->auth_iv.len, 4949 tdata->digest.len) < 0) 4950 return TEST_SKIPPED; 4951 4952 /* Create ZUC session */ 4953 retval = create_zuc_cipher_auth_encrypt_generate_session( 4954 ts_params->valid_devs[0], 4955 tdata); 4956 if (retval != 0) 4957 return retval; 4958 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4959 4960 /* clear mbuf payload */ 4961 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4962 rte_pktmbuf_tailroom(ut_params->ibuf)); 4963 4964 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4965 /* Append data which is padded to a multiple of */ 4966 /* the algorithms block size */ 4967 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4968 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4969 plaintext_pad_len); 4970 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4971 4972 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4973 4974 /* Create ZUC operation */ 4975 retval = create_zuc_cipher_hash_generate_operation(tdata); 4976 if (retval < 0) 4977 return retval; 4978 4979 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 4980 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 4981 tdata->cipher_iv.len); 4982 if (retval != TEST_SUCCESS) 4983 return retval; 4984 } else 4985 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4986 ut_params->op); 4987 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4988 ut_params->obuf = ut_params->op->sym->m_src; 4989 if (ut_params->obuf) 4990 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4991 else 4992 ciphertext = plaintext; 4993 4994 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4995 /* Validate obuf */ 4996 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4997 ciphertext, 4998 tdata->ciphertext.data, 4999 tdata->validDataLenInBits.len, 5000 "ZUC Ciphertext data not as expected"); 5001 5002 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 5003 uint8_t *, 5004 plaintext_pad_len); 5005 5006 /* Validate obuf */ 5007 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5008 ut_params->digest, 5009 tdata->digest.data, 5010 tdata->digest.len, 5011 "ZUC Generated auth tag not as expected"); 5012 return 0; 5013 } 5014 5015 static int 5016 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) 5017 { 5018 struct crypto_testsuite_params *ts_params = &testsuite_params; 5019 struct crypto_unittest_params *ut_params = &unittest_params; 5020 5021 int retval; 5022 5023 uint8_t *plaintext, *ciphertext; 5024 unsigned plaintext_pad_len; 5025 unsigned plaintext_len; 5026 struct rte_cryptodev_info dev_info; 5027 5028 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5029 uint64_t feat_flags = dev_info.feature_flags; 5030 5031 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5032 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5033 printf("Device doesn't support RAW data-path APIs.\n"); 5034 return TEST_SKIPPED; 5035 } 5036 5037 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5038 return TEST_SKIPPED; 5039 5040 /* Verify the capabilities */ 5041 struct rte_cryptodev_sym_capability_idx cap_idx; 5042 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5043 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5044 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5045 &cap_idx) == NULL) 5046 return TEST_SKIPPED; 5047 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5048 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5049 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5050 &cap_idx) == NULL) 5051 return TEST_SKIPPED; 5052 5053 /* Create SNOW 3G session */ 5054 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0], 5055 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5056 RTE_CRYPTO_AUTH_OP_GENERATE, 5057 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5058 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5059 tdata->key.data, tdata->key.len, 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 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5066 5067 /* clear mbuf payload */ 5068 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5069 rte_pktmbuf_tailroom(ut_params->ibuf)); 5070 5071 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5072 /* Append data which is padded to a multiple of */ 5073 /* the algorithms block size */ 5074 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5075 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5076 plaintext_pad_len); 5077 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5078 5079 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5080 5081 /* Create SNOW 3G operation */ 5082 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 5083 tdata->digest.len, tdata->auth_iv.data, 5084 tdata->auth_iv.len, 5085 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5086 tdata->cipher_iv.data, tdata->cipher_iv.len, 5087 tdata->validCipherLenInBits.len, 5088 0, 5089 tdata->validAuthLenInBits.len, 5090 0 5091 ); 5092 if (retval < 0) 5093 return retval; 5094 5095 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5096 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5097 tdata->cipher_iv.len); 5098 if (retval != TEST_SUCCESS) 5099 return retval; 5100 } else 5101 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5102 ut_params->op); 5103 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5104 ut_params->obuf = ut_params->op->sym->m_src; 5105 if (ut_params->obuf) 5106 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 5107 else 5108 ciphertext = plaintext; 5109 5110 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 5111 /* Validate obuf */ 5112 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5113 ciphertext, 5114 tdata->ciphertext.data, 5115 tdata->validDataLenInBits.len, 5116 "SNOW 3G Ciphertext data not as expected"); 5117 5118 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 5119 uint8_t *, 5120 plaintext_pad_len); 5121 5122 /* Validate obuf */ 5123 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5124 ut_params->digest, 5125 tdata->digest.data, 5126 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5127 "SNOW 3G Generated auth tag not as expected"); 5128 return 0; 5129 } 5130 5131 static int 5132 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata, 5133 uint8_t op_mode, uint8_t verify) 5134 { 5135 struct crypto_testsuite_params *ts_params = &testsuite_params; 5136 struct crypto_unittest_params *ut_params = &unittest_params; 5137 5138 int retval; 5139 5140 uint8_t *plaintext = NULL, *ciphertext = NULL; 5141 unsigned int plaintext_pad_len; 5142 unsigned int plaintext_len; 5143 unsigned int ciphertext_pad_len; 5144 unsigned int ciphertext_len; 5145 unsigned int digest_offset; 5146 5147 struct rte_cryptodev_info dev_info; 5148 5149 /* Verify the capabilities */ 5150 struct rte_cryptodev_sym_capability_idx cap_idx; 5151 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5152 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5153 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5154 &cap_idx) == NULL) 5155 return TEST_SKIPPED; 5156 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5157 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5158 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5159 &cap_idx) == NULL) 5160 return TEST_SKIPPED; 5161 5162 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5163 return TEST_SKIPPED; 5164 5165 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5166 5167 uint64_t feat_flags = dev_info.feature_flags; 5168 5169 if (op_mode == OUT_OF_PLACE) { 5170 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5171 printf("Device doesn't support digest encrypted.\n"); 5172 return TEST_SKIPPED; 5173 } 5174 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5175 return TEST_SKIPPED; 5176 } 5177 5178 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5179 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5180 printf("Device doesn't support RAW data-path APIs.\n"); 5181 return TEST_SKIPPED; 5182 } 5183 5184 /* Create SNOW 3G session */ 5185 retval = create_wireless_algo_auth_cipher_session( 5186 ts_params->valid_devs[0], 5187 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5188 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5189 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5190 : RTE_CRYPTO_AUTH_OP_GENERATE), 5191 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5192 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5193 tdata->key.data, tdata->key.len, 5194 tdata->key.data, tdata->key.len, 5195 tdata->auth_iv.len, tdata->digest.len, 5196 tdata->cipher_iv.len); 5197 if (retval != 0) 5198 return retval; 5199 5200 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5201 if (op_mode == OUT_OF_PLACE) 5202 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5203 5204 /* clear mbuf payload */ 5205 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5206 rte_pktmbuf_tailroom(ut_params->ibuf)); 5207 if (op_mode == OUT_OF_PLACE) 5208 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5209 rte_pktmbuf_tailroom(ut_params->obuf)); 5210 5211 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5212 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5213 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5214 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5215 5216 if (verify) { 5217 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5218 ciphertext_pad_len); 5219 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5220 if (op_mode == OUT_OF_PLACE) 5221 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5222 debug_hexdump(stdout, "ciphertext:", ciphertext, 5223 ciphertext_len); 5224 } else { 5225 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5226 plaintext_pad_len); 5227 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5228 if (op_mode == OUT_OF_PLACE) 5229 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5230 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5231 } 5232 5233 /* Create SNOW 3G operation */ 5234 retval = create_wireless_algo_auth_cipher_operation( 5235 tdata->digest.data, tdata->digest.len, 5236 tdata->cipher_iv.data, tdata->cipher_iv.len, 5237 tdata->auth_iv.data, tdata->auth_iv.len, 5238 (tdata->digest.offset_bytes == 0 ? 5239 (verify ? ciphertext_pad_len : plaintext_pad_len) 5240 : tdata->digest.offset_bytes), 5241 tdata->validCipherLenInBits.len, 5242 tdata->cipher.offset_bits, 5243 tdata->validAuthLenInBits.len, 5244 tdata->auth.offset_bits, 5245 op_mode, 0, verify); 5246 5247 if (retval < 0) 5248 return retval; 5249 5250 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5251 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5252 tdata->cipher_iv.len); 5253 if (retval != TEST_SUCCESS) 5254 return retval; 5255 } else 5256 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5257 ut_params->op); 5258 5259 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5260 5261 ut_params->obuf = (op_mode == IN_PLACE ? 5262 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5263 5264 if (verify) { 5265 if (ut_params->obuf) 5266 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5267 uint8_t *); 5268 else 5269 plaintext = ciphertext + 5270 (tdata->cipher.offset_bits >> 3); 5271 5272 debug_hexdump(stdout, "plaintext:", plaintext, 5273 (tdata->plaintext.len >> 3) - tdata->digest.len); 5274 debug_hexdump(stdout, "plaintext expected:", 5275 tdata->plaintext.data, 5276 (tdata->plaintext.len >> 3) - tdata->digest.len); 5277 } else { 5278 if (ut_params->obuf) 5279 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5280 uint8_t *); 5281 else 5282 ciphertext = plaintext; 5283 5284 debug_hexdump(stdout, "ciphertext:", ciphertext, 5285 ciphertext_len); 5286 debug_hexdump(stdout, "ciphertext expected:", 5287 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5288 5289 if (tdata->digest.offset_bytes == 0) 5290 digest_offset = plaintext_pad_len; 5291 else 5292 digest_offset = tdata->digest.offset_bytes; 5293 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 5294 uint8_t *, digest_offset); 5295 5296 debug_hexdump(stdout, "digest:", ut_params->digest, 5297 tdata->digest.len); 5298 debug_hexdump(stdout, "digest expected:", tdata->digest.data, 5299 tdata->digest.len); 5300 } 5301 5302 /* Validate obuf */ 5303 if (verify) { 5304 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5305 plaintext, 5306 tdata->plaintext.data, 5307 (tdata->plaintext.len - tdata->cipher.offset_bits - 5308 (tdata->digest.len << 3)), 5309 tdata->cipher.offset_bits, 5310 "SNOW 3G Plaintext data not as expected"); 5311 } else { 5312 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5313 ciphertext, 5314 tdata->ciphertext.data, 5315 (tdata->validDataLenInBits.len - 5316 tdata->cipher.offset_bits), 5317 tdata->cipher.offset_bits, 5318 "SNOW 3G Ciphertext data not as expected"); 5319 5320 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5321 ut_params->digest, 5322 tdata->digest.data, 5323 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5324 "SNOW 3G Generated auth tag not as expected"); 5325 } 5326 return 0; 5327 } 5328 5329 static int 5330 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata, 5331 uint8_t op_mode, uint8_t verify) 5332 { 5333 struct crypto_testsuite_params *ts_params = &testsuite_params; 5334 struct crypto_unittest_params *ut_params = &unittest_params; 5335 5336 int retval; 5337 5338 const uint8_t *plaintext = NULL; 5339 const uint8_t *ciphertext = NULL; 5340 const uint8_t *digest = NULL; 5341 unsigned int plaintext_pad_len; 5342 unsigned int plaintext_len; 5343 unsigned int ciphertext_pad_len; 5344 unsigned int ciphertext_len; 5345 uint8_t buffer[10000]; 5346 uint8_t digest_buffer[10000]; 5347 5348 struct rte_cryptodev_info dev_info; 5349 5350 /* Verify the capabilities */ 5351 struct rte_cryptodev_sym_capability_idx cap_idx; 5352 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5353 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 5354 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5355 &cap_idx) == NULL) 5356 return TEST_SKIPPED; 5357 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5358 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 5359 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5360 &cap_idx) == NULL) 5361 return TEST_SKIPPED; 5362 5363 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5364 return TEST_SKIPPED; 5365 5366 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5367 5368 uint64_t feat_flags = dev_info.feature_flags; 5369 5370 if (op_mode == IN_PLACE) { 5371 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5372 printf("Device doesn't support in-place scatter-gather " 5373 "in both input and output mbufs.\n"); 5374 return TEST_SKIPPED; 5375 } 5376 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5377 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5378 printf("Device doesn't support RAW data-path APIs.\n"); 5379 return TEST_SKIPPED; 5380 } 5381 } else { 5382 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5383 return TEST_SKIPPED; 5384 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5385 printf("Device doesn't support out-of-place scatter-gather " 5386 "in both input and output mbufs.\n"); 5387 return TEST_SKIPPED; 5388 } 5389 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5390 printf("Device doesn't support digest encrypted.\n"); 5391 return TEST_SKIPPED; 5392 } 5393 } 5394 5395 /* Create SNOW 3G session */ 5396 retval = create_wireless_algo_auth_cipher_session( 5397 ts_params->valid_devs[0], 5398 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5399 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5400 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5401 : RTE_CRYPTO_AUTH_OP_GENERATE), 5402 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 5403 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 5404 tdata->key.data, tdata->key.len, 5405 tdata->key.data, tdata->key.len, 5406 tdata->auth_iv.len, tdata->digest.len, 5407 tdata->cipher_iv.len); 5408 5409 if (retval != 0) 5410 return retval; 5411 5412 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5413 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5414 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5415 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5416 5417 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5418 plaintext_pad_len, 15, 0); 5419 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5420 "Failed to allocate input buffer in mempool"); 5421 5422 if (op_mode == OUT_OF_PLACE) { 5423 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5424 plaintext_pad_len, 15, 0); 5425 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5426 "Failed to allocate output buffer in mempool"); 5427 } 5428 5429 if (verify) { 5430 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5431 tdata->ciphertext.data); 5432 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5433 ciphertext_len, buffer); 5434 debug_hexdump(stdout, "ciphertext:", ciphertext, 5435 ciphertext_len); 5436 } else { 5437 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5438 tdata->plaintext.data); 5439 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5440 plaintext_len, buffer); 5441 debug_hexdump(stdout, "plaintext:", plaintext, 5442 plaintext_len); 5443 } 5444 memset(buffer, 0, sizeof(buffer)); 5445 5446 /* Create SNOW 3G operation */ 5447 retval = create_wireless_algo_auth_cipher_operation( 5448 tdata->digest.data, tdata->digest.len, 5449 tdata->cipher_iv.data, tdata->cipher_iv.len, 5450 tdata->auth_iv.data, tdata->auth_iv.len, 5451 (tdata->digest.offset_bytes == 0 ? 5452 (verify ? ciphertext_pad_len : plaintext_pad_len) 5453 : tdata->digest.offset_bytes), 5454 tdata->validCipherLenInBits.len, 5455 tdata->cipher.offset_bits, 5456 tdata->validAuthLenInBits.len, 5457 tdata->auth.offset_bits, 5458 op_mode, 1, verify); 5459 5460 if (retval < 0) 5461 return retval; 5462 5463 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5464 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5465 tdata->cipher_iv.len); 5466 if (retval != TEST_SUCCESS) 5467 return retval; 5468 } else 5469 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5470 ut_params->op); 5471 5472 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5473 5474 ut_params->obuf = (op_mode == IN_PLACE ? 5475 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5476 5477 if (verify) { 5478 if (ut_params->obuf) 5479 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5480 plaintext_len, buffer); 5481 else 5482 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5483 plaintext_len, buffer); 5484 5485 debug_hexdump(stdout, "plaintext:", plaintext, 5486 (tdata->plaintext.len >> 3) - tdata->digest.len); 5487 debug_hexdump(stdout, "plaintext expected:", 5488 tdata->plaintext.data, 5489 (tdata->plaintext.len >> 3) - tdata->digest.len); 5490 } else { 5491 if (ut_params->obuf) 5492 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5493 ciphertext_len, buffer); 5494 else 5495 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5496 ciphertext_len, buffer); 5497 5498 debug_hexdump(stdout, "ciphertext:", ciphertext, 5499 ciphertext_len); 5500 debug_hexdump(stdout, "ciphertext expected:", 5501 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5502 5503 if (ut_params->obuf) 5504 digest = rte_pktmbuf_read(ut_params->obuf, 5505 (tdata->digest.offset_bytes == 0 ? 5506 plaintext_pad_len : tdata->digest.offset_bytes), 5507 tdata->digest.len, digest_buffer); 5508 else 5509 digest = rte_pktmbuf_read(ut_params->ibuf, 5510 (tdata->digest.offset_bytes == 0 ? 5511 plaintext_pad_len : tdata->digest.offset_bytes), 5512 tdata->digest.len, digest_buffer); 5513 5514 debug_hexdump(stdout, "digest:", digest, 5515 tdata->digest.len); 5516 debug_hexdump(stdout, "digest expected:", 5517 tdata->digest.data, tdata->digest.len); 5518 } 5519 5520 /* Validate obuf */ 5521 if (verify) { 5522 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5523 plaintext, 5524 tdata->plaintext.data, 5525 (tdata->plaintext.len - tdata->cipher.offset_bits - 5526 (tdata->digest.len << 3)), 5527 tdata->cipher.offset_bits, 5528 "SNOW 3G Plaintext data not as expected"); 5529 } else { 5530 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 5531 ciphertext, 5532 tdata->ciphertext.data, 5533 (tdata->validDataLenInBits.len - 5534 tdata->cipher.offset_bits), 5535 tdata->cipher.offset_bits, 5536 "SNOW 3G Ciphertext data not as expected"); 5537 5538 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5539 digest, 5540 tdata->digest.data, 5541 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5542 "SNOW 3G Generated auth tag not as expected"); 5543 } 5544 return 0; 5545 } 5546 5547 static int 5548 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata, 5549 uint8_t op_mode, uint8_t verify) 5550 { 5551 struct crypto_testsuite_params *ts_params = &testsuite_params; 5552 struct crypto_unittest_params *ut_params = &unittest_params; 5553 5554 int retval; 5555 5556 uint8_t *plaintext = NULL, *ciphertext = NULL; 5557 unsigned int plaintext_pad_len; 5558 unsigned int plaintext_len; 5559 unsigned int ciphertext_pad_len; 5560 unsigned int ciphertext_len; 5561 unsigned int digest_offset; 5562 5563 struct rte_cryptodev_info dev_info; 5564 5565 /* Verify the capabilities */ 5566 struct rte_cryptodev_sym_capability_idx cap_idx; 5567 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5568 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5569 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5570 &cap_idx) == NULL) 5571 return TEST_SKIPPED; 5572 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5573 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5574 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5575 &cap_idx) == NULL) 5576 return TEST_SKIPPED; 5577 5578 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5579 5580 uint64_t feat_flags = dev_info.feature_flags; 5581 5582 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5583 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5584 printf("Device doesn't support RAW data-path APIs.\n"); 5585 return TEST_SKIPPED; 5586 } 5587 5588 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5589 return TEST_SKIPPED; 5590 5591 if (op_mode == OUT_OF_PLACE) { 5592 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5593 return TEST_SKIPPED; 5594 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5595 printf("Device doesn't support digest encrypted.\n"); 5596 return TEST_SKIPPED; 5597 } 5598 } 5599 5600 /* Create KASUMI session */ 5601 retval = create_wireless_algo_auth_cipher_session( 5602 ts_params->valid_devs[0], 5603 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5604 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5605 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5606 : RTE_CRYPTO_AUTH_OP_GENERATE), 5607 RTE_CRYPTO_AUTH_KASUMI_F9, 5608 RTE_CRYPTO_CIPHER_KASUMI_F8, 5609 tdata->key.data, tdata->key.len, 5610 tdata->key.data, tdata->key.len, 5611 0, tdata->digest.len, 5612 tdata->cipher_iv.len); 5613 5614 if (retval != 0) 5615 return retval; 5616 5617 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5618 if (op_mode == OUT_OF_PLACE) 5619 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5620 5621 /* clear mbuf payload */ 5622 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5623 rte_pktmbuf_tailroom(ut_params->ibuf)); 5624 if (op_mode == OUT_OF_PLACE) 5625 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5626 rte_pktmbuf_tailroom(ut_params->obuf)); 5627 5628 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5629 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5630 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5631 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5632 5633 if (verify) { 5634 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5635 ciphertext_pad_len); 5636 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5637 if (op_mode == OUT_OF_PLACE) 5638 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5639 debug_hexdump(stdout, "ciphertext:", ciphertext, 5640 ciphertext_len); 5641 } else { 5642 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5643 plaintext_pad_len); 5644 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5645 if (op_mode == OUT_OF_PLACE) 5646 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5647 debug_hexdump(stdout, "plaintext:", plaintext, 5648 plaintext_len); 5649 } 5650 5651 /* Create KASUMI operation */ 5652 retval = create_wireless_algo_auth_cipher_operation( 5653 tdata->digest.data, tdata->digest.len, 5654 tdata->cipher_iv.data, tdata->cipher_iv.len, 5655 NULL, 0, 5656 (tdata->digest.offset_bytes == 0 ? 5657 (verify ? ciphertext_pad_len : plaintext_pad_len) 5658 : tdata->digest.offset_bytes), 5659 tdata->validCipherLenInBits.len, 5660 tdata->validCipherOffsetInBits.len, 5661 tdata->validAuthLenInBits.len, 5662 0, 5663 op_mode, 0, verify); 5664 5665 if (retval < 0) 5666 return retval; 5667 5668 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5669 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5670 tdata->cipher_iv.len); 5671 if (retval != TEST_SUCCESS) 5672 return retval; 5673 } else 5674 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5675 ut_params->op); 5676 5677 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5678 5679 ut_params->obuf = (op_mode == IN_PLACE ? 5680 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5681 5682 5683 if (verify) { 5684 if (ut_params->obuf) 5685 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5686 uint8_t *); 5687 else 5688 plaintext = ciphertext; 5689 5690 debug_hexdump(stdout, "plaintext:", plaintext, 5691 (tdata->plaintext.len >> 3) - tdata->digest.len); 5692 debug_hexdump(stdout, "plaintext expected:", 5693 tdata->plaintext.data, 5694 (tdata->plaintext.len >> 3) - tdata->digest.len); 5695 } else { 5696 if (ut_params->obuf) 5697 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5698 uint8_t *); 5699 else 5700 ciphertext = plaintext; 5701 5702 debug_hexdump(stdout, "ciphertext:", ciphertext, 5703 ciphertext_len); 5704 debug_hexdump(stdout, "ciphertext expected:", 5705 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5706 5707 if (tdata->digest.offset_bytes == 0) 5708 digest_offset = plaintext_pad_len; 5709 else 5710 digest_offset = tdata->digest.offset_bytes; 5711 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 5712 uint8_t *, digest_offset); 5713 5714 debug_hexdump(stdout, "digest:", ut_params->digest, 5715 tdata->digest.len); 5716 debug_hexdump(stdout, "digest expected:", 5717 tdata->digest.data, tdata->digest.len); 5718 } 5719 5720 /* Validate obuf */ 5721 if (verify) { 5722 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5723 plaintext, 5724 tdata->plaintext.data, 5725 tdata->plaintext.len >> 3, 5726 "KASUMI Plaintext data not as expected"); 5727 } else { 5728 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5729 ciphertext, 5730 tdata->ciphertext.data, 5731 tdata->ciphertext.len >> 3, 5732 "KASUMI Ciphertext data not as expected"); 5733 5734 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5735 ut_params->digest, 5736 tdata->digest.data, 5737 DIGEST_BYTE_LENGTH_KASUMI_F9, 5738 "KASUMI Generated auth tag not as expected"); 5739 } 5740 return 0; 5741 } 5742 5743 static int 5744 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata, 5745 uint8_t op_mode, uint8_t verify) 5746 { 5747 struct crypto_testsuite_params *ts_params = &testsuite_params; 5748 struct crypto_unittest_params *ut_params = &unittest_params; 5749 5750 int retval; 5751 5752 const uint8_t *plaintext = NULL; 5753 const uint8_t *ciphertext = NULL; 5754 const uint8_t *digest = NULL; 5755 unsigned int plaintext_pad_len; 5756 unsigned int plaintext_len; 5757 unsigned int ciphertext_pad_len; 5758 unsigned int ciphertext_len; 5759 uint8_t buffer[10000]; 5760 uint8_t digest_buffer[10000]; 5761 5762 struct rte_cryptodev_info dev_info; 5763 5764 /* Verify the capabilities */ 5765 struct rte_cryptodev_sym_capability_idx cap_idx; 5766 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5767 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5768 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5769 &cap_idx) == NULL) 5770 return TEST_SKIPPED; 5771 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5772 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5773 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5774 &cap_idx) == NULL) 5775 return TEST_SKIPPED; 5776 5777 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5778 return TEST_SKIPPED; 5779 5780 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5781 5782 uint64_t feat_flags = dev_info.feature_flags; 5783 5784 if (op_mode == IN_PLACE) { 5785 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5786 printf("Device doesn't support in-place scatter-gather " 5787 "in both input and output mbufs.\n"); 5788 return TEST_SKIPPED; 5789 } 5790 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5791 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5792 printf("Device doesn't support RAW data-path APIs.\n"); 5793 return TEST_SKIPPED; 5794 } 5795 } else { 5796 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5797 return TEST_SKIPPED; 5798 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5799 printf("Device doesn't support out-of-place scatter-gather " 5800 "in both input and output mbufs.\n"); 5801 return TEST_SKIPPED; 5802 } 5803 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5804 printf("Device doesn't support digest encrypted.\n"); 5805 return TEST_SKIPPED; 5806 } 5807 } 5808 5809 /* Create KASUMI session */ 5810 retval = create_wireless_algo_auth_cipher_session( 5811 ts_params->valid_devs[0], 5812 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5813 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5814 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5815 : RTE_CRYPTO_AUTH_OP_GENERATE), 5816 RTE_CRYPTO_AUTH_KASUMI_F9, 5817 RTE_CRYPTO_CIPHER_KASUMI_F8, 5818 tdata->key.data, tdata->key.len, 5819 tdata->key.data, tdata->key.len, 5820 0, tdata->digest.len, 5821 tdata->cipher_iv.len); 5822 5823 if (retval != 0) 5824 return retval; 5825 5826 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5827 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5828 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5829 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5830 5831 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5832 plaintext_pad_len, 15, 0); 5833 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5834 "Failed to allocate input buffer in mempool"); 5835 5836 if (op_mode == OUT_OF_PLACE) { 5837 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5838 plaintext_pad_len, 15, 0); 5839 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5840 "Failed to allocate output buffer in mempool"); 5841 } 5842 5843 if (verify) { 5844 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5845 tdata->ciphertext.data); 5846 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5847 ciphertext_len, buffer); 5848 debug_hexdump(stdout, "ciphertext:", ciphertext, 5849 ciphertext_len); 5850 } else { 5851 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5852 tdata->plaintext.data); 5853 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5854 plaintext_len, buffer); 5855 debug_hexdump(stdout, "plaintext:", plaintext, 5856 plaintext_len); 5857 } 5858 memset(buffer, 0, sizeof(buffer)); 5859 5860 /* Create KASUMI operation */ 5861 retval = create_wireless_algo_auth_cipher_operation( 5862 tdata->digest.data, tdata->digest.len, 5863 tdata->cipher_iv.data, tdata->cipher_iv.len, 5864 NULL, 0, 5865 (tdata->digest.offset_bytes == 0 ? 5866 (verify ? ciphertext_pad_len : plaintext_pad_len) 5867 : tdata->digest.offset_bytes), 5868 tdata->validCipherLenInBits.len, 5869 tdata->validCipherOffsetInBits.len, 5870 tdata->validAuthLenInBits.len, 5871 0, 5872 op_mode, 1, verify); 5873 5874 if (retval < 0) 5875 return retval; 5876 5877 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 5878 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 5879 tdata->cipher_iv.len); 5880 if (retval != TEST_SUCCESS) 5881 return retval; 5882 } else 5883 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5884 ut_params->op); 5885 5886 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5887 5888 ut_params->obuf = (op_mode == IN_PLACE ? 5889 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5890 5891 if (verify) { 5892 if (ut_params->obuf) 5893 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5894 plaintext_len, buffer); 5895 else 5896 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5897 plaintext_len, buffer); 5898 5899 debug_hexdump(stdout, "plaintext:", plaintext, 5900 (tdata->plaintext.len >> 3) - tdata->digest.len); 5901 debug_hexdump(stdout, "plaintext expected:", 5902 tdata->plaintext.data, 5903 (tdata->plaintext.len >> 3) - tdata->digest.len); 5904 } else { 5905 if (ut_params->obuf) 5906 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5907 ciphertext_len, buffer); 5908 else 5909 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5910 ciphertext_len, buffer); 5911 5912 debug_hexdump(stdout, "ciphertext:", ciphertext, 5913 ciphertext_len); 5914 debug_hexdump(stdout, "ciphertext expected:", 5915 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5916 5917 if (ut_params->obuf) 5918 digest = rte_pktmbuf_read(ut_params->obuf, 5919 (tdata->digest.offset_bytes == 0 ? 5920 plaintext_pad_len : tdata->digest.offset_bytes), 5921 tdata->digest.len, digest_buffer); 5922 else 5923 digest = rte_pktmbuf_read(ut_params->ibuf, 5924 (tdata->digest.offset_bytes == 0 ? 5925 plaintext_pad_len : tdata->digest.offset_bytes), 5926 tdata->digest.len, digest_buffer); 5927 5928 debug_hexdump(stdout, "digest:", digest, 5929 tdata->digest.len); 5930 debug_hexdump(stdout, "digest expected:", 5931 tdata->digest.data, tdata->digest.len); 5932 } 5933 5934 /* Validate obuf */ 5935 if (verify) { 5936 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5937 plaintext, 5938 tdata->plaintext.data, 5939 tdata->plaintext.len >> 3, 5940 "KASUMI Plaintext data not as expected"); 5941 } else { 5942 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5943 ciphertext, 5944 tdata->ciphertext.data, 5945 tdata->validDataLenInBits.len, 5946 "KASUMI Ciphertext data not as expected"); 5947 5948 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5949 digest, 5950 tdata->digest.data, 5951 DIGEST_BYTE_LENGTH_KASUMI_F9, 5952 "KASUMI Generated auth tag not as expected"); 5953 } 5954 return 0; 5955 } 5956 5957 static int 5958 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata) 5959 { 5960 struct crypto_testsuite_params *ts_params = &testsuite_params; 5961 struct crypto_unittest_params *ut_params = &unittest_params; 5962 5963 int retval; 5964 5965 uint8_t *plaintext, *ciphertext; 5966 unsigned plaintext_pad_len; 5967 unsigned plaintext_len; 5968 struct rte_cryptodev_info dev_info; 5969 5970 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5971 uint64_t feat_flags = dev_info.feature_flags; 5972 5973 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5974 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5975 printf("Device doesn't support RAW data-path APIs.\n"); 5976 return TEST_SKIPPED; 5977 } 5978 5979 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5980 return TEST_SKIPPED; 5981 5982 /* Verify the capabilities */ 5983 struct rte_cryptodev_sym_capability_idx cap_idx; 5984 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5985 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5986 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5987 &cap_idx) == NULL) 5988 return TEST_SKIPPED; 5989 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5990 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5991 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5992 &cap_idx) == NULL) 5993 return TEST_SKIPPED; 5994 5995 /* Create KASUMI session */ 5996 retval = create_wireless_algo_cipher_auth_session( 5997 ts_params->valid_devs[0], 5998 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5999 RTE_CRYPTO_AUTH_OP_GENERATE, 6000 RTE_CRYPTO_AUTH_KASUMI_F9, 6001 RTE_CRYPTO_CIPHER_KASUMI_F8, 6002 tdata->key.data, tdata->key.len, 6003 tdata->key.data, tdata->key.len, 6004 0, tdata->digest.len, 6005 tdata->cipher_iv.len); 6006 if (retval != 0) 6007 return retval; 6008 6009 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6010 6011 /* clear mbuf payload */ 6012 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6013 rte_pktmbuf_tailroom(ut_params->ibuf)); 6014 6015 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6016 /* Append data which is padded to a multiple of */ 6017 /* the algorithms block size */ 6018 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6019 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6020 plaintext_pad_len); 6021 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6022 6023 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6024 6025 /* Create KASUMI operation */ 6026 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 6027 tdata->digest.len, NULL, 0, 6028 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 6029 tdata->cipher_iv.data, tdata->cipher_iv.len, 6030 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 6031 tdata->validCipherOffsetInBits.len, 6032 tdata->validAuthLenInBits.len, 6033 0 6034 ); 6035 if (retval < 0) 6036 return retval; 6037 6038 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6039 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 6040 tdata->cipher_iv.len); 6041 if (retval != TEST_SUCCESS) 6042 return retval; 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 if (ut_params->op->sym->m_dst) 6049 ut_params->obuf = ut_params->op->sym->m_dst; 6050 else 6051 ut_params->obuf = ut_params->op->sym->m_src; 6052 6053 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 6054 tdata->validCipherOffsetInBits.len >> 3); 6055 6056 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 6057 uint8_t *, 6058 plaintext_pad_len); 6059 6060 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 6061 (tdata->validCipherOffsetInBits.len >> 3); 6062 /* Validate obuf */ 6063 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6064 ciphertext, 6065 reference_ciphertext, 6066 tdata->validCipherLenInBits.len, 6067 "KASUMI Ciphertext data not as expected"); 6068 6069 /* Validate obuf */ 6070 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6071 ut_params->digest, 6072 tdata->digest.data, 6073 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 6074 "KASUMI Generated auth tag not as expected"); 6075 return 0; 6076 } 6077 6078 static int 6079 check_cipher_capability(const struct crypto_testsuite_params *ts_params, 6080 const enum rte_crypto_cipher_algorithm cipher_algo, 6081 const uint16_t key_size, const uint16_t iv_size) 6082 { 6083 struct rte_cryptodev_sym_capability_idx cap_idx; 6084 const struct rte_cryptodev_symmetric_capability *cap; 6085 6086 /* Check if device supports the algorithm */ 6087 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 6088 cap_idx.algo.cipher = cipher_algo; 6089 6090 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 6091 &cap_idx); 6092 6093 if (cap == NULL) 6094 return -1; 6095 6096 /* Check if device supports key size and IV size */ 6097 if (rte_cryptodev_sym_capability_check_cipher(cap, key_size, 6098 iv_size) < 0) { 6099 return -1; 6100 } 6101 6102 return 0; 6103 } 6104 6105 static int 6106 check_auth_capability(const struct crypto_testsuite_params *ts_params, 6107 const enum rte_crypto_auth_algorithm auth_algo, 6108 const uint16_t key_size, const uint16_t iv_size, 6109 const uint16_t tag_size) 6110 { 6111 struct rte_cryptodev_sym_capability_idx cap_idx; 6112 const struct rte_cryptodev_symmetric_capability *cap; 6113 6114 /* Check if device supports the algorithm */ 6115 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 6116 cap_idx.algo.auth = auth_algo; 6117 6118 cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 6119 &cap_idx); 6120 6121 if (cap == NULL) 6122 return -1; 6123 6124 /* Check if device supports key size and IV size */ 6125 if (rte_cryptodev_sym_capability_check_auth(cap, key_size, 6126 tag_size, iv_size) < 0) { 6127 return -1; 6128 } 6129 6130 return 0; 6131 } 6132 6133 static int 6134 test_zuc_cipher(const struct wireless_test_data *tdata, 6135 enum rte_crypto_cipher_operation direction) 6136 { 6137 struct crypto_testsuite_params *ts_params = &testsuite_params; 6138 struct crypto_unittest_params *ut_params = &unittest_params; 6139 6140 int retval; 6141 uint8_t *plaintext = NULL; 6142 uint8_t *ciphertext = NULL; 6143 unsigned int plaintext_pad_len, ciphertext_pad_len; 6144 unsigned int plaintext_len = 0; 6145 unsigned int ciphertext_len = 0; 6146 struct rte_cryptodev_info dev_info; 6147 6148 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6149 uint64_t feat_flags = dev_info.feature_flags; 6150 6151 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6152 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6153 printf("Device doesn't support RAW data-path APIs.\n"); 6154 return TEST_SKIPPED; 6155 } 6156 6157 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6158 return TEST_SKIPPED; 6159 6160 /* Check if device supports ZUC EEA3 */ 6161 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6162 tdata->key.len, tdata->cipher_iv.len) < 0) 6163 return TEST_SKIPPED; 6164 6165 /* Create ZUC session */ 6166 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 6167 direction, 6168 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6169 tdata->key.data, tdata->key.len, 6170 tdata->cipher_iv.len); 6171 if (retval != 0) 6172 return retval; 6173 6174 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6175 6176 /* Clear mbuf payload */ 6177 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6178 rte_pktmbuf_tailroom(ut_params->ibuf)); 6179 6180 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6181 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6182 /* Append data which is padded to a multiple */ 6183 /* of the algorithms block size */ 6184 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6185 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6186 plaintext_pad_len); 6187 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6188 6189 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6190 } else { 6191 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6192 /* Append data which is padded to a multiple */ 6193 /* of the algorithms block size */ 6194 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 6195 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6196 ciphertext_pad_len); 6197 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6198 6199 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 6200 } 6201 6202 /* Create ZUC operation */ 6203 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6204 tdata->cipher_iv.len, 6205 tdata->plaintext.len, 6206 tdata->validCipherOffsetInBits.len); 6207 if (retval < 0) 6208 return retval; 6209 6210 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6211 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 6212 tdata->cipher_iv.len); 6213 if (retval != TEST_SUCCESS) 6214 return retval; 6215 } else 6216 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6217 ut_params->op); 6218 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6219 6220 ut_params->obuf = ut_params->op->sym->m_dst; 6221 6222 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6223 if (ut_params->obuf) 6224 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 6225 else 6226 ciphertext = plaintext; 6227 6228 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6229 6230 /* Validate obuf */ 6231 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6232 ciphertext, 6233 tdata->ciphertext.data, 6234 tdata->validCipherLenInBits.len, 6235 "ZUC Ciphertext data not as expected"); 6236 } else { 6237 if (ut_params->obuf) 6238 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 6239 else 6240 plaintext = ciphertext; 6241 6242 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 6243 6244 const uint8_t *reference_plaintext = tdata->plaintext.data + 6245 (tdata->validCipherOffsetInBits.len >> 3); 6246 6247 /* Validate obuf */ 6248 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6249 plaintext, 6250 reference_plaintext, 6251 tdata->validCipherLenInBits.len, 6252 "ZUC Plaintext data not as expected"); 6253 } 6254 6255 return 0; 6256 } 6257 6258 static int 6259 test_zuc_cipher_sgl(const struct wireless_test_data *tdata, 6260 enum rte_crypto_cipher_operation direction) 6261 { 6262 struct crypto_testsuite_params *ts_params = &testsuite_params; 6263 struct crypto_unittest_params *ut_params = &unittest_params; 6264 6265 int retval; 6266 6267 unsigned int plaintext_pad_len, ciphertext_pad_len; 6268 unsigned int plaintext_len = 0; 6269 unsigned int ciphertext_len = 0; 6270 const uint8_t *ciphertext, *plaintext; 6271 uint8_t buffer[2048]; 6272 struct rte_cryptodev_info dev_info; 6273 6274 /* Check if device supports ZUC EEA3 */ 6275 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6276 tdata->key.len, tdata->cipher_iv.len) < 0) 6277 return TEST_SKIPPED; 6278 6279 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 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_IN_PLACE_SGL)) { 6287 printf("Device doesn't support in-place scatter-gather. " 6288 "Test Skipped.\n"); 6289 return TEST_SKIPPED; 6290 } 6291 6292 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6293 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6294 printf("Device doesn't support RAW data-path APIs.\n"); 6295 return TEST_SKIPPED; 6296 } 6297 6298 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6299 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6300 6301 /* Append data which is padded to a multiple */ 6302 /* of the algorithms block size */ 6303 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6304 6305 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6306 plaintext_pad_len, 10, 0); 6307 6308 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6309 tdata->plaintext.data); 6310 } else { 6311 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6312 6313 /* Append data which is padded to a multiple */ 6314 /* of the algorithms block size */ 6315 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 6316 6317 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6318 ciphertext_pad_len, 10, 0); 6319 6320 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6321 tdata->ciphertext.data); 6322 6323 } 6324 6325 /* Create ZUC session */ 6326 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 6327 direction, 6328 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6329 tdata->key.data, tdata->key.len, 6330 tdata->cipher_iv.len); 6331 if (retval < 0) 6332 return retval; 6333 6334 /* Clear mbuf payload */ 6335 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) 6336 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 6337 else 6338 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, tdata->ciphertext.data); 6339 6340 /* Create ZUC operation */ 6341 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 6342 tdata->cipher_iv.len, tdata->plaintext.len, 6343 tdata->validCipherOffsetInBits.len); 6344 if (retval < 0) 6345 return retval; 6346 6347 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6348 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1, 6349 tdata->cipher_iv.len); 6350 if (retval != TEST_SUCCESS) 6351 return retval; 6352 } else 6353 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6354 ut_params->op); 6355 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6356 6357 ut_params->obuf = ut_params->op->sym->m_dst; 6358 6359 if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { 6360 if (ut_params->obuf) 6361 ciphertext = rte_pktmbuf_read(ut_params->obuf, 6362 0, plaintext_len, buffer); 6363 else 6364 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 6365 0, plaintext_len, buffer); 6366 6367 /* Validate obuf */ 6368 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 6369 6370 /* Validate obuf */ 6371 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6372 ciphertext, 6373 tdata->ciphertext.data, 6374 tdata->validCipherLenInBits.len, 6375 "ZUC Ciphertext data not as expected"); 6376 } else { 6377 if (ut_params->obuf) 6378 plaintext = rte_pktmbuf_read(ut_params->obuf, 6379 0, ciphertext_len, buffer); 6380 else 6381 plaintext = rte_pktmbuf_read(ut_params->ibuf, 6382 0, ciphertext_len, buffer); 6383 6384 /* Validate obuf */ 6385 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 6386 6387 /* Validate obuf */ 6388 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6389 plaintext, 6390 tdata->plaintext.data, 6391 tdata->validCipherLenInBits.len, 6392 "ZUC Plaintext data not as expected"); 6393 } 6394 6395 return 0; 6396 } 6397 6398 static int 6399 test_zuc_authentication(const struct wireless_test_data *tdata, 6400 enum rte_crypto_auth_operation auth_op) 6401 { 6402 struct crypto_testsuite_params *ts_params = &testsuite_params; 6403 struct crypto_unittest_params *ut_params = &unittest_params; 6404 6405 int retval; 6406 unsigned plaintext_pad_len; 6407 unsigned plaintext_len; 6408 uint8_t *plaintext; 6409 6410 struct rte_cryptodev_info dev_info; 6411 6412 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6413 uint64_t feat_flags = dev_info.feature_flags; 6414 6415 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 6416 (tdata->validAuthLenInBits.len % 8 != 0)) { 6417 printf("Device doesn't support NON-Byte Aligned Data.\n"); 6418 return TEST_SKIPPED; 6419 } 6420 6421 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6422 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6423 printf("Device doesn't support RAW data-path APIs.\n"); 6424 return TEST_SKIPPED; 6425 } 6426 6427 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6428 return TEST_SKIPPED; 6429 6430 /* Check if device supports ZUC EIA3 */ 6431 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6432 tdata->key.len, tdata->auth_iv.len, 6433 tdata->digest.len) < 0) 6434 return TEST_SKIPPED; 6435 6436 /* Create ZUC session */ 6437 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 6438 tdata->key.data, tdata->key.len, 6439 tdata->auth_iv.len, tdata->digest.len, 6440 auth_op, RTE_CRYPTO_AUTH_ZUC_EIA3); 6441 if (retval != 0) 6442 return retval; 6443 6444 /* alloc mbuf and set payload */ 6445 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6446 6447 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6448 rte_pktmbuf_tailroom(ut_params->ibuf)); 6449 6450 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6451 /* Append data which is padded to a multiple of */ 6452 /* the algorithms block size */ 6453 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 6454 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6455 plaintext_pad_len); 6456 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6457 6458 /* Create ZUC operation */ 6459 retval = create_wireless_algo_hash_operation(tdata->digest.data, 6460 tdata->digest.len, 6461 tdata->auth_iv.data, tdata->auth_iv.len, 6462 plaintext_pad_len, 6463 auth_op, tdata->validAuthLenInBits.len, 0); 6464 if (retval < 0) 6465 return retval; 6466 6467 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6468 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1, 6469 0); 6470 if (retval != TEST_SUCCESS) 6471 return retval; 6472 } else 6473 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6474 ut_params->op); 6475 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6476 ut_params->obuf = ut_params->op->sym->m_src; 6477 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 6478 uint8_t *, 6479 plaintext_pad_len); 6480 6481 if (auth_op != RTE_CRYPTO_AUTH_OP_VERIFY) { 6482 /* Validate obuf */ 6483 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6484 ut_params->digest, 6485 tdata->digest.data, 6486 tdata->digest.len, 6487 "ZUC Generated auth tag not as expected"); 6488 return 0; 6489 } 6490 6491 /* Validate obuf */ 6492 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 6493 return 0; 6494 else 6495 return -1; 6496 6497 return 0; 6498 } 6499 6500 static int 6501 test_zuc_auth_cipher(const struct wireless_test_data *tdata, 6502 uint8_t op_mode, uint8_t verify) 6503 { 6504 struct crypto_testsuite_params *ts_params = &testsuite_params; 6505 struct crypto_unittest_params *ut_params = &unittest_params; 6506 6507 int retval; 6508 6509 uint8_t *plaintext = NULL, *ciphertext = NULL; 6510 unsigned int plaintext_pad_len; 6511 unsigned int plaintext_len; 6512 unsigned int ciphertext_pad_len; 6513 unsigned int ciphertext_len; 6514 unsigned int digest_offset; 6515 6516 struct rte_cryptodev_info dev_info; 6517 6518 /* Check if device supports ZUC EEA3 */ 6519 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6520 tdata->key.len, tdata->cipher_iv.len) < 0) 6521 return TEST_SKIPPED; 6522 6523 /* Check if device supports ZUC EIA3 */ 6524 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6525 tdata->key.len, tdata->auth_iv.len, 6526 tdata->digest.len) < 0) 6527 return TEST_SKIPPED; 6528 6529 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6530 return TEST_SKIPPED; 6531 6532 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6533 6534 uint64_t feat_flags = dev_info.feature_flags; 6535 6536 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6537 printf("Device doesn't support digest encrypted.\n"); 6538 return TEST_SKIPPED; 6539 } 6540 if (op_mode == IN_PLACE) { 6541 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6542 printf("Device doesn't support in-place scatter-gather " 6543 "in both input and output mbufs.\n"); 6544 return TEST_SKIPPED; 6545 } 6546 6547 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6548 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6549 printf("Device doesn't support RAW data-path APIs.\n"); 6550 return TEST_SKIPPED; 6551 } 6552 } else { 6553 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6554 return TEST_SKIPPED; 6555 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6556 printf("Device doesn't support out-of-place scatter-gather " 6557 "in both input and output mbufs.\n"); 6558 return TEST_SKIPPED; 6559 } 6560 } 6561 6562 /* Create ZUC session */ 6563 retval = create_wireless_algo_auth_cipher_session( 6564 ts_params->valid_devs[0], 6565 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6566 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6567 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6568 : RTE_CRYPTO_AUTH_OP_GENERATE), 6569 RTE_CRYPTO_AUTH_ZUC_EIA3, 6570 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6571 tdata->key.data, tdata->key.len, 6572 tdata->key.data, tdata->key.len, 6573 tdata->auth_iv.len, tdata->digest.len, 6574 tdata->cipher_iv.len); 6575 6576 if (retval != 0) 6577 return retval; 6578 6579 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6580 if (op_mode == OUT_OF_PLACE) 6581 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6582 6583 /* clear mbuf payload */ 6584 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6585 rte_pktmbuf_tailroom(ut_params->ibuf)); 6586 if (op_mode == OUT_OF_PLACE) 6587 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 6588 rte_pktmbuf_tailroom(ut_params->obuf)); 6589 6590 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6591 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6592 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6593 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6594 6595 if (verify) { 6596 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6597 ciphertext_pad_len); 6598 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6599 debug_hexdump(stdout, "ciphertext:", ciphertext, 6600 ciphertext_len); 6601 } else { 6602 /* make sure enough space to cover partial digest verify case */ 6603 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6604 ciphertext_pad_len); 6605 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6606 debug_hexdump(stdout, "plaintext:", plaintext, 6607 plaintext_len); 6608 } 6609 6610 if (op_mode == OUT_OF_PLACE) 6611 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 6612 6613 /* Create ZUC operation */ 6614 retval = create_wireless_algo_auth_cipher_operation( 6615 tdata->digest.data, tdata->digest.len, 6616 tdata->cipher_iv.data, tdata->cipher_iv.len, 6617 tdata->auth_iv.data, tdata->auth_iv.len, 6618 (tdata->digest.offset_bytes == 0 ? 6619 (verify ? ciphertext_pad_len : plaintext_pad_len) 6620 : tdata->digest.offset_bytes), 6621 tdata->validCipherLenInBits.len, 6622 tdata->validCipherOffsetInBits.len, 6623 tdata->validAuthLenInBits.len, 6624 0, 6625 op_mode, 0, verify); 6626 6627 if (retval < 0) 6628 return retval; 6629 6630 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6631 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 6632 tdata->cipher_iv.len); 6633 if (retval != TEST_SUCCESS) 6634 return retval; 6635 } else 6636 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6637 ut_params->op); 6638 6639 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6640 6641 ut_params->obuf = (op_mode == IN_PLACE ? 6642 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6643 6644 6645 if (verify) { 6646 if (ut_params->obuf) 6647 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 6648 uint8_t *); 6649 else 6650 plaintext = ciphertext; 6651 6652 debug_hexdump(stdout, "plaintext:", plaintext, 6653 (tdata->plaintext.len >> 3) - tdata->digest.len); 6654 debug_hexdump(stdout, "plaintext expected:", 6655 tdata->plaintext.data, 6656 (tdata->plaintext.len >> 3) - tdata->digest.len); 6657 } else { 6658 if (ut_params->obuf) 6659 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 6660 uint8_t *); 6661 else 6662 ciphertext = plaintext; 6663 6664 debug_hexdump(stdout, "ciphertext:", ciphertext, 6665 ciphertext_len); 6666 debug_hexdump(stdout, "ciphertext expected:", 6667 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6668 6669 if (tdata->digest.offset_bytes == 0) 6670 digest_offset = plaintext_pad_len; 6671 else 6672 digest_offset = tdata->digest.offset_bytes; 6673 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 6674 uint8_t *, digest_offset); 6675 6676 debug_hexdump(stdout, "digest:", ut_params->digest, 6677 tdata->digest.len); 6678 debug_hexdump(stdout, "digest expected:", 6679 tdata->digest.data, tdata->digest.len); 6680 } 6681 6682 /* Validate obuf */ 6683 if (verify) { 6684 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6685 plaintext, 6686 tdata->plaintext.data, 6687 tdata->plaintext.len >> 3, 6688 "ZUC Plaintext data not as expected"); 6689 } else { 6690 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6691 ciphertext, 6692 tdata->ciphertext.data, 6693 tdata->ciphertext.len >> 3, 6694 "ZUC Ciphertext data not as expected"); 6695 6696 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6697 ut_params->digest, 6698 tdata->digest.data, 6699 tdata->digest.len, 6700 "ZUC Generated auth tag not as expected"); 6701 } 6702 return 0; 6703 } 6704 6705 static int 6706 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata, 6707 uint8_t op_mode, uint8_t verify) 6708 { 6709 struct crypto_testsuite_params *ts_params = &testsuite_params; 6710 struct crypto_unittest_params *ut_params = &unittest_params; 6711 6712 int retval; 6713 6714 const uint8_t *plaintext = NULL; 6715 const uint8_t *ciphertext = NULL; 6716 const uint8_t *digest = NULL; 6717 unsigned int plaintext_pad_len; 6718 unsigned int plaintext_len; 6719 unsigned int ciphertext_pad_len; 6720 unsigned int ciphertext_len; 6721 uint8_t buffer[10000]; 6722 uint8_t digest_buffer[10000]; 6723 6724 struct rte_cryptodev_info dev_info; 6725 6726 /* Check if device supports ZUC EEA3 */ 6727 if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3, 6728 tdata->key.len, tdata->cipher_iv.len) < 0) 6729 return TEST_SKIPPED; 6730 6731 /* Check if device supports ZUC EIA3 */ 6732 if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3, 6733 tdata->key.len, tdata->auth_iv.len, 6734 tdata->digest.len) < 0) 6735 return TEST_SKIPPED; 6736 6737 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 6738 return TEST_SKIPPED; 6739 6740 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6741 6742 uint64_t feat_flags = dev_info.feature_flags; 6743 6744 if (op_mode == IN_PLACE) { 6745 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6746 printf("Device doesn't support in-place scatter-gather " 6747 "in both input and output mbufs.\n"); 6748 return TEST_SKIPPED; 6749 } 6750 6751 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 6752 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 6753 printf("Device doesn't support RAW data-path APIs.\n"); 6754 return TEST_SKIPPED; 6755 } 6756 } else { 6757 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6758 return TEST_SKIPPED; 6759 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6760 printf("Device doesn't support out-of-place scatter-gather " 6761 "in both input and output mbufs.\n"); 6762 return TEST_SKIPPED; 6763 } 6764 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6765 printf("Device doesn't support digest encrypted.\n"); 6766 return TEST_SKIPPED; 6767 } 6768 } 6769 6770 /* Create ZUC session */ 6771 retval = create_wireless_algo_auth_cipher_session( 6772 ts_params->valid_devs[0], 6773 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 6774 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 6775 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 6776 : RTE_CRYPTO_AUTH_OP_GENERATE), 6777 RTE_CRYPTO_AUTH_ZUC_EIA3, 6778 RTE_CRYPTO_CIPHER_ZUC_EEA3, 6779 tdata->key.data, tdata->key.len, 6780 tdata->key.data, tdata->key.len, 6781 tdata->auth_iv.len, tdata->digest.len, 6782 tdata->cipher_iv.len); 6783 6784 if (retval != 0) 6785 return retval; 6786 6787 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6788 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6789 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6790 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6791 6792 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6793 plaintext_pad_len, 15, 0); 6794 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6795 "Failed to allocate input buffer in mempool"); 6796 6797 if (op_mode == OUT_OF_PLACE) { 6798 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 6799 plaintext_pad_len, 15, 0); 6800 TEST_ASSERT_NOT_NULL(ut_params->obuf, 6801 "Failed to allocate output buffer in mempool"); 6802 } 6803 6804 if (verify) { 6805 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6806 tdata->ciphertext.data); 6807 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6808 ciphertext_len, buffer); 6809 debug_hexdump(stdout, "ciphertext:", ciphertext, 6810 ciphertext_len); 6811 } else { 6812 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6813 tdata->plaintext.data); 6814 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6815 plaintext_len, buffer); 6816 debug_hexdump(stdout, "plaintext:", plaintext, 6817 plaintext_len); 6818 } 6819 memset(buffer, 0, sizeof(buffer)); 6820 6821 /* Create ZUC operation */ 6822 retval = create_wireless_algo_auth_cipher_operation( 6823 tdata->digest.data, tdata->digest.len, 6824 tdata->cipher_iv.data, tdata->cipher_iv.len, 6825 tdata->auth_iv.data, tdata->auth_iv.len, 6826 (tdata->digest.offset_bytes == 0 ? 6827 (verify ? ciphertext_pad_len : plaintext_pad_len) 6828 : tdata->digest.offset_bytes), 6829 tdata->validCipherLenInBits.len, 6830 tdata->validCipherOffsetInBits.len, 6831 tdata->validAuthLenInBits.len, 6832 0, 6833 op_mode, 1, verify); 6834 6835 if (retval < 0) 6836 return retval; 6837 6838 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 6839 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1, 6840 tdata->cipher_iv.len); 6841 if (retval != TEST_SUCCESS) 6842 return retval; 6843 } else 6844 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6845 ut_params->op); 6846 6847 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6848 6849 ut_params->obuf = (op_mode == IN_PLACE ? 6850 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6851 6852 if (verify) { 6853 if (ut_params->obuf) 6854 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 6855 plaintext_len, buffer); 6856 else 6857 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6858 plaintext_len, buffer); 6859 6860 debug_hexdump(stdout, "plaintext:", plaintext, 6861 (tdata->plaintext.len >> 3) - tdata->digest.len); 6862 debug_hexdump(stdout, "plaintext expected:", 6863 tdata->plaintext.data, 6864 (tdata->plaintext.len >> 3) - tdata->digest.len); 6865 } else { 6866 if (ut_params->obuf) 6867 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 6868 ciphertext_len, buffer); 6869 else 6870 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6871 ciphertext_len, buffer); 6872 6873 debug_hexdump(stdout, "ciphertext:", ciphertext, 6874 ciphertext_len); 6875 debug_hexdump(stdout, "ciphertext expected:", 6876 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6877 6878 if (ut_params->obuf) 6879 digest = rte_pktmbuf_read(ut_params->obuf, 6880 (tdata->digest.offset_bytes == 0 ? 6881 plaintext_pad_len : tdata->digest.offset_bytes), 6882 tdata->digest.len, digest_buffer); 6883 else 6884 digest = rte_pktmbuf_read(ut_params->ibuf, 6885 (tdata->digest.offset_bytes == 0 ? 6886 plaintext_pad_len : tdata->digest.offset_bytes), 6887 tdata->digest.len, digest_buffer); 6888 6889 debug_hexdump(stdout, "digest:", digest, 6890 tdata->digest.len); 6891 debug_hexdump(stdout, "digest expected:", 6892 tdata->digest.data, tdata->digest.len); 6893 } 6894 6895 /* Validate obuf */ 6896 if (verify) { 6897 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6898 plaintext, 6899 tdata->plaintext.data, 6900 tdata->plaintext.len >> 3, 6901 "ZUC Plaintext data not as expected"); 6902 } else { 6903 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6904 ciphertext, 6905 tdata->ciphertext.data, 6906 tdata->validDataLenInBits.len, 6907 "ZUC Ciphertext data not as expected"); 6908 6909 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6910 digest, 6911 tdata->digest.data, 6912 tdata->digest.len, 6913 "ZUC Generated auth tag not as expected"); 6914 } 6915 return 0; 6916 } 6917 6918 static int 6919 test_kasumi_encryption_test_case_1(void) 6920 { 6921 return test_kasumi_encryption(&kasumi_test_case_1); 6922 } 6923 6924 static int 6925 test_kasumi_encryption_test_case_1_sgl(void) 6926 { 6927 return test_kasumi_encryption_sgl(&kasumi_test_case_1); 6928 } 6929 6930 static int 6931 test_kasumi_encryption_test_case_1_oop(void) 6932 { 6933 return test_kasumi_encryption_oop(&kasumi_test_case_1); 6934 } 6935 6936 static int 6937 test_kasumi_encryption_test_case_1_oop_sgl(void) 6938 { 6939 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1); 6940 } 6941 6942 static int 6943 test_kasumi_encryption_test_case_2(void) 6944 { 6945 return test_kasumi_encryption(&kasumi_test_case_2); 6946 } 6947 6948 static int 6949 test_kasumi_encryption_test_case_3(void) 6950 { 6951 return test_kasumi_encryption(&kasumi_test_case_3); 6952 } 6953 6954 static int 6955 test_kasumi_encryption_test_case_4(void) 6956 { 6957 return test_kasumi_encryption(&kasumi_test_case_4); 6958 } 6959 6960 static int 6961 test_kasumi_encryption_test_case_5(void) 6962 { 6963 return test_kasumi_encryption(&kasumi_test_case_5); 6964 } 6965 6966 static int 6967 test_kasumi_decryption_test_case_1(void) 6968 { 6969 return test_kasumi_decryption(&kasumi_test_case_1); 6970 } 6971 6972 static int 6973 test_kasumi_decryption_test_case_1_oop(void) 6974 { 6975 return test_kasumi_decryption_oop(&kasumi_test_case_1); 6976 } 6977 6978 static int 6979 test_kasumi_decryption_test_case_2(void) 6980 { 6981 return test_kasumi_decryption(&kasumi_test_case_2); 6982 } 6983 6984 static int 6985 test_kasumi_decryption_test_case_3(void) 6986 { 6987 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6988 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6989 return TEST_SKIPPED; 6990 return test_kasumi_decryption(&kasumi_test_case_3); 6991 } 6992 6993 static int 6994 test_kasumi_decryption_test_case_4(void) 6995 { 6996 return test_kasumi_decryption(&kasumi_test_case_4); 6997 } 6998 6999 static int 7000 test_kasumi_decryption_test_case_5(void) 7001 { 7002 return test_kasumi_decryption(&kasumi_test_case_5); 7003 } 7004 static int 7005 test_snow3g_encryption_test_case_1(void) 7006 { 7007 return test_snow3g_encryption(&snow3g_test_case_1); 7008 } 7009 7010 static int 7011 test_snow3g_encryption_test_case_1_oop(void) 7012 { 7013 return test_snow3g_encryption_oop(&snow3g_test_case_1); 7014 } 7015 7016 static int 7017 test_snow3g_encryption_test_case_1_oop_sgl(void) 7018 { 7019 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 1, 1); 7020 } 7021 7022 static int 7023 test_snow3g_encryption_test_case_1_oop_lb_in_sgl_out(void) 7024 { 7025 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 0, 1); 7026 } 7027 7028 static int 7029 test_snow3g_encryption_test_case_1_oop_sgl_in_lb_out(void) 7030 { 7031 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 1, 0); 7032 } 7033 7034 static int 7035 test_snow3g_encryption_test_case_1_offset_oop(void) 7036 { 7037 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); 7038 } 7039 7040 static int 7041 test_snow3g_encryption_test_case_2(void) 7042 { 7043 return test_snow3g_encryption(&snow3g_test_case_2); 7044 } 7045 7046 static int 7047 test_snow3g_encryption_test_case_3(void) 7048 { 7049 return test_snow3g_encryption(&snow3g_test_case_3); 7050 } 7051 7052 static int 7053 test_snow3g_encryption_test_case_4(void) 7054 { 7055 return test_snow3g_encryption(&snow3g_test_case_4); 7056 } 7057 7058 static int 7059 test_snow3g_encryption_test_case_5(void) 7060 { 7061 return test_snow3g_encryption(&snow3g_test_case_5); 7062 } 7063 7064 static int 7065 test_snow3g_decryption_test_case_1(void) 7066 { 7067 return test_snow3g_decryption(&snow3g_test_case_1); 7068 } 7069 7070 static int 7071 test_snow3g_decryption_test_case_1_oop(void) 7072 { 7073 return test_snow3g_decryption_oop(&snow3g_test_case_1); 7074 } 7075 7076 static int 7077 test_snow3g_decryption_test_case_2(void) 7078 { 7079 return test_snow3g_decryption(&snow3g_test_case_2); 7080 } 7081 7082 static int 7083 test_snow3g_decryption_test_case_3(void) 7084 { 7085 return test_snow3g_decryption(&snow3g_test_case_3); 7086 } 7087 7088 static int 7089 test_snow3g_decryption_test_case_4(void) 7090 { 7091 return test_snow3g_decryption(&snow3g_test_case_4); 7092 } 7093 7094 static int 7095 test_snow3g_decryption_test_case_5(void) 7096 { 7097 return test_snow3g_decryption(&snow3g_test_case_5); 7098 } 7099 7100 /* 7101 * Function prepares snow3g_hash_test_data from snow3g_test_data. 7102 * Pattern digest from snow3g_test_data must be allocated as 7103 * 4 last bytes in plaintext. 7104 */ 7105 static void 7106 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern, 7107 struct snow3g_hash_test_data *output) 7108 { 7109 if ((pattern != NULL) && (output != NULL)) { 7110 output->key.len = pattern->key.len; 7111 7112 memcpy(output->key.data, 7113 pattern->key.data, pattern->key.len); 7114 7115 output->auth_iv.len = pattern->auth_iv.len; 7116 7117 memcpy(output->auth_iv.data, 7118 pattern->auth_iv.data, pattern->auth_iv.len); 7119 7120 output->plaintext.len = pattern->plaintext.len; 7121 7122 memcpy(output->plaintext.data, 7123 pattern->plaintext.data, pattern->plaintext.len >> 3); 7124 7125 output->digest.len = pattern->digest.len; 7126 7127 memcpy(output->digest.data, 7128 &pattern->plaintext.data[pattern->digest.offset_bytes], 7129 pattern->digest.len); 7130 7131 output->validAuthLenInBits.len = 7132 pattern->validAuthLenInBits.len; 7133 } 7134 } 7135 7136 /* 7137 * Test case verify computed cipher and digest from snow3g_test_case_7 data. 7138 */ 7139 static int 7140 test_snow3g_decryption_with_digest_test_case_1(void) 7141 { 7142 int ret; 7143 struct snow3g_hash_test_data snow3g_hash_data; 7144 struct rte_cryptodev_info dev_info; 7145 struct crypto_testsuite_params *ts_params = &testsuite_params; 7146 7147 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7148 uint64_t feat_flags = dev_info.feature_flags; 7149 7150 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7151 printf("Device doesn't support encrypted digest operations.\n"); 7152 return TEST_SKIPPED; 7153 } 7154 7155 /* 7156 * Function prepare data for hash verification test case. 7157 * Digest is allocated in 4 last bytes in plaintext, pattern. 7158 */ 7159 snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data); 7160 7161 ret = test_snow3g_decryption(&snow3g_test_case_7); 7162 if (ret != 0) 7163 return ret; 7164 7165 return test_snow3g_authentication_verify(&snow3g_hash_data); 7166 } 7167 7168 static int 7169 test_snow3g_cipher_auth_test_case_1(void) 7170 { 7171 return test_snow3g_cipher_auth(&snow3g_test_case_3); 7172 } 7173 7174 static int 7175 test_snow3g_auth_cipher_test_case_1(void) 7176 { 7177 return test_snow3g_auth_cipher( 7178 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0); 7179 } 7180 7181 static int 7182 test_snow3g_auth_cipher_test_case_2(void) 7183 { 7184 return test_snow3g_auth_cipher( 7185 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0); 7186 } 7187 7188 static int 7189 test_snow3g_auth_cipher_test_case_2_oop(void) 7190 { 7191 return test_snow3g_auth_cipher( 7192 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7193 } 7194 7195 static int 7196 test_snow3g_auth_cipher_part_digest_enc(void) 7197 { 7198 return test_snow3g_auth_cipher( 7199 &snow3g_auth_cipher_partial_digest_encryption, 7200 IN_PLACE, 0); 7201 } 7202 7203 static int 7204 test_snow3g_auth_cipher_part_digest_enc_oop(void) 7205 { 7206 return test_snow3g_auth_cipher( 7207 &snow3g_auth_cipher_partial_digest_encryption, 7208 OUT_OF_PLACE, 0); 7209 } 7210 7211 static int 7212 test_snow3g_auth_cipher_test_case_3_sgl(void) 7213 { 7214 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 7215 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7216 return TEST_SKIPPED; 7217 return test_snow3g_auth_cipher_sgl( 7218 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0); 7219 } 7220 7221 static int 7222 test_snow3g_auth_cipher_test_case_3_oop_sgl(void) 7223 { 7224 return test_snow3g_auth_cipher_sgl( 7225 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0); 7226 } 7227 7228 static int 7229 test_snow3g_auth_cipher_part_digest_enc_sgl(void) 7230 { 7231 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 7232 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7233 return TEST_SKIPPED; 7234 return test_snow3g_auth_cipher_sgl( 7235 &snow3g_auth_cipher_partial_digest_encryption, 7236 IN_PLACE, 0); 7237 } 7238 7239 static int 7240 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void) 7241 { 7242 return test_snow3g_auth_cipher_sgl( 7243 &snow3g_auth_cipher_partial_digest_encryption, 7244 OUT_OF_PLACE, 0); 7245 } 7246 7247 static int 7248 test_snow3g_auth_cipher_total_digest_enc_1(void) 7249 { 7250 return test_snow3g_auth_cipher( 7251 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 0); 7252 } 7253 7254 static int 7255 test_snow3g_auth_cipher_total_digest_enc_1_oop(void) 7256 { 7257 return test_snow3g_auth_cipher( 7258 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 0); 7259 } 7260 7261 static int 7262 test_snow3g_auth_cipher_total_digest_enc_1_sgl(void) 7263 { 7264 return test_snow3g_auth_cipher_sgl( 7265 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 0); 7266 } 7267 7268 static int 7269 test_snow3g_auth_cipher_total_digest_enc_1_oop_sgl(void) 7270 { 7271 return test_snow3g_auth_cipher_sgl( 7272 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 0); 7273 } 7274 7275 static int 7276 test_snow3g_auth_cipher_verify_test_case_1(void) 7277 { 7278 return test_snow3g_auth_cipher( 7279 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1); 7280 } 7281 7282 static int 7283 test_snow3g_auth_cipher_verify_test_case_2(void) 7284 { 7285 return test_snow3g_auth_cipher( 7286 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1); 7287 } 7288 7289 static int 7290 test_snow3g_auth_cipher_verify_test_case_2_oop(void) 7291 { 7292 return test_snow3g_auth_cipher( 7293 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7294 } 7295 7296 static int 7297 test_snow3g_auth_cipher_verify_part_digest_enc(void) 7298 { 7299 return test_snow3g_auth_cipher( 7300 &snow3g_auth_cipher_partial_digest_encryption, 7301 IN_PLACE, 1); 7302 } 7303 7304 static int 7305 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void) 7306 { 7307 return test_snow3g_auth_cipher( 7308 &snow3g_auth_cipher_partial_digest_encryption, 7309 OUT_OF_PLACE, 1); 7310 } 7311 7312 static int 7313 test_snow3g_auth_cipher_verify_test_case_3_sgl(void) 7314 { 7315 return test_snow3g_auth_cipher_sgl( 7316 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1); 7317 } 7318 7319 static int 7320 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void) 7321 { 7322 return test_snow3g_auth_cipher_sgl( 7323 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1); 7324 } 7325 7326 static int 7327 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void) 7328 { 7329 return test_snow3g_auth_cipher_sgl( 7330 &snow3g_auth_cipher_partial_digest_encryption, 7331 IN_PLACE, 1); 7332 } 7333 7334 static int 7335 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void) 7336 { 7337 return test_snow3g_auth_cipher_sgl( 7338 &snow3g_auth_cipher_partial_digest_encryption, 7339 OUT_OF_PLACE, 1); 7340 } 7341 7342 static int 7343 test_snow3g_auth_cipher_verify_total_digest_enc_1(void) 7344 { 7345 return test_snow3g_auth_cipher( 7346 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 1); 7347 } 7348 7349 static int 7350 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop(void) 7351 { 7352 return test_snow3g_auth_cipher( 7353 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 1); 7354 } 7355 7356 static int 7357 test_snow3g_auth_cipher_verify_total_digest_enc_1_sgl(void) 7358 { 7359 return test_snow3g_auth_cipher_sgl( 7360 &snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 1); 7361 } 7362 7363 static int 7364 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop_sgl(void) 7365 { 7366 return test_snow3g_auth_cipher_sgl( 7367 &snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 1); 7368 } 7369 7370 static int 7371 test_snow3g_auth_cipher_with_digest_test_case_1(void) 7372 { 7373 return test_snow3g_auth_cipher( 7374 &snow3g_test_case_7, IN_PLACE, 0); 7375 } 7376 7377 static int 7378 test_kasumi_auth_cipher_test_case_1(void) 7379 { 7380 return test_kasumi_auth_cipher( 7381 &kasumi_test_case_3, IN_PLACE, 0); 7382 } 7383 7384 static int 7385 test_kasumi_auth_cipher_test_case_2(void) 7386 { 7387 return test_kasumi_auth_cipher( 7388 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7389 } 7390 7391 static int 7392 test_kasumi_auth_cipher_test_case_2_oop(void) 7393 { 7394 return test_kasumi_auth_cipher( 7395 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7396 } 7397 7398 static int 7399 test_kasumi_auth_cipher_test_case_2_sgl(void) 7400 { 7401 return test_kasumi_auth_cipher_sgl( 7402 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 7403 } 7404 7405 static int 7406 test_kasumi_auth_cipher_test_case_2_oop_sgl(void) 7407 { 7408 return test_kasumi_auth_cipher_sgl( 7409 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7410 } 7411 7412 static int 7413 test_kasumi_auth_cipher_verify_test_case_1(void) 7414 { 7415 return test_kasumi_auth_cipher( 7416 &kasumi_test_case_3, IN_PLACE, 1); 7417 } 7418 7419 static int 7420 test_kasumi_auth_cipher_verify_test_case_2(void) 7421 { 7422 return test_kasumi_auth_cipher( 7423 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7424 } 7425 7426 static int 7427 test_kasumi_auth_cipher_verify_test_case_2_oop(void) 7428 { 7429 return test_kasumi_auth_cipher( 7430 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7431 } 7432 7433 static int 7434 test_kasumi_auth_cipher_verify_test_case_2_sgl(void) 7435 { 7436 return test_kasumi_auth_cipher_sgl( 7437 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 7438 } 7439 7440 static int 7441 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void) 7442 { 7443 return test_kasumi_auth_cipher_sgl( 7444 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7445 } 7446 7447 static int 7448 test_kasumi_cipher_auth_test_case_1(void) 7449 { 7450 return test_kasumi_cipher_auth(&kasumi_test_case_6); 7451 } 7452 7453 static int 7454 test_zuc_encryption_test_case_1(void) 7455 { 7456 return test_zuc_cipher(&zuc_test_case_cipher_193b, 7457 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7458 } 7459 7460 static int 7461 test_zuc_encryption_test_case_2(void) 7462 { 7463 return test_zuc_cipher(&zuc_test_case_cipher_800b, 7464 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7465 } 7466 7467 static int 7468 test_zuc_encryption_test_case_3(void) 7469 { 7470 return test_zuc_cipher(&zuc_test_case_cipher_1570b, 7471 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7472 } 7473 7474 static int 7475 test_zuc_encryption_test_case_4(void) 7476 { 7477 return test_zuc_cipher(&zuc_test_case_cipher_2798b, 7478 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7479 } 7480 7481 static int 7482 test_zuc_encryption_test_case_5(void) 7483 { 7484 return test_zuc_cipher(&zuc_test_case_cipher_4019b, 7485 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7486 } 7487 7488 static int 7489 test_zuc_encryption_test_case_6_sgl(void) 7490 { 7491 return test_zuc_cipher_sgl(&zuc_test_case_cipher_193b, 7492 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7493 } 7494 7495 static int 7496 test_zuc_decryption_test_case_1(void) 7497 { 7498 return test_zuc_cipher(&zuc_test_case_cipher_193b, 7499 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7500 } 7501 7502 static int 7503 test_zuc_decryption_test_case_2(void) 7504 { 7505 return test_zuc_cipher(&zuc_test_case_cipher_800b, 7506 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7507 } 7508 7509 static int 7510 test_zuc_decryption_test_case_3(void) 7511 { 7512 return test_zuc_cipher(&zuc_test_case_cipher_1570b, 7513 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7514 } 7515 7516 static int 7517 test_zuc_decryption_test_case_4(void) 7518 { 7519 return test_zuc_cipher(&zuc_test_case_cipher_2798b, 7520 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7521 } 7522 7523 static int 7524 test_zuc_decryption_test_case_5(void) 7525 { 7526 return test_zuc_cipher(&zuc_test_case_cipher_4019b, 7527 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7528 } 7529 7530 static int 7531 test_zuc_decryption_test_case_6_sgl(void) 7532 { 7533 return test_zuc_cipher_sgl(&zuc_test_case_cipher_193b, 7534 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7535 } 7536 7537 static int 7538 test_zuc_hash_generate_test_case_1(void) 7539 { 7540 return test_zuc_authentication(&zuc_test_case_auth_1b, 7541 RTE_CRYPTO_AUTH_OP_GENERATE); 7542 } 7543 7544 static int 7545 test_zuc_hash_generate_test_case_2(void) 7546 { 7547 return test_zuc_authentication(&zuc_test_case_auth_90b, 7548 RTE_CRYPTO_AUTH_OP_GENERATE); 7549 } 7550 7551 static int 7552 test_zuc_hash_generate_test_case_3(void) 7553 { 7554 return test_zuc_authentication(&zuc_test_case_auth_577b, 7555 RTE_CRYPTO_AUTH_OP_GENERATE); 7556 } 7557 7558 static int 7559 test_zuc_hash_generate_test_case_4(void) 7560 { 7561 return test_zuc_authentication(&zuc_test_case_auth_2079b, 7562 RTE_CRYPTO_AUTH_OP_GENERATE); 7563 } 7564 7565 static int 7566 test_zuc_hash_generate_test_case_5(void) 7567 { 7568 return test_zuc_authentication(&zuc_test_auth_5670b, 7569 RTE_CRYPTO_AUTH_OP_GENERATE); 7570 } 7571 7572 static int 7573 test_zuc_hash_generate_test_case_6(void) 7574 { 7575 return test_zuc_authentication(&zuc_test_case_auth_128b, 7576 RTE_CRYPTO_AUTH_OP_GENERATE); 7577 } 7578 7579 static int 7580 test_zuc_hash_generate_test_case_7(void) 7581 { 7582 return test_zuc_authentication(&zuc_test_case_auth_2080b, 7583 RTE_CRYPTO_AUTH_OP_GENERATE); 7584 } 7585 7586 static int 7587 test_zuc_hash_generate_test_case_8(void) 7588 { 7589 return test_zuc_authentication(&zuc_test_case_auth_584b, 7590 RTE_CRYPTO_AUTH_OP_GENERATE); 7591 } 7592 7593 static int 7594 test_zuc_hash_verify_test_case_1(void) 7595 { 7596 return test_zuc_authentication(&zuc_test_case_auth_1b, 7597 RTE_CRYPTO_AUTH_OP_VERIFY); 7598 } 7599 7600 static int 7601 test_zuc_hash_verify_test_case_2(void) 7602 { 7603 return test_zuc_authentication(&zuc_test_case_auth_90b, 7604 RTE_CRYPTO_AUTH_OP_VERIFY); 7605 } 7606 7607 static int 7608 test_zuc_hash_verify_test_case_3(void) 7609 { 7610 return test_zuc_authentication(&zuc_test_case_auth_577b, 7611 RTE_CRYPTO_AUTH_OP_VERIFY); 7612 } 7613 7614 static int 7615 test_zuc_hash_verify_test_case_4(void) 7616 { 7617 return test_zuc_authentication(&zuc_test_case_auth_2079b, 7618 RTE_CRYPTO_AUTH_OP_VERIFY); 7619 } 7620 7621 static int 7622 test_zuc_hash_verify_test_case_5(void) 7623 { 7624 return test_zuc_authentication(&zuc_test_auth_5670b, 7625 RTE_CRYPTO_AUTH_OP_VERIFY); 7626 } 7627 7628 static int 7629 test_zuc_hash_verify_test_case_6(void) 7630 { 7631 return test_zuc_authentication(&zuc_test_case_auth_128b, 7632 RTE_CRYPTO_AUTH_OP_VERIFY); 7633 } 7634 7635 static int 7636 test_zuc_hash_verify_test_case_7(void) 7637 { 7638 return test_zuc_authentication(&zuc_test_case_auth_2080b, 7639 RTE_CRYPTO_AUTH_OP_VERIFY); 7640 } 7641 7642 static int 7643 test_zuc_hash_verify_test_case_8(void) 7644 { 7645 return test_zuc_authentication(&zuc_test_case_auth_584b, 7646 RTE_CRYPTO_AUTH_OP_VERIFY); 7647 } 7648 7649 static int 7650 test_zuc_cipher_auth_test_case_1(void) 7651 { 7652 return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b); 7653 } 7654 7655 static int 7656 test_zuc_cipher_auth_test_case_2(void) 7657 { 7658 return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b); 7659 } 7660 7661 static int 7662 test_zuc_auth_cipher_test_case_1(void) 7663 { 7664 return test_zuc_auth_cipher( 7665 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7666 } 7667 7668 static int 7669 test_zuc_auth_cipher_test_case_1_oop(void) 7670 { 7671 return test_zuc_auth_cipher( 7672 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7673 } 7674 7675 static int 7676 test_zuc_auth_cipher_test_case_1_sgl(void) 7677 { 7678 return test_zuc_auth_cipher_sgl( 7679 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 7680 } 7681 7682 static int 7683 test_zuc_auth_cipher_test_case_1_oop_sgl(void) 7684 { 7685 return test_zuc_auth_cipher_sgl( 7686 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 7687 } 7688 7689 static int 7690 test_zuc_auth_cipher_test_case_2(void) 7691 { 7692 return test_zuc_auth_cipher( 7693 &zuc_auth_cipher_test_case_2, IN_PLACE, 0); 7694 } 7695 7696 static int 7697 test_zuc_auth_cipher_test_case_2_oop(void) 7698 { 7699 return test_zuc_auth_cipher( 7700 &zuc_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 7701 } 7702 7703 static int 7704 test_zuc_auth_cipher_verify_test_case_1(void) 7705 { 7706 return test_zuc_auth_cipher( 7707 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7708 } 7709 7710 static int 7711 test_zuc_auth_cipher_verify_test_case_1_oop(void) 7712 { 7713 return test_zuc_auth_cipher( 7714 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7715 } 7716 7717 static int 7718 test_zuc_auth_cipher_verify_test_case_1_sgl(void) 7719 { 7720 return test_zuc_auth_cipher_sgl( 7721 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 7722 } 7723 7724 static int 7725 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void) 7726 { 7727 return test_zuc_auth_cipher_sgl( 7728 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 7729 } 7730 7731 static int 7732 test_zuc_auth_cipher_verify_test_case_2(void) 7733 { 7734 return test_zuc_auth_cipher( 7735 &zuc_auth_cipher_test_case_2, IN_PLACE, 1); 7736 } 7737 7738 static int 7739 test_zuc_auth_cipher_verify_test_case_2_oop(void) 7740 { 7741 return test_zuc_auth_cipher( 7742 &zuc_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 7743 } 7744 7745 static int 7746 test_zuc256_encryption_test_case_1(void) 7747 { 7748 return test_zuc_cipher(&zuc256_test_case_cipher_1, 7749 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7750 } 7751 7752 static int 7753 test_zuc256_encryption_test_case_2(void) 7754 { 7755 return test_zuc_cipher(&zuc256_test_case_cipher_2, 7756 RTE_CRYPTO_CIPHER_OP_ENCRYPT); 7757 } 7758 7759 static int 7760 test_zuc256_decryption_test_case_1(void) 7761 { 7762 return test_zuc_cipher(&zuc256_test_case_cipher_1, 7763 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7764 } 7765 7766 static int 7767 test_zuc256_decryption_test_case_2(void) 7768 { 7769 return test_zuc_cipher(&zuc256_test_case_cipher_2, 7770 RTE_CRYPTO_CIPHER_OP_DECRYPT); 7771 } 7772 7773 static int 7774 test_zuc256_hash_generate_4b_tag_test_case_1(void) 7775 { 7776 return test_zuc_authentication(&zuc256_test_case_auth_1, 7777 RTE_CRYPTO_AUTH_OP_GENERATE); 7778 } 7779 7780 static int 7781 test_zuc256_hash_generate_4b_tag_test_case_2(void) 7782 { 7783 return test_zuc_authentication(&zuc256_test_case_auth_2, 7784 RTE_CRYPTO_AUTH_OP_GENERATE); 7785 } 7786 7787 static int 7788 test_zuc256_hash_generate_4b_tag_test_case_3(void) 7789 { 7790 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b, 7791 RTE_CRYPTO_AUTH_OP_GENERATE); 7792 } 7793 7794 static int 7795 test_zuc256_hash_generate_8b_tag_test_case_1(void) 7796 { 7797 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b, 7798 RTE_CRYPTO_AUTH_OP_GENERATE); 7799 } 7800 7801 static int 7802 test_zuc256_hash_generate_16b_tag_test_case_1(void) 7803 { 7804 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b, 7805 RTE_CRYPTO_AUTH_OP_GENERATE); 7806 } 7807 7808 static int 7809 test_zuc256_hash_verify_4b_tag_test_case_1(void) 7810 { 7811 return test_zuc_authentication(&zuc256_test_case_auth_1, 7812 RTE_CRYPTO_AUTH_OP_VERIFY); 7813 } 7814 7815 static int 7816 test_zuc256_hash_verify_4b_tag_test_case_2(void) 7817 { 7818 return test_zuc_authentication(&zuc256_test_case_auth_2, 7819 RTE_CRYPTO_AUTH_OP_VERIFY); 7820 } 7821 7822 static int 7823 test_zuc256_hash_verify_4b_tag_test_case_3(void) 7824 { 7825 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b, 7826 RTE_CRYPTO_AUTH_OP_VERIFY); 7827 } 7828 7829 static int 7830 test_zuc256_hash_verify_8b_tag_test_case_1(void) 7831 { 7832 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b, 7833 RTE_CRYPTO_AUTH_OP_VERIFY); 7834 } 7835 7836 static int 7837 test_zuc256_hash_verify_16b_tag_test_case_1(void) 7838 { 7839 return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b, 7840 RTE_CRYPTO_AUTH_OP_VERIFY); 7841 } 7842 7843 static int 7844 test_zuc256_cipher_auth_4b_tag_test_case_1(void) 7845 { 7846 return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_1); 7847 } 7848 7849 static int 7850 test_zuc256_cipher_auth_4b_tag_test_case_2(void) 7851 { 7852 return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_2); 7853 } 7854 7855 static int 7856 test_zuc256_cipher_auth_8b_tag_test_case_1(void) 7857 { 7858 return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_3); 7859 } 7860 7861 static int 7862 test_zuc256_cipher_auth_16b_tag_test_case_1(void) 7863 { 7864 return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_4); 7865 } 7866 7867 static int 7868 test_zuc256_auth_cipher_4b_tag_test_case_1(void) 7869 { 7870 return test_zuc_auth_cipher( 7871 &zuc256_auth_cipher_test_case_1, IN_PLACE, 0); 7872 } 7873 7874 static int 7875 test_zuc256_auth_cipher_4b_tag_test_case_2(void) 7876 { 7877 return test_zuc_auth_cipher( 7878 &zuc256_auth_cipher_test_case_2, IN_PLACE, 0); 7879 } 7880 7881 static int 7882 test_zuc256_auth_cipher_8b_tag_test_case_1(void) 7883 { 7884 return test_zuc_auth_cipher( 7885 &zuc256_auth_cipher_test_case_3, IN_PLACE, 0); 7886 } 7887 7888 static int 7889 test_zuc256_auth_cipher_16b_tag_test_case_1(void) 7890 { 7891 return test_zuc_auth_cipher( 7892 &zuc256_auth_cipher_test_case_4, IN_PLACE, 0); 7893 } 7894 7895 static int 7896 test_zuc256_auth_cipher_verify_4b_tag_test_case_1(void) 7897 { 7898 return test_zuc_auth_cipher( 7899 &zuc256_auth_cipher_test_case_1, IN_PLACE, 1); 7900 } 7901 7902 static int 7903 test_zuc256_auth_cipher_verify_4b_tag_test_case_2(void) 7904 { 7905 return test_zuc_auth_cipher( 7906 &zuc256_auth_cipher_test_case_2, IN_PLACE, 1); 7907 } 7908 7909 static int 7910 test_zuc256_auth_cipher_verify_8b_tag_test_case_1(void) 7911 { 7912 return test_zuc_auth_cipher( 7913 &zuc256_auth_cipher_test_case_3, IN_PLACE, 1); 7914 } 7915 7916 static int 7917 test_zuc256_auth_cipher_verify_16b_tag_test_case_1(void) 7918 { 7919 return test_zuc_auth_cipher( 7920 &zuc256_auth_cipher_test_case_4, IN_PLACE, 1); 7921 } 7922 7923 static int 7924 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata) 7925 { 7926 uint8_t dev_id = testsuite_params.valid_devs[0]; 7927 7928 struct rte_cryptodev_sym_capability_idx cap_idx; 7929 7930 /* Check if device supports particular cipher algorithm */ 7931 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 7932 cap_idx.algo.cipher = tdata->cipher_algo; 7933 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 7934 return TEST_SKIPPED; 7935 7936 /* Check if device supports particular hash algorithm */ 7937 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 7938 cap_idx.algo.auth = tdata->auth_algo; 7939 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 7940 return TEST_SKIPPED; 7941 7942 return 0; 7943 } 7944 7945 static int 7946 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata, 7947 uint8_t op_mode, uint8_t verify) 7948 { 7949 struct crypto_testsuite_params *ts_params = &testsuite_params; 7950 struct crypto_unittest_params *ut_params = &unittest_params; 7951 7952 int retval; 7953 7954 uint8_t *plaintext = NULL, *ciphertext = NULL; 7955 unsigned int plaintext_pad_len; 7956 unsigned int plaintext_len; 7957 unsigned int ciphertext_pad_len; 7958 unsigned int ciphertext_len; 7959 unsigned int digest_offset; 7960 7961 struct rte_cryptodev_info dev_info; 7962 struct rte_crypto_op *op; 7963 7964 /* Check if device supports particular algorithms separately */ 7965 if (test_mixed_check_if_unsupported(tdata)) 7966 return TEST_SKIPPED; 7967 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7968 return TEST_SKIPPED; 7969 7970 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 7971 return TEST_SKIPPED; 7972 7973 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7974 7975 uint64_t feat_flags = dev_info.feature_flags; 7976 7977 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7978 printf("Device doesn't support digest encrypted.\n"); 7979 return TEST_SKIPPED; 7980 } 7981 7982 /* Create the session */ 7983 if (verify) 7984 retval = create_wireless_algo_cipher_auth_session( 7985 ts_params->valid_devs[0], 7986 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7987 RTE_CRYPTO_AUTH_OP_VERIFY, 7988 tdata->auth_algo, 7989 tdata->cipher_algo, 7990 tdata->auth_key.data, tdata->auth_key.len, 7991 tdata->cipher_key.data, tdata->cipher_key.len, 7992 tdata->auth_iv.len, tdata->digest_enc.len, 7993 tdata->cipher_iv.len); 7994 else 7995 retval = create_wireless_algo_auth_cipher_session( 7996 ts_params->valid_devs[0], 7997 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7998 RTE_CRYPTO_AUTH_OP_GENERATE, 7999 tdata->auth_algo, 8000 tdata->cipher_algo, 8001 tdata->auth_key.data, tdata->auth_key.len, 8002 tdata->cipher_key.data, tdata->cipher_key.len, 8003 tdata->auth_iv.len, tdata->digest_enc.len, 8004 tdata->cipher_iv.len); 8005 if (retval != 0) 8006 return retval; 8007 8008 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8009 if (op_mode == OUT_OF_PLACE) 8010 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8011 8012 /* clear mbuf payload */ 8013 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8014 rte_pktmbuf_tailroom(ut_params->ibuf)); 8015 if (op_mode == OUT_OF_PLACE) { 8016 8017 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 8018 rte_pktmbuf_tailroom(ut_params->obuf)); 8019 } 8020 8021 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 8022 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 8023 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 8024 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 8025 8026 if (verify) { 8027 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8028 ciphertext_pad_len); 8029 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 8030 debug_hexdump(stdout, "ciphertext:", ciphertext, 8031 ciphertext_len); 8032 } else { 8033 /* make sure enough space to cover partial digest verify case */ 8034 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8035 ciphertext_pad_len); 8036 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 8037 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 8038 } 8039 8040 if (op_mode == OUT_OF_PLACE) 8041 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 8042 8043 /* Create the operation */ 8044 retval = create_wireless_algo_auth_cipher_operation( 8045 tdata->digest_enc.data, tdata->digest_enc.len, 8046 tdata->cipher_iv.data, tdata->cipher_iv.len, 8047 tdata->auth_iv.data, tdata->auth_iv.len, 8048 (tdata->digest_enc.offset == 0 ? 8049 plaintext_pad_len 8050 : tdata->digest_enc.offset), 8051 tdata->validCipherLen.len_bits, 8052 tdata->cipher.offset_bits, 8053 tdata->validAuthLen.len_bits, 8054 tdata->auth.offset_bits, 8055 op_mode, 0, verify); 8056 8057 if (retval < 0) 8058 return retval; 8059 8060 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 8061 8062 /* Check if the op failed because the device doesn't */ 8063 /* support this particular combination of algorithms */ 8064 if (op == NULL && ut_params->op->status == 8065 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 8066 printf("Device doesn't support this mixed combination. " 8067 "Test Skipped.\n"); 8068 return TEST_SKIPPED; 8069 } 8070 ut_params->op = op; 8071 8072 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 8073 8074 ut_params->obuf = (op_mode == IN_PLACE ? 8075 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 8076 8077 if (verify) { 8078 if (ut_params->obuf) 8079 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 8080 uint8_t *); 8081 else 8082 plaintext = ciphertext + 8083 (tdata->cipher.offset_bits >> 3); 8084 8085 debug_hexdump(stdout, "plaintext:", plaintext, 8086 tdata->plaintext.len_bits >> 3); 8087 debug_hexdump(stdout, "plaintext expected:", 8088 tdata->plaintext.data, 8089 tdata->plaintext.len_bits >> 3); 8090 } else { 8091 if (ut_params->obuf) 8092 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 8093 uint8_t *); 8094 else 8095 ciphertext = plaintext; 8096 8097 debug_hexdump(stdout, "ciphertext:", ciphertext, 8098 ciphertext_len); 8099 debug_hexdump(stdout, "ciphertext expected:", 8100 tdata->ciphertext.data, 8101 tdata->ciphertext.len_bits >> 3); 8102 8103 if (tdata->digest_enc.offset == 0) 8104 digest_offset = plaintext_pad_len; 8105 else 8106 digest_offset = tdata->digest_enc.offset; 8107 8108 ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf, 8109 uint8_t *, digest_offset); 8110 8111 debug_hexdump(stdout, "digest:", ut_params->digest, 8112 tdata->digest_enc.len); 8113 debug_hexdump(stdout, "digest expected:", 8114 tdata->digest_enc.data, 8115 tdata->digest_enc.len); 8116 } 8117 8118 if (!verify) { 8119 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8120 ut_params->digest, 8121 tdata->digest_enc.data, 8122 tdata->digest_enc.len, 8123 "Generated auth tag not as expected"); 8124 } 8125 8126 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 8127 if (verify) { 8128 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 8129 plaintext, 8130 tdata->plaintext.data, 8131 tdata->plaintext.len_bits >> 3, 8132 "Plaintext data not as expected"); 8133 } else { 8134 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 8135 ciphertext, 8136 tdata->ciphertext.data, 8137 tdata->validDataLen.len_bits, 8138 "Ciphertext data not as expected"); 8139 } 8140 } 8141 8142 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8143 "crypto op processing failed"); 8144 8145 return 0; 8146 } 8147 8148 static int 8149 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata, 8150 uint8_t op_mode, uint8_t verify) 8151 { 8152 struct crypto_testsuite_params *ts_params = &testsuite_params; 8153 struct crypto_unittest_params *ut_params = &unittest_params; 8154 8155 int retval; 8156 8157 const uint8_t *plaintext = NULL; 8158 const uint8_t *ciphertext = NULL; 8159 const uint8_t *digest = NULL; 8160 unsigned int plaintext_pad_len; 8161 unsigned int plaintext_len; 8162 unsigned int ciphertext_pad_len; 8163 unsigned int ciphertext_len; 8164 uint8_t buffer[10000]; 8165 uint8_t digest_buffer[10000]; 8166 8167 struct rte_cryptodev_info dev_info; 8168 struct rte_crypto_op *op; 8169 8170 /* Check if device supports particular algorithms */ 8171 if (test_mixed_check_if_unsupported(tdata)) 8172 return TEST_SKIPPED; 8173 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 8174 return TEST_SKIPPED; 8175 8176 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8177 8178 uint64_t feat_flags = dev_info.feature_flags; 8179 8180 if (op_mode == IN_PLACE) { 8181 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 8182 printf("Device doesn't support in-place scatter-gather " 8183 "in both input and output mbufs.\n"); 8184 return TEST_SKIPPED; 8185 } 8186 } else { 8187 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 8188 printf("Device doesn't support out-of-place scatter-gather " 8189 "in both input and output mbufs.\n"); 8190 return TEST_SKIPPED; 8191 } 8192 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 8193 printf("Device doesn't support digest encrypted.\n"); 8194 return TEST_SKIPPED; 8195 } 8196 } 8197 8198 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 8199 return TEST_SKIPPED; 8200 8201 /* Create the session */ 8202 if (verify) 8203 retval = create_wireless_algo_cipher_auth_session( 8204 ts_params->valid_devs[0], 8205 RTE_CRYPTO_CIPHER_OP_DECRYPT, 8206 RTE_CRYPTO_AUTH_OP_VERIFY, 8207 tdata->auth_algo, 8208 tdata->cipher_algo, 8209 tdata->auth_key.data, tdata->auth_key.len, 8210 tdata->cipher_key.data, tdata->cipher_key.len, 8211 tdata->auth_iv.len, tdata->digest_enc.len, 8212 tdata->cipher_iv.len); 8213 else 8214 retval = create_wireless_algo_auth_cipher_session( 8215 ts_params->valid_devs[0], 8216 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8217 RTE_CRYPTO_AUTH_OP_GENERATE, 8218 tdata->auth_algo, 8219 tdata->cipher_algo, 8220 tdata->auth_key.data, tdata->auth_key.len, 8221 tdata->cipher_key.data, tdata->cipher_key.len, 8222 tdata->auth_iv.len, tdata->digest_enc.len, 8223 tdata->cipher_iv.len); 8224 if (retval != 0) 8225 return retval; 8226 8227 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 8228 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 8229 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 8230 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 8231 8232 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 8233 ciphertext_pad_len, 15, 0); 8234 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 8235 "Failed to allocate input buffer in mempool"); 8236 8237 if (op_mode == OUT_OF_PLACE) { 8238 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 8239 plaintext_pad_len, 15, 0); 8240 TEST_ASSERT_NOT_NULL(ut_params->obuf, 8241 "Failed to allocate output buffer in mempool"); 8242 } 8243 8244 if (verify) { 8245 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 8246 tdata->ciphertext.data); 8247 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 8248 ciphertext_len, buffer); 8249 debug_hexdump(stdout, "ciphertext:", ciphertext, 8250 ciphertext_len); 8251 } else { 8252 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 8253 tdata->plaintext.data); 8254 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 8255 plaintext_len, buffer); 8256 debug_hexdump(stdout, "plaintext:", plaintext, 8257 plaintext_len); 8258 } 8259 memset(buffer, 0, sizeof(buffer)); 8260 8261 /* Create the operation */ 8262 retval = create_wireless_algo_auth_cipher_operation( 8263 tdata->digest_enc.data, tdata->digest_enc.len, 8264 tdata->cipher_iv.data, tdata->cipher_iv.len, 8265 tdata->auth_iv.data, tdata->auth_iv.len, 8266 (tdata->digest_enc.offset == 0 ? 8267 plaintext_pad_len 8268 : tdata->digest_enc.offset), 8269 tdata->validCipherLen.len_bits, 8270 tdata->cipher.offset_bits, 8271 tdata->validAuthLen.len_bits, 8272 tdata->auth.offset_bits, 8273 op_mode, 1, verify); 8274 8275 if (retval < 0) 8276 return retval; 8277 8278 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 8279 8280 /* Check if the op failed because the device doesn't */ 8281 /* support this particular combination of algorithms */ 8282 if (op == NULL && ut_params->op->status == 8283 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 8284 printf("Device doesn't support this mixed combination. " 8285 "Test Skipped.\n"); 8286 return TEST_SKIPPED; 8287 } 8288 ut_params->op = op; 8289 8290 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 8291 8292 ut_params->obuf = (op_mode == IN_PLACE ? 8293 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 8294 8295 if (verify) { 8296 if (ut_params->obuf) 8297 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 8298 plaintext_len, buffer); 8299 else 8300 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 8301 plaintext_len, buffer); 8302 8303 debug_hexdump(stdout, "plaintext:", plaintext, 8304 (tdata->plaintext.len_bits >> 3) - 8305 tdata->digest_enc.len); 8306 debug_hexdump(stdout, "plaintext expected:", 8307 tdata->plaintext.data, 8308 (tdata->plaintext.len_bits >> 3) - 8309 tdata->digest_enc.len); 8310 } else { 8311 if (ut_params->obuf) 8312 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 8313 ciphertext_len, buffer); 8314 else 8315 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 8316 ciphertext_len, buffer); 8317 8318 debug_hexdump(stdout, "ciphertext:", ciphertext, 8319 ciphertext_len); 8320 debug_hexdump(stdout, "ciphertext expected:", 8321 tdata->ciphertext.data, 8322 tdata->ciphertext.len_bits >> 3); 8323 8324 if (ut_params->obuf) 8325 digest = rte_pktmbuf_read(ut_params->obuf, 8326 (tdata->digest_enc.offset == 0 ? 8327 plaintext_pad_len : 8328 tdata->digest_enc.offset), 8329 tdata->digest_enc.len, digest_buffer); 8330 else 8331 digest = rte_pktmbuf_read(ut_params->ibuf, 8332 (tdata->digest_enc.offset == 0 ? 8333 plaintext_pad_len : 8334 tdata->digest_enc.offset), 8335 tdata->digest_enc.len, digest_buffer); 8336 8337 debug_hexdump(stdout, "digest:", digest, 8338 tdata->digest_enc.len); 8339 debug_hexdump(stdout, "digest expected:", 8340 tdata->digest_enc.data, tdata->digest_enc.len); 8341 } 8342 8343 if (!verify) { 8344 TEST_ASSERT_BUFFERS_ARE_EQUAL( 8345 digest, 8346 tdata->digest_enc.data, 8347 tdata->digest_enc.len, 8348 "Generated auth tag not as expected"); 8349 } 8350 8351 if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 8352 if (verify) { 8353 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 8354 plaintext, 8355 tdata->plaintext.data, 8356 tdata->plaintext.len_bits >> 3, 8357 "Plaintext data not as expected"); 8358 } else { 8359 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 8360 ciphertext, 8361 tdata->ciphertext.data, 8362 tdata->validDataLen.len_bits, 8363 "Ciphertext data not as expected"); 8364 } 8365 } 8366 8367 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 8368 "crypto op processing failed"); 8369 8370 return 0; 8371 } 8372 8373 /** AUTH AES CMAC + CIPHER AES CTR */ 8374 8375 static int 8376 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 8377 { 8378 return test_mixed_auth_cipher( 8379 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8380 } 8381 8382 static int 8383 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 8384 { 8385 return test_mixed_auth_cipher( 8386 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8387 } 8388 8389 static int 8390 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 8391 { 8392 return test_mixed_auth_cipher_sgl( 8393 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8394 } 8395 8396 static int 8397 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 8398 { 8399 return test_mixed_auth_cipher_sgl( 8400 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8401 } 8402 8403 static int 8404 test_aes_cmac_aes_ctr_digest_enc_test_case_2(void) 8405 { 8406 return test_mixed_auth_cipher( 8407 &auth_aes_cmac_cipher_aes_ctr_test_case_2, IN_PLACE, 0); 8408 } 8409 8410 static int 8411 test_aes_cmac_aes_ctr_digest_enc_test_case_2_oop(void) 8412 { 8413 return test_mixed_auth_cipher( 8414 &auth_aes_cmac_cipher_aes_ctr_test_case_2, OUT_OF_PLACE, 0); 8415 } 8416 8417 static int 8418 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 8419 { 8420 return test_mixed_auth_cipher( 8421 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8422 } 8423 8424 static int 8425 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2(void) 8426 { 8427 return test_mixed_auth_cipher( 8428 &auth_aes_cmac_cipher_aes_ctr_test_case_2, IN_PLACE, 1); 8429 } 8430 8431 static int 8432 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 8433 { 8434 return test_mixed_auth_cipher( 8435 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8436 } 8437 8438 static int 8439 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 8440 { 8441 return test_mixed_auth_cipher_sgl( 8442 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8443 } 8444 8445 static int 8446 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 8447 { 8448 return test_mixed_auth_cipher_sgl( 8449 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8450 } 8451 8452 static int 8453 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2_oop(void) 8454 { 8455 return test_mixed_auth_cipher( 8456 &auth_aes_cmac_cipher_aes_ctr_test_case_2, OUT_OF_PLACE, 1); 8457 } 8458 8459 /** MIXED AUTH + CIPHER */ 8460 8461 static int 8462 test_auth_zuc_cipher_snow_test_case_1(void) 8463 { 8464 return test_mixed_auth_cipher( 8465 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 8466 } 8467 8468 static int 8469 test_verify_auth_zuc_cipher_snow_test_case_1(void) 8470 { 8471 return test_mixed_auth_cipher( 8472 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 8473 } 8474 8475 static int 8476 test_auth_zuc_cipher_snow_test_case_1_inplace(void) 8477 { 8478 return test_mixed_auth_cipher( 8479 &auth_zuc_cipher_snow_test_case_1, IN_PLACE, 0); 8480 } 8481 8482 static int 8483 test_verify_auth_zuc_cipher_snow_test_case_1_inplace(void) 8484 { 8485 return test_mixed_auth_cipher( 8486 &auth_zuc_cipher_snow_test_case_1, IN_PLACE, 1); 8487 } 8488 8489 8490 static int 8491 test_auth_aes_cmac_cipher_snow_test_case_1(void) 8492 { 8493 return test_mixed_auth_cipher( 8494 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 8495 } 8496 8497 static int 8498 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void) 8499 { 8500 return test_mixed_auth_cipher( 8501 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 8502 } 8503 8504 static int 8505 test_auth_aes_cmac_cipher_snow_test_case_1_inplace(void) 8506 { 8507 return test_mixed_auth_cipher( 8508 &auth_aes_cmac_cipher_snow_test_case_1, IN_PLACE, 0); 8509 } 8510 8511 static int 8512 test_verify_auth_aes_cmac_cipher_snow_test_case_1_inplace(void) 8513 { 8514 return test_mixed_auth_cipher( 8515 &auth_aes_cmac_cipher_snow_test_case_1, IN_PLACE, 1); 8516 } 8517 8518 static int 8519 test_auth_zuc_cipher_aes_ctr_test_case_1(void) 8520 { 8521 return test_mixed_auth_cipher( 8522 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8523 } 8524 8525 static int 8526 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void) 8527 { 8528 return test_mixed_auth_cipher( 8529 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8530 } 8531 8532 static int 8533 test_auth_zuc_cipher_aes_ctr_test_case_1_inplace(void) 8534 { 8535 return test_mixed_auth_cipher( 8536 &auth_zuc_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8537 } 8538 8539 static int 8540 test_verify_auth_zuc_cipher_aes_ctr_test_case_1_inplace(void) 8541 { 8542 return test_mixed_auth_cipher( 8543 &auth_zuc_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8544 } 8545 8546 static int 8547 test_auth_snow_cipher_aes_ctr_test_case_1(void) 8548 { 8549 return test_mixed_auth_cipher( 8550 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8551 } 8552 8553 static int 8554 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void) 8555 { 8556 return test_mixed_auth_cipher( 8557 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8558 } 8559 8560 static int 8561 test_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl(void) 8562 { 8563 return test_mixed_auth_cipher_sgl( 8564 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8565 } 8566 8567 static int 8568 test_auth_snow_cipher_aes_ctr_test_case_1_inplace(void) 8569 { 8570 return test_mixed_auth_cipher( 8571 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 8572 } 8573 8574 static int 8575 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl(void) 8576 { 8577 return test_mixed_auth_cipher_sgl( 8578 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8579 } 8580 8581 static int 8582 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace(void) 8583 { 8584 return test_mixed_auth_cipher( 8585 &auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 8586 } 8587 8588 static int 8589 test_auth_snow_cipher_zuc_test_case_1(void) 8590 { 8591 return test_mixed_auth_cipher( 8592 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 8593 } 8594 8595 static int 8596 test_verify_auth_snow_cipher_zuc_test_case_1(void) 8597 { 8598 return test_mixed_auth_cipher( 8599 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 8600 } 8601 8602 static int 8603 test_auth_snow_cipher_zuc_test_case_1_inplace(void) 8604 { 8605 return test_mixed_auth_cipher( 8606 &auth_snow_cipher_zuc_test_case_1, IN_PLACE, 0); 8607 } 8608 8609 static int 8610 test_verify_auth_snow_cipher_zuc_test_case_1_inplace(void) 8611 { 8612 return test_mixed_auth_cipher( 8613 &auth_snow_cipher_zuc_test_case_1, IN_PLACE, 1); 8614 } 8615 8616 static int 8617 test_auth_aes_cmac_cipher_zuc_test_case_1(void) 8618 { 8619 return test_mixed_auth_cipher( 8620 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 8621 } 8622 8623 static int 8624 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void) 8625 { 8626 return test_mixed_auth_cipher( 8627 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 8628 } 8629 static int 8630 test_auth_aes_cmac_cipher_zuc_test_case_1_inplace(void) 8631 { 8632 return test_mixed_auth_cipher( 8633 &auth_aes_cmac_cipher_zuc_test_case_1, IN_PLACE, 0); 8634 } 8635 8636 static int 8637 test_verify_auth_aes_cmac_cipher_zuc_test_case_1_inplace(void) 8638 { 8639 return test_mixed_auth_cipher( 8640 &auth_aes_cmac_cipher_zuc_test_case_1, IN_PLACE, 1); 8641 } 8642 8643 static int 8644 test_auth_null_cipher_snow_test_case_1(void) 8645 { 8646 return test_mixed_auth_cipher( 8647 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 8648 } 8649 8650 static int 8651 test_verify_auth_null_cipher_snow_test_case_1(void) 8652 { 8653 return test_mixed_auth_cipher( 8654 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 8655 } 8656 8657 static int 8658 test_auth_null_cipher_zuc_test_case_1(void) 8659 { 8660 return test_mixed_auth_cipher( 8661 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 8662 } 8663 8664 static int 8665 test_verify_auth_null_cipher_zuc_test_case_1(void) 8666 { 8667 return test_mixed_auth_cipher( 8668 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 8669 } 8670 8671 static int 8672 test_auth_snow_cipher_null_test_case_1(void) 8673 { 8674 return test_mixed_auth_cipher( 8675 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0); 8676 } 8677 8678 static int 8679 test_verify_auth_snow_cipher_null_test_case_1(void) 8680 { 8681 return test_mixed_auth_cipher( 8682 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1); 8683 } 8684 8685 static int 8686 test_auth_zuc_cipher_null_test_case_1(void) 8687 { 8688 return test_mixed_auth_cipher( 8689 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0); 8690 } 8691 8692 static int 8693 test_verify_auth_zuc_cipher_null_test_case_1(void) 8694 { 8695 return test_mixed_auth_cipher( 8696 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1); 8697 } 8698 8699 static int 8700 test_auth_null_cipher_aes_ctr_test_case_1(void) 8701 { 8702 return test_mixed_auth_cipher( 8703 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 8704 } 8705 8706 static int 8707 test_verify_auth_null_cipher_aes_ctr_test_case_1(void) 8708 { 8709 return test_mixed_auth_cipher( 8710 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 8711 } 8712 8713 static int 8714 test_auth_aes_cmac_cipher_null_test_case_1(void) 8715 { 8716 return test_mixed_auth_cipher( 8717 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0); 8718 } 8719 8720 static int 8721 test_verify_auth_aes_cmac_cipher_null_test_case_1(void) 8722 { 8723 return test_mixed_auth_cipher( 8724 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1); 8725 } 8726 8727 /* ***** AEAD algorithm Tests ***** */ 8728 8729 static int 8730 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo, 8731 enum rte_crypto_aead_operation op, 8732 const uint8_t *key, const uint8_t key_len, 8733 const uint16_t aad_len, const uint8_t auth_len, 8734 uint8_t iv_len) 8735 { 8736 uint8_t aead_key[key_len]; 8737 8738 struct crypto_testsuite_params *ts_params = &testsuite_params; 8739 struct crypto_unittest_params *ut_params = &unittest_params; 8740 8741 memcpy(aead_key, key, key_len); 8742 8743 /* Setup AEAD Parameters */ 8744 ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 8745 ut_params->aead_xform.next = NULL; 8746 ut_params->aead_xform.aead.algo = algo; 8747 ut_params->aead_xform.aead.op = op; 8748 ut_params->aead_xform.aead.key.data = aead_key; 8749 ut_params->aead_xform.aead.key.length = key_len; 8750 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 8751 ut_params->aead_xform.aead.iv.length = iv_len; 8752 ut_params->aead_xform.aead.digest_length = auth_len; 8753 ut_params->aead_xform.aead.aad_length = aad_len; 8754 8755 debug_hexdump(stdout, "key:", key, key_len); 8756 8757 /* Create Crypto session*/ 8758 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 8759 &ut_params->aead_xform, ts_params->session_mpool); 8760 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 8761 return TEST_SKIPPED; 8762 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 8763 return 0; 8764 } 8765 8766 static int 8767 create_aead_xform(struct rte_crypto_op *op, 8768 enum rte_crypto_aead_algorithm algo, 8769 enum rte_crypto_aead_operation aead_op, 8770 uint8_t *key, const uint8_t key_len, 8771 const uint8_t aad_len, const uint8_t auth_len, 8772 uint8_t iv_len) 8773 { 8774 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1), 8775 "failed to allocate space for crypto transform"); 8776 8777 struct rte_crypto_sym_op *sym_op = op->sym; 8778 8779 /* Setup AEAD Parameters */ 8780 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD; 8781 sym_op->xform->next = NULL; 8782 sym_op->xform->aead.algo = algo; 8783 sym_op->xform->aead.op = aead_op; 8784 sym_op->xform->aead.key.data = key; 8785 sym_op->xform->aead.key.length = key_len; 8786 sym_op->xform->aead.iv.offset = IV_OFFSET; 8787 sym_op->xform->aead.iv.length = iv_len; 8788 sym_op->xform->aead.digest_length = auth_len; 8789 sym_op->xform->aead.aad_length = aad_len; 8790 8791 debug_hexdump(stdout, "key:", key, key_len); 8792 8793 return 0; 8794 } 8795 8796 static int 8797 create_aead_operation(enum rte_crypto_aead_operation op, 8798 const struct aead_test_data *tdata) 8799 { 8800 struct crypto_testsuite_params *ts_params = &testsuite_params; 8801 struct crypto_unittest_params *ut_params = &unittest_params; 8802 8803 uint8_t *plaintext, *ciphertext; 8804 unsigned int aad_pad_len, plaintext_pad_len; 8805 8806 /* Generate Crypto op data structure */ 8807 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8808 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8809 TEST_ASSERT_NOT_NULL(ut_params->op, 8810 "Failed to allocate symmetric crypto operation struct"); 8811 8812 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 8813 8814 /* Append aad data */ 8815 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 8816 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16); 8817 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8818 aad_pad_len); 8819 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8820 "no room to append aad"); 8821 8822 sym_op->aead.aad.phys_addr = 8823 rte_pktmbuf_iova(ut_params->ibuf); 8824 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 8825 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len); 8826 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data + 18, 8827 tdata->aad.len); 8828 8829 /* Append IV at the end of the crypto operation*/ 8830 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8831 uint8_t *, IV_OFFSET); 8832 8833 /* Copy IV 1 byte after the IV pointer, according to the API */ 8834 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len); 8835 debug_hexdump(stdout, "iv:", iv_ptr + 1, 8836 tdata->iv.len); 8837 } else { 8838 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 8839 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8840 aad_pad_len); 8841 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 8842 "no room to append aad"); 8843 8844 sym_op->aead.aad.phys_addr = 8845 rte_pktmbuf_iova(ut_params->ibuf); 8846 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len); 8847 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 8848 tdata->aad.len); 8849 8850 /* Append IV at the end of the crypto operation*/ 8851 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 8852 uint8_t *, IV_OFFSET); 8853 8854 if (tdata->iv.len == 0) { 8855 rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH); 8856 debug_hexdump(stdout, "iv:", iv_ptr, 8857 AES_GCM_J0_LENGTH); 8858 } else { 8859 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 8860 debug_hexdump(stdout, "iv:", iv_ptr, 8861 tdata->iv.len); 8862 } 8863 } 8864 8865 /* Append plaintext/ciphertext */ 8866 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 8867 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 8868 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8869 plaintext_pad_len); 8870 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 8871 8872 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 8873 debug_hexdump(stdout, "plaintext:", plaintext, 8874 tdata->plaintext.len); 8875 8876 if (ut_params->obuf) { 8877 ciphertext = (uint8_t *)rte_pktmbuf_append( 8878 ut_params->obuf, 8879 plaintext_pad_len + aad_pad_len); 8880 TEST_ASSERT_NOT_NULL(ciphertext, 8881 "no room to append ciphertext"); 8882 8883 memset(ciphertext + aad_pad_len, 0, 8884 tdata->ciphertext.len); 8885 } 8886 } else { 8887 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); 8888 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8889 plaintext_pad_len); 8890 TEST_ASSERT_NOT_NULL(ciphertext, 8891 "no room to append ciphertext"); 8892 8893 memcpy(ciphertext, tdata->ciphertext.data, 8894 tdata->ciphertext.len); 8895 debug_hexdump(stdout, "ciphertext:", ciphertext, 8896 tdata->ciphertext.len); 8897 8898 if (ut_params->obuf) { 8899 plaintext = (uint8_t *)rte_pktmbuf_append( 8900 ut_params->obuf, 8901 plaintext_pad_len + aad_pad_len); 8902 TEST_ASSERT_NOT_NULL(plaintext, 8903 "no room to append plaintext"); 8904 8905 memset(plaintext + aad_pad_len, 0, 8906 tdata->plaintext.len); 8907 } 8908 } 8909 8910 /* Append digest data */ 8911 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 8912 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 8913 ut_params->obuf ? ut_params->obuf : 8914 ut_params->ibuf, 8915 tdata->auth_tag.len); 8916 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 8917 "no room to append digest"); 8918 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len); 8919 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 8920 ut_params->obuf ? ut_params->obuf : 8921 ut_params->ibuf, 8922 plaintext_pad_len + 8923 aad_pad_len); 8924 } else { 8925 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 8926 ut_params->ibuf, tdata->auth_tag.len); 8927 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 8928 "no room to append digest"); 8929 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 8930 ut_params->ibuf, 8931 plaintext_pad_len + aad_pad_len); 8932 8933 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 8934 tdata->auth_tag.len); 8935 debug_hexdump(stdout, "digest:", 8936 sym_op->aead.digest.data, 8937 tdata->auth_tag.len); 8938 } 8939 8940 sym_op->aead.data.length = tdata->plaintext.len; 8941 sym_op->aead.data.offset = aad_pad_len; 8942 8943 return 0; 8944 } 8945 8946 static int 8947 test_authenticated_encryption(const struct aead_test_data *tdata) 8948 { 8949 struct crypto_testsuite_params *ts_params = &testsuite_params; 8950 struct crypto_unittest_params *ut_params = &unittest_params; 8951 8952 int retval; 8953 uint8_t *ciphertext, *auth_tag; 8954 uint16_t plaintext_pad_len; 8955 uint32_t i; 8956 struct rte_cryptodev_info dev_info; 8957 8958 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8959 uint64_t feat_flags = dev_info.feature_flags; 8960 8961 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 8962 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 8963 printf("Device doesn't support RAW data-path APIs.\n"); 8964 return TEST_SKIPPED; 8965 } 8966 8967 /* Verify the capabilities */ 8968 struct rte_cryptodev_sym_capability_idx cap_idx; 8969 const struct rte_cryptodev_symmetric_capability *capability; 8970 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 8971 cap_idx.algo.aead = tdata->algo; 8972 capability = rte_cryptodev_sym_capability_get( 8973 ts_params->valid_devs[0], &cap_idx); 8974 if (capability == NULL) 8975 return TEST_SKIPPED; 8976 if (rte_cryptodev_sym_capability_check_aead( 8977 capability, tdata->key.len, tdata->auth_tag.len, 8978 tdata->aad.len, tdata->iv.len)) 8979 return TEST_SKIPPED; 8980 8981 /* Create AEAD session */ 8982 retval = create_aead_session(ts_params->valid_devs[0], 8983 tdata->algo, 8984 RTE_CRYPTO_AEAD_OP_ENCRYPT, 8985 tdata->key.data, tdata->key.len, 8986 tdata->aad.len, tdata->auth_tag.len, 8987 tdata->iv.len); 8988 if (retval != TEST_SUCCESS) 8989 return retval; 8990 8991 if (tdata->aad.len > MBUF_SIZE) { 8992 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 8993 /* Populate full size of add data */ 8994 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 8995 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 8996 } else 8997 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8998 8999 /* clear mbuf payload */ 9000 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9001 rte_pktmbuf_tailroom(ut_params->ibuf)); 9002 9003 /* Create AEAD operation */ 9004 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 9005 if (retval < 0) 9006 return retval; 9007 9008 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9009 9010 ut_params->op->sym->m_src = ut_params->ibuf; 9011 9012 /* Process crypto operation */ 9013 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9014 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 9015 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 9016 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 9017 0); 9018 if (retval != TEST_SUCCESS) 9019 return retval; 9020 } else 9021 TEST_ASSERT_NOT_NULL( 9022 process_crypto_request(ts_params->valid_devs[0], 9023 ut_params->op), "failed to process sym crypto op"); 9024 9025 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9026 "crypto op processing failed"); 9027 9028 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 9029 9030 if (ut_params->op->sym->m_dst) { 9031 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 9032 uint8_t *); 9033 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 9034 uint8_t *, plaintext_pad_len); 9035 } else { 9036 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 9037 uint8_t *, 9038 ut_params->op->sym->cipher.data.offset); 9039 auth_tag = ciphertext + plaintext_pad_len; 9040 } 9041 9042 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 9043 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 9044 9045 /* Validate obuf */ 9046 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9047 ciphertext, 9048 tdata->ciphertext.data, 9049 tdata->ciphertext.len, 9050 "Ciphertext data not as expected"); 9051 9052 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9053 auth_tag, 9054 tdata->auth_tag.data, 9055 tdata->auth_tag.len, 9056 "Generated auth tag not as expected"); 9057 9058 return 0; 9059 9060 } 9061 9062 #ifdef RTE_LIB_SECURITY 9063 static int 9064 security_proto_supported(enum rte_security_session_action_type action, 9065 enum rte_security_session_protocol proto) 9066 { 9067 struct crypto_testsuite_params *ts_params = &testsuite_params; 9068 9069 const struct rte_security_capability *capabilities; 9070 const struct rte_security_capability *capability; 9071 uint16_t i = 0; 9072 9073 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 9074 9075 9076 capabilities = rte_security_capabilities_get(ctx); 9077 9078 if (capabilities == NULL) 9079 return -ENOTSUP; 9080 9081 while ((capability = &capabilities[i++])->action != 9082 RTE_SECURITY_ACTION_TYPE_NONE) { 9083 if (capability->action == action && 9084 capability->protocol == proto) 9085 return 0; 9086 } 9087 9088 return -ENOTSUP; 9089 } 9090 9091 /* Basic algorithm run function for async inplace mode. 9092 * Creates a session from input parameters and runs one operation 9093 * on input_vec. Checks the output of the crypto operation against 9094 * output_vec. 9095 */ 9096 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc, 9097 enum rte_crypto_auth_operation opa, 9098 const uint8_t *input_vec, unsigned int input_vec_len, 9099 const uint8_t *output_vec, 9100 unsigned int output_vec_len, 9101 enum rte_crypto_cipher_algorithm cipher_alg, 9102 const uint8_t *cipher_key, uint32_t cipher_key_len, 9103 enum rte_crypto_auth_algorithm auth_alg, 9104 const uint8_t *auth_key, uint32_t auth_key_len, 9105 uint8_t bearer, enum rte_security_pdcp_domain domain, 9106 uint8_t packet_direction, uint8_t sn_size, 9107 uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap) 9108 { 9109 struct crypto_testsuite_params *ts_params = &testsuite_params; 9110 struct crypto_unittest_params *ut_params = &unittest_params; 9111 uint8_t *plaintext; 9112 int ret = TEST_SUCCESS; 9113 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 9114 struct rte_cryptodev_info dev_info; 9115 uint64_t feat_flags; 9116 9117 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9118 feat_flags = dev_info.feature_flags; 9119 9120 /* Verify the capabilities */ 9121 struct rte_security_capability_idx sec_cap_idx; 9122 9123 sec_cap_idx.action = ut_params->type; 9124 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 9125 sec_cap_idx.pdcp.domain = domain; 9126 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 9127 return TEST_SKIPPED; 9128 9129 /* Generate test mbuf data */ 9130 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9131 9132 /* clear mbuf payload */ 9133 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9134 rte_pktmbuf_tailroom(ut_params->ibuf)); 9135 9136 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9137 input_vec_len); 9138 memcpy(plaintext, input_vec, input_vec_len); 9139 9140 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9141 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9142 printf("Device does not support RAW data-path APIs.\n"); 9143 return TEST_SKIPPED; 9144 } 9145 /* Out of place support */ 9146 if (oop) { 9147 /* 9148 * For out-op-place we need to alloc another mbuf 9149 */ 9150 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9151 rte_pktmbuf_append(ut_params->obuf, output_vec_len); 9152 } 9153 9154 /* Setup Cipher Parameters */ 9155 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9156 ut_params->cipher_xform.cipher.algo = cipher_alg; 9157 ut_params->cipher_xform.cipher.op = opc; 9158 ut_params->cipher_xform.cipher.key.data = cipher_key; 9159 ut_params->cipher_xform.cipher.key.length = cipher_key_len; 9160 ut_params->cipher_xform.cipher.iv.length = 9161 packet_direction ? 4 : 0; 9162 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 9163 9164 /* Setup HMAC Parameters if ICV header is required */ 9165 if (auth_alg != 0) { 9166 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9167 ut_params->auth_xform.next = NULL; 9168 ut_params->auth_xform.auth.algo = auth_alg; 9169 ut_params->auth_xform.auth.op = opa; 9170 ut_params->auth_xform.auth.key.data = auth_key; 9171 ut_params->auth_xform.auth.key.length = auth_key_len; 9172 9173 ut_params->cipher_xform.next = &ut_params->auth_xform; 9174 } else { 9175 ut_params->cipher_xform.next = NULL; 9176 } 9177 9178 struct rte_security_session_conf sess_conf = { 9179 .action_type = ut_params->type, 9180 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 9181 {.pdcp = { 9182 .bearer = bearer, 9183 .domain = domain, 9184 .pkt_dir = packet_direction, 9185 .sn_size = sn_size, 9186 .hfn = packet_direction ? 0 : hfn, 9187 /** 9188 * hfn can be set as pdcp_test_hfn[i] 9189 * if hfn_ovrd is not set. Here, PDCP 9190 * packet direction is just used to 9191 * run half of the cases with session 9192 * HFN and other half with per packet 9193 * HFN. 9194 */ 9195 .hfn_threshold = hfn_threshold, 9196 .hfn_ovrd = packet_direction ? 1 : 0, 9197 .sdap_enabled = sdap, 9198 } }, 9199 .crypto_xform = &ut_params->cipher_xform 9200 }; 9201 9202 /* Create security session */ 9203 ut_params->sec_session = rte_security_session_create(ctx, 9204 &sess_conf, ts_params->session_mpool); 9205 9206 if (!ut_params->sec_session) { 9207 printf("TestCase %s()-%d line %d failed %s: ", 9208 __func__, i, __LINE__, "Failed to allocate session"); 9209 ret = TEST_FAILED; 9210 goto on_err; 9211 } 9212 9213 /* Generate crypto op data structure */ 9214 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9215 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9216 if (!ut_params->op) { 9217 printf("TestCase %s()-%d line %d failed %s: ", 9218 __func__, i, __LINE__, 9219 "Failed to allocate symmetric crypto operation struct"); 9220 ret = TEST_FAILED; 9221 goto on_err; 9222 } 9223 9224 uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op, 9225 uint32_t *, IV_OFFSET); 9226 *per_pkt_hfn = packet_direction ? hfn : 0; 9227 9228 rte_security_attach_session(ut_params->op, ut_params->sec_session); 9229 9230 /* set crypto operation source mbuf */ 9231 ut_params->op->sym->m_src = ut_params->ibuf; 9232 if (oop) 9233 ut_params->op->sym->m_dst = ut_params->obuf; 9234 9235 /* Process crypto operation */ 9236 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 9237 /* filling lengths */ 9238 ut_params->op->sym->cipher.data.length = ut_params->op->sym->m_src->pkt_len; 9239 ut_params->op->sym->auth.data.length = ut_params->op->sym->m_src->pkt_len; 9240 9241 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 0); 9242 if (ret != TEST_SUCCESS) 9243 return ret; 9244 } else { 9245 ut_params->op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 9246 } 9247 if (ut_params->op == NULL) { 9248 printf("TestCase %s()-%d line %d failed %s: ", 9249 __func__, i, __LINE__, 9250 "failed to process sym crypto op"); 9251 ret = TEST_FAILED; 9252 goto on_err; 9253 } 9254 9255 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 9256 printf("TestCase %s()-%d line %d failed %s: ", 9257 __func__, i, __LINE__, "crypto op processing failed"); 9258 ret = TEST_FAILED; 9259 goto on_err; 9260 } 9261 9262 /* Validate obuf */ 9263 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 9264 uint8_t *); 9265 if (oop) { 9266 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 9267 uint8_t *); 9268 } 9269 9270 if (memcmp(ciphertext, output_vec, output_vec_len)) { 9271 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 9272 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len); 9273 rte_hexdump(stdout, "reference", output_vec, output_vec_len); 9274 ret = TEST_FAILED; 9275 goto on_err; 9276 } 9277 9278 on_err: 9279 rte_crypto_op_free(ut_params->op); 9280 ut_params->op = NULL; 9281 9282 if (ut_params->sec_session) 9283 rte_security_session_destroy(ctx, ut_params->sec_session); 9284 ut_params->sec_session = NULL; 9285 9286 rte_pktmbuf_free(ut_params->ibuf); 9287 ut_params->ibuf = NULL; 9288 if (oop) { 9289 rte_pktmbuf_free(ut_params->obuf); 9290 ut_params->obuf = NULL; 9291 } 9292 9293 return ret; 9294 } 9295 9296 static int 9297 test_pdcp_proto_SGL(int i, int oop, 9298 enum rte_crypto_cipher_operation opc, 9299 enum rte_crypto_auth_operation opa, 9300 uint8_t *input_vec, 9301 unsigned int input_vec_len, 9302 uint8_t *output_vec, 9303 unsigned int output_vec_len, 9304 uint32_t fragsz, 9305 uint32_t fragsz_oop) 9306 { 9307 struct crypto_testsuite_params *ts_params = &testsuite_params; 9308 struct crypto_unittest_params *ut_params = &unittest_params; 9309 uint8_t *plaintext; 9310 struct rte_mbuf *buf, *buf_oop = NULL; 9311 int ret = TEST_SUCCESS; 9312 int to_trn = 0; 9313 int to_trn_tbl[16]; 9314 int segs = 1; 9315 unsigned int trn_data = 0; 9316 struct rte_cryptodev_info dev_info; 9317 uint64_t feat_flags; 9318 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 9319 struct rte_mbuf *temp_mbuf; 9320 9321 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9322 feat_flags = dev_info.feature_flags; 9323 9324 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9325 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9326 printf("Device does not support RAW data-path APIs.\n"); 9327 return -ENOTSUP; 9328 } 9329 /* Verify the capabilities */ 9330 struct rte_security_capability_idx sec_cap_idx; 9331 9332 sec_cap_idx.action = ut_params->type; 9333 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 9334 sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain; 9335 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 9336 return TEST_SKIPPED; 9337 9338 if (fragsz > input_vec_len) 9339 fragsz = input_vec_len; 9340 9341 uint16_t plaintext_len = fragsz; 9342 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 9343 9344 if (fragsz_oop > output_vec_len) 9345 frag_size_oop = output_vec_len; 9346 9347 int ecx = 0; 9348 if (input_vec_len % fragsz != 0) { 9349 if (input_vec_len / fragsz + 1 > 16) 9350 return 1; 9351 } else if (input_vec_len / fragsz > 16) 9352 return 1; 9353 9354 /* Out of place support */ 9355 if (oop) { 9356 /* 9357 * For out-op-place we need to alloc another mbuf 9358 */ 9359 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9360 rte_pktmbuf_append(ut_params->obuf, frag_size_oop); 9361 buf_oop = ut_params->obuf; 9362 } 9363 9364 /* Generate test mbuf data */ 9365 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9366 9367 /* clear mbuf payload */ 9368 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9369 rte_pktmbuf_tailroom(ut_params->ibuf)); 9370 9371 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 9372 plaintext_len); 9373 memcpy(plaintext, input_vec, plaintext_len); 9374 trn_data += plaintext_len; 9375 9376 buf = ut_params->ibuf; 9377 9378 /* 9379 * Loop until no more fragments 9380 */ 9381 9382 while (trn_data < input_vec_len) { 9383 ++segs; 9384 to_trn = (input_vec_len - trn_data < fragsz) ? 9385 (input_vec_len - trn_data) : fragsz; 9386 9387 to_trn_tbl[ecx++] = to_trn; 9388 9389 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9390 buf = buf->next; 9391 9392 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 9393 rte_pktmbuf_tailroom(buf)); 9394 9395 /* OOP */ 9396 if (oop && !fragsz_oop) { 9397 buf_oop->next = 9398 rte_pktmbuf_alloc(ts_params->mbuf_pool); 9399 buf_oop = buf_oop->next; 9400 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 9401 0, rte_pktmbuf_tailroom(buf_oop)); 9402 rte_pktmbuf_append(buf_oop, to_trn); 9403 } 9404 9405 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 9406 to_trn); 9407 9408 memcpy(plaintext, input_vec + trn_data, to_trn); 9409 trn_data += to_trn; 9410 } 9411 9412 ut_params->ibuf->nb_segs = segs; 9413 9414 segs = 1; 9415 if (fragsz_oop && oop) { 9416 to_trn = 0; 9417 ecx = 0; 9418 9419 trn_data = frag_size_oop; 9420 while (trn_data < output_vec_len) { 9421 ++segs; 9422 to_trn = 9423 (output_vec_len - trn_data < 9424 frag_size_oop) ? 9425 (output_vec_len - trn_data) : 9426 frag_size_oop; 9427 9428 to_trn_tbl[ecx++] = to_trn; 9429 9430 buf_oop->next = 9431 rte_pktmbuf_alloc(ts_params->mbuf_pool); 9432 buf_oop = buf_oop->next; 9433 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 9434 0, rte_pktmbuf_tailroom(buf_oop)); 9435 rte_pktmbuf_append(buf_oop, to_trn); 9436 9437 trn_data += to_trn; 9438 } 9439 ut_params->obuf->nb_segs = segs; 9440 } 9441 9442 /* Setup Cipher Parameters */ 9443 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9444 ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg; 9445 ut_params->cipher_xform.cipher.op = opc; 9446 ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i]; 9447 ut_params->cipher_xform.cipher.key.length = 9448 pdcp_test_params[i].cipher_key_len; 9449 ut_params->cipher_xform.cipher.iv.length = 0; 9450 9451 /* Setup HMAC Parameters if ICV header is required */ 9452 if (pdcp_test_params[i].auth_alg != 0) { 9453 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9454 ut_params->auth_xform.next = NULL; 9455 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg; 9456 ut_params->auth_xform.auth.op = opa; 9457 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i]; 9458 ut_params->auth_xform.auth.key.length = 9459 pdcp_test_params[i].auth_key_len; 9460 9461 ut_params->cipher_xform.next = &ut_params->auth_xform; 9462 } else { 9463 ut_params->cipher_xform.next = NULL; 9464 } 9465 9466 struct rte_security_session_conf sess_conf = { 9467 .action_type = ut_params->type, 9468 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 9469 {.pdcp = { 9470 .bearer = pdcp_test_bearer[i], 9471 .domain = pdcp_test_params[i].domain, 9472 .pkt_dir = pdcp_test_packet_direction[i], 9473 .sn_size = pdcp_test_data_sn_size[i], 9474 .hfn = pdcp_test_hfn[i], 9475 .hfn_threshold = pdcp_test_hfn_threshold[i], 9476 .hfn_ovrd = 0, 9477 } }, 9478 .crypto_xform = &ut_params->cipher_xform 9479 }; 9480 9481 /* Create security session */ 9482 ut_params->sec_session = rte_security_session_create(ctx, 9483 &sess_conf, ts_params->session_mpool); 9484 9485 if (!ut_params->sec_session) { 9486 printf("TestCase %s()-%d line %d failed %s: ", 9487 __func__, i, __LINE__, "Failed to allocate session"); 9488 ret = TEST_FAILED; 9489 goto on_err; 9490 } 9491 9492 /* Generate crypto op data structure */ 9493 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 9494 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 9495 if (!ut_params->op) { 9496 printf("TestCase %s()-%d line %d failed %s: ", 9497 __func__, i, __LINE__, 9498 "Failed to allocate symmetric crypto operation struct"); 9499 ret = TEST_FAILED; 9500 goto on_err; 9501 } 9502 9503 rte_security_attach_session(ut_params->op, ut_params->sec_session); 9504 9505 /* set crypto operation source mbuf */ 9506 ut_params->op->sym->m_src = ut_params->ibuf; 9507 if (oop) 9508 ut_params->op->sym->m_dst = ut_params->obuf; 9509 9510 /* Process crypto operation */ 9511 temp_mbuf = ut_params->op->sym->m_src; 9512 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 9513 /* filling lengths */ 9514 while (temp_mbuf) { 9515 ut_params->op->sym->cipher.data.length 9516 += temp_mbuf->pkt_len; 9517 ut_params->op->sym->auth.data.length 9518 += temp_mbuf->pkt_len; 9519 temp_mbuf = temp_mbuf->next; 9520 } 9521 9522 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 0); 9523 if (ret != TEST_SUCCESS) 9524 return ret; 9525 } else { 9526 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 9527 ut_params->op); 9528 } 9529 if (ut_params->op == NULL) { 9530 printf("TestCase %s()-%d line %d failed %s: ", 9531 __func__, i, __LINE__, 9532 "failed to process sym crypto op"); 9533 ret = TEST_FAILED; 9534 goto on_err; 9535 } 9536 9537 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 9538 printf("TestCase %s()-%d line %d failed %s: ", 9539 __func__, i, __LINE__, "crypto op processing failed"); 9540 ret = TEST_FAILED; 9541 goto on_err; 9542 } 9543 9544 /* Validate obuf */ 9545 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 9546 uint8_t *); 9547 if (oop) { 9548 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 9549 uint8_t *); 9550 } 9551 if (fragsz_oop) 9552 fragsz = frag_size_oop; 9553 if (memcmp(ciphertext, output_vec, fragsz)) { 9554 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 9555 rte_hexdump(stdout, "encrypted", ciphertext, fragsz); 9556 rte_hexdump(stdout, "reference", output_vec, fragsz); 9557 ret = TEST_FAILED; 9558 goto on_err; 9559 } 9560 9561 buf = ut_params->op->sym->m_src->next; 9562 if (oop) 9563 buf = ut_params->op->sym->m_dst->next; 9564 9565 unsigned int off = fragsz; 9566 9567 ecx = 0; 9568 while (buf) { 9569 ciphertext = rte_pktmbuf_mtod(buf, 9570 uint8_t *); 9571 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) { 9572 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 9573 rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]); 9574 rte_hexdump(stdout, "reference", output_vec + off, 9575 to_trn_tbl[ecx]); 9576 ret = TEST_FAILED; 9577 goto on_err; 9578 } 9579 off += to_trn_tbl[ecx++]; 9580 buf = buf->next; 9581 } 9582 on_err: 9583 rte_crypto_op_free(ut_params->op); 9584 ut_params->op = NULL; 9585 9586 if (ut_params->sec_session) 9587 rte_security_session_destroy(ctx, ut_params->sec_session); 9588 ut_params->sec_session = NULL; 9589 9590 rte_pktmbuf_free(ut_params->ibuf); 9591 ut_params->ibuf = NULL; 9592 if (oop) { 9593 rte_pktmbuf_free(ut_params->obuf); 9594 ut_params->obuf = NULL; 9595 } 9596 9597 return ret; 9598 } 9599 9600 int 9601 test_pdcp_proto_cplane_encap(int i) 9602 { 9603 return test_pdcp_proto( 9604 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 9605 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9606 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9607 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9608 pdcp_test_params[i].cipher_key_len, 9609 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9610 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9611 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9612 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9613 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9614 } 9615 9616 int 9617 test_pdcp_proto_uplane_encap(int i) 9618 { 9619 return test_pdcp_proto( 9620 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 9621 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9622 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 9623 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9624 pdcp_test_params[i].cipher_key_len, 9625 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9626 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9627 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9628 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9629 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9630 } 9631 9632 int 9633 test_pdcp_proto_uplane_encap_with_int(int i) 9634 { 9635 return test_pdcp_proto( 9636 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 9637 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9638 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9639 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9640 pdcp_test_params[i].cipher_key_len, 9641 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9642 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9643 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9644 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9645 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9646 } 9647 9648 int 9649 test_pdcp_proto_cplane_decap(int i) 9650 { 9651 return test_pdcp_proto( 9652 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 9653 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9654 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9655 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9656 pdcp_test_params[i].cipher_key_len, 9657 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9658 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9659 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9660 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9661 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9662 } 9663 9664 int 9665 test_pdcp_proto_uplane_decap(int i) 9666 { 9667 return test_pdcp_proto( 9668 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 9669 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 9670 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9671 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9672 pdcp_test_params[i].cipher_key_len, 9673 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9674 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9675 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9676 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9677 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9678 } 9679 9680 int 9681 test_pdcp_proto_uplane_decap_with_int(int i) 9682 { 9683 return test_pdcp_proto( 9684 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 9685 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 9686 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 9687 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 9688 pdcp_test_params[i].cipher_key_len, 9689 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 9690 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 9691 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 9692 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 9693 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 9694 } 9695 9696 static int 9697 test_PDCP_PROTO_SGL_in_place_32B(void) 9698 { 9699 /* i can be used for running any PDCP case 9700 * In this case it is uplane 12-bit AES-SNOW DL encap 9701 */ 9702 int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK; 9703 return test_pdcp_proto_SGL(i, IN_PLACE, 9704 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9705 RTE_CRYPTO_AUTH_OP_GENERATE, 9706 pdcp_test_data_in[i], 9707 pdcp_test_data_in_len[i], 9708 pdcp_test_data_out[i], 9709 pdcp_test_data_in_len[i]+4, 9710 32, 0); 9711 } 9712 static int 9713 test_PDCP_PROTO_SGL_oop_32B_128B(void) 9714 { 9715 /* i can be used for running any PDCP case 9716 * In this case it is uplane 18-bit NULL-NULL DL encap 9717 */ 9718 int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK; 9719 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9720 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9721 RTE_CRYPTO_AUTH_OP_GENERATE, 9722 pdcp_test_data_in[i], 9723 pdcp_test_data_in_len[i], 9724 pdcp_test_data_out[i], 9725 pdcp_test_data_in_len[i]+4, 9726 32, 128); 9727 } 9728 static int 9729 test_PDCP_PROTO_SGL_oop_32B_40B(void) 9730 { 9731 /* i can be used for running any PDCP case 9732 * In this case it is uplane 18-bit AES DL encap 9733 */ 9734 int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET 9735 + DOWNLINK; 9736 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9737 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9738 RTE_CRYPTO_AUTH_OP_GENERATE, 9739 pdcp_test_data_in[i], 9740 pdcp_test_data_in_len[i], 9741 pdcp_test_data_out[i], 9742 pdcp_test_data_in_len[i], 9743 32, 40); 9744 } 9745 static int 9746 test_PDCP_PROTO_SGL_oop_128B_32B(void) 9747 { 9748 /* i can be used for running any PDCP case 9749 * In this case it is cplane 12-bit AES-ZUC DL encap 9750 */ 9751 int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK; 9752 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 9753 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9754 RTE_CRYPTO_AUTH_OP_GENERATE, 9755 pdcp_test_data_in[i], 9756 pdcp_test_data_in_len[i], 9757 pdcp_test_data_out[i], 9758 pdcp_test_data_in_len[i]+4, 9759 128, 32); 9760 } 9761 9762 static int 9763 test_PDCP_SDAP_PROTO_encap_all(void) 9764 { 9765 int i = 0, size = 0; 9766 int err, all_err = TEST_SUCCESS; 9767 const struct pdcp_sdap_test *cur_test; 9768 9769 size = RTE_DIM(list_pdcp_sdap_tests); 9770 9771 for (i = 0; i < size; i++) { 9772 cur_test = &list_pdcp_sdap_tests[i]; 9773 err = test_pdcp_proto( 9774 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9775 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9776 cur_test->in_len, cur_test->data_out, 9777 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9778 cur_test->param.cipher_alg, cur_test->cipher_key, 9779 cur_test->param.cipher_key_len, 9780 cur_test->param.auth_alg, 9781 cur_test->auth_key, cur_test->param.auth_key_len, 9782 cur_test->bearer, cur_test->param.domain, 9783 cur_test->packet_direction, cur_test->sn_size, 9784 cur_test->hfn, 9785 cur_test->hfn_threshold, SDAP_ENABLED); 9786 if (err) { 9787 printf("\t%d) %s: Encapsulation failed\n", 9788 cur_test->test_idx, 9789 cur_test->param.name); 9790 err = TEST_FAILED; 9791 } else { 9792 printf("\t%d) %s: Encap PASS\n", cur_test->test_idx, 9793 cur_test->param.name); 9794 err = TEST_SUCCESS; 9795 } 9796 all_err += err; 9797 } 9798 9799 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9800 9801 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9802 } 9803 9804 static int 9805 test_PDCP_PROTO_short_mac(void) 9806 { 9807 int i = 0, size = 0; 9808 int err, all_err = TEST_SUCCESS; 9809 const struct pdcp_short_mac_test *cur_test; 9810 9811 size = RTE_DIM(list_pdcp_smac_tests); 9812 9813 for (i = 0; i < size; i++) { 9814 cur_test = &list_pdcp_smac_tests[i]; 9815 err = test_pdcp_proto( 9816 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 9817 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 9818 cur_test->in_len, cur_test->data_out, 9819 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9820 RTE_CRYPTO_CIPHER_NULL, NULL, 9821 0, cur_test->param.auth_alg, 9822 cur_test->auth_key, cur_test->param.auth_key_len, 9823 0, cur_test->param.domain, 0, 0, 9824 0, 0, 0); 9825 if (err) { 9826 printf("\t%d) %s: Short MAC test failed\n", 9827 cur_test->test_idx, 9828 cur_test->param.name); 9829 err = TEST_FAILED; 9830 } else { 9831 printf("\t%d) %s: Short MAC test PASS\n", 9832 cur_test->test_idx, 9833 cur_test->param.name); 9834 rte_hexdump(stdout, "MAC I", 9835 cur_test->data_out + cur_test->in_len + 2, 9836 2); 9837 err = TEST_SUCCESS; 9838 } 9839 all_err += err; 9840 } 9841 9842 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9843 9844 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9845 9846 } 9847 9848 static int 9849 test_PDCP_SDAP_PROTO_decap_all(void) 9850 { 9851 int i = 0, size = 0; 9852 int err, all_err = TEST_SUCCESS; 9853 const struct pdcp_sdap_test *cur_test; 9854 9855 size = RTE_DIM(list_pdcp_sdap_tests); 9856 9857 for (i = 0; i < size; i++) { 9858 cur_test = &list_pdcp_sdap_tests[i]; 9859 err = test_pdcp_proto( 9860 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, 9861 RTE_CRYPTO_AUTH_OP_VERIFY, 9862 cur_test->data_out, 9863 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 9864 cur_test->data_in, cur_test->in_len, 9865 cur_test->param.cipher_alg, 9866 cur_test->cipher_key, cur_test->param.cipher_key_len, 9867 cur_test->param.auth_alg, cur_test->auth_key, 9868 cur_test->param.auth_key_len, cur_test->bearer, 9869 cur_test->param.domain, cur_test->packet_direction, 9870 cur_test->sn_size, cur_test->hfn, 9871 cur_test->hfn_threshold, SDAP_ENABLED); 9872 if (err) { 9873 printf("\t%d) %s: Decapsulation failed\n", 9874 cur_test->test_idx, 9875 cur_test->param.name); 9876 err = TEST_FAILED; 9877 } else { 9878 printf("\t%d) %s: Decap PASS\n", cur_test->test_idx, 9879 cur_test->param.name); 9880 err = TEST_SUCCESS; 9881 } 9882 all_err += err; 9883 } 9884 9885 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 9886 9887 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 9888 } 9889 9890 static inline void 9891 ext_mbuf_callback_fn_free(void *addr __rte_unused, void *opaque __rte_unused) 9892 { 9893 } 9894 9895 static inline void 9896 ext_mbuf_memzone_free(int nb_segs) 9897 { 9898 int i; 9899 9900 for (i = 0; i <= nb_segs; i++) { 9901 char mz_name[RTE_MEMZONE_NAMESIZE]; 9902 const struct rte_memzone *memzone; 9903 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "ext_buf_%d", i); 9904 memzone = rte_memzone_lookup(mz_name); 9905 if (memzone != NULL) { 9906 rte_memzone_free(memzone); 9907 memzone = NULL; 9908 } 9909 } 9910 } 9911 9912 static inline struct rte_mbuf * 9913 ext_mbuf_create(struct rte_mempool *mbuf_pool, int pkt_len, 9914 int nb_segs, const void *input_text) 9915 { 9916 struct rte_mbuf *m = NULL, *mbuf = NULL; 9917 size_t data_off = 0; 9918 uint8_t *dst; 9919 int i, size; 9920 int t_len; 9921 9922 if (pkt_len < 1) { 9923 printf("Packet size must be 1 or more (is %d)\n", pkt_len); 9924 return NULL; 9925 } 9926 9927 if (nb_segs < 1) { 9928 printf("Number of segments must be 1 or more (is %d)\n", 9929 nb_segs); 9930 return NULL; 9931 } 9932 9933 t_len = pkt_len >= nb_segs ? pkt_len / nb_segs : 1; 9934 size = pkt_len; 9935 9936 /* Create chained mbuf_src with external buffer */ 9937 for (i = 0; size > 0; i++) { 9938 struct rte_mbuf_ext_shared_info *ret_shinfo = NULL; 9939 uint16_t data_len = RTE_MIN(size, t_len); 9940 char mz_name[RTE_MEMZONE_NAMESIZE]; 9941 const struct rte_memzone *memzone; 9942 void *ext_buf_addr = NULL; 9943 rte_iova_t buf_iova; 9944 bool freed = false; 9945 uint16_t buf_len; 9946 9947 buf_len = RTE_ALIGN_CEIL(data_len + 1024 + 9948 sizeof(struct rte_mbuf_ext_shared_info), 8); 9949 9950 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "ext_buf_%d", i); 9951 memzone = rte_memzone_lookup(mz_name); 9952 if (memzone != NULL && memzone->len != buf_len) { 9953 rte_memzone_free(memzone); 9954 memzone = NULL; 9955 } 9956 if (memzone == NULL) { 9957 memzone = rte_memzone_reserve_aligned(mz_name, buf_len, SOCKET_ID_ANY, 9958 RTE_MEMZONE_IOVA_CONTIG, RTE_CACHE_LINE_SIZE); 9959 if (memzone == NULL) { 9960 printf("Can't allocate memory zone %s\n", mz_name); 9961 return NULL; 9962 } 9963 } 9964 9965 ext_buf_addr = memzone->addr; 9966 memcpy(ext_buf_addr, RTE_PTR_ADD(input_text, data_off), data_len); 9967 9968 /* Create buffer to hold rte_mbuf header */ 9969 m = rte_pktmbuf_alloc(mbuf_pool); 9970 if (i == 0) 9971 mbuf = m; 9972 9973 if (m == NULL) { 9974 printf("Cannot create segment for source mbuf"); 9975 goto fail; 9976 } 9977 9978 /* Save shared data (like callback function) in external buffer's end */ 9979 ret_shinfo = rte_pktmbuf_ext_shinfo_init_helper(ext_buf_addr, &buf_len, 9980 ext_mbuf_callback_fn_free, &freed); 9981 if (ret_shinfo == NULL) { 9982 printf("Shared mem initialization failed!\n"); 9983 goto fail; 9984 } 9985 9986 buf_iova = rte_mem_virt2iova(ext_buf_addr); 9987 9988 /* Attach external buffer to mbuf */ 9989 rte_pktmbuf_attach_extbuf(m, ext_buf_addr, buf_iova, buf_len, 9990 ret_shinfo); 9991 if (m->ol_flags != RTE_MBUF_F_EXTERNAL) { 9992 printf("External buffer is not attached to mbuf\n"); 9993 goto fail; 9994 } 9995 9996 dst = (uint8_t *)rte_pktmbuf_append(m, data_len); 9997 if (dst == NULL) { 9998 printf("Cannot append %d bytes to the mbuf\n", data_len); 9999 goto fail; 10000 } 10001 10002 if (mbuf != m) 10003 rte_pktmbuf_chain(mbuf, m); 10004 10005 size -= data_len; 10006 data_off += data_len; 10007 } 10008 10009 return mbuf; 10010 10011 fail: 10012 rte_pktmbuf_free(mbuf); 10013 ext_mbuf_memzone_free(nb_segs); 10014 return NULL; 10015 } 10016 10017 static int 10018 test_ipsec_proto_crypto_op_enq(struct crypto_testsuite_params *ts_params, 10019 struct crypto_unittest_params *ut_params, 10020 struct rte_security_ipsec_xform *ipsec_xform, 10021 const struct ipsec_test_data *td, 10022 const struct ipsec_test_flags *flags, 10023 int pkt_num) 10024 { 10025 uint8_t dev_id = ts_params->valid_devs[0]; 10026 enum rte_security_ipsec_sa_direction dir; 10027 int ret; 10028 10029 dir = ipsec_xform->direction; 10030 10031 /* Generate crypto op data structure */ 10032 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10033 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10034 if (!ut_params->op) { 10035 printf("Could not allocate crypto op"); 10036 return TEST_FAILED; 10037 } 10038 10039 /* Attach session to operation */ 10040 rte_security_attach_session(ut_params->op, ut_params->sec_session); 10041 10042 /* Set crypto operation mbufs */ 10043 ut_params->op->sym->m_src = ut_params->ibuf; 10044 ut_params->op->sym->m_dst = NULL; 10045 10046 /* Copy IV in crypto operation when IV generation is disabled */ 10047 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS && 10048 ipsec_xform->options.iv_gen_disable == 1) { 10049 uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op, 10050 uint8_t *, 10051 IV_OFFSET); 10052 int len; 10053 10054 if (td->aead) 10055 len = td->xform.aead.aead.iv.length; 10056 else if (td->aes_gmac) 10057 len = td->xform.chain.auth.auth.iv.length; 10058 else 10059 len = td->xform.chain.cipher.cipher.iv.length; 10060 10061 memcpy(iv, td->iv.data, len); 10062 } 10063 10064 /* Process crypto operation */ 10065 process_crypto_request(dev_id, ut_params->op); 10066 10067 ret = test_ipsec_status_check(td, ut_params->op, flags, dir, pkt_num); 10068 10069 rte_crypto_op_free(ut_params->op); 10070 ut_params->op = NULL; 10071 10072 return ret; 10073 } 10074 10075 static int 10076 test_ipsec_proto_mbuf_enq(struct crypto_testsuite_params *ts_params, 10077 struct crypto_unittest_params *ut_params, 10078 void *ctx) 10079 { 10080 uint64_t timeout, userdata; 10081 struct rte_ether_hdr *hdr; 10082 struct rte_mbuf *m; 10083 void **sec_sess; 10084 int ret; 10085 10086 RTE_SET_USED(ts_params); 10087 10088 hdr = (void *)rte_pktmbuf_prepend(ut_params->ibuf, sizeof(struct rte_ether_hdr)); 10089 hdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4); 10090 10091 ut_params->ibuf->l2_len = sizeof(struct rte_ether_hdr); 10092 ut_params->ibuf->port = 0; 10093 10094 sec_sess = &ut_params->sec_session; 10095 ret = rte_security_inb_pkt_rx_inject(ctx, &ut_params->ibuf, sec_sess, 1); 10096 10097 if (ret != 1) 10098 return TEST_FAILED; 10099 10100 ut_params->ibuf = NULL; 10101 10102 /* Add a timeout for 1 s */ 10103 timeout = rte_get_tsc_cycles() + rte_get_tsc_hz(); 10104 10105 do { 10106 /* Get packet from port 0, queue 0 */ 10107 ret = rte_eth_rx_burst(0, 0, &m, 1); 10108 } while ((ret == 0) && (rte_get_tsc_cycles() < timeout)); 10109 10110 if (ret == 0) { 10111 printf("Could not receive packets from ethdev\n"); 10112 return TEST_FAILED; 10113 } 10114 10115 if (m == NULL) { 10116 printf("Received mbuf is NULL\n"); 10117 return TEST_FAILED; 10118 } 10119 10120 ut_params->ibuf = m; 10121 10122 if (!(m->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD)) { 10123 printf("Received packet is not Rx security processed\n"); 10124 return TEST_FAILED; 10125 } 10126 10127 if (m->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED) { 10128 printf("Received packet has failed Rx security processing\n"); 10129 return TEST_FAILED; 10130 } 10131 10132 /* 10133 * 'ut_params' is set as userdata. Verify that the field is returned 10134 * correctly. 10135 */ 10136 userdata = *(uint64_t *)rte_security_dynfield(m); 10137 if (userdata != (uint64_t)ut_params) { 10138 printf("Userdata retrieved not matching expected\n"); 10139 return TEST_FAILED; 10140 } 10141 10142 /* Trim L2 header */ 10143 rte_pktmbuf_adj(m, sizeof(struct rte_ether_hdr)); 10144 10145 return TEST_SUCCESS; 10146 } 10147 10148 static int 10149 test_ipsec_proto_process(const struct ipsec_test_data td[], 10150 struct ipsec_test_data res_d[], 10151 int nb_td, 10152 bool silent, 10153 const struct ipsec_test_flags *flags) 10154 { 10155 uint16_t v6_src[8] = {0x2607, 0xf8b0, 0x400c, 0x0c03, 0x0000, 0x0000, 10156 0x0000, 0x001a}; 10157 uint16_t v6_dst[8] = {0x2001, 0x0470, 0xe5bf, 0xdead, 0x4957, 0x2174, 10158 0xe82c, 0x4887}; 10159 const struct rte_ipv4_hdr *ipv4 = 10160 (const struct rte_ipv4_hdr *)td[0].output_text.data; 10161 int nb_segs = flags->nb_segs_in_mbuf ? flags->nb_segs_in_mbuf : 1; 10162 struct crypto_testsuite_params *ts_params = &testsuite_params; 10163 struct crypto_unittest_params *ut_params = &unittest_params; 10164 struct rte_security_capability_idx sec_cap_idx; 10165 const struct rte_security_capability *sec_cap; 10166 struct rte_security_ipsec_xform ipsec_xform; 10167 uint8_t dev_id = ts_params->valid_devs[0]; 10168 enum rte_security_ipsec_sa_direction dir; 10169 struct ipsec_test_data *res_d_tmp = NULL; 10170 uint8_t input_text[IPSEC_TEXT_MAX_LEN]; 10171 int salt_len, i, ret = TEST_SUCCESS; 10172 void *ctx; 10173 uint32_t src, dst; 10174 uint32_t verify; 10175 10176 ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 10177 gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; 10178 10179 /* Use first test data to create session */ 10180 10181 /* Copy IPsec xform */ 10182 memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform)); 10183 10184 dir = ipsec_xform.direction; 10185 verify = flags->tunnel_hdr_verify; 10186 10187 memcpy(&src, &ipv4->src_addr, sizeof(ipv4->src_addr)); 10188 memcpy(&dst, &ipv4->dst_addr, sizeof(ipv4->dst_addr)); 10189 10190 if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) { 10191 if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR) 10192 src += 1; 10193 else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR) 10194 dst += 1; 10195 } 10196 10197 if (td->ipsec_xform.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) { 10198 if (td->ipsec_xform.tunnel.type == 10199 RTE_SECURITY_IPSEC_TUNNEL_IPV4) { 10200 memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, 10201 sizeof(src)); 10202 memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, 10203 sizeof(dst)); 10204 10205 if (flags->df == TEST_IPSEC_SET_DF_0_INNER_1) 10206 ipsec_xform.tunnel.ipv4.df = 0; 10207 10208 if (flags->df == TEST_IPSEC_SET_DF_1_INNER_0) 10209 ipsec_xform.tunnel.ipv4.df = 1; 10210 10211 if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1) 10212 ipsec_xform.tunnel.ipv4.dscp = 0; 10213 10214 if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0) 10215 ipsec_xform.tunnel.ipv4.dscp = 10216 TEST_IPSEC_DSCP_VAL; 10217 10218 } else { 10219 if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1) 10220 ipsec_xform.tunnel.ipv6.dscp = 0; 10221 10222 if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0) 10223 ipsec_xform.tunnel.ipv6.dscp = 10224 TEST_IPSEC_DSCP_VAL; 10225 10226 memcpy(&ipsec_xform.tunnel.ipv6.src_addr, &v6_src, 10227 sizeof(v6_src)); 10228 memcpy(&ipsec_xform.tunnel.ipv6.dst_addr, &v6_dst, 10229 sizeof(v6_dst)); 10230 } 10231 } 10232 10233 ctx = rte_cryptodev_get_sec_ctx(dev_id); 10234 10235 sec_cap_idx.action = ut_params->type; 10236 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC; 10237 sec_cap_idx.ipsec.proto = ipsec_xform.proto; 10238 sec_cap_idx.ipsec.mode = ipsec_xform.mode; 10239 sec_cap_idx.ipsec.direction = ipsec_xform.direction; 10240 10241 if (flags->udp_encap) 10242 ipsec_xform.options.udp_encap = 1; 10243 10244 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 10245 if (sec_cap == NULL) 10246 return TEST_SKIPPED; 10247 10248 /* Copy cipher session parameters */ 10249 if (td[0].aead) { 10250 memcpy(&ut_params->aead_xform, &td[0].xform.aead, 10251 sizeof(ut_params->aead_xform)); 10252 ut_params->aead_xform.aead.key.data = td[0].key.data; 10253 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 10254 10255 /* Verify crypto capabilities */ 10256 if (test_sec_crypto_caps_aead_verify(sec_cap, &ut_params->aead_xform) != 0) { 10257 if (!silent) 10258 RTE_LOG(INFO, USER1, 10259 "Crypto capabilities not supported\n"); 10260 return TEST_SKIPPED; 10261 } 10262 } else if (td[0].auth_only) { 10263 memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth, 10264 sizeof(ut_params->auth_xform)); 10265 ut_params->auth_xform.auth.key.data = td[0].auth_key.data; 10266 10267 if (test_sec_crypto_caps_auth_verify(sec_cap, &ut_params->auth_xform) != 0) { 10268 if (!silent) 10269 RTE_LOG(INFO, USER1, 10270 "Auth crypto capabilities not supported\n"); 10271 return TEST_SKIPPED; 10272 } 10273 } else { 10274 memcpy(&ut_params->cipher_xform, &td[0].xform.chain.cipher, 10275 sizeof(ut_params->cipher_xform)); 10276 memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth, 10277 sizeof(ut_params->auth_xform)); 10278 ut_params->cipher_xform.cipher.key.data = td[0].key.data; 10279 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 10280 ut_params->auth_xform.auth.key.data = td[0].auth_key.data; 10281 10282 /* Verify crypto capabilities */ 10283 10284 if (test_sec_crypto_caps_cipher_verify(sec_cap, &ut_params->cipher_xform) != 0) { 10285 if (!silent) 10286 RTE_LOG(INFO, USER1, 10287 "Cipher crypto capabilities not supported\n"); 10288 return TEST_SKIPPED; 10289 } 10290 10291 if (test_sec_crypto_caps_auth_verify(sec_cap, &ut_params->auth_xform) != 0) { 10292 if (!silent) 10293 RTE_LOG(INFO, USER1, 10294 "Auth crypto capabilities not supported\n"); 10295 return TEST_SKIPPED; 10296 } 10297 } 10298 10299 if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0) 10300 return TEST_SKIPPED; 10301 10302 struct rte_security_session_conf sess_conf = { 10303 .action_type = ut_params->type, 10304 .protocol = RTE_SECURITY_PROTOCOL_IPSEC, 10305 }; 10306 10307 if (td[0].aead || td[0].aes_gmac) { 10308 salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len); 10309 memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len); 10310 } 10311 10312 if (td[0].aead) { 10313 sess_conf.ipsec = ipsec_xform; 10314 sess_conf.crypto_xform = &ut_params->aead_xform; 10315 } else if (td[0].auth_only) { 10316 sess_conf.ipsec = ipsec_xform; 10317 sess_conf.crypto_xform = &ut_params->auth_xform; 10318 } else { 10319 sess_conf.ipsec = ipsec_xform; 10320 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) { 10321 sess_conf.crypto_xform = &ut_params->cipher_xform; 10322 ut_params->cipher_xform.next = &ut_params->auth_xform; 10323 } else { 10324 sess_conf.crypto_xform = &ut_params->auth_xform; 10325 ut_params->auth_xform.next = &ut_params->cipher_xform; 10326 } 10327 } 10328 10329 if (dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS && flags->rx_inject) 10330 sess_conf.userdata = ut_params; 10331 10332 /* Create security session */ 10333 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 10334 ts_params->session_mpool); 10335 10336 if (ut_params->sec_session == NULL) 10337 return TEST_SKIPPED; 10338 10339 for (i = 0; i < nb_td; i++) { 10340 if (flags->antireplay && 10341 (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)) { 10342 sess_conf.ipsec.esn.value = td[i].ipsec_xform.esn.value; 10343 ret = rte_security_session_update(ctx, 10344 ut_params->sec_session, &sess_conf); 10345 if (ret) { 10346 printf("Could not update sequence number in " 10347 "session\n"); 10348 return TEST_SKIPPED; 10349 } 10350 } 10351 10352 /* Copy test data before modification */ 10353 memcpy(input_text, td[i].input_text.data, td[i].input_text.len); 10354 if (test_ipsec_pkt_update(input_text, flags)) { 10355 ret = TEST_FAILED; 10356 goto mbuf_free; 10357 } 10358 10359 /* Setup source mbuf payload */ 10360 if (flags->use_ext_mbuf) { 10361 ut_params->ibuf = ext_mbuf_create(ts_params->mbuf_pool, 10362 td[i].input_text.len, nb_segs, input_text); 10363 } else { 10364 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 10365 td[i].input_text.len, nb_segs, 0); 10366 pktmbuf_write(ut_params->ibuf, 0, td[i].input_text.len, input_text); 10367 } 10368 10369 if (dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS && flags->rx_inject) 10370 ret = test_ipsec_proto_mbuf_enq(ts_params, ut_params, 10371 ctx); 10372 else 10373 ret = test_ipsec_proto_crypto_op_enq(ts_params, 10374 ut_params, 10375 &ipsec_xform, 10376 &td[i], flags, 10377 i + 1); 10378 10379 if (ret != TEST_SUCCESS) 10380 goto mbuf_free; 10381 10382 if (res_d != NULL) 10383 res_d_tmp = &res_d[i]; 10384 10385 ret = test_ipsec_post_process(ut_params->ibuf, &td[i], 10386 res_d_tmp, silent, flags); 10387 if (ret != TEST_SUCCESS) 10388 goto mbuf_free; 10389 10390 ret = test_ipsec_stats_verify(ctx, ut_params->sec_session, 10391 flags, dir); 10392 if (ret != TEST_SUCCESS) 10393 goto mbuf_free; 10394 10395 rte_pktmbuf_free(ut_params->ibuf); 10396 ut_params->ibuf = NULL; 10397 } 10398 10399 mbuf_free: 10400 if (flags->use_ext_mbuf) 10401 ext_mbuf_memzone_free(nb_segs); 10402 10403 rte_pktmbuf_free(ut_params->ibuf); 10404 ut_params->ibuf = NULL; 10405 10406 if (ut_params->sec_session) 10407 rte_security_session_destroy(ctx, ut_params->sec_session); 10408 ut_params->sec_session = NULL; 10409 10410 return ret; 10411 } 10412 10413 static int 10414 test_ipsec_proto_known_vec(const void *test_data) 10415 { 10416 struct ipsec_test_data td_outb; 10417 struct ipsec_test_flags flags; 10418 10419 memset(&flags, 0, sizeof(flags)); 10420 10421 memcpy(&td_outb, test_data, sizeof(td_outb)); 10422 10423 if (td_outb.aes_gmac || td_outb.aead || 10424 ((td_outb.ipsec_xform.proto != RTE_SECURITY_IPSEC_SA_PROTO_AH) && 10425 (td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL))) { 10426 /* Disable IV gen to be able to test with known vectors */ 10427 td_outb.ipsec_xform.options.iv_gen_disable = 1; 10428 } 10429 10430 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 10431 } 10432 10433 static int 10434 test_ipsec_proto_known_vec_ext_mbuf(const void *test_data) 10435 { 10436 struct ipsec_test_data td_outb; 10437 struct ipsec_test_flags flags; 10438 10439 memset(&flags, 0, sizeof(flags)); 10440 flags.use_ext_mbuf = true; 10441 10442 memcpy(&td_outb, test_data, sizeof(td_outb)); 10443 10444 if (td_outb.aes_gmac || td_outb.aead || 10445 ((td_outb.ipsec_xform.proto != RTE_SECURITY_IPSEC_SA_PROTO_AH) && 10446 (td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL))) { 10447 /* Disable IV gen to be able to test with known vectors */ 10448 td_outb.ipsec_xform.options.iv_gen_disable = 1; 10449 } 10450 10451 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 10452 } 10453 10454 static int 10455 test_ipsec_proto_known_vec_inb(const void *test_data) 10456 { 10457 const struct ipsec_test_data *td = test_data; 10458 struct ipsec_test_flags flags; 10459 struct ipsec_test_data td_inb; 10460 10461 memset(&flags, 0, sizeof(flags)); 10462 10463 if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) 10464 test_ipsec_td_in_from_out(td, &td_inb); 10465 else 10466 memcpy(&td_inb, td, sizeof(td_inb)); 10467 10468 return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags); 10469 } 10470 10471 static int 10472 test_ipsec_proto_known_vec_fragmented(const void *test_data) 10473 { 10474 struct ipsec_test_data td_outb; 10475 struct ipsec_test_flags flags; 10476 10477 memset(&flags, 0, sizeof(flags)); 10478 flags.fragment = true; 10479 10480 memcpy(&td_outb, test_data, sizeof(td_outb)); 10481 10482 /* Disable IV gen to be able to test with known vectors */ 10483 td_outb.ipsec_xform.options.iv_gen_disable = 1; 10484 10485 return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); 10486 } 10487 10488 static int 10489 test_ipsec_proto_known_vec_inb_rx_inject(const void *test_data) 10490 { 10491 const struct ipsec_test_data *td = test_data; 10492 struct ipsec_test_flags flags; 10493 struct ipsec_test_data td_inb; 10494 10495 memset(&flags, 0, sizeof(flags)); 10496 flags.rx_inject = true; 10497 10498 if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) 10499 test_ipsec_td_in_from_out(td, &td_inb); 10500 else 10501 memcpy(&td_inb, td, sizeof(td_inb)); 10502 10503 return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags); 10504 } 10505 10506 static int 10507 test_ipsec_proto_all(const struct ipsec_test_flags *flags) 10508 { 10509 struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX]; 10510 struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX]; 10511 unsigned int i, nb_pkts = 1, pass_cnt = 0; 10512 int ret; 10513 10514 if (flags->iv_gen || 10515 flags->sa_expiry_pkts_soft || 10516 flags->sa_expiry_pkts_hard) 10517 nb_pkts = IPSEC_TEST_PACKETS_MAX; 10518 10519 for (i = 0; i < RTE_DIM(alg_list); i++) { 10520 test_ipsec_td_prepare(alg_list[i].param1, 10521 alg_list[i].param2, 10522 flags, 10523 td_outb, 10524 nb_pkts); 10525 10526 if (!td_outb->aead) { 10527 enum rte_crypto_cipher_algorithm cipher_alg; 10528 enum rte_crypto_auth_algorithm auth_alg; 10529 10530 cipher_alg = td_outb->xform.chain.cipher.cipher.algo; 10531 auth_alg = td_outb->xform.chain.auth.auth.algo; 10532 10533 if (td_outb->aes_gmac && cipher_alg != RTE_CRYPTO_CIPHER_NULL) 10534 continue; 10535 10536 /* ICV is not applicable for NULL auth */ 10537 if (flags->icv_corrupt && 10538 auth_alg == RTE_CRYPTO_AUTH_NULL) 10539 continue; 10540 10541 /* IV is not applicable for NULL cipher */ 10542 if (flags->iv_gen && 10543 cipher_alg == RTE_CRYPTO_CIPHER_NULL) 10544 continue; 10545 } 10546 10547 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 10548 flags); 10549 if (ret == TEST_SKIPPED) 10550 continue; 10551 10552 if (ret == TEST_FAILED) 10553 return TEST_FAILED; 10554 10555 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags); 10556 10557 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 10558 flags); 10559 if (ret == TEST_SKIPPED) 10560 continue; 10561 10562 if (ret == TEST_FAILED) 10563 return TEST_FAILED; 10564 10565 if (flags->display_alg) 10566 test_ipsec_display_alg(alg_list[i].param1, 10567 alg_list[i].param2); 10568 10569 pass_cnt++; 10570 } 10571 10572 if (pass_cnt > 0) 10573 return TEST_SUCCESS; 10574 else 10575 return TEST_SKIPPED; 10576 } 10577 10578 static int 10579 test_ipsec_ah_proto_all(const struct ipsec_test_flags *flags) 10580 { 10581 struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX]; 10582 struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX]; 10583 unsigned int i, nb_pkts = 1, pass_cnt = 0; 10584 int ret; 10585 10586 for (i = 0; i < RTE_DIM(ah_alg_list); i++) { 10587 test_ipsec_td_prepare(ah_alg_list[i].param1, 10588 ah_alg_list[i].param2, 10589 flags, 10590 td_outb, 10591 nb_pkts); 10592 10593 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 10594 flags); 10595 if (ret == TEST_SKIPPED) 10596 continue; 10597 10598 if (ret == TEST_FAILED) 10599 return TEST_FAILED; 10600 10601 test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags); 10602 10603 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 10604 flags); 10605 if (ret == TEST_SKIPPED) 10606 continue; 10607 10608 if (ret == TEST_FAILED) 10609 return TEST_FAILED; 10610 10611 if (flags->display_alg) 10612 test_ipsec_display_alg(ah_alg_list[i].param1, 10613 ah_alg_list[i].param2); 10614 10615 pass_cnt++; 10616 } 10617 10618 if (pass_cnt > 0) 10619 return TEST_SUCCESS; 10620 else 10621 return TEST_SKIPPED; 10622 } 10623 10624 static int 10625 test_ipsec_proto_display_list(void) 10626 { 10627 struct ipsec_test_flags flags; 10628 10629 memset(&flags, 0, sizeof(flags)); 10630 10631 flags.display_alg = true; 10632 10633 return test_ipsec_proto_all(&flags); 10634 } 10635 10636 static int 10637 test_ipsec_proto_ah_tunnel_ipv4(void) 10638 { 10639 struct ipsec_test_flags flags; 10640 10641 memset(&flags, 0, sizeof(flags)); 10642 10643 flags.ah = true; 10644 flags.display_alg = true; 10645 10646 return test_ipsec_ah_proto_all(&flags); 10647 } 10648 10649 static int 10650 test_ipsec_proto_ah_transport_ipv4(void) 10651 { 10652 struct ipsec_test_flags flags; 10653 10654 memset(&flags, 0, sizeof(flags)); 10655 10656 flags.ah = true; 10657 flags.transport = true; 10658 10659 return test_ipsec_ah_proto_all(&flags); 10660 } 10661 10662 static int 10663 test_ipsec_proto_iv_gen(void) 10664 { 10665 struct ipsec_test_flags flags; 10666 10667 memset(&flags, 0, sizeof(flags)); 10668 10669 flags.iv_gen = true; 10670 10671 return test_ipsec_proto_all(&flags); 10672 } 10673 10674 static int 10675 test_ipsec_proto_sa_exp_pkts_soft(void) 10676 { 10677 struct ipsec_test_flags flags; 10678 10679 memset(&flags, 0, sizeof(flags)); 10680 10681 flags.sa_expiry_pkts_soft = true; 10682 10683 return test_ipsec_proto_all(&flags); 10684 } 10685 10686 static int 10687 test_ipsec_proto_sa_exp_pkts_hard(void) 10688 { 10689 struct ipsec_test_flags flags; 10690 10691 memset(&flags, 0, sizeof(flags)); 10692 10693 flags.sa_expiry_pkts_hard = true; 10694 10695 return test_ipsec_proto_all(&flags); 10696 } 10697 10698 static int 10699 test_ipsec_proto_err_icv_corrupt(void) 10700 { 10701 struct ipsec_test_flags flags; 10702 10703 memset(&flags, 0, sizeof(flags)); 10704 10705 flags.icv_corrupt = true; 10706 10707 return test_ipsec_proto_all(&flags); 10708 } 10709 10710 static int 10711 test_ipsec_proto_udp_encap_custom_ports(void) 10712 { 10713 struct ipsec_test_flags flags; 10714 10715 if (gbl_driver_id == rte_cryptodev_driver_id_get( 10716 RTE_STR(CRYPTODEV_NAME_CN10K_PMD))) 10717 return TEST_SKIPPED; 10718 10719 memset(&flags, 0, sizeof(flags)); 10720 10721 flags.udp_encap = true; 10722 flags.udp_encap_custom_ports = true; 10723 10724 return test_ipsec_proto_all(&flags); 10725 } 10726 10727 static int 10728 test_ipsec_proto_udp_encap(void) 10729 { 10730 struct ipsec_test_flags flags; 10731 10732 memset(&flags, 0, sizeof(flags)); 10733 10734 flags.udp_encap = true; 10735 10736 return test_ipsec_proto_all(&flags); 10737 } 10738 10739 static int 10740 test_ipsec_proto_tunnel_src_dst_addr_verify(void) 10741 { 10742 struct ipsec_test_flags flags; 10743 10744 memset(&flags, 0, sizeof(flags)); 10745 10746 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR; 10747 10748 return test_ipsec_proto_all(&flags); 10749 } 10750 10751 static int 10752 test_ipsec_proto_tunnel_dst_addr_verify(void) 10753 { 10754 struct ipsec_test_flags flags; 10755 10756 memset(&flags, 0, sizeof(flags)); 10757 10758 flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR; 10759 10760 return test_ipsec_proto_all(&flags); 10761 } 10762 10763 static int 10764 test_ipsec_proto_udp_ports_verify(void) 10765 { 10766 struct ipsec_test_flags flags; 10767 10768 memset(&flags, 0, sizeof(flags)); 10769 10770 flags.udp_encap = true; 10771 flags.udp_ports_verify = true; 10772 10773 return test_ipsec_proto_all(&flags); 10774 } 10775 10776 static int 10777 test_ipsec_proto_inner_ip_csum(void) 10778 { 10779 struct ipsec_test_flags flags; 10780 10781 memset(&flags, 0, sizeof(flags)); 10782 10783 flags.ip_csum = true; 10784 10785 return test_ipsec_proto_all(&flags); 10786 } 10787 10788 static int 10789 test_ipsec_proto_inner_l4_csum(void) 10790 { 10791 struct ipsec_test_flags flags; 10792 10793 memset(&flags, 0, sizeof(flags)); 10794 10795 flags.l4_csum = true; 10796 10797 return test_ipsec_proto_all(&flags); 10798 } 10799 10800 static int 10801 test_ipsec_proto_tunnel_v4_in_v4(void) 10802 { 10803 struct ipsec_test_flags flags; 10804 10805 memset(&flags, 0, sizeof(flags)); 10806 10807 flags.ipv6 = false; 10808 flags.tunnel_ipv6 = false; 10809 10810 return test_ipsec_proto_all(&flags); 10811 } 10812 10813 static int 10814 test_ipsec_proto_tunnel_v6_in_v6(void) 10815 { 10816 struct ipsec_test_flags flags; 10817 10818 memset(&flags, 0, sizeof(flags)); 10819 10820 flags.ipv6 = true; 10821 flags.tunnel_ipv6 = true; 10822 10823 return test_ipsec_proto_all(&flags); 10824 } 10825 10826 static int 10827 test_ipsec_proto_tunnel_v4_in_v6(void) 10828 { 10829 struct ipsec_test_flags flags; 10830 10831 memset(&flags, 0, sizeof(flags)); 10832 10833 flags.ipv6 = false; 10834 flags.tunnel_ipv6 = true; 10835 10836 return test_ipsec_proto_all(&flags); 10837 } 10838 10839 static int 10840 test_ipsec_proto_tunnel_v6_in_v4(void) 10841 { 10842 struct ipsec_test_flags flags; 10843 10844 memset(&flags, 0, sizeof(flags)); 10845 10846 flags.ipv6 = true; 10847 flags.tunnel_ipv6 = false; 10848 10849 return test_ipsec_proto_all(&flags); 10850 } 10851 10852 static int 10853 test_ipsec_proto_transport_v4(void) 10854 { 10855 struct ipsec_test_flags flags; 10856 10857 memset(&flags, 0, sizeof(flags)); 10858 10859 flags.ipv6 = false; 10860 flags.transport = true; 10861 10862 return test_ipsec_proto_all(&flags); 10863 } 10864 10865 static int 10866 test_ipsec_proto_transport_l4_csum(void) 10867 { 10868 struct ipsec_test_flags flags = { 10869 .l4_csum = true, 10870 .transport = true, 10871 }; 10872 10873 return test_ipsec_proto_all(&flags); 10874 } 10875 10876 static int 10877 test_ipsec_proto_stats(void) 10878 { 10879 struct ipsec_test_flags flags; 10880 10881 memset(&flags, 0, sizeof(flags)); 10882 10883 flags.stats_success = true; 10884 10885 return test_ipsec_proto_all(&flags); 10886 } 10887 10888 static int 10889 test_ipsec_proto_pkt_fragment(void) 10890 { 10891 struct ipsec_test_flags flags; 10892 10893 memset(&flags, 0, sizeof(flags)); 10894 10895 flags.fragment = true; 10896 10897 return test_ipsec_proto_all(&flags); 10898 10899 } 10900 10901 static int 10902 test_ipsec_proto_copy_df_inner_0(void) 10903 { 10904 struct ipsec_test_flags flags; 10905 10906 memset(&flags, 0, sizeof(flags)); 10907 10908 flags.df = TEST_IPSEC_COPY_DF_INNER_0; 10909 10910 return test_ipsec_proto_all(&flags); 10911 } 10912 10913 static int 10914 test_ipsec_proto_copy_df_inner_1(void) 10915 { 10916 struct ipsec_test_flags flags; 10917 10918 memset(&flags, 0, sizeof(flags)); 10919 10920 flags.df = TEST_IPSEC_COPY_DF_INNER_1; 10921 10922 return test_ipsec_proto_all(&flags); 10923 } 10924 10925 static int 10926 test_ipsec_proto_set_df_0_inner_1(void) 10927 { 10928 struct ipsec_test_flags flags; 10929 10930 memset(&flags, 0, sizeof(flags)); 10931 10932 flags.df = TEST_IPSEC_SET_DF_0_INNER_1; 10933 10934 return test_ipsec_proto_all(&flags); 10935 } 10936 10937 static int 10938 test_ipsec_proto_set_df_1_inner_0(void) 10939 { 10940 struct ipsec_test_flags flags; 10941 10942 memset(&flags, 0, sizeof(flags)); 10943 10944 flags.df = TEST_IPSEC_SET_DF_1_INNER_0; 10945 10946 return test_ipsec_proto_all(&flags); 10947 } 10948 10949 static int 10950 test_ipsec_proto_ipv4_copy_dscp_inner_0(void) 10951 { 10952 struct ipsec_test_flags flags; 10953 10954 memset(&flags, 0, sizeof(flags)); 10955 10956 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0; 10957 10958 return test_ipsec_proto_all(&flags); 10959 } 10960 10961 static int 10962 test_ipsec_proto_ipv4_copy_dscp_inner_1(void) 10963 { 10964 struct ipsec_test_flags flags; 10965 10966 memset(&flags, 0, sizeof(flags)); 10967 10968 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1; 10969 10970 return test_ipsec_proto_all(&flags); 10971 } 10972 10973 static int 10974 test_ipsec_proto_ipv4_set_dscp_0_inner_1(void) 10975 { 10976 struct ipsec_test_flags flags; 10977 10978 if (gbl_driver_id == rte_cryptodev_driver_id_get( 10979 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 10980 return TEST_SKIPPED; 10981 10982 memset(&flags, 0, sizeof(flags)); 10983 10984 flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1; 10985 10986 return test_ipsec_proto_all(&flags); 10987 } 10988 10989 static int 10990 test_ipsec_proto_ipv4_set_dscp_1_inner_0(void) 10991 { 10992 struct ipsec_test_flags flags; 10993 10994 if (gbl_driver_id == rte_cryptodev_driver_id_get( 10995 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 10996 return TEST_SKIPPED; 10997 10998 memset(&flags, 0, sizeof(flags)); 10999 11000 flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0; 11001 11002 return test_ipsec_proto_all(&flags); 11003 } 11004 11005 static int 11006 test_ipsec_proto_ipv6_copy_dscp_inner_0(void) 11007 { 11008 struct ipsec_test_flags flags; 11009 11010 memset(&flags, 0, sizeof(flags)); 11011 11012 flags.ipv6 = true; 11013 flags.tunnel_ipv6 = true; 11014 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0; 11015 11016 return test_ipsec_proto_all(&flags); 11017 } 11018 11019 static int 11020 test_ipsec_proto_ipv6_copy_dscp_inner_1(void) 11021 { 11022 struct ipsec_test_flags flags; 11023 11024 memset(&flags, 0, sizeof(flags)); 11025 11026 flags.ipv6 = true; 11027 flags.tunnel_ipv6 = true; 11028 flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1; 11029 11030 return test_ipsec_proto_all(&flags); 11031 } 11032 11033 static int 11034 test_ipsec_proto_ipv6_set_dscp_0_inner_1(void) 11035 { 11036 struct ipsec_test_flags flags; 11037 11038 if (gbl_driver_id == rte_cryptodev_driver_id_get( 11039 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 11040 return TEST_SKIPPED; 11041 11042 memset(&flags, 0, sizeof(flags)); 11043 11044 flags.ipv6 = true; 11045 flags.tunnel_ipv6 = true; 11046 flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1; 11047 11048 return test_ipsec_proto_all(&flags); 11049 } 11050 11051 static int 11052 test_ipsec_proto_ipv6_set_dscp_1_inner_0(void) 11053 { 11054 struct ipsec_test_flags flags; 11055 11056 if (gbl_driver_id == rte_cryptodev_driver_id_get( 11057 RTE_STR(CRYPTODEV_NAME_CN9K_PMD))) 11058 return TEST_SKIPPED; 11059 11060 memset(&flags, 0, sizeof(flags)); 11061 11062 flags.ipv6 = true; 11063 flags.tunnel_ipv6 = true; 11064 flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0; 11065 11066 return test_ipsec_proto_all(&flags); 11067 } 11068 11069 static int 11070 test_ipsec_proto_sgl(void) 11071 { 11072 struct crypto_testsuite_params *ts_params = &testsuite_params; 11073 struct rte_cryptodev_info dev_info; 11074 11075 struct ipsec_test_flags flags = { 11076 .nb_segs_in_mbuf = 5 11077 }; 11078 11079 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11080 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 11081 printf("Device doesn't support in-place scatter-gather. " 11082 "Test Skipped.\n"); 11083 return TEST_SKIPPED; 11084 } 11085 11086 return test_ipsec_proto_all(&flags); 11087 } 11088 11089 static int 11090 test_ipsec_proto_sgl_ext_mbuf(void) 11091 { 11092 struct crypto_testsuite_params *ts_params = &testsuite_params; 11093 struct rte_cryptodev_info dev_info; 11094 11095 struct ipsec_test_flags flags = { 11096 .nb_segs_in_mbuf = 5, 11097 .use_ext_mbuf = 1 11098 }; 11099 11100 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11101 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 11102 printf("Device doesn't support in-place scatter-gather. " 11103 "Test Skipped.\n"); 11104 return TEST_SKIPPED; 11105 } 11106 11107 return test_ipsec_proto_all(&flags); 11108 } 11109 11110 static int 11111 test_ipsec_pkt_replay(const void *test_data, const uint64_t esn[], 11112 bool replayed_pkt[], uint32_t nb_pkts, bool esn_en, 11113 uint64_t winsz) 11114 { 11115 struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX]; 11116 struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX]; 11117 struct ipsec_test_flags flags; 11118 uint32_t i = 0, ret = 0; 11119 11120 if (nb_pkts == 0) 11121 return TEST_FAILED; 11122 11123 memset(&flags, 0, sizeof(flags)); 11124 flags.antireplay = true; 11125 11126 for (i = 0; i < nb_pkts; i++) { 11127 memcpy(&td_outb[i], test_data, sizeof(td_outb[i])); 11128 td_outb[i].ipsec_xform.options.iv_gen_disable = 1; 11129 td_outb[i].ipsec_xform.replay_win_sz = winsz; 11130 td_outb[i].ipsec_xform.options.esn = esn_en; 11131 } 11132 11133 for (i = 0; i < nb_pkts; i++) 11134 td_outb[i].ipsec_xform.esn.value = esn[i]; 11135 11136 ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true, 11137 &flags); 11138 if (ret != TEST_SUCCESS) 11139 return ret; 11140 11141 test_ipsec_td_update(td_inb, td_outb, nb_pkts, &flags); 11142 11143 for (i = 0; i < nb_pkts; i++) { 11144 td_inb[i].ipsec_xform.options.esn = esn_en; 11145 /* Set antireplay flag for packets to be dropped */ 11146 td_inb[i].ar_packet = replayed_pkt[i]; 11147 } 11148 11149 ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true, 11150 &flags); 11151 11152 return ret; 11153 } 11154 11155 static int 11156 test_ipsec_proto_pkt_antireplay(const void *test_data, uint64_t winsz) 11157 { 11158 11159 uint32_t nb_pkts = 5; 11160 bool replayed_pkt[5]; 11161 uint64_t esn[5]; 11162 11163 /* 1. Advance the TOP of the window to WS * 2 */ 11164 esn[0] = winsz * 2; 11165 /* 2. Test sequence number within the new window(WS + 1) */ 11166 esn[1] = winsz + 1; 11167 /* 3. Test sequence number less than the window BOTTOM */ 11168 esn[2] = winsz; 11169 /* 4. Test sequence number in the middle of the window */ 11170 esn[3] = winsz + (winsz / 2); 11171 /* 5. Test replay of the packet in the middle of the window */ 11172 esn[4] = winsz + (winsz / 2); 11173 11174 replayed_pkt[0] = false; 11175 replayed_pkt[1] = false; 11176 replayed_pkt[2] = true; 11177 replayed_pkt[3] = false; 11178 replayed_pkt[4] = true; 11179 11180 return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts, 11181 false, winsz); 11182 } 11183 11184 static int 11185 test_ipsec_proto_pkt_antireplay1024(const void *test_data) 11186 { 11187 return test_ipsec_proto_pkt_antireplay(test_data, 1024); 11188 } 11189 11190 static int 11191 test_ipsec_proto_pkt_antireplay2048(const void *test_data) 11192 { 11193 return test_ipsec_proto_pkt_antireplay(test_data, 2048); 11194 } 11195 11196 static int 11197 test_ipsec_proto_pkt_antireplay4096(const void *test_data) 11198 { 11199 return test_ipsec_proto_pkt_antireplay(test_data, 4096); 11200 } 11201 11202 static int 11203 test_ipsec_proto_pkt_esn_antireplay(const void *test_data, uint64_t winsz) 11204 { 11205 11206 uint32_t nb_pkts = 7; 11207 bool replayed_pkt[7]; 11208 uint64_t esn[7]; 11209 11210 /* Set the initial sequence number */ 11211 esn[0] = (uint64_t)(0xFFFFFFFF - winsz); 11212 /* 1. Advance the TOP of the window to (1<<32 + WS/2) */ 11213 esn[1] = (uint64_t)((1ULL << 32) + (winsz / 2)); 11214 /* 2. Test sequence number within new window (1<<32 + WS/2 + 1) */ 11215 esn[2] = (uint64_t)((1ULL << 32) - (winsz / 2) + 1); 11216 /* 3. Test with sequence number within window (1<<32 - 1) */ 11217 esn[3] = (uint64_t)((1ULL << 32) - 1); 11218 /* 4. Test with sequence number within window (1<<32 - 1) */ 11219 esn[4] = (uint64_t)(1ULL << 32); 11220 /* 5. Test with duplicate sequence number within 11221 * new window (1<<32 - 1) 11222 */ 11223 esn[5] = (uint64_t)((1ULL << 32) - 1); 11224 /* 6. Test with duplicate sequence number within new window (1<<32) */ 11225 esn[6] = (uint64_t)(1ULL << 32); 11226 11227 replayed_pkt[0] = false; 11228 replayed_pkt[1] = false; 11229 replayed_pkt[2] = false; 11230 replayed_pkt[3] = false; 11231 replayed_pkt[4] = false; 11232 replayed_pkt[5] = true; 11233 replayed_pkt[6] = true; 11234 11235 return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts, 11236 true, winsz); 11237 } 11238 11239 static int 11240 test_ipsec_proto_pkt_esn_antireplay1024(const void *test_data) 11241 { 11242 return test_ipsec_proto_pkt_esn_antireplay(test_data, 1024); 11243 } 11244 11245 static int 11246 test_ipsec_proto_pkt_esn_antireplay2048(const void *test_data) 11247 { 11248 return test_ipsec_proto_pkt_esn_antireplay(test_data, 2048); 11249 } 11250 11251 static int 11252 test_ipsec_proto_pkt_esn_antireplay4096(const void *test_data) 11253 { 11254 return test_ipsec_proto_pkt_esn_antireplay(test_data, 4096); 11255 } 11256 11257 static int 11258 test_PDCP_PROTO_all(void) 11259 { 11260 struct crypto_testsuite_params *ts_params = &testsuite_params; 11261 struct crypto_unittest_params *ut_params = &unittest_params; 11262 struct rte_cryptodev_info dev_info; 11263 int status; 11264 11265 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11266 uint64_t feat_flags = dev_info.feature_flags; 11267 11268 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 11269 return TEST_SKIPPED; 11270 11271 /* Set action type */ 11272 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 11273 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 11274 gbl_action_type; 11275 11276 if (security_proto_supported(ut_params->type, 11277 RTE_SECURITY_PROTOCOL_PDCP) < 0) 11278 return TEST_SKIPPED; 11279 11280 status = test_PDCP_PROTO_cplane_encap_all(); 11281 status += test_PDCP_PROTO_cplane_decap_all(); 11282 status += test_PDCP_PROTO_uplane_encap_all(); 11283 status += test_PDCP_PROTO_uplane_decap_all(); 11284 status += test_PDCP_PROTO_SGL_in_place_32B(); 11285 status += test_PDCP_PROTO_SGL_oop_32B_128B(); 11286 status += test_PDCP_PROTO_SGL_oop_32B_40B(); 11287 status += test_PDCP_PROTO_SGL_oop_128B_32B(); 11288 status += test_PDCP_SDAP_PROTO_encap_all(); 11289 status += test_PDCP_SDAP_PROTO_decap_all(); 11290 status += test_PDCP_PROTO_short_mac(); 11291 11292 if (status) 11293 return TEST_FAILED; 11294 else 11295 return TEST_SUCCESS; 11296 } 11297 11298 static int 11299 test_ipsec_proto_ipv4_ttl_decrement(void) 11300 { 11301 struct ipsec_test_flags flags = { 11302 .dec_ttl_or_hop_limit = true 11303 }; 11304 11305 return test_ipsec_proto_all(&flags); 11306 } 11307 11308 static int 11309 test_ipsec_proto_ipv6_hop_limit_decrement(void) 11310 { 11311 struct ipsec_test_flags flags = { 11312 .ipv6 = true, 11313 .dec_ttl_or_hop_limit = true 11314 }; 11315 11316 return test_ipsec_proto_all(&flags); 11317 } 11318 11319 static int 11320 test_docsis_proto_uplink(const void *data) 11321 { 11322 const struct docsis_test_data *d_td = data; 11323 struct crypto_testsuite_params *ts_params = &testsuite_params; 11324 struct crypto_unittest_params *ut_params = &unittest_params; 11325 uint8_t *plaintext = NULL; 11326 uint8_t *ciphertext = NULL; 11327 uint8_t *iv_ptr; 11328 int32_t cipher_len, crc_len; 11329 uint32_t crc_data_len; 11330 int ret = TEST_SUCCESS; 11331 11332 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 11333 11334 /* Verify the capabilities */ 11335 struct rte_security_capability_idx sec_cap_idx; 11336 const struct rte_security_capability *sec_cap; 11337 const struct rte_cryptodev_capabilities *crypto_cap; 11338 const struct rte_cryptodev_symmetric_capability *sym_cap; 11339 int j = 0; 11340 11341 /* Set action type */ 11342 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 11343 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 11344 gbl_action_type; 11345 11346 if (security_proto_supported(ut_params->type, 11347 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 11348 return TEST_SKIPPED; 11349 11350 sec_cap_idx.action = ut_params->type; 11351 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 11352 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK; 11353 11354 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 11355 if (sec_cap == NULL) 11356 return TEST_SKIPPED; 11357 11358 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 11359 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 11360 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 11361 crypto_cap->sym.xform_type == 11362 RTE_CRYPTO_SYM_XFORM_CIPHER && 11363 crypto_cap->sym.cipher.algo == 11364 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 11365 sym_cap = &crypto_cap->sym; 11366 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 11367 d_td->key.len, 11368 d_td->iv.len) == 0) 11369 break; 11370 } 11371 } 11372 11373 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 11374 return TEST_SKIPPED; 11375 11376 /* Setup source mbuf payload */ 11377 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11378 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11379 rte_pktmbuf_tailroom(ut_params->ibuf)); 11380 11381 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11382 d_td->ciphertext.len); 11383 11384 memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len); 11385 11386 /* Setup cipher session parameters */ 11387 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11388 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 11389 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 11390 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 11391 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 11392 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 11393 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 11394 ut_params->cipher_xform.next = NULL; 11395 11396 /* Setup DOCSIS session parameters */ 11397 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK; 11398 11399 struct rte_security_session_conf sess_conf = { 11400 .action_type = ut_params->type, 11401 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 11402 .docsis = ut_params->docsis_xform, 11403 .crypto_xform = &ut_params->cipher_xform, 11404 }; 11405 11406 /* Create security session */ 11407 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 11408 ts_params->session_mpool); 11409 11410 if (!ut_params->sec_session) { 11411 printf("Test function %s line %u: failed to allocate session\n", 11412 __func__, __LINE__); 11413 ret = TEST_FAILED; 11414 goto on_err; 11415 } 11416 11417 /* Generate crypto op data structure */ 11418 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11419 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11420 if (!ut_params->op) { 11421 printf("Test function %s line %u: failed to allocate symmetric " 11422 "crypto operation\n", __func__, __LINE__); 11423 ret = TEST_FAILED; 11424 goto on_err; 11425 } 11426 11427 /* Setup CRC operation parameters */ 11428 crc_len = d_td->ciphertext.no_crc == false ? 11429 (d_td->ciphertext.len - 11430 d_td->ciphertext.crc_offset - 11431 RTE_ETHER_CRC_LEN) : 11432 0; 11433 crc_len = crc_len > 0 ? crc_len : 0; 11434 crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN; 11435 ut_params->op->sym->auth.data.length = crc_len; 11436 ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset; 11437 11438 /* Setup cipher operation parameters */ 11439 cipher_len = d_td->ciphertext.no_cipher == false ? 11440 (d_td->ciphertext.len - 11441 d_td->ciphertext.cipher_offset) : 11442 0; 11443 cipher_len = cipher_len > 0 ? cipher_len : 0; 11444 ut_params->op->sym->cipher.data.length = cipher_len; 11445 ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset; 11446 11447 /* Setup cipher IV */ 11448 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 11449 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 11450 11451 /* Attach session to operation */ 11452 rte_security_attach_session(ut_params->op, ut_params->sec_session); 11453 11454 /* Set crypto operation mbufs */ 11455 ut_params->op->sym->m_src = ut_params->ibuf; 11456 ut_params->op->sym->m_dst = NULL; 11457 11458 /* Process crypto operation */ 11459 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 11460 NULL) { 11461 printf("Test function %s line %u: failed to process security " 11462 "crypto op\n", __func__, __LINE__); 11463 ret = TEST_FAILED; 11464 goto on_err; 11465 } 11466 11467 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 11468 printf("Test function %s line %u: failed to process crypto op\n", 11469 __func__, __LINE__); 11470 ret = TEST_FAILED; 11471 goto on_err; 11472 } 11473 11474 /* Validate plaintext */ 11475 plaintext = ciphertext; 11476 11477 if (memcmp(plaintext, d_td->plaintext.data, 11478 d_td->plaintext.len - crc_data_len)) { 11479 printf("Test function %s line %u: plaintext not as expected\n", 11480 __func__, __LINE__); 11481 rte_hexdump(stdout, "expected", d_td->plaintext.data, 11482 d_td->plaintext.len); 11483 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len); 11484 ret = TEST_FAILED; 11485 goto on_err; 11486 } 11487 11488 on_err: 11489 rte_crypto_op_free(ut_params->op); 11490 ut_params->op = NULL; 11491 11492 if (ut_params->sec_session) 11493 rte_security_session_destroy(ctx, ut_params->sec_session); 11494 ut_params->sec_session = NULL; 11495 11496 rte_pktmbuf_free(ut_params->ibuf); 11497 ut_params->ibuf = NULL; 11498 11499 return ret; 11500 } 11501 11502 static int 11503 test_docsis_proto_downlink(const void *data) 11504 { 11505 const struct docsis_test_data *d_td = data; 11506 struct crypto_testsuite_params *ts_params = &testsuite_params; 11507 struct crypto_unittest_params *ut_params = &unittest_params; 11508 uint8_t *plaintext = NULL; 11509 uint8_t *ciphertext = NULL; 11510 uint8_t *iv_ptr; 11511 int32_t cipher_len, crc_len; 11512 int ret = TEST_SUCCESS; 11513 11514 void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]); 11515 11516 /* Verify the capabilities */ 11517 struct rte_security_capability_idx sec_cap_idx; 11518 const struct rte_security_capability *sec_cap; 11519 const struct rte_cryptodev_capabilities *crypto_cap; 11520 const struct rte_cryptodev_symmetric_capability *sym_cap; 11521 int j = 0; 11522 11523 /* Set action type */ 11524 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 11525 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 11526 gbl_action_type; 11527 11528 if (security_proto_supported(ut_params->type, 11529 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 11530 return TEST_SKIPPED; 11531 11532 sec_cap_idx.action = ut_params->type; 11533 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 11534 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 11535 11536 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 11537 if (sec_cap == NULL) 11538 return TEST_SKIPPED; 11539 11540 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 11541 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 11542 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 11543 crypto_cap->sym.xform_type == 11544 RTE_CRYPTO_SYM_XFORM_CIPHER && 11545 crypto_cap->sym.cipher.algo == 11546 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 11547 sym_cap = &crypto_cap->sym; 11548 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 11549 d_td->key.len, 11550 d_td->iv.len) == 0) 11551 break; 11552 } 11553 } 11554 11555 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 11556 return TEST_SKIPPED; 11557 11558 /* Setup source mbuf payload */ 11559 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11560 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11561 rte_pktmbuf_tailroom(ut_params->ibuf)); 11562 11563 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11564 d_td->plaintext.len); 11565 11566 memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len); 11567 11568 /* Setup cipher session parameters */ 11569 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11570 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 11571 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 11572 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 11573 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 11574 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 11575 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 11576 ut_params->cipher_xform.next = NULL; 11577 11578 /* Setup DOCSIS session parameters */ 11579 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 11580 11581 struct rte_security_session_conf sess_conf = { 11582 .action_type = ut_params->type, 11583 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 11584 .docsis = ut_params->docsis_xform, 11585 .crypto_xform = &ut_params->cipher_xform, 11586 }; 11587 11588 /* Create security session */ 11589 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 11590 ts_params->session_mpool); 11591 11592 if (!ut_params->sec_session) { 11593 printf("Test function %s line %u: failed to allocate session\n", 11594 __func__, __LINE__); 11595 ret = TEST_FAILED; 11596 goto on_err; 11597 } 11598 11599 /* Generate crypto op data structure */ 11600 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11601 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11602 if (!ut_params->op) { 11603 printf("Test function %s line %u: failed to allocate symmetric " 11604 "crypto operation\n", __func__, __LINE__); 11605 ret = TEST_FAILED; 11606 goto on_err; 11607 } 11608 11609 /* Setup CRC operation parameters */ 11610 crc_len = d_td->plaintext.no_crc == false ? 11611 (d_td->plaintext.len - 11612 d_td->plaintext.crc_offset - 11613 RTE_ETHER_CRC_LEN) : 11614 0; 11615 crc_len = crc_len > 0 ? crc_len : 0; 11616 ut_params->op->sym->auth.data.length = crc_len; 11617 ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset; 11618 11619 /* Setup cipher operation parameters */ 11620 cipher_len = d_td->plaintext.no_cipher == false ? 11621 (d_td->plaintext.len - 11622 d_td->plaintext.cipher_offset) : 11623 0; 11624 cipher_len = cipher_len > 0 ? cipher_len : 0; 11625 ut_params->op->sym->cipher.data.length = cipher_len; 11626 ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset; 11627 11628 /* Setup cipher IV */ 11629 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 11630 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 11631 11632 /* Attach session to operation */ 11633 rte_security_attach_session(ut_params->op, ut_params->sec_session); 11634 11635 /* Set crypto operation mbufs */ 11636 ut_params->op->sym->m_src = ut_params->ibuf; 11637 ut_params->op->sym->m_dst = NULL; 11638 11639 /* Process crypto operation */ 11640 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 11641 NULL) { 11642 printf("Test function %s line %u: failed to process crypto op\n", 11643 __func__, __LINE__); 11644 ret = TEST_FAILED; 11645 goto on_err; 11646 } 11647 11648 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 11649 printf("Test function %s line %u: crypto op processing failed\n", 11650 __func__, __LINE__); 11651 ret = TEST_FAILED; 11652 goto on_err; 11653 } 11654 11655 /* Validate ciphertext */ 11656 ciphertext = plaintext; 11657 11658 if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) { 11659 printf("Test function %s line %u: plaintext not as expected\n", 11660 __func__, __LINE__); 11661 rte_hexdump(stdout, "expected", d_td->ciphertext.data, 11662 d_td->ciphertext.len); 11663 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len); 11664 ret = TEST_FAILED; 11665 goto on_err; 11666 } 11667 11668 on_err: 11669 rte_crypto_op_free(ut_params->op); 11670 ut_params->op = NULL; 11671 11672 if (ut_params->sec_session) 11673 rte_security_session_destroy(ctx, ut_params->sec_session); 11674 ut_params->sec_session = NULL; 11675 11676 rte_pktmbuf_free(ut_params->ibuf); 11677 ut_params->ibuf = NULL; 11678 11679 return ret; 11680 } 11681 #endif 11682 11683 static int 11684 test_AES_GCM_authenticated_encryption_test_case_1(void) 11685 { 11686 return test_authenticated_encryption(&gcm_test_case_1); 11687 } 11688 11689 static int 11690 test_AES_GCM_authenticated_encryption_test_case_2(void) 11691 { 11692 return test_authenticated_encryption(&gcm_test_case_2); 11693 } 11694 11695 static int 11696 test_AES_GCM_authenticated_encryption_test_case_3(void) 11697 { 11698 return test_authenticated_encryption(&gcm_test_case_3); 11699 } 11700 11701 static int 11702 test_AES_GCM_authenticated_encryption_test_case_4(void) 11703 { 11704 return test_authenticated_encryption(&gcm_test_case_4); 11705 } 11706 11707 static int 11708 test_AES_GCM_authenticated_encryption_test_case_5(void) 11709 { 11710 return test_authenticated_encryption(&gcm_test_case_5); 11711 } 11712 11713 static int 11714 test_AES_GCM_authenticated_encryption_test_case_6(void) 11715 { 11716 return test_authenticated_encryption(&gcm_test_case_6); 11717 } 11718 11719 static int 11720 test_AES_GCM_authenticated_encryption_test_case_7(void) 11721 { 11722 return test_authenticated_encryption(&gcm_test_case_7); 11723 } 11724 11725 static int 11726 test_AES_GCM_authenticated_encryption_test_case_8(void) 11727 { 11728 return test_authenticated_encryption(&gcm_test_case_8); 11729 } 11730 11731 static int 11732 test_AES_GCM_J0_authenticated_encryption_test_case_1(void) 11733 { 11734 return test_authenticated_encryption(&gcm_J0_test_case_1); 11735 } 11736 11737 static int 11738 test_AES_GCM_auth_encryption_test_case_192_1(void) 11739 { 11740 return test_authenticated_encryption(&gcm_test_case_192_1); 11741 } 11742 11743 static int 11744 test_AES_GCM_auth_encryption_test_case_192_2(void) 11745 { 11746 return test_authenticated_encryption(&gcm_test_case_192_2); 11747 } 11748 11749 static int 11750 test_AES_GCM_auth_encryption_test_case_192_3(void) 11751 { 11752 return test_authenticated_encryption(&gcm_test_case_192_3); 11753 } 11754 11755 static int 11756 test_AES_GCM_auth_encryption_test_case_192_4(void) 11757 { 11758 return test_authenticated_encryption(&gcm_test_case_192_4); 11759 } 11760 11761 static int 11762 test_AES_GCM_auth_encryption_test_case_192_5(void) 11763 { 11764 return test_authenticated_encryption(&gcm_test_case_192_5); 11765 } 11766 11767 static int 11768 test_AES_GCM_auth_encryption_test_case_192_6(void) 11769 { 11770 return test_authenticated_encryption(&gcm_test_case_192_6); 11771 } 11772 11773 static int 11774 test_AES_GCM_auth_encryption_test_case_192_7(void) 11775 { 11776 return test_authenticated_encryption(&gcm_test_case_192_7); 11777 } 11778 11779 static int 11780 test_AES_GCM_auth_encryption_test_case_256_1(void) 11781 { 11782 return test_authenticated_encryption(&gcm_test_case_256_1); 11783 } 11784 11785 static int 11786 test_AES_GCM_auth_encryption_test_case_256_2(void) 11787 { 11788 return test_authenticated_encryption(&gcm_test_case_256_2); 11789 } 11790 11791 static int 11792 test_AES_GCM_auth_encryption_test_case_256_3(void) 11793 { 11794 return test_authenticated_encryption(&gcm_test_case_256_3); 11795 } 11796 11797 static int 11798 test_AES_GCM_auth_encryption_test_case_256_4(void) 11799 { 11800 return test_authenticated_encryption(&gcm_test_case_256_4); 11801 } 11802 11803 static int 11804 test_AES_GCM_auth_encryption_test_case_256_5(void) 11805 { 11806 return test_authenticated_encryption(&gcm_test_case_256_5); 11807 } 11808 11809 static int 11810 test_AES_GCM_auth_encryption_test_case_256_6(void) 11811 { 11812 return test_authenticated_encryption(&gcm_test_case_256_6); 11813 } 11814 11815 static int 11816 test_AES_GCM_auth_encryption_test_case_256_7(void) 11817 { 11818 return test_authenticated_encryption(&gcm_test_case_256_7); 11819 } 11820 11821 static int 11822 test_AES_GCM_auth_encryption_test_case_aad_1(void) 11823 { 11824 return test_authenticated_encryption(&gcm_test_case_aad_1); 11825 } 11826 11827 static int 11828 test_AES_GCM_auth_encryption_test_case_aad_2(void) 11829 { 11830 return test_authenticated_encryption(&gcm_test_case_aad_2); 11831 } 11832 11833 static int 11834 test_AES_GCM_auth_encryption_fail_iv_corrupt(void) 11835 { 11836 struct aead_test_data tdata; 11837 int res; 11838 11839 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11840 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11841 tdata.iv.data[0] += 1; 11842 res = test_authenticated_encryption(&tdata); 11843 if (res == TEST_SKIPPED) 11844 return res; 11845 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 11846 return TEST_SUCCESS; 11847 } 11848 11849 static int 11850 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void) 11851 { 11852 struct aead_test_data tdata; 11853 int res; 11854 11855 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11856 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11857 tdata.plaintext.data[0] += 1; 11858 res = test_authenticated_encryption(&tdata); 11859 if (res == TEST_SKIPPED) 11860 return res; 11861 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 11862 return TEST_SUCCESS; 11863 } 11864 11865 static int 11866 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void) 11867 { 11868 struct aead_test_data tdata; 11869 int res; 11870 11871 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11872 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11873 tdata.ciphertext.data[0] += 1; 11874 res = test_authenticated_encryption(&tdata); 11875 if (res == TEST_SKIPPED) 11876 return res; 11877 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 11878 return TEST_SUCCESS; 11879 } 11880 11881 static int 11882 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void) 11883 { 11884 struct aead_test_data tdata; 11885 int res; 11886 11887 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11888 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11889 tdata.aad.len += 1; 11890 res = test_authenticated_encryption(&tdata); 11891 if (res == TEST_SKIPPED) 11892 return res; 11893 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 11894 return TEST_SUCCESS; 11895 } 11896 11897 static int 11898 test_AES_GCM_auth_encryption_fail_aad_corrupt(void) 11899 { 11900 struct aead_test_data tdata; 11901 uint8_t aad[gcm_test_case_7.aad.len]; 11902 int res; 11903 11904 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11905 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11906 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 11907 aad[0] += 1; 11908 tdata.aad.data = aad; 11909 res = test_authenticated_encryption(&tdata); 11910 if (res == TEST_SKIPPED) 11911 return res; 11912 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 11913 return TEST_SUCCESS; 11914 } 11915 11916 static int 11917 test_AES_GCM_auth_encryption_fail_tag_corrupt(void) 11918 { 11919 struct aead_test_data tdata; 11920 int res; 11921 11922 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 11923 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 11924 tdata.auth_tag.data[0] += 1; 11925 res = test_authenticated_encryption(&tdata); 11926 if (res == TEST_SKIPPED) 11927 return res; 11928 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 11929 return TEST_SUCCESS; 11930 } 11931 11932 static int 11933 test_authenticated_decryption(const struct aead_test_data *tdata) 11934 { 11935 struct crypto_testsuite_params *ts_params = &testsuite_params; 11936 struct crypto_unittest_params *ut_params = &unittest_params; 11937 11938 int retval; 11939 uint8_t *plaintext; 11940 uint32_t i; 11941 struct rte_cryptodev_info dev_info; 11942 11943 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11944 uint64_t feat_flags = dev_info.feature_flags; 11945 11946 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11947 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11948 printf("Device doesn't support RAW data-path APIs.\n"); 11949 return TEST_SKIPPED; 11950 } 11951 11952 /* Verify the capabilities */ 11953 struct rte_cryptodev_sym_capability_idx cap_idx; 11954 const struct rte_cryptodev_symmetric_capability *capability; 11955 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 11956 cap_idx.algo.aead = tdata->algo; 11957 capability = rte_cryptodev_sym_capability_get( 11958 ts_params->valid_devs[0], &cap_idx); 11959 if (capability == NULL) 11960 return TEST_SKIPPED; 11961 if (rte_cryptodev_sym_capability_check_aead( 11962 capability, tdata->key.len, tdata->auth_tag.len, 11963 tdata->aad.len, tdata->iv.len)) 11964 return TEST_SKIPPED; 11965 11966 /* Create AEAD session */ 11967 retval = create_aead_session(ts_params->valid_devs[0], 11968 tdata->algo, 11969 RTE_CRYPTO_AEAD_OP_DECRYPT, 11970 tdata->key.data, tdata->key.len, 11971 tdata->aad.len, tdata->auth_tag.len, 11972 tdata->iv.len); 11973 if (retval != TEST_SUCCESS) 11974 return retval; 11975 11976 /* alloc mbuf and set payload */ 11977 if (tdata->aad.len > MBUF_SIZE) { 11978 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 11979 /* Populate full size of add data */ 11980 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 11981 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 11982 } else 11983 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11984 11985 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11986 rte_pktmbuf_tailroom(ut_params->ibuf)); 11987 11988 /* Create AEAD operation */ 11989 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 11990 if (retval < 0) 11991 return retval; 11992 11993 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11994 11995 ut_params->op->sym->m_src = ut_params->ibuf; 11996 11997 /* Process crypto operation */ 11998 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11999 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 12000 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 12001 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 12002 0); 12003 if (retval != TEST_SUCCESS) 12004 return retval; 12005 } else 12006 TEST_ASSERT_NOT_NULL( 12007 process_crypto_request(ts_params->valid_devs[0], 12008 ut_params->op), "failed to process sym crypto op"); 12009 12010 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12011 "crypto op processing failed"); 12012 12013 if (ut_params->op->sym->m_dst) 12014 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 12015 uint8_t *); 12016 else 12017 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 12018 uint8_t *, 12019 ut_params->op->sym->cipher.data.offset); 12020 12021 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 12022 12023 /* Validate obuf */ 12024 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12025 plaintext, 12026 tdata->plaintext.data, 12027 tdata->plaintext.len, 12028 "Plaintext data not as expected"); 12029 12030 TEST_ASSERT_EQUAL(ut_params->op->status, 12031 RTE_CRYPTO_OP_STATUS_SUCCESS, 12032 "Authentication failed"); 12033 12034 return 0; 12035 } 12036 12037 static int 12038 test_AES_GCM_authenticated_decryption_test_case_1(void) 12039 { 12040 return test_authenticated_decryption(&gcm_test_case_1); 12041 } 12042 12043 static int 12044 test_AES_GCM_authenticated_decryption_test_case_2(void) 12045 { 12046 return test_authenticated_decryption(&gcm_test_case_2); 12047 } 12048 12049 static int 12050 test_AES_GCM_authenticated_decryption_test_case_3(void) 12051 { 12052 return test_authenticated_decryption(&gcm_test_case_3); 12053 } 12054 12055 static int 12056 test_AES_GCM_authenticated_decryption_test_case_4(void) 12057 { 12058 return test_authenticated_decryption(&gcm_test_case_4); 12059 } 12060 12061 static int 12062 test_AES_GCM_authenticated_decryption_test_case_5(void) 12063 { 12064 return test_authenticated_decryption(&gcm_test_case_5); 12065 } 12066 12067 static int 12068 test_AES_GCM_authenticated_decryption_test_case_6(void) 12069 { 12070 return test_authenticated_decryption(&gcm_test_case_6); 12071 } 12072 12073 static int 12074 test_AES_GCM_authenticated_decryption_test_case_7(void) 12075 { 12076 return test_authenticated_decryption(&gcm_test_case_7); 12077 } 12078 12079 static int 12080 test_AES_GCM_authenticated_decryption_test_case_8(void) 12081 { 12082 return test_authenticated_decryption(&gcm_test_case_8); 12083 } 12084 12085 static int 12086 test_AES_GCM_J0_authenticated_decryption_test_case_1(void) 12087 { 12088 return test_authenticated_decryption(&gcm_J0_test_case_1); 12089 } 12090 12091 static int 12092 test_AES_GCM_auth_decryption_test_case_192_1(void) 12093 { 12094 return test_authenticated_decryption(&gcm_test_case_192_1); 12095 } 12096 12097 static int 12098 test_AES_GCM_auth_decryption_test_case_192_2(void) 12099 { 12100 return test_authenticated_decryption(&gcm_test_case_192_2); 12101 } 12102 12103 static int 12104 test_AES_GCM_auth_decryption_test_case_192_3(void) 12105 { 12106 return test_authenticated_decryption(&gcm_test_case_192_3); 12107 } 12108 12109 static int 12110 test_AES_GCM_auth_decryption_test_case_192_4(void) 12111 { 12112 return test_authenticated_decryption(&gcm_test_case_192_4); 12113 } 12114 12115 static int 12116 test_AES_GCM_auth_decryption_test_case_192_5(void) 12117 { 12118 return test_authenticated_decryption(&gcm_test_case_192_5); 12119 } 12120 12121 static int 12122 test_AES_GCM_auth_decryption_test_case_192_6(void) 12123 { 12124 return test_authenticated_decryption(&gcm_test_case_192_6); 12125 } 12126 12127 static int 12128 test_AES_GCM_auth_decryption_test_case_192_7(void) 12129 { 12130 return test_authenticated_decryption(&gcm_test_case_192_7); 12131 } 12132 12133 static int 12134 test_AES_GCM_auth_decryption_test_case_256_1(void) 12135 { 12136 return test_authenticated_decryption(&gcm_test_case_256_1); 12137 } 12138 12139 static int 12140 test_AES_GCM_auth_decryption_test_case_256_2(void) 12141 { 12142 return test_authenticated_decryption(&gcm_test_case_256_2); 12143 } 12144 12145 static int 12146 test_AES_GCM_auth_decryption_test_case_256_3(void) 12147 { 12148 return test_authenticated_decryption(&gcm_test_case_256_3); 12149 } 12150 12151 static int 12152 test_AES_GCM_auth_decryption_test_case_256_4(void) 12153 { 12154 return test_authenticated_decryption(&gcm_test_case_256_4); 12155 } 12156 12157 static int 12158 test_AES_GCM_auth_decryption_test_case_256_5(void) 12159 { 12160 return test_authenticated_decryption(&gcm_test_case_256_5); 12161 } 12162 12163 static int 12164 test_AES_GCM_auth_decryption_test_case_256_6(void) 12165 { 12166 return test_authenticated_decryption(&gcm_test_case_256_6); 12167 } 12168 12169 static int 12170 test_AES_GCM_auth_decryption_test_case_256_7(void) 12171 { 12172 return test_authenticated_decryption(&gcm_test_case_256_7); 12173 } 12174 12175 static int 12176 test_AES_GCM_auth_decryption_test_case_aad_1(void) 12177 { 12178 return test_authenticated_decryption(&gcm_test_case_aad_1); 12179 } 12180 12181 static int 12182 test_AES_GCM_auth_decryption_test_case_aad_2(void) 12183 { 12184 return test_authenticated_decryption(&gcm_test_case_aad_2); 12185 } 12186 12187 static int 12188 test_AES_GCM_auth_decryption_fail_iv_corrupt(void) 12189 { 12190 struct aead_test_data tdata; 12191 int res; 12192 12193 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12194 tdata.iv.data[0] += 1; 12195 res = test_authenticated_decryption(&tdata); 12196 if (res == TEST_SKIPPED) 12197 return res; 12198 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12199 return TEST_SUCCESS; 12200 } 12201 12202 static int 12203 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void) 12204 { 12205 struct aead_test_data tdata; 12206 int res; 12207 12208 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 12209 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12210 tdata.plaintext.data[0] += 1; 12211 res = test_authenticated_decryption(&tdata); 12212 if (res == TEST_SKIPPED) 12213 return res; 12214 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12215 return TEST_SUCCESS; 12216 } 12217 12218 static int 12219 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void) 12220 { 12221 struct aead_test_data tdata; 12222 int res; 12223 12224 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12225 tdata.ciphertext.data[0] += 1; 12226 res = test_authenticated_decryption(&tdata); 12227 if (res == TEST_SKIPPED) 12228 return res; 12229 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12230 return TEST_SUCCESS; 12231 } 12232 12233 static int 12234 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void) 12235 { 12236 struct aead_test_data tdata; 12237 int res; 12238 12239 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12240 tdata.aad.len += 1; 12241 res = test_authenticated_decryption(&tdata); 12242 if (res == TEST_SKIPPED) 12243 return res; 12244 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12245 return TEST_SUCCESS; 12246 } 12247 12248 static int 12249 test_AES_GCM_auth_decryption_fail_aad_corrupt(void) 12250 { 12251 struct aead_test_data tdata; 12252 uint8_t aad[gcm_test_case_7.aad.len]; 12253 int res; 12254 12255 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12256 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 12257 aad[0] += 1; 12258 tdata.aad.data = aad; 12259 res = test_authenticated_decryption(&tdata); 12260 if (res == TEST_SKIPPED) 12261 return res; 12262 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 12263 return TEST_SUCCESS; 12264 } 12265 12266 static int 12267 test_AES_GCM_auth_decryption_fail_tag_corrupt(void) 12268 { 12269 struct aead_test_data tdata; 12270 int res; 12271 12272 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 12273 tdata.auth_tag.data[0] += 1; 12274 res = test_authenticated_decryption(&tdata); 12275 if (res == TEST_SKIPPED) 12276 return res; 12277 TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed"); 12278 return TEST_SUCCESS; 12279 } 12280 12281 static int 12282 test_authenticated_encryption_oop(const struct aead_test_data *tdata) 12283 { 12284 struct crypto_testsuite_params *ts_params = &testsuite_params; 12285 struct crypto_unittest_params *ut_params = &unittest_params; 12286 12287 int retval; 12288 uint8_t *ciphertext, *auth_tag; 12289 uint16_t plaintext_pad_len; 12290 struct rte_cryptodev_info dev_info; 12291 12292 /* Verify the capabilities */ 12293 struct rte_cryptodev_sym_capability_idx cap_idx; 12294 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12295 cap_idx.algo.aead = tdata->algo; 12296 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12297 &cap_idx) == NULL) 12298 return TEST_SKIPPED; 12299 12300 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12301 uint64_t feat_flags = dev_info.feature_flags; 12302 12303 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12304 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) 12305 return TEST_SKIPPED; 12306 12307 /* not supported with CPU crypto */ 12308 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12309 return TEST_SKIPPED; 12310 12311 /* Create AEAD session */ 12312 retval = create_aead_session(ts_params->valid_devs[0], 12313 tdata->algo, 12314 RTE_CRYPTO_AEAD_OP_ENCRYPT, 12315 tdata->key.data, tdata->key.len, 12316 tdata->aad.len, tdata->auth_tag.len, 12317 tdata->iv.len); 12318 if (retval < 0) 12319 return retval; 12320 12321 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12322 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12323 12324 /* clear mbuf payload */ 12325 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12326 rte_pktmbuf_tailroom(ut_params->ibuf)); 12327 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 12328 rte_pktmbuf_tailroom(ut_params->obuf)); 12329 12330 /* Create AEAD operation */ 12331 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 12332 if (retval < 0) 12333 return retval; 12334 12335 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12336 12337 ut_params->op->sym->m_src = ut_params->ibuf; 12338 ut_params->op->sym->m_dst = ut_params->obuf; 12339 12340 /* Process crypto operation */ 12341 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 12342 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 12343 0); 12344 if (retval != TEST_SUCCESS) 12345 return retval; 12346 } else 12347 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 12348 ut_params->op), "failed to process sym crypto op"); 12349 12350 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12351 "crypto op processing failed"); 12352 12353 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12354 12355 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 12356 ut_params->op->sym->cipher.data.offset); 12357 auth_tag = ciphertext + plaintext_pad_len; 12358 12359 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 12360 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 12361 12362 /* Validate obuf */ 12363 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12364 ciphertext, 12365 tdata->ciphertext.data, 12366 tdata->ciphertext.len, 12367 "Ciphertext data not as expected"); 12368 12369 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12370 auth_tag, 12371 tdata->auth_tag.data, 12372 tdata->auth_tag.len, 12373 "Generated auth tag not as expected"); 12374 12375 return 0; 12376 12377 } 12378 12379 static int 12380 test_AES_GCM_authenticated_encryption_oop_test_case_1(void) 12381 { 12382 return test_authenticated_encryption_oop(&gcm_test_case_5); 12383 } 12384 12385 static int 12386 test_authenticated_decryption_oop(const struct aead_test_data *tdata) 12387 { 12388 struct crypto_testsuite_params *ts_params = &testsuite_params; 12389 struct crypto_unittest_params *ut_params = &unittest_params; 12390 12391 int retval; 12392 uint8_t *plaintext; 12393 struct rte_cryptodev_info dev_info; 12394 12395 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12396 uint64_t feat_flags = dev_info.feature_flags; 12397 12398 /* Verify the capabilities */ 12399 struct rte_cryptodev_sym_capability_idx cap_idx; 12400 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12401 cap_idx.algo.aead = tdata->algo; 12402 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12403 &cap_idx) == NULL) 12404 return TEST_SKIPPED; 12405 12406 /* not supported with CPU crypto and raw data-path APIs*/ 12407 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO || 12408 global_api_test_type == CRYPTODEV_RAW_API_TEST) 12409 return TEST_SKIPPED; 12410 12411 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12412 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12413 printf("Device does not support RAW data-path APIs.\n"); 12414 return TEST_SKIPPED; 12415 } 12416 12417 /* Create AEAD session */ 12418 retval = create_aead_session(ts_params->valid_devs[0], 12419 tdata->algo, 12420 RTE_CRYPTO_AEAD_OP_DECRYPT, 12421 tdata->key.data, tdata->key.len, 12422 tdata->aad.len, tdata->auth_tag.len, 12423 tdata->iv.len); 12424 if (retval < 0) 12425 return retval; 12426 12427 /* alloc mbuf and set payload */ 12428 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12429 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12430 12431 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12432 rte_pktmbuf_tailroom(ut_params->ibuf)); 12433 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 12434 rte_pktmbuf_tailroom(ut_params->obuf)); 12435 12436 /* Create AEAD operation */ 12437 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 12438 if (retval < 0) 12439 return retval; 12440 12441 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12442 12443 ut_params->op->sym->m_src = ut_params->ibuf; 12444 ut_params->op->sym->m_dst = ut_params->obuf; 12445 12446 /* Process crypto operation */ 12447 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 12448 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 12449 0); 12450 if (retval != TEST_SUCCESS) 12451 return retval; 12452 } else 12453 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 12454 ut_params->op), "failed to process sym crypto op"); 12455 12456 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12457 "crypto op processing failed"); 12458 12459 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 12460 ut_params->op->sym->cipher.data.offset); 12461 12462 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 12463 12464 /* Validate obuf */ 12465 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12466 plaintext, 12467 tdata->plaintext.data, 12468 tdata->plaintext.len, 12469 "Plaintext data not as expected"); 12470 12471 TEST_ASSERT_EQUAL(ut_params->op->status, 12472 RTE_CRYPTO_OP_STATUS_SUCCESS, 12473 "Authentication failed"); 12474 return 0; 12475 } 12476 12477 static int 12478 test_AES_GCM_authenticated_decryption_oop_test_case_1(void) 12479 { 12480 return test_authenticated_decryption_oop(&gcm_test_case_5); 12481 } 12482 12483 static int 12484 test_authenticated_encryption_sessionless( 12485 const struct aead_test_data *tdata) 12486 { 12487 struct crypto_testsuite_params *ts_params = &testsuite_params; 12488 struct crypto_unittest_params *ut_params = &unittest_params; 12489 12490 int retval; 12491 uint8_t *ciphertext, *auth_tag; 12492 uint16_t plaintext_pad_len; 12493 uint8_t key[tdata->key.len + 1]; 12494 struct rte_cryptodev_info dev_info; 12495 12496 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12497 uint64_t feat_flags = dev_info.feature_flags; 12498 12499 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 12500 printf("Device doesn't support Sessionless ops.\n"); 12501 return TEST_SKIPPED; 12502 } 12503 12504 /* not supported with CPU crypto */ 12505 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12506 return TEST_SKIPPED; 12507 12508 /* Verify the capabilities */ 12509 struct rte_cryptodev_sym_capability_idx cap_idx; 12510 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12511 cap_idx.algo.aead = tdata->algo; 12512 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12513 &cap_idx) == NULL) 12514 return TEST_SKIPPED; 12515 12516 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12517 12518 /* clear mbuf payload */ 12519 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12520 rte_pktmbuf_tailroom(ut_params->ibuf)); 12521 12522 /* Create AEAD operation */ 12523 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 12524 if (retval < 0) 12525 return retval; 12526 12527 /* Create GCM xform */ 12528 memcpy(key, tdata->key.data, tdata->key.len); 12529 retval = create_aead_xform(ut_params->op, 12530 tdata->algo, 12531 RTE_CRYPTO_AEAD_OP_ENCRYPT, 12532 key, tdata->key.len, 12533 tdata->aad.len, tdata->auth_tag.len, 12534 tdata->iv.len); 12535 if (retval < 0) 12536 return retval; 12537 12538 ut_params->op->sym->m_src = ut_params->ibuf; 12539 12540 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 12541 RTE_CRYPTO_OP_SESSIONLESS, 12542 "crypto op session type not sessionless"); 12543 12544 /* Process crypto operation */ 12545 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 12546 ut_params->op), "failed to process sym crypto op"); 12547 12548 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 12549 12550 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12551 "crypto op status not success"); 12552 12553 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 12554 12555 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 12556 ut_params->op->sym->cipher.data.offset); 12557 auth_tag = ciphertext + plaintext_pad_len; 12558 12559 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 12560 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 12561 12562 /* Validate obuf */ 12563 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12564 ciphertext, 12565 tdata->ciphertext.data, 12566 tdata->ciphertext.len, 12567 "Ciphertext data not as expected"); 12568 12569 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12570 auth_tag, 12571 tdata->auth_tag.data, 12572 tdata->auth_tag.len, 12573 "Generated auth tag not as expected"); 12574 12575 return 0; 12576 12577 } 12578 12579 static int 12580 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void) 12581 { 12582 return test_authenticated_encryption_sessionless( 12583 &gcm_test_case_5); 12584 } 12585 12586 static int 12587 test_authenticated_decryption_sessionless( 12588 const struct aead_test_data *tdata) 12589 { 12590 struct crypto_testsuite_params *ts_params = &testsuite_params; 12591 struct crypto_unittest_params *ut_params = &unittest_params; 12592 12593 int retval; 12594 uint8_t *plaintext; 12595 uint8_t key[tdata->key.len + 1]; 12596 struct rte_cryptodev_info dev_info; 12597 12598 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12599 uint64_t feat_flags = dev_info.feature_flags; 12600 12601 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 12602 printf("Device doesn't support Sessionless ops.\n"); 12603 return TEST_SKIPPED; 12604 } 12605 12606 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12607 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12608 printf("Device doesn't support RAW data-path APIs.\n"); 12609 return TEST_SKIPPED; 12610 } 12611 12612 /* not supported with CPU crypto */ 12613 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12614 return TEST_SKIPPED; 12615 12616 /* Verify the capabilities */ 12617 struct rte_cryptodev_sym_capability_idx cap_idx; 12618 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12619 cap_idx.algo.aead = tdata->algo; 12620 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12621 &cap_idx) == NULL) 12622 return TEST_SKIPPED; 12623 12624 /* alloc mbuf and set payload */ 12625 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12626 12627 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12628 rte_pktmbuf_tailroom(ut_params->ibuf)); 12629 12630 /* Create AEAD operation */ 12631 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 12632 if (retval < 0) 12633 return retval; 12634 12635 /* Create AEAD xform */ 12636 memcpy(key, tdata->key.data, tdata->key.len); 12637 retval = create_aead_xform(ut_params->op, 12638 tdata->algo, 12639 RTE_CRYPTO_AEAD_OP_DECRYPT, 12640 key, tdata->key.len, 12641 tdata->aad.len, tdata->auth_tag.len, 12642 tdata->iv.len); 12643 if (retval < 0) 12644 return retval; 12645 12646 ut_params->op->sym->m_src = ut_params->ibuf; 12647 12648 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 12649 RTE_CRYPTO_OP_SESSIONLESS, 12650 "crypto op session type not sessionless"); 12651 12652 /* Process crypto operation */ 12653 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 12654 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 12655 0); 12656 if (retval != TEST_SUCCESS) 12657 return retval; 12658 } else 12659 TEST_ASSERT_NOT_NULL(process_crypto_request( 12660 ts_params->valid_devs[0], ut_params->op), 12661 "failed to process sym crypto op"); 12662 12663 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 12664 12665 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12666 "crypto op status not success"); 12667 12668 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 12669 ut_params->op->sym->cipher.data.offset); 12670 12671 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 12672 12673 /* Validate obuf */ 12674 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12675 plaintext, 12676 tdata->plaintext.data, 12677 tdata->plaintext.len, 12678 "Plaintext data not as expected"); 12679 12680 TEST_ASSERT_EQUAL(ut_params->op->status, 12681 RTE_CRYPTO_OP_STATUS_SUCCESS, 12682 "Authentication failed"); 12683 return 0; 12684 } 12685 12686 static int 12687 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void) 12688 { 12689 return test_authenticated_decryption_sessionless( 12690 &gcm_test_case_5); 12691 } 12692 12693 static int 12694 test_AES_CCM_authenticated_encryption_test_case_128_1(void) 12695 { 12696 return test_authenticated_encryption(&ccm_test_case_128_1); 12697 } 12698 12699 static int 12700 test_AES_CCM_authenticated_encryption_test_case_128_2(void) 12701 { 12702 return test_authenticated_encryption(&ccm_test_case_128_2); 12703 } 12704 12705 static int 12706 test_AES_CCM_authenticated_encryption_test_case_128_3(void) 12707 { 12708 return test_authenticated_encryption(&ccm_test_case_128_3); 12709 } 12710 12711 static int 12712 test_AES_CCM_authenticated_decryption_test_case_128_1(void) 12713 { 12714 return test_authenticated_decryption(&ccm_test_case_128_1); 12715 } 12716 12717 static int 12718 test_AES_CCM_authenticated_decryption_test_case_128_2(void) 12719 { 12720 return test_authenticated_decryption(&ccm_test_case_128_2); 12721 } 12722 12723 static int 12724 test_AES_CCM_authenticated_decryption_test_case_128_3(void) 12725 { 12726 return test_authenticated_decryption(&ccm_test_case_128_3); 12727 } 12728 12729 static int 12730 test_AES_CCM_authenticated_encryption_test_case_192_1(void) 12731 { 12732 return test_authenticated_encryption(&ccm_test_case_192_1); 12733 } 12734 12735 static int 12736 test_AES_CCM_authenticated_encryption_test_case_192_2(void) 12737 { 12738 return test_authenticated_encryption(&ccm_test_case_192_2); 12739 } 12740 12741 static int 12742 test_AES_CCM_authenticated_encryption_test_case_192_3(void) 12743 { 12744 return test_authenticated_encryption(&ccm_test_case_192_3); 12745 } 12746 12747 static int 12748 test_AES_CCM_authenticated_decryption_test_case_192_1(void) 12749 { 12750 return test_authenticated_decryption(&ccm_test_case_192_1); 12751 } 12752 12753 static int 12754 test_AES_CCM_authenticated_decryption_test_case_192_2(void) 12755 { 12756 return test_authenticated_decryption(&ccm_test_case_192_2); 12757 } 12758 12759 static int 12760 test_AES_CCM_authenticated_decryption_test_case_192_3(void) 12761 { 12762 return test_authenticated_decryption(&ccm_test_case_192_3); 12763 } 12764 12765 static int 12766 test_AES_CCM_authenticated_encryption_test_case_256_1(void) 12767 { 12768 return test_authenticated_encryption(&ccm_test_case_256_1); 12769 } 12770 12771 static int 12772 test_AES_CCM_authenticated_encryption_test_case_256_2(void) 12773 { 12774 return test_authenticated_encryption(&ccm_test_case_256_2); 12775 } 12776 12777 static int 12778 test_AES_CCM_authenticated_encryption_test_case_256_3(void) 12779 { 12780 return test_authenticated_encryption(&ccm_test_case_256_3); 12781 } 12782 12783 static int 12784 test_AES_CCM_authenticated_decryption_test_case_256_1(void) 12785 { 12786 return test_authenticated_decryption(&ccm_test_case_256_1); 12787 } 12788 12789 static int 12790 test_AES_CCM_authenticated_decryption_test_case_256_2(void) 12791 { 12792 return test_authenticated_decryption(&ccm_test_case_256_2); 12793 } 12794 12795 static int 12796 test_AES_CCM_authenticated_decryption_test_case_256_3(void) 12797 { 12798 return test_authenticated_decryption(&ccm_test_case_256_3); 12799 } 12800 12801 static int 12802 test_stats(void) 12803 { 12804 struct crypto_testsuite_params *ts_params = &testsuite_params; 12805 struct rte_cryptodev_stats stats; 12806 12807 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12808 return TEST_SKIPPED; 12809 12810 /* Verify the capabilities */ 12811 struct rte_cryptodev_sym_capability_idx cap_idx; 12812 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12813 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 12814 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12815 &cap_idx) == NULL) 12816 return TEST_SKIPPED; 12817 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12818 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 12819 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12820 &cap_idx) == NULL) 12821 return TEST_SKIPPED; 12822 12823 if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 12824 == -ENOTSUP) 12825 return TEST_SKIPPED; 12826 12827 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 12828 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 12829 &stats) == -ENODEV), 12830 "rte_cryptodev_stats_get invalid dev failed"); 12831 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 12832 "rte_cryptodev_stats_get invalid Param failed"); 12833 12834 /* Test expected values */ 12835 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 12836 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 12837 &stats), 12838 "rte_cryptodev_stats_get failed"); 12839 TEST_ASSERT((stats.enqueued_count == 1), 12840 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 12841 TEST_ASSERT((stats.dequeued_count == 1), 12842 "rte_cryptodev_stats_get returned unexpected dequeued stat"); 12843 TEST_ASSERT((stats.enqueue_err_count == 0), 12844 "rte_cryptodev_stats_get returned unexpected enqueued error count stat"); 12845 TEST_ASSERT((stats.dequeue_err_count == 0), 12846 "rte_cryptodev_stats_get returned unexpected dequeued error count stat"); 12847 12848 /* invalid device but should ignore and not reset device stats*/ 12849 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 12850 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 12851 &stats), 12852 "rte_cryptodev_stats_get failed"); 12853 TEST_ASSERT((stats.enqueued_count == 1), 12854 "rte_cryptodev_stats_get returned unexpected enqueued stat after invalid reset"); 12855 12856 /* check that a valid reset clears stats */ 12857 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 12858 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 12859 &stats), 12860 "rte_cryptodev_stats_get failed"); 12861 TEST_ASSERT((stats.enqueued_count == 0), 12862 "rte_cryptodev_stats_get returned unexpected enqueued stat after valid reset"); 12863 TEST_ASSERT((stats.dequeued_count == 0), 12864 "rte_cryptodev_stats_get returned unexpected dequeued stat after valid reset"); 12865 12866 return TEST_SUCCESS; 12867 } 12868 12869 static int 12870 test_device_reconfigure(void) 12871 { 12872 struct crypto_testsuite_params *ts_params = &testsuite_params; 12873 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 12874 struct rte_cryptodev_qp_conf qp_conf = { 12875 .nb_descriptors = MAX_NUM_OPS_INFLIGHT, 12876 .mp_session = ts_params->session_mpool 12877 }; 12878 uint16_t qp_id, dev_id, num_devs = 0; 12879 12880 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 12881 "Need at least %d devices for test", 1); 12882 12883 dev_id = ts_params->valid_devs[0]; 12884 12885 /* Stop the device in case it's started so it can be configured */ 12886 rte_cryptodev_stop(dev_id); 12887 12888 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 12889 "Failed test for rte_cryptodev_configure: " 12890 "dev_num %u", dev_id); 12891 12892 /* Reconfigure with same configure params */ 12893 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 12894 "Failed test for rte_cryptodev_configure: " 12895 "dev_num %u", dev_id); 12896 12897 /* Reconfigure with just one queue pair */ 12898 ts_params->conf.nb_queue_pairs = 1; 12899 12900 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 12901 &ts_params->conf), 12902 "Failed to configure cryptodev: dev_id %u, qp_id %u", 12903 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 12904 12905 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 12906 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 12907 ts_params->valid_devs[0], qp_id, &qp_conf, 12908 rte_cryptodev_socket_id( 12909 ts_params->valid_devs[0])), 12910 "Failed test for " 12911 "rte_cryptodev_queue_pair_setup: num_inflights " 12912 "%u on qp %u on cryptodev %u", 12913 qp_conf.nb_descriptors, qp_id, 12914 ts_params->valid_devs[0]); 12915 } 12916 12917 /* Reconfigure with max number of queue pairs */ 12918 ts_params->conf.nb_queue_pairs = orig_nb_qps; 12919 12920 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 12921 &ts_params->conf), 12922 "Failed to configure cryptodev: dev_id %u, qp_id %u", 12923 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 12924 12925 qp_conf.mp_session = ts_params->session_mpool; 12926 12927 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 12928 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 12929 ts_params->valid_devs[0], qp_id, &qp_conf, 12930 rte_cryptodev_socket_id( 12931 ts_params->valid_devs[0])), 12932 "Failed test for " 12933 "rte_cryptodev_queue_pair_setup: num_inflights " 12934 "%u on qp %u on cryptodev %u", 12935 qp_conf.nb_descriptors, qp_id, 12936 ts_params->valid_devs[0]); 12937 } 12938 12939 /* Start the device */ 12940 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 12941 "Failed to start cryptodev %u", 12942 ts_params->valid_devs[0]); 12943 12944 /* Test expected values */ 12945 return test_AES_CBC_HMAC_SHA1_encrypt_digest(); 12946 } 12947 12948 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 12949 struct crypto_unittest_params *ut_params, 12950 enum rte_crypto_auth_operation op, 12951 const struct HMAC_MD5_vector *test_case) 12952 { 12953 uint8_t key[64]; 12954 12955 memcpy(key, test_case->key.data, test_case->key.len); 12956 12957 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12958 ut_params->auth_xform.next = NULL; 12959 ut_params->auth_xform.auth.op = op; 12960 12961 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 12962 12963 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 12964 ut_params->auth_xform.auth.key.length = test_case->key.len; 12965 ut_params->auth_xform.auth.key.data = key; 12966 12967 ut_params->sess = rte_cryptodev_sym_session_create( 12968 ts_params->valid_devs[0], &ut_params->auth_xform, 12969 ts_params->session_mpool); 12970 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 12971 return TEST_SKIPPED; 12972 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12973 12974 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12975 12976 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12977 rte_pktmbuf_tailroom(ut_params->ibuf)); 12978 12979 return 0; 12980 } 12981 12982 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 12983 const struct HMAC_MD5_vector *test_case, 12984 uint8_t **plaintext) 12985 { 12986 uint16_t plaintext_pad_len; 12987 12988 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12989 12990 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 12991 16); 12992 12993 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12994 plaintext_pad_len); 12995 memcpy(*plaintext, test_case->plaintext.data, 12996 test_case->plaintext.len); 12997 12998 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 12999 ut_params->ibuf, MD5_DIGEST_LEN); 13000 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13001 "no room to append digest"); 13002 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 13003 ut_params->ibuf, plaintext_pad_len); 13004 13005 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 13006 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 13007 test_case->auth_tag.len); 13008 } 13009 13010 sym_op->auth.data.offset = 0; 13011 sym_op->auth.data.length = test_case->plaintext.len; 13012 13013 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 13014 ut_params->op->sym->m_src = ut_params->ibuf; 13015 13016 return 0; 13017 } 13018 13019 static int 13020 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 13021 { 13022 uint16_t plaintext_pad_len; 13023 uint8_t *plaintext, *auth_tag; 13024 int ret; 13025 13026 struct crypto_testsuite_params *ts_params = &testsuite_params; 13027 struct crypto_unittest_params *ut_params = &unittest_params; 13028 struct rte_cryptodev_info dev_info; 13029 13030 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13031 uint64_t feat_flags = dev_info.feature_flags; 13032 13033 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13034 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13035 printf("Device doesn't support RAW data-path APIs.\n"); 13036 return TEST_SKIPPED; 13037 } 13038 13039 /* Verify the capabilities */ 13040 struct rte_cryptodev_sym_capability_idx cap_idx; 13041 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13042 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 13043 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13044 &cap_idx) == NULL) 13045 return TEST_SKIPPED; 13046 13047 if (MD5_HMAC_create_session(ts_params, ut_params, 13048 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 13049 return TEST_FAILED; 13050 13051 /* Generate Crypto op data structure */ 13052 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13053 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13054 TEST_ASSERT_NOT_NULL(ut_params->op, 13055 "Failed to allocate symmetric crypto operation struct"); 13056 13057 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 13058 16); 13059 13060 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 13061 return TEST_FAILED; 13062 13063 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13064 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13065 ut_params->op); 13066 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 13067 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 0); 13068 if (ret != TEST_SUCCESS) 13069 return ret; 13070 } else 13071 TEST_ASSERT_NOT_NULL( 13072 process_crypto_request(ts_params->valid_devs[0], 13073 ut_params->op), 13074 "failed to process sym crypto op"); 13075 13076 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13077 "crypto op processing failed"); 13078 13079 if (ut_params->op->sym->m_dst) { 13080 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 13081 uint8_t *, plaintext_pad_len); 13082 } else { 13083 auth_tag = plaintext + plaintext_pad_len; 13084 } 13085 13086 TEST_ASSERT_BUFFERS_ARE_EQUAL( 13087 auth_tag, 13088 test_case->auth_tag.data, 13089 test_case->auth_tag.len, 13090 "HMAC_MD5 generated tag not as expected"); 13091 13092 return TEST_SUCCESS; 13093 } 13094 13095 static int 13096 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 13097 { 13098 uint8_t *plaintext; 13099 int ret; 13100 13101 struct crypto_testsuite_params *ts_params = &testsuite_params; 13102 struct crypto_unittest_params *ut_params = &unittest_params; 13103 struct rte_cryptodev_info dev_info; 13104 13105 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13106 uint64_t feat_flags = dev_info.feature_flags; 13107 13108 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13109 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13110 printf("Device doesn't support RAW data-path APIs.\n"); 13111 return TEST_SKIPPED; 13112 } 13113 13114 /* Verify the capabilities */ 13115 struct rte_cryptodev_sym_capability_idx cap_idx; 13116 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13117 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 13118 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13119 &cap_idx) == NULL) 13120 return TEST_SKIPPED; 13121 13122 if (MD5_HMAC_create_session(ts_params, ut_params, 13123 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 13124 return TEST_FAILED; 13125 } 13126 13127 /* Generate Crypto op data structure */ 13128 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13129 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13130 TEST_ASSERT_NOT_NULL(ut_params->op, 13131 "Failed to allocate symmetric crypto operation struct"); 13132 13133 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 13134 return TEST_FAILED; 13135 13136 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 13137 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 13138 ut_params->op); 13139 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 13140 ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 0); 13141 if (ret != TEST_SUCCESS) 13142 return ret; 13143 } else 13144 TEST_ASSERT_NOT_NULL( 13145 process_crypto_request(ts_params->valid_devs[0], 13146 ut_params->op), 13147 "failed to process sym crypto op"); 13148 13149 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 13150 "HMAC_MD5 crypto op processing failed"); 13151 13152 return TEST_SUCCESS; 13153 } 13154 13155 static int 13156 test_MD5_HMAC_generate_case_1(void) 13157 { 13158 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 13159 } 13160 13161 static int 13162 test_MD5_HMAC_verify_case_1(void) 13163 { 13164 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 13165 } 13166 13167 static int 13168 test_MD5_HMAC_generate_case_2(void) 13169 { 13170 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 13171 } 13172 13173 static int 13174 test_MD5_HMAC_verify_case_2(void) 13175 { 13176 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 13177 } 13178 13179 static int 13180 test_multi_session(void) 13181 { 13182 struct crypto_testsuite_params *ts_params = &testsuite_params; 13183 struct crypto_unittest_params *ut_params = &unittest_params; 13184 struct rte_cryptodev_info dev_info; 13185 int i, nb_sess, ret = TEST_SUCCESS; 13186 void **sessions; 13187 13188 /* Verify the capabilities */ 13189 struct rte_cryptodev_sym_capability_idx cap_idx; 13190 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13191 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 13192 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13193 &cap_idx) == NULL) 13194 return TEST_SKIPPED; 13195 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13196 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 13197 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13198 &cap_idx) == NULL) 13199 return TEST_SKIPPED; 13200 13201 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 13202 aes_cbc_key, hmac_sha512_key); 13203 13204 13205 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13206 13207 sessions = rte_malloc(NULL, 13208 sizeof(void *) * 13209 (MAX_NB_SESSIONS + 1), 0); 13210 13211 /* Create multiple crypto sessions*/ 13212 for (i = 0; i < MAX_NB_SESSIONS; i++) { 13213 sessions[i] = rte_cryptodev_sym_session_create( 13214 ts_params->valid_devs[0], &ut_params->auth_xform, 13215 ts_params->session_mpool); 13216 if (sessions[i] == NULL && rte_errno == ENOTSUP) { 13217 nb_sess = i; 13218 ret = TEST_SKIPPED; 13219 break; 13220 } 13221 13222 TEST_ASSERT_NOT_NULL(sessions[i], 13223 "Session creation failed at session number %u", 13224 i); 13225 13226 /* Attempt to send a request on each session */ 13227 ret = test_AES_CBC_HMAC_SHA512_decrypt_perform( 13228 sessions[i], 13229 ut_params, 13230 ts_params, 13231 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 13232 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 13233 aes_cbc_iv); 13234 13235 /* free crypto operation structure */ 13236 rte_crypto_op_free(ut_params->op); 13237 13238 /* 13239 * free mbuf - both obuf and ibuf are usually the same, 13240 * so check if they point at the same address is necessary, 13241 * to avoid freeing the mbuf twice. 13242 */ 13243 if (ut_params->obuf) { 13244 rte_pktmbuf_free(ut_params->obuf); 13245 if (ut_params->ibuf == ut_params->obuf) 13246 ut_params->ibuf = 0; 13247 ut_params->obuf = 0; 13248 } 13249 if (ut_params->ibuf) { 13250 rte_pktmbuf_free(ut_params->ibuf); 13251 ut_params->ibuf = 0; 13252 } 13253 13254 if (ret != TEST_SUCCESS) { 13255 i++; 13256 break; 13257 } 13258 } 13259 13260 nb_sess = i; 13261 13262 for (i = 0; i < nb_sess; i++) { 13263 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 13264 sessions[i]); 13265 } 13266 13267 rte_free(sessions); 13268 13269 if (ret != TEST_SKIPPED) 13270 TEST_ASSERT_SUCCESS(ret, "Failed to perform decrypt on request number %u.", i - 1); 13271 13272 return ret; 13273 } 13274 13275 struct multi_session_params { 13276 struct crypto_unittest_params ut_params; 13277 uint8_t *cipher_key; 13278 uint8_t *hmac_key; 13279 const uint8_t *cipher; 13280 const uint8_t *digest; 13281 uint8_t *iv; 13282 }; 13283 13284 #define MB_SESSION_NUMBER 3 13285 13286 static int 13287 test_multi_session_random_usage(void) 13288 { 13289 struct crypto_testsuite_params *ts_params = &testsuite_params; 13290 struct rte_cryptodev_info dev_info; 13291 int index = 0, ret = TEST_SUCCESS; 13292 uint32_t nb_sess, i, j; 13293 void **sessions; 13294 struct multi_session_params ut_paramz[] = { 13295 13296 { 13297 .cipher_key = ms_aes_cbc_key0, 13298 .hmac_key = ms_hmac_key0, 13299 .cipher = ms_aes_cbc_cipher0, 13300 .digest = ms_hmac_digest0, 13301 .iv = ms_aes_cbc_iv0 13302 }, 13303 { 13304 .cipher_key = ms_aes_cbc_key1, 13305 .hmac_key = ms_hmac_key1, 13306 .cipher = ms_aes_cbc_cipher1, 13307 .digest = ms_hmac_digest1, 13308 .iv = ms_aes_cbc_iv1 13309 }, 13310 { 13311 .cipher_key = ms_aes_cbc_key2, 13312 .hmac_key = ms_hmac_key2, 13313 .cipher = ms_aes_cbc_cipher2, 13314 .digest = ms_hmac_digest2, 13315 .iv = ms_aes_cbc_iv2 13316 }, 13317 13318 }; 13319 13320 /* Verify the capabilities */ 13321 struct rte_cryptodev_sym_capability_idx cap_idx; 13322 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13323 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 13324 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13325 &cap_idx) == NULL) 13326 return TEST_SKIPPED; 13327 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13328 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 13329 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13330 &cap_idx) == NULL) 13331 return TEST_SKIPPED; 13332 13333 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13334 13335 sessions = rte_malloc(NULL, (sizeof(void *) 13336 * MAX_NB_SESSIONS) + 1, 0); 13337 13338 for (i = 0; i < MB_SESSION_NUMBER; i++) { 13339 13340 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params, 13341 sizeof(struct crypto_unittest_params)); 13342 13343 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 13344 &ut_paramz[i].ut_params, 13345 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 13346 13347 /* Create multiple crypto sessions*/ 13348 sessions[i] = rte_cryptodev_sym_session_create( 13349 ts_params->valid_devs[0], 13350 &ut_paramz[i].ut_params.auth_xform, 13351 ts_params->session_mpool); 13352 if (sessions[i] == NULL && rte_errno == ENOTSUP) { 13353 nb_sess = i; 13354 ret = TEST_SKIPPED; 13355 goto session_clear; 13356 } 13357 13358 TEST_ASSERT_NOT_NULL(sessions[i], 13359 "Session creation failed at session number %u", 13360 i); 13361 } 13362 13363 nb_sess = i; 13364 13365 srand(time(NULL)); 13366 for (i = 0; i < 40000; i++) { 13367 13368 j = rand() % MB_SESSION_NUMBER; 13369 13370 ret = test_AES_CBC_HMAC_SHA512_decrypt_perform( 13371 sessions[j], 13372 &ut_paramz[j].ut_params, 13373 ts_params, ut_paramz[j].cipher, 13374 ut_paramz[j].digest, 13375 ut_paramz[j].iv); 13376 13377 rte_crypto_op_free(ut_paramz[j].ut_params.op); 13378 13379 /* 13380 * free mbuf - both obuf and ibuf are usually the same, 13381 * so check if they point at the same address is necessary, 13382 * to avoid freeing the mbuf twice. 13383 */ 13384 if (ut_paramz[j].ut_params.obuf) { 13385 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 13386 if (ut_paramz[j].ut_params.ibuf 13387 == ut_paramz[j].ut_params.obuf) 13388 ut_paramz[j].ut_params.ibuf = 0; 13389 ut_paramz[j].ut_params.obuf = 0; 13390 } 13391 if (ut_paramz[j].ut_params.ibuf) { 13392 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 13393 ut_paramz[j].ut_params.ibuf = 0; 13394 } 13395 13396 if (ret != TEST_SKIPPED) { 13397 index = i; 13398 break; 13399 } 13400 } 13401 13402 session_clear: 13403 for (i = 0; i < nb_sess; i++) { 13404 rte_cryptodev_sym_session_free(ts_params->valid_devs[0], 13405 sessions[i]); 13406 } 13407 13408 rte_free(sessions); 13409 13410 if (ret != TEST_SKIPPED) 13411 TEST_ASSERT_SUCCESS(ret, "Failed to perform decrypt on request number %u.", index); 13412 13413 return TEST_SUCCESS; 13414 } 13415 13416 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab, 13417 0xab, 0xab, 0xab, 0xab, 13418 0xab, 0xab, 0xab, 0xab, 13419 0xab, 0xab, 0xab, 0xab}; 13420 13421 static int 13422 test_null_invalid_operation(void) 13423 { 13424 struct crypto_testsuite_params *ts_params = &testsuite_params; 13425 struct crypto_unittest_params *ut_params = &unittest_params; 13426 13427 /* This test is for NULL PMD only */ 13428 if (gbl_driver_id != rte_cryptodev_driver_id_get( 13429 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 13430 return TEST_SKIPPED; 13431 13432 /* Setup Cipher Parameters */ 13433 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13434 ut_params->cipher_xform.next = NULL; 13435 13436 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 13437 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 13438 13439 /* Create Crypto session*/ 13440 ut_params->sess = rte_cryptodev_sym_session_create( 13441 ts_params->valid_devs[0], &ut_params->cipher_xform, 13442 ts_params->session_mpool); 13443 TEST_ASSERT(ut_params->sess == NULL, 13444 "Session creation succeeded unexpectedly"); 13445 13446 /* Setup HMAC Parameters */ 13447 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13448 ut_params->auth_xform.next = NULL; 13449 13450 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 13451 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 13452 13453 /* Create Crypto session*/ 13454 ut_params->sess = rte_cryptodev_sym_session_create( 13455 ts_params->valid_devs[0], &ut_params->auth_xform, 13456 ts_params->session_mpool); 13457 TEST_ASSERT(ut_params->sess == NULL, 13458 "Session creation succeeded unexpectedly"); 13459 13460 return TEST_SUCCESS; 13461 } 13462 13463 13464 #define NULL_BURST_LENGTH (32) 13465 13466 static int 13467 test_null_burst_operation(void) 13468 { 13469 struct crypto_testsuite_params *ts_params = &testsuite_params; 13470 struct crypto_unittest_params *ut_params = &unittest_params; 13471 13472 unsigned i, burst_len = NULL_BURST_LENGTH; 13473 13474 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 13475 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 13476 13477 /* This test is for NULL PMD only */ 13478 if (gbl_driver_id != rte_cryptodev_driver_id_get( 13479 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 13480 return TEST_SKIPPED; 13481 13482 /* Setup Cipher Parameters */ 13483 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 13484 ut_params->cipher_xform.next = &ut_params->auth_xform; 13485 13486 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 13487 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 13488 13489 /* Setup HMAC Parameters */ 13490 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13491 ut_params->auth_xform.next = NULL; 13492 13493 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 13494 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 13495 13496 /* Create Crypto session*/ 13497 ut_params->sess = rte_cryptodev_sym_session_create( 13498 ts_params->valid_devs[0], 13499 &ut_params->auth_xform, 13500 ts_params->session_mpool); 13501 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 13502 return TEST_SKIPPED; 13503 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13504 13505 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 13506 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 13507 burst_len, "failed to generate burst of crypto ops"); 13508 13509 /* Generate an operation for each mbuf in burst */ 13510 for (i = 0; i < burst_len; i++) { 13511 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13512 13513 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 13514 13515 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 13516 sizeof(unsigned)); 13517 *data = i; 13518 13519 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 13520 13521 burst[i]->sym->m_src = m; 13522 } 13523 13524 /* Process crypto operation */ 13525 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 13526 0, burst, burst_len), 13527 burst_len, 13528 "Error enqueuing burst"); 13529 13530 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 13531 0, burst_dequeued, burst_len), 13532 burst_len, 13533 "Error dequeuing burst"); 13534 13535 13536 for (i = 0; i < burst_len; i++) { 13537 TEST_ASSERT_EQUAL( 13538 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 13539 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 13540 uint32_t *), 13541 "data not as expected"); 13542 13543 rte_pktmbuf_free(burst[i]->sym->m_src); 13544 rte_crypto_op_free(burst[i]); 13545 } 13546 13547 return TEST_SUCCESS; 13548 } 13549 13550 static uint16_t 13551 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 13552 uint16_t nb_ops, void *user_param) 13553 { 13554 RTE_SET_USED(dev_id); 13555 RTE_SET_USED(qp_id); 13556 RTE_SET_USED(ops); 13557 RTE_SET_USED(user_param); 13558 13559 printf("crypto enqueue callback called\n"); 13560 return nb_ops; 13561 } 13562 13563 static uint16_t 13564 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 13565 uint16_t nb_ops, void *user_param) 13566 { 13567 RTE_SET_USED(dev_id); 13568 RTE_SET_USED(qp_id); 13569 RTE_SET_USED(ops); 13570 RTE_SET_USED(user_param); 13571 13572 printf("crypto dequeue callback called\n"); 13573 return nb_ops; 13574 } 13575 13576 /* 13577 * Thread using enqueue/dequeue callback with RCU. 13578 */ 13579 static int 13580 test_enqdeq_callback_thread(void *arg) 13581 { 13582 RTE_SET_USED(arg); 13583 /* DP thread calls rte_cryptodev_enqueue_burst()/ 13584 * rte_cryptodev_dequeue_burst() and invokes callback. 13585 */ 13586 test_null_burst_operation(); 13587 return 0; 13588 } 13589 13590 static int 13591 test_enq_callback_setup(void) 13592 { 13593 struct crypto_testsuite_params *ts_params = &testsuite_params; 13594 struct rte_cryptodev_info dev_info; 13595 struct rte_cryptodev_qp_conf qp_conf = { 13596 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 13597 }; 13598 13599 struct rte_cryptodev_cb *cb; 13600 uint16_t qp_id = 0; 13601 13602 /* Stop the device in case it's started so it can be configured */ 13603 rte_cryptodev_stop(ts_params->valid_devs[0]); 13604 13605 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13606 13607 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 13608 &ts_params->conf), 13609 "Failed to configure cryptodev %u", 13610 ts_params->valid_devs[0]); 13611 13612 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 13613 qp_conf.mp_session = ts_params->session_mpool; 13614 13615 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 13616 ts_params->valid_devs[0], qp_id, &qp_conf, 13617 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 13618 "Failed test for " 13619 "rte_cryptodev_queue_pair_setup: num_inflights " 13620 "%u on qp %u on cryptodev %u", 13621 qp_conf.nb_descriptors, qp_id, 13622 ts_params->valid_devs[0]); 13623 13624 /* Test with invalid crypto device */ 13625 cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS, 13626 qp_id, test_enq_callback, NULL); 13627 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 13628 "cryptodev %u did not fail", 13629 qp_id, RTE_CRYPTO_MAX_DEVS); 13630 13631 /* Test with invalid queue pair */ 13632 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 13633 dev_info.max_nb_queue_pairs + 1, 13634 test_enq_callback, NULL); 13635 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 13636 "cryptodev %u did not fail", 13637 dev_info.max_nb_queue_pairs + 1, 13638 ts_params->valid_devs[0]); 13639 13640 /* Test with NULL callback */ 13641 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 13642 qp_id, NULL, NULL); 13643 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 13644 "cryptodev %u did not fail", 13645 qp_id, ts_params->valid_devs[0]); 13646 13647 /* Test with valid configuration */ 13648 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 13649 qp_id, test_enq_callback, NULL); 13650 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 13651 "qp %u on cryptodev %u", 13652 qp_id, ts_params->valid_devs[0]); 13653 13654 rte_cryptodev_start(ts_params->valid_devs[0]); 13655 13656 /* Launch a thread */ 13657 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 13658 rte_get_next_lcore(-1, 1, 0)); 13659 13660 /* Wait until reader exited. */ 13661 rte_eal_mp_wait_lcore(); 13662 13663 /* Test with invalid crypto device */ 13664 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 13665 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 13666 "Expected call to fail as crypto device is invalid"); 13667 13668 /* Test with invalid queue pair */ 13669 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 13670 ts_params->valid_devs[0], 13671 dev_info.max_nb_queue_pairs + 1, cb), 13672 "Expected call to fail as queue pair is invalid"); 13673 13674 /* Test with NULL callback */ 13675 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 13676 ts_params->valid_devs[0], qp_id, NULL), 13677 "Expected call to fail as callback is NULL"); 13678 13679 /* Test with valid configuration */ 13680 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback( 13681 ts_params->valid_devs[0], qp_id, cb), 13682 "Failed test to remove callback on " 13683 "qp %u on cryptodev %u", 13684 qp_id, ts_params->valid_devs[0]); 13685 13686 return TEST_SUCCESS; 13687 } 13688 13689 static int 13690 test_deq_callback_setup(void) 13691 { 13692 struct crypto_testsuite_params *ts_params = &testsuite_params; 13693 struct rte_cryptodev_info dev_info; 13694 struct rte_cryptodev_qp_conf qp_conf = { 13695 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 13696 }; 13697 13698 struct rte_cryptodev_cb *cb; 13699 uint16_t qp_id = 0; 13700 13701 /* Stop the device in case it's started so it can be configured */ 13702 rte_cryptodev_stop(ts_params->valid_devs[0]); 13703 13704 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13705 13706 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 13707 &ts_params->conf), 13708 "Failed to configure cryptodev %u", 13709 ts_params->valid_devs[0]); 13710 13711 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 13712 qp_conf.mp_session = ts_params->session_mpool; 13713 13714 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 13715 ts_params->valid_devs[0], qp_id, &qp_conf, 13716 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 13717 "Failed test for " 13718 "rte_cryptodev_queue_pair_setup: num_inflights " 13719 "%u on qp %u on cryptodev %u", 13720 qp_conf.nb_descriptors, qp_id, 13721 ts_params->valid_devs[0]); 13722 13723 /* Test with invalid crypto device */ 13724 cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS, 13725 qp_id, test_deq_callback, NULL); 13726 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 13727 "cryptodev %u did not fail", 13728 qp_id, RTE_CRYPTO_MAX_DEVS); 13729 13730 /* Test with invalid queue pair */ 13731 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 13732 dev_info.max_nb_queue_pairs + 1, 13733 test_deq_callback, NULL); 13734 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 13735 "cryptodev %u did not fail", 13736 dev_info.max_nb_queue_pairs + 1, 13737 ts_params->valid_devs[0]); 13738 13739 /* Test with NULL callback */ 13740 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 13741 qp_id, NULL, NULL); 13742 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 13743 "cryptodev %u did not fail", 13744 qp_id, ts_params->valid_devs[0]); 13745 13746 /* Test with valid configuration */ 13747 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 13748 qp_id, test_deq_callback, NULL); 13749 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 13750 "qp %u on cryptodev %u", 13751 qp_id, ts_params->valid_devs[0]); 13752 13753 rte_cryptodev_start(ts_params->valid_devs[0]); 13754 13755 /* Launch a thread */ 13756 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 13757 rte_get_next_lcore(-1, 1, 0)); 13758 13759 /* Wait until reader exited. */ 13760 rte_eal_mp_wait_lcore(); 13761 13762 /* Test with invalid crypto device */ 13763 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 13764 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 13765 "Expected call to fail as crypto device is invalid"); 13766 13767 /* Test with invalid queue pair */ 13768 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 13769 ts_params->valid_devs[0], 13770 dev_info.max_nb_queue_pairs + 1, cb), 13771 "Expected call to fail as queue pair is invalid"); 13772 13773 /* Test with NULL callback */ 13774 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 13775 ts_params->valid_devs[0], qp_id, NULL), 13776 "Expected call to fail as callback is NULL"); 13777 13778 /* Test with valid configuration */ 13779 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback( 13780 ts_params->valid_devs[0], qp_id, cb), 13781 "Failed test to remove callback on " 13782 "qp %u on cryptodev %u", 13783 qp_id, ts_params->valid_devs[0]); 13784 13785 return TEST_SUCCESS; 13786 } 13787 13788 static void 13789 generate_gmac_large_plaintext(uint8_t *data) 13790 { 13791 uint16_t i; 13792 13793 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 13794 memcpy(&data[i], &data[0], 32); 13795 } 13796 13797 static int 13798 create_gmac_operation(enum rte_crypto_auth_operation op, 13799 const struct gmac_test_data *tdata) 13800 { 13801 struct crypto_testsuite_params *ts_params = &testsuite_params; 13802 struct crypto_unittest_params *ut_params = &unittest_params; 13803 struct rte_crypto_sym_op *sym_op; 13804 13805 uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 13806 13807 /* Generate Crypto op data structure */ 13808 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13809 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13810 TEST_ASSERT_NOT_NULL(ut_params->op, 13811 "Failed to allocate symmetric crypto operation struct"); 13812 13813 sym_op = ut_params->op->sym; 13814 13815 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 13816 ut_params->ibuf, tdata->gmac_tag.len); 13817 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13818 "no room to append digest"); 13819 13820 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 13821 ut_params->ibuf, plaintext_pad_len); 13822 13823 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 13824 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 13825 tdata->gmac_tag.len); 13826 debug_hexdump(stdout, "digest:", 13827 sym_op->auth.digest.data, 13828 tdata->gmac_tag.len); 13829 } 13830 13831 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 13832 uint8_t *, IV_OFFSET); 13833 13834 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 13835 13836 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 13837 13838 sym_op->cipher.data.length = 0; 13839 sym_op->cipher.data.offset = 0; 13840 13841 sym_op->auth.data.offset = 0; 13842 sym_op->auth.data.length = tdata->plaintext.len; 13843 13844 return 0; 13845 } 13846 13847 static int 13848 create_gmac_operation_sgl(enum rte_crypto_auth_operation op, 13849 const struct gmac_test_data *tdata, 13850 void *digest_mem, uint64_t digest_phys) 13851 { 13852 struct crypto_testsuite_params *ts_params = &testsuite_params; 13853 struct crypto_unittest_params *ut_params = &unittest_params; 13854 struct rte_crypto_sym_op *sym_op; 13855 13856 /* Generate Crypto op data structure */ 13857 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 13858 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 13859 TEST_ASSERT_NOT_NULL(ut_params->op, 13860 "Failed to allocate symmetric crypto operation struct"); 13861 13862 sym_op = ut_params->op->sym; 13863 13864 sym_op->auth.digest.data = digest_mem; 13865 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 13866 "no room to append digest"); 13867 13868 sym_op->auth.digest.phys_addr = digest_phys; 13869 13870 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 13871 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 13872 tdata->gmac_tag.len); 13873 debug_hexdump(stdout, "digest:", 13874 sym_op->auth.digest.data, 13875 tdata->gmac_tag.len); 13876 } 13877 13878 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 13879 uint8_t *, IV_OFFSET); 13880 13881 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 13882 13883 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 13884 13885 sym_op->cipher.data.length = 0; 13886 sym_op->cipher.data.offset = 0; 13887 13888 sym_op->auth.data.offset = 0; 13889 sym_op->auth.data.length = tdata->plaintext.len; 13890 13891 return 0; 13892 } 13893 13894 static int create_gmac_session(uint8_t dev_id, 13895 const struct gmac_test_data *tdata, 13896 enum rte_crypto_auth_operation auth_op) 13897 { 13898 uint8_t auth_key[tdata->key.len]; 13899 13900 struct crypto_testsuite_params *ts_params = &testsuite_params; 13901 struct crypto_unittest_params *ut_params = &unittest_params; 13902 13903 memcpy(auth_key, tdata->key.data, tdata->key.len); 13904 13905 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13906 ut_params->auth_xform.next = NULL; 13907 13908 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 13909 ut_params->auth_xform.auth.op = auth_op; 13910 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 13911 ut_params->auth_xform.auth.key.length = tdata->key.len; 13912 ut_params->auth_xform.auth.key.data = auth_key; 13913 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 13914 ut_params->auth_xform.auth.iv.length = tdata->iv.len; 13915 13916 13917 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 13918 &ut_params->auth_xform, ts_params->session_mpool); 13919 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 13920 return TEST_SKIPPED; 13921 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 13922 13923 return 0; 13924 } 13925 13926 static int 13927 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 13928 { 13929 struct crypto_testsuite_params *ts_params = &testsuite_params; 13930 struct crypto_unittest_params *ut_params = &unittest_params; 13931 struct rte_cryptodev_info dev_info; 13932 13933 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 13934 uint64_t feat_flags = dev_info.feature_flags; 13935 13936 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 13937 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 13938 printf("Device doesn't support RAW data-path APIs.\n"); 13939 return TEST_SKIPPED; 13940 } 13941 13942 int retval; 13943 13944 uint8_t *auth_tag, *plaintext; 13945 uint16_t plaintext_pad_len; 13946 13947 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 13948 "No GMAC length in the source data"); 13949 13950 /* Verify the capabilities */ 13951 struct rte_cryptodev_sym_capability_idx cap_idx; 13952 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 13953 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 13954 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 13955 &cap_idx) == NULL) 13956 return TEST_SKIPPED; 13957 13958 retval = create_gmac_session(ts_params->valid_devs[0], 13959 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 13960 13961 if (retval == TEST_SKIPPED) 13962 return TEST_SKIPPED; 13963 if (retval < 0) 13964 return retval; 13965 13966 if (tdata->plaintext.len > MBUF_SIZE) 13967 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 13968 else 13969 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 13970 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 13971 "Failed to allocate input buffer in mempool"); 13972 13973 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 13974 rte_pktmbuf_tailroom(ut_params->ibuf)); 13975 13976 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 13977 /* 13978 * Runtime generate the large plain text instead of use hard code 13979 * plain text vector. It is done to avoid create huge source file 13980 * with the test vector. 13981 */ 13982 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 13983 generate_gmac_large_plaintext(tdata->plaintext.data); 13984 13985 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 13986 plaintext_pad_len); 13987 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 13988 13989 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 13990 debug_hexdump(stdout, "plaintext:", plaintext, 13991 tdata->plaintext.len); 13992 13993 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 13994 tdata); 13995 13996 if (retval < 0) 13997 return retval; 13998 13999 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14000 14001 ut_params->op->sym->m_src = ut_params->ibuf; 14002 14003 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14004 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14005 ut_params->op); 14006 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 14007 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 14008 0); 14009 if (retval != TEST_SUCCESS) 14010 return retval; 14011 } else 14012 TEST_ASSERT_NOT_NULL( 14013 process_crypto_request(ts_params->valid_devs[0], 14014 ut_params->op), "failed to process sym crypto op"); 14015 14016 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14017 "crypto op processing failed"); 14018 14019 if (ut_params->op->sym->m_dst) { 14020 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 14021 uint8_t *, plaintext_pad_len); 14022 } else { 14023 auth_tag = plaintext + plaintext_pad_len; 14024 } 14025 14026 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 14027 14028 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14029 auth_tag, 14030 tdata->gmac_tag.data, 14031 tdata->gmac_tag.len, 14032 "GMAC Generated auth tag not as expected"); 14033 14034 return 0; 14035 } 14036 14037 static int 14038 test_AES_GMAC_authentication_test_case_1(void) 14039 { 14040 return test_AES_GMAC_authentication(&gmac_test_case_1); 14041 } 14042 14043 static int 14044 test_AES_GMAC_authentication_test_case_2(void) 14045 { 14046 return test_AES_GMAC_authentication(&gmac_test_case_2); 14047 } 14048 14049 static int 14050 test_AES_GMAC_authentication_test_case_3(void) 14051 { 14052 return test_AES_GMAC_authentication(&gmac_test_case_3); 14053 } 14054 14055 static int 14056 test_AES_GMAC_authentication_test_case_4(void) 14057 { 14058 return test_AES_GMAC_authentication(&gmac_test_case_4); 14059 } 14060 14061 static int 14062 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 14063 { 14064 struct crypto_testsuite_params *ts_params = &testsuite_params; 14065 struct crypto_unittest_params *ut_params = &unittest_params; 14066 int retval; 14067 uint32_t plaintext_pad_len; 14068 uint8_t *plaintext; 14069 struct rte_cryptodev_info dev_info; 14070 14071 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14072 uint64_t feat_flags = dev_info.feature_flags; 14073 14074 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14075 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14076 printf("Device doesn't support RAW data-path APIs.\n"); 14077 return TEST_SKIPPED; 14078 } 14079 14080 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 14081 "No GMAC length in the source data"); 14082 14083 /* Verify the capabilities */ 14084 struct rte_cryptodev_sym_capability_idx cap_idx; 14085 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14086 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 14087 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14088 &cap_idx) == NULL) 14089 return TEST_SKIPPED; 14090 14091 retval = create_gmac_session(ts_params->valid_devs[0], 14092 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 14093 14094 if (retval == TEST_SKIPPED) 14095 return TEST_SKIPPED; 14096 if (retval < 0) 14097 return retval; 14098 14099 if (tdata->plaintext.len > MBUF_SIZE) 14100 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 14101 else 14102 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14103 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14104 "Failed to allocate input buffer in mempool"); 14105 14106 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14107 rte_pktmbuf_tailroom(ut_params->ibuf)); 14108 14109 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 14110 14111 /* 14112 * Runtime generate the large plain text instead of use hard code 14113 * plain text vector. It is done to avoid create huge source file 14114 * with the test vector. 14115 */ 14116 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 14117 generate_gmac_large_plaintext(tdata->plaintext.data); 14118 14119 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14120 plaintext_pad_len); 14121 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14122 14123 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 14124 debug_hexdump(stdout, "plaintext:", plaintext, 14125 tdata->plaintext.len); 14126 14127 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 14128 tdata); 14129 14130 if (retval < 0) 14131 return retval; 14132 14133 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14134 14135 ut_params->op->sym->m_src = ut_params->ibuf; 14136 14137 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14138 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14139 ut_params->op); 14140 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 14141 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 14142 0); 14143 if (retval != TEST_SUCCESS) 14144 return retval; 14145 } else 14146 TEST_ASSERT_NOT_NULL( 14147 process_crypto_request(ts_params->valid_devs[0], 14148 ut_params->op), "failed to process sym crypto op"); 14149 14150 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14151 "crypto op processing failed"); 14152 14153 return 0; 14154 14155 } 14156 14157 static int 14158 test_AES_GMAC_authentication_verify_test_case_1(void) 14159 { 14160 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 14161 } 14162 14163 static int 14164 test_AES_GMAC_authentication_verify_test_case_2(void) 14165 { 14166 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 14167 } 14168 14169 static int 14170 test_AES_GMAC_authentication_verify_test_case_3(void) 14171 { 14172 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 14173 } 14174 14175 static int 14176 test_AES_GMAC_authentication_verify_test_case_4(void) 14177 { 14178 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 14179 } 14180 14181 static int 14182 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata, 14183 uint32_t fragsz) 14184 { 14185 struct crypto_testsuite_params *ts_params = &testsuite_params; 14186 struct crypto_unittest_params *ut_params = &unittest_params; 14187 struct rte_cryptodev_info dev_info; 14188 uint64_t feature_flags; 14189 unsigned int trn_data = 0; 14190 void *digest_mem = NULL; 14191 uint32_t segs = 1; 14192 unsigned int to_trn = 0; 14193 struct rte_mbuf *buf = NULL; 14194 uint8_t *auth_tag, *plaintext; 14195 int retval; 14196 14197 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 14198 "No GMAC length in the source data"); 14199 14200 /* Verify the capabilities */ 14201 struct rte_cryptodev_sym_capability_idx cap_idx; 14202 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14203 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 14204 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14205 &cap_idx) == NULL) 14206 return TEST_SKIPPED; 14207 14208 /* Check for any input SGL support */ 14209 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14210 feature_flags = dev_info.feature_flags; 14211 14212 if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) || 14213 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) || 14214 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))) 14215 return TEST_SKIPPED; 14216 14217 if (fragsz > tdata->plaintext.len) 14218 fragsz = tdata->plaintext.len; 14219 14220 uint16_t plaintext_len = fragsz; 14221 14222 retval = create_gmac_session(ts_params->valid_devs[0], 14223 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 14224 14225 if (retval == TEST_SKIPPED) 14226 return TEST_SKIPPED; 14227 if (retval < 0) 14228 return retval; 14229 14230 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14231 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14232 "Failed to allocate input buffer in mempool"); 14233 14234 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14235 rte_pktmbuf_tailroom(ut_params->ibuf)); 14236 14237 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14238 plaintext_len); 14239 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14240 14241 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 14242 14243 trn_data += plaintext_len; 14244 14245 buf = ut_params->ibuf; 14246 14247 /* 14248 * Loop until no more fragments 14249 */ 14250 14251 while (trn_data < tdata->plaintext.len) { 14252 ++segs; 14253 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 14254 (tdata->plaintext.len - trn_data) : fragsz; 14255 14256 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14257 buf = buf->next; 14258 14259 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 14260 rte_pktmbuf_tailroom(buf)); 14261 14262 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 14263 to_trn); 14264 14265 memcpy(plaintext, tdata->plaintext.data + trn_data, 14266 to_trn); 14267 trn_data += to_trn; 14268 if (trn_data == tdata->plaintext.len) 14269 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 14270 tdata->gmac_tag.len); 14271 } 14272 ut_params->ibuf->nb_segs = segs; 14273 14274 /* 14275 * Place digest at the end of the last buffer 14276 */ 14277 uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn; 14278 14279 if (!digest_mem) { 14280 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14281 + tdata->gmac_tag.len); 14282 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 14283 tdata->plaintext.len); 14284 } 14285 14286 retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE, 14287 tdata, digest_mem, digest_phys); 14288 14289 if (retval < 0) 14290 return retval; 14291 14292 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14293 14294 ut_params->op->sym->m_src = ut_params->ibuf; 14295 14296 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 14297 return TEST_SKIPPED; 14298 14299 TEST_ASSERT_NOT_NULL( 14300 process_crypto_request(ts_params->valid_devs[0], 14301 ut_params->op), "failed to process sym crypto op"); 14302 14303 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 14304 "crypto op processing failed"); 14305 14306 auth_tag = digest_mem; 14307 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 14308 TEST_ASSERT_BUFFERS_ARE_EQUAL( 14309 auth_tag, 14310 tdata->gmac_tag.data, 14311 tdata->gmac_tag.len, 14312 "GMAC Generated auth tag not as expected"); 14313 14314 return 0; 14315 } 14316 14317 /* Segment size not multiple of block size (16B) */ 14318 static int 14319 test_AES_GMAC_authentication_SGL_40B(void) 14320 { 14321 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40); 14322 } 14323 14324 static int 14325 test_AES_GMAC_authentication_SGL_80B(void) 14326 { 14327 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80); 14328 } 14329 14330 static int 14331 test_AES_GMAC_authentication_SGL_2048B(void) 14332 { 14333 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048); 14334 } 14335 14336 /* Segment size not multiple of block size (16B) */ 14337 static int 14338 test_AES_GMAC_authentication_SGL_2047B(void) 14339 { 14340 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047); 14341 } 14342 14343 struct test_crypto_vector { 14344 enum rte_crypto_cipher_algorithm crypto_algo; 14345 unsigned int cipher_offset; 14346 unsigned int cipher_len; 14347 14348 struct { 14349 uint8_t data[64]; 14350 unsigned int len; 14351 } cipher_key; 14352 14353 struct { 14354 uint8_t data[64]; 14355 unsigned int len; 14356 } iv; 14357 14358 struct { 14359 const uint8_t *data; 14360 unsigned int len; 14361 } plaintext; 14362 14363 struct { 14364 const uint8_t *data; 14365 unsigned int len; 14366 } ciphertext; 14367 14368 enum rte_crypto_auth_algorithm auth_algo; 14369 unsigned int auth_offset; 14370 14371 struct { 14372 uint8_t data[128]; 14373 unsigned int len; 14374 } auth_key; 14375 14376 struct { 14377 const uint8_t *data; 14378 unsigned int len; 14379 } aad; 14380 14381 struct { 14382 uint8_t data[128]; 14383 unsigned int len; 14384 } digest; 14385 }; 14386 14387 static const struct test_crypto_vector 14388 hmac_sha1_test_crypto_vector = { 14389 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 14390 .plaintext = { 14391 .data = plaintext_hash, 14392 .len = 512 14393 }, 14394 .auth_key = { 14395 .data = { 14396 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 14397 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 14398 0xDE, 0xF4, 0xDE, 0xAD 14399 }, 14400 .len = 20 14401 }, 14402 .digest = { 14403 .data = { 14404 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 14405 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 14406 0x3F, 0x91, 0x64, 0x59 14407 }, 14408 .len = 20 14409 } 14410 }; 14411 14412 static const struct test_crypto_vector 14413 aes128_gmac_test_vector = { 14414 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 14415 .plaintext = { 14416 .data = plaintext_hash, 14417 .len = 512 14418 }, 14419 .iv = { 14420 .data = { 14421 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 14422 0x08, 0x09, 0x0A, 0x0B 14423 }, 14424 .len = 12 14425 }, 14426 .auth_key = { 14427 .data = { 14428 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 14429 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 14430 }, 14431 .len = 16 14432 }, 14433 .digest = { 14434 .data = { 14435 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 14436 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 14437 }, 14438 .len = 16 14439 } 14440 }; 14441 14442 static const struct test_crypto_vector 14443 aes128cbc_hmac_sha1_test_vector = { 14444 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 14445 .cipher_offset = 0, 14446 .cipher_len = 512, 14447 .cipher_key = { 14448 .data = { 14449 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 14450 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 14451 }, 14452 .len = 16 14453 }, 14454 .iv = { 14455 .data = { 14456 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 14457 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 14458 }, 14459 .len = 16 14460 }, 14461 .plaintext = { 14462 .data = plaintext_hash, 14463 .len = 512 14464 }, 14465 .ciphertext = { 14466 .data = ciphertext512_aes128cbc, 14467 .len = 512 14468 }, 14469 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 14470 .auth_offset = 0, 14471 .auth_key = { 14472 .data = { 14473 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 14474 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 14475 0xDE, 0xF4, 0xDE, 0xAD 14476 }, 14477 .len = 20 14478 }, 14479 .digest = { 14480 .data = { 14481 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 14482 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 14483 0x18, 0x8C, 0x1D, 0x32 14484 }, 14485 .len = 20 14486 } 14487 }; 14488 14489 static const struct test_crypto_vector 14490 aes128cbc_hmac_sha1_aad_test_vector = { 14491 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 14492 .cipher_offset = 8, 14493 .cipher_len = 496, 14494 .cipher_key = { 14495 .data = { 14496 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 14497 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 14498 }, 14499 .len = 16 14500 }, 14501 .iv = { 14502 .data = { 14503 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 14504 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 14505 }, 14506 .len = 16 14507 }, 14508 .plaintext = { 14509 .data = plaintext_hash, 14510 .len = 512 14511 }, 14512 .ciphertext = { 14513 .data = ciphertext512_aes128cbc_aad, 14514 .len = 512 14515 }, 14516 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 14517 .auth_offset = 0, 14518 .auth_key = { 14519 .data = { 14520 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 14521 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 14522 0xDE, 0xF4, 0xDE, 0xAD 14523 }, 14524 .len = 20 14525 }, 14526 .digest = { 14527 .data = { 14528 0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F, 14529 0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B, 14530 0x62, 0x0F, 0xFB, 0x10 14531 }, 14532 .len = 20 14533 } 14534 }; 14535 14536 static void 14537 data_corruption(uint8_t *data) 14538 { 14539 data[0] += 1; 14540 } 14541 14542 static void 14543 tag_corruption(uint8_t *data, unsigned int tag_offset) 14544 { 14545 data[tag_offset] += 1; 14546 } 14547 14548 static int 14549 create_auth_session(struct crypto_unittest_params *ut_params, 14550 uint8_t dev_id, 14551 const struct test_crypto_vector *reference, 14552 enum rte_crypto_auth_operation auth_op) 14553 { 14554 struct crypto_testsuite_params *ts_params = &testsuite_params; 14555 uint8_t auth_key[reference->auth_key.len + 1]; 14556 14557 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 14558 14559 /* Setup Authentication Parameters */ 14560 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14561 ut_params->auth_xform.auth.op = auth_op; 14562 ut_params->auth_xform.next = NULL; 14563 ut_params->auth_xform.auth.algo = reference->auth_algo; 14564 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 14565 ut_params->auth_xform.auth.key.data = auth_key; 14566 ut_params->auth_xform.auth.digest_length = reference->digest.len; 14567 14568 /* Create Crypto session*/ 14569 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 14570 &ut_params->auth_xform, 14571 ts_params->session_mpool); 14572 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 14573 return TEST_SKIPPED; 14574 14575 return 0; 14576 } 14577 14578 static int 14579 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 14580 uint8_t dev_id, 14581 const struct test_crypto_vector *reference, 14582 enum rte_crypto_auth_operation auth_op, 14583 enum rte_crypto_cipher_operation cipher_op) 14584 { 14585 struct crypto_testsuite_params *ts_params = &testsuite_params; 14586 uint8_t cipher_key[reference->cipher_key.len + 1]; 14587 uint8_t auth_key[reference->auth_key.len + 1]; 14588 14589 memcpy(cipher_key, reference->cipher_key.data, 14590 reference->cipher_key.len); 14591 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 14592 14593 /* Setup Authentication Parameters */ 14594 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14595 ut_params->auth_xform.auth.op = auth_op; 14596 ut_params->auth_xform.auth.algo = reference->auth_algo; 14597 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 14598 ut_params->auth_xform.auth.key.data = auth_key; 14599 ut_params->auth_xform.auth.digest_length = reference->digest.len; 14600 14601 if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) { 14602 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 14603 ut_params->auth_xform.auth.iv.length = reference->iv.len; 14604 } else { 14605 ut_params->auth_xform.next = &ut_params->cipher_xform; 14606 14607 /* Setup Cipher Parameters */ 14608 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 14609 ut_params->cipher_xform.next = NULL; 14610 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 14611 ut_params->cipher_xform.cipher.op = cipher_op; 14612 ut_params->cipher_xform.cipher.key.data = cipher_key; 14613 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 14614 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 14615 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 14616 } 14617 14618 /* Create Crypto session*/ 14619 ut_params->sess = rte_cryptodev_sym_session_create(dev_id, 14620 &ut_params->auth_xform, 14621 ts_params->session_mpool); 14622 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 14623 return TEST_SKIPPED; 14624 14625 return 0; 14626 } 14627 14628 static int 14629 create_auth_operation(struct crypto_testsuite_params *ts_params, 14630 struct crypto_unittest_params *ut_params, 14631 const struct test_crypto_vector *reference, 14632 unsigned int auth_generate) 14633 { 14634 /* Generate Crypto op data structure */ 14635 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 14636 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 14637 TEST_ASSERT_NOT_NULL(ut_params->op, 14638 "Failed to allocate pktmbuf offload"); 14639 14640 /* Set crypto operation data parameters */ 14641 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14642 14643 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 14644 14645 /* set crypto operation source mbuf */ 14646 sym_op->m_src = ut_params->ibuf; 14647 14648 /* digest */ 14649 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 14650 ut_params->ibuf, reference->digest.len); 14651 14652 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 14653 "no room to append auth tag"); 14654 14655 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 14656 ut_params->ibuf, reference->plaintext.len); 14657 14658 if (auth_generate) 14659 memset(sym_op->auth.digest.data, 0, reference->digest.len); 14660 else 14661 memcpy(sym_op->auth.digest.data, 14662 reference->digest.data, 14663 reference->digest.len); 14664 14665 debug_hexdump(stdout, "digest:", 14666 sym_op->auth.digest.data, 14667 reference->digest.len); 14668 14669 sym_op->auth.data.length = reference->plaintext.len; 14670 sym_op->auth.data.offset = 0; 14671 14672 return 0; 14673 } 14674 14675 static int 14676 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 14677 struct crypto_unittest_params *ut_params, 14678 const struct test_crypto_vector *reference, 14679 unsigned int auth_generate) 14680 { 14681 /* Generate Crypto op data structure */ 14682 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 14683 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 14684 TEST_ASSERT_NOT_NULL(ut_params->op, 14685 "Failed to allocate pktmbuf offload"); 14686 14687 /* Set crypto operation data parameters */ 14688 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14689 14690 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 14691 14692 /* set crypto operation source mbuf */ 14693 sym_op->m_src = ut_params->ibuf; 14694 14695 /* digest */ 14696 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 14697 ut_params->ibuf, reference->digest.len); 14698 14699 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 14700 "no room to append auth tag"); 14701 14702 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 14703 ut_params->ibuf, reference->ciphertext.len); 14704 14705 if (auth_generate) 14706 memset(sym_op->auth.digest.data, 0, reference->digest.len); 14707 else 14708 memcpy(sym_op->auth.digest.data, 14709 reference->digest.data, 14710 reference->digest.len); 14711 14712 debug_hexdump(stdout, "digest:", 14713 sym_op->auth.digest.data, 14714 reference->digest.len); 14715 14716 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 14717 reference->iv.data, reference->iv.len); 14718 14719 sym_op->cipher.data.length = 0; 14720 sym_op->cipher.data.offset = 0; 14721 14722 sym_op->auth.data.length = reference->plaintext.len; 14723 sym_op->auth.data.offset = 0; 14724 14725 return 0; 14726 } 14727 14728 static int 14729 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 14730 struct crypto_unittest_params *ut_params, 14731 const struct test_crypto_vector *reference, 14732 unsigned int auth_generate) 14733 { 14734 /* Generate Crypto op data structure */ 14735 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 14736 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 14737 TEST_ASSERT_NOT_NULL(ut_params->op, 14738 "Failed to allocate pktmbuf offload"); 14739 14740 /* Set crypto operation data parameters */ 14741 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 14742 14743 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 14744 14745 /* set crypto operation source mbuf */ 14746 sym_op->m_src = ut_params->ibuf; 14747 14748 /* digest */ 14749 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 14750 ut_params->ibuf, reference->digest.len); 14751 14752 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 14753 "no room to append auth tag"); 14754 14755 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 14756 ut_params->ibuf, reference->ciphertext.len); 14757 14758 if (auth_generate) 14759 memset(sym_op->auth.digest.data, 0, reference->digest.len); 14760 else 14761 memcpy(sym_op->auth.digest.data, 14762 reference->digest.data, 14763 reference->digest.len); 14764 14765 debug_hexdump(stdout, "digest:", 14766 sym_op->auth.digest.data, 14767 reference->digest.len); 14768 14769 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 14770 reference->iv.data, reference->iv.len); 14771 14772 sym_op->cipher.data.length = reference->cipher_len; 14773 sym_op->cipher.data.offset = reference->cipher_offset; 14774 14775 sym_op->auth.data.length = reference->plaintext.len; 14776 sym_op->auth.data.offset = reference->auth_offset; 14777 14778 return 0; 14779 } 14780 14781 static int 14782 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 14783 struct crypto_unittest_params *ut_params, 14784 const struct test_crypto_vector *reference) 14785 { 14786 return create_auth_operation(ts_params, ut_params, reference, 0); 14787 } 14788 14789 static int 14790 create_auth_verify_GMAC_operation( 14791 struct crypto_testsuite_params *ts_params, 14792 struct crypto_unittest_params *ut_params, 14793 const struct test_crypto_vector *reference) 14794 { 14795 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 14796 } 14797 14798 static int 14799 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params, 14800 struct crypto_unittest_params *ut_params, 14801 const struct test_crypto_vector *reference) 14802 { 14803 return create_cipher_auth_operation(ts_params, ut_params, reference, 0); 14804 } 14805 14806 static int 14807 test_authentication_verify_fail_when_data_corruption( 14808 struct crypto_testsuite_params *ts_params, 14809 struct crypto_unittest_params *ut_params, 14810 const struct test_crypto_vector *reference, 14811 unsigned int data_corrupted) 14812 { 14813 int retval; 14814 14815 uint8_t *plaintext; 14816 struct rte_cryptodev_info dev_info; 14817 14818 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14819 uint64_t feat_flags = dev_info.feature_flags; 14820 14821 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14822 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14823 printf("Device doesn't support RAW data-path APIs.\n"); 14824 return TEST_SKIPPED; 14825 } 14826 14827 /* Verify the capabilities */ 14828 struct rte_cryptodev_sym_capability_idx cap_idx; 14829 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14830 cap_idx.algo.auth = reference->auth_algo; 14831 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14832 &cap_idx) == NULL) 14833 return TEST_SKIPPED; 14834 14835 14836 /* Create session */ 14837 retval = create_auth_session(ut_params, 14838 ts_params->valid_devs[0], 14839 reference, 14840 RTE_CRYPTO_AUTH_OP_VERIFY); 14841 14842 if (retval == TEST_SKIPPED) 14843 return TEST_SKIPPED; 14844 if (retval < 0) 14845 return retval; 14846 14847 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14848 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14849 "Failed to allocate input buffer in mempool"); 14850 14851 /* clear mbuf payload */ 14852 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14853 rte_pktmbuf_tailroom(ut_params->ibuf)); 14854 14855 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14856 reference->plaintext.len); 14857 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14858 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 14859 14860 debug_hexdump(stdout, "plaintext:", plaintext, 14861 reference->plaintext.len); 14862 14863 /* Create operation */ 14864 retval = create_auth_verify_operation(ts_params, ut_params, reference); 14865 14866 if (retval < 0) 14867 return retval; 14868 14869 if (data_corrupted) 14870 data_corruption(plaintext); 14871 else 14872 tag_corruption(plaintext, reference->plaintext.len); 14873 14874 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 14875 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14876 ut_params->op); 14877 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 14878 RTE_CRYPTO_OP_STATUS_SUCCESS, 14879 "authentication not failed"); 14880 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 14881 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 14882 0); 14883 if (retval != TEST_SUCCESS) 14884 return retval; 14885 } else { 14886 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 14887 ut_params->op); 14888 } 14889 if (ut_params->op == NULL) 14890 return 0; 14891 else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) 14892 return 0; 14893 14894 return -1; 14895 } 14896 14897 static int 14898 test_authentication_verify_GMAC_fail_when_corruption( 14899 struct crypto_testsuite_params *ts_params, 14900 struct crypto_unittest_params *ut_params, 14901 const struct test_crypto_vector *reference, 14902 unsigned int data_corrupted) 14903 { 14904 int retval; 14905 uint8_t *plaintext; 14906 struct rte_cryptodev_info dev_info; 14907 14908 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14909 uint64_t feat_flags = dev_info.feature_flags; 14910 14911 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 14912 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 14913 printf("Device doesn't support RAW data-path APIs.\n"); 14914 return TEST_SKIPPED; 14915 } 14916 14917 /* Verify the capabilities */ 14918 struct rte_cryptodev_sym_capability_idx cap_idx; 14919 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 14920 cap_idx.algo.auth = reference->auth_algo; 14921 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 14922 &cap_idx) == NULL) 14923 return TEST_SKIPPED; 14924 14925 /* Create session */ 14926 retval = create_auth_cipher_session(ut_params, 14927 ts_params->valid_devs[0], 14928 reference, 14929 RTE_CRYPTO_AUTH_OP_VERIFY, 14930 RTE_CRYPTO_CIPHER_OP_DECRYPT); 14931 if (retval == TEST_SKIPPED) 14932 return TEST_SKIPPED; 14933 if (retval < 0) 14934 return retval; 14935 14936 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 14937 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 14938 "Failed to allocate input buffer in mempool"); 14939 14940 /* clear mbuf payload */ 14941 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 14942 rte_pktmbuf_tailroom(ut_params->ibuf)); 14943 14944 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 14945 reference->plaintext.len); 14946 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 14947 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 14948 14949 debug_hexdump(stdout, "plaintext:", plaintext, 14950 reference->plaintext.len); 14951 14952 /* Create operation */ 14953 retval = create_auth_verify_GMAC_operation(ts_params, 14954 ut_params, 14955 reference); 14956 14957 if (retval < 0) 14958 return retval; 14959 14960 if (data_corrupted) 14961 data_corruption(plaintext); 14962 else 14963 tag_corruption(plaintext, reference->aad.len); 14964 14965 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 14966 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 14967 ut_params->op); 14968 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 14969 RTE_CRYPTO_OP_STATUS_SUCCESS, 14970 "authentication not failed"); 14971 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 14972 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 14973 0); 14974 if (retval != TEST_SUCCESS) 14975 return retval; 14976 } else { 14977 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 14978 ut_params->op); 14979 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 14980 } 14981 14982 return 0; 14983 } 14984 14985 static int 14986 test_authenticated_decryption_fail_when_corruption( 14987 struct crypto_testsuite_params *ts_params, 14988 struct crypto_unittest_params *ut_params, 14989 const struct test_crypto_vector *reference, 14990 unsigned int data_corrupted) 14991 { 14992 int retval; 14993 14994 uint8_t *ciphertext; 14995 struct rte_cryptodev_info dev_info; 14996 14997 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 14998 uint64_t feat_flags = dev_info.feature_flags; 14999 15000 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15001 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15002 printf("Device doesn't support RAW data-path APIs.\n"); 15003 return TEST_SKIPPED; 15004 } 15005 15006 /* Verify the capabilities */ 15007 struct rte_cryptodev_sym_capability_idx cap_idx; 15008 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15009 cap_idx.algo.auth = reference->auth_algo; 15010 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15011 &cap_idx) == NULL) 15012 return TEST_SKIPPED; 15013 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15014 cap_idx.algo.cipher = reference->crypto_algo; 15015 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15016 &cap_idx) == NULL) 15017 return TEST_SKIPPED; 15018 15019 /* Create session */ 15020 retval = create_auth_cipher_session(ut_params, 15021 ts_params->valid_devs[0], 15022 reference, 15023 RTE_CRYPTO_AUTH_OP_VERIFY, 15024 RTE_CRYPTO_CIPHER_OP_DECRYPT); 15025 if (retval == TEST_SKIPPED) 15026 return TEST_SKIPPED; 15027 if (retval < 0) 15028 return retval; 15029 15030 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15031 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 15032 "Failed to allocate input buffer in mempool"); 15033 15034 /* clear mbuf payload */ 15035 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15036 rte_pktmbuf_tailroom(ut_params->ibuf)); 15037 15038 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15039 reference->ciphertext.len); 15040 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 15041 memcpy(ciphertext, reference->ciphertext.data, 15042 reference->ciphertext.len); 15043 15044 /* Create operation */ 15045 retval = create_cipher_auth_verify_operation(ts_params, 15046 ut_params, 15047 reference); 15048 15049 if (retval < 0) 15050 return retval; 15051 15052 if (data_corrupted) 15053 data_corruption(ciphertext); 15054 else 15055 tag_corruption(ciphertext, reference->ciphertext.len); 15056 15057 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 15058 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 15059 ut_params->op); 15060 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 15061 RTE_CRYPTO_OP_STATUS_SUCCESS, 15062 "authentication not failed"); 15063 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15064 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 15065 0); 15066 if (retval != TEST_SUCCESS) 15067 return retval; 15068 } else { 15069 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 15070 ut_params->op); 15071 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 15072 } 15073 15074 return 0; 15075 } 15076 15077 static int 15078 test_authenticated_encrypt_with_esn( 15079 struct crypto_testsuite_params *ts_params, 15080 struct crypto_unittest_params *ut_params, 15081 const struct test_crypto_vector *reference) 15082 { 15083 int retval; 15084 15085 uint8_t *authciphertext, *plaintext, *auth_tag; 15086 uint16_t plaintext_pad_len; 15087 uint8_t cipher_key[reference->cipher_key.len + 1]; 15088 uint8_t auth_key[reference->auth_key.len + 1]; 15089 struct rte_cryptodev_info dev_info; 15090 15091 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15092 uint64_t feat_flags = dev_info.feature_flags; 15093 15094 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15095 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15096 printf("Device doesn't support RAW data-path APIs.\n"); 15097 return TEST_SKIPPED; 15098 } 15099 15100 /* Verify the capabilities */ 15101 struct rte_cryptodev_sym_capability_idx cap_idx; 15102 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15103 cap_idx.algo.auth = reference->auth_algo; 15104 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15105 &cap_idx) == NULL) 15106 return TEST_SKIPPED; 15107 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15108 cap_idx.algo.cipher = reference->crypto_algo; 15109 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15110 &cap_idx) == NULL) 15111 return TEST_SKIPPED; 15112 15113 /* Create session */ 15114 memcpy(cipher_key, reference->cipher_key.data, 15115 reference->cipher_key.len); 15116 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 15117 15118 /* Setup Cipher Parameters */ 15119 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15120 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 15121 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 15122 ut_params->cipher_xform.cipher.key.data = cipher_key; 15123 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 15124 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 15125 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 15126 15127 ut_params->cipher_xform.next = &ut_params->auth_xform; 15128 15129 /* Setup Authentication Parameters */ 15130 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15131 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 15132 ut_params->auth_xform.auth.algo = reference->auth_algo; 15133 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 15134 ut_params->auth_xform.auth.key.data = auth_key; 15135 ut_params->auth_xform.auth.digest_length = reference->digest.len; 15136 ut_params->auth_xform.next = NULL; 15137 15138 /* Create Crypto session*/ 15139 ut_params->sess = rte_cryptodev_sym_session_create( 15140 ts_params->valid_devs[0], &ut_params->cipher_xform, 15141 ts_params->session_mpool); 15142 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 15143 return TEST_SKIPPED; 15144 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 15145 15146 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15147 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 15148 "Failed to allocate input buffer in mempool"); 15149 15150 /* clear mbuf payload */ 15151 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15152 rte_pktmbuf_tailroom(ut_params->ibuf)); 15153 15154 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15155 reference->plaintext.len); 15156 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 15157 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 15158 15159 /* Create operation */ 15160 retval = create_cipher_auth_operation(ts_params, 15161 ut_params, 15162 reference, 0); 15163 15164 if (retval < 0) 15165 return retval; 15166 15167 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 15168 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 15169 ut_params->op); 15170 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15171 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 15172 0); 15173 if (retval != TEST_SUCCESS) 15174 return retval; 15175 } else 15176 ut_params->op = process_crypto_request( 15177 ts_params->valid_devs[0], ut_params->op); 15178 15179 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 15180 15181 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 15182 "crypto op processing failed"); 15183 15184 plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16); 15185 15186 authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 15187 ut_params->op->sym->auth.data.offset); 15188 auth_tag = authciphertext + plaintext_pad_len; 15189 debug_hexdump(stdout, "ciphertext:", authciphertext, 15190 reference->ciphertext.len); 15191 debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len); 15192 15193 /* Validate obuf */ 15194 TEST_ASSERT_BUFFERS_ARE_EQUAL( 15195 authciphertext, 15196 reference->ciphertext.data, 15197 reference->ciphertext.len, 15198 "Ciphertext data not as expected"); 15199 15200 TEST_ASSERT_BUFFERS_ARE_EQUAL( 15201 auth_tag, 15202 reference->digest.data, 15203 reference->digest.len, 15204 "Generated digest not as expected"); 15205 15206 return TEST_SUCCESS; 15207 15208 } 15209 15210 static int 15211 test_authenticated_decrypt_with_esn( 15212 struct crypto_testsuite_params *ts_params, 15213 struct crypto_unittest_params *ut_params, 15214 const struct test_crypto_vector *reference) 15215 { 15216 int retval; 15217 15218 uint8_t *ciphertext; 15219 uint8_t cipher_key[reference->cipher_key.len + 1]; 15220 uint8_t auth_key[reference->auth_key.len + 1]; 15221 struct rte_cryptodev_info dev_info; 15222 15223 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15224 uint64_t feat_flags = dev_info.feature_flags; 15225 15226 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15227 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15228 printf("Device doesn't support RAW data-path APIs.\n"); 15229 return TEST_SKIPPED; 15230 } 15231 15232 /* Verify the capabilities */ 15233 struct rte_cryptodev_sym_capability_idx cap_idx; 15234 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15235 cap_idx.algo.auth = reference->auth_algo; 15236 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15237 &cap_idx) == NULL) 15238 return TEST_SKIPPED; 15239 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15240 cap_idx.algo.cipher = reference->crypto_algo; 15241 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15242 &cap_idx) == NULL) 15243 return TEST_SKIPPED; 15244 15245 /* Create session */ 15246 memcpy(cipher_key, reference->cipher_key.data, 15247 reference->cipher_key.len); 15248 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 15249 15250 /* Setup Authentication Parameters */ 15251 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 15252 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 15253 ut_params->auth_xform.auth.algo = reference->auth_algo; 15254 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 15255 ut_params->auth_xform.auth.key.data = auth_key; 15256 ut_params->auth_xform.auth.digest_length = reference->digest.len; 15257 ut_params->auth_xform.next = &ut_params->cipher_xform; 15258 15259 /* Setup Cipher Parameters */ 15260 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 15261 ut_params->cipher_xform.next = NULL; 15262 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 15263 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 15264 ut_params->cipher_xform.cipher.key.data = cipher_key; 15265 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 15266 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 15267 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 15268 15269 /* Create Crypto session*/ 15270 ut_params->sess = rte_cryptodev_sym_session_create( 15271 ts_params->valid_devs[0], &ut_params->auth_xform, 15272 ts_params->session_mpool); 15273 if (ut_params->sess == NULL && rte_errno == ENOTSUP) 15274 return TEST_SKIPPED; 15275 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 15276 15277 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15278 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 15279 "Failed to allocate input buffer in mempool"); 15280 15281 /* clear mbuf payload */ 15282 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15283 rte_pktmbuf_tailroom(ut_params->ibuf)); 15284 15285 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15286 reference->ciphertext.len); 15287 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 15288 memcpy(ciphertext, reference->ciphertext.data, 15289 reference->ciphertext.len); 15290 15291 /* Create operation */ 15292 retval = create_cipher_auth_verify_operation(ts_params, 15293 ut_params, 15294 reference); 15295 15296 if (retval < 0) 15297 return retval; 15298 15299 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 15300 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 15301 ut_params->op); 15302 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15303 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 15304 0); 15305 if (retval != TEST_SUCCESS) 15306 return retval; 15307 } else 15308 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 15309 ut_params->op); 15310 15311 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 15312 TEST_ASSERT_EQUAL(ut_params->op->status, 15313 RTE_CRYPTO_OP_STATUS_SUCCESS, 15314 "crypto op processing passed"); 15315 15316 ut_params->obuf = ut_params->op->sym->m_src; 15317 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 15318 15319 return 0; 15320 } 15321 15322 static int 15323 create_aead_operation_SGL(enum rte_crypto_aead_operation op, 15324 const struct aead_test_data *tdata, 15325 void *digest_mem, uint64_t digest_phys) 15326 { 15327 struct crypto_testsuite_params *ts_params = &testsuite_params; 15328 struct crypto_unittest_params *ut_params = &unittest_params; 15329 15330 const unsigned int auth_tag_len = tdata->auth_tag.len; 15331 const unsigned int iv_len = tdata->iv.len; 15332 unsigned int aad_len = tdata->aad.len; 15333 unsigned int aad_len_pad = 0; 15334 15335 /* Generate Crypto op data structure */ 15336 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 15337 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 15338 TEST_ASSERT_NOT_NULL(ut_params->op, 15339 "Failed to allocate symmetric crypto operation struct"); 15340 15341 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 15342 15343 sym_op->aead.digest.data = digest_mem; 15344 15345 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 15346 "no room to append digest"); 15347 15348 sym_op->aead.digest.phys_addr = digest_phys; 15349 15350 if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) { 15351 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 15352 auth_tag_len); 15353 debug_hexdump(stdout, "digest:", 15354 sym_op->aead.digest.data, 15355 auth_tag_len); 15356 } 15357 15358 /* Append aad data */ 15359 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 15360 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 15361 uint8_t *, IV_OFFSET); 15362 15363 /* Copy IV 1 byte after the IV pointer, according to the API */ 15364 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len); 15365 15366 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16); 15367 15368 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 15369 ut_params->ibuf, aad_len); 15370 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 15371 "no room to prepend aad"); 15372 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 15373 ut_params->ibuf); 15374 15375 memset(sym_op->aead.aad.data, 0, aad_len); 15376 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 15377 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 15378 15379 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 15380 debug_hexdump(stdout, "aad:", 15381 sym_op->aead.aad.data, aad_len); 15382 } else { 15383 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 15384 uint8_t *, IV_OFFSET); 15385 15386 rte_memcpy(iv_ptr, tdata->iv.data, iv_len); 15387 15388 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16); 15389 15390 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 15391 ut_params->ibuf, aad_len_pad); 15392 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 15393 "no room to prepend aad"); 15394 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 15395 ut_params->ibuf); 15396 15397 memset(sym_op->aead.aad.data, 0, aad_len); 15398 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 15399 15400 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 15401 debug_hexdump(stdout, "aad:", 15402 sym_op->aead.aad.data, aad_len); 15403 } 15404 15405 sym_op->aead.data.length = tdata->plaintext.len; 15406 sym_op->aead.data.offset = aad_len_pad; 15407 15408 return 0; 15409 } 15410 15411 #define SGL_MAX_NO 16 15412 15413 static int 15414 test_authenticated_encryption_SGL(const struct aead_test_data *tdata, 15415 const int oop, uint32_t fragsz, uint32_t fragsz_oop) 15416 { 15417 struct crypto_testsuite_params *ts_params = &testsuite_params; 15418 struct crypto_unittest_params *ut_params = &unittest_params; 15419 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL; 15420 int retval; 15421 int to_trn = 0; 15422 int to_trn_tbl[SGL_MAX_NO]; 15423 int segs = 1; 15424 unsigned int trn_data = 0; 15425 uint8_t *plaintext, *ciphertext, *auth_tag; 15426 struct rte_cryptodev_info dev_info; 15427 15428 /* Verify the capabilities */ 15429 struct rte_cryptodev_sym_capability_idx cap_idx; 15430 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 15431 cap_idx.algo.aead = tdata->algo; 15432 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 15433 &cap_idx) == NULL) 15434 return TEST_SKIPPED; 15435 15436 /* 15437 * SGL not supported on AESNI_MB PMD CPU crypto, 15438 * OOP not supported on AESNI_GCM CPU crypto 15439 */ 15440 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO && 15441 (gbl_driver_id == rte_cryptodev_driver_id_get( 15442 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) || oop)) 15443 return TEST_SKIPPED; 15444 15445 /* Detailed check for the particular SGL support flag */ 15446 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 15447 if (!oop) { 15448 unsigned int sgl_in = fragsz < tdata->plaintext.len; 15449 if (sgl_in && (!(dev_info.feature_flags & 15450 RTE_CRYPTODEV_FF_IN_PLACE_SGL))) 15451 return TEST_SKIPPED; 15452 15453 uint64_t feat_flags = dev_info.feature_flags; 15454 15455 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 15456 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 15457 printf("Device doesn't support RAW data-path APIs.\n"); 15458 return TEST_SKIPPED; 15459 } 15460 } else { 15461 unsigned int sgl_in = fragsz < tdata->plaintext.len; 15462 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) < 15463 tdata->plaintext.len; 15464 /* Raw data path API does not support OOP */ 15465 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 15466 return TEST_SKIPPED; 15467 if (sgl_in && !sgl_out) { 15468 if (!(dev_info.feature_flags & 15469 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) 15470 return TEST_SKIPPED; 15471 } else if (!sgl_in && sgl_out) { 15472 if (!(dev_info.feature_flags & 15473 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 15474 return TEST_SKIPPED; 15475 } else if (sgl_in && sgl_out) { 15476 if (!(dev_info.feature_flags & 15477 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 15478 return TEST_SKIPPED; 15479 } 15480 } 15481 15482 if (fragsz > tdata->plaintext.len) 15483 fragsz = tdata->plaintext.len; 15484 15485 uint16_t plaintext_len = fragsz; 15486 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 15487 15488 if (fragsz_oop > tdata->plaintext.len) 15489 frag_size_oop = tdata->plaintext.len; 15490 15491 int ecx = 0; 15492 void *digest_mem = NULL; 15493 15494 uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 15495 15496 if (tdata->plaintext.len % fragsz != 0) { 15497 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO) 15498 return 1; 15499 } else { 15500 if (tdata->plaintext.len / fragsz > SGL_MAX_NO) 15501 return 1; 15502 } 15503 15504 /* 15505 * For out-op-place we need to alloc another mbuf 15506 */ 15507 if (oop) { 15508 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15509 rte_pktmbuf_append(ut_params->obuf, 15510 frag_size_oop + prepend_len); 15511 buf_oop = ut_params->obuf; 15512 } 15513 15514 /* Create AEAD session */ 15515 retval = create_aead_session(ts_params->valid_devs[0], 15516 tdata->algo, 15517 RTE_CRYPTO_AEAD_OP_ENCRYPT, 15518 tdata->key.data, tdata->key.len, 15519 tdata->aad.len, tdata->auth_tag.len, 15520 tdata->iv.len); 15521 if (retval < 0) 15522 return retval; 15523 15524 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15525 15526 /* clear mbuf payload */ 15527 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 15528 rte_pktmbuf_tailroom(ut_params->ibuf)); 15529 15530 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15531 plaintext_len); 15532 15533 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 15534 15535 trn_data += plaintext_len; 15536 15537 buf = ut_params->ibuf; 15538 15539 /* 15540 * Loop until no more fragments 15541 */ 15542 15543 while (trn_data < tdata->plaintext.len) { 15544 ++segs; 15545 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 15546 (tdata->plaintext.len - trn_data) : fragsz; 15547 15548 to_trn_tbl[ecx++] = to_trn; 15549 15550 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 15551 buf = buf->next; 15552 15553 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 15554 rte_pktmbuf_tailroom(buf)); 15555 15556 /* OOP */ 15557 if (oop && !fragsz_oop) { 15558 buf_last_oop = buf_oop->next = 15559 rte_pktmbuf_alloc(ts_params->mbuf_pool); 15560 buf_oop = buf_oop->next; 15561 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 15562 0, rte_pktmbuf_tailroom(buf_oop)); 15563 rte_pktmbuf_append(buf_oop, to_trn); 15564 } 15565 15566 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 15567 to_trn); 15568 15569 memcpy(plaintext, tdata->plaintext.data + trn_data, 15570 to_trn); 15571 trn_data += to_trn; 15572 if (trn_data == tdata->plaintext.len) { 15573 if (oop) { 15574 if (!fragsz_oop) 15575 digest_mem = rte_pktmbuf_append(buf_oop, 15576 tdata->auth_tag.len); 15577 } else 15578 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 15579 tdata->auth_tag.len); 15580 } 15581 } 15582 15583 uint64_t digest_phys = 0; 15584 15585 ut_params->ibuf->nb_segs = segs; 15586 15587 segs = 1; 15588 if (fragsz_oop && oop) { 15589 to_trn = 0; 15590 ecx = 0; 15591 15592 if (frag_size_oop == tdata->plaintext.len) { 15593 digest_mem = rte_pktmbuf_append(ut_params->obuf, 15594 tdata->auth_tag.len); 15595 15596 digest_phys = rte_pktmbuf_iova_offset( 15597 ut_params->obuf, 15598 tdata->plaintext.len + prepend_len); 15599 } 15600 15601 trn_data = frag_size_oop; 15602 while (trn_data < tdata->plaintext.len) { 15603 ++segs; 15604 to_trn = 15605 (tdata->plaintext.len - trn_data < 15606 frag_size_oop) ? 15607 (tdata->plaintext.len - trn_data) : 15608 frag_size_oop; 15609 15610 to_trn_tbl[ecx++] = to_trn; 15611 15612 buf_last_oop = buf_oop->next = 15613 rte_pktmbuf_alloc(ts_params->mbuf_pool); 15614 buf_oop = buf_oop->next; 15615 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 15616 0, rte_pktmbuf_tailroom(buf_oop)); 15617 rte_pktmbuf_append(buf_oop, to_trn); 15618 15619 trn_data += to_trn; 15620 15621 if (trn_data == tdata->plaintext.len) { 15622 digest_mem = rte_pktmbuf_append(buf_oop, 15623 tdata->auth_tag.len); 15624 } 15625 } 15626 15627 ut_params->obuf->nb_segs = segs; 15628 } 15629 15630 /* 15631 * Place digest at the end of the last buffer 15632 */ 15633 if (!digest_phys) 15634 digest_phys = rte_pktmbuf_iova(buf) + to_trn; 15635 if (oop && buf_last_oop) 15636 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn; 15637 15638 if (!digest_mem && !oop) { 15639 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 15640 + tdata->auth_tag.len); 15641 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 15642 tdata->plaintext.len); 15643 } 15644 15645 /* Create AEAD operation */ 15646 retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT, 15647 tdata, digest_mem, digest_phys); 15648 15649 if (retval < 0) 15650 return retval; 15651 15652 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 15653 15654 ut_params->op->sym->m_src = ut_params->ibuf; 15655 if (oop) 15656 ut_params->op->sym->m_dst = ut_params->obuf; 15657 15658 /* Process crypto operation */ 15659 if (oop == IN_PLACE && 15660 gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 15661 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 15662 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) { 15663 retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0, 15664 0); 15665 if (retval != TEST_SUCCESS) 15666 return retval; 15667 } else 15668 TEST_ASSERT_NOT_NULL( 15669 process_crypto_request(ts_params->valid_devs[0], 15670 ut_params->op), "failed to process sym crypto op"); 15671 15672 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 15673 "crypto op processing failed"); 15674 15675 15676 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 15677 uint8_t *, prepend_len); 15678 if (oop) { 15679 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 15680 uint8_t *, prepend_len); 15681 } 15682 15683 if (fragsz_oop) 15684 fragsz = fragsz_oop; 15685 15686 TEST_ASSERT_BUFFERS_ARE_EQUAL( 15687 ciphertext, 15688 tdata->ciphertext.data, 15689 fragsz, 15690 "Ciphertext data not as expected"); 15691 15692 buf = ut_params->op->sym->m_src->next; 15693 if (oop) 15694 buf = ut_params->op->sym->m_dst->next; 15695 15696 unsigned int off = fragsz; 15697 15698 ecx = 0; 15699 while (buf) { 15700 ciphertext = rte_pktmbuf_mtod(buf, 15701 uint8_t *); 15702 15703 TEST_ASSERT_BUFFERS_ARE_EQUAL( 15704 ciphertext, 15705 tdata->ciphertext.data + off, 15706 to_trn_tbl[ecx], 15707 "Ciphertext data not as expected"); 15708 15709 off += to_trn_tbl[ecx++]; 15710 buf = buf->next; 15711 } 15712 15713 auth_tag = digest_mem; 15714 TEST_ASSERT_BUFFERS_ARE_EQUAL( 15715 auth_tag, 15716 tdata->auth_tag.data, 15717 tdata->auth_tag.len, 15718 "Generated auth tag not as expected"); 15719 15720 return 0; 15721 } 15722 15723 static int 15724 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) 15725 { 15726 return test_authenticated_encryption_SGL( 15727 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400); 15728 } 15729 15730 static int 15731 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void) 15732 { 15733 return test_authenticated_encryption_SGL( 15734 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000); 15735 } 15736 15737 static int 15738 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void) 15739 { 15740 return test_authenticated_encryption_SGL( 15741 &gcm_test_case_8, OUT_OF_PLACE, 400, 15742 gcm_test_case_8.plaintext.len); 15743 } 15744 15745 static int 15746 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void) 15747 { 15748 /* This test is not for OPENSSL PMD */ 15749 if (gbl_driver_id == rte_cryptodev_driver_id_get( 15750 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) 15751 return TEST_SKIPPED; 15752 15753 return test_authenticated_encryption_SGL( 15754 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0); 15755 } 15756 15757 static int 15758 test_authentication_verify_fail_when_data_corrupted( 15759 struct crypto_testsuite_params *ts_params, 15760 struct crypto_unittest_params *ut_params, 15761 const struct test_crypto_vector *reference) 15762 { 15763 return test_authentication_verify_fail_when_data_corruption( 15764 ts_params, ut_params, reference, 1); 15765 } 15766 15767 static int 15768 test_authentication_verify_fail_when_tag_corrupted( 15769 struct crypto_testsuite_params *ts_params, 15770 struct crypto_unittest_params *ut_params, 15771 const struct test_crypto_vector *reference) 15772 { 15773 return test_authentication_verify_fail_when_data_corruption( 15774 ts_params, ut_params, reference, 0); 15775 } 15776 15777 static int 15778 test_authentication_verify_GMAC_fail_when_data_corrupted( 15779 struct crypto_testsuite_params *ts_params, 15780 struct crypto_unittest_params *ut_params, 15781 const struct test_crypto_vector *reference) 15782 { 15783 return test_authentication_verify_GMAC_fail_when_corruption( 15784 ts_params, ut_params, reference, 1); 15785 } 15786 15787 static int 15788 test_authentication_verify_GMAC_fail_when_tag_corrupted( 15789 struct crypto_testsuite_params *ts_params, 15790 struct crypto_unittest_params *ut_params, 15791 const struct test_crypto_vector *reference) 15792 { 15793 return test_authentication_verify_GMAC_fail_when_corruption( 15794 ts_params, ut_params, reference, 0); 15795 } 15796 15797 static int 15798 test_authenticated_decryption_fail_when_data_corrupted( 15799 struct crypto_testsuite_params *ts_params, 15800 struct crypto_unittest_params *ut_params, 15801 const struct test_crypto_vector *reference) 15802 { 15803 return test_authenticated_decryption_fail_when_corruption( 15804 ts_params, ut_params, reference, 1); 15805 } 15806 15807 static int 15808 test_authenticated_decryption_fail_when_tag_corrupted( 15809 struct crypto_testsuite_params *ts_params, 15810 struct crypto_unittest_params *ut_params, 15811 const struct test_crypto_vector *reference) 15812 { 15813 return test_authenticated_decryption_fail_when_corruption( 15814 ts_params, ut_params, reference, 0); 15815 } 15816 15817 static int 15818 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 15819 { 15820 return test_authentication_verify_fail_when_data_corrupted( 15821 &testsuite_params, &unittest_params, 15822 &hmac_sha1_test_crypto_vector); 15823 } 15824 15825 static int 15826 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 15827 { 15828 return test_authentication_verify_fail_when_tag_corrupted( 15829 &testsuite_params, &unittest_params, 15830 &hmac_sha1_test_crypto_vector); 15831 } 15832 15833 static int 15834 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 15835 { 15836 return test_authentication_verify_GMAC_fail_when_data_corrupted( 15837 &testsuite_params, &unittest_params, 15838 &aes128_gmac_test_vector); 15839 } 15840 15841 static int 15842 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 15843 { 15844 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 15845 &testsuite_params, &unittest_params, 15846 &aes128_gmac_test_vector); 15847 } 15848 15849 static int 15850 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 15851 { 15852 return test_authenticated_decryption_fail_when_data_corrupted( 15853 &testsuite_params, 15854 &unittest_params, 15855 &aes128cbc_hmac_sha1_test_vector); 15856 } 15857 15858 static int 15859 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 15860 { 15861 return test_authenticated_decryption_fail_when_tag_corrupted( 15862 &testsuite_params, 15863 &unittest_params, 15864 &aes128cbc_hmac_sha1_test_vector); 15865 } 15866 15867 static int 15868 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void) 15869 { 15870 return test_authenticated_encrypt_with_esn( 15871 &testsuite_params, 15872 &unittest_params, 15873 &aes128cbc_hmac_sha1_aad_test_vector); 15874 } 15875 15876 static int 15877 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void) 15878 { 15879 return test_authenticated_decrypt_with_esn( 15880 &testsuite_params, 15881 &unittest_params, 15882 &aes128cbc_hmac_sha1_aad_test_vector); 15883 } 15884 15885 static int 15886 test_chacha20_poly1305_encrypt_test_case_rfc8439(void) 15887 { 15888 return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439); 15889 } 15890 15891 static int 15892 test_chacha20_poly1305_decrypt_test_case_rfc8439(void) 15893 { 15894 return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439); 15895 } 15896 15897 static int 15898 test_chacha20_poly1305_encrypt_SGL_out_of_place(void) 15899 { 15900 return test_authenticated_encryption_SGL( 15901 &chacha20_poly1305_case_2, OUT_OF_PLACE, 32, 15902 chacha20_poly1305_case_2.plaintext.len); 15903 } 15904 15905 #ifdef RTE_CRYPTO_SCHEDULER 15906 15907 /* global AESNI worker IDs for the scheduler test */ 15908 uint8_t aesni_ids[2]; 15909 15910 static int 15911 scheduler_testsuite_setup(void) 15912 { 15913 uint32_t i = 0; 15914 int32_t nb_devs, ret; 15915 char vdev_args[VDEV_ARGS_SIZE] = {""}; 15916 char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core," 15917 "ordering=enable,name=cryptodev_test_scheduler,corelist="}; 15918 uint16_t worker_core_count = 0; 15919 uint16_t socket_id = 0; 15920 15921 if (gbl_driver_id == rte_cryptodev_driver_id_get( 15922 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) { 15923 15924 /* Identify the Worker Cores 15925 * Use 2 worker cores for the device args 15926 */ 15927 RTE_LCORE_FOREACH_WORKER(i) { 15928 if (worker_core_count > 1) 15929 break; 15930 snprintf(vdev_args, sizeof(vdev_args), 15931 "%s%d", temp_str, i); 15932 strcpy(temp_str, vdev_args); 15933 strlcat(temp_str, ";", sizeof(temp_str)); 15934 worker_core_count++; 15935 socket_id = rte_lcore_to_socket_id(i); 15936 } 15937 if (worker_core_count != 2) { 15938 RTE_LOG(ERR, USER1, 15939 "Cryptodev scheduler test require at least " 15940 "two worker cores to run. " 15941 "Please use the correct coremask.\n"); 15942 return TEST_FAILED; 15943 } 15944 strcpy(temp_str, vdev_args); 15945 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", 15946 temp_str, socket_id); 15947 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args); 15948 nb_devs = rte_cryptodev_device_count_by_driver( 15949 rte_cryptodev_driver_id_get( 15950 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))); 15951 if (nb_devs < 1) { 15952 ret = rte_vdev_init( 15953 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD), 15954 vdev_args); 15955 TEST_ASSERT(ret == 0, 15956 "Failed to create instance %u of pmd : %s", 15957 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 15958 } 15959 } 15960 return testsuite_setup(); 15961 } 15962 15963 static int 15964 test_scheduler_attach_worker_op(void) 15965 { 15966 struct crypto_testsuite_params *ts_params = &testsuite_params; 15967 uint8_t sched_id = ts_params->valid_devs[0]; 15968 uint32_t i, nb_devs_attached = 0; 15969 int ret; 15970 char vdev_name[32]; 15971 unsigned int count = rte_cryptodev_count(); 15972 15973 /* create 2 AESNI_MB vdevs on top of existing devices */ 15974 for (i = count; i < count + 2; i++) { 15975 snprintf(vdev_name, sizeof(vdev_name), "%s_%u", 15976 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), 15977 i); 15978 ret = rte_vdev_init(vdev_name, NULL); 15979 15980 TEST_ASSERT(ret == 0, 15981 "Failed to create instance %u of" 15982 " pmd : %s", 15983 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 15984 15985 if (ret < 0) { 15986 RTE_LOG(ERR, USER1, 15987 "Failed to create 2 AESNI MB PMDs.\n"); 15988 return TEST_SKIPPED; 15989 } 15990 } 15991 15992 /* attach 2 AESNI_MB cdevs */ 15993 for (i = count; i < count + 2; i++) { 15994 struct rte_cryptodev_info info; 15995 unsigned int session_size; 15996 15997 rte_cryptodev_info_get(i, &info); 15998 if (info.driver_id != rte_cryptodev_driver_id_get( 15999 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) 16000 continue; 16001 16002 session_size = rte_cryptodev_sym_get_private_session_size(i); 16003 /* 16004 * Create the session mempool again, since now there are new devices 16005 * to use the mempool. 16006 */ 16007 if (ts_params->session_mpool) { 16008 rte_mempool_free(ts_params->session_mpool); 16009 ts_params->session_mpool = NULL; 16010 } 16011 16012 if (info.sym.max_nb_sessions != 0 && 16013 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 16014 RTE_LOG(ERR, USER1, 16015 "Device does not support " 16016 "at least %u sessions\n", 16017 MAX_NB_SESSIONS); 16018 return TEST_FAILED; 16019 } 16020 /* 16021 * Create mempool with maximum number of sessions, 16022 * to include the session headers 16023 */ 16024 if (ts_params->session_mpool == NULL) { 16025 ts_params->session_mpool = 16026 rte_cryptodev_sym_session_pool_create( 16027 "test_sess_mp", 16028 MAX_NB_SESSIONS, session_size, 16029 0, 0, SOCKET_ID_ANY); 16030 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 16031 "session mempool allocation failed"); 16032 } 16033 16034 ts_params->qp_conf.mp_session = ts_params->session_mpool; 16035 16036 ret = rte_cryptodev_scheduler_worker_attach(sched_id, 16037 (uint8_t)i); 16038 16039 TEST_ASSERT(ret == 0, 16040 "Failed to attach device %u of pmd : %s", i, 16041 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 16042 16043 aesni_ids[nb_devs_attached] = (uint8_t)i; 16044 16045 nb_devs_attached++; 16046 } 16047 16048 return 0; 16049 } 16050 16051 static int 16052 test_scheduler_detach_worker_op(void) 16053 { 16054 struct crypto_testsuite_params *ts_params = &testsuite_params; 16055 uint8_t sched_id = ts_params->valid_devs[0]; 16056 uint32_t i; 16057 int ret; 16058 16059 for (i = 0; i < 2; i++) { 16060 ret = rte_cryptodev_scheduler_worker_detach(sched_id, 16061 aesni_ids[i]); 16062 TEST_ASSERT(ret == 0, 16063 "Failed to detach device %u", aesni_ids[i]); 16064 } 16065 16066 return 0; 16067 } 16068 16069 static int 16070 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode) 16071 { 16072 struct crypto_testsuite_params *ts_params = &testsuite_params; 16073 uint8_t sched_id = ts_params->valid_devs[0]; 16074 /* set mode */ 16075 return rte_cryptodev_scheduler_mode_set(sched_id, 16076 scheduler_mode); 16077 } 16078 16079 static int 16080 test_scheduler_mode_roundrobin_op(void) 16081 { 16082 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) == 16083 0, "Failed to set roundrobin mode"); 16084 return 0; 16085 16086 } 16087 16088 static int 16089 test_scheduler_mode_multicore_op(void) 16090 { 16091 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) == 16092 0, "Failed to set multicore mode"); 16093 16094 return 0; 16095 } 16096 16097 static int 16098 test_scheduler_mode_failover_op(void) 16099 { 16100 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) == 16101 0, "Failed to set failover mode"); 16102 16103 return 0; 16104 } 16105 16106 static int 16107 test_scheduler_mode_pkt_size_distr_op(void) 16108 { 16109 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) == 16110 0, "Failed to set pktsize mode"); 16111 16112 return 0; 16113 } 16114 16115 static int 16116 scheduler_multicore_testsuite_setup(void) 16117 { 16118 if (test_scheduler_attach_worker_op() < 0) 16119 return TEST_SKIPPED; 16120 if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0) 16121 return TEST_SKIPPED; 16122 return 0; 16123 } 16124 16125 static int 16126 scheduler_roundrobin_testsuite_setup(void) 16127 { 16128 if (test_scheduler_attach_worker_op() < 0) 16129 return TEST_SKIPPED; 16130 if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0) 16131 return TEST_SKIPPED; 16132 return 0; 16133 } 16134 16135 static int 16136 scheduler_failover_testsuite_setup(void) 16137 { 16138 if (test_scheduler_attach_worker_op() < 0) 16139 return TEST_SKIPPED; 16140 if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0) 16141 return TEST_SKIPPED; 16142 return 0; 16143 } 16144 16145 static int 16146 scheduler_pkt_size_distr_testsuite_setup(void) 16147 { 16148 if (test_scheduler_attach_worker_op() < 0) 16149 return TEST_SKIPPED; 16150 if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0) 16151 return TEST_SKIPPED; 16152 return 0; 16153 } 16154 16155 static void 16156 scheduler_mode_testsuite_teardown(void) 16157 { 16158 test_scheduler_detach_worker_op(); 16159 } 16160 16161 #endif /* RTE_CRYPTO_SCHEDULER */ 16162 16163 static struct unit_test_suite end_testsuite = { 16164 .suite_name = NULL, 16165 .setup = NULL, 16166 .teardown = NULL, 16167 .unit_test_suites = NULL 16168 }; 16169 16170 #ifdef RTE_LIB_SECURITY 16171 static struct unit_test_suite ipsec_proto_testsuite = { 16172 .suite_name = "IPsec Proto Unit Test Suite", 16173 .setup = ipsec_proto_testsuite_setup, 16174 .unit_test_cases = { 16175 TEST_CASE_NAMED_WITH_DATA( 16176 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 16177 ut_setup_security, ut_teardown, 16178 test_ipsec_proto_known_vec, &pkt_aes_128_gcm), 16179 TEST_CASE_NAMED_WITH_DATA( 16180 "Outbound known vector ext_mbuf mode (ESP tunnel mode IPv4 AES-GCM 128)", 16181 ut_setup_security, ut_teardown, 16182 test_ipsec_proto_known_vec_ext_mbuf, &pkt_aes_128_gcm), 16183 TEST_CASE_NAMED_WITH_DATA( 16184 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 16185 ut_setup_security, ut_teardown, 16186 test_ipsec_proto_known_vec, &pkt_aes_192_gcm), 16187 TEST_CASE_NAMED_WITH_DATA( 16188 "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 16189 ut_setup_security, ut_teardown, 16190 test_ipsec_proto_known_vec, &pkt_aes_256_gcm), 16191 TEST_CASE_NAMED_WITH_DATA( 16192 "Outbound known vector (ESP tunnel mode IPv4 AES-CCM 256)", 16193 ut_setup_security, ut_teardown, 16194 test_ipsec_proto_known_vec, &pkt_aes_256_ccm), 16195 TEST_CASE_NAMED_WITH_DATA( 16196 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC MD5 [12B ICV])", 16197 ut_setup_security, ut_teardown, 16198 test_ipsec_proto_known_vec, 16199 &pkt_aes_128_cbc_md5), 16200 TEST_CASE_NAMED_WITH_DATA( 16201 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])", 16202 ut_setup_security, ut_teardown, 16203 test_ipsec_proto_known_vec, 16204 &pkt_aes_128_cbc_hmac_sha256), 16205 TEST_CASE_NAMED_WITH_DATA( 16206 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])", 16207 ut_setup_security, ut_teardown, 16208 test_ipsec_proto_known_vec, 16209 &pkt_aes_128_cbc_hmac_sha384), 16210 TEST_CASE_NAMED_WITH_DATA( 16211 "Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])", 16212 ut_setup_security, ut_teardown, 16213 test_ipsec_proto_known_vec, 16214 &pkt_aes_128_cbc_hmac_sha512), 16215 TEST_CASE_NAMED_WITH_DATA( 16216 "Outbound known vector (ESP tunnel mode IPv6 AES-GCM 128)", 16217 ut_setup_security, ut_teardown, 16218 test_ipsec_proto_known_vec, &pkt_aes_256_gcm_v6), 16219 TEST_CASE_NAMED_WITH_DATA( 16220 "Outbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])", 16221 ut_setup_security, ut_teardown, 16222 test_ipsec_proto_known_vec, 16223 &pkt_aes_128_cbc_hmac_sha256_v6), 16224 TEST_CASE_NAMED_WITH_DATA( 16225 "Outbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])", 16226 ut_setup_security, ut_teardown, 16227 test_ipsec_proto_known_vec, 16228 &pkt_null_aes_xcbc), 16229 TEST_CASE_NAMED_WITH_DATA( 16230 "Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA256 [16B ICV])", 16231 ut_setup_security, ut_teardown, 16232 test_ipsec_proto_known_vec, 16233 &pkt_des_cbc_hmac_sha256), 16234 TEST_CASE_NAMED_WITH_DATA( 16235 "Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA384 [24B ICV])", 16236 ut_setup_security, ut_teardown, 16237 test_ipsec_proto_known_vec, 16238 &pkt_des_cbc_hmac_sha384), 16239 TEST_CASE_NAMED_WITH_DATA( 16240 "Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA512 [32B ICV])", 16241 ut_setup_security, ut_teardown, 16242 test_ipsec_proto_known_vec, 16243 &pkt_des_cbc_hmac_sha512), 16244 TEST_CASE_NAMED_WITH_DATA( 16245 "Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA256 [16B ICV])", 16246 ut_setup_security, ut_teardown, 16247 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha256), 16248 TEST_CASE_NAMED_WITH_DATA( 16249 "Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA384 [24B ICV])", 16250 ut_setup_security, ut_teardown, 16251 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha384), 16252 TEST_CASE_NAMED_WITH_DATA( 16253 "Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA512 [32B ICV])", 16254 ut_setup_security, ut_teardown, 16255 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha512), 16256 TEST_CASE_NAMED_WITH_DATA( 16257 "Outbound known vector (ESP tunnel mode IPv6 DES-CBC HMAC-SHA256 [16B ICV])", 16258 ut_setup_security, ut_teardown, 16259 test_ipsec_proto_known_vec, 16260 &pkt_des_cbc_hmac_sha256_v6), 16261 TEST_CASE_NAMED_WITH_DATA( 16262 "Outbound known vector (ESP tunnel mode IPv6 3DES-CBC HMAC-SHA256 [16B ICV])", 16263 ut_setup_security, ut_teardown, 16264 test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha256_v6), 16265 TEST_CASE_NAMED_WITH_DATA( 16266 "Outbound known vector (AH tunnel mode IPv4 HMAC-SHA256)", 16267 ut_setup_security, ut_teardown, 16268 test_ipsec_proto_known_vec, 16269 &pkt_ah_tunnel_sha256), 16270 TEST_CASE_NAMED_WITH_DATA( 16271 "Outbound known vector (AH transport mode IPv4 HMAC-SHA256)", 16272 ut_setup_security, ut_teardown, 16273 test_ipsec_proto_known_vec, 16274 &pkt_ah_transport_sha256), 16275 TEST_CASE_NAMED_WITH_DATA( 16276 "Outbound known vector (AH transport mode IPv4 AES-GMAC 128)", 16277 ut_setup_security, ut_teardown, 16278 test_ipsec_proto_known_vec, 16279 &pkt_ah_ipv4_aes_gmac_128), 16280 TEST_CASE_NAMED_WITH_DATA( 16281 "Outbound fragmented packet", 16282 ut_setup_security, ut_teardown, 16283 test_ipsec_proto_known_vec_fragmented, 16284 &pkt_aes_128_gcm_frag), 16285 TEST_CASE_NAMED_WITH_DATA( 16286 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", 16287 ut_setup_security, ut_teardown, 16288 test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm), 16289 TEST_CASE_NAMED_WITH_DATA( 16290 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", 16291 ut_setup_security, ut_teardown, 16292 test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm), 16293 TEST_CASE_NAMED_WITH_DATA( 16294 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)", 16295 ut_setup_security, ut_teardown, 16296 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm), 16297 TEST_CASE_NAMED_WITH_DATA( 16298 "Inbound known vector (ESP tunnel mode IPv4 AES-CCM 256)", 16299 ut_setup_security, ut_teardown, 16300 test_ipsec_proto_known_vec_inb, &pkt_aes_256_ccm), 16301 TEST_CASE_NAMED_WITH_DATA( 16302 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)", 16303 ut_setup_security, ut_teardown, 16304 test_ipsec_proto_known_vec_inb, &pkt_aes_128_cbc_null), 16305 TEST_CASE_NAMED_WITH_DATA( 16306 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC MD5 [12B ICV])", 16307 ut_setup_security, ut_teardown, 16308 test_ipsec_proto_known_vec_inb, 16309 &pkt_aes_128_cbc_md5), 16310 TEST_CASE_NAMED_WITH_DATA( 16311 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])", 16312 ut_setup_security, ut_teardown, 16313 test_ipsec_proto_known_vec_inb, 16314 &pkt_aes_128_cbc_hmac_sha256), 16315 TEST_CASE_NAMED_WITH_DATA( 16316 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])", 16317 ut_setup_security, ut_teardown, 16318 test_ipsec_proto_known_vec_inb, 16319 &pkt_aes_128_cbc_hmac_sha384), 16320 TEST_CASE_NAMED_WITH_DATA( 16321 "Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])", 16322 ut_setup_security, ut_teardown, 16323 test_ipsec_proto_known_vec_inb, 16324 &pkt_aes_128_cbc_hmac_sha512), 16325 TEST_CASE_NAMED_WITH_DATA( 16326 "Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)", 16327 ut_setup_security, ut_teardown, 16328 test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm_v6), 16329 TEST_CASE_NAMED_WITH_DATA( 16330 "Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])", 16331 ut_setup_security, ut_teardown, 16332 test_ipsec_proto_known_vec_inb, 16333 &pkt_aes_128_cbc_hmac_sha256_v6), 16334 TEST_CASE_NAMED_WITH_DATA( 16335 "Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])", 16336 ut_setup_security, ut_teardown, 16337 test_ipsec_proto_known_vec_inb, 16338 &pkt_null_aes_xcbc), 16339 TEST_CASE_NAMED_WITH_DATA( 16340 "Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA256 [16B ICV])", 16341 ut_setup_security, ut_teardown, 16342 test_ipsec_proto_known_vec_inb, 16343 &pkt_des_cbc_hmac_sha256), 16344 TEST_CASE_NAMED_WITH_DATA( 16345 "Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA384 [24B ICV])", 16346 ut_setup_security, ut_teardown, 16347 test_ipsec_proto_known_vec_inb, 16348 &pkt_des_cbc_hmac_sha384), 16349 TEST_CASE_NAMED_WITH_DATA( 16350 "Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA512 [32B ICV])", 16351 ut_setup_security, ut_teardown, 16352 test_ipsec_proto_known_vec_inb, 16353 &pkt_des_cbc_hmac_sha512), 16354 TEST_CASE_NAMED_WITH_DATA( 16355 "Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA256 [16B ICV])", 16356 ut_setup_security, ut_teardown, 16357 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha256), 16358 TEST_CASE_NAMED_WITH_DATA( 16359 "Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA384 [24B ICV])", 16360 ut_setup_security, ut_teardown, 16361 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha384), 16362 TEST_CASE_NAMED_WITH_DATA( 16363 "Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA512 [32B ICV])", 16364 ut_setup_security, ut_teardown, 16365 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha512), 16366 TEST_CASE_NAMED_WITH_DATA( 16367 "Inbound known vector (ESP tunnel mode IPv6 DES-CBC HMAC-SHA256 [16B ICV])", 16368 ut_setup_security, ut_teardown, 16369 test_ipsec_proto_known_vec_inb, 16370 &pkt_des_cbc_hmac_sha256_v6), 16371 TEST_CASE_NAMED_WITH_DATA( 16372 "Inbound known vector (ESP tunnel mode IPv6 3DES-CBC HMAC-SHA256 [16B ICV])", 16373 ut_setup_security, ut_teardown, 16374 test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha256_v6), 16375 TEST_CASE_NAMED_WITH_DATA( 16376 "Inbound known vector (AH tunnel mode IPv4 HMAC-SHA256)", 16377 ut_setup_security, ut_teardown, 16378 test_ipsec_proto_known_vec_inb, 16379 &pkt_ah_tunnel_sha256), 16380 TEST_CASE_NAMED_WITH_DATA( 16381 "Inbound known vector (AH transport mode IPv4 HMAC-SHA256)", 16382 ut_setup_security, ut_teardown, 16383 test_ipsec_proto_known_vec_inb, 16384 &pkt_ah_transport_sha256), 16385 TEST_CASE_NAMED_WITH_DATA( 16386 "Inbound known vector (AH transport mode IPv4 AES-GMAC 128)", 16387 ut_setup_security, ut_teardown, 16388 test_ipsec_proto_known_vec_inb, 16389 &pkt_ah_ipv4_aes_gmac_128), 16390 TEST_CASE_NAMED_ST( 16391 "Combined test alg list", 16392 ut_setup_security, ut_teardown, 16393 test_ipsec_proto_display_list), 16394 TEST_CASE_NAMED_ST( 16395 "Combined test alg list (AH)", 16396 ut_setup_security, ut_teardown, 16397 test_ipsec_proto_ah_tunnel_ipv4), 16398 TEST_CASE_NAMED_ST( 16399 "IV generation", 16400 ut_setup_security, ut_teardown, 16401 test_ipsec_proto_iv_gen), 16402 TEST_CASE_NAMED_ST( 16403 "UDP encapsulation", 16404 ut_setup_security, ut_teardown, 16405 test_ipsec_proto_udp_encap), 16406 TEST_CASE_NAMED_ST( 16407 "UDP encapsulation with custom ports", 16408 ut_setup_security, ut_teardown, 16409 test_ipsec_proto_udp_encap_custom_ports), 16410 TEST_CASE_NAMED_ST( 16411 "UDP encapsulation ports verification test", 16412 ut_setup_security, ut_teardown, 16413 test_ipsec_proto_udp_ports_verify), 16414 TEST_CASE_NAMED_ST( 16415 "SA expiry packets soft", 16416 ut_setup_security, ut_teardown, 16417 test_ipsec_proto_sa_exp_pkts_soft), 16418 TEST_CASE_NAMED_ST( 16419 "SA expiry packets hard", 16420 ut_setup_security, ut_teardown, 16421 test_ipsec_proto_sa_exp_pkts_hard), 16422 TEST_CASE_NAMED_ST( 16423 "Negative test: ICV corruption", 16424 ut_setup_security, ut_teardown, 16425 test_ipsec_proto_err_icv_corrupt), 16426 TEST_CASE_NAMED_ST( 16427 "Tunnel dst addr verification", 16428 ut_setup_security, ut_teardown, 16429 test_ipsec_proto_tunnel_dst_addr_verify), 16430 TEST_CASE_NAMED_ST( 16431 "Tunnel src and dst addr verification", 16432 ut_setup_security, ut_teardown, 16433 test_ipsec_proto_tunnel_src_dst_addr_verify), 16434 TEST_CASE_NAMED_ST( 16435 "Inner IP checksum", 16436 ut_setup_security, ut_teardown, 16437 test_ipsec_proto_inner_ip_csum), 16438 TEST_CASE_NAMED_ST( 16439 "Inner L4 checksum", 16440 ut_setup_security, ut_teardown, 16441 test_ipsec_proto_inner_l4_csum), 16442 TEST_CASE_NAMED_ST( 16443 "Tunnel IPv4 in IPv4", 16444 ut_setup_security, ut_teardown, 16445 test_ipsec_proto_tunnel_v4_in_v4), 16446 TEST_CASE_NAMED_ST( 16447 "Tunnel IPv6 in IPv6", 16448 ut_setup_security, ut_teardown, 16449 test_ipsec_proto_tunnel_v6_in_v6), 16450 TEST_CASE_NAMED_ST( 16451 "Tunnel IPv4 in IPv6", 16452 ut_setup_security, ut_teardown, 16453 test_ipsec_proto_tunnel_v4_in_v6), 16454 TEST_CASE_NAMED_ST( 16455 "Tunnel IPv6 in IPv4", 16456 ut_setup_security, ut_teardown, 16457 test_ipsec_proto_tunnel_v6_in_v4), 16458 TEST_CASE_NAMED_ST( 16459 "Transport IPv4", 16460 ut_setup_security, ut_teardown, 16461 test_ipsec_proto_transport_v4), 16462 TEST_CASE_NAMED_ST( 16463 "AH transport IPv4", 16464 ut_setup_security, ut_teardown, 16465 test_ipsec_proto_ah_transport_ipv4), 16466 TEST_CASE_NAMED_ST( 16467 "Transport l4 checksum", 16468 ut_setup_security, ut_teardown, 16469 test_ipsec_proto_transport_l4_csum), 16470 TEST_CASE_NAMED_ST( 16471 "Statistics: success", 16472 ut_setup_security, ut_teardown, 16473 test_ipsec_proto_stats), 16474 TEST_CASE_NAMED_ST( 16475 "Fragmented packet", 16476 ut_setup_security, ut_teardown, 16477 test_ipsec_proto_pkt_fragment), 16478 TEST_CASE_NAMED_ST( 16479 "Tunnel header copy DF (inner 0)", 16480 ut_setup_security, ut_teardown, 16481 test_ipsec_proto_copy_df_inner_0), 16482 TEST_CASE_NAMED_ST( 16483 "Tunnel header copy DF (inner 1)", 16484 ut_setup_security, ut_teardown, 16485 test_ipsec_proto_copy_df_inner_1), 16486 TEST_CASE_NAMED_ST( 16487 "Tunnel header set DF 0 (inner 1)", 16488 ut_setup_security, ut_teardown, 16489 test_ipsec_proto_set_df_0_inner_1), 16490 TEST_CASE_NAMED_ST( 16491 "Tunnel header set DF 1 (inner 0)", 16492 ut_setup_security, ut_teardown, 16493 test_ipsec_proto_set_df_1_inner_0), 16494 TEST_CASE_NAMED_ST( 16495 "Tunnel header IPv4 copy DSCP (inner 0)", 16496 ut_setup_security, ut_teardown, 16497 test_ipsec_proto_ipv4_copy_dscp_inner_0), 16498 TEST_CASE_NAMED_ST( 16499 "Tunnel header IPv4 copy DSCP (inner 1)", 16500 ut_setup_security, ut_teardown, 16501 test_ipsec_proto_ipv4_copy_dscp_inner_1), 16502 TEST_CASE_NAMED_ST( 16503 "Tunnel header IPv4 set DSCP 0 (inner 1)", 16504 ut_setup_security, ut_teardown, 16505 test_ipsec_proto_ipv4_set_dscp_0_inner_1), 16506 TEST_CASE_NAMED_ST( 16507 "Tunnel header IPv4 set DSCP 1 (inner 0)", 16508 ut_setup_security, ut_teardown, 16509 test_ipsec_proto_ipv4_set_dscp_1_inner_0), 16510 TEST_CASE_NAMED_ST( 16511 "Tunnel header IPv6 copy DSCP (inner 0)", 16512 ut_setup_security, ut_teardown, 16513 test_ipsec_proto_ipv6_copy_dscp_inner_0), 16514 TEST_CASE_NAMED_ST( 16515 "Tunnel header IPv6 copy DSCP (inner 1)", 16516 ut_setup_security, ut_teardown, 16517 test_ipsec_proto_ipv6_copy_dscp_inner_1), 16518 TEST_CASE_NAMED_ST( 16519 "Tunnel header IPv6 set DSCP 0 (inner 1)", 16520 ut_setup_security, ut_teardown, 16521 test_ipsec_proto_ipv6_set_dscp_0_inner_1), 16522 TEST_CASE_NAMED_ST( 16523 "Tunnel header IPv6 set DSCP 1 (inner 0)", 16524 ut_setup_security, ut_teardown, 16525 test_ipsec_proto_ipv6_set_dscp_1_inner_0), 16526 TEST_CASE_NAMED_WITH_DATA( 16527 "Antireplay with window size 1024", 16528 ut_setup_security, ut_teardown, 16529 test_ipsec_proto_pkt_antireplay1024, &pkt_aes_128_gcm), 16530 TEST_CASE_NAMED_WITH_DATA( 16531 "Antireplay with window size 2048", 16532 ut_setup_security, ut_teardown, 16533 test_ipsec_proto_pkt_antireplay2048, &pkt_aes_128_gcm), 16534 TEST_CASE_NAMED_WITH_DATA( 16535 "Antireplay with window size 4096", 16536 ut_setup_security, ut_teardown, 16537 test_ipsec_proto_pkt_antireplay4096, &pkt_aes_128_gcm), 16538 TEST_CASE_NAMED_WITH_DATA( 16539 "ESN and Antireplay with window size 1024", 16540 ut_setup_security, ut_teardown, 16541 test_ipsec_proto_pkt_esn_antireplay1024, 16542 &pkt_aes_128_gcm), 16543 TEST_CASE_NAMED_WITH_DATA( 16544 "ESN and Antireplay with window size 2048", 16545 ut_setup_security, ut_teardown, 16546 test_ipsec_proto_pkt_esn_antireplay2048, 16547 &pkt_aes_128_gcm), 16548 TEST_CASE_NAMED_WITH_DATA( 16549 "ESN and Antireplay with window size 4096", 16550 ut_setup_security, ut_teardown, 16551 test_ipsec_proto_pkt_esn_antireplay4096, 16552 &pkt_aes_128_gcm), 16553 TEST_CASE_NAMED_ST( 16554 "Tunnel header IPv4 decrement inner TTL", 16555 ut_setup_security, ut_teardown, 16556 test_ipsec_proto_ipv4_ttl_decrement), 16557 TEST_CASE_NAMED_ST( 16558 "Tunnel header IPv6 decrement inner hop limit", 16559 ut_setup_security, ut_teardown, 16560 test_ipsec_proto_ipv6_hop_limit_decrement), 16561 TEST_CASE_NAMED_ST( 16562 "Multi-segmented mode", 16563 ut_setup_security, ut_teardown, 16564 test_ipsec_proto_sgl), 16565 TEST_CASE_NAMED_ST( 16566 "Multi-segmented external mbuf mode", 16567 ut_setup_security, ut_teardown, 16568 test_ipsec_proto_sgl_ext_mbuf), 16569 TEST_CASE_NAMED_WITH_DATA( 16570 "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128) Rx inject", 16571 ut_setup_security_rx_inject, ut_teardown_rx_inject, 16572 test_ipsec_proto_known_vec_inb_rx_inject, &pkt_aes_128_gcm), 16573 TEST_CASES_END() /**< NULL terminate unit test array */ 16574 } 16575 }; 16576 16577 static struct unit_test_suite pdcp_proto_testsuite = { 16578 .suite_name = "PDCP Proto Unit Test Suite", 16579 .setup = pdcp_proto_testsuite_setup, 16580 .unit_test_cases = { 16581 TEST_CASE_ST(ut_setup_security, ut_teardown, 16582 test_PDCP_PROTO_all), 16583 TEST_CASES_END() /**< NULL terminate unit test array */ 16584 } 16585 }; 16586 16587 #define ADD_UPLINK_TESTCASE(data) \ 16588 TEST_CASE_NAMED_WITH_DATA(data.test_descr_uplink, ut_setup_security, \ 16589 ut_teardown, test_docsis_proto_uplink, (const void *) &data), \ 16590 16591 #define ADD_DOWNLINK_TESTCASE(data) \ 16592 TEST_CASE_NAMED_WITH_DATA(data.test_descr_downlink, ut_setup_security, \ 16593 ut_teardown, test_docsis_proto_downlink, (const void *) &data), \ 16594 16595 static struct unit_test_suite docsis_proto_testsuite = { 16596 .suite_name = "DOCSIS Proto Unit Test Suite", 16597 .setup = docsis_proto_testsuite_setup, 16598 .unit_test_cases = { 16599 /* Uplink */ 16600 ADD_UPLINK_TESTCASE(docsis_test_case_1) 16601 ADD_UPLINK_TESTCASE(docsis_test_case_2) 16602 ADD_UPLINK_TESTCASE(docsis_test_case_3) 16603 ADD_UPLINK_TESTCASE(docsis_test_case_4) 16604 ADD_UPLINK_TESTCASE(docsis_test_case_5) 16605 ADD_UPLINK_TESTCASE(docsis_test_case_6) 16606 ADD_UPLINK_TESTCASE(docsis_test_case_7) 16607 ADD_UPLINK_TESTCASE(docsis_test_case_8) 16608 ADD_UPLINK_TESTCASE(docsis_test_case_9) 16609 ADD_UPLINK_TESTCASE(docsis_test_case_10) 16610 ADD_UPLINK_TESTCASE(docsis_test_case_11) 16611 ADD_UPLINK_TESTCASE(docsis_test_case_12) 16612 ADD_UPLINK_TESTCASE(docsis_test_case_13) 16613 ADD_UPLINK_TESTCASE(docsis_test_case_14) 16614 ADD_UPLINK_TESTCASE(docsis_test_case_15) 16615 ADD_UPLINK_TESTCASE(docsis_test_case_16) 16616 ADD_UPLINK_TESTCASE(docsis_test_case_17) 16617 ADD_UPLINK_TESTCASE(docsis_test_case_18) 16618 ADD_UPLINK_TESTCASE(docsis_test_case_19) 16619 ADD_UPLINK_TESTCASE(docsis_test_case_20) 16620 ADD_UPLINK_TESTCASE(docsis_test_case_21) 16621 ADD_UPLINK_TESTCASE(docsis_test_case_22) 16622 ADD_UPLINK_TESTCASE(docsis_test_case_23) 16623 ADD_UPLINK_TESTCASE(docsis_test_case_24) 16624 ADD_UPLINK_TESTCASE(docsis_test_case_25) 16625 ADD_UPLINK_TESTCASE(docsis_test_case_26) 16626 /* Downlink */ 16627 ADD_DOWNLINK_TESTCASE(docsis_test_case_1) 16628 ADD_DOWNLINK_TESTCASE(docsis_test_case_2) 16629 ADD_DOWNLINK_TESTCASE(docsis_test_case_3) 16630 ADD_DOWNLINK_TESTCASE(docsis_test_case_4) 16631 ADD_DOWNLINK_TESTCASE(docsis_test_case_5) 16632 ADD_DOWNLINK_TESTCASE(docsis_test_case_6) 16633 ADD_DOWNLINK_TESTCASE(docsis_test_case_7) 16634 ADD_DOWNLINK_TESTCASE(docsis_test_case_8) 16635 ADD_DOWNLINK_TESTCASE(docsis_test_case_9) 16636 ADD_DOWNLINK_TESTCASE(docsis_test_case_10) 16637 ADD_DOWNLINK_TESTCASE(docsis_test_case_11) 16638 ADD_DOWNLINK_TESTCASE(docsis_test_case_12) 16639 ADD_DOWNLINK_TESTCASE(docsis_test_case_13) 16640 ADD_DOWNLINK_TESTCASE(docsis_test_case_14) 16641 ADD_DOWNLINK_TESTCASE(docsis_test_case_15) 16642 ADD_DOWNLINK_TESTCASE(docsis_test_case_16) 16643 ADD_DOWNLINK_TESTCASE(docsis_test_case_17) 16644 ADD_DOWNLINK_TESTCASE(docsis_test_case_18) 16645 ADD_DOWNLINK_TESTCASE(docsis_test_case_19) 16646 ADD_DOWNLINK_TESTCASE(docsis_test_case_20) 16647 ADD_DOWNLINK_TESTCASE(docsis_test_case_21) 16648 ADD_DOWNLINK_TESTCASE(docsis_test_case_22) 16649 ADD_DOWNLINK_TESTCASE(docsis_test_case_23) 16650 ADD_DOWNLINK_TESTCASE(docsis_test_case_24) 16651 ADD_DOWNLINK_TESTCASE(docsis_test_case_25) 16652 ADD_DOWNLINK_TESTCASE(docsis_test_case_26) 16653 TEST_CASES_END() /**< NULL terminate unit test array */ 16654 } 16655 }; 16656 #endif 16657 16658 static struct unit_test_suite cryptodev_gen_testsuite = { 16659 .suite_name = "Crypto General Unit Test Suite", 16660 .setup = crypto_gen_testsuite_setup, 16661 .unit_test_cases = { 16662 TEST_CASE_ST(ut_setup, ut_teardown, 16663 test_device_reconfigure), 16664 TEST_CASE_ST(ut_setup, ut_teardown, 16665 test_device_configure_invalid_dev_id), 16666 TEST_CASE_ST(ut_setup, ut_teardown, 16667 test_queue_pair_descriptor_setup), 16668 TEST_CASE_ST(ut_setup, ut_teardown, 16669 test_device_configure_invalid_queue_pair_ids), 16670 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 16671 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup), 16672 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup), 16673 TEST_CASES_END() /**< NULL terminate unit test array */ 16674 } 16675 }; 16676 16677 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = { 16678 .suite_name = "Negative HMAC SHA1 Unit Test Suite", 16679 .setup = negative_hmac_sha1_testsuite_setup, 16680 .unit_test_cases = { 16681 /** Negative tests */ 16682 TEST_CASE_ST(ut_setup, ut_teardown, 16683 authentication_verify_HMAC_SHA1_fail_data_corrupt), 16684 TEST_CASE_ST(ut_setup, ut_teardown, 16685 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 16686 TEST_CASE_ST(ut_setup, ut_teardown, 16687 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 16688 TEST_CASE_ST(ut_setup, ut_teardown, 16689 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 16690 16691 TEST_CASES_END() /**< NULL terminate unit test array */ 16692 } 16693 }; 16694 16695 static struct unit_test_suite cryptodev_multi_session_testsuite = { 16696 .suite_name = "Multi Session Unit Test Suite", 16697 .setup = multi_session_testsuite_setup, 16698 .unit_test_cases = { 16699 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 16700 TEST_CASE_ST(ut_setup, ut_teardown, 16701 test_multi_session_random_usage), 16702 16703 TEST_CASES_END() /**< NULL terminate unit test array */ 16704 } 16705 }; 16706 16707 static struct unit_test_suite cryptodev_null_testsuite = { 16708 .suite_name = "NULL Test Suite", 16709 .setup = null_testsuite_setup, 16710 .unit_test_cases = { 16711 TEST_CASE_ST(ut_setup, ut_teardown, 16712 test_null_invalid_operation), 16713 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation), 16714 TEST_CASES_END() 16715 } 16716 }; 16717 16718 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite = { 16719 .suite_name = "AES CCM Authenticated Test Suite", 16720 .setup = aes_ccm_auth_testsuite_setup, 16721 .unit_test_cases = { 16722 /** AES CCM Authenticated Encryption 128 bits key*/ 16723 TEST_CASE_ST(ut_setup, ut_teardown, 16724 test_AES_CCM_authenticated_encryption_test_case_128_1), 16725 TEST_CASE_ST(ut_setup, ut_teardown, 16726 test_AES_CCM_authenticated_encryption_test_case_128_2), 16727 TEST_CASE_ST(ut_setup, ut_teardown, 16728 test_AES_CCM_authenticated_encryption_test_case_128_3), 16729 16730 /** AES CCM Authenticated Decryption 128 bits key*/ 16731 TEST_CASE_ST(ut_setup, ut_teardown, 16732 test_AES_CCM_authenticated_decryption_test_case_128_1), 16733 TEST_CASE_ST(ut_setup, ut_teardown, 16734 test_AES_CCM_authenticated_decryption_test_case_128_2), 16735 TEST_CASE_ST(ut_setup, ut_teardown, 16736 test_AES_CCM_authenticated_decryption_test_case_128_3), 16737 16738 /** AES CCM Authenticated Encryption 192 bits key */ 16739 TEST_CASE_ST(ut_setup, ut_teardown, 16740 test_AES_CCM_authenticated_encryption_test_case_192_1), 16741 TEST_CASE_ST(ut_setup, ut_teardown, 16742 test_AES_CCM_authenticated_encryption_test_case_192_2), 16743 TEST_CASE_ST(ut_setup, ut_teardown, 16744 test_AES_CCM_authenticated_encryption_test_case_192_3), 16745 16746 /** AES CCM Authenticated Decryption 192 bits key*/ 16747 TEST_CASE_ST(ut_setup, ut_teardown, 16748 test_AES_CCM_authenticated_decryption_test_case_192_1), 16749 TEST_CASE_ST(ut_setup, ut_teardown, 16750 test_AES_CCM_authenticated_decryption_test_case_192_2), 16751 TEST_CASE_ST(ut_setup, ut_teardown, 16752 test_AES_CCM_authenticated_decryption_test_case_192_3), 16753 16754 /** AES CCM Authenticated Encryption 256 bits key */ 16755 TEST_CASE_ST(ut_setup, ut_teardown, 16756 test_AES_CCM_authenticated_encryption_test_case_256_1), 16757 TEST_CASE_ST(ut_setup, ut_teardown, 16758 test_AES_CCM_authenticated_encryption_test_case_256_2), 16759 TEST_CASE_ST(ut_setup, ut_teardown, 16760 test_AES_CCM_authenticated_encryption_test_case_256_3), 16761 16762 /** AES CCM Authenticated Decryption 256 bits key*/ 16763 TEST_CASE_ST(ut_setup, ut_teardown, 16764 test_AES_CCM_authenticated_decryption_test_case_256_1), 16765 TEST_CASE_ST(ut_setup, ut_teardown, 16766 test_AES_CCM_authenticated_decryption_test_case_256_2), 16767 TEST_CASE_ST(ut_setup, ut_teardown, 16768 test_AES_CCM_authenticated_decryption_test_case_256_3), 16769 TEST_CASES_END() 16770 } 16771 }; 16772 16773 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite = { 16774 .suite_name = "AES GCM Authenticated Test Suite", 16775 .setup = aes_gcm_auth_testsuite_setup, 16776 .unit_test_cases = { 16777 /** AES GCM Authenticated Encryption */ 16778 TEST_CASE_ST(ut_setup, ut_teardown, 16779 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 16780 TEST_CASE_ST(ut_setup, ut_teardown, 16781 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 16782 TEST_CASE_ST(ut_setup, ut_teardown, 16783 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 16784 TEST_CASE_ST(ut_setup, ut_teardown, 16785 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 16786 TEST_CASE_ST(ut_setup, ut_teardown, 16787 test_AES_GCM_authenticated_encryption_test_case_1), 16788 TEST_CASE_ST(ut_setup, ut_teardown, 16789 test_AES_GCM_authenticated_encryption_test_case_2), 16790 TEST_CASE_ST(ut_setup, ut_teardown, 16791 test_AES_GCM_authenticated_encryption_test_case_3), 16792 TEST_CASE_ST(ut_setup, ut_teardown, 16793 test_AES_GCM_authenticated_encryption_test_case_4), 16794 TEST_CASE_ST(ut_setup, ut_teardown, 16795 test_AES_GCM_authenticated_encryption_test_case_5), 16796 TEST_CASE_ST(ut_setup, ut_teardown, 16797 test_AES_GCM_authenticated_encryption_test_case_6), 16798 TEST_CASE_ST(ut_setup, ut_teardown, 16799 test_AES_GCM_authenticated_encryption_test_case_7), 16800 TEST_CASE_ST(ut_setup, ut_teardown, 16801 test_AES_GCM_authenticated_encryption_test_case_8), 16802 TEST_CASE_ST(ut_setup, ut_teardown, 16803 test_AES_GCM_J0_authenticated_encryption_test_case_1), 16804 16805 /** AES GCM Authenticated Decryption */ 16806 TEST_CASE_ST(ut_setup, ut_teardown, 16807 test_AES_GCM_authenticated_decryption_test_case_1), 16808 TEST_CASE_ST(ut_setup, ut_teardown, 16809 test_AES_GCM_authenticated_decryption_test_case_2), 16810 TEST_CASE_ST(ut_setup, ut_teardown, 16811 test_AES_GCM_authenticated_decryption_test_case_3), 16812 TEST_CASE_ST(ut_setup, ut_teardown, 16813 test_AES_GCM_authenticated_decryption_test_case_4), 16814 TEST_CASE_ST(ut_setup, ut_teardown, 16815 test_AES_GCM_authenticated_decryption_test_case_5), 16816 TEST_CASE_ST(ut_setup, ut_teardown, 16817 test_AES_GCM_authenticated_decryption_test_case_6), 16818 TEST_CASE_ST(ut_setup, ut_teardown, 16819 test_AES_GCM_authenticated_decryption_test_case_7), 16820 TEST_CASE_ST(ut_setup, ut_teardown, 16821 test_AES_GCM_authenticated_decryption_test_case_8), 16822 TEST_CASE_ST(ut_setup, ut_teardown, 16823 test_AES_GCM_J0_authenticated_decryption_test_case_1), 16824 16825 /** AES GCM Authenticated Encryption 192 bits key */ 16826 TEST_CASE_ST(ut_setup, ut_teardown, 16827 test_AES_GCM_auth_encryption_test_case_192_1), 16828 TEST_CASE_ST(ut_setup, ut_teardown, 16829 test_AES_GCM_auth_encryption_test_case_192_2), 16830 TEST_CASE_ST(ut_setup, ut_teardown, 16831 test_AES_GCM_auth_encryption_test_case_192_3), 16832 TEST_CASE_ST(ut_setup, ut_teardown, 16833 test_AES_GCM_auth_encryption_test_case_192_4), 16834 TEST_CASE_ST(ut_setup, ut_teardown, 16835 test_AES_GCM_auth_encryption_test_case_192_5), 16836 TEST_CASE_ST(ut_setup, ut_teardown, 16837 test_AES_GCM_auth_encryption_test_case_192_6), 16838 TEST_CASE_ST(ut_setup, ut_teardown, 16839 test_AES_GCM_auth_encryption_test_case_192_7), 16840 16841 /** AES GCM Authenticated Decryption 192 bits key */ 16842 TEST_CASE_ST(ut_setup, ut_teardown, 16843 test_AES_GCM_auth_decryption_test_case_192_1), 16844 TEST_CASE_ST(ut_setup, ut_teardown, 16845 test_AES_GCM_auth_decryption_test_case_192_2), 16846 TEST_CASE_ST(ut_setup, ut_teardown, 16847 test_AES_GCM_auth_decryption_test_case_192_3), 16848 TEST_CASE_ST(ut_setup, ut_teardown, 16849 test_AES_GCM_auth_decryption_test_case_192_4), 16850 TEST_CASE_ST(ut_setup, ut_teardown, 16851 test_AES_GCM_auth_decryption_test_case_192_5), 16852 TEST_CASE_ST(ut_setup, ut_teardown, 16853 test_AES_GCM_auth_decryption_test_case_192_6), 16854 TEST_CASE_ST(ut_setup, ut_teardown, 16855 test_AES_GCM_auth_decryption_test_case_192_7), 16856 16857 /** AES GCM Authenticated Encryption 256 bits key */ 16858 TEST_CASE_ST(ut_setup, ut_teardown, 16859 test_AES_GCM_auth_encryption_test_case_256_1), 16860 TEST_CASE_ST(ut_setup, ut_teardown, 16861 test_AES_GCM_auth_encryption_test_case_256_2), 16862 TEST_CASE_ST(ut_setup, ut_teardown, 16863 test_AES_GCM_auth_encryption_test_case_256_3), 16864 TEST_CASE_ST(ut_setup, ut_teardown, 16865 test_AES_GCM_auth_encryption_test_case_256_4), 16866 TEST_CASE_ST(ut_setup, ut_teardown, 16867 test_AES_GCM_auth_encryption_test_case_256_5), 16868 TEST_CASE_ST(ut_setup, ut_teardown, 16869 test_AES_GCM_auth_encryption_test_case_256_6), 16870 TEST_CASE_ST(ut_setup, ut_teardown, 16871 test_AES_GCM_auth_encryption_test_case_256_7), 16872 16873 /** AES GCM Authenticated Decryption 256 bits key */ 16874 TEST_CASE_ST(ut_setup, ut_teardown, 16875 test_AES_GCM_auth_decryption_test_case_256_1), 16876 TEST_CASE_ST(ut_setup, ut_teardown, 16877 test_AES_GCM_auth_decryption_test_case_256_2), 16878 TEST_CASE_ST(ut_setup, ut_teardown, 16879 test_AES_GCM_auth_decryption_test_case_256_3), 16880 TEST_CASE_ST(ut_setup, ut_teardown, 16881 test_AES_GCM_auth_decryption_test_case_256_4), 16882 TEST_CASE_ST(ut_setup, ut_teardown, 16883 test_AES_GCM_auth_decryption_test_case_256_5), 16884 TEST_CASE_ST(ut_setup, ut_teardown, 16885 test_AES_GCM_auth_decryption_test_case_256_6), 16886 TEST_CASE_ST(ut_setup, ut_teardown, 16887 test_AES_GCM_auth_decryption_test_case_256_7), 16888 16889 /** AES GCM Authenticated Encryption big aad size */ 16890 TEST_CASE_ST(ut_setup, ut_teardown, 16891 test_AES_GCM_auth_encryption_test_case_aad_1), 16892 TEST_CASE_ST(ut_setup, ut_teardown, 16893 test_AES_GCM_auth_encryption_test_case_aad_2), 16894 16895 /** AES GCM Authenticated Decryption big aad size */ 16896 TEST_CASE_ST(ut_setup, ut_teardown, 16897 test_AES_GCM_auth_decryption_test_case_aad_1), 16898 TEST_CASE_ST(ut_setup, ut_teardown, 16899 test_AES_GCM_auth_decryption_test_case_aad_2), 16900 16901 /** Out of place tests */ 16902 TEST_CASE_ST(ut_setup, ut_teardown, 16903 test_AES_GCM_authenticated_encryption_oop_test_case_1), 16904 TEST_CASE_ST(ut_setup, ut_teardown, 16905 test_AES_GCM_authenticated_decryption_oop_test_case_1), 16906 16907 /** Session-less tests */ 16908 TEST_CASE_ST(ut_setup, ut_teardown, 16909 test_AES_GCM_authenticated_encryption_sessionless_test_case_1), 16910 TEST_CASE_ST(ut_setup, ut_teardown, 16911 test_AES_GCM_authenticated_decryption_sessionless_test_case_1), 16912 16913 TEST_CASES_END() 16914 } 16915 }; 16916 16917 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite = { 16918 .suite_name = "AES GMAC Authentication Test Suite", 16919 .setup = aes_gmac_auth_testsuite_setup, 16920 .unit_test_cases = { 16921 TEST_CASE_ST(ut_setup, ut_teardown, 16922 test_AES_GMAC_authentication_test_case_1), 16923 TEST_CASE_ST(ut_setup, ut_teardown, 16924 test_AES_GMAC_authentication_verify_test_case_1), 16925 TEST_CASE_ST(ut_setup, ut_teardown, 16926 test_AES_GMAC_authentication_test_case_2), 16927 TEST_CASE_ST(ut_setup, ut_teardown, 16928 test_AES_GMAC_authentication_verify_test_case_2), 16929 TEST_CASE_ST(ut_setup, ut_teardown, 16930 test_AES_GMAC_authentication_test_case_3), 16931 TEST_CASE_ST(ut_setup, ut_teardown, 16932 test_AES_GMAC_authentication_verify_test_case_3), 16933 TEST_CASE_ST(ut_setup, ut_teardown, 16934 test_AES_GMAC_authentication_test_case_4), 16935 TEST_CASE_ST(ut_setup, ut_teardown, 16936 test_AES_GMAC_authentication_verify_test_case_4), 16937 TEST_CASE_ST(ut_setup, ut_teardown, 16938 test_AES_GMAC_authentication_SGL_40B), 16939 TEST_CASE_ST(ut_setup, ut_teardown, 16940 test_AES_GMAC_authentication_SGL_80B), 16941 TEST_CASE_ST(ut_setup, ut_teardown, 16942 test_AES_GMAC_authentication_SGL_2048B), 16943 TEST_CASE_ST(ut_setup, ut_teardown, 16944 test_AES_GMAC_authentication_SGL_2047B), 16945 16946 TEST_CASES_END() 16947 } 16948 }; 16949 16950 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite = { 16951 .suite_name = "Chacha20-Poly1305 Test Suite", 16952 .setup = chacha20_poly1305_testsuite_setup, 16953 .unit_test_cases = { 16954 TEST_CASE_ST(ut_setup, ut_teardown, 16955 test_chacha20_poly1305_encrypt_test_case_rfc8439), 16956 TEST_CASE_ST(ut_setup, ut_teardown, 16957 test_chacha20_poly1305_decrypt_test_case_rfc8439), 16958 TEST_CASE_ST(ut_setup, ut_teardown, 16959 test_chacha20_poly1305_encrypt_SGL_out_of_place), 16960 TEST_CASES_END() 16961 } 16962 }; 16963 16964 static struct unit_test_suite cryptodev_snow3g_testsuite = { 16965 .suite_name = "SNOW 3G Test Suite", 16966 .setup = snow3g_testsuite_setup, 16967 .unit_test_cases = { 16968 /** SNOW 3G encrypt only (UEA2) */ 16969 TEST_CASE_ST(ut_setup, ut_teardown, 16970 test_snow3g_encryption_test_case_1), 16971 TEST_CASE_ST(ut_setup, ut_teardown, 16972 test_snow3g_encryption_test_case_2), 16973 TEST_CASE_ST(ut_setup, ut_teardown, 16974 test_snow3g_encryption_test_case_3), 16975 TEST_CASE_ST(ut_setup, ut_teardown, 16976 test_snow3g_encryption_test_case_4), 16977 TEST_CASE_ST(ut_setup, ut_teardown, 16978 test_snow3g_encryption_test_case_5), 16979 16980 TEST_CASE_ST(ut_setup, ut_teardown, 16981 test_snow3g_encryption_test_case_1_oop), 16982 TEST_CASE_ST(ut_setup, ut_teardown, 16983 test_snow3g_encryption_test_case_1_oop_sgl), 16984 TEST_CASE_ST(ut_setup, ut_teardown, 16985 test_snow3g_encryption_test_case_1_oop_lb_in_sgl_out), 16986 TEST_CASE_ST(ut_setup, ut_teardown, 16987 test_snow3g_encryption_test_case_1_oop_sgl_in_lb_out), 16988 TEST_CASE_ST(ut_setup, ut_teardown, 16989 test_snow3g_encryption_test_case_1_offset_oop), 16990 TEST_CASE_ST(ut_setup, ut_teardown, 16991 test_snow3g_decryption_test_case_1_oop), 16992 16993 /** SNOW 3G generate auth, then encrypt (UEA2) */ 16994 TEST_CASE_ST(ut_setup, ut_teardown, 16995 test_snow3g_auth_cipher_test_case_1), 16996 TEST_CASE_ST(ut_setup, ut_teardown, 16997 test_snow3g_auth_cipher_test_case_2), 16998 TEST_CASE_ST(ut_setup, ut_teardown, 16999 test_snow3g_auth_cipher_test_case_2_oop), 17000 TEST_CASE_ST(ut_setup, ut_teardown, 17001 test_snow3g_auth_cipher_part_digest_enc), 17002 TEST_CASE_ST(ut_setup, ut_teardown, 17003 test_snow3g_auth_cipher_part_digest_enc_oop), 17004 TEST_CASE_ST(ut_setup, ut_teardown, 17005 test_snow3g_auth_cipher_test_case_3_sgl), 17006 TEST_CASE_ST(ut_setup, ut_teardown, 17007 test_snow3g_auth_cipher_test_case_3_oop_sgl), 17008 TEST_CASE_ST(ut_setup, ut_teardown, 17009 test_snow3g_auth_cipher_part_digest_enc_sgl), 17010 TEST_CASE_ST(ut_setup, ut_teardown, 17011 test_snow3g_auth_cipher_part_digest_enc_oop_sgl), 17012 TEST_CASE_ST(ut_setup, ut_teardown, 17013 test_snow3g_auth_cipher_total_digest_enc_1), 17014 TEST_CASE_ST(ut_setup, ut_teardown, 17015 test_snow3g_auth_cipher_total_digest_enc_1_oop), 17016 TEST_CASE_ST(ut_setup, ut_teardown, 17017 test_snow3g_auth_cipher_total_digest_enc_1_sgl), 17018 TEST_CASE_ST(ut_setup, ut_teardown, 17019 test_snow3g_auth_cipher_total_digest_enc_1_oop_sgl), 17020 17021 /** SNOW 3G decrypt (UEA2), then verify auth */ 17022 TEST_CASE_ST(ut_setup, ut_teardown, 17023 test_snow3g_auth_cipher_verify_test_case_1), 17024 TEST_CASE_ST(ut_setup, ut_teardown, 17025 test_snow3g_auth_cipher_verify_test_case_2), 17026 TEST_CASE_ST(ut_setup, ut_teardown, 17027 test_snow3g_auth_cipher_verify_test_case_2_oop), 17028 TEST_CASE_ST(ut_setup, ut_teardown, 17029 test_snow3g_auth_cipher_verify_part_digest_enc), 17030 TEST_CASE_ST(ut_setup, ut_teardown, 17031 test_snow3g_auth_cipher_verify_part_digest_enc_oop), 17032 TEST_CASE_ST(ut_setup, ut_teardown, 17033 test_snow3g_auth_cipher_verify_test_case_3_sgl), 17034 TEST_CASE_ST(ut_setup, ut_teardown, 17035 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl), 17036 TEST_CASE_ST(ut_setup, ut_teardown, 17037 test_snow3g_auth_cipher_verify_part_digest_enc_sgl), 17038 TEST_CASE_ST(ut_setup, ut_teardown, 17039 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl), 17040 TEST_CASE_ST(ut_setup, ut_teardown, 17041 test_snow3g_auth_cipher_verify_total_digest_enc_1), 17042 TEST_CASE_ST(ut_setup, ut_teardown, 17043 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop), 17044 TEST_CASE_ST(ut_setup, ut_teardown, 17045 test_snow3g_auth_cipher_verify_total_digest_enc_1_sgl), 17046 TEST_CASE_ST(ut_setup, ut_teardown, 17047 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop_sgl), 17048 17049 /** SNOW 3G decrypt only (UEA2) */ 17050 TEST_CASE_ST(ut_setup, ut_teardown, 17051 test_snow3g_decryption_test_case_1), 17052 TEST_CASE_ST(ut_setup, ut_teardown, 17053 test_snow3g_decryption_test_case_2), 17054 TEST_CASE_ST(ut_setup, ut_teardown, 17055 test_snow3g_decryption_test_case_3), 17056 TEST_CASE_ST(ut_setup, ut_teardown, 17057 test_snow3g_decryption_test_case_4), 17058 TEST_CASE_ST(ut_setup, ut_teardown, 17059 test_snow3g_decryption_test_case_5), 17060 TEST_CASE_ST(ut_setup, ut_teardown, 17061 test_snow3g_decryption_with_digest_test_case_1), 17062 TEST_CASE_ST(ut_setup, ut_teardown, 17063 test_snow3g_hash_generate_test_case_1), 17064 TEST_CASE_ST(ut_setup, ut_teardown, 17065 test_snow3g_hash_generate_test_case_2), 17066 TEST_CASE_ST(ut_setup, ut_teardown, 17067 test_snow3g_hash_generate_test_case_3), 17068 17069 /* Tests with buffers which length is not byte-aligned */ 17070 TEST_CASE_ST(ut_setup, ut_teardown, 17071 test_snow3g_hash_generate_test_case_4), 17072 TEST_CASE_ST(ut_setup, ut_teardown, 17073 test_snow3g_hash_generate_test_case_5), 17074 TEST_CASE_ST(ut_setup, ut_teardown, 17075 test_snow3g_hash_generate_test_case_6), 17076 TEST_CASE_ST(ut_setup, ut_teardown, 17077 test_snow3g_hash_verify_test_case_1), 17078 TEST_CASE_ST(ut_setup, ut_teardown, 17079 test_snow3g_hash_verify_test_case_2), 17080 TEST_CASE_ST(ut_setup, ut_teardown, 17081 test_snow3g_hash_verify_test_case_3), 17082 17083 /* Tests with buffers which length is not byte-aligned */ 17084 TEST_CASE_ST(ut_setup, ut_teardown, 17085 test_snow3g_hash_verify_test_case_4), 17086 TEST_CASE_ST(ut_setup, ut_teardown, 17087 test_snow3g_hash_verify_test_case_5), 17088 TEST_CASE_ST(ut_setup, ut_teardown, 17089 test_snow3g_hash_verify_test_case_6), 17090 TEST_CASE_ST(ut_setup, ut_teardown, 17091 test_snow3g_cipher_auth_test_case_1), 17092 TEST_CASE_ST(ut_setup, ut_teardown, 17093 test_snow3g_auth_cipher_with_digest_test_case_1), 17094 TEST_CASES_END() 17095 } 17096 }; 17097 17098 static struct unit_test_suite cryptodev_zuc_testsuite = { 17099 .suite_name = "ZUC Test Suite", 17100 .setup = zuc_testsuite_setup, 17101 .unit_test_cases = { 17102 /** ZUC encrypt only (EEA3) */ 17103 TEST_CASE_ST(ut_setup, ut_teardown, 17104 test_zuc_encryption_test_case_1), 17105 TEST_CASE_ST(ut_setup, ut_teardown, 17106 test_zuc_encryption_test_case_2), 17107 TEST_CASE_ST(ut_setup, ut_teardown, 17108 test_zuc_encryption_test_case_3), 17109 TEST_CASE_ST(ut_setup, ut_teardown, 17110 test_zuc_encryption_test_case_4), 17111 TEST_CASE_ST(ut_setup, ut_teardown, 17112 test_zuc_encryption_test_case_5), 17113 TEST_CASE_ST(ut_setup, ut_teardown, 17114 test_zuc_encryption_test_case_6_sgl), 17115 17116 /** ZUC decrypt only (EEA3) */ 17117 TEST_CASE_ST(ut_setup, ut_teardown, 17118 test_zuc_decryption_test_case_1), 17119 TEST_CASE_ST(ut_setup, ut_teardown, 17120 test_zuc_decryption_test_case_2), 17121 TEST_CASE_ST(ut_setup, ut_teardown, 17122 test_zuc_decryption_test_case_3), 17123 TEST_CASE_ST(ut_setup, ut_teardown, 17124 test_zuc_decryption_test_case_4), 17125 TEST_CASE_ST(ut_setup, ut_teardown, 17126 test_zuc_decryption_test_case_5), 17127 TEST_CASE_ST(ut_setup, ut_teardown, 17128 test_zuc_decryption_test_case_6_sgl), 17129 17130 /** ZUC authenticate (EIA3) */ 17131 TEST_CASE_ST(ut_setup, ut_teardown, 17132 test_zuc_hash_generate_test_case_1), 17133 TEST_CASE_ST(ut_setup, ut_teardown, 17134 test_zuc_hash_generate_test_case_2), 17135 TEST_CASE_ST(ut_setup, ut_teardown, 17136 test_zuc_hash_generate_test_case_3), 17137 TEST_CASE_ST(ut_setup, ut_teardown, 17138 test_zuc_hash_generate_test_case_4), 17139 TEST_CASE_ST(ut_setup, ut_teardown, 17140 test_zuc_hash_generate_test_case_5), 17141 TEST_CASE_ST(ut_setup, ut_teardown, 17142 test_zuc_hash_generate_test_case_6), 17143 TEST_CASE_ST(ut_setup, ut_teardown, 17144 test_zuc_hash_generate_test_case_7), 17145 TEST_CASE_ST(ut_setup, ut_teardown, 17146 test_zuc_hash_generate_test_case_8), 17147 17148 /** ZUC verify (EIA3) */ 17149 TEST_CASE_ST(ut_setup, ut_teardown, 17150 test_zuc_hash_verify_test_case_1), 17151 TEST_CASE_ST(ut_setup, ut_teardown, 17152 test_zuc_hash_verify_test_case_2), 17153 TEST_CASE_ST(ut_setup, ut_teardown, 17154 test_zuc_hash_verify_test_case_3), 17155 TEST_CASE_ST(ut_setup, ut_teardown, 17156 test_zuc_hash_verify_test_case_4), 17157 TEST_CASE_ST(ut_setup, ut_teardown, 17158 test_zuc_hash_verify_test_case_5), 17159 TEST_CASE_ST(ut_setup, ut_teardown, 17160 test_zuc_hash_verify_test_case_6), 17161 TEST_CASE_ST(ut_setup, ut_teardown, 17162 test_zuc_hash_verify_test_case_7), 17163 TEST_CASE_ST(ut_setup, ut_teardown, 17164 test_zuc_hash_verify_test_case_8), 17165 17166 /** ZUC alg-chain (EEA3/EIA3) */ 17167 TEST_CASE_ST(ut_setup, ut_teardown, 17168 test_zuc_cipher_auth_test_case_1), 17169 TEST_CASE_ST(ut_setup, ut_teardown, 17170 test_zuc_cipher_auth_test_case_2), 17171 17172 /** ZUC generate auth, then encrypt (EEA3) */ 17173 TEST_CASE_ST(ut_setup, ut_teardown, 17174 test_zuc_auth_cipher_test_case_1), 17175 TEST_CASE_ST(ut_setup, ut_teardown, 17176 test_zuc_auth_cipher_test_case_1_oop), 17177 TEST_CASE_ST(ut_setup, ut_teardown, 17178 test_zuc_auth_cipher_test_case_1_sgl), 17179 TEST_CASE_ST(ut_setup, ut_teardown, 17180 test_zuc_auth_cipher_test_case_1_oop_sgl), 17181 TEST_CASE_ST(ut_setup, ut_teardown, 17182 test_zuc_auth_cipher_test_case_2), 17183 TEST_CASE_ST(ut_setup, ut_teardown, 17184 test_zuc_auth_cipher_test_case_2_oop), 17185 17186 /** ZUC decrypt (EEA3), then verify auth */ 17187 TEST_CASE_ST(ut_setup, ut_teardown, 17188 test_zuc_auth_cipher_verify_test_case_1), 17189 TEST_CASE_ST(ut_setup, ut_teardown, 17190 test_zuc_auth_cipher_verify_test_case_1_oop), 17191 TEST_CASE_ST(ut_setup, ut_teardown, 17192 test_zuc_auth_cipher_verify_test_case_1_sgl), 17193 TEST_CASE_ST(ut_setup, ut_teardown, 17194 test_zuc_auth_cipher_verify_test_case_1_oop_sgl), 17195 TEST_CASE_ST(ut_setup, ut_teardown, 17196 test_zuc_auth_cipher_verify_test_case_2), 17197 TEST_CASE_ST(ut_setup, ut_teardown, 17198 test_zuc_auth_cipher_verify_test_case_2_oop), 17199 17200 /** ZUC-256 encrypt only **/ 17201 TEST_CASE_ST(ut_setup, ut_teardown, 17202 test_zuc256_encryption_test_case_1), 17203 TEST_CASE_ST(ut_setup, ut_teardown, 17204 test_zuc256_encryption_test_case_2), 17205 17206 /** ZUC-256 decrypt only **/ 17207 TEST_CASE_ST(ut_setup, ut_teardown, 17208 test_zuc256_decryption_test_case_1), 17209 TEST_CASE_ST(ut_setup, ut_teardown, 17210 test_zuc256_decryption_test_case_2), 17211 17212 /** ZUC-256 authentication only **/ 17213 TEST_CASE_ST(ut_setup, ut_teardown, 17214 test_zuc256_hash_generate_4b_tag_test_case_1), 17215 TEST_CASE_ST(ut_setup, ut_teardown, 17216 test_zuc256_hash_generate_4b_tag_test_case_2), 17217 TEST_CASE_ST(ut_setup, ut_teardown, 17218 test_zuc256_hash_generate_4b_tag_test_case_3), 17219 TEST_CASE_ST(ut_setup, ut_teardown, 17220 test_zuc256_hash_generate_8b_tag_test_case_1), 17221 TEST_CASE_ST(ut_setup, ut_teardown, 17222 test_zuc256_hash_generate_16b_tag_test_case_1), 17223 17224 /** ZUC-256 authentication verify only **/ 17225 TEST_CASE_ST(ut_setup, ut_teardown, 17226 test_zuc256_hash_verify_4b_tag_test_case_1), 17227 TEST_CASE_ST(ut_setup, ut_teardown, 17228 test_zuc256_hash_verify_4b_tag_test_case_2), 17229 TEST_CASE_ST(ut_setup, ut_teardown, 17230 test_zuc256_hash_verify_4b_tag_test_case_3), 17231 TEST_CASE_ST(ut_setup, ut_teardown, 17232 test_zuc256_hash_verify_8b_tag_test_case_1), 17233 TEST_CASE_ST(ut_setup, ut_teardown, 17234 test_zuc256_hash_verify_16b_tag_test_case_1), 17235 17236 /** ZUC-256 encrypt and authenticate **/ 17237 TEST_CASE_ST(ut_setup, ut_teardown, 17238 test_zuc256_cipher_auth_4b_tag_test_case_1), 17239 TEST_CASE_ST(ut_setup, ut_teardown, 17240 test_zuc256_cipher_auth_4b_tag_test_case_2), 17241 TEST_CASE_ST(ut_setup, ut_teardown, 17242 test_zuc256_cipher_auth_8b_tag_test_case_1), 17243 TEST_CASE_ST(ut_setup, ut_teardown, 17244 test_zuc256_cipher_auth_16b_tag_test_case_1), 17245 17246 /** ZUC-256 generate auth, then encrypt */ 17247 TEST_CASE_ST(ut_setup, ut_teardown, 17248 test_zuc256_auth_cipher_4b_tag_test_case_1), 17249 TEST_CASE_ST(ut_setup, ut_teardown, 17250 test_zuc256_auth_cipher_4b_tag_test_case_2), 17251 TEST_CASE_ST(ut_setup, ut_teardown, 17252 test_zuc256_auth_cipher_8b_tag_test_case_1), 17253 TEST_CASE_ST(ut_setup, ut_teardown, 17254 test_zuc256_auth_cipher_16b_tag_test_case_1), 17255 17256 /** ZUC-256 decrypt, then verify auth */ 17257 TEST_CASE_ST(ut_setup, ut_teardown, 17258 test_zuc256_auth_cipher_verify_4b_tag_test_case_1), 17259 TEST_CASE_ST(ut_setup, ut_teardown, 17260 test_zuc256_auth_cipher_verify_4b_tag_test_case_2), 17261 TEST_CASE_ST(ut_setup, ut_teardown, 17262 test_zuc256_auth_cipher_verify_8b_tag_test_case_1), 17263 TEST_CASE_ST(ut_setup, ut_teardown, 17264 test_zuc256_auth_cipher_verify_16b_tag_test_case_1), 17265 17266 TEST_CASES_END() 17267 } 17268 }; 17269 17270 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite = { 17271 .suite_name = "HMAC_MD5 Authentication Test Suite", 17272 .setup = hmac_md5_auth_testsuite_setup, 17273 .unit_test_cases = { 17274 TEST_CASE_ST(ut_setup, ut_teardown, 17275 test_MD5_HMAC_generate_case_1), 17276 TEST_CASE_ST(ut_setup, ut_teardown, 17277 test_MD5_HMAC_verify_case_1), 17278 TEST_CASE_ST(ut_setup, ut_teardown, 17279 test_MD5_HMAC_generate_case_2), 17280 TEST_CASE_ST(ut_setup, ut_teardown, 17281 test_MD5_HMAC_verify_case_2), 17282 TEST_CASES_END() 17283 } 17284 }; 17285 17286 static struct unit_test_suite cryptodev_kasumi_testsuite = { 17287 .suite_name = "Kasumi Test Suite", 17288 .setup = kasumi_testsuite_setup, 17289 .unit_test_cases = { 17290 /** KASUMI hash only (UIA1) */ 17291 TEST_CASE_ST(ut_setup, ut_teardown, 17292 test_kasumi_hash_generate_test_case_1), 17293 TEST_CASE_ST(ut_setup, ut_teardown, 17294 test_kasumi_hash_generate_test_case_2), 17295 TEST_CASE_ST(ut_setup, ut_teardown, 17296 test_kasumi_hash_generate_test_case_3), 17297 TEST_CASE_ST(ut_setup, ut_teardown, 17298 test_kasumi_hash_generate_test_case_4), 17299 TEST_CASE_ST(ut_setup, ut_teardown, 17300 test_kasumi_hash_generate_test_case_5), 17301 TEST_CASE_ST(ut_setup, ut_teardown, 17302 test_kasumi_hash_generate_test_case_6), 17303 17304 TEST_CASE_ST(ut_setup, ut_teardown, 17305 test_kasumi_hash_verify_test_case_1), 17306 TEST_CASE_ST(ut_setup, ut_teardown, 17307 test_kasumi_hash_verify_test_case_2), 17308 TEST_CASE_ST(ut_setup, ut_teardown, 17309 test_kasumi_hash_verify_test_case_3), 17310 TEST_CASE_ST(ut_setup, ut_teardown, 17311 test_kasumi_hash_verify_test_case_4), 17312 TEST_CASE_ST(ut_setup, ut_teardown, 17313 test_kasumi_hash_verify_test_case_5), 17314 17315 /** KASUMI encrypt only (UEA1) */ 17316 TEST_CASE_ST(ut_setup, ut_teardown, 17317 test_kasumi_encryption_test_case_1), 17318 TEST_CASE_ST(ut_setup, ut_teardown, 17319 test_kasumi_encryption_test_case_1_sgl), 17320 TEST_CASE_ST(ut_setup, ut_teardown, 17321 test_kasumi_encryption_test_case_1_oop), 17322 TEST_CASE_ST(ut_setup, ut_teardown, 17323 test_kasumi_encryption_test_case_1_oop_sgl), 17324 TEST_CASE_ST(ut_setup, ut_teardown, 17325 test_kasumi_encryption_test_case_2), 17326 TEST_CASE_ST(ut_setup, ut_teardown, 17327 test_kasumi_encryption_test_case_3), 17328 TEST_CASE_ST(ut_setup, ut_teardown, 17329 test_kasumi_encryption_test_case_4), 17330 TEST_CASE_ST(ut_setup, ut_teardown, 17331 test_kasumi_encryption_test_case_5), 17332 17333 /** KASUMI decrypt only (UEA1) */ 17334 TEST_CASE_ST(ut_setup, ut_teardown, 17335 test_kasumi_decryption_test_case_1), 17336 TEST_CASE_ST(ut_setup, ut_teardown, 17337 test_kasumi_decryption_test_case_2), 17338 TEST_CASE_ST(ut_setup, ut_teardown, 17339 test_kasumi_decryption_test_case_3), 17340 TEST_CASE_ST(ut_setup, ut_teardown, 17341 test_kasumi_decryption_test_case_4), 17342 TEST_CASE_ST(ut_setup, ut_teardown, 17343 test_kasumi_decryption_test_case_5), 17344 TEST_CASE_ST(ut_setup, ut_teardown, 17345 test_kasumi_decryption_test_case_1_oop), 17346 TEST_CASE_ST(ut_setup, ut_teardown, 17347 test_kasumi_cipher_auth_test_case_1), 17348 17349 /** KASUMI generate auth, then encrypt (F8) */ 17350 TEST_CASE_ST(ut_setup, ut_teardown, 17351 test_kasumi_auth_cipher_test_case_1), 17352 TEST_CASE_ST(ut_setup, ut_teardown, 17353 test_kasumi_auth_cipher_test_case_2), 17354 TEST_CASE_ST(ut_setup, ut_teardown, 17355 test_kasumi_auth_cipher_test_case_2_oop), 17356 TEST_CASE_ST(ut_setup, ut_teardown, 17357 test_kasumi_auth_cipher_test_case_2_sgl), 17358 TEST_CASE_ST(ut_setup, ut_teardown, 17359 test_kasumi_auth_cipher_test_case_2_oop_sgl), 17360 17361 /** KASUMI decrypt (F8), then verify auth */ 17362 TEST_CASE_ST(ut_setup, ut_teardown, 17363 test_kasumi_auth_cipher_verify_test_case_1), 17364 TEST_CASE_ST(ut_setup, ut_teardown, 17365 test_kasumi_auth_cipher_verify_test_case_2), 17366 TEST_CASE_ST(ut_setup, ut_teardown, 17367 test_kasumi_auth_cipher_verify_test_case_2_oop), 17368 TEST_CASE_ST(ut_setup, ut_teardown, 17369 test_kasumi_auth_cipher_verify_test_case_2_sgl), 17370 TEST_CASE_ST(ut_setup, ut_teardown, 17371 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl), 17372 17373 TEST_CASES_END() 17374 } 17375 }; 17376 17377 static struct unit_test_suite cryptodev_esn_testsuite = { 17378 .suite_name = "ESN Test Suite", 17379 .setup = esn_testsuite_setup, 17380 .unit_test_cases = { 17381 TEST_CASE_ST(ut_setup, ut_teardown, 17382 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 17383 TEST_CASE_ST(ut_setup, ut_teardown, 17384 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 17385 TEST_CASES_END() 17386 } 17387 }; 17388 17389 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite = { 17390 .suite_name = "Negative AES GCM Test Suite", 17391 .setup = negative_aes_gcm_testsuite_setup, 17392 .unit_test_cases = { 17393 TEST_CASE_ST(ut_setup, ut_teardown, 17394 test_AES_GCM_auth_encryption_fail_iv_corrupt), 17395 TEST_CASE_ST(ut_setup, ut_teardown, 17396 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 17397 TEST_CASE_ST(ut_setup, ut_teardown, 17398 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 17399 TEST_CASE_ST(ut_setup, ut_teardown, 17400 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 17401 TEST_CASE_ST(ut_setup, ut_teardown, 17402 test_AES_GCM_auth_encryption_fail_aad_corrupt), 17403 TEST_CASE_ST(ut_setup, ut_teardown, 17404 test_AES_GCM_auth_encryption_fail_tag_corrupt), 17405 TEST_CASE_ST(ut_setup, ut_teardown, 17406 test_AES_GCM_auth_decryption_fail_iv_corrupt), 17407 TEST_CASE_ST(ut_setup, ut_teardown, 17408 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 17409 TEST_CASE_ST(ut_setup, ut_teardown, 17410 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 17411 TEST_CASE_ST(ut_setup, ut_teardown, 17412 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 17413 TEST_CASE_ST(ut_setup, ut_teardown, 17414 test_AES_GCM_auth_decryption_fail_aad_corrupt), 17415 TEST_CASE_ST(ut_setup, ut_teardown, 17416 test_AES_GCM_auth_decryption_fail_tag_corrupt), 17417 17418 TEST_CASES_END() 17419 } 17420 }; 17421 17422 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite = { 17423 .suite_name = "Negative AES GMAC Test Suite", 17424 .setup = negative_aes_gmac_testsuite_setup, 17425 .unit_test_cases = { 17426 TEST_CASE_ST(ut_setup, ut_teardown, 17427 authentication_verify_AES128_GMAC_fail_data_corrupt), 17428 TEST_CASE_ST(ut_setup, ut_teardown, 17429 authentication_verify_AES128_GMAC_fail_tag_corrupt), 17430 17431 TEST_CASES_END() 17432 } 17433 }; 17434 17435 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite = { 17436 .suite_name = "Mixed CIPHER + HASH algorithms Test Suite", 17437 .setup = mixed_cipher_hash_testsuite_setup, 17438 .unit_test_cases = { 17439 /** AUTH AES CMAC + CIPHER AES CTR */ 17440 TEST_CASE_ST(ut_setup, ut_teardown, 17441 test_aes_cmac_aes_ctr_digest_enc_test_case_1), 17442 TEST_CASE_ST(ut_setup, ut_teardown, 17443 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 17444 TEST_CASE_ST(ut_setup, ut_teardown, 17445 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 17446 TEST_CASE_ST(ut_setup, ut_teardown, 17447 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 17448 TEST_CASE_ST(ut_setup, ut_teardown, 17449 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1), 17450 TEST_CASE_ST(ut_setup, ut_teardown, 17451 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 17452 TEST_CASE_ST(ut_setup, ut_teardown, 17453 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 17454 TEST_CASE_ST(ut_setup, ut_teardown, 17455 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 17456 TEST_CASE_ST(ut_setup, ut_teardown, 17457 test_aes_cmac_aes_ctr_digest_enc_test_case_2), 17458 TEST_CASE_ST(ut_setup, ut_teardown, 17459 test_aes_cmac_aes_ctr_digest_enc_test_case_2_oop), 17460 TEST_CASE_ST(ut_setup, ut_teardown, 17461 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2), 17462 TEST_CASE_ST(ut_setup, ut_teardown, 17463 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2_oop), 17464 17465 /** AUTH ZUC + CIPHER SNOW3G */ 17466 TEST_CASE_ST(ut_setup, ut_teardown, 17467 test_auth_zuc_cipher_snow_test_case_1), 17468 TEST_CASE_ST(ut_setup, ut_teardown, 17469 test_verify_auth_zuc_cipher_snow_test_case_1), 17470 TEST_CASE_ST(ut_setup, ut_teardown, 17471 test_auth_zuc_cipher_snow_test_case_1_inplace), 17472 TEST_CASE_ST(ut_setup, ut_teardown, 17473 test_verify_auth_zuc_cipher_snow_test_case_1_inplace), 17474 /** AUTH AES CMAC + CIPHER SNOW3G */ 17475 TEST_CASE_ST(ut_setup, ut_teardown, 17476 test_auth_aes_cmac_cipher_snow_test_case_1), 17477 TEST_CASE_ST(ut_setup, ut_teardown, 17478 test_verify_auth_aes_cmac_cipher_snow_test_case_1), 17479 TEST_CASE_ST(ut_setup, ut_teardown, 17480 test_auth_aes_cmac_cipher_snow_test_case_1_inplace), 17481 TEST_CASE_ST(ut_setup, ut_teardown, 17482 test_verify_auth_aes_cmac_cipher_snow_test_case_1_inplace), 17483 /** AUTH ZUC + CIPHER AES CTR */ 17484 TEST_CASE_ST(ut_setup, ut_teardown, 17485 test_auth_zuc_cipher_aes_ctr_test_case_1), 17486 TEST_CASE_ST(ut_setup, ut_teardown, 17487 test_verify_auth_zuc_cipher_aes_ctr_test_case_1), 17488 TEST_CASE_ST(ut_setup, ut_teardown, 17489 test_auth_zuc_cipher_aes_ctr_test_case_1_inplace), 17490 TEST_CASE_ST(ut_setup, ut_teardown, 17491 test_verify_auth_zuc_cipher_aes_ctr_test_case_1_inplace), 17492 /** AUTH SNOW3G + CIPHER AES CTR */ 17493 TEST_CASE_ST(ut_setup, ut_teardown, 17494 test_auth_snow_cipher_aes_ctr_test_case_1), 17495 TEST_CASE_ST(ut_setup, ut_teardown, 17496 test_verify_auth_snow_cipher_aes_ctr_test_case_1), 17497 TEST_CASE_ST(ut_setup, ut_teardown, 17498 test_auth_snow_cipher_aes_ctr_test_case_1_inplace), 17499 TEST_CASE_ST(ut_setup, ut_teardown, 17500 test_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl), 17501 TEST_CASE_ST(ut_setup, ut_teardown, 17502 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace), 17503 TEST_CASE_ST(ut_setup, ut_teardown, 17504 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl), 17505 /** AUTH SNOW3G + CIPHER ZUC */ 17506 TEST_CASE_ST(ut_setup, ut_teardown, 17507 test_auth_snow_cipher_zuc_test_case_1), 17508 TEST_CASE_ST(ut_setup, ut_teardown, 17509 test_verify_auth_snow_cipher_zuc_test_case_1), 17510 TEST_CASE_ST(ut_setup, ut_teardown, 17511 test_auth_snow_cipher_zuc_test_case_1_inplace), 17512 TEST_CASE_ST(ut_setup, ut_teardown, 17513 test_verify_auth_snow_cipher_zuc_test_case_1_inplace), 17514 /** AUTH AES CMAC + CIPHER ZUC */ 17515 TEST_CASE_ST(ut_setup, ut_teardown, 17516 test_auth_aes_cmac_cipher_zuc_test_case_1), 17517 TEST_CASE_ST(ut_setup, ut_teardown, 17518 test_verify_auth_aes_cmac_cipher_zuc_test_case_1), 17519 TEST_CASE_ST(ut_setup, ut_teardown, 17520 test_auth_aes_cmac_cipher_zuc_test_case_1_inplace), 17521 TEST_CASE_ST(ut_setup, ut_teardown, 17522 test_verify_auth_aes_cmac_cipher_zuc_test_case_1_inplace), 17523 17524 /** AUTH NULL + CIPHER SNOW3G */ 17525 TEST_CASE_ST(ut_setup, ut_teardown, 17526 test_auth_null_cipher_snow_test_case_1), 17527 TEST_CASE_ST(ut_setup, ut_teardown, 17528 test_verify_auth_null_cipher_snow_test_case_1), 17529 /** AUTH NULL + CIPHER ZUC */ 17530 TEST_CASE_ST(ut_setup, ut_teardown, 17531 test_auth_null_cipher_zuc_test_case_1), 17532 TEST_CASE_ST(ut_setup, ut_teardown, 17533 test_verify_auth_null_cipher_zuc_test_case_1), 17534 /** AUTH SNOW3G + CIPHER NULL */ 17535 TEST_CASE_ST(ut_setup, ut_teardown, 17536 test_auth_snow_cipher_null_test_case_1), 17537 TEST_CASE_ST(ut_setup, ut_teardown, 17538 test_verify_auth_snow_cipher_null_test_case_1), 17539 /** AUTH ZUC + CIPHER NULL */ 17540 TEST_CASE_ST(ut_setup, ut_teardown, 17541 test_auth_zuc_cipher_null_test_case_1), 17542 TEST_CASE_ST(ut_setup, ut_teardown, 17543 test_verify_auth_zuc_cipher_null_test_case_1), 17544 /** AUTH NULL + CIPHER AES CTR */ 17545 TEST_CASE_ST(ut_setup, ut_teardown, 17546 test_auth_null_cipher_aes_ctr_test_case_1), 17547 TEST_CASE_ST(ut_setup, ut_teardown, 17548 test_verify_auth_null_cipher_aes_ctr_test_case_1), 17549 /** AUTH AES CMAC + CIPHER NULL */ 17550 TEST_CASE_ST(ut_setup, ut_teardown, 17551 test_auth_aes_cmac_cipher_null_test_case_1), 17552 TEST_CASE_ST(ut_setup, ut_teardown, 17553 test_verify_auth_aes_cmac_cipher_null_test_case_1), 17554 TEST_CASES_END() 17555 } 17556 }; 17557 17558 static int 17559 run_cryptodev_testsuite(const char *pmd_name) 17560 { 17561 uint8_t ret, j, i = 0, blk_start_idx = 0; 17562 const enum blockcipher_test_type blk_suites[] = { 17563 BLKCIPHER_AES_CHAIN_TYPE, 17564 BLKCIPHER_AES_CIPHERONLY_TYPE, 17565 BLKCIPHER_AES_DOCSIS_TYPE, 17566 BLKCIPHER_3DES_CHAIN_TYPE, 17567 BLKCIPHER_3DES_CIPHERONLY_TYPE, 17568 BLKCIPHER_DES_CIPHERONLY_TYPE, 17569 BLKCIPHER_DES_DOCSIS_TYPE, 17570 BLKCIPHER_SM4_CHAIN_TYPE, 17571 BLKCIPHER_SM4_CIPHERONLY_TYPE, 17572 BLKCIPHER_AUTHONLY_TYPE}; 17573 struct unit_test_suite *static_suites[] = { 17574 &cryptodev_multi_session_testsuite, 17575 &cryptodev_null_testsuite, 17576 &cryptodev_aes_ccm_auth_testsuite, 17577 &cryptodev_aes_gcm_auth_testsuite, 17578 &cryptodev_aes_gmac_auth_testsuite, 17579 &cryptodev_snow3g_testsuite, 17580 &cryptodev_chacha20_poly1305_testsuite, 17581 &cryptodev_zuc_testsuite, 17582 &cryptodev_hmac_md5_auth_testsuite, 17583 &cryptodev_kasumi_testsuite, 17584 &cryptodev_esn_testsuite, 17585 &cryptodev_negative_aes_gcm_testsuite, 17586 &cryptodev_negative_aes_gmac_testsuite, 17587 &cryptodev_mixed_cipher_hash_testsuite, 17588 &cryptodev_negative_hmac_sha1_testsuite, 17589 &cryptodev_gen_testsuite, 17590 #ifdef RTE_LIB_SECURITY 17591 &ipsec_proto_testsuite, 17592 &pdcp_proto_testsuite, 17593 &docsis_proto_testsuite, 17594 #endif 17595 &end_testsuite 17596 }; 17597 static struct unit_test_suite ts = { 17598 .suite_name = "Cryptodev Unit Test Suite", 17599 .setup = testsuite_setup, 17600 .teardown = testsuite_teardown, 17601 .unit_test_cases = {TEST_CASES_END()} 17602 }; 17603 17604 gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name); 17605 17606 if (gbl_driver_id == -1) { 17607 RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name); 17608 return TEST_SKIPPED; 17609 } 17610 17611 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 17612 (RTE_DIM(blk_suites) + RTE_DIM(static_suites))); 17613 17614 ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites)); 17615 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 17616 ret = unit_test_suite_runner(&ts); 17617 17618 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites)); 17619 free(ts.unit_test_suites); 17620 return ret; 17621 } 17622 17623 static int 17624 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name) 17625 { 17626 struct rte_cryptodev_info dev_info; 17627 uint8_t i, nb_devs; 17628 int driver_id; 17629 17630 driver_id = rte_cryptodev_driver_id_get(pmd_name); 17631 if (driver_id == -1) { 17632 RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name); 17633 return TEST_SKIPPED; 17634 } 17635 17636 nb_devs = rte_cryptodev_count(); 17637 if (nb_devs < 1) { 17638 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 17639 return TEST_SKIPPED; 17640 } 17641 17642 for (i = 0; i < nb_devs; i++) { 17643 rte_cryptodev_info_get(i, &dev_info); 17644 if (dev_info.driver_id == driver_id) { 17645 if (!(dev_info.feature_flags & flag)) { 17646 RTE_LOG(INFO, USER1, "%s not supported\n", 17647 flag_name); 17648 return TEST_SKIPPED; 17649 } 17650 return 0; /* found */ 17651 } 17652 } 17653 17654 RTE_LOG(INFO, USER1, "%s not supported\n", flag_name); 17655 return TEST_SKIPPED; 17656 } 17657 17658 static int 17659 test_cryptodev_qat(void) 17660 { 17661 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 17662 } 17663 17664 static int 17665 test_cryptodev_uadk(void) 17666 { 17667 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_UADK_PMD)); 17668 } 17669 17670 static int 17671 test_cryptodev_virtio(void) 17672 { 17673 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)); 17674 } 17675 17676 static int 17677 test_cryptodev_aesni_mb(void) 17678 { 17679 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 17680 } 17681 17682 static int 17683 test_cryptodev_cpu_aesni_mb(void) 17684 { 17685 int32_t rc; 17686 enum rte_security_session_action_type at = gbl_action_type; 17687 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 17688 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 17689 gbl_action_type = at; 17690 return rc; 17691 } 17692 17693 static int 17694 test_cryptodev_chacha_poly_mb(void) 17695 { 17696 int32_t rc; 17697 enum rte_security_session_action_type at = gbl_action_type; 17698 rc = run_cryptodev_testsuite( 17699 RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD)); 17700 gbl_action_type = at; 17701 return rc; 17702 } 17703 17704 static int 17705 test_cryptodev_openssl(void) 17706 { 17707 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 17708 } 17709 17710 static int 17711 test_cryptodev_aesni_gcm(void) 17712 { 17713 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 17714 } 17715 17716 static int 17717 test_cryptodev_cpu_aesni_gcm(void) 17718 { 17719 int32_t rc; 17720 enum rte_security_session_action_type at = gbl_action_type; 17721 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 17722 rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 17723 gbl_action_type = at; 17724 return rc; 17725 } 17726 17727 static int 17728 test_cryptodev_mlx5(void) 17729 { 17730 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD)); 17731 } 17732 17733 static int 17734 test_cryptodev_null(void) 17735 { 17736 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 17737 } 17738 17739 static int 17740 test_cryptodev_sw_snow3g(void) 17741 { 17742 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 17743 } 17744 17745 static int 17746 test_cryptodev_sw_kasumi(void) 17747 { 17748 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 17749 } 17750 17751 static int 17752 test_cryptodev_sw_zuc(void) 17753 { 17754 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 17755 } 17756 17757 static int 17758 test_cryptodev_armv8(void) 17759 { 17760 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 17761 } 17762 17763 static int 17764 test_cryptodev_mrvl(void) 17765 { 17766 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 17767 } 17768 17769 #ifdef RTE_CRYPTO_SCHEDULER 17770 17771 static int 17772 test_cryptodev_scheduler(void) 17773 { 17774 uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0; 17775 const enum blockcipher_test_type blk_suites[] = { 17776 BLKCIPHER_AES_CHAIN_TYPE, 17777 BLKCIPHER_AES_CIPHERONLY_TYPE, 17778 BLKCIPHER_AUTHONLY_TYPE 17779 }; 17780 static struct unit_test_suite scheduler_multicore = { 17781 .suite_name = "Scheduler Multicore Unit Test Suite", 17782 .setup = scheduler_multicore_testsuite_setup, 17783 .teardown = scheduler_mode_testsuite_teardown, 17784 .unit_test_cases = {TEST_CASES_END()} 17785 }; 17786 static struct unit_test_suite scheduler_round_robin = { 17787 .suite_name = "Scheduler Round Robin Unit Test Suite", 17788 .setup = scheduler_roundrobin_testsuite_setup, 17789 .teardown = scheduler_mode_testsuite_teardown, 17790 .unit_test_cases = {TEST_CASES_END()} 17791 }; 17792 static struct unit_test_suite scheduler_failover = { 17793 .suite_name = "Scheduler Failover Unit Test Suite", 17794 .setup = scheduler_failover_testsuite_setup, 17795 .teardown = scheduler_mode_testsuite_teardown, 17796 .unit_test_cases = {TEST_CASES_END()} 17797 }; 17798 static struct unit_test_suite scheduler_pkt_size_distr = { 17799 .suite_name = "Scheduler Pkt Size Distr Unit Test Suite", 17800 .setup = scheduler_pkt_size_distr_testsuite_setup, 17801 .teardown = scheduler_mode_testsuite_teardown, 17802 .unit_test_cases = {TEST_CASES_END()} 17803 }; 17804 struct unit_test_suite *sched_mode_suites[] = { 17805 &scheduler_multicore, 17806 &scheduler_round_robin, 17807 &scheduler_failover, 17808 &scheduler_pkt_size_distr 17809 }; 17810 static struct unit_test_suite scheduler_config = { 17811 .suite_name = "Crypto Device Scheduler Config Unit Test Suite", 17812 .unit_test_cases = { 17813 TEST_CASE(test_scheduler_attach_worker_op), 17814 TEST_CASE(test_scheduler_mode_multicore_op), 17815 TEST_CASE(test_scheduler_mode_roundrobin_op), 17816 TEST_CASE(test_scheduler_mode_failover_op), 17817 TEST_CASE(test_scheduler_mode_pkt_size_distr_op), 17818 TEST_CASE(test_scheduler_detach_worker_op), 17819 17820 TEST_CASES_END() /**< NULL terminate array */ 17821 } 17822 }; 17823 struct unit_test_suite *static_suites[] = { 17824 &scheduler_config, 17825 &end_testsuite 17826 }; 17827 struct unit_test_suite *sched_mode_static_suites[] = { 17828 #ifdef RTE_LIB_SECURITY 17829 &docsis_proto_testsuite, 17830 #endif 17831 &end_testsuite 17832 }; 17833 static struct unit_test_suite ts = { 17834 .suite_name = "Scheduler Unit Test Suite", 17835 .setup = scheduler_testsuite_setup, 17836 .teardown = testsuite_teardown, 17837 .unit_test_cases = {TEST_CASES_END()} 17838 }; 17839 17840 gbl_driver_id = rte_cryptodev_driver_id_get( 17841 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 17842 17843 if (gbl_driver_id == -1) { 17844 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n"); 17845 return TEST_SKIPPED; 17846 } 17847 17848 if (rte_cryptodev_driver_id_get( 17849 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) { 17850 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 17851 return TEST_SKIPPED; 17852 } 17853 17854 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 17855 uint8_t blk_i = 0; 17856 sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof 17857 (struct unit_test_suite *) * 17858 (RTE_DIM(blk_suites) + 17859 RTE_DIM(sched_mode_static_suites) + 1)); 17860 ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]), 17861 blk_suites, RTE_DIM(blk_suites)); 17862 ADD_STATIC_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]), 17863 sched_mode_static_suites, 17864 RTE_DIM(sched_mode_static_suites)); 17865 sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite; 17866 } 17867 17868 ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * 17869 (RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites))); 17870 ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites, 17871 RTE_DIM(sched_mode_suites)); 17872 ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites)); 17873 ret = unit_test_suite_runner(&ts); 17874 17875 for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) { 17876 FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, 17877 (*sched_mode_suites[sched_i]), 17878 RTE_DIM(blk_suites)); 17879 free(sched_mode_suites[sched_i]->unit_test_suites); 17880 } 17881 free(ts.unit_test_suites); 17882 return ret; 17883 } 17884 17885 REGISTER_DRIVER_TEST(cryptodev_scheduler_autotest, test_cryptodev_scheduler); 17886 17887 #endif 17888 17889 static int 17890 test_cryptodev_dpaa2_sec(void) 17891 { 17892 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 17893 } 17894 17895 static int 17896 test_cryptodev_dpaa_sec(void) 17897 { 17898 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 17899 } 17900 17901 static int 17902 test_cryptodev_ccp(void) 17903 { 17904 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 17905 } 17906 17907 static int 17908 test_cryptodev_octeontx(void) 17909 { 17910 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)); 17911 } 17912 17913 static int 17914 test_cryptodev_caam_jr(void) 17915 { 17916 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)); 17917 } 17918 17919 static int 17920 test_cryptodev_nitrox(void) 17921 { 17922 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD)); 17923 } 17924 17925 static int 17926 test_cryptodev_bcmfs(void) 17927 { 17928 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD)); 17929 } 17930 17931 static int 17932 run_cryptodev_raw_testsuite(const char *pmd_name) 17933 { 17934 int ret; 17935 17936 ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, "RAW API"); 17937 if (ret) 17938 return ret; 17939 17940 global_api_test_type = CRYPTODEV_RAW_API_TEST; 17941 ret = run_cryptodev_testsuite(pmd_name); 17942 global_api_test_type = CRYPTODEV_API_TEST; 17943 17944 return ret; 17945 } 17946 17947 static int 17948 test_cryptodev_qat_raw_api(void) 17949 { 17950 return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 17951 } 17952 17953 static int 17954 test_cryptodev_cn9k(void) 17955 { 17956 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD)); 17957 } 17958 17959 static int 17960 test_cryptodev_cn10k(void) 17961 { 17962 return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD)); 17963 } 17964 17965 static int 17966 test_cryptodev_cn10k_raw_api(void) 17967 { 17968 return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD)); 17969 } 17970 17971 static int 17972 test_cryptodev_dpaa2_sec_raw_api(void) 17973 { 17974 return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 17975 } 17976 17977 static int 17978 test_cryptodev_dpaa_sec_raw_api(void) 17979 { 17980 return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 17981 } 17982 17983 REGISTER_DRIVER_TEST(cryptodev_cn10k_raw_api_autotest, 17984 test_cryptodev_cn10k_raw_api); 17985 REGISTER_DRIVER_TEST(cryptodev_dpaa2_sec_raw_api_autotest, 17986 test_cryptodev_dpaa2_sec_raw_api); 17987 REGISTER_DRIVER_TEST(cryptodev_dpaa_sec_raw_api_autotest, 17988 test_cryptodev_dpaa_sec_raw_api); 17989 REGISTER_DRIVER_TEST(cryptodev_qat_raw_api_autotest, 17990 test_cryptodev_qat_raw_api); 17991 REGISTER_DRIVER_TEST(cryptodev_qat_autotest, test_cryptodev_qat); 17992 REGISTER_DRIVER_TEST(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 17993 REGISTER_DRIVER_TEST(cryptodev_cpu_aesni_mb_autotest, 17994 test_cryptodev_cpu_aesni_mb); 17995 REGISTER_DRIVER_TEST(cryptodev_chacha_poly_mb_autotest, 17996 test_cryptodev_chacha_poly_mb); 17997 REGISTER_DRIVER_TEST(cryptodev_openssl_autotest, test_cryptodev_openssl); 17998 REGISTER_DRIVER_TEST(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 17999 REGISTER_DRIVER_TEST(cryptodev_cpu_aesni_gcm_autotest, 18000 test_cryptodev_cpu_aesni_gcm); 18001 REGISTER_DRIVER_TEST(cryptodev_mlx5_autotest, test_cryptodev_mlx5); 18002 REGISTER_DRIVER_TEST(cryptodev_null_autotest, test_cryptodev_null); 18003 REGISTER_DRIVER_TEST(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 18004 REGISTER_DRIVER_TEST(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 18005 REGISTER_DRIVER_TEST(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 18006 REGISTER_DRIVER_TEST(cryptodev_sw_armv8_autotest, test_cryptodev_armv8); 18007 REGISTER_DRIVER_TEST(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl); 18008 REGISTER_DRIVER_TEST(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec); 18009 REGISTER_DRIVER_TEST(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec); 18010 REGISTER_DRIVER_TEST(cryptodev_ccp_autotest, test_cryptodev_ccp); 18011 REGISTER_DRIVER_TEST(cryptodev_uadk_autotest, test_cryptodev_uadk); 18012 REGISTER_DRIVER_TEST(cryptodev_virtio_autotest, test_cryptodev_virtio); 18013 REGISTER_DRIVER_TEST(cryptodev_octeontx_autotest, test_cryptodev_octeontx); 18014 REGISTER_DRIVER_TEST(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr); 18015 REGISTER_DRIVER_TEST(cryptodev_nitrox_autotest, test_cryptodev_nitrox); 18016 REGISTER_DRIVER_TEST(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs); 18017 REGISTER_DRIVER_TEST(cryptodev_cn9k_autotest, test_cryptodev_cn9k); 18018 REGISTER_DRIVER_TEST(cryptodev_cn10k_autotest, test_cryptodev_cn10k); 18019