1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2015-2020 Intel Corporation 3 * Copyright 2020 NXP 4 */ 5 6 #include <time.h> 7 8 #include <rte_common.h> 9 #include <rte_hexdump.h> 10 #include <rte_mbuf.h> 11 #include <rte_malloc.h> 12 #include <rte_memcpy.h> 13 #include <rte_pause.h> 14 #include <rte_bus_vdev.h> 15 #include <rte_ether.h> 16 17 #include <rte_crypto.h> 18 #include <rte_cryptodev.h> 19 #include <rte_cryptodev_pmd.h> 20 #include <rte_string_fns.h> 21 22 #ifdef RTE_CRYPTO_SCHEDULER 23 #include <rte_cryptodev_scheduler.h> 24 #include <rte_cryptodev_scheduler_operations.h> 25 #endif 26 27 #include <rte_lcore.h> 28 29 #include "test.h" 30 #include "test_cryptodev.h" 31 32 #include "test_cryptodev_blockcipher.h" 33 #include "test_cryptodev_aes_test_vectors.h" 34 #include "test_cryptodev_des_test_vectors.h" 35 #include "test_cryptodev_hash_test_vectors.h" 36 #include "test_cryptodev_kasumi_test_vectors.h" 37 #include "test_cryptodev_kasumi_hash_test_vectors.h" 38 #include "test_cryptodev_snow3g_test_vectors.h" 39 #include "test_cryptodev_snow3g_hash_test_vectors.h" 40 #include "test_cryptodev_zuc_test_vectors.h" 41 #include "test_cryptodev_aead_test_vectors.h" 42 #include "test_cryptodev_hmac_test_vectors.h" 43 #include "test_cryptodev_mixed_test_vectors.h" 44 #ifdef RTE_LIB_SECURITY 45 #include "test_cryptodev_security_pdcp_test_vectors.h" 46 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h" 47 #include "test_cryptodev_security_pdcp_test_func.h" 48 #include "test_cryptodev_security_docsis_test_vectors.h" 49 50 #define SDAP_DISABLED 0 51 #define SDAP_ENABLED 1 52 #endif 53 54 #define VDEV_ARGS_SIZE 100 55 #define MAX_NB_SESSIONS 4 56 57 #define MAX_DRV_SERVICE_CTX_SIZE 256 58 59 #define MAX_RAW_DEQUEUE_COUNT 65535 60 61 #define IN_PLACE 0 62 #define OUT_OF_PLACE 1 63 64 #ifndef ARRAY_SIZE 65 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 66 #endif 67 68 static int gbl_driver_id; 69 70 static enum rte_security_session_action_type gbl_action_type = 71 RTE_SECURITY_ACTION_TYPE_NONE; 72 73 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST; 74 75 struct crypto_testsuite_params { 76 struct rte_mempool *mbuf_pool; 77 struct rte_mempool *large_mbuf_pool; 78 struct rte_mempool *op_mpool; 79 struct rte_mempool *session_mpool; 80 struct rte_mempool *session_priv_mpool; 81 struct rte_cryptodev_config conf; 82 struct rte_cryptodev_qp_conf qp_conf; 83 84 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS]; 85 uint8_t valid_dev_count; 86 }; 87 88 struct crypto_unittest_params { 89 struct rte_crypto_sym_xform cipher_xform; 90 struct rte_crypto_sym_xform auth_xform; 91 struct rte_crypto_sym_xform aead_xform; 92 #ifdef RTE_LIB_SECURITY 93 struct rte_security_docsis_xform docsis_xform; 94 #endif 95 96 union { 97 struct rte_cryptodev_sym_session *sess; 98 #ifdef RTE_LIB_SECURITY 99 struct rte_security_session *sec_session; 100 #endif 101 }; 102 #ifdef RTE_LIB_SECURITY 103 enum rte_security_session_action_type type; 104 #endif 105 struct rte_crypto_op *op; 106 107 struct rte_mbuf *obuf, *ibuf; 108 109 uint8_t *digest; 110 }; 111 112 #define ALIGN_POW2_ROUNDUP(num, align) \ 113 (((num) + (align) - 1) & ~((align) - 1)) 114 115 /* 116 * Forward declarations. 117 */ 118 static int 119 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 120 struct crypto_unittest_params *ut_params, uint8_t *cipher_key, 121 uint8_t *hmac_key); 122 123 static int 124 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 125 struct crypto_unittest_params *ut_params, 126 struct crypto_testsuite_params *ts_param, 127 const uint8_t *cipher, 128 const uint8_t *digest, 129 const uint8_t *iv); 130 131 static struct rte_mbuf * 132 setup_test_string(struct rte_mempool *mpool, 133 const char *string, size_t len, uint8_t blocksize) 134 { 135 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool); 136 size_t t_len = len - (blocksize ? (len % blocksize) : 0); 137 138 memset(m->buf_addr, 0, m->buf_len); 139 if (m) { 140 char *dst = rte_pktmbuf_append(m, t_len); 141 142 if (!dst) { 143 rte_pktmbuf_free(m); 144 return NULL; 145 } 146 if (string != NULL) 147 rte_memcpy(dst, string, t_len); 148 else 149 memset(dst, 0, t_len); 150 } 151 152 return m; 153 } 154 155 /* Get number of bytes in X bits (rounding up) */ 156 static uint32_t 157 ceil_byte_length(uint32_t num_bits) 158 { 159 if (num_bits % 8) 160 return ((num_bits >> 3) + 1); 161 else 162 return (num_bits >> 3); 163 } 164 165 static uint32_t 166 get_raw_dp_dequeue_count(void *user_data __rte_unused) 167 { 168 return 1; 169 } 170 171 static void 172 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused, 173 uint8_t is_op_success) 174 { 175 struct rte_crypto_op *op = user_data; 176 op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS : 177 RTE_CRYPTO_OP_STATUS_ERROR; 178 } 179 180 void 181 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id, 182 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth, 183 uint8_t len_in_bits, uint8_t cipher_iv_len) 184 { 185 struct rte_crypto_sym_op *sop = op->sym; 186 struct rte_crypto_op *ret_op = NULL; 187 struct rte_crypto_vec data_vec[UINT8_MAX]; 188 struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv; 189 union rte_crypto_sym_ofs ofs; 190 struct rte_crypto_sym_vec vec; 191 struct rte_crypto_sgl sgl; 192 uint32_t max_len; 193 union rte_cryptodev_session_ctx sess; 194 uint32_t count = 0; 195 struct rte_crypto_raw_dp_ctx *ctx; 196 uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0, 197 auth_len = 0; 198 int32_t n; 199 uint32_t n_success; 200 int ctx_service_size; 201 int32_t status = 0; 202 int enqueue_status, dequeue_status; 203 204 ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id); 205 if (ctx_service_size < 0) { 206 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 207 return; 208 } 209 210 ctx = malloc(ctx_service_size); 211 if (!ctx) { 212 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 213 return; 214 } 215 216 /* Both are enums, setting crypto_sess will suit any session type */ 217 sess.crypto_sess = op->sym->session; 218 219 if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx, 220 op->sess_type, sess, 0) < 0) { 221 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 222 goto exit; 223 } 224 225 cipher_iv.iova = 0; 226 cipher_iv.va = NULL; 227 aad_auth_iv.iova = 0; 228 aad_auth_iv.va = NULL; 229 digest.iova = 0; 230 digest.va = NULL; 231 sgl.vec = data_vec; 232 vec.num = 1; 233 vec.sgl = &sgl; 234 vec.iv = &cipher_iv; 235 vec.digest = &digest; 236 vec.aad = &aad_auth_iv; 237 vec.status = &status; 238 239 ofs.raw = 0; 240 241 if (is_cipher && is_auth) { 242 cipher_offset = sop->cipher.data.offset; 243 cipher_len = sop->cipher.data.length; 244 auth_offset = sop->auth.data.offset; 245 auth_len = sop->auth.data.length; 246 max_len = RTE_MAX(cipher_offset + cipher_len, 247 auth_offset + auth_len); 248 if (len_in_bits) { 249 max_len = max_len >> 3; 250 cipher_offset = cipher_offset >> 3; 251 auth_offset = auth_offset >> 3; 252 cipher_len = cipher_len >> 3; 253 auth_len = auth_len >> 3; 254 } 255 ofs.ofs.cipher.head = cipher_offset; 256 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 257 ofs.ofs.auth.head = auth_offset; 258 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 259 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 260 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 261 aad_auth_iv.va = rte_crypto_op_ctod_offset( 262 op, void *, IV_OFFSET + cipher_iv_len); 263 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 264 cipher_iv_len); 265 digest.va = (void *)sop->auth.digest.data; 266 digest.iova = sop->auth.digest.phys_addr; 267 268 } else if (is_cipher) { 269 cipher_offset = sop->cipher.data.offset; 270 cipher_len = sop->cipher.data.length; 271 max_len = cipher_len + cipher_offset; 272 if (len_in_bits) { 273 max_len = max_len >> 3; 274 cipher_offset = cipher_offset >> 3; 275 cipher_len = cipher_len >> 3; 276 } 277 ofs.ofs.cipher.head = cipher_offset; 278 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 279 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 280 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 281 282 } else if (is_auth) { 283 auth_offset = sop->auth.data.offset; 284 auth_len = sop->auth.data.length; 285 max_len = auth_len + auth_offset; 286 if (len_in_bits) { 287 max_len = max_len >> 3; 288 auth_offset = auth_offset >> 3; 289 auth_len = auth_len >> 3; 290 } 291 ofs.ofs.auth.head = auth_offset; 292 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 293 aad_auth_iv.va = rte_crypto_op_ctod_offset( 294 op, void *, IV_OFFSET + cipher_iv_len); 295 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 296 cipher_iv_len); 297 digest.va = (void *)sop->auth.digest.data; 298 digest.iova = sop->auth.digest.phys_addr; 299 300 } else { /* aead */ 301 cipher_offset = sop->aead.data.offset; 302 cipher_len = sop->aead.data.length; 303 max_len = cipher_len + cipher_offset; 304 if (len_in_bits) { 305 max_len = max_len >> 3; 306 cipher_offset = cipher_offset >> 3; 307 cipher_len = cipher_len >> 3; 308 } 309 ofs.ofs.cipher.head = cipher_offset; 310 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 311 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 312 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 313 aad_auth_iv.va = (void *)sop->aead.aad.data; 314 aad_auth_iv.iova = sop->aead.aad.phys_addr; 315 digest.va = (void *)sop->aead.digest.data; 316 digest.iova = sop->aead.digest.phys_addr; 317 } 318 319 n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len, 320 data_vec, RTE_DIM(data_vec)); 321 if (n < 0 || n > sop->m_src->nb_segs) { 322 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 323 goto exit; 324 } 325 326 sgl.num = n; 327 328 if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op, 329 &enqueue_status) < 1) { 330 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 331 goto exit; 332 } 333 334 if (enqueue_status == 0) { 335 status = rte_cryptodev_raw_enqueue_done(ctx, 1); 336 if (status < 0) { 337 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 338 goto exit; 339 } 340 } else if (enqueue_status < 0) { 341 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 342 goto exit; 343 } 344 345 n = n_success = 0; 346 while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) { 347 n = rte_cryptodev_raw_dequeue_burst(ctx, 348 get_raw_dp_dequeue_count, post_process_raw_dp_op, 349 (void **)&ret_op, 0, &n_success, 350 &dequeue_status); 351 if (dequeue_status < 0) { 352 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 353 goto exit; 354 } 355 if (n == 0) 356 rte_pause(); 357 } 358 359 if (n == 1 && dequeue_status == 0) { 360 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) { 361 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 362 goto exit; 363 } 364 } 365 366 op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op || 367 n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR : 368 RTE_CRYPTO_OP_STATUS_SUCCESS; 369 370 exit: 371 free(ctx); 372 } 373 374 static void 375 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op) 376 { 377 int32_t n, st; 378 struct rte_crypto_sym_op *sop; 379 union rte_crypto_sym_ofs ofs; 380 struct rte_crypto_sgl sgl; 381 struct rte_crypto_sym_vec symvec; 382 struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr; 383 struct rte_crypto_vec vec[UINT8_MAX]; 384 385 sop = op->sym; 386 387 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset, 388 sop->aead.data.length, vec, RTE_DIM(vec)); 389 390 if (n < 0 || n != sop->m_src->nb_segs) { 391 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 392 return; 393 } 394 395 sgl.vec = vec; 396 sgl.num = n; 397 symvec.sgl = &sgl; 398 symvec.iv = &iv_ptr; 399 symvec.digest = &digest_ptr; 400 symvec.aad = &aad_ptr; 401 symvec.status = &st; 402 symvec.num = 1; 403 404 /* for CPU crypto the IOVA address is not required */ 405 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 406 digest_ptr.va = (void *)sop->aead.digest.data; 407 aad_ptr.va = (void *)sop->aead.aad.data; 408 409 ofs.raw = 0; 410 411 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 412 &symvec); 413 414 if (n != 1) 415 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 416 else 417 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 418 } 419 420 static void 421 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op) 422 { 423 int32_t n, st; 424 struct rte_crypto_sym_op *sop; 425 union rte_crypto_sym_ofs ofs; 426 struct rte_crypto_sgl sgl; 427 struct rte_crypto_sym_vec symvec; 428 struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr; 429 struct rte_crypto_vec vec[UINT8_MAX]; 430 431 sop = op->sym; 432 433 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset, 434 sop->auth.data.length, vec, RTE_DIM(vec)); 435 436 if (n < 0 || n != sop->m_src->nb_segs) { 437 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 438 return; 439 } 440 441 sgl.vec = vec; 442 sgl.num = n; 443 symvec.sgl = &sgl; 444 symvec.iv = &iv_ptr; 445 symvec.digest = &digest_ptr; 446 symvec.status = &st; 447 symvec.num = 1; 448 449 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 450 digest_ptr.va = (void *)sop->auth.digest.data; 451 452 ofs.raw = 0; 453 ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset; 454 ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) - 455 (sop->cipher.data.offset + sop->cipher.data.length); 456 457 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 458 &symvec); 459 460 if (n != 1) 461 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 462 else 463 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 464 } 465 466 static struct rte_crypto_op * 467 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op) 468 { 469 470 RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO); 471 472 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 473 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n"); 474 return NULL; 475 } 476 477 op = NULL; 478 479 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 480 rte_pause(); 481 482 if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 483 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status); 484 return NULL; 485 } 486 487 return op; 488 } 489 490 static struct crypto_testsuite_params testsuite_params = { NULL }; 491 static struct crypto_unittest_params unittest_params; 492 493 static int 494 testsuite_setup(void) 495 { 496 struct crypto_testsuite_params *ts_params = &testsuite_params; 497 struct rte_cryptodev_info info; 498 uint32_t i = 0, nb_devs, dev_id; 499 int ret; 500 uint16_t qp_id; 501 502 memset(ts_params, 0, sizeof(*ts_params)); 503 504 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 505 if (ts_params->mbuf_pool == NULL) { 506 /* Not already created so create */ 507 ts_params->mbuf_pool = rte_pktmbuf_pool_create( 508 "CRYPTO_MBUFPOOL", 509 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE, 510 rte_socket_id()); 511 if (ts_params->mbuf_pool == NULL) { 512 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n"); 513 return TEST_FAILED; 514 } 515 } 516 517 ts_params->large_mbuf_pool = rte_mempool_lookup( 518 "CRYPTO_LARGE_MBUFPOOL"); 519 if (ts_params->large_mbuf_pool == NULL) { 520 /* Not already created so create */ 521 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create( 522 "CRYPTO_LARGE_MBUFPOOL", 523 1, 0, 0, UINT16_MAX, 524 rte_socket_id()); 525 if (ts_params->large_mbuf_pool == NULL) { 526 RTE_LOG(ERR, USER1, 527 "Can't create CRYPTO_LARGE_MBUFPOOL\n"); 528 return TEST_FAILED; 529 } 530 } 531 532 ts_params->op_mpool = rte_crypto_op_pool_create( 533 "MBUF_CRYPTO_SYM_OP_POOL", 534 RTE_CRYPTO_OP_TYPE_SYMMETRIC, 535 NUM_MBUFS, MBUF_CACHE_SIZE, 536 DEFAULT_NUM_XFORMS * 537 sizeof(struct rte_crypto_sym_xform) + 538 MAXIMUM_IV_LENGTH, 539 rte_socket_id()); 540 if (ts_params->op_mpool == NULL) { 541 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n"); 542 return TEST_FAILED; 543 } 544 545 /* Create an AESNI MB device if required */ 546 if (gbl_driver_id == rte_cryptodev_driver_id_get( 547 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) { 548 nb_devs = rte_cryptodev_device_count_by_driver( 549 rte_cryptodev_driver_id_get( 550 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))); 551 if (nb_devs < 1) { 552 ret = rte_vdev_init( 553 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL); 554 555 TEST_ASSERT(ret == 0, 556 "Failed to create instance of" 557 " pmd : %s", 558 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 559 } 560 } 561 562 /* Create an AESNI GCM device if required */ 563 if (gbl_driver_id == rte_cryptodev_driver_id_get( 564 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))) { 565 nb_devs = rte_cryptodev_device_count_by_driver( 566 rte_cryptodev_driver_id_get( 567 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))); 568 if (nb_devs < 1) { 569 TEST_ASSERT_SUCCESS(rte_vdev_init( 570 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL), 571 "Failed to create instance of" 572 " pmd : %s", 573 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 574 } 575 } 576 577 /* Create a SNOW 3G device if required */ 578 if (gbl_driver_id == rte_cryptodev_driver_id_get( 579 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD))) { 580 nb_devs = rte_cryptodev_device_count_by_driver( 581 rte_cryptodev_driver_id_get( 582 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD))); 583 if (nb_devs < 1) { 584 TEST_ASSERT_SUCCESS(rte_vdev_init( 585 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL), 586 "Failed to create instance of" 587 " pmd : %s", 588 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 589 } 590 } 591 592 /* Create a KASUMI device if required */ 593 if (gbl_driver_id == rte_cryptodev_driver_id_get( 594 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD))) { 595 nb_devs = rte_cryptodev_device_count_by_driver( 596 rte_cryptodev_driver_id_get( 597 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD))); 598 if (nb_devs < 1) { 599 TEST_ASSERT_SUCCESS(rte_vdev_init( 600 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL), 601 "Failed to create instance of" 602 " pmd : %s", 603 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 604 } 605 } 606 607 /* Create a ZUC device if required */ 608 if (gbl_driver_id == rte_cryptodev_driver_id_get( 609 RTE_STR(CRYPTODEV_NAME_ZUC_PMD))) { 610 nb_devs = rte_cryptodev_device_count_by_driver( 611 rte_cryptodev_driver_id_get( 612 RTE_STR(CRYPTODEV_NAME_ZUC_PMD))); 613 if (nb_devs < 1) { 614 TEST_ASSERT_SUCCESS(rte_vdev_init( 615 RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL), 616 "Failed to create instance of" 617 " pmd : %s", 618 RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 619 } 620 } 621 622 /* Create a NULL device if required */ 623 if (gbl_driver_id == rte_cryptodev_driver_id_get( 624 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) { 625 nb_devs = rte_cryptodev_device_count_by_driver( 626 rte_cryptodev_driver_id_get( 627 RTE_STR(CRYPTODEV_NAME_NULL_PMD))); 628 if (nb_devs < 1) { 629 ret = rte_vdev_init( 630 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL); 631 632 TEST_ASSERT(ret == 0, 633 "Failed to create instance of" 634 " pmd : %s", 635 RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 636 } 637 } 638 639 /* Create an OPENSSL device if required */ 640 if (gbl_driver_id == rte_cryptodev_driver_id_get( 641 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) { 642 nb_devs = rte_cryptodev_device_count_by_driver( 643 rte_cryptodev_driver_id_get( 644 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))); 645 if (nb_devs < 1) { 646 ret = rte_vdev_init( 647 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD), 648 NULL); 649 650 TEST_ASSERT(ret == 0, "Failed to create " 651 "instance of pmd : %s", 652 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 653 } 654 } 655 656 /* Create a ARMv8 device if required */ 657 if (gbl_driver_id == rte_cryptodev_driver_id_get( 658 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD))) { 659 nb_devs = rte_cryptodev_device_count_by_driver( 660 rte_cryptodev_driver_id_get( 661 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD))); 662 if (nb_devs < 1) { 663 ret = rte_vdev_init( 664 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD), 665 NULL); 666 667 TEST_ASSERT(ret == 0, "Failed to create " 668 "instance of pmd : %s", 669 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 670 } 671 } 672 673 /* Create a MVSAM device if required */ 674 if (gbl_driver_id == rte_cryptodev_driver_id_get( 675 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD))) { 676 nb_devs = rte_cryptodev_device_count_by_driver( 677 rte_cryptodev_driver_id_get( 678 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD))); 679 if (nb_devs < 1) { 680 ret = rte_vdev_init( 681 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD), 682 NULL); 683 684 TEST_ASSERT(ret == 0, "Failed to create " 685 "instance of pmd : %s", 686 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 687 } 688 } 689 690 /* Create an CCP device if required */ 691 if (gbl_driver_id == rte_cryptodev_driver_id_get( 692 RTE_STR(CRYPTODEV_NAME_CCP_PMD))) { 693 nb_devs = rte_cryptodev_device_count_by_driver( 694 rte_cryptodev_driver_id_get( 695 RTE_STR(CRYPTODEV_NAME_CCP_PMD))); 696 if (nb_devs < 1) { 697 ret = rte_vdev_init( 698 RTE_STR(CRYPTODEV_NAME_CCP_PMD), 699 NULL); 700 701 TEST_ASSERT(ret == 0, "Failed to create " 702 "instance of pmd : %s", 703 RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 704 } 705 } 706 707 #ifdef RTE_CRYPTO_SCHEDULER 708 char vdev_args[VDEV_ARGS_SIZE] = {""}; 709 char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core," 710 "ordering=enable,name=cryptodev_test_scheduler,corelist="}; 711 uint16_t worker_core_count = 0; 712 uint16_t socket_id = 0; 713 714 if (gbl_driver_id == rte_cryptodev_driver_id_get( 715 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) { 716 717 /* Identify the Worker Cores 718 * Use 2 worker cores for the device args 719 */ 720 RTE_LCORE_FOREACH_WORKER(i) { 721 if (worker_core_count > 1) 722 break; 723 snprintf(vdev_args, sizeof(vdev_args), 724 "%s%d", temp_str, i); 725 strcpy(temp_str, vdev_args); 726 strlcat(temp_str, ";", sizeof(temp_str)); 727 worker_core_count++; 728 socket_id = rte_lcore_to_socket_id(i); 729 } 730 if (worker_core_count != 2) { 731 RTE_LOG(ERR, USER1, 732 "Cryptodev scheduler test require at least " 733 "two worker cores to run. " 734 "Please use the correct coremask.\n"); 735 return TEST_FAILED; 736 } 737 strcpy(temp_str, vdev_args); 738 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", 739 temp_str, socket_id); 740 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args); 741 nb_devs = rte_cryptodev_device_count_by_driver( 742 rte_cryptodev_driver_id_get( 743 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))); 744 if (nb_devs < 1) { 745 ret = rte_vdev_init( 746 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD), 747 vdev_args); 748 TEST_ASSERT(ret == 0, 749 "Failed to create instance %u of" 750 " pmd : %s", 751 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 752 } 753 } 754 #endif /* RTE_CRYPTO_SCHEDULER */ 755 756 nb_devs = rte_cryptodev_count(); 757 if (nb_devs < 1) { 758 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 759 return TEST_SKIPPED; 760 } 761 762 /* Create list of valid crypto devs */ 763 for (i = 0; i < nb_devs; i++) { 764 rte_cryptodev_info_get(i, &info); 765 if (info.driver_id == gbl_driver_id) 766 ts_params->valid_devs[ts_params->valid_dev_count++] = i; 767 } 768 769 if (ts_params->valid_dev_count < 1) 770 return TEST_FAILED; 771 772 /* Set up all the qps on the first of the valid devices found */ 773 774 dev_id = ts_params->valid_devs[0]; 775 776 rte_cryptodev_info_get(dev_id, &info); 777 778 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; 779 ts_params->conf.socket_id = SOCKET_ID_ANY; 780 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY; 781 782 unsigned int session_size = 783 rte_cryptodev_sym_get_private_session_size(dev_id); 784 785 #ifdef RTE_LIB_SECURITY 786 unsigned int security_session_size = rte_security_session_get_size( 787 rte_cryptodev_get_sec_ctx(dev_id)); 788 789 if (session_size < security_session_size) 790 session_size = security_session_size; 791 #endif 792 /* 793 * Create mempool with maximum number of sessions. 794 */ 795 if (info.sym.max_nb_sessions != 0 && 796 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 797 RTE_LOG(ERR, USER1, "Device does not support " 798 "at least %u sessions\n", 799 MAX_NB_SESSIONS); 800 return TEST_FAILED; 801 } 802 803 ts_params->session_mpool = rte_cryptodev_sym_session_pool_create( 804 "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0, 805 SOCKET_ID_ANY); 806 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 807 "session mempool allocation failed"); 808 809 ts_params->session_priv_mpool = rte_mempool_create( 810 "test_sess_mp_priv", 811 MAX_NB_SESSIONS, 812 session_size, 813 0, 0, NULL, NULL, NULL, 814 NULL, SOCKET_ID_ANY, 815 0); 816 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 817 "session mempool allocation failed"); 818 819 820 821 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, 822 &ts_params->conf), 823 "Failed to configure cryptodev %u with %u qps", 824 dev_id, ts_params->conf.nb_queue_pairs); 825 826 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 827 ts_params->qp_conf.mp_session = ts_params->session_mpool; 828 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 829 830 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 831 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 832 dev_id, qp_id, &ts_params->qp_conf, 833 rte_cryptodev_socket_id(dev_id)), 834 "Failed to setup queue pair %u on cryptodev %u", 835 qp_id, dev_id); 836 } 837 838 return TEST_SUCCESS; 839 } 840 841 static void 842 testsuite_teardown(void) 843 { 844 struct crypto_testsuite_params *ts_params = &testsuite_params; 845 846 if (ts_params->mbuf_pool != NULL) { 847 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 848 rte_mempool_avail_count(ts_params->mbuf_pool)); 849 } 850 851 if (ts_params->op_mpool != NULL) { 852 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", 853 rte_mempool_avail_count(ts_params->op_mpool)); 854 } 855 856 /* Free session mempools */ 857 if (ts_params->session_priv_mpool != NULL) { 858 rte_mempool_free(ts_params->session_priv_mpool); 859 ts_params->session_priv_mpool = NULL; 860 } 861 862 if (ts_params->session_mpool != NULL) { 863 rte_mempool_free(ts_params->session_mpool); 864 ts_params->session_mpool = NULL; 865 } 866 } 867 868 static int 869 dev_configure_and_start(uint64_t ff_disable) 870 { 871 struct crypto_testsuite_params *ts_params = &testsuite_params; 872 struct crypto_unittest_params *ut_params = &unittest_params; 873 874 uint16_t qp_id; 875 876 /* Clear unit test parameters before running test */ 877 memset(ut_params, 0, sizeof(*ut_params)); 878 879 /* Reconfigure device to default parameters */ 880 ts_params->conf.socket_id = SOCKET_ID_ANY; 881 ts_params->conf.ff_disable = ff_disable; 882 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 883 ts_params->qp_conf.mp_session = ts_params->session_mpool; 884 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 885 886 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 887 &ts_params->conf), 888 "Failed to configure cryptodev %u", 889 ts_params->valid_devs[0]); 890 891 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { 892 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 893 ts_params->valid_devs[0], qp_id, 894 &ts_params->qp_conf, 895 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 896 "Failed to setup queue pair %u on cryptodev %u", 897 qp_id, ts_params->valid_devs[0]); 898 } 899 900 901 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 902 903 /* Start the device */ 904 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 905 "Failed to start cryptodev %u", 906 ts_params->valid_devs[0]); 907 908 return TEST_SUCCESS; 909 } 910 911 static int 912 ut_setup(void) 913 { 914 /* Configure and start the device with security feature disabled */ 915 return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY); 916 } 917 918 static int 919 ut_setup_security(void) 920 { 921 /* Configure and start the device with no features disabled */ 922 return dev_configure_and_start(0); 923 } 924 925 static void 926 ut_teardown(void) 927 { 928 struct crypto_testsuite_params *ts_params = &testsuite_params; 929 struct crypto_unittest_params *ut_params = &unittest_params; 930 struct rte_cryptodev_stats stats; 931 932 /* free crypto session structure */ 933 #ifdef RTE_LIB_SECURITY 934 if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) { 935 if (ut_params->sec_session) { 936 rte_security_session_destroy(rte_cryptodev_get_sec_ctx 937 (ts_params->valid_devs[0]), 938 ut_params->sec_session); 939 ut_params->sec_session = NULL; 940 } 941 } else 942 #endif 943 { 944 if (ut_params->sess) { 945 rte_cryptodev_sym_session_clear( 946 ts_params->valid_devs[0], 947 ut_params->sess); 948 rte_cryptodev_sym_session_free(ut_params->sess); 949 ut_params->sess = NULL; 950 } 951 } 952 953 /* free crypto operation structure */ 954 if (ut_params->op) 955 rte_crypto_op_free(ut_params->op); 956 957 /* 958 * free mbuf - both obuf and ibuf are usually the same, 959 * so check if they point at the same address is necessary, 960 * to avoid freeing the mbuf twice. 961 */ 962 if (ut_params->obuf) { 963 rte_pktmbuf_free(ut_params->obuf); 964 if (ut_params->ibuf == ut_params->obuf) 965 ut_params->ibuf = 0; 966 ut_params->obuf = 0; 967 } 968 if (ut_params->ibuf) { 969 rte_pktmbuf_free(ut_params->ibuf); 970 ut_params->ibuf = 0; 971 } 972 973 if (ts_params->mbuf_pool != NULL) 974 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 975 rte_mempool_avail_count(ts_params->mbuf_pool)); 976 977 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats); 978 979 /* Stop the device */ 980 rte_cryptodev_stop(ts_params->valid_devs[0]); 981 } 982 983 static int 984 test_device_configure_invalid_dev_id(void) 985 { 986 struct crypto_testsuite_params *ts_params = &testsuite_params; 987 uint16_t dev_id, num_devs = 0; 988 989 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 990 "Need at least %d devices for test", 1); 991 992 /* valid dev_id values */ 993 dev_id = ts_params->valid_devs[0]; 994 995 /* Stop the device in case it's started so it can be configured */ 996 rte_cryptodev_stop(dev_id); 997 998 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 999 "Failed test for rte_cryptodev_configure: " 1000 "invalid dev_num %u", dev_id); 1001 1002 /* invalid dev_id values */ 1003 dev_id = num_devs; 1004 1005 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1006 "Failed test for rte_cryptodev_configure: " 1007 "invalid dev_num %u", dev_id); 1008 1009 dev_id = 0xff; 1010 1011 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1012 "Failed test for rte_cryptodev_configure:" 1013 "invalid dev_num %u", dev_id); 1014 1015 return TEST_SUCCESS; 1016 } 1017 1018 static int 1019 test_device_configure_invalid_queue_pair_ids(void) 1020 { 1021 struct crypto_testsuite_params *ts_params = &testsuite_params; 1022 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 1023 1024 /* Stop the device in case it's started so it can be configured */ 1025 rte_cryptodev_stop(ts_params->valid_devs[0]); 1026 1027 /* valid - max value queue pairs */ 1028 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1029 1030 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1031 &ts_params->conf), 1032 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1033 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 1034 1035 /* valid - one queue pairs */ 1036 ts_params->conf.nb_queue_pairs = 1; 1037 1038 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1039 &ts_params->conf), 1040 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1041 ts_params->valid_devs[0], 1042 ts_params->conf.nb_queue_pairs); 1043 1044 1045 /* invalid - zero queue pairs */ 1046 ts_params->conf.nb_queue_pairs = 0; 1047 1048 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1049 &ts_params->conf), 1050 "Failed test for rte_cryptodev_configure, dev_id %u," 1051 " invalid qps: %u", 1052 ts_params->valid_devs[0], 1053 ts_params->conf.nb_queue_pairs); 1054 1055 1056 /* invalid - max value supported by field queue pairs */ 1057 ts_params->conf.nb_queue_pairs = UINT16_MAX; 1058 1059 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1060 &ts_params->conf), 1061 "Failed test for rte_cryptodev_configure, dev_id %u," 1062 " invalid qps: %u", 1063 ts_params->valid_devs[0], 1064 ts_params->conf.nb_queue_pairs); 1065 1066 1067 /* invalid - max value + 1 queue pairs */ 1068 ts_params->conf.nb_queue_pairs = orig_nb_qps + 1; 1069 1070 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1071 &ts_params->conf), 1072 "Failed test for rte_cryptodev_configure, dev_id %u," 1073 " invalid qps: %u", 1074 ts_params->valid_devs[0], 1075 ts_params->conf.nb_queue_pairs); 1076 1077 /* revert to original testsuite value */ 1078 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1079 1080 return TEST_SUCCESS; 1081 } 1082 1083 static int 1084 test_queue_pair_descriptor_setup(void) 1085 { 1086 struct crypto_testsuite_params *ts_params = &testsuite_params; 1087 struct rte_cryptodev_qp_conf qp_conf = { 1088 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 1089 }; 1090 uint16_t qp_id; 1091 1092 /* Stop the device in case it's started so it can be configured */ 1093 rte_cryptodev_stop(ts_params->valid_devs[0]); 1094 1095 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1096 &ts_params->conf), 1097 "Failed to configure cryptodev %u", 1098 ts_params->valid_devs[0]); 1099 1100 /* 1101 * Test various ring sizes on this device. memzones can't be 1102 * freed so are re-used if ring is released and re-created. 1103 */ 1104 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/ 1105 qp_conf.mp_session = ts_params->session_mpool; 1106 qp_conf.mp_session_private = ts_params->session_priv_mpool; 1107 1108 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1109 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1110 ts_params->valid_devs[0], qp_id, &qp_conf, 1111 rte_cryptodev_socket_id( 1112 ts_params->valid_devs[0])), 1113 "Failed test for " 1114 "rte_cryptodev_queue_pair_setup: num_inflights " 1115 "%u on qp %u on cryptodev %u", 1116 qp_conf.nb_descriptors, qp_id, 1117 ts_params->valid_devs[0]); 1118 } 1119 1120 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2); 1121 1122 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1123 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1124 ts_params->valid_devs[0], qp_id, &qp_conf, 1125 rte_cryptodev_socket_id( 1126 ts_params->valid_devs[0])), 1127 "Failed test for" 1128 " rte_cryptodev_queue_pair_setup: num_inflights" 1129 " %u on qp %u on cryptodev %u", 1130 qp_conf.nb_descriptors, qp_id, 1131 ts_params->valid_devs[0]); 1132 } 1133 1134 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */ 1135 1136 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1137 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1138 ts_params->valid_devs[0], qp_id, &qp_conf, 1139 rte_cryptodev_socket_id( 1140 ts_params->valid_devs[0])), 1141 "Failed test for " 1142 "rte_cryptodev_queue_pair_setup: num_inflights" 1143 " %u on qp %u on cryptodev %u", 1144 qp_conf.nb_descriptors, qp_id, 1145 ts_params->valid_devs[0]); 1146 } 1147 1148 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 1149 1150 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1151 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1152 ts_params->valid_devs[0], qp_id, &qp_conf, 1153 rte_cryptodev_socket_id( 1154 ts_params->valid_devs[0])), 1155 "Failed test for" 1156 " rte_cryptodev_queue_pair_setup:" 1157 "num_inflights %u on qp %u on cryptodev %u", 1158 qp_conf.nb_descriptors, qp_id, 1159 ts_params->valid_devs[0]); 1160 } 1161 1162 /* test invalid queue pair id */ 1163 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */ 1164 1165 qp_id = ts_params->conf.nb_queue_pairs; /*invalid */ 1166 1167 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1168 ts_params->valid_devs[0], 1169 qp_id, &qp_conf, 1170 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1171 "Failed test for rte_cryptodev_queue_pair_setup:" 1172 "invalid qp %u on cryptodev %u", 1173 qp_id, ts_params->valid_devs[0]); 1174 1175 qp_id = 0xffff; /*invalid*/ 1176 1177 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1178 ts_params->valid_devs[0], 1179 qp_id, &qp_conf, 1180 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1181 "Failed test for rte_cryptodev_queue_pair_setup:" 1182 "invalid qp %u on cryptodev %u", 1183 qp_id, ts_params->valid_devs[0]); 1184 1185 return TEST_SUCCESS; 1186 } 1187 1188 /* ***** Plaintext data for tests ***** */ 1189 1190 const char catch_22_quote_1[] = 1191 "There was only one catch and that was Catch-22, which " 1192 "specified that a concern for one's safety in the face of " 1193 "dangers that were real and immediate was the process of a " 1194 "rational mind. Orr was crazy and could be grounded. All he " 1195 "had to do was ask; and as soon as he did, he would no longer " 1196 "be crazy and would have to fly more missions. Orr would be " 1197 "crazy to fly more missions and sane if he didn't, but if he " 1198 "was sane he had to fly them. If he flew them he was crazy " 1199 "and didn't have to; but if he didn't want to he was sane and " 1200 "had to. Yossarian was moved very deeply by the absolute " 1201 "simplicity of this clause of Catch-22 and let out a " 1202 "respectful whistle. \"That's some catch, that Catch-22\", he " 1203 "observed. \"It's the best there is,\" Doc Daneeka agreed."; 1204 1205 const char catch_22_quote[] = 1206 "What a lousy earth! He wondered how many people were " 1207 "destitute that same night even in his own prosperous country, " 1208 "how many homes were shanties, how many husbands were drunk " 1209 "and wives socked, and how many children were bullied, abused, " 1210 "or abandoned. How many families hungered for food they could " 1211 "not afford to buy? How many hearts were broken? How many " 1212 "suicides would take place that same night, how many people " 1213 "would go insane? How many cockroaches and landlords would " 1214 "triumph? How many winners were losers, successes failures, " 1215 "and rich men poor men? How many wise guys were stupid? How " 1216 "many happy endings were unhappy endings? How many honest men " 1217 "were liars, brave men cowards, loyal men traitors, how many " 1218 "sainted men were corrupt, how many people in positions of " 1219 "trust had sold their souls to bodyguards, how many had never " 1220 "had souls? How many straight-and-narrow paths were crooked " 1221 "paths? How many best families were worst families and how " 1222 "many good people were bad people? When you added them all up " 1223 "and then subtracted, you might be left with only the children, " 1224 "and perhaps with Albert Einstein and an old violinist or " 1225 "sculptor somewhere."; 1226 1227 #define QUOTE_480_BYTES (480) 1228 #define QUOTE_512_BYTES (512) 1229 #define QUOTE_768_BYTES (768) 1230 #define QUOTE_1024_BYTES (1024) 1231 1232 1233 1234 /* ***** SHA1 Hash Tests ***** */ 1235 1236 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1) 1237 1238 static uint8_t hmac_sha1_key[] = { 1239 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 1240 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 1241 0xDE, 0xF4, 0xDE, 0xAD }; 1242 1243 /* ***** SHA224 Hash Tests ***** */ 1244 1245 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224) 1246 1247 1248 /* ***** AES-CBC Cipher Tests ***** */ 1249 1250 #define CIPHER_KEY_LENGTH_AES_CBC (16) 1251 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC) 1252 1253 static uint8_t aes_cbc_key[] = { 1254 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 1255 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A }; 1256 1257 static uint8_t aes_cbc_iv[] = { 1258 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 1259 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; 1260 1261 1262 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */ 1263 1264 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = { 1265 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, 1266 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, 1267 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, 1268 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, 1269 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E, 1270 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08, 1271 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0, 1272 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01, 1273 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57, 1274 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE, 1275 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9, 1276 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9, 1277 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D, 1278 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3, 1279 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46, 1280 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3, 1281 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80, 1282 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92, 1283 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5, 1284 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5, 1285 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2, 1286 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5, 1287 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1288 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76, 1289 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4, 1290 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62, 1291 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4, 1292 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4, 1293 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54, 1294 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61, 1295 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91, 1296 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A, 1297 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF, 1298 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F, 1299 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28, 1300 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E, 1301 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7, 1302 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76, 1303 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6, 1304 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03, 1305 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C, 1306 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2, 1307 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6, 1308 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96, 1309 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6, 1310 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA, 1311 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87, 1312 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55, 1313 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B, 1314 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98, 1315 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53, 1316 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A, 1317 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26, 1318 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36, 1319 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36, 1320 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D, 1321 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E, 1322 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E, 1323 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A, 1324 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6, 1325 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4, 1326 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7, 1327 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1, 1328 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C 1329 }; 1330 1331 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = { 1332 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60, 1333 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1334 0x18, 0x8c, 0x1d, 0x32 1335 }; 1336 1337 1338 /* Multisession Vector context Test */ 1339 /*Begin Session 0 */ 1340 static uint8_t ms_aes_cbc_key0[] = { 1341 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1342 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1343 }; 1344 1345 static uint8_t ms_aes_cbc_iv0[] = { 1346 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1347 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1348 }; 1349 1350 static const uint8_t ms_aes_cbc_cipher0[] = { 1351 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38, 1352 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC, 1353 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB, 1354 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9, 1355 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D, 1356 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4, 1357 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34, 1358 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F, 1359 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99, 1360 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED, 1361 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D, 1362 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24, 1363 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71, 1364 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72, 1365 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E, 1366 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD, 1367 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18, 1368 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6, 1369 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29, 1370 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C, 1371 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96, 1372 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26, 1373 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55, 1374 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46, 1375 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B, 1376 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4, 1377 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7, 1378 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5, 1379 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0, 1380 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E, 1381 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D, 1382 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44, 1383 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76, 1384 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3, 1385 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83, 1386 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85, 1387 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45, 1388 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25, 1389 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A, 1390 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1, 1391 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA, 1392 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3, 1393 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4, 1394 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60, 1395 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A, 1396 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A, 1397 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9, 1398 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55, 1399 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13, 1400 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B, 1401 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1, 1402 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0, 1403 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3, 1404 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23, 1405 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B, 1406 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07, 1407 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB, 1408 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1, 1409 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F, 1410 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F, 1411 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84, 1412 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B, 1413 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17, 1414 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF 1415 }; 1416 1417 1418 static uint8_t ms_hmac_key0[] = { 1419 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1420 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1421 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1422 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1423 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1424 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1425 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1426 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1427 }; 1428 1429 static const uint8_t ms_hmac_digest0[] = { 1430 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51, 1431 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F, 1432 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C, 1433 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4, 1434 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56, 1435 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4, 1436 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23, 1437 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90 1438 }; 1439 1440 /* End Session 0 */ 1441 /* Begin session 1 */ 1442 1443 static uint8_t ms_aes_cbc_key1[] = { 1444 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1445 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1446 }; 1447 1448 static uint8_t ms_aes_cbc_iv1[] = { 1449 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1450 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1451 }; 1452 1453 static const uint8_t ms_aes_cbc_cipher1[] = { 1454 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71, 1455 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23, 1456 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09, 1457 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A, 1458 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C, 1459 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F, 1460 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9, 1461 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66, 1462 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43, 1463 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB, 1464 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23, 1465 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29, 1466 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26, 1467 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F, 1468 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68, 1469 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77, 1470 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8, 1471 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97, 1472 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3, 1473 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90, 1474 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5, 1475 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E, 1476 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45, 1477 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B, 1478 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5, 1479 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D, 1480 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E, 1481 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD, 1482 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE, 1483 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1, 1484 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F, 1485 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25, 1486 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1, 1487 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3, 1488 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE, 1489 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6, 1490 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52, 1491 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA, 1492 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63, 1493 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E, 1494 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA, 1495 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB, 1496 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71, 1497 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF, 1498 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A, 1499 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95, 1500 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73, 1501 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49, 1502 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB, 1503 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B, 1504 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC, 1505 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED, 1506 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02, 1507 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4, 1508 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF, 1509 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82, 1510 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D, 1511 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6, 1512 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9, 1513 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35, 1514 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0, 1515 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53, 1516 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5, 1517 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3 1518 1519 }; 1520 1521 static uint8_t ms_hmac_key1[] = { 1522 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1523 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1524 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1525 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1526 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1527 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1528 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1529 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1530 }; 1531 1532 static const uint8_t ms_hmac_digest1[] = { 1533 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69, 1534 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50, 1535 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20, 1536 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD, 1537 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9, 1538 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4, 1539 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA, 1540 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F 1541 }; 1542 /* End Session 1 */ 1543 /* Begin Session 2 */ 1544 static uint8_t ms_aes_cbc_key2[] = { 1545 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1546 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1547 }; 1548 1549 static uint8_t ms_aes_cbc_iv2[] = { 1550 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1551 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1552 }; 1553 1554 static const uint8_t ms_aes_cbc_cipher2[] = { 1555 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91, 1556 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97, 1557 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8, 1558 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5, 1559 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98, 1560 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69, 1561 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09, 1562 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF, 1563 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44, 1564 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B, 1565 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9, 1566 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34, 1567 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99, 1568 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF, 1569 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC, 1570 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26, 1571 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3, 1572 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF, 1573 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3, 1574 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3, 1575 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA, 1576 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13, 1577 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38, 1578 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71, 1579 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC, 1580 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1, 1581 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E, 1582 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22, 1583 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62, 1584 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72, 1585 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6, 1586 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6, 1587 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44, 1588 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24, 1589 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5, 1590 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E, 1591 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17, 1592 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9, 1593 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D, 1594 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D, 1595 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22, 1596 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9, 1597 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49, 1598 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E, 1599 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B, 1600 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2, 1601 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95, 1602 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07, 1603 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3, 1604 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A, 1605 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57, 1606 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84, 1607 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61, 1608 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF, 1609 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17, 1610 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A, 1611 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1, 1612 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53, 1613 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7, 1614 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2, 1615 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A, 1616 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8, 1617 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70, 1618 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92 1619 }; 1620 1621 static uint8_t ms_hmac_key2[] = { 1622 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1623 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1624 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1625 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1626 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1627 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1628 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1629 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1630 }; 1631 1632 static const uint8_t ms_hmac_digest2[] = { 1633 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF, 1634 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6, 1635 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77, 1636 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27, 1637 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82, 1638 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24, 1639 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E, 1640 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59 1641 }; 1642 1643 /* End Session 2 */ 1644 1645 1646 static int 1647 test_AES_CBC_HMAC_SHA1_encrypt_digest(void) 1648 { 1649 struct crypto_testsuite_params *ts_params = &testsuite_params; 1650 struct crypto_unittest_params *ut_params = &unittest_params; 1651 1652 /* Verify the capabilities */ 1653 struct rte_cryptodev_sym_capability_idx cap_idx; 1654 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1655 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 1656 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 1657 &cap_idx) == NULL) 1658 return -ENOTSUP; 1659 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1660 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 1661 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 1662 &cap_idx) == NULL) 1663 return -ENOTSUP; 1664 1665 /* Generate test mbuf data and space for digest */ 1666 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 1667 catch_22_quote, QUOTE_512_BYTES, 0); 1668 1669 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 1670 DIGEST_BYTE_LENGTH_SHA1); 1671 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 1672 1673 /* Setup Cipher Parameters */ 1674 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1675 ut_params->cipher_xform.next = &ut_params->auth_xform; 1676 1677 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 1678 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 1679 ut_params->cipher_xform.cipher.key.data = aes_cbc_key; 1680 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 1681 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 1682 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 1683 1684 /* Setup HMAC Parameters */ 1685 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1686 1687 ut_params->auth_xform.next = NULL; 1688 1689 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 1690 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 1691 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; 1692 ut_params->auth_xform.auth.key.data = hmac_sha1_key; 1693 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; 1694 1695 ut_params->sess = rte_cryptodev_sym_session_create( 1696 ts_params->session_mpool); 1697 1698 /* Create crypto session*/ 1699 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 1700 ut_params->sess, &ut_params->cipher_xform, 1701 ts_params->session_priv_mpool); 1702 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 1703 1704 /* Generate crypto op data structure */ 1705 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1706 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1707 TEST_ASSERT_NOT_NULL(ut_params->op, 1708 "Failed to allocate symmetric crypto operation struct"); 1709 1710 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 1711 1712 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1713 1714 /* set crypto operation source mbuf */ 1715 sym_op->m_src = ut_params->ibuf; 1716 1717 /* Set crypto operation authentication parameters */ 1718 sym_op->auth.digest.data = ut_params->digest; 1719 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 1720 ut_params->ibuf, QUOTE_512_BYTES); 1721 1722 sym_op->auth.data.offset = 0; 1723 sym_op->auth.data.length = QUOTE_512_BYTES; 1724 1725 /* Copy IV at the end of the crypto operation */ 1726 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 1727 aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC); 1728 1729 /* Set crypto operation cipher parameters */ 1730 sym_op->cipher.data.offset = 0; 1731 sym_op->cipher.data.length = QUOTE_512_BYTES; 1732 1733 /* Process crypto operation */ 1734 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 1735 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 1736 ut_params->op); 1737 else 1738 TEST_ASSERT_NOT_NULL( 1739 process_crypto_request(ts_params->valid_devs[0], 1740 ut_params->op), 1741 "failed to process sym crypto op"); 1742 1743 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1744 "crypto op processing failed"); 1745 1746 /* Validate obuf */ 1747 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 1748 uint8_t *); 1749 1750 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, 1751 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 1752 QUOTE_512_BYTES, 1753 "ciphertext data not as expected"); 1754 1755 uint8_t *digest = ciphertext + QUOTE_512_BYTES; 1756 1757 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, 1758 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, 1759 gbl_driver_id == rte_cryptodev_driver_id_get( 1760 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ? 1761 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : 1762 DIGEST_BYTE_LENGTH_SHA1, 1763 "Generated digest data not as expected"); 1764 1765 return TEST_SUCCESS; 1766 } 1767 1768 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ 1769 1770 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) 1771 1772 static uint8_t hmac_sha512_key[] = { 1773 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1774 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1775 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1776 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60, 1777 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1, 1778 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1779 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76, 1780 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 }; 1781 1782 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = { 1783 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8, 1784 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48, 1785 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8, 1786 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70, 1787 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8, 1788 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E, 1789 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D, 1790 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A }; 1791 1792 1793 1794 static int 1795 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 1796 struct crypto_unittest_params *ut_params, 1797 uint8_t *cipher_key, 1798 uint8_t *hmac_key); 1799 1800 static int 1801 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 1802 struct crypto_unittest_params *ut_params, 1803 struct crypto_testsuite_params *ts_params, 1804 const uint8_t *cipher, 1805 const uint8_t *digest, 1806 const uint8_t *iv); 1807 1808 1809 static int 1810 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 1811 struct crypto_unittest_params *ut_params, 1812 uint8_t *cipher_key, 1813 uint8_t *hmac_key) 1814 { 1815 1816 /* Setup Cipher Parameters */ 1817 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1818 ut_params->cipher_xform.next = NULL; 1819 1820 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 1821 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 1822 ut_params->cipher_xform.cipher.key.data = cipher_key; 1823 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 1824 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 1825 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 1826 1827 /* Setup HMAC Parameters */ 1828 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1829 ut_params->auth_xform.next = &ut_params->cipher_xform; 1830 1831 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 1832 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC; 1833 ut_params->auth_xform.auth.key.data = hmac_key; 1834 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512; 1835 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512; 1836 1837 return TEST_SUCCESS; 1838 } 1839 1840 1841 static int 1842 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 1843 struct crypto_unittest_params *ut_params, 1844 struct crypto_testsuite_params *ts_params, 1845 const uint8_t *cipher, 1846 const uint8_t *digest, 1847 const uint8_t *iv) 1848 { 1849 /* Generate test mbuf data and digest */ 1850 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 1851 (const char *) 1852 cipher, 1853 QUOTE_512_BYTES, 0); 1854 1855 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 1856 DIGEST_BYTE_LENGTH_SHA512); 1857 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 1858 1859 rte_memcpy(ut_params->digest, 1860 digest, 1861 DIGEST_BYTE_LENGTH_SHA512); 1862 1863 /* Generate Crypto op data structure */ 1864 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1865 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1866 TEST_ASSERT_NOT_NULL(ut_params->op, 1867 "Failed to allocate symmetric crypto operation struct"); 1868 1869 rte_crypto_op_attach_sym_session(ut_params->op, sess); 1870 1871 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1872 1873 /* set crypto operation source mbuf */ 1874 sym_op->m_src = ut_params->ibuf; 1875 1876 sym_op->auth.digest.data = ut_params->digest; 1877 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 1878 ut_params->ibuf, QUOTE_512_BYTES); 1879 1880 sym_op->auth.data.offset = 0; 1881 sym_op->auth.data.length = QUOTE_512_BYTES; 1882 1883 /* Copy IV at the end of the crypto operation */ 1884 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 1885 iv, CIPHER_IV_LENGTH_AES_CBC); 1886 1887 sym_op->cipher.data.offset = 0; 1888 sym_op->cipher.data.length = QUOTE_512_BYTES; 1889 1890 /* Process crypto operation */ 1891 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 1892 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 1893 ut_params->op); 1894 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 1895 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 1896 ut_params->op, 1, 1, 0, 0); 1897 else 1898 TEST_ASSERT_NOT_NULL( 1899 process_crypto_request(ts_params->valid_devs[0], 1900 ut_params->op), 1901 "failed to process sym crypto op"); 1902 1903 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1904 "crypto op processing failed"); 1905 1906 ut_params->obuf = ut_params->op->sym->m_src; 1907 1908 /* Validate obuf */ 1909 TEST_ASSERT_BUFFERS_ARE_EQUAL( 1910 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 1911 catch_22_quote, 1912 QUOTE_512_BYTES, 1913 "Plaintext data not as expected"); 1914 1915 /* Validate obuf */ 1916 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1917 "Digest verification failed"); 1918 1919 return TEST_SUCCESS; 1920 } 1921 1922 static int 1923 test_blockcipher(enum blockcipher_test_type test_type) 1924 { 1925 struct crypto_testsuite_params *ts_params = &testsuite_params; 1926 int status; 1927 1928 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1929 ts_params->op_mpool, 1930 ts_params->session_mpool, ts_params->session_priv_mpool, 1931 ts_params->valid_devs[0], 1932 test_type); 1933 1934 if (status == -ENOTSUP) 1935 return status; 1936 1937 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1938 1939 return TEST_SUCCESS; 1940 } 1941 1942 static int 1943 test_AES_cipheronly_all(void) 1944 { 1945 return test_blockcipher(BLKCIPHER_AES_CIPHERONLY_TYPE); 1946 } 1947 1948 static int 1949 test_AES_docsis_all(void) 1950 { 1951 /* Data-path service does not support DOCSIS yet */ 1952 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 1953 return -ENOTSUP; 1954 return test_blockcipher(BLKCIPHER_AES_DOCSIS_TYPE); 1955 } 1956 1957 static int 1958 test_DES_docsis_all(void) 1959 { 1960 /* Data-path service does not support DOCSIS yet */ 1961 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 1962 return -ENOTSUP; 1963 return test_blockcipher(BLKCIPHER_DES_DOCSIS_TYPE); 1964 } 1965 1966 static int 1967 test_DES_cipheronly_all(void) 1968 { 1969 return test_blockcipher(BLKCIPHER_DES_CIPHERONLY_TYPE); 1970 } 1971 1972 static int 1973 test_authonly_all(void) 1974 { 1975 return test_blockcipher(BLKCIPHER_AUTHONLY_TYPE); 1976 } 1977 1978 static int 1979 test_AES_chain_all(void) 1980 { 1981 return test_blockcipher(BLKCIPHER_AES_CHAIN_TYPE); 1982 } 1983 1984 static int 1985 test_3DES_chain_all(void) 1986 { 1987 return test_blockcipher(BLKCIPHER_3DES_CHAIN_TYPE); 1988 } 1989 1990 static int 1991 test_3DES_cipheronly_all(void) 1992 { 1993 return test_blockcipher(BLKCIPHER_3DES_CIPHERONLY_TYPE); 1994 } 1995 1996 /* ***** SNOW 3G Tests ***** */ 1997 static int 1998 create_wireless_algo_hash_session(uint8_t dev_id, 1999 const uint8_t *key, const uint8_t key_len, 2000 const uint8_t iv_len, const uint8_t auth_len, 2001 enum rte_crypto_auth_operation op, 2002 enum rte_crypto_auth_algorithm algo) 2003 { 2004 uint8_t hash_key[key_len]; 2005 int status; 2006 2007 struct crypto_testsuite_params *ts_params = &testsuite_params; 2008 struct crypto_unittest_params *ut_params = &unittest_params; 2009 2010 memcpy(hash_key, key, key_len); 2011 2012 debug_hexdump(stdout, "key:", key, key_len); 2013 2014 /* Setup Authentication Parameters */ 2015 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2016 ut_params->auth_xform.next = NULL; 2017 2018 ut_params->auth_xform.auth.op = op; 2019 ut_params->auth_xform.auth.algo = algo; 2020 ut_params->auth_xform.auth.key.length = key_len; 2021 ut_params->auth_xform.auth.key.data = hash_key; 2022 ut_params->auth_xform.auth.digest_length = auth_len; 2023 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 2024 ut_params->auth_xform.auth.iv.length = iv_len; 2025 ut_params->sess = rte_cryptodev_sym_session_create( 2026 ts_params->session_mpool); 2027 2028 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2029 &ut_params->auth_xform, 2030 ts_params->session_priv_mpool); 2031 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2032 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2033 return 0; 2034 } 2035 2036 static int 2037 create_wireless_algo_cipher_session(uint8_t dev_id, 2038 enum rte_crypto_cipher_operation op, 2039 enum rte_crypto_cipher_algorithm algo, 2040 const uint8_t *key, const uint8_t key_len, 2041 uint8_t iv_len) 2042 { 2043 uint8_t cipher_key[key_len]; 2044 int status; 2045 struct crypto_testsuite_params *ts_params = &testsuite_params; 2046 struct crypto_unittest_params *ut_params = &unittest_params; 2047 2048 memcpy(cipher_key, key, key_len); 2049 2050 /* Setup Cipher Parameters */ 2051 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2052 ut_params->cipher_xform.next = NULL; 2053 2054 ut_params->cipher_xform.cipher.algo = algo; 2055 ut_params->cipher_xform.cipher.op = op; 2056 ut_params->cipher_xform.cipher.key.data = cipher_key; 2057 ut_params->cipher_xform.cipher.key.length = key_len; 2058 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2059 ut_params->cipher_xform.cipher.iv.length = iv_len; 2060 2061 debug_hexdump(stdout, "key:", key, key_len); 2062 2063 /* Create Crypto session */ 2064 ut_params->sess = rte_cryptodev_sym_session_create( 2065 ts_params->session_mpool); 2066 2067 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2068 &ut_params->cipher_xform, 2069 ts_params->session_priv_mpool); 2070 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2071 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2072 return 0; 2073 } 2074 2075 static int 2076 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len, 2077 unsigned int cipher_len, 2078 unsigned int cipher_offset) 2079 { 2080 struct crypto_testsuite_params *ts_params = &testsuite_params; 2081 struct crypto_unittest_params *ut_params = &unittest_params; 2082 2083 /* Generate Crypto op data structure */ 2084 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2085 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2086 TEST_ASSERT_NOT_NULL(ut_params->op, 2087 "Failed to allocate pktmbuf offload"); 2088 2089 /* Set crypto operation data parameters */ 2090 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2091 2092 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2093 2094 /* set crypto operation source mbuf */ 2095 sym_op->m_src = ut_params->ibuf; 2096 2097 /* iv */ 2098 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2099 iv, iv_len); 2100 sym_op->cipher.data.length = cipher_len; 2101 sym_op->cipher.data.offset = cipher_offset; 2102 return 0; 2103 } 2104 2105 static int 2106 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len, 2107 unsigned int cipher_len, 2108 unsigned int cipher_offset) 2109 { 2110 struct crypto_testsuite_params *ts_params = &testsuite_params; 2111 struct crypto_unittest_params *ut_params = &unittest_params; 2112 2113 /* Generate Crypto op data structure */ 2114 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2115 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2116 TEST_ASSERT_NOT_NULL(ut_params->op, 2117 "Failed to allocate pktmbuf offload"); 2118 2119 /* Set crypto operation data parameters */ 2120 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2121 2122 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2123 2124 /* set crypto operation source mbuf */ 2125 sym_op->m_src = ut_params->ibuf; 2126 sym_op->m_dst = ut_params->obuf; 2127 2128 /* iv */ 2129 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2130 iv, iv_len); 2131 sym_op->cipher.data.length = cipher_len; 2132 sym_op->cipher.data.offset = cipher_offset; 2133 return 0; 2134 } 2135 2136 static int 2137 create_wireless_algo_cipher_auth_session(uint8_t dev_id, 2138 enum rte_crypto_cipher_operation cipher_op, 2139 enum rte_crypto_auth_operation auth_op, 2140 enum rte_crypto_auth_algorithm auth_algo, 2141 enum rte_crypto_cipher_algorithm cipher_algo, 2142 const uint8_t *key, uint8_t key_len, 2143 uint8_t auth_iv_len, uint8_t auth_len, 2144 uint8_t cipher_iv_len) 2145 2146 { 2147 uint8_t cipher_auth_key[key_len]; 2148 int status; 2149 2150 struct crypto_testsuite_params *ts_params = &testsuite_params; 2151 struct crypto_unittest_params *ut_params = &unittest_params; 2152 2153 memcpy(cipher_auth_key, key, key_len); 2154 2155 /* Setup Authentication Parameters */ 2156 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2157 ut_params->auth_xform.next = NULL; 2158 2159 ut_params->auth_xform.auth.op = auth_op; 2160 ut_params->auth_xform.auth.algo = auth_algo; 2161 ut_params->auth_xform.auth.key.length = key_len; 2162 /* Hash key = cipher key */ 2163 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2164 ut_params->auth_xform.auth.digest_length = auth_len; 2165 /* Auth IV will be after cipher IV */ 2166 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2167 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2168 2169 /* Setup Cipher Parameters */ 2170 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2171 ut_params->cipher_xform.next = &ut_params->auth_xform; 2172 2173 ut_params->cipher_xform.cipher.algo = cipher_algo; 2174 ut_params->cipher_xform.cipher.op = cipher_op; 2175 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2176 ut_params->cipher_xform.cipher.key.length = key_len; 2177 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2178 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2179 2180 debug_hexdump(stdout, "key:", key, key_len); 2181 2182 /* Create Crypto session*/ 2183 ut_params->sess = rte_cryptodev_sym_session_create( 2184 ts_params->session_mpool); 2185 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2186 2187 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2188 &ut_params->cipher_xform, 2189 ts_params->session_priv_mpool); 2190 if (status == -ENOTSUP) 2191 return status; 2192 2193 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2194 return 0; 2195 } 2196 2197 static int 2198 create_wireless_cipher_auth_session(uint8_t dev_id, 2199 enum rte_crypto_cipher_operation cipher_op, 2200 enum rte_crypto_auth_operation auth_op, 2201 enum rte_crypto_auth_algorithm auth_algo, 2202 enum rte_crypto_cipher_algorithm cipher_algo, 2203 const struct wireless_test_data *tdata) 2204 { 2205 const uint8_t key_len = tdata->key.len; 2206 uint8_t cipher_auth_key[key_len]; 2207 int status; 2208 2209 struct crypto_testsuite_params *ts_params = &testsuite_params; 2210 struct crypto_unittest_params *ut_params = &unittest_params; 2211 const uint8_t *key = tdata->key.data; 2212 const uint8_t auth_len = tdata->digest.len; 2213 uint8_t cipher_iv_len = tdata->cipher_iv.len; 2214 uint8_t auth_iv_len = tdata->auth_iv.len; 2215 2216 memcpy(cipher_auth_key, key, key_len); 2217 2218 /* Setup Authentication Parameters */ 2219 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2220 ut_params->auth_xform.next = NULL; 2221 2222 ut_params->auth_xform.auth.op = auth_op; 2223 ut_params->auth_xform.auth.algo = auth_algo; 2224 ut_params->auth_xform.auth.key.length = key_len; 2225 /* Hash key = cipher key */ 2226 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2227 ut_params->auth_xform.auth.digest_length = auth_len; 2228 /* Auth IV will be after cipher IV */ 2229 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2230 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2231 2232 /* Setup Cipher Parameters */ 2233 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2234 ut_params->cipher_xform.next = &ut_params->auth_xform; 2235 2236 ut_params->cipher_xform.cipher.algo = cipher_algo; 2237 ut_params->cipher_xform.cipher.op = cipher_op; 2238 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2239 ut_params->cipher_xform.cipher.key.length = key_len; 2240 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2241 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2242 2243 2244 debug_hexdump(stdout, "key:", key, key_len); 2245 2246 /* Create Crypto session*/ 2247 ut_params->sess = rte_cryptodev_sym_session_create( 2248 ts_params->session_mpool); 2249 2250 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2251 &ut_params->cipher_xform, 2252 ts_params->session_priv_mpool); 2253 if (status == -ENOTSUP) 2254 return status; 2255 2256 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2257 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2258 return 0; 2259 } 2260 2261 static int 2262 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id, 2263 const struct wireless_test_data *tdata) 2264 { 2265 return create_wireless_cipher_auth_session(dev_id, 2266 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2267 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3, 2268 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata); 2269 } 2270 2271 static int 2272 create_wireless_algo_auth_cipher_session(uint8_t dev_id, 2273 enum rte_crypto_cipher_operation cipher_op, 2274 enum rte_crypto_auth_operation auth_op, 2275 enum rte_crypto_auth_algorithm auth_algo, 2276 enum rte_crypto_cipher_algorithm cipher_algo, 2277 const uint8_t *key, const uint8_t key_len, 2278 uint8_t auth_iv_len, uint8_t auth_len, 2279 uint8_t cipher_iv_len) 2280 { 2281 uint8_t auth_cipher_key[key_len]; 2282 int status; 2283 struct crypto_testsuite_params *ts_params = &testsuite_params; 2284 struct crypto_unittest_params *ut_params = &unittest_params; 2285 2286 memcpy(auth_cipher_key, key, key_len); 2287 2288 /* Setup Authentication Parameters */ 2289 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2290 ut_params->auth_xform.auth.op = auth_op; 2291 ut_params->auth_xform.next = &ut_params->cipher_xform; 2292 ut_params->auth_xform.auth.algo = auth_algo; 2293 ut_params->auth_xform.auth.key.length = key_len; 2294 ut_params->auth_xform.auth.key.data = auth_cipher_key; 2295 ut_params->auth_xform.auth.digest_length = auth_len; 2296 /* Auth IV will be after cipher IV */ 2297 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2298 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2299 2300 /* Setup Cipher Parameters */ 2301 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2302 ut_params->cipher_xform.next = NULL; 2303 ut_params->cipher_xform.cipher.algo = cipher_algo; 2304 ut_params->cipher_xform.cipher.op = cipher_op; 2305 ut_params->cipher_xform.cipher.key.data = auth_cipher_key; 2306 ut_params->cipher_xform.cipher.key.length = key_len; 2307 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2308 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2309 2310 debug_hexdump(stdout, "key:", key, key_len); 2311 2312 /* Create Crypto session*/ 2313 ut_params->sess = rte_cryptodev_sym_session_create( 2314 ts_params->session_mpool); 2315 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2316 2317 if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 2318 ut_params->auth_xform.next = NULL; 2319 ut_params->cipher_xform.next = &ut_params->auth_xform; 2320 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2321 &ut_params->cipher_xform, 2322 ts_params->session_priv_mpool); 2323 2324 } else 2325 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2326 &ut_params->auth_xform, 2327 ts_params->session_priv_mpool); 2328 2329 if (status == -ENOTSUP) 2330 return status; 2331 2332 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2333 2334 return 0; 2335 } 2336 2337 static int 2338 create_wireless_algo_hash_operation(const uint8_t *auth_tag, 2339 unsigned int auth_tag_len, 2340 const uint8_t *iv, unsigned int iv_len, 2341 unsigned int data_pad_len, 2342 enum rte_crypto_auth_operation op, 2343 unsigned int auth_len, unsigned int auth_offset) 2344 { 2345 struct crypto_testsuite_params *ts_params = &testsuite_params; 2346 2347 struct crypto_unittest_params *ut_params = &unittest_params; 2348 2349 /* Generate Crypto op data structure */ 2350 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2351 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2352 TEST_ASSERT_NOT_NULL(ut_params->op, 2353 "Failed to allocate pktmbuf offload"); 2354 2355 /* Set crypto operation data parameters */ 2356 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2357 2358 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2359 2360 /* set crypto operation source mbuf */ 2361 sym_op->m_src = ut_params->ibuf; 2362 2363 /* iv */ 2364 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2365 iv, iv_len); 2366 /* digest */ 2367 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2368 ut_params->ibuf, auth_tag_len); 2369 2370 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2371 "no room to append auth tag"); 2372 ut_params->digest = sym_op->auth.digest.data; 2373 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2374 ut_params->ibuf, data_pad_len); 2375 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2376 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2377 else 2378 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2379 2380 debug_hexdump(stdout, "digest:", 2381 sym_op->auth.digest.data, 2382 auth_tag_len); 2383 2384 sym_op->auth.data.length = auth_len; 2385 sym_op->auth.data.offset = auth_offset; 2386 2387 return 0; 2388 } 2389 2390 static int 2391 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata, 2392 enum rte_crypto_auth_operation op) 2393 { 2394 struct crypto_testsuite_params *ts_params = &testsuite_params; 2395 struct crypto_unittest_params *ut_params = &unittest_params; 2396 2397 const uint8_t *auth_tag = tdata->digest.data; 2398 const unsigned int auth_tag_len = tdata->digest.len; 2399 unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len); 2400 unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2401 2402 const uint8_t *cipher_iv = tdata->cipher_iv.data; 2403 const uint8_t cipher_iv_len = tdata->cipher_iv.len; 2404 const uint8_t *auth_iv = tdata->auth_iv.data; 2405 const uint8_t auth_iv_len = tdata->auth_iv.len; 2406 const unsigned int cipher_len = tdata->validCipherLenInBits.len; 2407 const unsigned int auth_len = tdata->validAuthLenInBits.len; 2408 2409 /* Generate Crypto op data structure */ 2410 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2411 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2412 TEST_ASSERT_NOT_NULL(ut_params->op, 2413 "Failed to allocate pktmbuf offload"); 2414 /* Set crypto operation data parameters */ 2415 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2416 2417 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2418 2419 /* set crypto operation source mbuf */ 2420 sym_op->m_src = ut_params->ibuf; 2421 2422 /* digest */ 2423 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2424 ut_params->ibuf, auth_tag_len); 2425 2426 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2427 "no room to append auth tag"); 2428 ut_params->digest = sym_op->auth.digest.data; 2429 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2430 ut_params->ibuf, data_pad_len); 2431 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2432 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2433 else 2434 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2435 2436 debug_hexdump(stdout, "digest:", 2437 sym_op->auth.digest.data, 2438 auth_tag_len); 2439 2440 /* Copy cipher and auth IVs at the end of the crypto operation */ 2441 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2442 IV_OFFSET); 2443 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2444 iv_ptr += cipher_iv_len; 2445 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2446 2447 sym_op->cipher.data.length = cipher_len; 2448 sym_op->cipher.data.offset = 0; 2449 sym_op->auth.data.length = auth_len; 2450 sym_op->auth.data.offset = 0; 2451 2452 return 0; 2453 } 2454 2455 static int 2456 create_zuc_cipher_hash_generate_operation( 2457 const struct wireless_test_data *tdata) 2458 { 2459 return create_wireless_cipher_hash_operation(tdata, 2460 RTE_CRYPTO_AUTH_OP_GENERATE); 2461 } 2462 2463 static int 2464 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag, 2465 const unsigned auth_tag_len, 2466 const uint8_t *auth_iv, uint8_t auth_iv_len, 2467 unsigned data_pad_len, 2468 enum rte_crypto_auth_operation op, 2469 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2470 const unsigned cipher_len, const unsigned cipher_offset, 2471 const unsigned auth_len, const unsigned auth_offset) 2472 { 2473 struct crypto_testsuite_params *ts_params = &testsuite_params; 2474 struct crypto_unittest_params *ut_params = &unittest_params; 2475 2476 enum rte_crypto_cipher_algorithm cipher_algo = 2477 ut_params->cipher_xform.cipher.algo; 2478 enum rte_crypto_auth_algorithm auth_algo = 2479 ut_params->auth_xform.auth.algo; 2480 2481 /* Generate Crypto op data structure */ 2482 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2483 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2484 TEST_ASSERT_NOT_NULL(ut_params->op, 2485 "Failed to allocate pktmbuf offload"); 2486 /* Set crypto operation data parameters */ 2487 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2488 2489 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2490 2491 /* set crypto operation source mbuf */ 2492 sym_op->m_src = ut_params->ibuf; 2493 2494 /* digest */ 2495 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2496 ut_params->ibuf, auth_tag_len); 2497 2498 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2499 "no room to append auth tag"); 2500 ut_params->digest = sym_op->auth.digest.data; 2501 2502 if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) { 2503 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2504 ut_params->ibuf, data_pad_len); 2505 } else { 2506 struct rte_mbuf *m = ut_params->ibuf; 2507 unsigned int offset = data_pad_len; 2508 2509 while (offset > m->data_len && m->next != NULL) { 2510 offset -= m->data_len; 2511 m = m->next; 2512 } 2513 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2514 m, offset); 2515 } 2516 2517 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2518 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2519 else 2520 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2521 2522 debug_hexdump(stdout, "digest:", 2523 sym_op->auth.digest.data, 2524 auth_tag_len); 2525 2526 /* Copy cipher and auth IVs at the end of the crypto operation */ 2527 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2528 IV_OFFSET); 2529 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2530 iv_ptr += cipher_iv_len; 2531 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2532 2533 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 2534 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 2535 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 2536 sym_op->cipher.data.length = cipher_len; 2537 sym_op->cipher.data.offset = cipher_offset; 2538 } else { 2539 sym_op->cipher.data.length = cipher_len >> 3; 2540 sym_op->cipher.data.offset = cipher_offset >> 3; 2541 } 2542 2543 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 2544 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 2545 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 2546 sym_op->auth.data.length = auth_len; 2547 sym_op->auth.data.offset = auth_offset; 2548 } else { 2549 sym_op->auth.data.length = auth_len >> 3; 2550 sym_op->auth.data.offset = auth_offset >> 3; 2551 } 2552 2553 return 0; 2554 } 2555 2556 static int 2557 create_wireless_algo_auth_cipher_operation( 2558 const uint8_t *auth_tag, unsigned int auth_tag_len, 2559 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2560 const uint8_t *auth_iv, uint8_t auth_iv_len, 2561 unsigned int data_pad_len, 2562 unsigned int cipher_len, unsigned int cipher_offset, 2563 unsigned int auth_len, unsigned int auth_offset, 2564 uint8_t op_mode, uint8_t do_sgl, uint8_t verify) 2565 { 2566 struct crypto_testsuite_params *ts_params = &testsuite_params; 2567 struct crypto_unittest_params *ut_params = &unittest_params; 2568 2569 enum rte_crypto_cipher_algorithm cipher_algo = 2570 ut_params->cipher_xform.cipher.algo; 2571 enum rte_crypto_auth_algorithm auth_algo = 2572 ut_params->auth_xform.auth.algo; 2573 2574 /* Generate Crypto op data structure */ 2575 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2576 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2577 TEST_ASSERT_NOT_NULL(ut_params->op, 2578 "Failed to allocate pktmbuf offload"); 2579 2580 /* Set crypto operation data parameters */ 2581 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2582 2583 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2584 2585 /* set crypto operation mbufs */ 2586 sym_op->m_src = ut_params->ibuf; 2587 if (op_mode == OUT_OF_PLACE) 2588 sym_op->m_dst = ut_params->obuf; 2589 2590 /* digest */ 2591 if (!do_sgl) { 2592 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset( 2593 (op_mode == IN_PLACE ? 2594 ut_params->ibuf : ut_params->obuf), 2595 uint8_t *, data_pad_len); 2596 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2597 (op_mode == IN_PLACE ? 2598 ut_params->ibuf : ut_params->obuf), 2599 data_pad_len); 2600 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2601 } else { 2602 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3); 2603 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ? 2604 sym_op->m_src : sym_op->m_dst); 2605 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) { 2606 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 2607 sgl_buf = sgl_buf->next; 2608 } 2609 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf, 2610 uint8_t *, remaining_off); 2611 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf, 2612 remaining_off); 2613 memset(sym_op->auth.digest.data, 0, remaining_off); 2614 while (sgl_buf->next != NULL) { 2615 memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *), 2616 0, rte_pktmbuf_data_len(sgl_buf)); 2617 sgl_buf = sgl_buf->next; 2618 } 2619 } 2620 2621 /* Copy digest for the verification */ 2622 if (verify) 2623 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2624 2625 /* Copy cipher and auth IVs at the end of the crypto operation */ 2626 uint8_t *iv_ptr = rte_crypto_op_ctod_offset( 2627 ut_params->op, uint8_t *, IV_OFFSET); 2628 2629 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2630 iv_ptr += cipher_iv_len; 2631 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2632 2633 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 2634 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 2635 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 2636 sym_op->cipher.data.length = cipher_len; 2637 sym_op->cipher.data.offset = cipher_offset; 2638 } else { 2639 sym_op->cipher.data.length = cipher_len >> 3; 2640 sym_op->cipher.data.offset = cipher_offset >> 3; 2641 } 2642 2643 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 2644 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 2645 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 2646 sym_op->auth.data.length = auth_len; 2647 sym_op->auth.data.offset = auth_offset; 2648 } else { 2649 sym_op->auth.data.length = auth_len >> 3; 2650 sym_op->auth.data.offset = auth_offset >> 3; 2651 } 2652 2653 return 0; 2654 } 2655 2656 static int 2657 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) 2658 { 2659 struct crypto_testsuite_params *ts_params = &testsuite_params; 2660 struct crypto_unittest_params *ut_params = &unittest_params; 2661 2662 int retval; 2663 unsigned plaintext_pad_len; 2664 unsigned plaintext_len; 2665 uint8_t *plaintext; 2666 struct rte_cryptodev_info dev_info; 2667 2668 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2669 uint64_t feat_flags = dev_info.feature_flags; 2670 2671 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 2672 ((tdata->validAuthLenInBits.len % 8) != 0)) { 2673 printf("Device doesn't support NON-Byte Aligned Data.\n"); 2674 return -ENOTSUP; 2675 } 2676 2677 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 2678 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 2679 printf("Device doesn't support RAW data-path APIs.\n"); 2680 return -ENOTSUP; 2681 } 2682 2683 /* Verify the capabilities */ 2684 struct rte_cryptodev_sym_capability_idx cap_idx; 2685 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2686 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 2687 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2688 &cap_idx) == NULL) 2689 return -ENOTSUP; 2690 2691 /* Create SNOW 3G session */ 2692 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2693 tdata->key.data, tdata->key.len, 2694 tdata->auth_iv.len, tdata->digest.len, 2695 RTE_CRYPTO_AUTH_OP_GENERATE, 2696 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 2697 if (retval < 0) 2698 return retval; 2699 2700 /* alloc mbuf and set payload */ 2701 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2702 2703 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2704 rte_pktmbuf_tailroom(ut_params->ibuf)); 2705 2706 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2707 /* Append data which is padded to a multiple of */ 2708 /* the algorithms block size */ 2709 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2710 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2711 plaintext_pad_len); 2712 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2713 2714 /* Create SNOW 3G operation */ 2715 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 2716 tdata->auth_iv.data, tdata->auth_iv.len, 2717 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 2718 tdata->validAuthLenInBits.len, 2719 0); 2720 if (retval < 0) 2721 return retval; 2722 2723 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2724 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2725 ut_params->op, 0, 1, 1, 0); 2726 else 2727 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2728 ut_params->op); 2729 ut_params->obuf = ut_params->op->sym->m_src; 2730 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2731 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2732 + plaintext_pad_len; 2733 2734 /* Validate obuf */ 2735 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2736 ut_params->digest, 2737 tdata->digest.data, 2738 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 2739 "SNOW 3G Generated auth tag not as expected"); 2740 2741 return 0; 2742 } 2743 2744 static int 2745 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) 2746 { 2747 struct crypto_testsuite_params *ts_params = &testsuite_params; 2748 struct crypto_unittest_params *ut_params = &unittest_params; 2749 2750 int retval; 2751 unsigned plaintext_pad_len; 2752 unsigned plaintext_len; 2753 uint8_t *plaintext; 2754 struct rte_cryptodev_info dev_info; 2755 2756 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2757 uint64_t feat_flags = dev_info.feature_flags; 2758 2759 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 2760 ((tdata->validAuthLenInBits.len % 8) != 0)) { 2761 printf("Device doesn't support NON-Byte Aligned Data.\n"); 2762 return -ENOTSUP; 2763 } 2764 2765 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 2766 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 2767 printf("Device doesn't support RAW data-path APIs.\n"); 2768 return -ENOTSUP; 2769 } 2770 2771 /* Verify the capabilities */ 2772 struct rte_cryptodev_sym_capability_idx cap_idx; 2773 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2774 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 2775 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2776 &cap_idx) == NULL) 2777 return -ENOTSUP; 2778 2779 /* Create SNOW 3G session */ 2780 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2781 tdata->key.data, tdata->key.len, 2782 tdata->auth_iv.len, tdata->digest.len, 2783 RTE_CRYPTO_AUTH_OP_VERIFY, 2784 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 2785 if (retval < 0) 2786 return retval; 2787 /* alloc mbuf and set payload */ 2788 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2789 2790 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2791 rte_pktmbuf_tailroom(ut_params->ibuf)); 2792 2793 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2794 /* Append data which is padded to a multiple of */ 2795 /* the algorithms block size */ 2796 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2797 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2798 plaintext_pad_len); 2799 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2800 2801 /* Create SNOW 3G operation */ 2802 retval = create_wireless_algo_hash_operation(tdata->digest.data, 2803 tdata->digest.len, 2804 tdata->auth_iv.data, tdata->auth_iv.len, 2805 plaintext_pad_len, 2806 RTE_CRYPTO_AUTH_OP_VERIFY, 2807 tdata->validAuthLenInBits.len, 2808 0); 2809 if (retval < 0) 2810 return retval; 2811 2812 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2813 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2814 ut_params->op, 0, 1, 1, 0); 2815 else 2816 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2817 ut_params->op); 2818 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2819 ut_params->obuf = ut_params->op->sym->m_src; 2820 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2821 + plaintext_pad_len; 2822 2823 /* Validate obuf */ 2824 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 2825 return 0; 2826 else 2827 return -1; 2828 2829 return 0; 2830 } 2831 2832 static int 2833 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata) 2834 { 2835 struct crypto_testsuite_params *ts_params = &testsuite_params; 2836 struct crypto_unittest_params *ut_params = &unittest_params; 2837 2838 int retval; 2839 unsigned plaintext_pad_len; 2840 unsigned plaintext_len; 2841 uint8_t *plaintext; 2842 struct rte_cryptodev_info dev_info; 2843 2844 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2845 uint64_t feat_flags = dev_info.feature_flags; 2846 2847 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 2848 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 2849 printf("Device doesn't support RAW data-path APIs.\n"); 2850 return -ENOTSUP; 2851 } 2852 2853 /* Verify the capabilities */ 2854 struct rte_cryptodev_sym_capability_idx cap_idx; 2855 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2856 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 2857 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2858 &cap_idx) == NULL) 2859 return -ENOTSUP; 2860 2861 /* Create KASUMI session */ 2862 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2863 tdata->key.data, tdata->key.len, 2864 0, tdata->digest.len, 2865 RTE_CRYPTO_AUTH_OP_GENERATE, 2866 RTE_CRYPTO_AUTH_KASUMI_F9); 2867 if (retval < 0) 2868 return retval; 2869 2870 /* alloc mbuf and set payload */ 2871 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2872 2873 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2874 rte_pktmbuf_tailroom(ut_params->ibuf)); 2875 2876 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2877 /* Append data which is padded to a multiple of */ 2878 /* the algorithms block size */ 2879 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2880 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2881 plaintext_pad_len); 2882 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2883 2884 /* Create KASUMI operation */ 2885 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 2886 NULL, 0, 2887 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 2888 tdata->plaintext.len, 2889 0); 2890 if (retval < 0) 2891 return retval; 2892 2893 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2894 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2895 ut_params->op); 2896 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2897 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2898 ut_params->op, 0, 1, 1, 0); 2899 else 2900 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2901 ut_params->op); 2902 2903 ut_params->obuf = ut_params->op->sym->m_src; 2904 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2905 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2906 + plaintext_pad_len; 2907 2908 /* Validate obuf */ 2909 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2910 ut_params->digest, 2911 tdata->digest.data, 2912 DIGEST_BYTE_LENGTH_KASUMI_F9, 2913 "KASUMI Generated auth tag not as expected"); 2914 2915 return 0; 2916 } 2917 2918 static int 2919 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata) 2920 { 2921 struct crypto_testsuite_params *ts_params = &testsuite_params; 2922 struct crypto_unittest_params *ut_params = &unittest_params; 2923 2924 int retval; 2925 unsigned plaintext_pad_len; 2926 unsigned plaintext_len; 2927 uint8_t *plaintext; 2928 struct rte_cryptodev_info dev_info; 2929 2930 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2931 uint64_t feat_flags = dev_info.feature_flags; 2932 2933 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 2934 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 2935 printf("Device doesn't support RAW data-path APIs.\n"); 2936 return -ENOTSUP; 2937 } 2938 2939 /* Verify the capabilities */ 2940 struct rte_cryptodev_sym_capability_idx cap_idx; 2941 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2942 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 2943 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2944 &cap_idx) == NULL) 2945 return -ENOTSUP; 2946 2947 /* Create KASUMI session */ 2948 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2949 tdata->key.data, tdata->key.len, 2950 0, tdata->digest.len, 2951 RTE_CRYPTO_AUTH_OP_VERIFY, 2952 RTE_CRYPTO_AUTH_KASUMI_F9); 2953 if (retval < 0) 2954 return retval; 2955 /* alloc mbuf and set payload */ 2956 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2957 2958 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2959 rte_pktmbuf_tailroom(ut_params->ibuf)); 2960 2961 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2962 /* Append data which is padded to a multiple */ 2963 /* of the algorithms block size */ 2964 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2965 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2966 plaintext_pad_len); 2967 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2968 2969 /* Create KASUMI operation */ 2970 retval = create_wireless_algo_hash_operation(tdata->digest.data, 2971 tdata->digest.len, 2972 NULL, 0, 2973 plaintext_pad_len, 2974 RTE_CRYPTO_AUTH_OP_VERIFY, 2975 tdata->plaintext.len, 2976 0); 2977 if (retval < 0) 2978 return retval; 2979 2980 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2981 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2982 ut_params->op, 0, 1, 1, 0); 2983 else 2984 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2985 ut_params->op); 2986 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2987 ut_params->obuf = ut_params->op->sym->m_src; 2988 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2989 + plaintext_pad_len; 2990 2991 /* Validate obuf */ 2992 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 2993 return 0; 2994 else 2995 return -1; 2996 2997 return 0; 2998 } 2999 3000 static int 3001 test_snow3g_hash_generate_test_case_1(void) 3002 { 3003 return test_snow3g_authentication(&snow3g_hash_test_case_1); 3004 } 3005 3006 static int 3007 test_snow3g_hash_generate_test_case_2(void) 3008 { 3009 return test_snow3g_authentication(&snow3g_hash_test_case_2); 3010 } 3011 3012 static int 3013 test_snow3g_hash_generate_test_case_3(void) 3014 { 3015 return test_snow3g_authentication(&snow3g_hash_test_case_3); 3016 } 3017 3018 static int 3019 test_snow3g_hash_generate_test_case_4(void) 3020 { 3021 return test_snow3g_authentication(&snow3g_hash_test_case_4); 3022 } 3023 3024 static int 3025 test_snow3g_hash_generate_test_case_5(void) 3026 { 3027 return test_snow3g_authentication(&snow3g_hash_test_case_5); 3028 } 3029 3030 static int 3031 test_snow3g_hash_generate_test_case_6(void) 3032 { 3033 return test_snow3g_authentication(&snow3g_hash_test_case_6); 3034 } 3035 3036 static int 3037 test_snow3g_hash_verify_test_case_1(void) 3038 { 3039 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1); 3040 3041 } 3042 3043 static int 3044 test_snow3g_hash_verify_test_case_2(void) 3045 { 3046 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2); 3047 } 3048 3049 static int 3050 test_snow3g_hash_verify_test_case_3(void) 3051 { 3052 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3); 3053 } 3054 3055 static int 3056 test_snow3g_hash_verify_test_case_4(void) 3057 { 3058 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4); 3059 } 3060 3061 static int 3062 test_snow3g_hash_verify_test_case_5(void) 3063 { 3064 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5); 3065 } 3066 3067 static int 3068 test_snow3g_hash_verify_test_case_6(void) 3069 { 3070 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6); 3071 } 3072 3073 static int 3074 test_kasumi_hash_generate_test_case_1(void) 3075 { 3076 return test_kasumi_authentication(&kasumi_hash_test_case_1); 3077 } 3078 3079 static int 3080 test_kasumi_hash_generate_test_case_2(void) 3081 { 3082 return test_kasumi_authentication(&kasumi_hash_test_case_2); 3083 } 3084 3085 static int 3086 test_kasumi_hash_generate_test_case_3(void) 3087 { 3088 return test_kasumi_authentication(&kasumi_hash_test_case_3); 3089 } 3090 3091 static int 3092 test_kasumi_hash_generate_test_case_4(void) 3093 { 3094 return test_kasumi_authentication(&kasumi_hash_test_case_4); 3095 } 3096 3097 static int 3098 test_kasumi_hash_generate_test_case_5(void) 3099 { 3100 return test_kasumi_authentication(&kasumi_hash_test_case_5); 3101 } 3102 3103 static int 3104 test_kasumi_hash_generate_test_case_6(void) 3105 { 3106 return test_kasumi_authentication(&kasumi_hash_test_case_6); 3107 } 3108 3109 static int 3110 test_kasumi_hash_verify_test_case_1(void) 3111 { 3112 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1); 3113 } 3114 3115 static int 3116 test_kasumi_hash_verify_test_case_2(void) 3117 { 3118 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2); 3119 } 3120 3121 static int 3122 test_kasumi_hash_verify_test_case_3(void) 3123 { 3124 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3); 3125 } 3126 3127 static int 3128 test_kasumi_hash_verify_test_case_4(void) 3129 { 3130 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4); 3131 } 3132 3133 static int 3134 test_kasumi_hash_verify_test_case_5(void) 3135 { 3136 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5); 3137 } 3138 3139 static int 3140 test_kasumi_encryption(const struct kasumi_test_data *tdata) 3141 { 3142 struct crypto_testsuite_params *ts_params = &testsuite_params; 3143 struct crypto_unittest_params *ut_params = &unittest_params; 3144 3145 int retval; 3146 uint8_t *plaintext, *ciphertext; 3147 unsigned plaintext_pad_len; 3148 unsigned plaintext_len; 3149 struct rte_cryptodev_info dev_info; 3150 3151 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3152 uint64_t feat_flags = dev_info.feature_flags; 3153 3154 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3155 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3156 printf("Device doesn't support RAW data-path APIs.\n"); 3157 return -ENOTSUP; 3158 } 3159 3160 /* Verify the capabilities */ 3161 struct rte_cryptodev_sym_capability_idx cap_idx; 3162 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3163 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3164 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3165 &cap_idx) == NULL) 3166 return -ENOTSUP; 3167 3168 /* Create KASUMI session */ 3169 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3170 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3171 RTE_CRYPTO_CIPHER_KASUMI_F8, 3172 tdata->key.data, tdata->key.len, 3173 tdata->cipher_iv.len); 3174 if (retval < 0) 3175 return retval; 3176 3177 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3178 3179 /* Clear mbuf payload */ 3180 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3181 rte_pktmbuf_tailroom(ut_params->ibuf)); 3182 3183 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3184 /* Append data which is padded to a multiple */ 3185 /* of the algorithms block size */ 3186 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3187 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3188 plaintext_pad_len); 3189 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3190 3191 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3192 3193 /* Create KASUMI operation */ 3194 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3195 tdata->cipher_iv.len, 3196 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3197 tdata->validCipherOffsetInBits.len); 3198 if (retval < 0) 3199 return retval; 3200 3201 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3202 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3203 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3204 else 3205 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3206 ut_params->op); 3207 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3208 3209 ut_params->obuf = ut_params->op->sym->m_dst; 3210 if (ut_params->obuf) 3211 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3212 else 3213 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3214 3215 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3216 3217 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3218 (tdata->validCipherOffsetInBits.len >> 3); 3219 /* Validate obuf */ 3220 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3221 ciphertext, 3222 reference_ciphertext, 3223 tdata->validCipherLenInBits.len, 3224 "KASUMI Ciphertext data not as expected"); 3225 return 0; 3226 } 3227 3228 static int 3229 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata) 3230 { 3231 struct crypto_testsuite_params *ts_params = &testsuite_params; 3232 struct crypto_unittest_params *ut_params = &unittest_params; 3233 3234 int retval; 3235 3236 unsigned int plaintext_pad_len; 3237 unsigned int plaintext_len; 3238 3239 uint8_t buffer[10000]; 3240 const uint8_t *ciphertext; 3241 3242 struct rte_cryptodev_info dev_info; 3243 3244 /* Verify the capabilities */ 3245 struct rte_cryptodev_sym_capability_idx cap_idx; 3246 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3247 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3248 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3249 &cap_idx) == NULL) 3250 return -ENOTSUP; 3251 3252 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3253 3254 uint64_t feat_flags = dev_info.feature_flags; 3255 3256 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 3257 printf("Device doesn't support in-place scatter-gather. " 3258 "Test Skipped.\n"); 3259 return -ENOTSUP; 3260 } 3261 3262 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3263 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3264 printf("Device doesn't support RAW data-path APIs.\n"); 3265 return -ENOTSUP; 3266 } 3267 3268 /* Create KASUMI session */ 3269 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3270 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3271 RTE_CRYPTO_CIPHER_KASUMI_F8, 3272 tdata->key.data, tdata->key.len, 3273 tdata->cipher_iv.len); 3274 if (retval < 0) 3275 return retval; 3276 3277 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3278 3279 3280 /* Append data which is padded to a multiple */ 3281 /* of the algorithms block size */ 3282 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3283 3284 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3285 plaintext_pad_len, 10, 0); 3286 3287 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3288 3289 /* Create KASUMI operation */ 3290 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3291 tdata->cipher_iv.len, 3292 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3293 tdata->validCipherOffsetInBits.len); 3294 if (retval < 0) 3295 return retval; 3296 3297 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3298 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3299 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3300 else 3301 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3302 ut_params->op); 3303 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3304 3305 ut_params->obuf = ut_params->op->sym->m_dst; 3306 3307 if (ut_params->obuf) 3308 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3309 plaintext_len, buffer); 3310 else 3311 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3312 tdata->validCipherOffsetInBits.len >> 3, 3313 plaintext_len, buffer); 3314 3315 /* Validate obuf */ 3316 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3317 3318 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3319 (tdata->validCipherOffsetInBits.len >> 3); 3320 /* Validate obuf */ 3321 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3322 ciphertext, 3323 reference_ciphertext, 3324 tdata->validCipherLenInBits.len, 3325 "KASUMI Ciphertext data not as expected"); 3326 return 0; 3327 } 3328 3329 static int 3330 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata) 3331 { 3332 struct crypto_testsuite_params *ts_params = &testsuite_params; 3333 struct crypto_unittest_params *ut_params = &unittest_params; 3334 3335 int retval; 3336 uint8_t *plaintext, *ciphertext; 3337 unsigned plaintext_pad_len; 3338 unsigned plaintext_len; 3339 3340 /* Verify the capabilities */ 3341 struct rte_cryptodev_sym_capability_idx cap_idx; 3342 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3343 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3344 /* Data-path service does not support OOP */ 3345 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3346 &cap_idx) == NULL) 3347 return -ENOTSUP; 3348 3349 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3350 return -ENOTSUP; 3351 3352 /* Create KASUMI session */ 3353 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3354 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3355 RTE_CRYPTO_CIPHER_KASUMI_F8, 3356 tdata->key.data, tdata->key.len, 3357 tdata->cipher_iv.len); 3358 if (retval < 0) 3359 return retval; 3360 3361 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3362 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3363 3364 /* Clear mbuf payload */ 3365 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3366 rte_pktmbuf_tailroom(ut_params->ibuf)); 3367 3368 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3369 /* Append data which is padded to a multiple */ 3370 /* of the algorithms block size */ 3371 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3372 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3373 plaintext_pad_len); 3374 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3375 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3376 3377 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3378 3379 /* Create KASUMI operation */ 3380 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3381 tdata->cipher_iv.len, 3382 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3383 tdata->validCipherOffsetInBits.len); 3384 if (retval < 0) 3385 return retval; 3386 3387 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3388 ut_params->op); 3389 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3390 3391 ut_params->obuf = ut_params->op->sym->m_dst; 3392 if (ut_params->obuf) 3393 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3394 else 3395 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3396 3397 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3398 3399 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3400 (tdata->validCipherOffsetInBits.len >> 3); 3401 /* Validate obuf */ 3402 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3403 ciphertext, 3404 reference_ciphertext, 3405 tdata->validCipherLenInBits.len, 3406 "KASUMI Ciphertext data not as expected"); 3407 return 0; 3408 } 3409 3410 static int 3411 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata) 3412 { 3413 struct crypto_testsuite_params *ts_params = &testsuite_params; 3414 struct crypto_unittest_params *ut_params = &unittest_params; 3415 3416 int retval; 3417 unsigned int plaintext_pad_len; 3418 unsigned int plaintext_len; 3419 3420 const uint8_t *ciphertext; 3421 uint8_t buffer[2048]; 3422 3423 struct rte_cryptodev_info dev_info; 3424 3425 /* Verify the capabilities */ 3426 struct rte_cryptodev_sym_capability_idx cap_idx; 3427 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3428 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3429 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3430 &cap_idx) == NULL) 3431 return -ENOTSUP; 3432 3433 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3434 return -ENOTSUP; 3435 3436 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3437 3438 uint64_t feat_flags = dev_info.feature_flags; 3439 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 3440 printf("Device doesn't support out-of-place scatter-gather " 3441 "in both input and output mbufs. " 3442 "Test Skipped.\n"); 3443 return -ENOTSUP; 3444 } 3445 3446 /* Create KASUMI session */ 3447 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3448 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3449 RTE_CRYPTO_CIPHER_KASUMI_F8, 3450 tdata->key.data, tdata->key.len, 3451 tdata->cipher_iv.len); 3452 if (retval < 0) 3453 return retval; 3454 3455 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3456 /* Append data which is padded to a multiple */ 3457 /* of the algorithms block size */ 3458 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3459 3460 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3461 plaintext_pad_len, 10, 0); 3462 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 3463 plaintext_pad_len, 3, 0); 3464 3465 /* Append data which is padded to a multiple */ 3466 /* of the algorithms block size */ 3467 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3468 3469 /* Create KASUMI operation */ 3470 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3471 tdata->cipher_iv.len, 3472 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3473 tdata->validCipherOffsetInBits.len); 3474 if (retval < 0) 3475 return retval; 3476 3477 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3478 ut_params->op); 3479 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3480 3481 ut_params->obuf = ut_params->op->sym->m_dst; 3482 if (ut_params->obuf) 3483 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3484 plaintext_pad_len, buffer); 3485 else 3486 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3487 tdata->validCipherOffsetInBits.len >> 3, 3488 plaintext_pad_len, buffer); 3489 3490 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3491 (tdata->validCipherOffsetInBits.len >> 3); 3492 /* Validate obuf */ 3493 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3494 ciphertext, 3495 reference_ciphertext, 3496 tdata->validCipherLenInBits.len, 3497 "KASUMI Ciphertext data not as expected"); 3498 return 0; 3499 } 3500 3501 3502 static int 3503 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata) 3504 { 3505 struct crypto_testsuite_params *ts_params = &testsuite_params; 3506 struct crypto_unittest_params *ut_params = &unittest_params; 3507 3508 int retval; 3509 uint8_t *ciphertext, *plaintext; 3510 unsigned ciphertext_pad_len; 3511 unsigned ciphertext_len; 3512 3513 /* Verify the capabilities */ 3514 struct rte_cryptodev_sym_capability_idx cap_idx; 3515 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3516 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3517 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3518 &cap_idx) == NULL) 3519 return -ENOTSUP; 3520 3521 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3522 return -ENOTSUP; 3523 3524 /* Create KASUMI session */ 3525 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3526 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3527 RTE_CRYPTO_CIPHER_KASUMI_F8, 3528 tdata->key.data, tdata->key.len, 3529 tdata->cipher_iv.len); 3530 if (retval < 0) 3531 return retval; 3532 3533 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3534 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3535 3536 /* Clear mbuf payload */ 3537 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3538 rte_pktmbuf_tailroom(ut_params->ibuf)); 3539 3540 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 3541 /* Append data which is padded to a multiple */ 3542 /* of the algorithms block size */ 3543 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 3544 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3545 ciphertext_pad_len); 3546 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 3547 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 3548 3549 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 3550 3551 /* Create KASUMI operation */ 3552 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3553 tdata->cipher_iv.len, 3554 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3555 tdata->validCipherOffsetInBits.len); 3556 if (retval < 0) 3557 return retval; 3558 3559 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3560 ut_params->op); 3561 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3562 3563 ut_params->obuf = ut_params->op->sym->m_dst; 3564 if (ut_params->obuf) 3565 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3566 else 3567 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 3568 3569 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 3570 3571 const uint8_t *reference_plaintext = tdata->plaintext.data + 3572 (tdata->validCipherOffsetInBits.len >> 3); 3573 /* Validate obuf */ 3574 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3575 plaintext, 3576 reference_plaintext, 3577 tdata->validCipherLenInBits.len, 3578 "KASUMI Plaintext data not as expected"); 3579 return 0; 3580 } 3581 3582 static int 3583 test_kasumi_decryption(const struct kasumi_test_data *tdata) 3584 { 3585 struct crypto_testsuite_params *ts_params = &testsuite_params; 3586 struct crypto_unittest_params *ut_params = &unittest_params; 3587 3588 int retval; 3589 uint8_t *ciphertext, *plaintext; 3590 unsigned ciphertext_pad_len; 3591 unsigned ciphertext_len; 3592 struct rte_cryptodev_info dev_info; 3593 3594 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3595 uint64_t feat_flags = dev_info.feature_flags; 3596 3597 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3598 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3599 printf("Device doesn't support RAW data-path APIs.\n"); 3600 return -ENOTSUP; 3601 } 3602 3603 /* Verify the capabilities */ 3604 struct rte_cryptodev_sym_capability_idx cap_idx; 3605 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3606 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3607 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3608 &cap_idx) == NULL) 3609 return -ENOTSUP; 3610 3611 /* Create KASUMI session */ 3612 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3613 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3614 RTE_CRYPTO_CIPHER_KASUMI_F8, 3615 tdata->key.data, tdata->key.len, 3616 tdata->cipher_iv.len); 3617 if (retval < 0) 3618 return retval; 3619 3620 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3621 3622 /* Clear mbuf payload */ 3623 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3624 rte_pktmbuf_tailroom(ut_params->ibuf)); 3625 3626 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 3627 /* Append data which is padded to a multiple */ 3628 /* of the algorithms block size */ 3629 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 3630 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3631 ciphertext_pad_len); 3632 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 3633 3634 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 3635 3636 /* Create KASUMI operation */ 3637 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3638 tdata->cipher_iv.len, 3639 tdata->ciphertext.len, 3640 tdata->validCipherOffsetInBits.len); 3641 if (retval < 0) 3642 return retval; 3643 3644 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3645 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3646 ut_params->op, 1, 0, 1, 0); 3647 else 3648 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3649 ut_params->op); 3650 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3651 3652 ut_params->obuf = ut_params->op->sym->m_dst; 3653 if (ut_params->obuf) 3654 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3655 else 3656 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 3657 3658 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 3659 3660 const uint8_t *reference_plaintext = tdata->plaintext.data + 3661 (tdata->validCipherOffsetInBits.len >> 3); 3662 /* Validate obuf */ 3663 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3664 plaintext, 3665 reference_plaintext, 3666 tdata->validCipherLenInBits.len, 3667 "KASUMI Plaintext data not as expected"); 3668 return 0; 3669 } 3670 3671 static int 3672 test_snow3g_encryption(const struct snow3g_test_data *tdata) 3673 { 3674 struct crypto_testsuite_params *ts_params = &testsuite_params; 3675 struct crypto_unittest_params *ut_params = &unittest_params; 3676 3677 int retval; 3678 uint8_t *plaintext, *ciphertext; 3679 unsigned plaintext_pad_len; 3680 unsigned plaintext_len; 3681 struct rte_cryptodev_info dev_info; 3682 3683 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3684 uint64_t feat_flags = dev_info.feature_flags; 3685 3686 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3687 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3688 printf("Device doesn't support RAW data-path APIs.\n"); 3689 return -ENOTSUP; 3690 } 3691 3692 /* Verify the capabilities */ 3693 struct rte_cryptodev_sym_capability_idx cap_idx; 3694 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3695 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3696 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3697 &cap_idx) == NULL) 3698 return -ENOTSUP; 3699 3700 /* Create SNOW 3G session */ 3701 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3702 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3703 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3704 tdata->key.data, tdata->key.len, 3705 tdata->cipher_iv.len); 3706 if (retval < 0) 3707 return retval; 3708 3709 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3710 3711 /* Clear mbuf payload */ 3712 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3713 rte_pktmbuf_tailroom(ut_params->ibuf)); 3714 3715 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3716 /* Append data which is padded to a multiple of */ 3717 /* the algorithms block size */ 3718 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3719 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3720 plaintext_pad_len); 3721 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3722 3723 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3724 3725 /* Create SNOW 3G operation */ 3726 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3727 tdata->cipher_iv.len, 3728 tdata->validCipherLenInBits.len, 3729 0); 3730 if (retval < 0) 3731 return retval; 3732 3733 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3734 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3735 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3736 else 3737 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3738 ut_params->op); 3739 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3740 3741 ut_params->obuf = ut_params->op->sym->m_dst; 3742 if (ut_params->obuf) 3743 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3744 else 3745 ciphertext = plaintext; 3746 3747 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3748 3749 /* Validate obuf */ 3750 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3751 ciphertext, 3752 tdata->ciphertext.data, 3753 tdata->validDataLenInBits.len, 3754 "SNOW 3G Ciphertext data not as expected"); 3755 return 0; 3756 } 3757 3758 3759 static int 3760 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) 3761 { 3762 struct crypto_testsuite_params *ts_params = &testsuite_params; 3763 struct crypto_unittest_params *ut_params = &unittest_params; 3764 uint8_t *plaintext, *ciphertext; 3765 3766 int retval; 3767 unsigned plaintext_pad_len; 3768 unsigned plaintext_len; 3769 3770 /* Verify the capabilities */ 3771 struct rte_cryptodev_sym_capability_idx cap_idx; 3772 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3773 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3774 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3775 &cap_idx) == NULL) 3776 return -ENOTSUP; 3777 3778 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3779 return -ENOTSUP; 3780 3781 /* Create SNOW 3G session */ 3782 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3783 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3784 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3785 tdata->key.data, tdata->key.len, 3786 tdata->cipher_iv.len); 3787 if (retval < 0) 3788 return retval; 3789 3790 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3791 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3792 3793 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 3794 "Failed to allocate input buffer in mempool"); 3795 TEST_ASSERT_NOT_NULL(ut_params->obuf, 3796 "Failed to allocate output buffer in mempool"); 3797 3798 /* Clear mbuf payload */ 3799 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3800 rte_pktmbuf_tailroom(ut_params->ibuf)); 3801 3802 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3803 /* Append data which is padded to a multiple of */ 3804 /* the algorithms block size */ 3805 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3806 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3807 plaintext_pad_len); 3808 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3809 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3810 3811 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3812 3813 /* Create SNOW 3G operation */ 3814 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3815 tdata->cipher_iv.len, 3816 tdata->validCipherLenInBits.len, 3817 0); 3818 if (retval < 0) 3819 return retval; 3820 3821 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3822 ut_params->op); 3823 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3824 3825 ut_params->obuf = ut_params->op->sym->m_dst; 3826 if (ut_params->obuf) 3827 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3828 else 3829 ciphertext = plaintext; 3830 3831 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3832 3833 /* Validate obuf */ 3834 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3835 ciphertext, 3836 tdata->ciphertext.data, 3837 tdata->validDataLenInBits.len, 3838 "SNOW 3G Ciphertext data not as expected"); 3839 return 0; 3840 } 3841 3842 static int 3843 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata) 3844 { 3845 struct crypto_testsuite_params *ts_params = &testsuite_params; 3846 struct crypto_unittest_params *ut_params = &unittest_params; 3847 3848 int retval; 3849 unsigned int plaintext_pad_len; 3850 unsigned int plaintext_len; 3851 uint8_t buffer[10000]; 3852 const uint8_t *ciphertext; 3853 3854 struct rte_cryptodev_info dev_info; 3855 3856 /* Verify the capabilities */ 3857 struct rte_cryptodev_sym_capability_idx cap_idx; 3858 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3859 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3860 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3861 &cap_idx) == NULL) 3862 return -ENOTSUP; 3863 3864 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3865 return -ENOTSUP; 3866 3867 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3868 3869 uint64_t feat_flags = dev_info.feature_flags; 3870 3871 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 3872 printf("Device doesn't support out-of-place scatter-gather " 3873 "in both input and output mbufs. " 3874 "Test Skipped.\n"); 3875 return -ENOTSUP; 3876 } 3877 3878 /* Create SNOW 3G session */ 3879 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3880 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3881 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3882 tdata->key.data, tdata->key.len, 3883 tdata->cipher_iv.len); 3884 if (retval < 0) 3885 return retval; 3886 3887 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3888 /* Append data which is padded to a multiple of */ 3889 /* the algorithms block size */ 3890 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3891 3892 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3893 plaintext_pad_len, 10, 0); 3894 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 3895 plaintext_pad_len, 3, 0); 3896 3897 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 3898 "Failed to allocate input buffer in mempool"); 3899 TEST_ASSERT_NOT_NULL(ut_params->obuf, 3900 "Failed to allocate output buffer in mempool"); 3901 3902 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3903 3904 /* Create SNOW 3G operation */ 3905 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3906 tdata->cipher_iv.len, 3907 tdata->validCipherLenInBits.len, 3908 0); 3909 if (retval < 0) 3910 return retval; 3911 3912 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3913 ut_params->op); 3914 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3915 3916 ut_params->obuf = ut_params->op->sym->m_dst; 3917 if (ut_params->obuf) 3918 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3919 plaintext_len, buffer); 3920 else 3921 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 3922 plaintext_len, buffer); 3923 3924 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3925 3926 /* Validate obuf */ 3927 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3928 ciphertext, 3929 tdata->ciphertext.data, 3930 tdata->validDataLenInBits.len, 3931 "SNOW 3G Ciphertext data not as expected"); 3932 3933 return 0; 3934 } 3935 3936 /* Shift right a buffer by "offset" bits, "offset" < 8 */ 3937 static void 3938 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) 3939 { 3940 uint8_t curr_byte, prev_byte; 3941 uint32_t length_in_bytes = ceil_byte_length(length + offset); 3942 uint8_t lower_byte_mask = (1 << offset) - 1; 3943 unsigned i; 3944 3945 prev_byte = buffer[0]; 3946 buffer[0] >>= offset; 3947 3948 for (i = 1; i < length_in_bytes; i++) { 3949 curr_byte = buffer[i]; 3950 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | 3951 (curr_byte >> offset); 3952 prev_byte = curr_byte; 3953 } 3954 } 3955 3956 static int 3957 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) 3958 { 3959 struct crypto_testsuite_params *ts_params = &testsuite_params; 3960 struct crypto_unittest_params *ut_params = &unittest_params; 3961 uint8_t *plaintext, *ciphertext; 3962 int retval; 3963 uint32_t plaintext_len; 3964 uint32_t plaintext_pad_len; 3965 uint8_t extra_offset = 4; 3966 uint8_t *expected_ciphertext_shifted; 3967 struct rte_cryptodev_info dev_info; 3968 3969 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3970 uint64_t feat_flags = dev_info.feature_flags; 3971 3972 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 3973 ((tdata->validDataLenInBits.len % 8) != 0)) { 3974 printf("Device doesn't support NON-Byte Aligned Data.\n"); 3975 return -ENOTSUP; 3976 } 3977 3978 /* Verify the capabilities */ 3979 struct rte_cryptodev_sym_capability_idx cap_idx; 3980 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3981 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3982 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3983 &cap_idx) == NULL) 3984 return -ENOTSUP; 3985 3986 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3987 return -ENOTSUP; 3988 3989 /* Create SNOW 3G session */ 3990 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3991 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3992 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3993 tdata->key.data, tdata->key.len, 3994 tdata->cipher_iv.len); 3995 if (retval < 0) 3996 return retval; 3997 3998 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3999 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4000 4001 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4002 "Failed to allocate input buffer in mempool"); 4003 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4004 "Failed to allocate output buffer in mempool"); 4005 4006 /* Clear mbuf payload */ 4007 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4008 rte_pktmbuf_tailroom(ut_params->ibuf)); 4009 4010 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset); 4011 /* 4012 * Append data which is padded to a 4013 * multiple of the algorithms block size 4014 */ 4015 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4016 4017 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, 4018 plaintext_pad_len); 4019 4020 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4021 4022 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); 4023 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); 4024 4025 #ifdef RTE_APP_TEST_DEBUG 4026 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); 4027 #endif 4028 /* Create SNOW 3G operation */ 4029 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4030 tdata->cipher_iv.len, 4031 tdata->validCipherLenInBits.len, 4032 extra_offset); 4033 if (retval < 0) 4034 return retval; 4035 4036 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4037 ut_params->op); 4038 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4039 4040 ut_params->obuf = ut_params->op->sym->m_dst; 4041 if (ut_params->obuf) 4042 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4043 else 4044 ciphertext = plaintext; 4045 4046 #ifdef RTE_APP_TEST_DEBUG 4047 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4048 #endif 4049 4050 expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8); 4051 4052 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, 4053 "failed to reserve memory for ciphertext shifted\n"); 4054 4055 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, 4056 ceil_byte_length(tdata->ciphertext.len)); 4057 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, 4058 extra_offset); 4059 /* Validate obuf */ 4060 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4061 ciphertext, 4062 expected_ciphertext_shifted, 4063 tdata->validDataLenInBits.len, 4064 extra_offset, 4065 "SNOW 3G Ciphertext data not as expected"); 4066 return 0; 4067 } 4068 4069 static int test_snow3g_decryption(const struct snow3g_test_data *tdata) 4070 { 4071 struct crypto_testsuite_params *ts_params = &testsuite_params; 4072 struct crypto_unittest_params *ut_params = &unittest_params; 4073 4074 int retval; 4075 4076 uint8_t *plaintext, *ciphertext; 4077 unsigned ciphertext_pad_len; 4078 unsigned ciphertext_len; 4079 struct rte_cryptodev_info dev_info; 4080 4081 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4082 uint64_t feat_flags = dev_info.feature_flags; 4083 4084 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4085 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4086 printf("Device doesn't support RAW data-path APIs.\n"); 4087 return -ENOTSUP; 4088 } 4089 4090 /* Verify the capabilities */ 4091 struct rte_cryptodev_sym_capability_idx cap_idx; 4092 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4093 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4094 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4095 &cap_idx) == NULL) 4096 return -ENOTSUP; 4097 4098 /* Create SNOW 3G session */ 4099 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4100 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4101 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4102 tdata->key.data, tdata->key.len, 4103 tdata->cipher_iv.len); 4104 if (retval < 0) 4105 return retval; 4106 4107 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4108 4109 /* Clear mbuf payload */ 4110 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4111 rte_pktmbuf_tailroom(ut_params->ibuf)); 4112 4113 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4114 /* Append data which is padded to a multiple of */ 4115 /* the algorithms block size */ 4116 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4117 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4118 ciphertext_pad_len); 4119 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4120 4121 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4122 4123 /* Create SNOW 3G operation */ 4124 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4125 tdata->cipher_iv.len, 4126 tdata->validCipherLenInBits.len, 4127 tdata->cipher.offset_bits); 4128 if (retval < 0) 4129 return retval; 4130 4131 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4132 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4133 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4134 else 4135 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4136 ut_params->op); 4137 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4138 ut_params->obuf = ut_params->op->sym->m_dst; 4139 if (ut_params->obuf) 4140 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4141 else 4142 plaintext = ciphertext; 4143 4144 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4145 4146 /* Validate obuf */ 4147 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4148 tdata->plaintext.data, 4149 tdata->validDataLenInBits.len, 4150 "SNOW 3G Plaintext data not as expected"); 4151 return 0; 4152 } 4153 4154 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) 4155 { 4156 struct crypto_testsuite_params *ts_params = &testsuite_params; 4157 struct crypto_unittest_params *ut_params = &unittest_params; 4158 4159 int retval; 4160 4161 uint8_t *plaintext, *ciphertext; 4162 unsigned ciphertext_pad_len; 4163 unsigned ciphertext_len; 4164 4165 /* Verify the capabilities */ 4166 struct rte_cryptodev_sym_capability_idx cap_idx; 4167 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4168 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4169 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4170 &cap_idx) == NULL) 4171 return -ENOTSUP; 4172 4173 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4174 return -ENOTSUP; 4175 4176 /* Create SNOW 3G session */ 4177 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4178 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4179 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4180 tdata->key.data, tdata->key.len, 4181 tdata->cipher_iv.len); 4182 if (retval < 0) 4183 return retval; 4184 4185 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4186 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4187 4188 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4189 "Failed to allocate input buffer"); 4190 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4191 "Failed to allocate output buffer"); 4192 4193 /* Clear mbuf payload */ 4194 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4195 rte_pktmbuf_tailroom(ut_params->ibuf)); 4196 4197 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4198 rte_pktmbuf_tailroom(ut_params->obuf)); 4199 4200 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4201 /* Append data which is padded to a multiple of */ 4202 /* the algorithms block size */ 4203 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4204 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4205 ciphertext_pad_len); 4206 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4207 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4208 4209 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4210 4211 /* Create SNOW 3G operation */ 4212 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4213 tdata->cipher_iv.len, 4214 tdata->validCipherLenInBits.len, 4215 0); 4216 if (retval < 0) 4217 return retval; 4218 4219 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4220 ut_params->op); 4221 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4222 ut_params->obuf = ut_params->op->sym->m_dst; 4223 if (ut_params->obuf) 4224 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4225 else 4226 plaintext = ciphertext; 4227 4228 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4229 4230 /* Validate obuf */ 4231 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4232 tdata->plaintext.data, 4233 tdata->validDataLenInBits.len, 4234 "SNOW 3G Plaintext data not as expected"); 4235 return 0; 4236 } 4237 4238 static int 4239 test_zuc_cipher_auth(const struct wireless_test_data *tdata) 4240 { 4241 struct crypto_testsuite_params *ts_params = &testsuite_params; 4242 struct crypto_unittest_params *ut_params = &unittest_params; 4243 4244 int retval; 4245 4246 uint8_t *plaintext, *ciphertext; 4247 unsigned int plaintext_pad_len; 4248 unsigned int plaintext_len; 4249 4250 struct rte_cryptodev_info dev_info; 4251 struct rte_cryptodev_sym_capability_idx cap_idx; 4252 4253 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4254 uint64_t feat_flags = dev_info.feature_flags; 4255 4256 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4257 ((tdata->validAuthLenInBits.len % 8 != 0) || 4258 (tdata->validDataLenInBits.len % 8 != 0))) { 4259 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4260 return -ENOTSUP; 4261 } 4262 4263 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4264 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4265 printf("Device doesn't support RAW data-path APIs.\n"); 4266 return -ENOTSUP; 4267 } 4268 4269 /* Check if device supports ZUC EEA3 */ 4270 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4271 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 4272 4273 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4274 &cap_idx) == NULL) 4275 return -ENOTSUP; 4276 4277 /* Check if device supports ZUC EIA3 */ 4278 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4279 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 4280 4281 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4282 &cap_idx) == NULL) 4283 return -ENOTSUP; 4284 4285 /* Create ZUC session */ 4286 retval = create_zuc_cipher_auth_encrypt_generate_session( 4287 ts_params->valid_devs[0], 4288 tdata); 4289 if (retval < 0) 4290 return retval; 4291 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4292 4293 /* clear mbuf payload */ 4294 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4295 rte_pktmbuf_tailroom(ut_params->ibuf)); 4296 4297 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4298 /* Append data which is padded to a multiple of */ 4299 /* the algorithms block size */ 4300 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4301 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4302 plaintext_pad_len); 4303 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4304 4305 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4306 4307 /* Create ZUC operation */ 4308 retval = create_zuc_cipher_hash_generate_operation(tdata); 4309 if (retval < 0) 4310 return retval; 4311 4312 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4313 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4314 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4315 else 4316 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4317 ut_params->op); 4318 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4319 ut_params->obuf = ut_params->op->sym->m_src; 4320 if (ut_params->obuf) 4321 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4322 else 4323 ciphertext = plaintext; 4324 4325 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4326 /* Validate obuf */ 4327 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4328 ciphertext, 4329 tdata->ciphertext.data, 4330 tdata->validDataLenInBits.len, 4331 "ZUC Ciphertext data not as expected"); 4332 4333 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4334 + plaintext_pad_len; 4335 4336 /* Validate obuf */ 4337 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4338 ut_params->digest, 4339 tdata->digest.data, 4340 4, 4341 "ZUC Generated auth tag not as expected"); 4342 return 0; 4343 } 4344 4345 static int 4346 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) 4347 { 4348 struct crypto_testsuite_params *ts_params = &testsuite_params; 4349 struct crypto_unittest_params *ut_params = &unittest_params; 4350 4351 int retval; 4352 4353 uint8_t *plaintext, *ciphertext; 4354 unsigned plaintext_pad_len; 4355 unsigned plaintext_len; 4356 struct rte_cryptodev_info dev_info; 4357 4358 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4359 uint64_t feat_flags = dev_info.feature_flags; 4360 4361 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4362 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4363 printf("Device doesn't support RAW data-path APIs.\n"); 4364 return -ENOTSUP; 4365 } 4366 4367 /* Verify the capabilities */ 4368 struct rte_cryptodev_sym_capability_idx cap_idx; 4369 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4370 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4371 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4372 &cap_idx) == NULL) 4373 return -ENOTSUP; 4374 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4375 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4376 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4377 &cap_idx) == NULL) 4378 return -ENOTSUP; 4379 4380 /* Create SNOW 3G session */ 4381 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0], 4382 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4383 RTE_CRYPTO_AUTH_OP_GENERATE, 4384 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4385 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4386 tdata->key.data, tdata->key.len, 4387 tdata->auth_iv.len, tdata->digest.len, 4388 tdata->cipher_iv.len); 4389 if (retval < 0) 4390 return retval; 4391 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4392 4393 /* clear mbuf payload */ 4394 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4395 rte_pktmbuf_tailroom(ut_params->ibuf)); 4396 4397 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4398 /* Append data which is padded to a multiple of */ 4399 /* the algorithms block size */ 4400 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4401 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4402 plaintext_pad_len); 4403 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4404 4405 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4406 4407 /* Create SNOW 3G operation */ 4408 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 4409 tdata->digest.len, tdata->auth_iv.data, 4410 tdata->auth_iv.len, 4411 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 4412 tdata->cipher_iv.data, tdata->cipher_iv.len, 4413 tdata->validCipherLenInBits.len, 4414 0, 4415 tdata->validAuthLenInBits.len, 4416 0 4417 ); 4418 if (retval < 0) 4419 return retval; 4420 4421 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4422 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4423 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4424 else 4425 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4426 ut_params->op); 4427 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4428 ut_params->obuf = ut_params->op->sym->m_src; 4429 if (ut_params->obuf) 4430 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4431 else 4432 ciphertext = plaintext; 4433 4434 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4435 /* Validate obuf */ 4436 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4437 ciphertext, 4438 tdata->ciphertext.data, 4439 tdata->validDataLenInBits.len, 4440 "SNOW 3G Ciphertext data not as expected"); 4441 4442 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4443 + plaintext_pad_len; 4444 4445 /* Validate obuf */ 4446 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4447 ut_params->digest, 4448 tdata->digest.data, 4449 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4450 "SNOW 3G Generated auth tag not as expected"); 4451 return 0; 4452 } 4453 4454 static int 4455 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata, 4456 uint8_t op_mode, uint8_t verify) 4457 { 4458 struct crypto_testsuite_params *ts_params = &testsuite_params; 4459 struct crypto_unittest_params *ut_params = &unittest_params; 4460 4461 int retval; 4462 4463 uint8_t *plaintext = NULL, *ciphertext = NULL; 4464 unsigned int plaintext_pad_len; 4465 unsigned int plaintext_len; 4466 unsigned int ciphertext_pad_len; 4467 unsigned int ciphertext_len; 4468 4469 struct rte_cryptodev_info dev_info; 4470 4471 /* Verify the capabilities */ 4472 struct rte_cryptodev_sym_capability_idx cap_idx; 4473 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4474 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4475 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4476 &cap_idx) == NULL) 4477 return -ENOTSUP; 4478 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4479 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4480 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4481 &cap_idx) == NULL) 4482 return -ENOTSUP; 4483 4484 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4485 4486 uint64_t feat_flags = dev_info.feature_flags; 4487 4488 if (op_mode == OUT_OF_PLACE) { 4489 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 4490 printf("Device doesn't support digest encrypted.\n"); 4491 return -ENOTSUP; 4492 } 4493 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4494 return -ENOTSUP; 4495 } 4496 4497 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4498 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4499 printf("Device doesn't support RAW data-path APIs.\n"); 4500 return -ENOTSUP; 4501 } 4502 4503 /* Create SNOW 3G session */ 4504 retval = create_wireless_algo_auth_cipher_session( 4505 ts_params->valid_devs[0], 4506 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 4507 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 4508 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 4509 : RTE_CRYPTO_AUTH_OP_GENERATE), 4510 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4511 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4512 tdata->key.data, tdata->key.len, 4513 tdata->auth_iv.len, tdata->digest.len, 4514 tdata->cipher_iv.len); 4515 4516 if (retval < 0) 4517 return retval; 4518 4519 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4520 if (op_mode == OUT_OF_PLACE) 4521 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4522 4523 /* clear mbuf payload */ 4524 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4525 rte_pktmbuf_tailroom(ut_params->ibuf)); 4526 if (op_mode == OUT_OF_PLACE) 4527 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4528 rte_pktmbuf_tailroom(ut_params->obuf)); 4529 4530 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4531 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4532 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4533 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4534 4535 if (verify) { 4536 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4537 ciphertext_pad_len); 4538 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4539 if (op_mode == OUT_OF_PLACE) 4540 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4541 debug_hexdump(stdout, "ciphertext:", ciphertext, 4542 ciphertext_len); 4543 } else { 4544 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4545 plaintext_pad_len); 4546 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4547 if (op_mode == OUT_OF_PLACE) 4548 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4549 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4550 } 4551 4552 /* Create SNOW 3G operation */ 4553 retval = create_wireless_algo_auth_cipher_operation( 4554 tdata->digest.data, tdata->digest.len, 4555 tdata->cipher_iv.data, tdata->cipher_iv.len, 4556 tdata->auth_iv.data, tdata->auth_iv.len, 4557 (tdata->digest.offset_bytes == 0 ? 4558 (verify ? ciphertext_pad_len : plaintext_pad_len) 4559 : tdata->digest.offset_bytes), 4560 tdata->validCipherLenInBits.len, 4561 tdata->cipher.offset_bits, 4562 tdata->validAuthLenInBits.len, 4563 tdata->auth.offset_bits, 4564 op_mode, 0, verify); 4565 4566 if (retval < 0) 4567 return retval; 4568 4569 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4570 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4571 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4572 else 4573 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4574 ut_params->op); 4575 4576 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4577 4578 ut_params->obuf = (op_mode == IN_PLACE ? 4579 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 4580 4581 if (verify) { 4582 if (ut_params->obuf) 4583 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 4584 uint8_t *); 4585 else 4586 plaintext = ciphertext + 4587 (tdata->cipher.offset_bits >> 3); 4588 4589 debug_hexdump(stdout, "plaintext:", plaintext, 4590 (tdata->plaintext.len >> 3) - tdata->digest.len); 4591 debug_hexdump(stdout, "plaintext expected:", 4592 tdata->plaintext.data, 4593 (tdata->plaintext.len >> 3) - tdata->digest.len); 4594 } else { 4595 if (ut_params->obuf) 4596 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 4597 uint8_t *); 4598 else 4599 ciphertext = plaintext; 4600 4601 debug_hexdump(stdout, "ciphertext:", ciphertext, 4602 ciphertext_len); 4603 debug_hexdump(stdout, "ciphertext expected:", 4604 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 4605 4606 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4607 + (tdata->digest.offset_bytes == 0 ? 4608 plaintext_pad_len : tdata->digest.offset_bytes); 4609 4610 debug_hexdump(stdout, "digest:", ut_params->digest, 4611 tdata->digest.len); 4612 debug_hexdump(stdout, "digest expected:", tdata->digest.data, 4613 tdata->digest.len); 4614 } 4615 4616 /* Validate obuf */ 4617 if (verify) { 4618 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4619 plaintext, 4620 tdata->plaintext.data, 4621 tdata->plaintext.len >> 3, 4622 "SNOW 3G Plaintext data not as expected"); 4623 } else { 4624 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4625 ciphertext, 4626 tdata->ciphertext.data, 4627 tdata->validDataLenInBits.len, 4628 "SNOW 3G Ciphertext data not as expected"); 4629 4630 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4631 ut_params->digest, 4632 tdata->digest.data, 4633 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4634 "SNOW 3G Generated auth tag not as expected"); 4635 } 4636 return 0; 4637 } 4638 4639 static int 4640 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata, 4641 uint8_t op_mode, uint8_t verify) 4642 { 4643 struct crypto_testsuite_params *ts_params = &testsuite_params; 4644 struct crypto_unittest_params *ut_params = &unittest_params; 4645 4646 int retval; 4647 4648 const uint8_t *plaintext = NULL; 4649 const uint8_t *ciphertext = NULL; 4650 const uint8_t *digest = NULL; 4651 unsigned int plaintext_pad_len; 4652 unsigned int plaintext_len; 4653 unsigned int ciphertext_pad_len; 4654 unsigned int ciphertext_len; 4655 uint8_t buffer[10000]; 4656 uint8_t digest_buffer[10000]; 4657 4658 struct rte_cryptodev_info dev_info; 4659 4660 /* Verify the capabilities */ 4661 struct rte_cryptodev_sym_capability_idx cap_idx; 4662 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4663 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4664 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4665 &cap_idx) == NULL) 4666 return -ENOTSUP; 4667 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4668 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4669 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4670 &cap_idx) == NULL) 4671 return -ENOTSUP; 4672 4673 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4674 4675 uint64_t feat_flags = dev_info.feature_flags; 4676 4677 if (op_mode == IN_PLACE) { 4678 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 4679 printf("Device doesn't support in-place scatter-gather " 4680 "in both input and output mbufs.\n"); 4681 return -ENOTSUP; 4682 } 4683 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4684 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4685 printf("Device doesn't support RAW data-path APIs.\n"); 4686 return -ENOTSUP; 4687 } 4688 } else { 4689 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4690 return -ENOTSUP; 4691 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 4692 printf("Device doesn't support out-of-place scatter-gather " 4693 "in both input and output mbufs.\n"); 4694 return -ENOTSUP; 4695 } 4696 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 4697 printf("Device doesn't support digest encrypted.\n"); 4698 return -ENOTSUP; 4699 } 4700 } 4701 4702 /* Create SNOW 3G session */ 4703 retval = create_wireless_algo_auth_cipher_session( 4704 ts_params->valid_devs[0], 4705 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 4706 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 4707 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 4708 : RTE_CRYPTO_AUTH_OP_GENERATE), 4709 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4710 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4711 tdata->key.data, tdata->key.len, 4712 tdata->auth_iv.len, tdata->digest.len, 4713 tdata->cipher_iv.len); 4714 4715 if (retval < 0) 4716 return retval; 4717 4718 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4719 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4720 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4721 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4722 4723 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4724 plaintext_pad_len, 15, 0); 4725 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4726 "Failed to allocate input buffer in mempool"); 4727 4728 if (op_mode == OUT_OF_PLACE) { 4729 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4730 plaintext_pad_len, 15, 0); 4731 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4732 "Failed to allocate output buffer in mempool"); 4733 } 4734 4735 if (verify) { 4736 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 4737 tdata->ciphertext.data); 4738 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4739 ciphertext_len, buffer); 4740 debug_hexdump(stdout, "ciphertext:", ciphertext, 4741 ciphertext_len); 4742 } else { 4743 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 4744 tdata->plaintext.data); 4745 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 4746 plaintext_len, buffer); 4747 debug_hexdump(stdout, "plaintext:", plaintext, 4748 plaintext_len); 4749 } 4750 memset(buffer, 0, sizeof(buffer)); 4751 4752 /* Create SNOW 3G operation */ 4753 retval = create_wireless_algo_auth_cipher_operation( 4754 tdata->digest.data, tdata->digest.len, 4755 tdata->cipher_iv.data, tdata->cipher_iv.len, 4756 tdata->auth_iv.data, tdata->auth_iv.len, 4757 (tdata->digest.offset_bytes == 0 ? 4758 (verify ? ciphertext_pad_len : plaintext_pad_len) 4759 : tdata->digest.offset_bytes), 4760 tdata->validCipherLenInBits.len, 4761 tdata->cipher.offset_bits, 4762 tdata->validAuthLenInBits.len, 4763 tdata->auth.offset_bits, 4764 op_mode, 1, verify); 4765 4766 if (retval < 0) 4767 return retval; 4768 4769 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4770 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4771 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4772 else 4773 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4774 ut_params->op); 4775 4776 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4777 4778 ut_params->obuf = (op_mode == IN_PLACE ? 4779 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 4780 4781 if (verify) { 4782 if (ut_params->obuf) 4783 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 4784 plaintext_len, buffer); 4785 else 4786 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 4787 plaintext_len, buffer); 4788 4789 debug_hexdump(stdout, "plaintext:", plaintext, 4790 (tdata->plaintext.len >> 3) - tdata->digest.len); 4791 debug_hexdump(stdout, "plaintext expected:", 4792 tdata->plaintext.data, 4793 (tdata->plaintext.len >> 3) - tdata->digest.len); 4794 } else { 4795 if (ut_params->obuf) 4796 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4797 ciphertext_len, buffer); 4798 else 4799 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4800 ciphertext_len, buffer); 4801 4802 debug_hexdump(stdout, "ciphertext:", ciphertext, 4803 ciphertext_len); 4804 debug_hexdump(stdout, "ciphertext expected:", 4805 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 4806 4807 if (ut_params->obuf) 4808 digest = rte_pktmbuf_read(ut_params->obuf, 4809 (tdata->digest.offset_bytes == 0 ? 4810 plaintext_pad_len : tdata->digest.offset_bytes), 4811 tdata->digest.len, digest_buffer); 4812 else 4813 digest = rte_pktmbuf_read(ut_params->ibuf, 4814 (tdata->digest.offset_bytes == 0 ? 4815 plaintext_pad_len : tdata->digest.offset_bytes), 4816 tdata->digest.len, digest_buffer); 4817 4818 debug_hexdump(stdout, "digest:", digest, 4819 tdata->digest.len); 4820 debug_hexdump(stdout, "digest expected:", 4821 tdata->digest.data, tdata->digest.len); 4822 } 4823 4824 /* Validate obuf */ 4825 if (verify) { 4826 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4827 plaintext, 4828 tdata->plaintext.data, 4829 tdata->plaintext.len >> 3, 4830 "SNOW 3G Plaintext data not as expected"); 4831 } else { 4832 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4833 ciphertext, 4834 tdata->ciphertext.data, 4835 tdata->validDataLenInBits.len, 4836 "SNOW 3G Ciphertext data not as expected"); 4837 4838 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4839 digest, 4840 tdata->digest.data, 4841 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4842 "SNOW 3G Generated auth tag not as expected"); 4843 } 4844 return 0; 4845 } 4846 4847 static int 4848 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata, 4849 uint8_t op_mode, uint8_t verify) 4850 { 4851 struct crypto_testsuite_params *ts_params = &testsuite_params; 4852 struct crypto_unittest_params *ut_params = &unittest_params; 4853 4854 int retval; 4855 4856 uint8_t *plaintext = NULL, *ciphertext = NULL; 4857 unsigned int plaintext_pad_len; 4858 unsigned int plaintext_len; 4859 unsigned int ciphertext_pad_len; 4860 unsigned int ciphertext_len; 4861 4862 struct rte_cryptodev_info dev_info; 4863 4864 /* Verify the capabilities */ 4865 struct rte_cryptodev_sym_capability_idx cap_idx; 4866 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4867 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 4868 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4869 &cap_idx) == NULL) 4870 return -ENOTSUP; 4871 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4872 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4873 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4874 &cap_idx) == NULL) 4875 return -ENOTSUP; 4876 4877 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4878 4879 uint64_t feat_flags = dev_info.feature_flags; 4880 4881 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4882 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4883 printf("Device doesn't support RAW data-path APIs.\n"); 4884 return -ENOTSUP; 4885 } 4886 4887 if (op_mode == OUT_OF_PLACE) { 4888 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4889 return -ENOTSUP; 4890 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 4891 printf("Device doesn't support digest encrypted.\n"); 4892 return -ENOTSUP; 4893 } 4894 } 4895 4896 /* Create KASUMI session */ 4897 retval = create_wireless_algo_auth_cipher_session( 4898 ts_params->valid_devs[0], 4899 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 4900 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 4901 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 4902 : RTE_CRYPTO_AUTH_OP_GENERATE), 4903 RTE_CRYPTO_AUTH_KASUMI_F9, 4904 RTE_CRYPTO_CIPHER_KASUMI_F8, 4905 tdata->key.data, tdata->key.len, 4906 0, tdata->digest.len, 4907 tdata->cipher_iv.len); 4908 4909 if (retval < 0) 4910 return retval; 4911 4912 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4913 if (op_mode == OUT_OF_PLACE) 4914 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4915 4916 /* clear mbuf payload */ 4917 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4918 rte_pktmbuf_tailroom(ut_params->ibuf)); 4919 if (op_mode == OUT_OF_PLACE) 4920 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4921 rte_pktmbuf_tailroom(ut_params->obuf)); 4922 4923 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4924 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4925 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4926 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4927 4928 if (verify) { 4929 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4930 ciphertext_pad_len); 4931 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4932 if (op_mode == OUT_OF_PLACE) 4933 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4934 debug_hexdump(stdout, "ciphertext:", ciphertext, 4935 ciphertext_len); 4936 } else { 4937 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4938 plaintext_pad_len); 4939 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4940 if (op_mode == OUT_OF_PLACE) 4941 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4942 debug_hexdump(stdout, "plaintext:", plaintext, 4943 plaintext_len); 4944 } 4945 4946 /* Create KASUMI operation */ 4947 retval = create_wireless_algo_auth_cipher_operation( 4948 tdata->digest.data, tdata->digest.len, 4949 tdata->cipher_iv.data, tdata->cipher_iv.len, 4950 NULL, 0, 4951 (tdata->digest.offset_bytes == 0 ? 4952 (verify ? ciphertext_pad_len : plaintext_pad_len) 4953 : tdata->digest.offset_bytes), 4954 tdata->validCipherLenInBits.len, 4955 tdata->validCipherOffsetInBits.len, 4956 tdata->validAuthLenInBits.len, 4957 0, 4958 op_mode, 0, verify); 4959 4960 if (retval < 0) 4961 return retval; 4962 4963 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4964 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4965 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4966 else 4967 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4968 ut_params->op); 4969 4970 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4971 4972 ut_params->obuf = (op_mode == IN_PLACE ? 4973 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 4974 4975 4976 if (verify) { 4977 if (ut_params->obuf) 4978 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 4979 uint8_t *); 4980 else 4981 plaintext = ciphertext; 4982 4983 debug_hexdump(stdout, "plaintext:", plaintext, 4984 (tdata->plaintext.len >> 3) - tdata->digest.len); 4985 debug_hexdump(stdout, "plaintext expected:", 4986 tdata->plaintext.data, 4987 (tdata->plaintext.len >> 3) - tdata->digest.len); 4988 } else { 4989 if (ut_params->obuf) 4990 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 4991 uint8_t *); 4992 else 4993 ciphertext = plaintext; 4994 4995 debug_hexdump(stdout, "ciphertext:", ciphertext, 4996 ciphertext_len); 4997 debug_hexdump(stdout, "ciphertext expected:", 4998 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 4999 5000 ut_params->digest = rte_pktmbuf_mtod( 5001 ut_params->obuf, uint8_t *) + 5002 (tdata->digest.offset_bytes == 0 ? 5003 plaintext_pad_len : tdata->digest.offset_bytes); 5004 5005 debug_hexdump(stdout, "digest:", ut_params->digest, 5006 tdata->digest.len); 5007 debug_hexdump(stdout, "digest expected:", 5008 tdata->digest.data, tdata->digest.len); 5009 } 5010 5011 /* Validate obuf */ 5012 if (verify) { 5013 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5014 plaintext, 5015 tdata->plaintext.data, 5016 tdata->plaintext.len >> 3, 5017 "KASUMI Plaintext data not as expected"); 5018 } else { 5019 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5020 ciphertext, 5021 tdata->ciphertext.data, 5022 tdata->ciphertext.len >> 3, 5023 "KASUMI Ciphertext data not as expected"); 5024 5025 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5026 ut_params->digest, 5027 tdata->digest.data, 5028 DIGEST_BYTE_LENGTH_KASUMI_F9, 5029 "KASUMI Generated auth tag not as expected"); 5030 } 5031 return 0; 5032 } 5033 5034 static int 5035 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata, 5036 uint8_t op_mode, uint8_t verify) 5037 { 5038 struct crypto_testsuite_params *ts_params = &testsuite_params; 5039 struct crypto_unittest_params *ut_params = &unittest_params; 5040 5041 int retval; 5042 5043 const uint8_t *plaintext = NULL; 5044 const uint8_t *ciphertext = NULL; 5045 const uint8_t *digest = NULL; 5046 unsigned int plaintext_pad_len; 5047 unsigned int plaintext_len; 5048 unsigned int ciphertext_pad_len; 5049 unsigned int ciphertext_len; 5050 uint8_t buffer[10000]; 5051 uint8_t digest_buffer[10000]; 5052 5053 struct rte_cryptodev_info dev_info; 5054 5055 /* Verify the capabilities */ 5056 struct rte_cryptodev_sym_capability_idx cap_idx; 5057 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5058 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5059 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5060 &cap_idx) == NULL) 5061 return -ENOTSUP; 5062 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5063 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5064 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5065 &cap_idx) == NULL) 5066 return -ENOTSUP; 5067 5068 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5069 5070 uint64_t feat_flags = dev_info.feature_flags; 5071 5072 if (op_mode == IN_PLACE) { 5073 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5074 printf("Device doesn't support in-place scatter-gather " 5075 "in both input and output mbufs.\n"); 5076 return -ENOTSUP; 5077 } 5078 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5079 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5080 printf("Device doesn't support RAW data-path APIs.\n"); 5081 return -ENOTSUP; 5082 } 5083 } else { 5084 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5085 return -ENOTSUP; 5086 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5087 printf("Device doesn't support out-of-place scatter-gather " 5088 "in both input and output mbufs.\n"); 5089 return -ENOTSUP; 5090 } 5091 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5092 printf("Device doesn't support digest encrypted.\n"); 5093 return -ENOTSUP; 5094 } 5095 } 5096 5097 /* Create KASUMI session */ 5098 retval = create_wireless_algo_auth_cipher_session( 5099 ts_params->valid_devs[0], 5100 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5101 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5102 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5103 : RTE_CRYPTO_AUTH_OP_GENERATE), 5104 RTE_CRYPTO_AUTH_KASUMI_F9, 5105 RTE_CRYPTO_CIPHER_KASUMI_F8, 5106 tdata->key.data, tdata->key.len, 5107 0, tdata->digest.len, 5108 tdata->cipher_iv.len); 5109 5110 if (retval < 0) 5111 return retval; 5112 5113 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5114 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5115 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5116 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5117 5118 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5119 plaintext_pad_len, 15, 0); 5120 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5121 "Failed to allocate input buffer in mempool"); 5122 5123 if (op_mode == OUT_OF_PLACE) { 5124 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5125 plaintext_pad_len, 15, 0); 5126 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5127 "Failed to allocate output buffer in mempool"); 5128 } 5129 5130 if (verify) { 5131 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5132 tdata->ciphertext.data); 5133 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5134 ciphertext_len, buffer); 5135 debug_hexdump(stdout, "ciphertext:", ciphertext, 5136 ciphertext_len); 5137 } else { 5138 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5139 tdata->plaintext.data); 5140 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5141 plaintext_len, buffer); 5142 debug_hexdump(stdout, "plaintext:", plaintext, 5143 plaintext_len); 5144 } 5145 memset(buffer, 0, sizeof(buffer)); 5146 5147 /* Create KASUMI operation */ 5148 retval = create_wireless_algo_auth_cipher_operation( 5149 tdata->digest.data, tdata->digest.len, 5150 tdata->cipher_iv.data, tdata->cipher_iv.len, 5151 NULL, 0, 5152 (tdata->digest.offset_bytes == 0 ? 5153 (verify ? ciphertext_pad_len : plaintext_pad_len) 5154 : tdata->digest.offset_bytes), 5155 tdata->validCipherLenInBits.len, 5156 tdata->validCipherOffsetInBits.len, 5157 tdata->validAuthLenInBits.len, 5158 0, 5159 op_mode, 1, verify); 5160 5161 if (retval < 0) 5162 return retval; 5163 5164 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5165 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5166 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5167 else 5168 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5169 ut_params->op); 5170 5171 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5172 5173 ut_params->obuf = (op_mode == IN_PLACE ? 5174 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5175 5176 if (verify) { 5177 if (ut_params->obuf) 5178 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5179 plaintext_len, buffer); 5180 else 5181 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5182 plaintext_len, buffer); 5183 5184 debug_hexdump(stdout, "plaintext:", plaintext, 5185 (tdata->plaintext.len >> 3) - tdata->digest.len); 5186 debug_hexdump(stdout, "plaintext expected:", 5187 tdata->plaintext.data, 5188 (tdata->plaintext.len >> 3) - tdata->digest.len); 5189 } else { 5190 if (ut_params->obuf) 5191 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5192 ciphertext_len, buffer); 5193 else 5194 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5195 ciphertext_len, buffer); 5196 5197 debug_hexdump(stdout, "ciphertext:", ciphertext, 5198 ciphertext_len); 5199 debug_hexdump(stdout, "ciphertext expected:", 5200 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5201 5202 if (ut_params->obuf) 5203 digest = rte_pktmbuf_read(ut_params->obuf, 5204 (tdata->digest.offset_bytes == 0 ? 5205 plaintext_pad_len : tdata->digest.offset_bytes), 5206 tdata->digest.len, digest_buffer); 5207 else 5208 digest = rte_pktmbuf_read(ut_params->ibuf, 5209 (tdata->digest.offset_bytes == 0 ? 5210 plaintext_pad_len : tdata->digest.offset_bytes), 5211 tdata->digest.len, digest_buffer); 5212 5213 debug_hexdump(stdout, "digest:", digest, 5214 tdata->digest.len); 5215 debug_hexdump(stdout, "digest expected:", 5216 tdata->digest.data, tdata->digest.len); 5217 } 5218 5219 /* Validate obuf */ 5220 if (verify) { 5221 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5222 plaintext, 5223 tdata->plaintext.data, 5224 tdata->plaintext.len >> 3, 5225 "KASUMI Plaintext data not as expected"); 5226 } else { 5227 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5228 ciphertext, 5229 tdata->ciphertext.data, 5230 tdata->validDataLenInBits.len, 5231 "KASUMI Ciphertext data not as expected"); 5232 5233 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5234 digest, 5235 tdata->digest.data, 5236 DIGEST_BYTE_LENGTH_KASUMI_F9, 5237 "KASUMI Generated auth tag not as expected"); 5238 } 5239 return 0; 5240 } 5241 5242 static int 5243 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata) 5244 { 5245 struct crypto_testsuite_params *ts_params = &testsuite_params; 5246 struct crypto_unittest_params *ut_params = &unittest_params; 5247 5248 int retval; 5249 5250 uint8_t *plaintext, *ciphertext; 5251 unsigned plaintext_pad_len; 5252 unsigned plaintext_len; 5253 struct rte_cryptodev_info dev_info; 5254 5255 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5256 uint64_t feat_flags = dev_info.feature_flags; 5257 5258 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5259 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5260 printf("Device doesn't support RAW data-path APIs.\n"); 5261 return -ENOTSUP; 5262 } 5263 5264 /* Verify the capabilities */ 5265 struct rte_cryptodev_sym_capability_idx cap_idx; 5266 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5267 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5268 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5269 &cap_idx) == NULL) 5270 return -ENOTSUP; 5271 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5272 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5273 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5274 &cap_idx) == NULL) 5275 return -ENOTSUP; 5276 5277 /* Create KASUMI session */ 5278 retval = create_wireless_algo_cipher_auth_session( 5279 ts_params->valid_devs[0], 5280 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5281 RTE_CRYPTO_AUTH_OP_GENERATE, 5282 RTE_CRYPTO_AUTH_KASUMI_F9, 5283 RTE_CRYPTO_CIPHER_KASUMI_F8, 5284 tdata->key.data, tdata->key.len, 5285 0, tdata->digest.len, 5286 tdata->cipher_iv.len); 5287 if (retval < 0) 5288 return retval; 5289 5290 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5291 5292 /* clear mbuf payload */ 5293 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5294 rte_pktmbuf_tailroom(ut_params->ibuf)); 5295 5296 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5297 /* Append data which is padded to a multiple of */ 5298 /* the algorithms block size */ 5299 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5300 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5301 plaintext_pad_len); 5302 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5303 5304 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5305 5306 /* Create KASUMI operation */ 5307 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 5308 tdata->digest.len, NULL, 0, 5309 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5310 tdata->cipher_iv.data, tdata->cipher_iv.len, 5311 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 5312 tdata->validCipherOffsetInBits.len, 5313 tdata->validAuthLenInBits.len, 5314 0 5315 ); 5316 if (retval < 0) 5317 return retval; 5318 5319 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5320 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5321 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5322 else 5323 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5324 ut_params->op); 5325 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5326 5327 if (ut_params->op->sym->m_dst) 5328 ut_params->obuf = ut_params->op->sym->m_dst; 5329 else 5330 ut_params->obuf = ut_params->op->sym->m_src; 5331 5332 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 5333 tdata->validCipherOffsetInBits.len >> 3); 5334 5335 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5336 + plaintext_pad_len; 5337 5338 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 5339 (tdata->validCipherOffsetInBits.len >> 3); 5340 /* Validate obuf */ 5341 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5342 ciphertext, 5343 reference_ciphertext, 5344 tdata->validCipherLenInBits.len, 5345 "KASUMI Ciphertext data not as expected"); 5346 5347 /* Validate obuf */ 5348 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5349 ut_params->digest, 5350 tdata->digest.data, 5351 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5352 "KASUMI Generated auth tag not as expected"); 5353 return 0; 5354 } 5355 5356 static int 5357 test_zuc_encryption(const struct wireless_test_data *tdata) 5358 { 5359 struct crypto_testsuite_params *ts_params = &testsuite_params; 5360 struct crypto_unittest_params *ut_params = &unittest_params; 5361 5362 int retval; 5363 uint8_t *plaintext, *ciphertext; 5364 unsigned plaintext_pad_len; 5365 unsigned plaintext_len; 5366 struct rte_cryptodev_info dev_info; 5367 5368 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5369 uint64_t feat_flags = dev_info.feature_flags; 5370 5371 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5372 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5373 printf("Device doesn't support RAW data-path APIs.\n"); 5374 return -ENOTSUP; 5375 } 5376 5377 struct rte_cryptodev_sym_capability_idx cap_idx; 5378 5379 /* Check if device supports ZUC EEA3 */ 5380 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5381 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 5382 5383 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5384 &cap_idx) == NULL) 5385 return -ENOTSUP; 5386 5387 /* Create ZUC session */ 5388 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 5389 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5390 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5391 tdata->key.data, tdata->key.len, 5392 tdata->cipher_iv.len); 5393 if (retval < 0) 5394 return retval; 5395 5396 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5397 5398 /* Clear mbuf payload */ 5399 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5400 rte_pktmbuf_tailroom(ut_params->ibuf)); 5401 5402 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5403 /* Append data which is padded to a multiple */ 5404 /* of the algorithms block size */ 5405 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 5406 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5407 plaintext_pad_len); 5408 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5409 5410 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5411 5412 /* Create ZUC operation */ 5413 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 5414 tdata->cipher_iv.len, 5415 tdata->plaintext.len, 5416 0); 5417 if (retval < 0) 5418 return retval; 5419 5420 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5421 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5422 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 5423 else 5424 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5425 ut_params->op); 5426 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5427 5428 ut_params->obuf = ut_params->op->sym->m_dst; 5429 if (ut_params->obuf) 5430 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 5431 else 5432 ciphertext = plaintext; 5433 5434 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 5435 5436 /* Validate obuf */ 5437 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5438 ciphertext, 5439 tdata->ciphertext.data, 5440 tdata->validCipherLenInBits.len, 5441 "ZUC Ciphertext data not as expected"); 5442 return 0; 5443 } 5444 5445 static int 5446 test_zuc_encryption_sgl(const struct wireless_test_data *tdata) 5447 { 5448 struct crypto_testsuite_params *ts_params = &testsuite_params; 5449 struct crypto_unittest_params *ut_params = &unittest_params; 5450 5451 int retval; 5452 5453 unsigned int plaintext_pad_len; 5454 unsigned int plaintext_len; 5455 const uint8_t *ciphertext; 5456 uint8_t ciphertext_buffer[2048]; 5457 struct rte_cryptodev_info dev_info; 5458 5459 struct rte_cryptodev_sym_capability_idx cap_idx; 5460 5461 /* Check if device supports ZUC EEA3 */ 5462 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5463 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 5464 5465 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5466 &cap_idx) == NULL) 5467 return -ENOTSUP; 5468 5469 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5470 5471 uint64_t feat_flags = dev_info.feature_flags; 5472 5473 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5474 printf("Device doesn't support in-place scatter-gather. " 5475 "Test Skipped.\n"); 5476 return -ENOTSUP; 5477 } 5478 5479 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5480 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5481 printf("Device doesn't support RAW data-path APIs.\n"); 5482 return -ENOTSUP; 5483 } 5484 5485 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5486 5487 /* Append data which is padded to a multiple */ 5488 /* of the algorithms block size */ 5489 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 5490 5491 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5492 plaintext_pad_len, 10, 0); 5493 5494 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5495 tdata->plaintext.data); 5496 5497 /* Create ZUC session */ 5498 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 5499 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5500 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5501 tdata->key.data, tdata->key.len, 5502 tdata->cipher_iv.len); 5503 if (retval < 0) 5504 return retval; 5505 5506 /* Clear mbuf payload */ 5507 5508 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 5509 5510 /* Create ZUC operation */ 5511 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 5512 tdata->cipher_iv.len, tdata->plaintext.len, 5513 0); 5514 if (retval < 0) 5515 return retval; 5516 5517 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5518 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5519 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 5520 else 5521 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5522 ut_params->op); 5523 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5524 5525 ut_params->obuf = ut_params->op->sym->m_dst; 5526 if (ut_params->obuf) 5527 ciphertext = rte_pktmbuf_read(ut_params->obuf, 5528 0, plaintext_len, ciphertext_buffer); 5529 else 5530 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 5531 0, plaintext_len, ciphertext_buffer); 5532 5533 /* Validate obuf */ 5534 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 5535 5536 /* Validate obuf */ 5537 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5538 ciphertext, 5539 tdata->ciphertext.data, 5540 tdata->validCipherLenInBits.len, 5541 "ZUC Ciphertext data not as expected"); 5542 5543 return 0; 5544 } 5545 5546 static int 5547 test_zuc_authentication(const struct wireless_test_data *tdata) 5548 { 5549 struct crypto_testsuite_params *ts_params = &testsuite_params; 5550 struct crypto_unittest_params *ut_params = &unittest_params; 5551 5552 int retval; 5553 unsigned plaintext_pad_len; 5554 unsigned plaintext_len; 5555 uint8_t *plaintext; 5556 5557 struct rte_cryptodev_sym_capability_idx cap_idx; 5558 struct rte_cryptodev_info dev_info; 5559 5560 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5561 uint64_t feat_flags = dev_info.feature_flags; 5562 5563 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 5564 (tdata->validAuthLenInBits.len % 8 != 0)) { 5565 printf("Device doesn't support NON-Byte Aligned Data.\n"); 5566 return -ENOTSUP; 5567 } 5568 5569 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5570 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5571 printf("Device doesn't support RAW data-path APIs.\n"); 5572 return -ENOTSUP; 5573 } 5574 5575 /* Check if device supports ZUC EIA3 */ 5576 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5577 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 5578 5579 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5580 &cap_idx) == NULL) 5581 return -ENOTSUP; 5582 5583 /* Create ZUC session */ 5584 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 5585 tdata->key.data, tdata->key.len, 5586 tdata->auth_iv.len, tdata->digest.len, 5587 RTE_CRYPTO_AUTH_OP_GENERATE, 5588 RTE_CRYPTO_AUTH_ZUC_EIA3); 5589 if (retval < 0) 5590 return retval; 5591 5592 /* alloc mbuf and set payload */ 5593 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5594 5595 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5596 rte_pktmbuf_tailroom(ut_params->ibuf)); 5597 5598 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5599 /* Append data which is padded to a multiple of */ 5600 /* the algorithms block size */ 5601 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 5602 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5603 plaintext_pad_len); 5604 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5605 5606 /* Create ZUC operation */ 5607 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 5608 tdata->auth_iv.data, tdata->auth_iv.len, 5609 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5610 tdata->validAuthLenInBits.len, 5611 0); 5612 if (retval < 0) 5613 return retval; 5614 5615 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5616 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5617 ut_params->op, 0, 1, 1, 0); 5618 else 5619 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5620 ut_params->op); 5621 ut_params->obuf = ut_params->op->sym->m_src; 5622 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5623 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5624 + plaintext_pad_len; 5625 5626 /* Validate obuf */ 5627 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5628 ut_params->digest, 5629 tdata->digest.data, 5630 tdata->digest.len, 5631 "ZUC Generated auth tag not as expected"); 5632 5633 return 0; 5634 } 5635 5636 static int 5637 test_zuc_auth_cipher(const struct wireless_test_data *tdata, 5638 uint8_t op_mode, uint8_t verify) 5639 { 5640 struct crypto_testsuite_params *ts_params = &testsuite_params; 5641 struct crypto_unittest_params *ut_params = &unittest_params; 5642 5643 int retval; 5644 5645 uint8_t *plaintext = NULL, *ciphertext = NULL; 5646 unsigned int plaintext_pad_len; 5647 unsigned int plaintext_len; 5648 unsigned int ciphertext_pad_len; 5649 unsigned int ciphertext_len; 5650 5651 struct rte_cryptodev_info dev_info; 5652 struct rte_cryptodev_sym_capability_idx cap_idx; 5653 5654 /* Check if device supports ZUC EIA3 */ 5655 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5656 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 5657 5658 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5659 &cap_idx) == NULL) 5660 return -ENOTSUP; 5661 5662 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5663 5664 uint64_t feat_flags = dev_info.feature_flags; 5665 5666 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5667 printf("Device doesn't support digest encrypted.\n"); 5668 return -ENOTSUP; 5669 } 5670 if (op_mode == IN_PLACE) { 5671 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5672 printf("Device doesn't support in-place scatter-gather " 5673 "in both input and output mbufs.\n"); 5674 return -ENOTSUP; 5675 } 5676 5677 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5678 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5679 printf("Device doesn't support RAW data-path APIs.\n"); 5680 return -ENOTSUP; 5681 } 5682 } else { 5683 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5684 return -ENOTSUP; 5685 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5686 printf("Device doesn't support out-of-place scatter-gather " 5687 "in both input and output mbufs.\n"); 5688 return -ENOTSUP; 5689 } 5690 } 5691 5692 /* Create ZUC session */ 5693 retval = create_wireless_algo_auth_cipher_session( 5694 ts_params->valid_devs[0], 5695 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5696 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5697 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5698 : RTE_CRYPTO_AUTH_OP_GENERATE), 5699 RTE_CRYPTO_AUTH_ZUC_EIA3, 5700 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5701 tdata->key.data, tdata->key.len, 5702 tdata->auth_iv.len, tdata->digest.len, 5703 tdata->cipher_iv.len); 5704 5705 if (retval < 0) 5706 return retval; 5707 5708 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5709 if (op_mode == OUT_OF_PLACE) 5710 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5711 5712 /* clear mbuf payload */ 5713 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5714 rte_pktmbuf_tailroom(ut_params->ibuf)); 5715 if (op_mode == OUT_OF_PLACE) 5716 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5717 rte_pktmbuf_tailroom(ut_params->obuf)); 5718 5719 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5720 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5721 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5722 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5723 5724 if (verify) { 5725 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5726 ciphertext_pad_len); 5727 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5728 if (op_mode == OUT_OF_PLACE) 5729 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5730 debug_hexdump(stdout, "ciphertext:", ciphertext, 5731 ciphertext_len); 5732 } else { 5733 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5734 plaintext_pad_len); 5735 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5736 if (op_mode == OUT_OF_PLACE) 5737 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5738 debug_hexdump(stdout, "plaintext:", plaintext, 5739 plaintext_len); 5740 } 5741 5742 /* Create ZUC operation */ 5743 retval = create_wireless_algo_auth_cipher_operation( 5744 tdata->digest.data, tdata->digest.len, 5745 tdata->cipher_iv.data, tdata->cipher_iv.len, 5746 tdata->auth_iv.data, tdata->auth_iv.len, 5747 (tdata->digest.offset_bytes == 0 ? 5748 (verify ? ciphertext_pad_len : plaintext_pad_len) 5749 : tdata->digest.offset_bytes), 5750 tdata->validCipherLenInBits.len, 5751 tdata->validCipherOffsetInBits.len, 5752 tdata->validAuthLenInBits.len, 5753 0, 5754 op_mode, 0, verify); 5755 5756 if (retval < 0) 5757 return retval; 5758 5759 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5760 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5761 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5762 else 5763 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5764 ut_params->op); 5765 5766 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5767 5768 ut_params->obuf = (op_mode == IN_PLACE ? 5769 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5770 5771 5772 if (verify) { 5773 if (ut_params->obuf) 5774 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5775 uint8_t *); 5776 else 5777 plaintext = ciphertext; 5778 5779 debug_hexdump(stdout, "plaintext:", plaintext, 5780 (tdata->plaintext.len >> 3) - tdata->digest.len); 5781 debug_hexdump(stdout, "plaintext expected:", 5782 tdata->plaintext.data, 5783 (tdata->plaintext.len >> 3) - tdata->digest.len); 5784 } else { 5785 if (ut_params->obuf) 5786 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5787 uint8_t *); 5788 else 5789 ciphertext = plaintext; 5790 5791 debug_hexdump(stdout, "ciphertext:", ciphertext, 5792 ciphertext_len); 5793 debug_hexdump(stdout, "ciphertext expected:", 5794 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5795 5796 ut_params->digest = rte_pktmbuf_mtod( 5797 ut_params->obuf, uint8_t *) + 5798 (tdata->digest.offset_bytes == 0 ? 5799 plaintext_pad_len : tdata->digest.offset_bytes); 5800 5801 debug_hexdump(stdout, "digest:", ut_params->digest, 5802 tdata->digest.len); 5803 debug_hexdump(stdout, "digest expected:", 5804 tdata->digest.data, tdata->digest.len); 5805 } 5806 5807 /* Validate obuf */ 5808 if (verify) { 5809 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5810 plaintext, 5811 tdata->plaintext.data, 5812 tdata->plaintext.len >> 3, 5813 "ZUC Plaintext data not as expected"); 5814 } else { 5815 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5816 ciphertext, 5817 tdata->ciphertext.data, 5818 tdata->ciphertext.len >> 3, 5819 "ZUC Ciphertext data not as expected"); 5820 5821 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5822 ut_params->digest, 5823 tdata->digest.data, 5824 DIGEST_BYTE_LENGTH_KASUMI_F9, 5825 "ZUC Generated auth tag not as expected"); 5826 } 5827 return 0; 5828 } 5829 5830 static int 5831 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata, 5832 uint8_t op_mode, uint8_t verify) 5833 { 5834 struct crypto_testsuite_params *ts_params = &testsuite_params; 5835 struct crypto_unittest_params *ut_params = &unittest_params; 5836 5837 int retval; 5838 5839 const uint8_t *plaintext = NULL; 5840 const uint8_t *ciphertext = NULL; 5841 const uint8_t *digest = NULL; 5842 unsigned int plaintext_pad_len; 5843 unsigned int plaintext_len; 5844 unsigned int ciphertext_pad_len; 5845 unsigned int ciphertext_len; 5846 uint8_t buffer[10000]; 5847 uint8_t digest_buffer[10000]; 5848 5849 struct rte_cryptodev_info dev_info; 5850 struct rte_cryptodev_sym_capability_idx cap_idx; 5851 5852 /* Check if device supports ZUC EIA3 */ 5853 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5854 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 5855 5856 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5857 &cap_idx) == NULL) 5858 return -ENOTSUP; 5859 5860 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5861 5862 uint64_t feat_flags = dev_info.feature_flags; 5863 5864 if (op_mode == IN_PLACE) { 5865 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5866 printf("Device doesn't support in-place scatter-gather " 5867 "in both input and output mbufs.\n"); 5868 return -ENOTSUP; 5869 } 5870 5871 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5872 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5873 printf("Device doesn't support RAW data-path APIs.\n"); 5874 return -ENOTSUP; 5875 } 5876 } else { 5877 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5878 return -ENOTSUP; 5879 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5880 printf("Device doesn't support out-of-place scatter-gather " 5881 "in both input and output mbufs.\n"); 5882 return -ENOTSUP; 5883 } 5884 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5885 printf("Device doesn't support digest encrypted.\n"); 5886 return -ENOTSUP; 5887 } 5888 } 5889 5890 /* Create ZUC session */ 5891 retval = create_wireless_algo_auth_cipher_session( 5892 ts_params->valid_devs[0], 5893 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5894 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5895 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5896 : RTE_CRYPTO_AUTH_OP_GENERATE), 5897 RTE_CRYPTO_AUTH_ZUC_EIA3, 5898 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5899 tdata->key.data, tdata->key.len, 5900 tdata->auth_iv.len, tdata->digest.len, 5901 tdata->cipher_iv.len); 5902 5903 if (retval < 0) 5904 return retval; 5905 5906 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5907 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5908 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5909 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5910 5911 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5912 plaintext_pad_len, 15, 0); 5913 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5914 "Failed to allocate input buffer in mempool"); 5915 5916 if (op_mode == OUT_OF_PLACE) { 5917 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5918 plaintext_pad_len, 15, 0); 5919 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5920 "Failed to allocate output buffer in mempool"); 5921 } 5922 5923 if (verify) { 5924 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5925 tdata->ciphertext.data); 5926 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5927 ciphertext_len, buffer); 5928 debug_hexdump(stdout, "ciphertext:", ciphertext, 5929 ciphertext_len); 5930 } else { 5931 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5932 tdata->plaintext.data); 5933 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5934 plaintext_len, buffer); 5935 debug_hexdump(stdout, "plaintext:", plaintext, 5936 plaintext_len); 5937 } 5938 memset(buffer, 0, sizeof(buffer)); 5939 5940 /* Create ZUC operation */ 5941 retval = create_wireless_algo_auth_cipher_operation( 5942 tdata->digest.data, tdata->digest.len, 5943 tdata->cipher_iv.data, tdata->cipher_iv.len, 5944 NULL, 0, 5945 (tdata->digest.offset_bytes == 0 ? 5946 (verify ? ciphertext_pad_len : plaintext_pad_len) 5947 : tdata->digest.offset_bytes), 5948 tdata->validCipherLenInBits.len, 5949 tdata->validCipherOffsetInBits.len, 5950 tdata->validAuthLenInBits.len, 5951 0, 5952 op_mode, 1, verify); 5953 5954 if (retval < 0) 5955 return retval; 5956 5957 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5958 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5959 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5960 else 5961 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5962 ut_params->op); 5963 5964 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5965 5966 ut_params->obuf = (op_mode == IN_PLACE ? 5967 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5968 5969 if (verify) { 5970 if (ut_params->obuf) 5971 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5972 plaintext_len, buffer); 5973 else 5974 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5975 plaintext_len, buffer); 5976 5977 debug_hexdump(stdout, "plaintext:", plaintext, 5978 (tdata->plaintext.len >> 3) - tdata->digest.len); 5979 debug_hexdump(stdout, "plaintext expected:", 5980 tdata->plaintext.data, 5981 (tdata->plaintext.len >> 3) - tdata->digest.len); 5982 } else { 5983 if (ut_params->obuf) 5984 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5985 ciphertext_len, buffer); 5986 else 5987 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5988 ciphertext_len, buffer); 5989 5990 debug_hexdump(stdout, "ciphertext:", ciphertext, 5991 ciphertext_len); 5992 debug_hexdump(stdout, "ciphertext expected:", 5993 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5994 5995 if (ut_params->obuf) 5996 digest = rte_pktmbuf_read(ut_params->obuf, 5997 (tdata->digest.offset_bytes == 0 ? 5998 plaintext_pad_len : tdata->digest.offset_bytes), 5999 tdata->digest.len, digest_buffer); 6000 else 6001 digest = rte_pktmbuf_read(ut_params->ibuf, 6002 (tdata->digest.offset_bytes == 0 ? 6003 plaintext_pad_len : tdata->digest.offset_bytes), 6004 tdata->digest.len, digest_buffer); 6005 6006 debug_hexdump(stdout, "digest:", digest, 6007 tdata->digest.len); 6008 debug_hexdump(stdout, "digest expected:", 6009 tdata->digest.data, tdata->digest.len); 6010 } 6011 6012 /* Validate obuf */ 6013 if (verify) { 6014 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6015 plaintext, 6016 tdata->plaintext.data, 6017 tdata->plaintext.len >> 3, 6018 "ZUC Plaintext data not as expected"); 6019 } else { 6020 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6021 ciphertext, 6022 tdata->ciphertext.data, 6023 tdata->validDataLenInBits.len, 6024 "ZUC Ciphertext data not as expected"); 6025 6026 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6027 digest, 6028 tdata->digest.data, 6029 DIGEST_BYTE_LENGTH_KASUMI_F9, 6030 "ZUC Generated auth tag not as expected"); 6031 } 6032 return 0; 6033 } 6034 6035 static int 6036 test_kasumi_encryption_test_case_1(void) 6037 { 6038 return test_kasumi_encryption(&kasumi_test_case_1); 6039 } 6040 6041 static int 6042 test_kasumi_encryption_test_case_1_sgl(void) 6043 { 6044 return test_kasumi_encryption_sgl(&kasumi_test_case_1); 6045 } 6046 6047 static int 6048 test_kasumi_encryption_test_case_1_oop(void) 6049 { 6050 return test_kasumi_encryption_oop(&kasumi_test_case_1); 6051 } 6052 6053 static int 6054 test_kasumi_encryption_test_case_1_oop_sgl(void) 6055 { 6056 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1); 6057 } 6058 6059 static int 6060 test_kasumi_encryption_test_case_2(void) 6061 { 6062 return test_kasumi_encryption(&kasumi_test_case_2); 6063 } 6064 6065 static int 6066 test_kasumi_encryption_test_case_3(void) 6067 { 6068 return test_kasumi_encryption(&kasumi_test_case_3); 6069 } 6070 6071 static int 6072 test_kasumi_encryption_test_case_4(void) 6073 { 6074 return test_kasumi_encryption(&kasumi_test_case_4); 6075 } 6076 6077 static int 6078 test_kasumi_encryption_test_case_5(void) 6079 { 6080 return test_kasumi_encryption(&kasumi_test_case_5); 6081 } 6082 6083 static int 6084 test_kasumi_decryption_test_case_1(void) 6085 { 6086 return test_kasumi_decryption(&kasumi_test_case_1); 6087 } 6088 6089 static int 6090 test_kasumi_decryption_test_case_1_oop(void) 6091 { 6092 return test_kasumi_decryption_oop(&kasumi_test_case_1); 6093 } 6094 6095 static int 6096 test_kasumi_decryption_test_case_2(void) 6097 { 6098 return test_kasumi_decryption(&kasumi_test_case_2); 6099 } 6100 6101 static int 6102 test_kasumi_decryption_test_case_3(void) 6103 { 6104 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6105 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6106 return -ENOTSUP; 6107 return test_kasumi_decryption(&kasumi_test_case_3); 6108 } 6109 6110 static int 6111 test_kasumi_decryption_test_case_4(void) 6112 { 6113 return test_kasumi_decryption(&kasumi_test_case_4); 6114 } 6115 6116 static int 6117 test_kasumi_decryption_test_case_5(void) 6118 { 6119 return test_kasumi_decryption(&kasumi_test_case_5); 6120 } 6121 static int 6122 test_snow3g_encryption_test_case_1(void) 6123 { 6124 return test_snow3g_encryption(&snow3g_test_case_1); 6125 } 6126 6127 static int 6128 test_snow3g_encryption_test_case_1_oop(void) 6129 { 6130 return test_snow3g_encryption_oop(&snow3g_test_case_1); 6131 } 6132 6133 static int 6134 test_snow3g_encryption_test_case_1_oop_sgl(void) 6135 { 6136 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1); 6137 } 6138 6139 6140 static int 6141 test_snow3g_encryption_test_case_1_offset_oop(void) 6142 { 6143 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); 6144 } 6145 6146 static int 6147 test_snow3g_encryption_test_case_2(void) 6148 { 6149 return test_snow3g_encryption(&snow3g_test_case_2); 6150 } 6151 6152 static int 6153 test_snow3g_encryption_test_case_3(void) 6154 { 6155 return test_snow3g_encryption(&snow3g_test_case_3); 6156 } 6157 6158 static int 6159 test_snow3g_encryption_test_case_4(void) 6160 { 6161 return test_snow3g_encryption(&snow3g_test_case_4); 6162 } 6163 6164 static int 6165 test_snow3g_encryption_test_case_5(void) 6166 { 6167 return test_snow3g_encryption(&snow3g_test_case_5); 6168 } 6169 6170 static int 6171 test_snow3g_decryption_test_case_1(void) 6172 { 6173 return test_snow3g_decryption(&snow3g_test_case_1); 6174 } 6175 6176 static int 6177 test_snow3g_decryption_test_case_1_oop(void) 6178 { 6179 return test_snow3g_decryption_oop(&snow3g_test_case_1); 6180 } 6181 6182 static int 6183 test_snow3g_decryption_test_case_2(void) 6184 { 6185 return test_snow3g_decryption(&snow3g_test_case_2); 6186 } 6187 6188 static int 6189 test_snow3g_decryption_test_case_3(void) 6190 { 6191 return test_snow3g_decryption(&snow3g_test_case_3); 6192 } 6193 6194 static int 6195 test_snow3g_decryption_test_case_4(void) 6196 { 6197 return test_snow3g_decryption(&snow3g_test_case_4); 6198 } 6199 6200 static int 6201 test_snow3g_decryption_test_case_5(void) 6202 { 6203 return test_snow3g_decryption(&snow3g_test_case_5); 6204 } 6205 6206 /* 6207 * Function prepares snow3g_hash_test_data from snow3g_test_data. 6208 * Pattern digest from snow3g_test_data must be allocated as 6209 * 4 last bytes in plaintext. 6210 */ 6211 static void 6212 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern, 6213 struct snow3g_hash_test_data *output) 6214 { 6215 if ((pattern != NULL) && (output != NULL)) { 6216 output->key.len = pattern->key.len; 6217 6218 memcpy(output->key.data, 6219 pattern->key.data, pattern->key.len); 6220 6221 output->auth_iv.len = pattern->auth_iv.len; 6222 6223 memcpy(output->auth_iv.data, 6224 pattern->auth_iv.data, pattern->auth_iv.len); 6225 6226 output->plaintext.len = pattern->plaintext.len; 6227 6228 memcpy(output->plaintext.data, 6229 pattern->plaintext.data, pattern->plaintext.len >> 3); 6230 6231 output->digest.len = pattern->digest.len; 6232 6233 memcpy(output->digest.data, 6234 &pattern->plaintext.data[pattern->digest.offset_bytes], 6235 pattern->digest.len); 6236 6237 output->validAuthLenInBits.len = 6238 pattern->validAuthLenInBits.len; 6239 } 6240 } 6241 6242 /* 6243 * Test case verify computed cipher and digest from snow3g_test_case_7 data. 6244 */ 6245 static int 6246 test_snow3g_decryption_with_digest_test_case_1(void) 6247 { 6248 struct snow3g_hash_test_data snow3g_hash_data; 6249 6250 /* 6251 * Function prepare data for hash veryfication test case. 6252 * Digest is allocated in 4 last bytes in plaintext, pattern. 6253 */ 6254 snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data); 6255 6256 return test_snow3g_decryption(&snow3g_test_case_7) & 6257 test_snow3g_authentication_verify(&snow3g_hash_data); 6258 } 6259 6260 static int 6261 test_snow3g_cipher_auth_test_case_1(void) 6262 { 6263 return test_snow3g_cipher_auth(&snow3g_test_case_3); 6264 } 6265 6266 static int 6267 test_snow3g_auth_cipher_test_case_1(void) 6268 { 6269 return test_snow3g_auth_cipher( 6270 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0); 6271 } 6272 6273 static int 6274 test_snow3g_auth_cipher_test_case_2(void) 6275 { 6276 return test_snow3g_auth_cipher( 6277 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0); 6278 } 6279 6280 static int 6281 test_snow3g_auth_cipher_test_case_2_oop(void) 6282 { 6283 return test_snow3g_auth_cipher( 6284 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6285 } 6286 6287 static int 6288 test_snow3g_auth_cipher_part_digest_enc(void) 6289 { 6290 return test_snow3g_auth_cipher( 6291 &snow3g_auth_cipher_partial_digest_encryption, 6292 IN_PLACE, 0); 6293 } 6294 6295 static int 6296 test_snow3g_auth_cipher_part_digest_enc_oop(void) 6297 { 6298 return test_snow3g_auth_cipher( 6299 &snow3g_auth_cipher_partial_digest_encryption, 6300 OUT_OF_PLACE, 0); 6301 } 6302 6303 static int 6304 test_snow3g_auth_cipher_test_case_3_sgl(void) 6305 { 6306 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6307 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6308 return -ENOTSUP; 6309 return test_snow3g_auth_cipher_sgl( 6310 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0); 6311 } 6312 6313 static int 6314 test_snow3g_auth_cipher_test_case_3_oop_sgl(void) 6315 { 6316 return test_snow3g_auth_cipher_sgl( 6317 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0); 6318 } 6319 6320 static int 6321 test_snow3g_auth_cipher_part_digest_enc_sgl(void) 6322 { 6323 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6324 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6325 return -ENOTSUP; 6326 return test_snow3g_auth_cipher_sgl( 6327 &snow3g_auth_cipher_partial_digest_encryption, 6328 IN_PLACE, 0); 6329 } 6330 6331 static int 6332 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void) 6333 { 6334 return test_snow3g_auth_cipher_sgl( 6335 &snow3g_auth_cipher_partial_digest_encryption, 6336 OUT_OF_PLACE, 0); 6337 } 6338 6339 static int 6340 test_snow3g_auth_cipher_verify_test_case_1(void) 6341 { 6342 return test_snow3g_auth_cipher( 6343 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1); 6344 } 6345 6346 static int 6347 test_snow3g_auth_cipher_verify_test_case_2(void) 6348 { 6349 return test_snow3g_auth_cipher( 6350 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1); 6351 } 6352 6353 static int 6354 test_snow3g_auth_cipher_verify_test_case_2_oop(void) 6355 { 6356 return test_snow3g_auth_cipher( 6357 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 6358 } 6359 6360 static int 6361 test_snow3g_auth_cipher_verify_part_digest_enc(void) 6362 { 6363 return test_snow3g_auth_cipher( 6364 &snow3g_auth_cipher_partial_digest_encryption, 6365 IN_PLACE, 1); 6366 } 6367 6368 static int 6369 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void) 6370 { 6371 return test_snow3g_auth_cipher( 6372 &snow3g_auth_cipher_partial_digest_encryption, 6373 OUT_OF_PLACE, 1); 6374 } 6375 6376 static int 6377 test_snow3g_auth_cipher_verify_test_case_3_sgl(void) 6378 { 6379 return test_snow3g_auth_cipher_sgl( 6380 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1); 6381 } 6382 6383 static int 6384 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void) 6385 { 6386 return test_snow3g_auth_cipher_sgl( 6387 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1); 6388 } 6389 6390 static int 6391 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void) 6392 { 6393 return test_snow3g_auth_cipher_sgl( 6394 &snow3g_auth_cipher_partial_digest_encryption, 6395 IN_PLACE, 1); 6396 } 6397 6398 static int 6399 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void) 6400 { 6401 return test_snow3g_auth_cipher_sgl( 6402 &snow3g_auth_cipher_partial_digest_encryption, 6403 OUT_OF_PLACE, 1); 6404 } 6405 6406 static int 6407 test_snow3g_auth_cipher_with_digest_test_case_1(void) 6408 { 6409 return test_snow3g_auth_cipher( 6410 &snow3g_test_case_7, IN_PLACE, 0); 6411 } 6412 6413 static int 6414 test_kasumi_auth_cipher_test_case_1(void) 6415 { 6416 return test_kasumi_auth_cipher( 6417 &kasumi_test_case_3, IN_PLACE, 0); 6418 } 6419 6420 static int 6421 test_kasumi_auth_cipher_test_case_2(void) 6422 { 6423 return test_kasumi_auth_cipher( 6424 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 6425 } 6426 6427 static int 6428 test_kasumi_auth_cipher_test_case_2_oop(void) 6429 { 6430 return test_kasumi_auth_cipher( 6431 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6432 } 6433 6434 static int 6435 test_kasumi_auth_cipher_test_case_2_sgl(void) 6436 { 6437 return test_kasumi_auth_cipher_sgl( 6438 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 6439 } 6440 6441 static int 6442 test_kasumi_auth_cipher_test_case_2_oop_sgl(void) 6443 { 6444 return test_kasumi_auth_cipher_sgl( 6445 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6446 } 6447 6448 static int 6449 test_kasumi_auth_cipher_verify_test_case_1(void) 6450 { 6451 return test_kasumi_auth_cipher( 6452 &kasumi_test_case_3, IN_PLACE, 1); 6453 } 6454 6455 static int 6456 test_kasumi_auth_cipher_verify_test_case_2(void) 6457 { 6458 return test_kasumi_auth_cipher( 6459 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 6460 } 6461 6462 static int 6463 test_kasumi_auth_cipher_verify_test_case_2_oop(void) 6464 { 6465 return test_kasumi_auth_cipher( 6466 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 6467 } 6468 6469 static int 6470 test_kasumi_auth_cipher_verify_test_case_2_sgl(void) 6471 { 6472 return test_kasumi_auth_cipher_sgl( 6473 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 6474 } 6475 6476 static int 6477 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void) 6478 { 6479 return test_kasumi_auth_cipher_sgl( 6480 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 6481 } 6482 6483 static int 6484 test_kasumi_cipher_auth_test_case_1(void) 6485 { 6486 return test_kasumi_cipher_auth(&kasumi_test_case_6); 6487 } 6488 6489 static int 6490 test_zuc_encryption_test_case_1(void) 6491 { 6492 return test_zuc_encryption(&zuc_test_case_cipher_193b); 6493 } 6494 6495 static int 6496 test_zuc_encryption_test_case_2(void) 6497 { 6498 return test_zuc_encryption(&zuc_test_case_cipher_800b); 6499 } 6500 6501 static int 6502 test_zuc_encryption_test_case_3(void) 6503 { 6504 return test_zuc_encryption(&zuc_test_case_cipher_1570b); 6505 } 6506 6507 static int 6508 test_zuc_encryption_test_case_4(void) 6509 { 6510 return test_zuc_encryption(&zuc_test_case_cipher_2798b); 6511 } 6512 6513 static int 6514 test_zuc_encryption_test_case_5(void) 6515 { 6516 return test_zuc_encryption(&zuc_test_case_cipher_4019b); 6517 } 6518 6519 static int 6520 test_zuc_encryption_test_case_6_sgl(void) 6521 { 6522 return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b); 6523 } 6524 6525 static int 6526 test_zuc_hash_generate_test_case_1(void) 6527 { 6528 return test_zuc_authentication(&zuc_test_case_auth_1b); 6529 } 6530 6531 static int 6532 test_zuc_hash_generate_test_case_2(void) 6533 { 6534 return test_zuc_authentication(&zuc_test_case_auth_90b); 6535 } 6536 6537 static int 6538 test_zuc_hash_generate_test_case_3(void) 6539 { 6540 return test_zuc_authentication(&zuc_test_case_auth_577b); 6541 } 6542 6543 static int 6544 test_zuc_hash_generate_test_case_4(void) 6545 { 6546 return test_zuc_authentication(&zuc_test_case_auth_2079b); 6547 } 6548 6549 static int 6550 test_zuc_hash_generate_test_case_5(void) 6551 { 6552 return test_zuc_authentication(&zuc_test_auth_5670b); 6553 } 6554 6555 static int 6556 test_zuc_hash_generate_test_case_6(void) 6557 { 6558 return test_zuc_authentication(&zuc_test_case_auth_128b); 6559 } 6560 6561 static int 6562 test_zuc_hash_generate_test_case_7(void) 6563 { 6564 return test_zuc_authentication(&zuc_test_case_auth_2080b); 6565 } 6566 6567 static int 6568 test_zuc_hash_generate_test_case_8(void) 6569 { 6570 return test_zuc_authentication(&zuc_test_case_auth_584b); 6571 } 6572 6573 static int 6574 test_zuc_cipher_auth_test_case_1(void) 6575 { 6576 return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b); 6577 } 6578 6579 static int 6580 test_zuc_cipher_auth_test_case_2(void) 6581 { 6582 return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b); 6583 } 6584 6585 static int 6586 test_zuc_auth_cipher_test_case_1(void) 6587 { 6588 return test_zuc_auth_cipher( 6589 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 6590 } 6591 6592 static int 6593 test_zuc_auth_cipher_test_case_1_oop(void) 6594 { 6595 return test_zuc_auth_cipher( 6596 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 6597 } 6598 6599 static int 6600 test_zuc_auth_cipher_test_case_1_sgl(void) 6601 { 6602 return test_zuc_auth_cipher_sgl( 6603 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 6604 } 6605 6606 static int 6607 test_zuc_auth_cipher_test_case_1_oop_sgl(void) 6608 { 6609 return test_zuc_auth_cipher_sgl( 6610 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 6611 } 6612 6613 static int 6614 test_zuc_auth_cipher_verify_test_case_1(void) 6615 { 6616 return test_zuc_auth_cipher( 6617 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 6618 } 6619 6620 static int 6621 test_zuc_auth_cipher_verify_test_case_1_oop(void) 6622 { 6623 return test_zuc_auth_cipher( 6624 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 6625 } 6626 6627 static int 6628 test_zuc_auth_cipher_verify_test_case_1_sgl(void) 6629 { 6630 return test_zuc_auth_cipher_sgl( 6631 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 6632 } 6633 6634 static int 6635 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void) 6636 { 6637 return test_zuc_auth_cipher_sgl( 6638 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 6639 } 6640 6641 static int 6642 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata) 6643 { 6644 uint8_t dev_id = testsuite_params.valid_devs[0]; 6645 6646 struct rte_cryptodev_sym_capability_idx cap_idx; 6647 6648 /* Check if device supports particular cipher algorithm */ 6649 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 6650 cap_idx.algo.cipher = tdata->cipher_algo; 6651 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 6652 return -ENOTSUP; 6653 6654 /* Check if device supports particular hash algorithm */ 6655 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 6656 cap_idx.algo.auth = tdata->auth_algo; 6657 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 6658 return -ENOTSUP; 6659 6660 return 0; 6661 } 6662 6663 static int 6664 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata, 6665 uint8_t op_mode, uint8_t verify) 6666 { 6667 struct crypto_testsuite_params *ts_params = &testsuite_params; 6668 struct crypto_unittest_params *ut_params = &unittest_params; 6669 6670 int retval; 6671 6672 uint8_t *plaintext = NULL, *ciphertext = NULL; 6673 unsigned int plaintext_pad_len; 6674 unsigned int plaintext_len; 6675 unsigned int ciphertext_pad_len; 6676 unsigned int ciphertext_len; 6677 6678 struct rte_cryptodev_info dev_info; 6679 6680 /* Check if device supports particular algorithms separately */ 6681 if (test_mixed_check_if_unsupported(tdata)) 6682 return -ENOTSUP; 6683 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6684 return -ENOTSUP; 6685 6686 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6687 6688 uint64_t feat_flags = dev_info.feature_flags; 6689 6690 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6691 printf("Device doesn't support digest encrypted.\n"); 6692 return -ENOTSUP; 6693 } 6694 6695 if (op_mode == OUT_OF_PLACE) 6696 return -ENOTSUP; 6697 6698 /* Create the session */ 6699 if (verify) 6700 retval = create_wireless_algo_cipher_auth_session( 6701 ts_params->valid_devs[0], 6702 RTE_CRYPTO_CIPHER_OP_DECRYPT, 6703 RTE_CRYPTO_AUTH_OP_VERIFY, 6704 tdata->auth_algo, 6705 tdata->cipher_algo, 6706 tdata->auth_key.data, tdata->auth_key.len, 6707 tdata->auth_iv.len, tdata->digest_enc.len, 6708 tdata->cipher_iv.len); 6709 else 6710 retval = create_wireless_algo_auth_cipher_session( 6711 ts_params->valid_devs[0], 6712 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6713 RTE_CRYPTO_AUTH_OP_GENERATE, 6714 tdata->auth_algo, 6715 tdata->cipher_algo, 6716 tdata->auth_key.data, tdata->auth_key.len, 6717 tdata->auth_iv.len, tdata->digest_enc.len, 6718 tdata->cipher_iv.len); 6719 if (retval < 0) 6720 return retval; 6721 6722 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6723 if (op_mode == OUT_OF_PLACE) 6724 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6725 6726 /* clear mbuf payload */ 6727 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6728 rte_pktmbuf_tailroom(ut_params->ibuf)); 6729 if (op_mode == OUT_OF_PLACE) { 6730 6731 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 6732 rte_pktmbuf_tailroom(ut_params->obuf)); 6733 } 6734 6735 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 6736 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 6737 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6738 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6739 6740 if (verify) { 6741 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6742 ciphertext_pad_len); 6743 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6744 if (op_mode == OUT_OF_PLACE) 6745 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 6746 debug_hexdump(stdout, "ciphertext:", ciphertext, 6747 ciphertext_len); 6748 } else { 6749 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6750 plaintext_pad_len); 6751 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6752 if (op_mode == OUT_OF_PLACE) 6753 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 6754 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6755 } 6756 6757 /* Create the operation */ 6758 retval = create_wireless_algo_auth_cipher_operation( 6759 tdata->digest_enc.data, tdata->digest_enc.len, 6760 tdata->cipher_iv.data, tdata->cipher_iv.len, 6761 tdata->auth_iv.data, tdata->auth_iv.len, 6762 (tdata->digest_enc.offset == 0 ? 6763 plaintext_pad_len 6764 : tdata->digest_enc.offset), 6765 tdata->validCipherLen.len_bits, 6766 tdata->cipher.offset_bits, 6767 tdata->validAuthLen.len_bits, 6768 tdata->auth.offset_bits, 6769 op_mode, 0, verify); 6770 6771 if (retval < 0) 6772 return retval; 6773 6774 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6775 ut_params->op); 6776 6777 /* Check if the op failed because the device doesn't */ 6778 /* support this particular combination of algorithms */ 6779 if (ut_params->op == NULL && ut_params->op->status == 6780 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 6781 printf("Device doesn't support this mixed combination. " 6782 "Test Skipped.\n"); 6783 return -ENOTSUP; 6784 } 6785 6786 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6787 6788 ut_params->obuf = (op_mode == IN_PLACE ? 6789 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6790 6791 if (verify) { 6792 if (ut_params->obuf) 6793 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 6794 uint8_t *); 6795 else 6796 plaintext = ciphertext + 6797 (tdata->cipher.offset_bits >> 3); 6798 6799 debug_hexdump(stdout, "plaintext:", plaintext, 6800 tdata->plaintext.len_bits >> 3); 6801 debug_hexdump(stdout, "plaintext expected:", 6802 tdata->plaintext.data, 6803 tdata->plaintext.len_bits >> 3); 6804 } else { 6805 if (ut_params->obuf) 6806 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 6807 uint8_t *); 6808 else 6809 ciphertext = plaintext; 6810 6811 debug_hexdump(stdout, "ciphertext:", ciphertext, 6812 ciphertext_len); 6813 debug_hexdump(stdout, "ciphertext expected:", 6814 tdata->ciphertext.data, 6815 tdata->ciphertext.len_bits >> 3); 6816 6817 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 6818 + (tdata->digest_enc.offset == 0 ? 6819 plaintext_pad_len : tdata->digest_enc.offset); 6820 6821 debug_hexdump(stdout, "digest:", ut_params->digest, 6822 tdata->digest_enc.len); 6823 debug_hexdump(stdout, "digest expected:", 6824 tdata->digest_enc.data, 6825 tdata->digest_enc.len); 6826 } 6827 6828 /* Validate obuf */ 6829 if (verify) { 6830 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6831 plaintext, 6832 tdata->plaintext.data, 6833 tdata->plaintext.len_bits >> 3, 6834 "Plaintext data not as expected"); 6835 } else { 6836 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6837 ciphertext, 6838 tdata->ciphertext.data, 6839 tdata->validDataLen.len_bits, 6840 "Ciphertext data not as expected"); 6841 6842 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6843 ut_params->digest, 6844 tdata->digest_enc.data, 6845 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 6846 "Generated auth tag not as expected"); 6847 } 6848 6849 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 6850 "crypto op processing failed"); 6851 6852 return 0; 6853 } 6854 6855 static int 6856 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata, 6857 uint8_t op_mode, uint8_t verify) 6858 { 6859 struct crypto_testsuite_params *ts_params = &testsuite_params; 6860 struct crypto_unittest_params *ut_params = &unittest_params; 6861 6862 int retval; 6863 6864 const uint8_t *plaintext = NULL; 6865 const uint8_t *ciphertext = NULL; 6866 const uint8_t *digest = NULL; 6867 unsigned int plaintext_pad_len; 6868 unsigned int plaintext_len; 6869 unsigned int ciphertext_pad_len; 6870 unsigned int ciphertext_len; 6871 uint8_t buffer[10000]; 6872 uint8_t digest_buffer[10000]; 6873 6874 struct rte_cryptodev_info dev_info; 6875 6876 /* Check if device supports particular algorithms */ 6877 if (test_mixed_check_if_unsupported(tdata)) 6878 return -ENOTSUP; 6879 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6880 return -ENOTSUP; 6881 6882 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6883 6884 uint64_t feat_flags = dev_info.feature_flags; 6885 6886 if (op_mode == IN_PLACE) { 6887 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6888 printf("Device doesn't support in-place scatter-gather " 6889 "in both input and output mbufs.\n"); 6890 return -ENOTSUP; 6891 } 6892 } else { 6893 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6894 printf("Device doesn't support out-of-place scatter-gather " 6895 "in both input and output mbufs.\n"); 6896 return -ENOTSUP; 6897 } 6898 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6899 printf("Device doesn't support digest encrypted.\n"); 6900 return -ENOTSUP; 6901 } 6902 } 6903 6904 /* Create the session */ 6905 if (verify) 6906 retval = create_wireless_algo_cipher_auth_session( 6907 ts_params->valid_devs[0], 6908 RTE_CRYPTO_CIPHER_OP_DECRYPT, 6909 RTE_CRYPTO_AUTH_OP_VERIFY, 6910 tdata->auth_algo, 6911 tdata->cipher_algo, 6912 tdata->auth_key.data, tdata->auth_key.len, 6913 tdata->auth_iv.len, tdata->digest_enc.len, 6914 tdata->cipher_iv.len); 6915 else 6916 retval = create_wireless_algo_auth_cipher_session( 6917 ts_params->valid_devs[0], 6918 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6919 RTE_CRYPTO_AUTH_OP_GENERATE, 6920 tdata->auth_algo, 6921 tdata->cipher_algo, 6922 tdata->auth_key.data, tdata->auth_key.len, 6923 tdata->auth_iv.len, tdata->digest_enc.len, 6924 tdata->cipher_iv.len); 6925 if (retval < 0) 6926 return retval; 6927 6928 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 6929 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 6930 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6931 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6932 6933 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6934 ciphertext_pad_len, 15, 0); 6935 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6936 "Failed to allocate input buffer in mempool"); 6937 6938 if (op_mode == OUT_OF_PLACE) { 6939 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 6940 plaintext_pad_len, 15, 0); 6941 TEST_ASSERT_NOT_NULL(ut_params->obuf, 6942 "Failed to allocate output buffer in mempool"); 6943 } 6944 6945 if (verify) { 6946 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6947 tdata->ciphertext.data); 6948 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6949 ciphertext_len, buffer); 6950 debug_hexdump(stdout, "ciphertext:", ciphertext, 6951 ciphertext_len); 6952 } else { 6953 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6954 tdata->plaintext.data); 6955 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6956 plaintext_len, buffer); 6957 debug_hexdump(stdout, "plaintext:", plaintext, 6958 plaintext_len); 6959 } 6960 memset(buffer, 0, sizeof(buffer)); 6961 6962 /* Create the operation */ 6963 retval = create_wireless_algo_auth_cipher_operation( 6964 tdata->digest_enc.data, tdata->digest_enc.len, 6965 tdata->cipher_iv.data, tdata->cipher_iv.len, 6966 tdata->auth_iv.data, tdata->auth_iv.len, 6967 (tdata->digest_enc.offset == 0 ? 6968 plaintext_pad_len 6969 : tdata->digest_enc.offset), 6970 tdata->validCipherLen.len_bits, 6971 tdata->cipher.offset_bits, 6972 tdata->validAuthLen.len_bits, 6973 tdata->auth.offset_bits, 6974 op_mode, 1, verify); 6975 6976 if (retval < 0) 6977 return retval; 6978 6979 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6980 ut_params->op); 6981 6982 /* Check if the op failed because the device doesn't */ 6983 /* support this particular combination of algorithms */ 6984 if (ut_params->op == NULL && ut_params->op->status == 6985 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 6986 printf("Device doesn't support this mixed combination. " 6987 "Test Skipped.\n"); 6988 return -ENOTSUP; 6989 } 6990 6991 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6992 6993 ut_params->obuf = (op_mode == IN_PLACE ? 6994 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6995 6996 if (verify) { 6997 if (ut_params->obuf) 6998 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 6999 plaintext_len, buffer); 7000 else 7001 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7002 plaintext_len, buffer); 7003 7004 debug_hexdump(stdout, "plaintext:", plaintext, 7005 (tdata->plaintext.len_bits >> 3) - 7006 tdata->digest_enc.len); 7007 debug_hexdump(stdout, "plaintext expected:", 7008 tdata->plaintext.data, 7009 (tdata->plaintext.len_bits >> 3) - 7010 tdata->digest_enc.len); 7011 } else { 7012 if (ut_params->obuf) 7013 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 7014 ciphertext_len, buffer); 7015 else 7016 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7017 ciphertext_len, buffer); 7018 7019 debug_hexdump(stdout, "ciphertext:", ciphertext, 7020 ciphertext_len); 7021 debug_hexdump(stdout, "ciphertext expected:", 7022 tdata->ciphertext.data, 7023 tdata->ciphertext.len_bits >> 3); 7024 7025 if (ut_params->obuf) 7026 digest = rte_pktmbuf_read(ut_params->obuf, 7027 (tdata->digest_enc.offset == 0 ? 7028 plaintext_pad_len : 7029 tdata->digest_enc.offset), 7030 tdata->digest_enc.len, digest_buffer); 7031 else 7032 digest = rte_pktmbuf_read(ut_params->ibuf, 7033 (tdata->digest_enc.offset == 0 ? 7034 plaintext_pad_len : 7035 tdata->digest_enc.offset), 7036 tdata->digest_enc.len, digest_buffer); 7037 7038 debug_hexdump(stdout, "digest:", digest, 7039 tdata->digest_enc.len); 7040 debug_hexdump(stdout, "digest expected:", 7041 tdata->digest_enc.data, tdata->digest_enc.len); 7042 } 7043 7044 /* Validate obuf */ 7045 if (verify) { 7046 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7047 plaintext, 7048 tdata->plaintext.data, 7049 tdata->plaintext.len_bits >> 3, 7050 "Plaintext data not as expected"); 7051 } else { 7052 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7053 ciphertext, 7054 tdata->ciphertext.data, 7055 tdata->validDataLen.len_bits, 7056 "Ciphertext data not as expected"); 7057 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7058 digest, 7059 tdata->digest_enc.data, 7060 tdata->digest_enc.len, 7061 "Generated auth tag not as expected"); 7062 } 7063 7064 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7065 "crypto op processing failed"); 7066 7067 return 0; 7068 } 7069 7070 /** AUTH AES CMAC + CIPHER AES CTR */ 7071 7072 static int 7073 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7074 { 7075 return test_mixed_auth_cipher( 7076 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7077 } 7078 7079 static int 7080 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7081 { 7082 return test_mixed_auth_cipher( 7083 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7084 } 7085 7086 static int 7087 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7088 { 7089 return test_mixed_auth_cipher_sgl( 7090 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7091 } 7092 7093 static int 7094 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7095 { 7096 return test_mixed_auth_cipher_sgl( 7097 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7098 } 7099 7100 static int 7101 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7102 { 7103 return test_mixed_auth_cipher( 7104 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7105 } 7106 7107 static int 7108 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7109 { 7110 return test_mixed_auth_cipher( 7111 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7112 } 7113 7114 static int 7115 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7116 { 7117 return test_mixed_auth_cipher_sgl( 7118 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7119 } 7120 7121 static int 7122 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7123 { 7124 return test_mixed_auth_cipher_sgl( 7125 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7126 } 7127 7128 /** MIXED AUTH + CIPHER */ 7129 7130 static int 7131 test_auth_zuc_cipher_snow_test_case_1(void) 7132 { 7133 return test_mixed_auth_cipher( 7134 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7135 } 7136 7137 static int 7138 test_verify_auth_zuc_cipher_snow_test_case_1(void) 7139 { 7140 return test_mixed_auth_cipher( 7141 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7142 } 7143 7144 static int 7145 test_auth_aes_cmac_cipher_snow_test_case_1(void) 7146 { 7147 return test_mixed_auth_cipher( 7148 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7149 } 7150 7151 static int 7152 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void) 7153 { 7154 return test_mixed_auth_cipher( 7155 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7156 } 7157 7158 static int 7159 test_auth_zuc_cipher_aes_ctr_test_case_1(void) 7160 { 7161 return test_mixed_auth_cipher( 7162 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7163 } 7164 7165 static int 7166 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void) 7167 { 7168 return test_mixed_auth_cipher( 7169 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7170 } 7171 7172 static int 7173 test_auth_snow_cipher_aes_ctr_test_case_1(void) 7174 { 7175 return test_mixed_auth_cipher( 7176 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7177 } 7178 7179 static int 7180 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void) 7181 { 7182 return test_mixed_auth_cipher( 7183 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7184 } 7185 7186 static int 7187 test_auth_snow_cipher_zuc_test_case_1(void) 7188 { 7189 return test_mixed_auth_cipher( 7190 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7191 } 7192 7193 static int 7194 test_verify_auth_snow_cipher_zuc_test_case_1(void) 7195 { 7196 return test_mixed_auth_cipher( 7197 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7198 } 7199 7200 static int 7201 test_auth_aes_cmac_cipher_zuc_test_case_1(void) 7202 { 7203 return test_mixed_auth_cipher( 7204 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7205 } 7206 7207 static int 7208 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void) 7209 { 7210 return test_mixed_auth_cipher( 7211 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7212 } 7213 7214 static int 7215 test_auth_null_cipher_snow_test_case_1(void) 7216 { 7217 return test_mixed_auth_cipher( 7218 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7219 } 7220 7221 static int 7222 test_verify_auth_null_cipher_snow_test_case_1(void) 7223 { 7224 return test_mixed_auth_cipher( 7225 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7226 } 7227 7228 static int 7229 test_auth_null_cipher_zuc_test_case_1(void) 7230 { 7231 return test_mixed_auth_cipher( 7232 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7233 } 7234 7235 static int 7236 test_verify_auth_null_cipher_zuc_test_case_1(void) 7237 { 7238 return test_mixed_auth_cipher( 7239 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7240 } 7241 7242 static int 7243 test_auth_snow_cipher_null_test_case_1(void) 7244 { 7245 return test_mixed_auth_cipher( 7246 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7247 } 7248 7249 static int 7250 test_verify_auth_snow_cipher_null_test_case_1(void) 7251 { 7252 return test_mixed_auth_cipher( 7253 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7254 } 7255 7256 static int 7257 test_auth_zuc_cipher_null_test_case_1(void) 7258 { 7259 return test_mixed_auth_cipher( 7260 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7261 } 7262 7263 static int 7264 test_verify_auth_zuc_cipher_null_test_case_1(void) 7265 { 7266 return test_mixed_auth_cipher( 7267 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7268 } 7269 7270 static int 7271 test_auth_null_cipher_aes_ctr_test_case_1(void) 7272 { 7273 return test_mixed_auth_cipher( 7274 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7275 } 7276 7277 static int 7278 test_verify_auth_null_cipher_aes_ctr_test_case_1(void) 7279 { 7280 return test_mixed_auth_cipher( 7281 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7282 } 7283 7284 static int 7285 test_auth_aes_cmac_cipher_null_test_case_1(void) 7286 { 7287 return test_mixed_auth_cipher( 7288 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7289 } 7290 7291 static int 7292 test_verify_auth_aes_cmac_cipher_null_test_case_1(void) 7293 { 7294 return test_mixed_auth_cipher( 7295 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7296 } 7297 7298 /* ***** AEAD algorithm Tests ***** */ 7299 7300 static int 7301 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo, 7302 enum rte_crypto_aead_operation op, 7303 const uint8_t *key, const uint8_t key_len, 7304 const uint16_t aad_len, const uint8_t auth_len, 7305 uint8_t iv_len) 7306 { 7307 uint8_t aead_key[key_len]; 7308 7309 struct crypto_testsuite_params *ts_params = &testsuite_params; 7310 struct crypto_unittest_params *ut_params = &unittest_params; 7311 7312 memcpy(aead_key, key, key_len); 7313 7314 /* Setup AEAD Parameters */ 7315 ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 7316 ut_params->aead_xform.next = NULL; 7317 ut_params->aead_xform.aead.algo = algo; 7318 ut_params->aead_xform.aead.op = op; 7319 ut_params->aead_xform.aead.key.data = aead_key; 7320 ut_params->aead_xform.aead.key.length = key_len; 7321 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 7322 ut_params->aead_xform.aead.iv.length = iv_len; 7323 ut_params->aead_xform.aead.digest_length = auth_len; 7324 ut_params->aead_xform.aead.aad_length = aad_len; 7325 7326 debug_hexdump(stdout, "key:", key, key_len); 7327 7328 /* Create Crypto session*/ 7329 ut_params->sess = rte_cryptodev_sym_session_create( 7330 ts_params->session_mpool); 7331 7332 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 7333 &ut_params->aead_xform, 7334 ts_params->session_priv_mpool); 7335 7336 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 7337 7338 return 0; 7339 } 7340 7341 static int 7342 create_aead_xform(struct rte_crypto_op *op, 7343 enum rte_crypto_aead_algorithm algo, 7344 enum rte_crypto_aead_operation aead_op, 7345 uint8_t *key, const uint8_t key_len, 7346 const uint8_t aad_len, const uint8_t auth_len, 7347 uint8_t iv_len) 7348 { 7349 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1), 7350 "failed to allocate space for crypto transform"); 7351 7352 struct rte_crypto_sym_op *sym_op = op->sym; 7353 7354 /* Setup AEAD Parameters */ 7355 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD; 7356 sym_op->xform->next = NULL; 7357 sym_op->xform->aead.algo = algo; 7358 sym_op->xform->aead.op = aead_op; 7359 sym_op->xform->aead.key.data = key; 7360 sym_op->xform->aead.key.length = key_len; 7361 sym_op->xform->aead.iv.offset = IV_OFFSET; 7362 sym_op->xform->aead.iv.length = iv_len; 7363 sym_op->xform->aead.digest_length = auth_len; 7364 sym_op->xform->aead.aad_length = aad_len; 7365 7366 debug_hexdump(stdout, "key:", key, key_len); 7367 7368 return 0; 7369 } 7370 7371 static int 7372 create_aead_operation(enum rte_crypto_aead_operation op, 7373 const struct aead_test_data *tdata) 7374 { 7375 struct crypto_testsuite_params *ts_params = &testsuite_params; 7376 struct crypto_unittest_params *ut_params = &unittest_params; 7377 7378 uint8_t *plaintext, *ciphertext; 7379 unsigned int aad_pad_len, plaintext_pad_len; 7380 7381 /* Generate Crypto op data structure */ 7382 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 7383 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 7384 TEST_ASSERT_NOT_NULL(ut_params->op, 7385 "Failed to allocate symmetric crypto operation struct"); 7386 7387 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 7388 7389 /* Append aad data */ 7390 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 7391 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16); 7392 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7393 aad_pad_len); 7394 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 7395 "no room to append aad"); 7396 7397 sym_op->aead.aad.phys_addr = 7398 rte_pktmbuf_iova(ut_params->ibuf); 7399 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 7400 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len); 7401 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 7402 tdata->aad.len); 7403 7404 /* Append IV at the end of the crypto operation*/ 7405 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 7406 uint8_t *, IV_OFFSET); 7407 7408 /* Copy IV 1 byte after the IV pointer, according to the API */ 7409 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len); 7410 debug_hexdump(stdout, "iv:", iv_ptr, 7411 tdata->iv.len); 7412 } else { 7413 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 7414 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7415 aad_pad_len); 7416 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 7417 "no room to append aad"); 7418 7419 sym_op->aead.aad.phys_addr = 7420 rte_pktmbuf_iova(ut_params->ibuf); 7421 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len); 7422 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 7423 tdata->aad.len); 7424 7425 /* Append IV at the end of the crypto operation*/ 7426 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 7427 uint8_t *, IV_OFFSET); 7428 7429 if (tdata->iv.len == 0) { 7430 rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH); 7431 debug_hexdump(stdout, "iv:", iv_ptr, 7432 AES_GCM_J0_LENGTH); 7433 } else { 7434 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 7435 debug_hexdump(stdout, "iv:", iv_ptr, 7436 tdata->iv.len); 7437 } 7438 } 7439 7440 /* Append plaintext/ciphertext */ 7441 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 7442 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 7443 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7444 plaintext_pad_len); 7445 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 7446 7447 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 7448 debug_hexdump(stdout, "plaintext:", plaintext, 7449 tdata->plaintext.len); 7450 7451 if (ut_params->obuf) { 7452 ciphertext = (uint8_t *)rte_pktmbuf_append( 7453 ut_params->obuf, 7454 plaintext_pad_len + aad_pad_len); 7455 TEST_ASSERT_NOT_NULL(ciphertext, 7456 "no room to append ciphertext"); 7457 7458 memset(ciphertext + aad_pad_len, 0, 7459 tdata->ciphertext.len); 7460 } 7461 } else { 7462 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); 7463 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7464 plaintext_pad_len); 7465 TEST_ASSERT_NOT_NULL(ciphertext, 7466 "no room to append ciphertext"); 7467 7468 memcpy(ciphertext, tdata->ciphertext.data, 7469 tdata->ciphertext.len); 7470 debug_hexdump(stdout, "ciphertext:", ciphertext, 7471 tdata->ciphertext.len); 7472 7473 if (ut_params->obuf) { 7474 plaintext = (uint8_t *)rte_pktmbuf_append( 7475 ut_params->obuf, 7476 plaintext_pad_len + aad_pad_len); 7477 TEST_ASSERT_NOT_NULL(plaintext, 7478 "no room to append plaintext"); 7479 7480 memset(plaintext + aad_pad_len, 0, 7481 tdata->plaintext.len); 7482 } 7483 } 7484 7485 /* Append digest data */ 7486 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 7487 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 7488 ut_params->obuf ? ut_params->obuf : 7489 ut_params->ibuf, 7490 tdata->auth_tag.len); 7491 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 7492 "no room to append digest"); 7493 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len); 7494 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 7495 ut_params->obuf ? ut_params->obuf : 7496 ut_params->ibuf, 7497 plaintext_pad_len + 7498 aad_pad_len); 7499 } else { 7500 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 7501 ut_params->ibuf, tdata->auth_tag.len); 7502 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 7503 "no room to append digest"); 7504 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 7505 ut_params->ibuf, 7506 plaintext_pad_len + aad_pad_len); 7507 7508 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 7509 tdata->auth_tag.len); 7510 debug_hexdump(stdout, "digest:", 7511 sym_op->aead.digest.data, 7512 tdata->auth_tag.len); 7513 } 7514 7515 sym_op->aead.data.length = tdata->plaintext.len; 7516 sym_op->aead.data.offset = aad_pad_len; 7517 7518 return 0; 7519 } 7520 7521 static int 7522 test_authenticated_encryption(const struct aead_test_data *tdata) 7523 { 7524 struct crypto_testsuite_params *ts_params = &testsuite_params; 7525 struct crypto_unittest_params *ut_params = &unittest_params; 7526 7527 int retval; 7528 uint8_t *ciphertext, *auth_tag; 7529 uint16_t plaintext_pad_len; 7530 uint32_t i; 7531 struct rte_cryptodev_info dev_info; 7532 7533 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7534 uint64_t feat_flags = dev_info.feature_flags; 7535 7536 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 7537 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 7538 printf("Device doesn't support RAW data-path APIs.\n"); 7539 return -ENOTSUP; 7540 } 7541 7542 /* Verify the capabilities */ 7543 struct rte_cryptodev_sym_capability_idx cap_idx; 7544 const struct rte_cryptodev_symmetric_capability *capability; 7545 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 7546 cap_idx.algo.aead = tdata->algo; 7547 capability = rte_cryptodev_sym_capability_get( 7548 ts_params->valid_devs[0], &cap_idx); 7549 if (capability == NULL) 7550 return -ENOTSUP; 7551 if (rte_cryptodev_sym_capability_check_aead( 7552 capability, tdata->key.len, tdata->auth_tag.len, 7553 tdata->aad.len, tdata->iv.len)) 7554 return -ENOTSUP; 7555 7556 /* Create AEAD session */ 7557 retval = create_aead_session(ts_params->valid_devs[0], 7558 tdata->algo, 7559 RTE_CRYPTO_AEAD_OP_ENCRYPT, 7560 tdata->key.data, tdata->key.len, 7561 tdata->aad.len, tdata->auth_tag.len, 7562 tdata->iv.len); 7563 if (retval < 0) 7564 return retval; 7565 7566 if (tdata->aad.len > MBUF_SIZE) { 7567 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 7568 /* Populate full size of add data */ 7569 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 7570 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 7571 } else 7572 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7573 7574 /* clear mbuf payload */ 7575 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7576 rte_pktmbuf_tailroom(ut_params->ibuf)); 7577 7578 /* Create AEAD operation */ 7579 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 7580 if (retval < 0) 7581 return retval; 7582 7583 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 7584 7585 ut_params->op->sym->m_src = ut_params->ibuf; 7586 7587 /* Process crypto operation */ 7588 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 7589 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 7590 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7591 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 7592 ut_params->op, 0, 0, 0, 0); 7593 else 7594 TEST_ASSERT_NOT_NULL( 7595 process_crypto_request(ts_params->valid_devs[0], 7596 ut_params->op), "failed to process sym crypto op"); 7597 7598 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7599 "crypto op processing failed"); 7600 7601 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 7602 7603 if (ut_params->op->sym->m_dst) { 7604 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 7605 uint8_t *); 7606 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 7607 uint8_t *, plaintext_pad_len); 7608 } else { 7609 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 7610 uint8_t *, 7611 ut_params->op->sym->cipher.data.offset); 7612 auth_tag = ciphertext + plaintext_pad_len; 7613 } 7614 7615 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 7616 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 7617 7618 /* Validate obuf */ 7619 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7620 ciphertext, 7621 tdata->ciphertext.data, 7622 tdata->ciphertext.len, 7623 "Ciphertext data not as expected"); 7624 7625 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7626 auth_tag, 7627 tdata->auth_tag.data, 7628 tdata->auth_tag.len, 7629 "Generated auth tag not as expected"); 7630 7631 return 0; 7632 7633 } 7634 7635 #ifdef RTE_LIB_SECURITY 7636 static int 7637 security_proto_supported(enum rte_security_session_action_type action, 7638 enum rte_security_session_protocol proto) 7639 { 7640 struct crypto_testsuite_params *ts_params = &testsuite_params; 7641 7642 const struct rte_security_capability *capabilities; 7643 const struct rte_security_capability *capability; 7644 uint16_t i = 0; 7645 7646 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 7647 rte_cryptodev_get_sec_ctx( 7648 ts_params->valid_devs[0]); 7649 7650 7651 capabilities = rte_security_capabilities_get(ctx); 7652 7653 if (capabilities == NULL) 7654 return -ENOTSUP; 7655 7656 while ((capability = &capabilities[i++])->action != 7657 RTE_SECURITY_ACTION_TYPE_NONE) { 7658 if (capability->action == action && 7659 capability->protocol == proto) 7660 return 0; 7661 } 7662 7663 return -ENOTSUP; 7664 } 7665 7666 /* Basic algorithm run function for async inplace mode. 7667 * Creates a session from input parameters and runs one operation 7668 * on input_vec. Checks the output of the crypto operation against 7669 * output_vec. 7670 */ 7671 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc, 7672 enum rte_crypto_auth_operation opa, 7673 const uint8_t *input_vec, unsigned int input_vec_len, 7674 const uint8_t *output_vec, 7675 unsigned int output_vec_len, 7676 enum rte_crypto_cipher_algorithm cipher_alg, 7677 const uint8_t *cipher_key, uint32_t cipher_key_len, 7678 enum rte_crypto_auth_algorithm auth_alg, 7679 const uint8_t *auth_key, uint32_t auth_key_len, 7680 uint8_t bearer, enum rte_security_pdcp_domain domain, 7681 uint8_t packet_direction, uint8_t sn_size, 7682 uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap) 7683 { 7684 struct crypto_testsuite_params *ts_params = &testsuite_params; 7685 struct crypto_unittest_params *ut_params = &unittest_params; 7686 uint8_t *plaintext; 7687 int ret = TEST_SUCCESS; 7688 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 7689 rte_cryptodev_get_sec_ctx( 7690 ts_params->valid_devs[0]); 7691 7692 /* Verify the capabilities */ 7693 struct rte_security_capability_idx sec_cap_idx; 7694 7695 sec_cap_idx.action = ut_params->type; 7696 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 7697 sec_cap_idx.pdcp.domain = domain; 7698 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 7699 return -ENOTSUP; 7700 7701 /* Generate test mbuf data */ 7702 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7703 7704 /* clear mbuf payload */ 7705 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7706 rte_pktmbuf_tailroom(ut_params->ibuf)); 7707 7708 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7709 input_vec_len); 7710 memcpy(plaintext, input_vec, input_vec_len); 7711 7712 /* Out of place support */ 7713 if (oop) { 7714 /* 7715 * For out-op-place we need to alloc another mbuf 7716 */ 7717 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7718 rte_pktmbuf_append(ut_params->obuf, output_vec_len); 7719 } 7720 7721 /* Setup Cipher Parameters */ 7722 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 7723 ut_params->cipher_xform.cipher.algo = cipher_alg; 7724 ut_params->cipher_xform.cipher.op = opc; 7725 ut_params->cipher_xform.cipher.key.data = cipher_key; 7726 ut_params->cipher_xform.cipher.key.length = cipher_key_len; 7727 ut_params->cipher_xform.cipher.iv.length = 7728 packet_direction ? 4 : 0; 7729 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 7730 7731 /* Setup HMAC Parameters if ICV header is required */ 7732 if (auth_alg != 0) { 7733 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 7734 ut_params->auth_xform.next = NULL; 7735 ut_params->auth_xform.auth.algo = auth_alg; 7736 ut_params->auth_xform.auth.op = opa; 7737 ut_params->auth_xform.auth.key.data = auth_key; 7738 ut_params->auth_xform.auth.key.length = auth_key_len; 7739 7740 ut_params->cipher_xform.next = &ut_params->auth_xform; 7741 } else { 7742 ut_params->cipher_xform.next = NULL; 7743 } 7744 7745 struct rte_security_session_conf sess_conf = { 7746 .action_type = ut_params->type, 7747 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 7748 {.pdcp = { 7749 .bearer = bearer, 7750 .domain = domain, 7751 .pkt_dir = packet_direction, 7752 .sn_size = sn_size, 7753 .hfn = packet_direction ? 0 : hfn, 7754 /** 7755 * hfn can be set as pdcp_test_hfn[i] 7756 * if hfn_ovrd is not set. Here, PDCP 7757 * packet direction is just used to 7758 * run half of the cases with session 7759 * HFN and other half with per packet 7760 * HFN. 7761 */ 7762 .hfn_threshold = hfn_threshold, 7763 .hfn_ovrd = packet_direction ? 1 : 0, 7764 .sdap_enabled = sdap, 7765 } }, 7766 .crypto_xform = &ut_params->cipher_xform 7767 }; 7768 7769 /* Create security session */ 7770 ut_params->sec_session = rte_security_session_create(ctx, 7771 &sess_conf, ts_params->session_mpool, 7772 ts_params->session_priv_mpool); 7773 7774 if (!ut_params->sec_session) { 7775 printf("TestCase %s()-%d line %d failed %s: ", 7776 __func__, i, __LINE__, "Failed to allocate session"); 7777 ret = TEST_FAILED; 7778 goto on_err; 7779 } 7780 7781 /* Generate crypto op data structure */ 7782 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 7783 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 7784 if (!ut_params->op) { 7785 printf("TestCase %s()-%d line %d failed %s: ", 7786 __func__, i, __LINE__, 7787 "Failed to allocate symmetric crypto operation struct"); 7788 ret = TEST_FAILED; 7789 goto on_err; 7790 } 7791 7792 uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op, 7793 uint32_t *, IV_OFFSET); 7794 *per_pkt_hfn = packet_direction ? hfn : 0; 7795 7796 rte_security_attach_session(ut_params->op, ut_params->sec_session); 7797 7798 /* set crypto operation source mbuf */ 7799 ut_params->op->sym->m_src = ut_params->ibuf; 7800 if (oop) 7801 ut_params->op->sym->m_dst = ut_params->obuf; 7802 7803 /* Process crypto operation */ 7804 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) 7805 == NULL) { 7806 printf("TestCase %s()-%d line %d failed %s: ", 7807 __func__, i, __LINE__, 7808 "failed to process sym crypto op"); 7809 ret = TEST_FAILED; 7810 goto on_err; 7811 } 7812 7813 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 7814 printf("TestCase %s()-%d line %d failed %s: ", 7815 __func__, i, __LINE__, "crypto op processing failed"); 7816 ret = TEST_FAILED; 7817 goto on_err; 7818 } 7819 7820 /* Validate obuf */ 7821 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 7822 uint8_t *); 7823 if (oop) { 7824 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 7825 uint8_t *); 7826 } 7827 7828 if (memcmp(ciphertext, output_vec, output_vec_len)) { 7829 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 7830 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len); 7831 rte_hexdump(stdout, "reference", output_vec, output_vec_len); 7832 ret = TEST_FAILED; 7833 goto on_err; 7834 } 7835 7836 on_err: 7837 rte_crypto_op_free(ut_params->op); 7838 ut_params->op = NULL; 7839 7840 if (ut_params->sec_session) 7841 rte_security_session_destroy(ctx, ut_params->sec_session); 7842 ut_params->sec_session = NULL; 7843 7844 rte_pktmbuf_free(ut_params->ibuf); 7845 ut_params->ibuf = NULL; 7846 if (oop) { 7847 rte_pktmbuf_free(ut_params->obuf); 7848 ut_params->obuf = NULL; 7849 } 7850 7851 return ret; 7852 } 7853 7854 static int 7855 test_pdcp_proto_SGL(int i, int oop, 7856 enum rte_crypto_cipher_operation opc, 7857 enum rte_crypto_auth_operation opa, 7858 uint8_t *input_vec, 7859 unsigned int input_vec_len, 7860 uint8_t *output_vec, 7861 unsigned int output_vec_len, 7862 uint32_t fragsz, 7863 uint32_t fragsz_oop) 7864 { 7865 struct crypto_testsuite_params *ts_params = &testsuite_params; 7866 struct crypto_unittest_params *ut_params = &unittest_params; 7867 uint8_t *plaintext; 7868 struct rte_mbuf *buf, *buf_oop = NULL; 7869 int ret = TEST_SUCCESS; 7870 int to_trn = 0; 7871 int to_trn_tbl[16]; 7872 int segs = 1; 7873 unsigned int trn_data = 0; 7874 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 7875 rte_cryptodev_get_sec_ctx( 7876 ts_params->valid_devs[0]); 7877 7878 /* Verify the capabilities */ 7879 struct rte_security_capability_idx sec_cap_idx; 7880 7881 sec_cap_idx.action = ut_params->type; 7882 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 7883 sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain; 7884 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 7885 return -ENOTSUP; 7886 7887 if (fragsz > input_vec_len) 7888 fragsz = input_vec_len; 7889 7890 uint16_t plaintext_len = fragsz; 7891 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 7892 7893 if (fragsz_oop > output_vec_len) 7894 frag_size_oop = output_vec_len; 7895 7896 int ecx = 0; 7897 if (input_vec_len % fragsz != 0) { 7898 if (input_vec_len / fragsz + 1 > 16) 7899 return 1; 7900 } else if (input_vec_len / fragsz > 16) 7901 return 1; 7902 7903 /* Out of place support */ 7904 if (oop) { 7905 /* 7906 * For out-op-place we need to alloc another mbuf 7907 */ 7908 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7909 rte_pktmbuf_append(ut_params->obuf, frag_size_oop); 7910 buf_oop = ut_params->obuf; 7911 } 7912 7913 /* Generate test mbuf data */ 7914 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7915 7916 /* clear mbuf payload */ 7917 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7918 rte_pktmbuf_tailroom(ut_params->ibuf)); 7919 7920 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7921 plaintext_len); 7922 memcpy(plaintext, input_vec, plaintext_len); 7923 trn_data += plaintext_len; 7924 7925 buf = ut_params->ibuf; 7926 7927 /* 7928 * Loop until no more fragments 7929 */ 7930 7931 while (trn_data < input_vec_len) { 7932 ++segs; 7933 to_trn = (input_vec_len - trn_data < fragsz) ? 7934 (input_vec_len - trn_data) : fragsz; 7935 7936 to_trn_tbl[ecx++] = to_trn; 7937 7938 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7939 buf = buf->next; 7940 7941 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 7942 rte_pktmbuf_tailroom(buf)); 7943 7944 /* OOP */ 7945 if (oop && !fragsz_oop) { 7946 buf_oop->next = 7947 rte_pktmbuf_alloc(ts_params->mbuf_pool); 7948 buf_oop = buf_oop->next; 7949 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 7950 0, rte_pktmbuf_tailroom(buf_oop)); 7951 rte_pktmbuf_append(buf_oop, to_trn); 7952 } 7953 7954 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 7955 to_trn); 7956 7957 memcpy(plaintext, input_vec + trn_data, to_trn); 7958 trn_data += to_trn; 7959 } 7960 7961 ut_params->ibuf->nb_segs = segs; 7962 7963 segs = 1; 7964 if (fragsz_oop && oop) { 7965 to_trn = 0; 7966 ecx = 0; 7967 7968 trn_data = frag_size_oop; 7969 while (trn_data < output_vec_len) { 7970 ++segs; 7971 to_trn = 7972 (output_vec_len - trn_data < 7973 frag_size_oop) ? 7974 (output_vec_len - trn_data) : 7975 frag_size_oop; 7976 7977 to_trn_tbl[ecx++] = to_trn; 7978 7979 buf_oop->next = 7980 rte_pktmbuf_alloc(ts_params->mbuf_pool); 7981 buf_oop = buf_oop->next; 7982 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 7983 0, rte_pktmbuf_tailroom(buf_oop)); 7984 rte_pktmbuf_append(buf_oop, to_trn); 7985 7986 trn_data += to_trn; 7987 } 7988 ut_params->obuf->nb_segs = segs; 7989 } 7990 7991 /* Setup Cipher Parameters */ 7992 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 7993 ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg; 7994 ut_params->cipher_xform.cipher.op = opc; 7995 ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i]; 7996 ut_params->cipher_xform.cipher.key.length = 7997 pdcp_test_params[i].cipher_key_len; 7998 ut_params->cipher_xform.cipher.iv.length = 0; 7999 8000 /* Setup HMAC Parameters if ICV header is required */ 8001 if (pdcp_test_params[i].auth_alg != 0) { 8002 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8003 ut_params->auth_xform.next = NULL; 8004 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg; 8005 ut_params->auth_xform.auth.op = opa; 8006 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i]; 8007 ut_params->auth_xform.auth.key.length = 8008 pdcp_test_params[i].auth_key_len; 8009 8010 ut_params->cipher_xform.next = &ut_params->auth_xform; 8011 } else { 8012 ut_params->cipher_xform.next = NULL; 8013 } 8014 8015 struct rte_security_session_conf sess_conf = { 8016 .action_type = ut_params->type, 8017 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 8018 {.pdcp = { 8019 .bearer = pdcp_test_bearer[i], 8020 .domain = pdcp_test_params[i].domain, 8021 .pkt_dir = pdcp_test_packet_direction[i], 8022 .sn_size = pdcp_test_data_sn_size[i], 8023 .hfn = pdcp_test_hfn[i], 8024 .hfn_threshold = pdcp_test_hfn_threshold[i], 8025 .hfn_ovrd = 0, 8026 } }, 8027 .crypto_xform = &ut_params->cipher_xform 8028 }; 8029 8030 /* Create security session */ 8031 ut_params->sec_session = rte_security_session_create(ctx, 8032 &sess_conf, ts_params->session_mpool, 8033 ts_params->session_priv_mpool); 8034 8035 if (!ut_params->sec_session) { 8036 printf("TestCase %s()-%d line %d failed %s: ", 8037 __func__, i, __LINE__, "Failed to allocate session"); 8038 ret = TEST_FAILED; 8039 goto on_err; 8040 } 8041 8042 /* Generate crypto op data structure */ 8043 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8044 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8045 if (!ut_params->op) { 8046 printf("TestCase %s()-%d line %d failed %s: ", 8047 __func__, i, __LINE__, 8048 "Failed to allocate symmetric crypto operation struct"); 8049 ret = TEST_FAILED; 8050 goto on_err; 8051 } 8052 8053 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8054 8055 /* set crypto operation source mbuf */ 8056 ut_params->op->sym->m_src = ut_params->ibuf; 8057 if (oop) 8058 ut_params->op->sym->m_dst = ut_params->obuf; 8059 8060 /* Process crypto operation */ 8061 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) 8062 == NULL) { 8063 printf("TestCase %s()-%d line %d failed %s: ", 8064 __func__, i, __LINE__, 8065 "failed to process sym crypto op"); 8066 ret = TEST_FAILED; 8067 goto on_err; 8068 } 8069 8070 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8071 printf("TestCase %s()-%d line %d failed %s: ", 8072 __func__, i, __LINE__, "crypto op processing failed"); 8073 ret = TEST_FAILED; 8074 goto on_err; 8075 } 8076 8077 /* Validate obuf */ 8078 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 8079 uint8_t *); 8080 if (oop) { 8081 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8082 uint8_t *); 8083 } 8084 if (fragsz_oop) 8085 fragsz = frag_size_oop; 8086 if (memcmp(ciphertext, output_vec, fragsz)) { 8087 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8088 rte_hexdump(stdout, "encrypted", ciphertext, fragsz); 8089 rte_hexdump(stdout, "reference", output_vec, fragsz); 8090 ret = TEST_FAILED; 8091 goto on_err; 8092 } 8093 8094 buf = ut_params->op->sym->m_src->next; 8095 if (oop) 8096 buf = ut_params->op->sym->m_dst->next; 8097 8098 unsigned int off = fragsz; 8099 8100 ecx = 0; 8101 while (buf) { 8102 ciphertext = rte_pktmbuf_mtod(buf, 8103 uint8_t *); 8104 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) { 8105 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8106 rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]); 8107 rte_hexdump(stdout, "reference", output_vec + off, 8108 to_trn_tbl[ecx]); 8109 ret = TEST_FAILED; 8110 goto on_err; 8111 } 8112 off += to_trn_tbl[ecx++]; 8113 buf = buf->next; 8114 } 8115 on_err: 8116 rte_crypto_op_free(ut_params->op); 8117 ut_params->op = NULL; 8118 8119 if (ut_params->sec_session) 8120 rte_security_session_destroy(ctx, ut_params->sec_session); 8121 ut_params->sec_session = NULL; 8122 8123 rte_pktmbuf_free(ut_params->ibuf); 8124 ut_params->ibuf = NULL; 8125 if (oop) { 8126 rte_pktmbuf_free(ut_params->obuf); 8127 ut_params->obuf = NULL; 8128 } 8129 8130 return ret; 8131 } 8132 8133 int 8134 test_pdcp_proto_cplane_encap(int i) 8135 { 8136 return test_pdcp_proto( 8137 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8138 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8139 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8140 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8141 pdcp_test_params[i].cipher_key_len, 8142 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8143 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8144 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8145 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8146 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8147 } 8148 8149 int 8150 test_pdcp_proto_uplane_encap(int i) 8151 { 8152 return test_pdcp_proto( 8153 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8154 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8155 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 8156 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8157 pdcp_test_params[i].cipher_key_len, 8158 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8159 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8160 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8161 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8162 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8163 } 8164 8165 int 8166 test_pdcp_proto_uplane_encap_with_int(int i) 8167 { 8168 return test_pdcp_proto( 8169 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8170 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8171 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8172 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8173 pdcp_test_params[i].cipher_key_len, 8174 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8175 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8176 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8177 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8178 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8179 } 8180 8181 int 8182 test_pdcp_proto_cplane_decap(int i) 8183 { 8184 return test_pdcp_proto( 8185 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8186 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8187 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8188 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8189 pdcp_test_params[i].cipher_key_len, 8190 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8191 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8192 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8193 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8194 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8195 } 8196 8197 int 8198 test_pdcp_proto_uplane_decap(int i) 8199 { 8200 return test_pdcp_proto( 8201 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8202 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 8203 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8204 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8205 pdcp_test_params[i].cipher_key_len, 8206 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8207 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8208 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8209 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8210 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8211 } 8212 8213 int 8214 test_pdcp_proto_uplane_decap_with_int(int i) 8215 { 8216 return test_pdcp_proto( 8217 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8218 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8219 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8220 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8221 pdcp_test_params[i].cipher_key_len, 8222 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8223 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8224 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8225 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8226 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8227 } 8228 8229 static int 8230 test_PDCP_PROTO_SGL_in_place_32B(void) 8231 { 8232 /* i can be used for running any PDCP case 8233 * In this case it is uplane 12-bit AES-SNOW DL encap 8234 */ 8235 int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK; 8236 return test_pdcp_proto_SGL(i, IN_PLACE, 8237 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8238 RTE_CRYPTO_AUTH_OP_GENERATE, 8239 pdcp_test_data_in[i], 8240 pdcp_test_data_in_len[i], 8241 pdcp_test_data_out[i], 8242 pdcp_test_data_in_len[i]+4, 8243 32, 0); 8244 } 8245 static int 8246 test_PDCP_PROTO_SGL_oop_32B_128B(void) 8247 { 8248 /* i can be used for running any PDCP case 8249 * In this case it is uplane 18-bit NULL-NULL DL encap 8250 */ 8251 int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK; 8252 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8253 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8254 RTE_CRYPTO_AUTH_OP_GENERATE, 8255 pdcp_test_data_in[i], 8256 pdcp_test_data_in_len[i], 8257 pdcp_test_data_out[i], 8258 pdcp_test_data_in_len[i]+4, 8259 32, 128); 8260 } 8261 static int 8262 test_PDCP_PROTO_SGL_oop_32B_40B(void) 8263 { 8264 /* i can be used for running any PDCP case 8265 * In this case it is uplane 18-bit AES DL encap 8266 */ 8267 int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET 8268 + DOWNLINK; 8269 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8270 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8271 RTE_CRYPTO_AUTH_OP_GENERATE, 8272 pdcp_test_data_in[i], 8273 pdcp_test_data_in_len[i], 8274 pdcp_test_data_out[i], 8275 pdcp_test_data_in_len[i], 8276 32, 40); 8277 } 8278 static int 8279 test_PDCP_PROTO_SGL_oop_128B_32B(void) 8280 { 8281 /* i can be used for running any PDCP case 8282 * In this case it is cplane 12-bit AES-ZUC DL encap 8283 */ 8284 int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK; 8285 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8286 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8287 RTE_CRYPTO_AUTH_OP_GENERATE, 8288 pdcp_test_data_in[i], 8289 pdcp_test_data_in_len[i], 8290 pdcp_test_data_out[i], 8291 pdcp_test_data_in_len[i]+4, 8292 128, 32); 8293 } 8294 8295 static int 8296 test_PDCP_SDAP_PROTO_encap_all(void) 8297 { 8298 int i = 0, size = 0; 8299 int err, all_err = TEST_SUCCESS; 8300 const struct pdcp_sdap_test *cur_test; 8301 8302 size = ARRAY_SIZE(list_pdcp_sdap_tests); 8303 8304 for (i = 0; i < size; i++) { 8305 cur_test = &list_pdcp_sdap_tests[i]; 8306 err = test_pdcp_proto( 8307 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8308 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 8309 cur_test->in_len, cur_test->data_out, 8310 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 8311 cur_test->param.cipher_alg, cur_test->cipher_key, 8312 cur_test->param.cipher_key_len, 8313 cur_test->param.auth_alg, 8314 cur_test->auth_key, cur_test->param.auth_key_len, 8315 cur_test->bearer, cur_test->param.domain, 8316 cur_test->packet_direction, cur_test->sn_size, 8317 cur_test->hfn, 8318 cur_test->hfn_threshold, SDAP_ENABLED); 8319 if (err) { 8320 printf("\t%d) %s: Encapsulation failed\n", 8321 cur_test->test_idx, 8322 cur_test->param.name); 8323 err = TEST_FAILED; 8324 } else { 8325 printf("\t%d) %s: Encap PASS\n", cur_test->test_idx, 8326 cur_test->param.name); 8327 err = TEST_SUCCESS; 8328 } 8329 all_err += err; 8330 } 8331 8332 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 8333 8334 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 8335 } 8336 8337 static int 8338 test_PDCP_SDAP_PROTO_decap_all(void) 8339 { 8340 int i = 0, size = 0; 8341 int err, all_err = TEST_SUCCESS; 8342 const struct pdcp_sdap_test *cur_test; 8343 8344 size = ARRAY_SIZE(list_pdcp_sdap_tests); 8345 8346 for (i = 0; i < size; i++) { 8347 cur_test = &list_pdcp_sdap_tests[i]; 8348 err = test_pdcp_proto( 8349 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, 8350 RTE_CRYPTO_AUTH_OP_VERIFY, 8351 cur_test->data_out, 8352 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 8353 cur_test->data_in, cur_test->in_len, 8354 cur_test->param.cipher_alg, 8355 cur_test->cipher_key, cur_test->param.cipher_key_len, 8356 cur_test->param.auth_alg, cur_test->auth_key, 8357 cur_test->param.auth_key_len, cur_test->bearer, 8358 cur_test->param.domain, cur_test->packet_direction, 8359 cur_test->sn_size, cur_test->hfn, 8360 cur_test->hfn_threshold, SDAP_ENABLED); 8361 if (err) { 8362 printf("\t%d) %s: Decapsulation failed\n", 8363 cur_test->test_idx, 8364 cur_test->param.name); 8365 err = TEST_FAILED; 8366 } else { 8367 printf("\t%d) %s: Decap PASS\n", cur_test->test_idx, 8368 cur_test->param.name); 8369 err = TEST_SUCCESS; 8370 } 8371 all_err += err; 8372 } 8373 8374 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 8375 8376 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 8377 } 8378 8379 static int 8380 test_PDCP_PROTO_all(void) 8381 { 8382 struct crypto_testsuite_params *ts_params = &testsuite_params; 8383 struct crypto_unittest_params *ut_params = &unittest_params; 8384 struct rte_cryptodev_info dev_info; 8385 int status; 8386 8387 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8388 uint64_t feat_flags = dev_info.feature_flags; 8389 8390 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 8391 return -ENOTSUP; 8392 8393 /* Set action type */ 8394 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 8395 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 8396 gbl_action_type; 8397 8398 if (security_proto_supported(ut_params->type, 8399 RTE_SECURITY_PROTOCOL_PDCP) < 0) 8400 return -ENOTSUP; 8401 8402 status = test_PDCP_PROTO_cplane_encap_all(); 8403 status += test_PDCP_PROTO_cplane_decap_all(); 8404 status += test_PDCP_PROTO_uplane_encap_all(); 8405 status += test_PDCP_PROTO_uplane_decap_all(); 8406 status += test_PDCP_PROTO_SGL_in_place_32B(); 8407 status += test_PDCP_PROTO_SGL_oop_32B_128B(); 8408 status += test_PDCP_PROTO_SGL_oop_32B_40B(); 8409 status += test_PDCP_PROTO_SGL_oop_128B_32B(); 8410 status += test_PDCP_SDAP_PROTO_encap_all(); 8411 status += test_PDCP_SDAP_PROTO_decap_all(); 8412 8413 if (status) 8414 return TEST_FAILED; 8415 else 8416 return TEST_SUCCESS; 8417 } 8418 8419 static int 8420 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td) 8421 { 8422 struct crypto_testsuite_params *ts_params = &testsuite_params; 8423 struct crypto_unittest_params *ut_params = &unittest_params; 8424 uint8_t *plaintext, *ciphertext; 8425 uint8_t *iv_ptr; 8426 int32_t cipher_len, crc_len; 8427 uint32_t crc_data_len; 8428 int ret = TEST_SUCCESS; 8429 8430 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8431 rte_cryptodev_get_sec_ctx( 8432 ts_params->valid_devs[0]); 8433 8434 /* Verify the capabilities */ 8435 struct rte_security_capability_idx sec_cap_idx; 8436 const struct rte_security_capability *sec_cap; 8437 const struct rte_cryptodev_capabilities *crypto_cap; 8438 const struct rte_cryptodev_symmetric_capability *sym_cap; 8439 int j = 0; 8440 8441 sec_cap_idx.action = ut_params->type; 8442 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 8443 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK; 8444 8445 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 8446 if (sec_cap == NULL) 8447 return -ENOTSUP; 8448 8449 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 8450 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 8451 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 8452 crypto_cap->sym.xform_type == 8453 RTE_CRYPTO_SYM_XFORM_CIPHER && 8454 crypto_cap->sym.cipher.algo == 8455 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 8456 sym_cap = &crypto_cap->sym; 8457 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 8458 d_td->key.len, 8459 d_td->iv.len) == 0) 8460 break; 8461 } 8462 } 8463 8464 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 8465 return -ENOTSUP; 8466 8467 /* Setup source mbuf payload */ 8468 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8469 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8470 rte_pktmbuf_tailroom(ut_params->ibuf)); 8471 8472 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8473 d_td->ciphertext.len); 8474 8475 memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len); 8476 8477 /* Setup cipher session parameters */ 8478 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8479 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 8480 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 8481 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 8482 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 8483 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 8484 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 8485 ut_params->cipher_xform.next = NULL; 8486 8487 /* Setup DOCSIS session parameters */ 8488 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK; 8489 8490 struct rte_security_session_conf sess_conf = { 8491 .action_type = ut_params->type, 8492 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 8493 .docsis = ut_params->docsis_xform, 8494 .crypto_xform = &ut_params->cipher_xform, 8495 }; 8496 8497 /* Create security session */ 8498 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 8499 ts_params->session_mpool, 8500 ts_params->session_priv_mpool); 8501 8502 if (!ut_params->sec_session) { 8503 printf("TestCase %s(%d) line %d: %s\n", 8504 __func__, i, __LINE__, "failed to allocate session"); 8505 ret = TEST_FAILED; 8506 goto on_err; 8507 } 8508 8509 /* Generate crypto op data structure */ 8510 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8511 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8512 if (!ut_params->op) { 8513 printf("TestCase %s(%d) line %d: %s\n", 8514 __func__, i, __LINE__, 8515 "failed to allocate symmetric crypto operation"); 8516 ret = TEST_FAILED; 8517 goto on_err; 8518 } 8519 8520 /* Setup CRC operation parameters */ 8521 crc_len = d_td->ciphertext.no_crc == false ? 8522 (d_td->ciphertext.len - 8523 d_td->ciphertext.crc_offset - 8524 RTE_ETHER_CRC_LEN) : 8525 0; 8526 crc_len = crc_len > 0 ? crc_len : 0; 8527 crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN; 8528 ut_params->op->sym->auth.data.length = crc_len; 8529 ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset; 8530 8531 /* Setup cipher operation parameters */ 8532 cipher_len = d_td->ciphertext.no_cipher == false ? 8533 (d_td->ciphertext.len - 8534 d_td->ciphertext.cipher_offset) : 8535 0; 8536 cipher_len = cipher_len > 0 ? cipher_len : 0; 8537 ut_params->op->sym->cipher.data.length = cipher_len; 8538 ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset; 8539 8540 /* Setup cipher IV */ 8541 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 8542 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 8543 8544 /* Attach session to operation */ 8545 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8546 8547 /* Set crypto operation mbufs */ 8548 ut_params->op->sym->m_src = ut_params->ibuf; 8549 ut_params->op->sym->m_dst = NULL; 8550 8551 /* Process crypto operation */ 8552 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 8553 NULL) { 8554 printf("TestCase %s(%d) line %d: %s\n", 8555 __func__, i, __LINE__, 8556 "failed to process security crypto op"); 8557 ret = TEST_FAILED; 8558 goto on_err; 8559 } 8560 8561 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8562 printf("TestCase %s(%d) line %d: %s\n", 8563 __func__, i, __LINE__, "crypto op processing failed"); 8564 ret = TEST_FAILED; 8565 goto on_err; 8566 } 8567 8568 /* Validate plaintext */ 8569 plaintext = ciphertext; 8570 8571 if (memcmp(plaintext, d_td->plaintext.data, 8572 d_td->plaintext.len - crc_data_len)) { 8573 printf("TestCase %s(%d) line %d: %s\n", 8574 __func__, i, __LINE__, "plaintext not as expected\n"); 8575 rte_hexdump(stdout, "expected", d_td->plaintext.data, 8576 d_td->plaintext.len); 8577 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len); 8578 ret = TEST_FAILED; 8579 goto on_err; 8580 } 8581 8582 on_err: 8583 rte_crypto_op_free(ut_params->op); 8584 ut_params->op = NULL; 8585 8586 if (ut_params->sec_session) 8587 rte_security_session_destroy(ctx, ut_params->sec_session); 8588 ut_params->sec_session = NULL; 8589 8590 rte_pktmbuf_free(ut_params->ibuf); 8591 ut_params->ibuf = NULL; 8592 8593 return ret; 8594 } 8595 8596 static int 8597 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td) 8598 { 8599 struct crypto_testsuite_params *ts_params = &testsuite_params; 8600 struct crypto_unittest_params *ut_params = &unittest_params; 8601 uint8_t *plaintext, *ciphertext; 8602 uint8_t *iv_ptr; 8603 int32_t cipher_len, crc_len; 8604 int ret = TEST_SUCCESS; 8605 8606 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8607 rte_cryptodev_get_sec_ctx( 8608 ts_params->valid_devs[0]); 8609 8610 /* Verify the capabilities */ 8611 struct rte_security_capability_idx sec_cap_idx; 8612 const struct rte_security_capability *sec_cap; 8613 const struct rte_cryptodev_capabilities *crypto_cap; 8614 const struct rte_cryptodev_symmetric_capability *sym_cap; 8615 int j = 0; 8616 8617 sec_cap_idx.action = ut_params->type; 8618 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 8619 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 8620 8621 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 8622 if (sec_cap == NULL) 8623 return -ENOTSUP; 8624 8625 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 8626 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 8627 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 8628 crypto_cap->sym.xform_type == 8629 RTE_CRYPTO_SYM_XFORM_CIPHER && 8630 crypto_cap->sym.cipher.algo == 8631 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 8632 sym_cap = &crypto_cap->sym; 8633 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 8634 d_td->key.len, 8635 d_td->iv.len) == 0) 8636 break; 8637 } 8638 } 8639 8640 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 8641 return -ENOTSUP; 8642 8643 /* Setup source mbuf payload */ 8644 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8645 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8646 rte_pktmbuf_tailroom(ut_params->ibuf)); 8647 8648 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8649 d_td->plaintext.len); 8650 8651 memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len); 8652 8653 /* Setup cipher session parameters */ 8654 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8655 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 8656 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 8657 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 8658 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 8659 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 8660 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 8661 ut_params->cipher_xform.next = NULL; 8662 8663 /* Setup DOCSIS session parameters */ 8664 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 8665 8666 struct rte_security_session_conf sess_conf = { 8667 .action_type = ut_params->type, 8668 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 8669 .docsis = ut_params->docsis_xform, 8670 .crypto_xform = &ut_params->cipher_xform, 8671 }; 8672 8673 /* Create security session */ 8674 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 8675 ts_params->session_mpool, 8676 ts_params->session_priv_mpool); 8677 8678 if (!ut_params->sec_session) { 8679 printf("TestCase %s(%d) line %d: %s\n", 8680 __func__, i, __LINE__, "failed to allocate session"); 8681 ret = TEST_FAILED; 8682 goto on_err; 8683 } 8684 8685 /* Generate crypto op data structure */ 8686 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8687 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8688 if (!ut_params->op) { 8689 printf("TestCase %s(%d) line %d: %s\n", 8690 __func__, i, __LINE__, 8691 "failed to allocate security crypto operation"); 8692 ret = TEST_FAILED; 8693 goto on_err; 8694 } 8695 8696 /* Setup CRC operation parameters */ 8697 crc_len = d_td->plaintext.no_crc == false ? 8698 (d_td->plaintext.len - 8699 d_td->plaintext.crc_offset - 8700 RTE_ETHER_CRC_LEN) : 8701 0; 8702 crc_len = crc_len > 0 ? crc_len : 0; 8703 ut_params->op->sym->auth.data.length = crc_len; 8704 ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset; 8705 8706 /* Setup cipher operation parameters */ 8707 cipher_len = d_td->plaintext.no_cipher == false ? 8708 (d_td->plaintext.len - 8709 d_td->plaintext.cipher_offset) : 8710 0; 8711 cipher_len = cipher_len > 0 ? cipher_len : 0; 8712 ut_params->op->sym->cipher.data.length = cipher_len; 8713 ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset; 8714 8715 /* Setup cipher IV */ 8716 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 8717 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 8718 8719 /* Attach session to operation */ 8720 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8721 8722 /* Set crypto operation mbufs */ 8723 ut_params->op->sym->m_src = ut_params->ibuf; 8724 ut_params->op->sym->m_dst = NULL; 8725 8726 /* Process crypto operation */ 8727 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 8728 NULL) { 8729 printf("TestCase %s(%d) line %d: %s\n", 8730 __func__, i, __LINE__, 8731 "failed to process security crypto op"); 8732 ret = TEST_FAILED; 8733 goto on_err; 8734 } 8735 8736 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8737 printf("TestCase %s(%d) line %d: %s\n", 8738 __func__, i, __LINE__, "crypto op processing failed"); 8739 ret = TEST_FAILED; 8740 goto on_err; 8741 } 8742 8743 /* Validate ciphertext */ 8744 ciphertext = plaintext; 8745 8746 if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) { 8747 printf("TestCase %s(%d) line %d: %s\n", 8748 __func__, i, __LINE__, "ciphertext not as expected\n"); 8749 rte_hexdump(stdout, "expected", d_td->ciphertext.data, 8750 d_td->ciphertext.len); 8751 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len); 8752 ret = TEST_FAILED; 8753 goto on_err; 8754 } 8755 8756 on_err: 8757 rte_crypto_op_free(ut_params->op); 8758 ut_params->op = NULL; 8759 8760 if (ut_params->sec_session) 8761 rte_security_session_destroy(ctx, ut_params->sec_session); 8762 ut_params->sec_session = NULL; 8763 8764 rte_pktmbuf_free(ut_params->ibuf); 8765 ut_params->ibuf = NULL; 8766 8767 return ret; 8768 } 8769 8770 #define TEST_DOCSIS_COUNT(func) do { \ 8771 int ret = func; \ 8772 if (ret == TEST_SUCCESS) { \ 8773 printf("\t%2d)", n++); \ 8774 printf("+++++ PASSED:" #func"\n"); \ 8775 p++; \ 8776 } else if (ret == -ENOTSUP) { \ 8777 printf("\t%2d)", n++); \ 8778 printf("~~~~~ UNSUPP:" #func"\n"); \ 8779 u++; \ 8780 } else { \ 8781 printf("\t%2d)", n++); \ 8782 printf("----- FAILED:" #func"\n"); \ 8783 f++; \ 8784 } \ 8785 } while (0) 8786 8787 static int 8788 test_DOCSIS_PROTO_uplink_all(void) 8789 { 8790 int p = 0, u = 0, f = 0, n = 0; 8791 8792 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1)); 8793 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2)); 8794 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3)); 8795 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4)); 8796 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5)); 8797 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6)); 8798 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7)); 8799 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8)); 8800 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9)); 8801 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10)); 8802 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11)); 8803 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12)); 8804 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13)); 8805 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14)); 8806 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15)); 8807 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16)); 8808 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17)); 8809 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18)); 8810 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19)); 8811 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20)); 8812 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21)); 8813 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22)); 8814 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23)); 8815 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24)); 8816 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25)); 8817 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26)); 8818 8819 if (f) 8820 printf("## %s: %d passed out of %d (%d unsupported)\n", 8821 __func__, p, n, u); 8822 8823 return f; 8824 }; 8825 8826 static int 8827 test_DOCSIS_PROTO_downlink_all(void) 8828 { 8829 int p = 0, u = 0, f = 0, n = 0; 8830 8831 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1)); 8832 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2)); 8833 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3)); 8834 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4)); 8835 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5)); 8836 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6)); 8837 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7)); 8838 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8)); 8839 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9)); 8840 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10)); 8841 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11)); 8842 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12)); 8843 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13)); 8844 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14)); 8845 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15)); 8846 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16)); 8847 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17)); 8848 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18)); 8849 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19)); 8850 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20)); 8851 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21)); 8852 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22)); 8853 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23)); 8854 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24)); 8855 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25)); 8856 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26)); 8857 8858 if (f) 8859 printf("## %s: %d passed out of %d (%d unsupported)\n", 8860 __func__, p, n, u); 8861 8862 return f; 8863 }; 8864 8865 static int 8866 test_DOCSIS_PROTO_all(void) 8867 { 8868 struct crypto_testsuite_params *ts_params = &testsuite_params; 8869 struct crypto_unittest_params *ut_params = &unittest_params; 8870 struct rte_cryptodev_info dev_info; 8871 int status; 8872 8873 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8874 uint64_t feat_flags = dev_info.feature_flags; 8875 8876 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 8877 return -ENOTSUP; 8878 8879 /* Set action type */ 8880 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 8881 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 8882 gbl_action_type; 8883 8884 if (security_proto_supported(ut_params->type, 8885 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 8886 return -ENOTSUP; 8887 8888 status = test_DOCSIS_PROTO_uplink_all(); 8889 status += test_DOCSIS_PROTO_downlink_all(); 8890 8891 if (status) 8892 return TEST_FAILED; 8893 else 8894 return TEST_SUCCESS; 8895 } 8896 #endif 8897 8898 static int 8899 test_AES_GCM_authenticated_encryption_test_case_1(void) 8900 { 8901 return test_authenticated_encryption(&gcm_test_case_1); 8902 } 8903 8904 static int 8905 test_AES_GCM_authenticated_encryption_test_case_2(void) 8906 { 8907 return test_authenticated_encryption(&gcm_test_case_2); 8908 } 8909 8910 static int 8911 test_AES_GCM_authenticated_encryption_test_case_3(void) 8912 { 8913 return test_authenticated_encryption(&gcm_test_case_3); 8914 } 8915 8916 static int 8917 test_AES_GCM_authenticated_encryption_test_case_4(void) 8918 { 8919 return test_authenticated_encryption(&gcm_test_case_4); 8920 } 8921 8922 static int 8923 test_AES_GCM_authenticated_encryption_test_case_5(void) 8924 { 8925 return test_authenticated_encryption(&gcm_test_case_5); 8926 } 8927 8928 static int 8929 test_AES_GCM_authenticated_encryption_test_case_6(void) 8930 { 8931 return test_authenticated_encryption(&gcm_test_case_6); 8932 } 8933 8934 static int 8935 test_AES_GCM_authenticated_encryption_test_case_7(void) 8936 { 8937 return test_authenticated_encryption(&gcm_test_case_7); 8938 } 8939 8940 static int 8941 test_AES_GCM_authenticated_encryption_test_case_8(void) 8942 { 8943 return test_authenticated_encryption(&gcm_test_case_8); 8944 } 8945 8946 static int 8947 test_AES_GCM_J0_authenticated_encryption_test_case_1(void) 8948 { 8949 return test_authenticated_encryption(&gcm_J0_test_case_1); 8950 } 8951 8952 static int 8953 test_AES_GCM_auth_encryption_test_case_192_1(void) 8954 { 8955 return test_authenticated_encryption(&gcm_test_case_192_1); 8956 } 8957 8958 static int 8959 test_AES_GCM_auth_encryption_test_case_192_2(void) 8960 { 8961 return test_authenticated_encryption(&gcm_test_case_192_2); 8962 } 8963 8964 static int 8965 test_AES_GCM_auth_encryption_test_case_192_3(void) 8966 { 8967 return test_authenticated_encryption(&gcm_test_case_192_3); 8968 } 8969 8970 static int 8971 test_AES_GCM_auth_encryption_test_case_192_4(void) 8972 { 8973 return test_authenticated_encryption(&gcm_test_case_192_4); 8974 } 8975 8976 static int 8977 test_AES_GCM_auth_encryption_test_case_192_5(void) 8978 { 8979 return test_authenticated_encryption(&gcm_test_case_192_5); 8980 } 8981 8982 static int 8983 test_AES_GCM_auth_encryption_test_case_192_6(void) 8984 { 8985 return test_authenticated_encryption(&gcm_test_case_192_6); 8986 } 8987 8988 static int 8989 test_AES_GCM_auth_encryption_test_case_192_7(void) 8990 { 8991 return test_authenticated_encryption(&gcm_test_case_192_7); 8992 } 8993 8994 static int 8995 test_AES_GCM_auth_encryption_test_case_256_1(void) 8996 { 8997 return test_authenticated_encryption(&gcm_test_case_256_1); 8998 } 8999 9000 static int 9001 test_AES_GCM_auth_encryption_test_case_256_2(void) 9002 { 9003 return test_authenticated_encryption(&gcm_test_case_256_2); 9004 } 9005 9006 static int 9007 test_AES_GCM_auth_encryption_test_case_256_3(void) 9008 { 9009 return test_authenticated_encryption(&gcm_test_case_256_3); 9010 } 9011 9012 static int 9013 test_AES_GCM_auth_encryption_test_case_256_4(void) 9014 { 9015 return test_authenticated_encryption(&gcm_test_case_256_4); 9016 } 9017 9018 static int 9019 test_AES_GCM_auth_encryption_test_case_256_5(void) 9020 { 9021 return test_authenticated_encryption(&gcm_test_case_256_5); 9022 } 9023 9024 static int 9025 test_AES_GCM_auth_encryption_test_case_256_6(void) 9026 { 9027 return test_authenticated_encryption(&gcm_test_case_256_6); 9028 } 9029 9030 static int 9031 test_AES_GCM_auth_encryption_test_case_256_7(void) 9032 { 9033 return test_authenticated_encryption(&gcm_test_case_256_7); 9034 } 9035 9036 static int 9037 test_AES_GCM_auth_encryption_test_case_aad_1(void) 9038 { 9039 return test_authenticated_encryption(&gcm_test_case_aad_1); 9040 } 9041 9042 static int 9043 test_AES_GCM_auth_encryption_test_case_aad_2(void) 9044 { 9045 return test_authenticated_encryption(&gcm_test_case_aad_2); 9046 } 9047 9048 static int 9049 test_AES_GCM_auth_encryption_fail_iv_corrupt(void) 9050 { 9051 struct aead_test_data tdata; 9052 int res; 9053 9054 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9055 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9056 tdata.iv.data[0] += 1; 9057 res = test_authenticated_encryption(&tdata); 9058 if (res == -ENOTSUP) 9059 return res; 9060 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9061 return TEST_SUCCESS; 9062 } 9063 9064 static int 9065 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void) 9066 { 9067 struct aead_test_data tdata; 9068 int res; 9069 9070 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9071 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9072 tdata.plaintext.data[0] += 1; 9073 res = test_authenticated_encryption(&tdata); 9074 if (res == -ENOTSUP) 9075 return res; 9076 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9077 return TEST_SUCCESS; 9078 } 9079 9080 static int 9081 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void) 9082 { 9083 struct aead_test_data tdata; 9084 int res; 9085 9086 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9087 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9088 tdata.ciphertext.data[0] += 1; 9089 res = test_authenticated_encryption(&tdata); 9090 if (res == -ENOTSUP) 9091 return res; 9092 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9093 return TEST_SUCCESS; 9094 } 9095 9096 static int 9097 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void) 9098 { 9099 struct aead_test_data tdata; 9100 int res; 9101 9102 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9103 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9104 tdata.aad.len += 1; 9105 res = test_authenticated_encryption(&tdata); 9106 if (res == -ENOTSUP) 9107 return res; 9108 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9109 return TEST_SUCCESS; 9110 } 9111 9112 static int 9113 test_AES_GCM_auth_encryption_fail_aad_corrupt(void) 9114 { 9115 struct aead_test_data tdata; 9116 uint8_t aad[gcm_test_case_7.aad.len]; 9117 int res; 9118 9119 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9120 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9121 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 9122 aad[0] += 1; 9123 tdata.aad.data = aad; 9124 res = test_authenticated_encryption(&tdata); 9125 if (res == -ENOTSUP) 9126 return res; 9127 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9128 return TEST_SUCCESS; 9129 } 9130 9131 static int 9132 test_AES_GCM_auth_encryption_fail_tag_corrupt(void) 9133 { 9134 struct aead_test_data tdata; 9135 int res; 9136 9137 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9138 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9139 tdata.auth_tag.data[0] += 1; 9140 res = test_authenticated_encryption(&tdata); 9141 if (res == -ENOTSUP) 9142 return res; 9143 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9144 return TEST_SUCCESS; 9145 } 9146 9147 static int 9148 test_authenticated_decryption(const struct aead_test_data *tdata) 9149 { 9150 struct crypto_testsuite_params *ts_params = &testsuite_params; 9151 struct crypto_unittest_params *ut_params = &unittest_params; 9152 9153 int retval; 9154 uint8_t *plaintext; 9155 uint32_t i; 9156 struct rte_cryptodev_info dev_info; 9157 9158 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9159 uint64_t feat_flags = dev_info.feature_flags; 9160 9161 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9162 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9163 printf("Device doesn't support RAW data-path APIs.\n"); 9164 return -ENOTSUP; 9165 } 9166 9167 /* Verify the capabilities */ 9168 struct rte_cryptodev_sym_capability_idx cap_idx; 9169 const struct rte_cryptodev_symmetric_capability *capability; 9170 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9171 cap_idx.algo.aead = tdata->algo; 9172 capability = rte_cryptodev_sym_capability_get( 9173 ts_params->valid_devs[0], &cap_idx); 9174 if (capability == NULL) 9175 return -ENOTSUP; 9176 if (rte_cryptodev_sym_capability_check_aead( 9177 capability, tdata->key.len, tdata->auth_tag.len, 9178 tdata->aad.len, tdata->iv.len)) 9179 return -ENOTSUP; 9180 9181 /* Create AEAD session */ 9182 retval = create_aead_session(ts_params->valid_devs[0], 9183 tdata->algo, 9184 RTE_CRYPTO_AEAD_OP_DECRYPT, 9185 tdata->key.data, tdata->key.len, 9186 tdata->aad.len, tdata->auth_tag.len, 9187 tdata->iv.len); 9188 if (retval < 0) 9189 return retval; 9190 9191 /* alloc mbuf and set payload */ 9192 if (tdata->aad.len > MBUF_SIZE) { 9193 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 9194 /* Populate full size of add data */ 9195 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 9196 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 9197 } else 9198 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9199 9200 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9201 rte_pktmbuf_tailroom(ut_params->ibuf)); 9202 9203 /* Create AEAD operation */ 9204 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 9205 if (retval < 0) 9206 return retval; 9207 9208 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9209 9210 ut_params->op->sym->m_src = ut_params->ibuf; 9211 9212 /* Process crypto operation */ 9213 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9214 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 9215 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 9216 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 9217 ut_params->op, 0, 0, 0, 0); 9218 else 9219 TEST_ASSERT_NOT_NULL( 9220 process_crypto_request(ts_params->valid_devs[0], 9221 ut_params->op), "failed to process sym crypto op"); 9222 9223 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9224 "crypto op processing failed"); 9225 9226 if (ut_params->op->sym->m_dst) 9227 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 9228 uint8_t *); 9229 else 9230 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 9231 uint8_t *, 9232 ut_params->op->sym->cipher.data.offset); 9233 9234 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 9235 9236 /* Validate obuf */ 9237 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9238 plaintext, 9239 tdata->plaintext.data, 9240 tdata->plaintext.len, 9241 "Plaintext data not as expected"); 9242 9243 TEST_ASSERT_EQUAL(ut_params->op->status, 9244 RTE_CRYPTO_OP_STATUS_SUCCESS, 9245 "Authentication failed"); 9246 9247 return 0; 9248 } 9249 9250 static int 9251 test_AES_GCM_authenticated_decryption_test_case_1(void) 9252 { 9253 return test_authenticated_decryption(&gcm_test_case_1); 9254 } 9255 9256 static int 9257 test_AES_GCM_authenticated_decryption_test_case_2(void) 9258 { 9259 return test_authenticated_decryption(&gcm_test_case_2); 9260 } 9261 9262 static int 9263 test_AES_GCM_authenticated_decryption_test_case_3(void) 9264 { 9265 return test_authenticated_decryption(&gcm_test_case_3); 9266 } 9267 9268 static int 9269 test_AES_GCM_authenticated_decryption_test_case_4(void) 9270 { 9271 return test_authenticated_decryption(&gcm_test_case_4); 9272 } 9273 9274 static int 9275 test_AES_GCM_authenticated_decryption_test_case_5(void) 9276 { 9277 return test_authenticated_decryption(&gcm_test_case_5); 9278 } 9279 9280 static int 9281 test_AES_GCM_authenticated_decryption_test_case_6(void) 9282 { 9283 return test_authenticated_decryption(&gcm_test_case_6); 9284 } 9285 9286 static int 9287 test_AES_GCM_authenticated_decryption_test_case_7(void) 9288 { 9289 return test_authenticated_decryption(&gcm_test_case_7); 9290 } 9291 9292 static int 9293 test_AES_GCM_authenticated_decryption_test_case_8(void) 9294 { 9295 return test_authenticated_decryption(&gcm_test_case_8); 9296 } 9297 9298 static int 9299 test_AES_GCM_J0_authenticated_decryption_test_case_1(void) 9300 { 9301 return test_authenticated_decryption(&gcm_J0_test_case_1); 9302 } 9303 9304 static int 9305 test_AES_GCM_auth_decryption_test_case_192_1(void) 9306 { 9307 return test_authenticated_decryption(&gcm_test_case_192_1); 9308 } 9309 9310 static int 9311 test_AES_GCM_auth_decryption_test_case_192_2(void) 9312 { 9313 return test_authenticated_decryption(&gcm_test_case_192_2); 9314 } 9315 9316 static int 9317 test_AES_GCM_auth_decryption_test_case_192_3(void) 9318 { 9319 return test_authenticated_decryption(&gcm_test_case_192_3); 9320 } 9321 9322 static int 9323 test_AES_GCM_auth_decryption_test_case_192_4(void) 9324 { 9325 return test_authenticated_decryption(&gcm_test_case_192_4); 9326 } 9327 9328 static int 9329 test_AES_GCM_auth_decryption_test_case_192_5(void) 9330 { 9331 return test_authenticated_decryption(&gcm_test_case_192_5); 9332 } 9333 9334 static int 9335 test_AES_GCM_auth_decryption_test_case_192_6(void) 9336 { 9337 return test_authenticated_decryption(&gcm_test_case_192_6); 9338 } 9339 9340 static int 9341 test_AES_GCM_auth_decryption_test_case_192_7(void) 9342 { 9343 return test_authenticated_decryption(&gcm_test_case_192_7); 9344 } 9345 9346 static int 9347 test_AES_GCM_auth_decryption_test_case_256_1(void) 9348 { 9349 return test_authenticated_decryption(&gcm_test_case_256_1); 9350 } 9351 9352 static int 9353 test_AES_GCM_auth_decryption_test_case_256_2(void) 9354 { 9355 return test_authenticated_decryption(&gcm_test_case_256_2); 9356 } 9357 9358 static int 9359 test_AES_GCM_auth_decryption_test_case_256_3(void) 9360 { 9361 return test_authenticated_decryption(&gcm_test_case_256_3); 9362 } 9363 9364 static int 9365 test_AES_GCM_auth_decryption_test_case_256_4(void) 9366 { 9367 return test_authenticated_decryption(&gcm_test_case_256_4); 9368 } 9369 9370 static int 9371 test_AES_GCM_auth_decryption_test_case_256_5(void) 9372 { 9373 return test_authenticated_decryption(&gcm_test_case_256_5); 9374 } 9375 9376 static int 9377 test_AES_GCM_auth_decryption_test_case_256_6(void) 9378 { 9379 return test_authenticated_decryption(&gcm_test_case_256_6); 9380 } 9381 9382 static int 9383 test_AES_GCM_auth_decryption_test_case_256_7(void) 9384 { 9385 return test_authenticated_decryption(&gcm_test_case_256_7); 9386 } 9387 9388 static int 9389 test_AES_GCM_auth_decryption_test_case_aad_1(void) 9390 { 9391 return test_authenticated_decryption(&gcm_test_case_aad_1); 9392 } 9393 9394 static int 9395 test_AES_GCM_auth_decryption_test_case_aad_2(void) 9396 { 9397 return test_authenticated_decryption(&gcm_test_case_aad_2); 9398 } 9399 9400 static int 9401 test_AES_GCM_auth_decryption_fail_iv_corrupt(void) 9402 { 9403 struct aead_test_data tdata; 9404 int res; 9405 9406 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9407 tdata.iv.data[0] += 1; 9408 res = test_authenticated_decryption(&tdata); 9409 if (res == -ENOTSUP) 9410 return res; 9411 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9412 return TEST_SUCCESS; 9413 } 9414 9415 static int 9416 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void) 9417 { 9418 struct aead_test_data tdata; 9419 int res; 9420 9421 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9422 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9423 tdata.plaintext.data[0] += 1; 9424 res = test_authenticated_decryption(&tdata); 9425 if (res == -ENOTSUP) 9426 return res; 9427 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9428 return TEST_SUCCESS; 9429 } 9430 9431 static int 9432 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void) 9433 { 9434 struct aead_test_data tdata; 9435 int res; 9436 9437 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9438 tdata.ciphertext.data[0] += 1; 9439 res = test_authenticated_decryption(&tdata); 9440 if (res == -ENOTSUP) 9441 return res; 9442 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9443 return TEST_SUCCESS; 9444 } 9445 9446 static int 9447 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void) 9448 { 9449 struct aead_test_data tdata; 9450 int res; 9451 9452 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9453 tdata.aad.len += 1; 9454 res = test_authenticated_decryption(&tdata); 9455 if (res == -ENOTSUP) 9456 return res; 9457 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9458 return TEST_SUCCESS; 9459 } 9460 9461 static int 9462 test_AES_GCM_auth_decryption_fail_aad_corrupt(void) 9463 { 9464 struct aead_test_data tdata; 9465 uint8_t aad[gcm_test_case_7.aad.len]; 9466 int res; 9467 9468 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9469 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 9470 aad[0] += 1; 9471 tdata.aad.data = aad; 9472 res = test_authenticated_decryption(&tdata); 9473 if (res == -ENOTSUP) 9474 return res; 9475 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9476 return TEST_SUCCESS; 9477 } 9478 9479 static int 9480 test_AES_GCM_auth_decryption_fail_tag_corrupt(void) 9481 { 9482 struct aead_test_data tdata; 9483 int res; 9484 9485 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9486 tdata.auth_tag.data[0] += 1; 9487 res = test_authenticated_decryption(&tdata); 9488 if (res == -ENOTSUP) 9489 return res; 9490 TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed"); 9491 return TEST_SUCCESS; 9492 } 9493 9494 static int 9495 test_authenticated_encryption_oop(const struct aead_test_data *tdata) 9496 { 9497 struct crypto_testsuite_params *ts_params = &testsuite_params; 9498 struct crypto_unittest_params *ut_params = &unittest_params; 9499 9500 int retval; 9501 uint8_t *ciphertext, *auth_tag; 9502 uint16_t plaintext_pad_len; 9503 9504 /* Verify the capabilities */ 9505 struct rte_cryptodev_sym_capability_idx cap_idx; 9506 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9507 cap_idx.algo.aead = tdata->algo; 9508 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9509 &cap_idx) == NULL) 9510 return -ENOTSUP; 9511 9512 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 9513 return -ENOTSUP; 9514 9515 /* not supported with CPU crypto */ 9516 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9517 return -ENOTSUP; 9518 9519 /* Create AEAD session */ 9520 retval = create_aead_session(ts_params->valid_devs[0], 9521 tdata->algo, 9522 RTE_CRYPTO_AEAD_OP_ENCRYPT, 9523 tdata->key.data, tdata->key.len, 9524 tdata->aad.len, tdata->auth_tag.len, 9525 tdata->iv.len); 9526 if (retval < 0) 9527 return retval; 9528 9529 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9530 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9531 9532 /* clear mbuf payload */ 9533 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9534 rte_pktmbuf_tailroom(ut_params->ibuf)); 9535 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 9536 rte_pktmbuf_tailroom(ut_params->obuf)); 9537 9538 /* Create AEAD operation */ 9539 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 9540 if (retval < 0) 9541 return retval; 9542 9543 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9544 9545 ut_params->op->sym->m_src = ut_params->ibuf; 9546 ut_params->op->sym->m_dst = ut_params->obuf; 9547 9548 /* Process crypto operation */ 9549 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 9550 ut_params->op), "failed to process sym crypto op"); 9551 9552 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9553 "crypto op processing failed"); 9554 9555 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 9556 9557 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 9558 ut_params->op->sym->cipher.data.offset); 9559 auth_tag = ciphertext + plaintext_pad_len; 9560 9561 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 9562 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 9563 9564 /* Validate obuf */ 9565 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9566 ciphertext, 9567 tdata->ciphertext.data, 9568 tdata->ciphertext.len, 9569 "Ciphertext data not as expected"); 9570 9571 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9572 auth_tag, 9573 tdata->auth_tag.data, 9574 tdata->auth_tag.len, 9575 "Generated auth tag not as expected"); 9576 9577 return 0; 9578 9579 } 9580 9581 static int 9582 test_AES_GCM_authenticated_encryption_oop_test_case_1(void) 9583 { 9584 return test_authenticated_encryption_oop(&gcm_test_case_5); 9585 } 9586 9587 static int 9588 test_authenticated_decryption_oop(const struct aead_test_data *tdata) 9589 { 9590 struct crypto_testsuite_params *ts_params = &testsuite_params; 9591 struct crypto_unittest_params *ut_params = &unittest_params; 9592 9593 int retval; 9594 uint8_t *plaintext; 9595 9596 /* Verify the capabilities */ 9597 struct rte_cryptodev_sym_capability_idx cap_idx; 9598 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9599 cap_idx.algo.aead = tdata->algo; 9600 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9601 &cap_idx) == NULL) 9602 return -ENOTSUP; 9603 9604 /* not supported with CPU crypto and raw data-path APIs*/ 9605 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO || 9606 global_api_test_type == CRYPTODEV_RAW_API_TEST) 9607 return -ENOTSUP; 9608 9609 /* Create AEAD session */ 9610 retval = create_aead_session(ts_params->valid_devs[0], 9611 tdata->algo, 9612 RTE_CRYPTO_AEAD_OP_DECRYPT, 9613 tdata->key.data, tdata->key.len, 9614 tdata->aad.len, tdata->auth_tag.len, 9615 tdata->iv.len); 9616 if (retval < 0) 9617 return retval; 9618 9619 /* alloc mbuf and set payload */ 9620 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9621 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9622 9623 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9624 rte_pktmbuf_tailroom(ut_params->ibuf)); 9625 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 9626 rte_pktmbuf_tailroom(ut_params->obuf)); 9627 9628 /* Create AEAD operation */ 9629 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 9630 if (retval < 0) 9631 return retval; 9632 9633 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9634 9635 ut_params->op->sym->m_src = ut_params->ibuf; 9636 ut_params->op->sym->m_dst = ut_params->obuf; 9637 9638 /* Process crypto operation */ 9639 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 9640 ut_params->op), "failed to process sym crypto op"); 9641 9642 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9643 "crypto op processing failed"); 9644 9645 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 9646 ut_params->op->sym->cipher.data.offset); 9647 9648 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 9649 9650 /* Validate obuf */ 9651 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9652 plaintext, 9653 tdata->plaintext.data, 9654 tdata->plaintext.len, 9655 "Plaintext data not as expected"); 9656 9657 TEST_ASSERT_EQUAL(ut_params->op->status, 9658 RTE_CRYPTO_OP_STATUS_SUCCESS, 9659 "Authentication failed"); 9660 return 0; 9661 } 9662 9663 static int 9664 test_AES_GCM_authenticated_decryption_oop_test_case_1(void) 9665 { 9666 return test_authenticated_decryption_oop(&gcm_test_case_5); 9667 } 9668 9669 static int 9670 test_authenticated_encryption_sessionless( 9671 const struct aead_test_data *tdata) 9672 { 9673 struct crypto_testsuite_params *ts_params = &testsuite_params; 9674 struct crypto_unittest_params *ut_params = &unittest_params; 9675 9676 int retval; 9677 uint8_t *ciphertext, *auth_tag; 9678 uint16_t plaintext_pad_len; 9679 uint8_t key[tdata->key.len + 1]; 9680 struct rte_cryptodev_info dev_info; 9681 9682 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9683 uint64_t feat_flags = dev_info.feature_flags; 9684 9685 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 9686 printf("Device doesn't support Sessionless ops.\n"); 9687 return -ENOTSUP; 9688 } 9689 9690 /* not supported with CPU crypto */ 9691 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9692 return -ENOTSUP; 9693 9694 /* Verify the capabilities */ 9695 struct rte_cryptodev_sym_capability_idx cap_idx; 9696 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9697 cap_idx.algo.aead = tdata->algo; 9698 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9699 &cap_idx) == NULL) 9700 return -ENOTSUP; 9701 9702 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9703 9704 /* clear mbuf payload */ 9705 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9706 rte_pktmbuf_tailroom(ut_params->ibuf)); 9707 9708 /* Create AEAD operation */ 9709 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 9710 if (retval < 0) 9711 return retval; 9712 9713 /* Create GCM xform */ 9714 memcpy(key, tdata->key.data, tdata->key.len); 9715 retval = create_aead_xform(ut_params->op, 9716 tdata->algo, 9717 RTE_CRYPTO_AEAD_OP_ENCRYPT, 9718 key, tdata->key.len, 9719 tdata->aad.len, tdata->auth_tag.len, 9720 tdata->iv.len); 9721 if (retval < 0) 9722 return retval; 9723 9724 ut_params->op->sym->m_src = ut_params->ibuf; 9725 9726 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 9727 RTE_CRYPTO_OP_SESSIONLESS, 9728 "crypto op session type not sessionless"); 9729 9730 /* Process crypto operation */ 9731 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 9732 ut_params->op), "failed to process sym crypto op"); 9733 9734 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 9735 9736 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9737 "crypto op status not success"); 9738 9739 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 9740 9741 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 9742 ut_params->op->sym->cipher.data.offset); 9743 auth_tag = ciphertext + plaintext_pad_len; 9744 9745 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 9746 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 9747 9748 /* Validate obuf */ 9749 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9750 ciphertext, 9751 tdata->ciphertext.data, 9752 tdata->ciphertext.len, 9753 "Ciphertext data not as expected"); 9754 9755 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9756 auth_tag, 9757 tdata->auth_tag.data, 9758 tdata->auth_tag.len, 9759 "Generated auth tag not as expected"); 9760 9761 return 0; 9762 9763 } 9764 9765 static int 9766 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void) 9767 { 9768 return test_authenticated_encryption_sessionless( 9769 &gcm_test_case_5); 9770 } 9771 9772 static int 9773 test_authenticated_decryption_sessionless( 9774 const struct aead_test_data *tdata) 9775 { 9776 struct crypto_testsuite_params *ts_params = &testsuite_params; 9777 struct crypto_unittest_params *ut_params = &unittest_params; 9778 9779 int retval; 9780 uint8_t *plaintext; 9781 uint8_t key[tdata->key.len + 1]; 9782 struct rte_cryptodev_info dev_info; 9783 9784 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9785 uint64_t feat_flags = dev_info.feature_flags; 9786 9787 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 9788 printf("Device doesn't support Sessionless ops.\n"); 9789 return -ENOTSUP; 9790 } 9791 9792 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9793 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9794 printf("Device doesn't support RAW data-path APIs.\n"); 9795 return -ENOTSUP; 9796 } 9797 9798 /* not supported with CPU crypto */ 9799 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9800 return -ENOTSUP; 9801 9802 /* Verify the capabilities */ 9803 struct rte_cryptodev_sym_capability_idx cap_idx; 9804 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9805 cap_idx.algo.aead = tdata->algo; 9806 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9807 &cap_idx) == NULL) 9808 return -ENOTSUP; 9809 9810 /* alloc mbuf and set payload */ 9811 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9812 9813 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9814 rte_pktmbuf_tailroom(ut_params->ibuf)); 9815 9816 /* Create AEAD operation */ 9817 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 9818 if (retval < 0) 9819 return retval; 9820 9821 /* Create AEAD xform */ 9822 memcpy(key, tdata->key.data, tdata->key.len); 9823 retval = create_aead_xform(ut_params->op, 9824 tdata->algo, 9825 RTE_CRYPTO_AEAD_OP_DECRYPT, 9826 key, tdata->key.len, 9827 tdata->aad.len, tdata->auth_tag.len, 9828 tdata->iv.len); 9829 if (retval < 0) 9830 return retval; 9831 9832 ut_params->op->sym->m_src = ut_params->ibuf; 9833 9834 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 9835 RTE_CRYPTO_OP_SESSIONLESS, 9836 "crypto op session type not sessionless"); 9837 9838 /* Process crypto operation */ 9839 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 9840 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 9841 ut_params->op, 0, 0, 0, 0); 9842 else 9843 TEST_ASSERT_NOT_NULL(process_crypto_request( 9844 ts_params->valid_devs[0], ut_params->op), 9845 "failed to process sym crypto op"); 9846 9847 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 9848 9849 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9850 "crypto op status not success"); 9851 9852 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 9853 ut_params->op->sym->cipher.data.offset); 9854 9855 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 9856 9857 /* Validate obuf */ 9858 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9859 plaintext, 9860 tdata->plaintext.data, 9861 tdata->plaintext.len, 9862 "Plaintext data not as expected"); 9863 9864 TEST_ASSERT_EQUAL(ut_params->op->status, 9865 RTE_CRYPTO_OP_STATUS_SUCCESS, 9866 "Authentication failed"); 9867 return 0; 9868 } 9869 9870 static int 9871 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void) 9872 { 9873 return test_authenticated_decryption_sessionless( 9874 &gcm_test_case_5); 9875 } 9876 9877 static int 9878 test_AES_CCM_authenticated_encryption_test_case_128_1(void) 9879 { 9880 return test_authenticated_encryption(&ccm_test_case_128_1); 9881 } 9882 9883 static int 9884 test_AES_CCM_authenticated_encryption_test_case_128_2(void) 9885 { 9886 return test_authenticated_encryption(&ccm_test_case_128_2); 9887 } 9888 9889 static int 9890 test_AES_CCM_authenticated_encryption_test_case_128_3(void) 9891 { 9892 return test_authenticated_encryption(&ccm_test_case_128_3); 9893 } 9894 9895 static int 9896 test_AES_CCM_authenticated_decryption_test_case_128_1(void) 9897 { 9898 return test_authenticated_decryption(&ccm_test_case_128_1); 9899 } 9900 9901 static int 9902 test_AES_CCM_authenticated_decryption_test_case_128_2(void) 9903 { 9904 return test_authenticated_decryption(&ccm_test_case_128_2); 9905 } 9906 9907 static int 9908 test_AES_CCM_authenticated_decryption_test_case_128_3(void) 9909 { 9910 return test_authenticated_decryption(&ccm_test_case_128_3); 9911 } 9912 9913 static int 9914 test_AES_CCM_authenticated_encryption_test_case_192_1(void) 9915 { 9916 return test_authenticated_encryption(&ccm_test_case_192_1); 9917 } 9918 9919 static int 9920 test_AES_CCM_authenticated_encryption_test_case_192_2(void) 9921 { 9922 return test_authenticated_encryption(&ccm_test_case_192_2); 9923 } 9924 9925 static int 9926 test_AES_CCM_authenticated_encryption_test_case_192_3(void) 9927 { 9928 return test_authenticated_encryption(&ccm_test_case_192_3); 9929 } 9930 9931 static int 9932 test_AES_CCM_authenticated_decryption_test_case_192_1(void) 9933 { 9934 return test_authenticated_decryption(&ccm_test_case_192_1); 9935 } 9936 9937 static int 9938 test_AES_CCM_authenticated_decryption_test_case_192_2(void) 9939 { 9940 return test_authenticated_decryption(&ccm_test_case_192_2); 9941 } 9942 9943 static int 9944 test_AES_CCM_authenticated_decryption_test_case_192_3(void) 9945 { 9946 return test_authenticated_decryption(&ccm_test_case_192_3); 9947 } 9948 9949 static int 9950 test_AES_CCM_authenticated_encryption_test_case_256_1(void) 9951 { 9952 return test_authenticated_encryption(&ccm_test_case_256_1); 9953 } 9954 9955 static int 9956 test_AES_CCM_authenticated_encryption_test_case_256_2(void) 9957 { 9958 return test_authenticated_encryption(&ccm_test_case_256_2); 9959 } 9960 9961 static int 9962 test_AES_CCM_authenticated_encryption_test_case_256_3(void) 9963 { 9964 return test_authenticated_encryption(&ccm_test_case_256_3); 9965 } 9966 9967 static int 9968 test_AES_CCM_authenticated_decryption_test_case_256_1(void) 9969 { 9970 return test_authenticated_decryption(&ccm_test_case_256_1); 9971 } 9972 9973 static int 9974 test_AES_CCM_authenticated_decryption_test_case_256_2(void) 9975 { 9976 return test_authenticated_decryption(&ccm_test_case_256_2); 9977 } 9978 9979 static int 9980 test_AES_CCM_authenticated_decryption_test_case_256_3(void) 9981 { 9982 return test_authenticated_decryption(&ccm_test_case_256_3); 9983 } 9984 9985 static int 9986 test_stats(void) 9987 { 9988 struct crypto_testsuite_params *ts_params = &testsuite_params; 9989 struct rte_cryptodev_stats stats; 9990 9991 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9992 return -ENOTSUP; 9993 9994 /* Verify the capabilities */ 9995 struct rte_cryptodev_sym_capability_idx cap_idx; 9996 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9997 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 9998 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9999 &cap_idx) == NULL) 10000 return -ENOTSUP; 10001 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10002 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 10003 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10004 &cap_idx) == NULL) 10005 return -ENOTSUP; 10006 10007 if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 10008 == -ENOTSUP) 10009 return -ENOTSUP; 10010 10011 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 10012 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 10013 &stats) == -ENODEV), 10014 "rte_cryptodev_stats_get invalid dev failed"); 10015 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 10016 "rte_cryptodev_stats_get invalid Param failed"); 10017 10018 /* Test expected values */ 10019 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 10020 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 10021 &stats), 10022 "rte_cryptodev_stats_get failed"); 10023 TEST_ASSERT((stats.enqueued_count == 1), 10024 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10025 TEST_ASSERT((stats.dequeued_count == 1), 10026 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10027 TEST_ASSERT((stats.enqueue_err_count == 0), 10028 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10029 TEST_ASSERT((stats.dequeue_err_count == 0), 10030 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10031 10032 /* invalid device but should ignore and not reset device stats*/ 10033 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 10034 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 10035 &stats), 10036 "rte_cryptodev_stats_get failed"); 10037 TEST_ASSERT((stats.enqueued_count == 1), 10038 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10039 10040 /* check that a valid reset clears stats */ 10041 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 10042 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 10043 &stats), 10044 "rte_cryptodev_stats_get failed"); 10045 TEST_ASSERT((stats.enqueued_count == 0), 10046 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10047 TEST_ASSERT((stats.dequeued_count == 0), 10048 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10049 10050 return TEST_SUCCESS; 10051 } 10052 10053 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 10054 struct crypto_unittest_params *ut_params, 10055 enum rte_crypto_auth_operation op, 10056 const struct HMAC_MD5_vector *test_case) 10057 { 10058 uint8_t key[64]; 10059 10060 memcpy(key, test_case->key.data, test_case->key.len); 10061 10062 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10063 ut_params->auth_xform.next = NULL; 10064 ut_params->auth_xform.auth.op = op; 10065 10066 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 10067 10068 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 10069 ut_params->auth_xform.auth.key.length = test_case->key.len; 10070 ut_params->auth_xform.auth.key.data = key; 10071 10072 ut_params->sess = rte_cryptodev_sym_session_create( 10073 ts_params->session_mpool); 10074 10075 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10076 ut_params->sess, &ut_params->auth_xform, 10077 ts_params->session_priv_mpool); 10078 10079 if (ut_params->sess == NULL) 10080 return TEST_FAILED; 10081 10082 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10083 10084 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10085 rte_pktmbuf_tailroom(ut_params->ibuf)); 10086 10087 return 0; 10088 } 10089 10090 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 10091 const struct HMAC_MD5_vector *test_case, 10092 uint8_t **plaintext) 10093 { 10094 uint16_t plaintext_pad_len; 10095 10096 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 10097 10098 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 10099 16); 10100 10101 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10102 plaintext_pad_len); 10103 memcpy(*plaintext, test_case->plaintext.data, 10104 test_case->plaintext.len); 10105 10106 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 10107 ut_params->ibuf, MD5_DIGEST_LEN); 10108 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 10109 "no room to append digest"); 10110 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 10111 ut_params->ibuf, plaintext_pad_len); 10112 10113 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 10114 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 10115 test_case->auth_tag.len); 10116 } 10117 10118 sym_op->auth.data.offset = 0; 10119 sym_op->auth.data.length = test_case->plaintext.len; 10120 10121 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10122 ut_params->op->sym->m_src = ut_params->ibuf; 10123 10124 return 0; 10125 } 10126 10127 static int 10128 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 10129 { 10130 uint16_t plaintext_pad_len; 10131 uint8_t *plaintext, *auth_tag; 10132 10133 struct crypto_testsuite_params *ts_params = &testsuite_params; 10134 struct crypto_unittest_params *ut_params = &unittest_params; 10135 struct rte_cryptodev_info dev_info; 10136 10137 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10138 uint64_t feat_flags = dev_info.feature_flags; 10139 10140 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10141 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10142 printf("Device doesn't support RAW data-path APIs.\n"); 10143 return -ENOTSUP; 10144 } 10145 10146 /* Verify the capabilities */ 10147 struct rte_cryptodev_sym_capability_idx cap_idx; 10148 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10149 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 10150 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10151 &cap_idx) == NULL) 10152 return -ENOTSUP; 10153 10154 if (MD5_HMAC_create_session(ts_params, ut_params, 10155 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 10156 return TEST_FAILED; 10157 10158 /* Generate Crypto op data structure */ 10159 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10160 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10161 TEST_ASSERT_NOT_NULL(ut_params->op, 10162 "Failed to allocate symmetric crypto operation struct"); 10163 10164 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 10165 16); 10166 10167 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 10168 return TEST_FAILED; 10169 10170 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10171 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 10172 ut_params->op); 10173 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10174 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10175 ut_params->op, 0, 1, 0, 0); 10176 else 10177 TEST_ASSERT_NOT_NULL( 10178 process_crypto_request(ts_params->valid_devs[0], 10179 ut_params->op), 10180 "failed to process sym crypto op"); 10181 10182 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10183 "crypto op processing failed"); 10184 10185 if (ut_params->op->sym->m_dst) { 10186 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 10187 uint8_t *, plaintext_pad_len); 10188 } else { 10189 auth_tag = plaintext + plaintext_pad_len; 10190 } 10191 10192 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10193 auth_tag, 10194 test_case->auth_tag.data, 10195 test_case->auth_tag.len, 10196 "HMAC_MD5 generated tag not as expected"); 10197 10198 return TEST_SUCCESS; 10199 } 10200 10201 static int 10202 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 10203 { 10204 uint8_t *plaintext; 10205 10206 struct crypto_testsuite_params *ts_params = &testsuite_params; 10207 struct crypto_unittest_params *ut_params = &unittest_params; 10208 struct rte_cryptodev_info dev_info; 10209 10210 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10211 uint64_t feat_flags = dev_info.feature_flags; 10212 10213 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10214 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10215 printf("Device doesn't support RAW data-path APIs.\n"); 10216 return -ENOTSUP; 10217 } 10218 10219 /* Verify the capabilities */ 10220 struct rte_cryptodev_sym_capability_idx cap_idx; 10221 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10222 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 10223 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10224 &cap_idx) == NULL) 10225 return -ENOTSUP; 10226 10227 if (MD5_HMAC_create_session(ts_params, ut_params, 10228 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 10229 return TEST_FAILED; 10230 } 10231 10232 /* Generate Crypto op data structure */ 10233 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10234 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10235 TEST_ASSERT_NOT_NULL(ut_params->op, 10236 "Failed to allocate symmetric crypto operation struct"); 10237 10238 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 10239 return TEST_FAILED; 10240 10241 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10242 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 10243 ut_params->op); 10244 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10245 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10246 ut_params->op, 0, 1, 0, 0); 10247 else 10248 TEST_ASSERT_NOT_NULL( 10249 process_crypto_request(ts_params->valid_devs[0], 10250 ut_params->op), 10251 "failed to process sym crypto op"); 10252 10253 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10254 "HMAC_MD5 crypto op processing failed"); 10255 10256 return TEST_SUCCESS; 10257 } 10258 10259 static int 10260 test_MD5_HMAC_generate_case_1(void) 10261 { 10262 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 10263 } 10264 10265 static int 10266 test_MD5_HMAC_verify_case_1(void) 10267 { 10268 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 10269 } 10270 10271 static int 10272 test_MD5_HMAC_generate_case_2(void) 10273 { 10274 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 10275 } 10276 10277 static int 10278 test_MD5_HMAC_verify_case_2(void) 10279 { 10280 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 10281 } 10282 10283 static int 10284 test_multi_session(void) 10285 { 10286 struct crypto_testsuite_params *ts_params = &testsuite_params; 10287 struct crypto_unittest_params *ut_params = &unittest_params; 10288 10289 struct rte_cryptodev_info dev_info; 10290 struct rte_cryptodev_sym_session **sessions; 10291 10292 uint16_t i; 10293 10294 /* Verify the capabilities */ 10295 struct rte_cryptodev_sym_capability_idx cap_idx; 10296 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10297 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 10298 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10299 &cap_idx) == NULL) 10300 return -ENOTSUP; 10301 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10302 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 10303 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10304 &cap_idx) == NULL) 10305 return -ENOTSUP; 10306 10307 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 10308 aes_cbc_key, hmac_sha512_key); 10309 10310 10311 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10312 10313 sessions = rte_malloc(NULL, 10314 (sizeof(struct rte_cryptodev_sym_session *) * 10315 MAX_NB_SESSIONS) + 1, 0); 10316 10317 /* Create multiple crypto sessions*/ 10318 for (i = 0; i < MAX_NB_SESSIONS; i++) { 10319 10320 sessions[i] = rte_cryptodev_sym_session_create( 10321 ts_params->session_mpool); 10322 10323 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10324 sessions[i], &ut_params->auth_xform, 10325 ts_params->session_priv_mpool); 10326 TEST_ASSERT_NOT_NULL(sessions[i], 10327 "Session creation failed at session number %u", 10328 i); 10329 10330 /* Attempt to send a request on each session */ 10331 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform( 10332 sessions[i], 10333 ut_params, 10334 ts_params, 10335 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 10336 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 10337 aes_cbc_iv), 10338 "Failed to perform decrypt on request number %u.", i); 10339 /* free crypto operation structure */ 10340 if (ut_params->op) 10341 rte_crypto_op_free(ut_params->op); 10342 10343 /* 10344 * free mbuf - both obuf and ibuf are usually the same, 10345 * so check if they point at the same address is necessary, 10346 * to avoid freeing the mbuf twice. 10347 */ 10348 if (ut_params->obuf) { 10349 rte_pktmbuf_free(ut_params->obuf); 10350 if (ut_params->ibuf == ut_params->obuf) 10351 ut_params->ibuf = 0; 10352 ut_params->obuf = 0; 10353 } 10354 if (ut_params->ibuf) { 10355 rte_pktmbuf_free(ut_params->ibuf); 10356 ut_params->ibuf = 0; 10357 } 10358 } 10359 10360 /* Next session create should fail */ 10361 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10362 sessions[i], &ut_params->auth_xform, 10363 ts_params->session_priv_mpool); 10364 TEST_ASSERT_NULL(sessions[i], 10365 "Session creation succeeded unexpectedly!"); 10366 10367 for (i = 0; i < MAX_NB_SESSIONS; i++) { 10368 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 10369 sessions[i]); 10370 rte_cryptodev_sym_session_free(sessions[i]); 10371 } 10372 10373 rte_free(sessions); 10374 10375 return TEST_SUCCESS; 10376 } 10377 10378 struct multi_session_params { 10379 struct crypto_unittest_params ut_params; 10380 uint8_t *cipher_key; 10381 uint8_t *hmac_key; 10382 const uint8_t *cipher; 10383 const uint8_t *digest; 10384 uint8_t *iv; 10385 }; 10386 10387 #define MB_SESSION_NUMBER 3 10388 10389 static int 10390 test_multi_session_random_usage(void) 10391 { 10392 struct crypto_testsuite_params *ts_params = &testsuite_params; 10393 struct rte_cryptodev_info dev_info; 10394 struct rte_cryptodev_sym_session **sessions; 10395 uint32_t i, j; 10396 struct multi_session_params ut_paramz[] = { 10397 10398 { 10399 .cipher_key = ms_aes_cbc_key0, 10400 .hmac_key = ms_hmac_key0, 10401 .cipher = ms_aes_cbc_cipher0, 10402 .digest = ms_hmac_digest0, 10403 .iv = ms_aes_cbc_iv0 10404 }, 10405 { 10406 .cipher_key = ms_aes_cbc_key1, 10407 .hmac_key = ms_hmac_key1, 10408 .cipher = ms_aes_cbc_cipher1, 10409 .digest = ms_hmac_digest1, 10410 .iv = ms_aes_cbc_iv1 10411 }, 10412 { 10413 .cipher_key = ms_aes_cbc_key2, 10414 .hmac_key = ms_hmac_key2, 10415 .cipher = ms_aes_cbc_cipher2, 10416 .digest = ms_hmac_digest2, 10417 .iv = ms_aes_cbc_iv2 10418 }, 10419 10420 }; 10421 10422 /* Verify the capabilities */ 10423 struct rte_cryptodev_sym_capability_idx cap_idx; 10424 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10425 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 10426 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10427 &cap_idx) == NULL) 10428 return -ENOTSUP; 10429 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10430 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 10431 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10432 &cap_idx) == NULL) 10433 return -ENOTSUP; 10434 10435 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10436 10437 sessions = rte_malloc(NULL, 10438 (sizeof(struct rte_cryptodev_sym_session *) 10439 * MAX_NB_SESSIONS) + 1, 0); 10440 10441 for (i = 0; i < MB_SESSION_NUMBER; i++) { 10442 sessions[i] = rte_cryptodev_sym_session_create( 10443 ts_params->session_mpool); 10444 10445 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params, 10446 sizeof(struct crypto_unittest_params)); 10447 10448 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 10449 &ut_paramz[i].ut_params, 10450 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 10451 10452 /* Create multiple crypto sessions*/ 10453 rte_cryptodev_sym_session_init( 10454 ts_params->valid_devs[0], 10455 sessions[i], 10456 &ut_paramz[i].ut_params.auth_xform, 10457 ts_params->session_priv_mpool); 10458 10459 TEST_ASSERT_NOT_NULL(sessions[i], 10460 "Session creation failed at session number %u", 10461 i); 10462 10463 } 10464 10465 srand(time(NULL)); 10466 for (i = 0; i < 40000; i++) { 10467 10468 j = rand() % MB_SESSION_NUMBER; 10469 10470 TEST_ASSERT_SUCCESS( 10471 test_AES_CBC_HMAC_SHA512_decrypt_perform( 10472 sessions[j], 10473 &ut_paramz[j].ut_params, 10474 ts_params, ut_paramz[j].cipher, 10475 ut_paramz[j].digest, 10476 ut_paramz[j].iv), 10477 "Failed to perform decrypt on request number %u.", i); 10478 10479 if (ut_paramz[j].ut_params.op) 10480 rte_crypto_op_free(ut_paramz[j].ut_params.op); 10481 10482 /* 10483 * free mbuf - both obuf and ibuf are usually the same, 10484 * so check if they point at the same address is necessary, 10485 * to avoid freeing the mbuf twice. 10486 */ 10487 if (ut_paramz[j].ut_params.obuf) { 10488 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 10489 if (ut_paramz[j].ut_params.ibuf 10490 == ut_paramz[j].ut_params.obuf) 10491 ut_paramz[j].ut_params.ibuf = 0; 10492 ut_paramz[j].ut_params.obuf = 0; 10493 } 10494 if (ut_paramz[j].ut_params.ibuf) { 10495 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 10496 ut_paramz[j].ut_params.ibuf = 0; 10497 } 10498 } 10499 10500 for (i = 0; i < MB_SESSION_NUMBER; i++) { 10501 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 10502 sessions[i]); 10503 rte_cryptodev_sym_session_free(sessions[i]); 10504 } 10505 10506 rte_free(sessions); 10507 10508 return TEST_SUCCESS; 10509 } 10510 10511 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab, 10512 0xab, 0xab, 0xab, 0xab, 10513 0xab, 0xab, 0xab, 0xab, 10514 0xab, 0xab, 0xab, 0xab}; 10515 10516 static int 10517 test_null_invalid_operation(void) 10518 { 10519 struct crypto_testsuite_params *ts_params = &testsuite_params; 10520 struct crypto_unittest_params *ut_params = &unittest_params; 10521 int ret; 10522 10523 /* This test is for NULL PMD only */ 10524 if (gbl_driver_id != rte_cryptodev_driver_id_get( 10525 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 10526 return -ENOTSUP; 10527 10528 /* Setup Cipher Parameters */ 10529 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10530 ut_params->cipher_xform.next = NULL; 10531 10532 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 10533 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 10534 10535 ut_params->sess = rte_cryptodev_sym_session_create( 10536 ts_params->session_mpool); 10537 10538 /* Create Crypto session*/ 10539 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10540 ut_params->sess, &ut_params->cipher_xform, 10541 ts_params->session_priv_mpool); 10542 TEST_ASSERT(ret < 0, 10543 "Session creation succeeded unexpectedly"); 10544 10545 10546 /* Setup HMAC Parameters */ 10547 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10548 ut_params->auth_xform.next = NULL; 10549 10550 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 10551 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 10552 10553 ut_params->sess = rte_cryptodev_sym_session_create( 10554 ts_params->session_mpool); 10555 10556 /* Create Crypto session*/ 10557 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10558 ut_params->sess, &ut_params->auth_xform, 10559 ts_params->session_priv_mpool); 10560 TEST_ASSERT(ret < 0, 10561 "Session creation succeeded unexpectedly"); 10562 10563 return TEST_SUCCESS; 10564 } 10565 10566 10567 #define NULL_BURST_LENGTH (32) 10568 10569 static int 10570 test_null_burst_operation(void) 10571 { 10572 struct crypto_testsuite_params *ts_params = &testsuite_params; 10573 struct crypto_unittest_params *ut_params = &unittest_params; 10574 10575 unsigned i, burst_len = NULL_BURST_LENGTH; 10576 10577 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 10578 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 10579 10580 /* This test is for NULL PMD only */ 10581 if (gbl_driver_id != rte_cryptodev_driver_id_get( 10582 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 10583 return -ENOTSUP; 10584 10585 /* Setup Cipher Parameters */ 10586 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10587 ut_params->cipher_xform.next = &ut_params->auth_xform; 10588 10589 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 10590 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 10591 10592 /* Setup HMAC Parameters */ 10593 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10594 ut_params->auth_xform.next = NULL; 10595 10596 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 10597 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 10598 10599 ut_params->sess = rte_cryptodev_sym_session_create( 10600 ts_params->session_mpool); 10601 10602 /* Create Crypto session*/ 10603 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10604 ut_params->sess, &ut_params->cipher_xform, 10605 ts_params->session_priv_mpool); 10606 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 10607 10608 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 10609 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 10610 burst_len, "failed to generate burst of crypto ops"); 10611 10612 /* Generate an operation for each mbuf in burst */ 10613 for (i = 0; i < burst_len; i++) { 10614 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10615 10616 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 10617 10618 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 10619 sizeof(unsigned)); 10620 *data = i; 10621 10622 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 10623 10624 burst[i]->sym->m_src = m; 10625 } 10626 10627 /* Process crypto operation */ 10628 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 10629 0, burst, burst_len), 10630 burst_len, 10631 "Error enqueuing burst"); 10632 10633 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 10634 0, burst_dequeued, burst_len), 10635 burst_len, 10636 "Error dequeuing burst"); 10637 10638 10639 for (i = 0; i < burst_len; i++) { 10640 TEST_ASSERT_EQUAL( 10641 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 10642 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 10643 uint32_t *), 10644 "data not as expected"); 10645 10646 rte_pktmbuf_free(burst[i]->sym->m_src); 10647 rte_crypto_op_free(burst[i]); 10648 } 10649 10650 return TEST_SUCCESS; 10651 } 10652 10653 static void 10654 generate_gmac_large_plaintext(uint8_t *data) 10655 { 10656 uint16_t i; 10657 10658 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 10659 memcpy(&data[i], &data[0], 32); 10660 } 10661 10662 static int 10663 create_gmac_operation(enum rte_crypto_auth_operation op, 10664 const struct gmac_test_data *tdata) 10665 { 10666 struct crypto_testsuite_params *ts_params = &testsuite_params; 10667 struct crypto_unittest_params *ut_params = &unittest_params; 10668 struct rte_crypto_sym_op *sym_op; 10669 10670 uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 10671 10672 /* Generate Crypto op data structure */ 10673 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10674 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10675 TEST_ASSERT_NOT_NULL(ut_params->op, 10676 "Failed to allocate symmetric crypto operation struct"); 10677 10678 sym_op = ut_params->op->sym; 10679 10680 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 10681 ut_params->ibuf, tdata->gmac_tag.len); 10682 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 10683 "no room to append digest"); 10684 10685 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 10686 ut_params->ibuf, plaintext_pad_len); 10687 10688 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 10689 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 10690 tdata->gmac_tag.len); 10691 debug_hexdump(stdout, "digest:", 10692 sym_op->auth.digest.data, 10693 tdata->gmac_tag.len); 10694 } 10695 10696 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 10697 uint8_t *, IV_OFFSET); 10698 10699 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 10700 10701 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 10702 10703 sym_op->cipher.data.length = 0; 10704 sym_op->cipher.data.offset = 0; 10705 10706 sym_op->auth.data.offset = 0; 10707 sym_op->auth.data.length = tdata->plaintext.len; 10708 10709 return 0; 10710 } 10711 10712 static int 10713 create_gmac_operation_sgl(enum rte_crypto_auth_operation op, 10714 const struct gmac_test_data *tdata, 10715 void *digest_mem, uint64_t digest_phys) 10716 { 10717 struct crypto_testsuite_params *ts_params = &testsuite_params; 10718 struct crypto_unittest_params *ut_params = &unittest_params; 10719 struct rte_crypto_sym_op *sym_op; 10720 10721 /* Generate Crypto op data structure */ 10722 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10723 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10724 TEST_ASSERT_NOT_NULL(ut_params->op, 10725 "Failed to allocate symmetric crypto operation struct"); 10726 10727 sym_op = ut_params->op->sym; 10728 10729 sym_op->auth.digest.data = digest_mem; 10730 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 10731 "no room to append digest"); 10732 10733 sym_op->auth.digest.phys_addr = digest_phys; 10734 10735 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 10736 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 10737 tdata->gmac_tag.len); 10738 debug_hexdump(stdout, "digest:", 10739 sym_op->auth.digest.data, 10740 tdata->gmac_tag.len); 10741 } 10742 10743 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 10744 uint8_t *, IV_OFFSET); 10745 10746 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 10747 10748 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 10749 10750 sym_op->cipher.data.length = 0; 10751 sym_op->cipher.data.offset = 0; 10752 10753 sym_op->auth.data.offset = 0; 10754 sym_op->auth.data.length = tdata->plaintext.len; 10755 10756 return 0; 10757 } 10758 10759 static int create_gmac_session(uint8_t dev_id, 10760 const struct gmac_test_data *tdata, 10761 enum rte_crypto_auth_operation auth_op) 10762 { 10763 uint8_t auth_key[tdata->key.len]; 10764 10765 struct crypto_testsuite_params *ts_params = &testsuite_params; 10766 struct crypto_unittest_params *ut_params = &unittest_params; 10767 10768 memcpy(auth_key, tdata->key.data, tdata->key.len); 10769 10770 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10771 ut_params->auth_xform.next = NULL; 10772 10773 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 10774 ut_params->auth_xform.auth.op = auth_op; 10775 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 10776 ut_params->auth_xform.auth.key.length = tdata->key.len; 10777 ut_params->auth_xform.auth.key.data = auth_key; 10778 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 10779 ut_params->auth_xform.auth.iv.length = tdata->iv.len; 10780 10781 10782 ut_params->sess = rte_cryptodev_sym_session_create( 10783 ts_params->session_mpool); 10784 10785 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 10786 &ut_params->auth_xform, 10787 ts_params->session_priv_mpool); 10788 10789 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 10790 10791 return 0; 10792 } 10793 10794 static int 10795 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 10796 { 10797 struct crypto_testsuite_params *ts_params = &testsuite_params; 10798 struct crypto_unittest_params *ut_params = &unittest_params; 10799 struct rte_cryptodev_info dev_info; 10800 10801 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10802 uint64_t feat_flags = dev_info.feature_flags; 10803 10804 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10805 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10806 printf("Device doesn't support RAW data-path APIs.\n"); 10807 return -ENOTSUP; 10808 } 10809 10810 int retval; 10811 10812 uint8_t *auth_tag, *plaintext; 10813 uint16_t plaintext_pad_len; 10814 10815 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 10816 "No GMAC length in the source data"); 10817 10818 /* Verify the capabilities */ 10819 struct rte_cryptodev_sym_capability_idx cap_idx; 10820 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10821 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 10822 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10823 &cap_idx) == NULL) 10824 return -ENOTSUP; 10825 10826 retval = create_gmac_session(ts_params->valid_devs[0], 10827 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 10828 10829 if (retval < 0) 10830 return retval; 10831 10832 if (tdata->plaintext.len > MBUF_SIZE) 10833 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 10834 else 10835 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10836 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 10837 "Failed to allocate input buffer in mempool"); 10838 10839 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10840 rte_pktmbuf_tailroom(ut_params->ibuf)); 10841 10842 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 10843 /* 10844 * Runtime generate the large plain text instead of use hard code 10845 * plain text vector. It is done to avoid create huge source file 10846 * with the test vector. 10847 */ 10848 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 10849 generate_gmac_large_plaintext(tdata->plaintext.data); 10850 10851 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10852 plaintext_pad_len); 10853 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 10854 10855 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 10856 debug_hexdump(stdout, "plaintext:", plaintext, 10857 tdata->plaintext.len); 10858 10859 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 10860 tdata); 10861 10862 if (retval < 0) 10863 return retval; 10864 10865 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10866 10867 ut_params->op->sym->m_src = ut_params->ibuf; 10868 10869 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10870 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 10871 ut_params->op); 10872 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10873 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10874 ut_params->op, 0, 1, 0, 0); 10875 else 10876 TEST_ASSERT_NOT_NULL( 10877 process_crypto_request(ts_params->valid_devs[0], 10878 ut_params->op), "failed to process sym crypto op"); 10879 10880 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10881 "crypto op processing failed"); 10882 10883 if (ut_params->op->sym->m_dst) { 10884 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 10885 uint8_t *, plaintext_pad_len); 10886 } else { 10887 auth_tag = plaintext + plaintext_pad_len; 10888 } 10889 10890 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 10891 10892 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10893 auth_tag, 10894 tdata->gmac_tag.data, 10895 tdata->gmac_tag.len, 10896 "GMAC Generated auth tag not as expected"); 10897 10898 return 0; 10899 } 10900 10901 static int 10902 test_AES_GMAC_authentication_test_case_1(void) 10903 { 10904 return test_AES_GMAC_authentication(&gmac_test_case_1); 10905 } 10906 10907 static int 10908 test_AES_GMAC_authentication_test_case_2(void) 10909 { 10910 return test_AES_GMAC_authentication(&gmac_test_case_2); 10911 } 10912 10913 static int 10914 test_AES_GMAC_authentication_test_case_3(void) 10915 { 10916 return test_AES_GMAC_authentication(&gmac_test_case_3); 10917 } 10918 10919 static int 10920 test_AES_GMAC_authentication_test_case_4(void) 10921 { 10922 return test_AES_GMAC_authentication(&gmac_test_case_4); 10923 } 10924 10925 static int 10926 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 10927 { 10928 struct crypto_testsuite_params *ts_params = &testsuite_params; 10929 struct crypto_unittest_params *ut_params = &unittest_params; 10930 int retval; 10931 uint32_t plaintext_pad_len; 10932 uint8_t *plaintext; 10933 struct rte_cryptodev_info dev_info; 10934 10935 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10936 uint64_t feat_flags = dev_info.feature_flags; 10937 10938 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10939 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10940 printf("Device doesn't support RAW data-path APIs.\n"); 10941 return -ENOTSUP; 10942 } 10943 10944 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 10945 "No GMAC length in the source data"); 10946 10947 /* Verify the capabilities */ 10948 struct rte_cryptodev_sym_capability_idx cap_idx; 10949 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10950 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 10951 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10952 &cap_idx) == NULL) 10953 return -ENOTSUP; 10954 10955 retval = create_gmac_session(ts_params->valid_devs[0], 10956 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 10957 10958 if (retval < 0) 10959 return retval; 10960 10961 if (tdata->plaintext.len > MBUF_SIZE) 10962 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 10963 else 10964 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10965 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 10966 "Failed to allocate input buffer in mempool"); 10967 10968 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10969 rte_pktmbuf_tailroom(ut_params->ibuf)); 10970 10971 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 10972 10973 /* 10974 * Runtime generate the large plain text instead of use hard code 10975 * plain text vector. It is done to avoid create huge source file 10976 * with the test vector. 10977 */ 10978 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 10979 generate_gmac_large_plaintext(tdata->plaintext.data); 10980 10981 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10982 plaintext_pad_len); 10983 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 10984 10985 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 10986 debug_hexdump(stdout, "plaintext:", plaintext, 10987 tdata->plaintext.len); 10988 10989 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 10990 tdata); 10991 10992 if (retval < 0) 10993 return retval; 10994 10995 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10996 10997 ut_params->op->sym->m_src = ut_params->ibuf; 10998 10999 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11000 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11001 ut_params->op); 11002 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11003 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11004 ut_params->op, 0, 1, 0, 0); 11005 else 11006 TEST_ASSERT_NOT_NULL( 11007 process_crypto_request(ts_params->valid_devs[0], 11008 ut_params->op), "failed to process sym crypto op"); 11009 11010 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11011 "crypto op processing failed"); 11012 11013 return 0; 11014 11015 } 11016 11017 static int 11018 test_AES_GMAC_authentication_verify_test_case_1(void) 11019 { 11020 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 11021 } 11022 11023 static int 11024 test_AES_GMAC_authentication_verify_test_case_2(void) 11025 { 11026 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 11027 } 11028 11029 static int 11030 test_AES_GMAC_authentication_verify_test_case_3(void) 11031 { 11032 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 11033 } 11034 11035 static int 11036 test_AES_GMAC_authentication_verify_test_case_4(void) 11037 { 11038 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 11039 } 11040 11041 static int 11042 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata, 11043 uint32_t fragsz) 11044 { 11045 struct crypto_testsuite_params *ts_params = &testsuite_params; 11046 struct crypto_unittest_params *ut_params = &unittest_params; 11047 struct rte_cryptodev_info dev_info; 11048 uint64_t feature_flags; 11049 unsigned int trn_data = 0; 11050 void *digest_mem = NULL; 11051 uint32_t segs = 1; 11052 unsigned int to_trn = 0; 11053 struct rte_mbuf *buf = NULL; 11054 uint8_t *auth_tag, *plaintext; 11055 int retval; 11056 11057 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 11058 "No GMAC length in the source data"); 11059 11060 /* Verify the capabilities */ 11061 struct rte_cryptodev_sym_capability_idx cap_idx; 11062 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11063 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 11064 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11065 &cap_idx) == NULL) 11066 return -ENOTSUP; 11067 11068 /* Check for any input SGL support */ 11069 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11070 feature_flags = dev_info.feature_flags; 11071 11072 if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) && 11073 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) && 11074 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))) 11075 return -ENOTSUP; 11076 11077 if (fragsz > tdata->plaintext.len) 11078 fragsz = tdata->plaintext.len; 11079 11080 uint16_t plaintext_len = fragsz; 11081 11082 retval = create_gmac_session(ts_params->valid_devs[0], 11083 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 11084 11085 if (retval < 0) 11086 return retval; 11087 11088 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11089 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 11090 "Failed to allocate input buffer in mempool"); 11091 11092 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11093 rte_pktmbuf_tailroom(ut_params->ibuf)); 11094 11095 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11096 plaintext_len); 11097 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 11098 11099 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 11100 11101 trn_data += plaintext_len; 11102 11103 buf = ut_params->ibuf; 11104 11105 /* 11106 * Loop until no more fragments 11107 */ 11108 11109 while (trn_data < tdata->plaintext.len) { 11110 ++segs; 11111 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 11112 (tdata->plaintext.len - trn_data) : fragsz; 11113 11114 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11115 buf = buf->next; 11116 11117 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 11118 rte_pktmbuf_tailroom(buf)); 11119 11120 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 11121 to_trn); 11122 11123 memcpy(plaintext, tdata->plaintext.data + trn_data, 11124 to_trn); 11125 trn_data += to_trn; 11126 if (trn_data == tdata->plaintext.len) 11127 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 11128 tdata->gmac_tag.len); 11129 } 11130 ut_params->ibuf->nb_segs = segs; 11131 11132 /* 11133 * Place digest at the end of the last buffer 11134 */ 11135 uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn; 11136 11137 if (!digest_mem) { 11138 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11139 + tdata->gmac_tag.len); 11140 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 11141 tdata->plaintext.len); 11142 } 11143 11144 retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE, 11145 tdata, digest_mem, digest_phys); 11146 11147 if (retval < 0) 11148 return retval; 11149 11150 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11151 11152 ut_params->op->sym->m_src = ut_params->ibuf; 11153 11154 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11155 return -ENOTSUP; 11156 11157 TEST_ASSERT_NOT_NULL( 11158 process_crypto_request(ts_params->valid_devs[0], 11159 ut_params->op), "failed to process sym crypto op"); 11160 11161 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11162 "crypto op processing failed"); 11163 11164 auth_tag = digest_mem; 11165 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 11166 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11167 auth_tag, 11168 tdata->gmac_tag.data, 11169 tdata->gmac_tag.len, 11170 "GMAC Generated auth tag not as expected"); 11171 11172 return 0; 11173 } 11174 11175 /* Segment size not multiple of block size (16B) */ 11176 static int 11177 test_AES_GMAC_authentication_SGL_40B(void) 11178 { 11179 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40); 11180 } 11181 11182 static int 11183 test_AES_GMAC_authentication_SGL_80B(void) 11184 { 11185 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80); 11186 } 11187 11188 static int 11189 test_AES_GMAC_authentication_SGL_2048B(void) 11190 { 11191 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048); 11192 } 11193 11194 /* Segment size not multiple of block size (16B) */ 11195 static int 11196 test_AES_GMAC_authentication_SGL_2047B(void) 11197 { 11198 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047); 11199 } 11200 11201 struct test_crypto_vector { 11202 enum rte_crypto_cipher_algorithm crypto_algo; 11203 unsigned int cipher_offset; 11204 unsigned int cipher_len; 11205 11206 struct { 11207 uint8_t data[64]; 11208 unsigned int len; 11209 } cipher_key; 11210 11211 struct { 11212 uint8_t data[64]; 11213 unsigned int len; 11214 } iv; 11215 11216 struct { 11217 const uint8_t *data; 11218 unsigned int len; 11219 } plaintext; 11220 11221 struct { 11222 const uint8_t *data; 11223 unsigned int len; 11224 } ciphertext; 11225 11226 enum rte_crypto_auth_algorithm auth_algo; 11227 unsigned int auth_offset; 11228 11229 struct { 11230 uint8_t data[128]; 11231 unsigned int len; 11232 } auth_key; 11233 11234 struct { 11235 const uint8_t *data; 11236 unsigned int len; 11237 } aad; 11238 11239 struct { 11240 uint8_t data[128]; 11241 unsigned int len; 11242 } digest; 11243 }; 11244 11245 static const struct test_crypto_vector 11246 hmac_sha1_test_crypto_vector = { 11247 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 11248 .plaintext = { 11249 .data = plaintext_hash, 11250 .len = 512 11251 }, 11252 .auth_key = { 11253 .data = { 11254 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 11255 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 11256 0xDE, 0xF4, 0xDE, 0xAD 11257 }, 11258 .len = 20 11259 }, 11260 .digest = { 11261 .data = { 11262 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 11263 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 11264 0x3F, 0x91, 0x64, 0x59 11265 }, 11266 .len = 20 11267 } 11268 }; 11269 11270 static const struct test_crypto_vector 11271 aes128_gmac_test_vector = { 11272 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 11273 .plaintext = { 11274 .data = plaintext_hash, 11275 .len = 512 11276 }, 11277 .iv = { 11278 .data = { 11279 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 11280 0x08, 0x09, 0x0A, 0x0B 11281 }, 11282 .len = 12 11283 }, 11284 .auth_key = { 11285 .data = { 11286 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 11287 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 11288 }, 11289 .len = 16 11290 }, 11291 .digest = { 11292 .data = { 11293 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 11294 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 11295 }, 11296 .len = 16 11297 } 11298 }; 11299 11300 static const struct test_crypto_vector 11301 aes128cbc_hmac_sha1_test_vector = { 11302 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 11303 .cipher_offset = 0, 11304 .cipher_len = 512, 11305 .cipher_key = { 11306 .data = { 11307 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 11308 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 11309 }, 11310 .len = 16 11311 }, 11312 .iv = { 11313 .data = { 11314 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 11315 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 11316 }, 11317 .len = 16 11318 }, 11319 .plaintext = { 11320 .data = plaintext_hash, 11321 .len = 512 11322 }, 11323 .ciphertext = { 11324 .data = ciphertext512_aes128cbc, 11325 .len = 512 11326 }, 11327 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 11328 .auth_offset = 0, 11329 .auth_key = { 11330 .data = { 11331 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 11332 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 11333 0xDE, 0xF4, 0xDE, 0xAD 11334 }, 11335 .len = 20 11336 }, 11337 .digest = { 11338 .data = { 11339 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 11340 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 11341 0x18, 0x8C, 0x1D, 0x32 11342 }, 11343 .len = 20 11344 } 11345 }; 11346 11347 static const struct test_crypto_vector 11348 aes128cbc_hmac_sha1_aad_test_vector = { 11349 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 11350 .cipher_offset = 8, 11351 .cipher_len = 496, 11352 .cipher_key = { 11353 .data = { 11354 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 11355 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 11356 }, 11357 .len = 16 11358 }, 11359 .iv = { 11360 .data = { 11361 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 11362 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 11363 }, 11364 .len = 16 11365 }, 11366 .plaintext = { 11367 .data = plaintext_hash, 11368 .len = 512 11369 }, 11370 .ciphertext = { 11371 .data = ciphertext512_aes128cbc_aad, 11372 .len = 512 11373 }, 11374 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 11375 .auth_offset = 0, 11376 .auth_key = { 11377 .data = { 11378 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 11379 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 11380 0xDE, 0xF4, 0xDE, 0xAD 11381 }, 11382 .len = 20 11383 }, 11384 .digest = { 11385 .data = { 11386 0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F, 11387 0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B, 11388 0x62, 0x0F, 0xFB, 0x10 11389 }, 11390 .len = 20 11391 } 11392 }; 11393 11394 static void 11395 data_corruption(uint8_t *data) 11396 { 11397 data[0] += 1; 11398 } 11399 11400 static void 11401 tag_corruption(uint8_t *data, unsigned int tag_offset) 11402 { 11403 data[tag_offset] += 1; 11404 } 11405 11406 static int 11407 create_auth_session(struct crypto_unittest_params *ut_params, 11408 uint8_t dev_id, 11409 const struct test_crypto_vector *reference, 11410 enum rte_crypto_auth_operation auth_op) 11411 { 11412 struct crypto_testsuite_params *ts_params = &testsuite_params; 11413 uint8_t auth_key[reference->auth_key.len + 1]; 11414 11415 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 11416 11417 /* Setup Authentication Parameters */ 11418 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11419 ut_params->auth_xform.auth.op = auth_op; 11420 ut_params->auth_xform.next = NULL; 11421 ut_params->auth_xform.auth.algo = reference->auth_algo; 11422 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 11423 ut_params->auth_xform.auth.key.data = auth_key; 11424 ut_params->auth_xform.auth.digest_length = reference->digest.len; 11425 11426 /* Create Crypto session*/ 11427 ut_params->sess = rte_cryptodev_sym_session_create( 11428 ts_params->session_mpool); 11429 11430 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 11431 &ut_params->auth_xform, 11432 ts_params->session_priv_mpool); 11433 11434 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11435 11436 return 0; 11437 } 11438 11439 static int 11440 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 11441 uint8_t dev_id, 11442 const struct test_crypto_vector *reference, 11443 enum rte_crypto_auth_operation auth_op, 11444 enum rte_crypto_cipher_operation cipher_op) 11445 { 11446 struct crypto_testsuite_params *ts_params = &testsuite_params; 11447 uint8_t cipher_key[reference->cipher_key.len + 1]; 11448 uint8_t auth_key[reference->auth_key.len + 1]; 11449 11450 memcpy(cipher_key, reference->cipher_key.data, 11451 reference->cipher_key.len); 11452 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 11453 11454 /* Setup Authentication Parameters */ 11455 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11456 ut_params->auth_xform.auth.op = auth_op; 11457 ut_params->auth_xform.auth.algo = reference->auth_algo; 11458 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 11459 ut_params->auth_xform.auth.key.data = auth_key; 11460 ut_params->auth_xform.auth.digest_length = reference->digest.len; 11461 11462 if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) { 11463 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 11464 ut_params->auth_xform.auth.iv.length = reference->iv.len; 11465 } else { 11466 ut_params->auth_xform.next = &ut_params->cipher_xform; 11467 11468 /* Setup Cipher Parameters */ 11469 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11470 ut_params->cipher_xform.next = NULL; 11471 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 11472 ut_params->cipher_xform.cipher.op = cipher_op; 11473 ut_params->cipher_xform.cipher.key.data = cipher_key; 11474 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 11475 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 11476 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 11477 } 11478 11479 /* Create Crypto session*/ 11480 ut_params->sess = rte_cryptodev_sym_session_create( 11481 ts_params->session_mpool); 11482 11483 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 11484 &ut_params->auth_xform, 11485 ts_params->session_priv_mpool); 11486 11487 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11488 11489 return 0; 11490 } 11491 11492 static int 11493 create_auth_operation(struct crypto_testsuite_params *ts_params, 11494 struct crypto_unittest_params *ut_params, 11495 const struct test_crypto_vector *reference, 11496 unsigned int auth_generate) 11497 { 11498 /* Generate Crypto op data structure */ 11499 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11500 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11501 TEST_ASSERT_NOT_NULL(ut_params->op, 11502 "Failed to allocate pktmbuf offload"); 11503 11504 /* Set crypto operation data parameters */ 11505 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11506 11507 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 11508 11509 /* set crypto operation source mbuf */ 11510 sym_op->m_src = ut_params->ibuf; 11511 11512 /* digest */ 11513 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11514 ut_params->ibuf, reference->digest.len); 11515 11516 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11517 "no room to append auth tag"); 11518 11519 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11520 ut_params->ibuf, reference->plaintext.len); 11521 11522 if (auth_generate) 11523 memset(sym_op->auth.digest.data, 0, reference->digest.len); 11524 else 11525 memcpy(sym_op->auth.digest.data, 11526 reference->digest.data, 11527 reference->digest.len); 11528 11529 debug_hexdump(stdout, "digest:", 11530 sym_op->auth.digest.data, 11531 reference->digest.len); 11532 11533 sym_op->auth.data.length = reference->plaintext.len; 11534 sym_op->auth.data.offset = 0; 11535 11536 return 0; 11537 } 11538 11539 static int 11540 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 11541 struct crypto_unittest_params *ut_params, 11542 const struct test_crypto_vector *reference, 11543 unsigned int auth_generate) 11544 { 11545 /* Generate Crypto op data structure */ 11546 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11547 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11548 TEST_ASSERT_NOT_NULL(ut_params->op, 11549 "Failed to allocate pktmbuf offload"); 11550 11551 /* Set crypto operation data parameters */ 11552 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11553 11554 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 11555 11556 /* set crypto operation source mbuf */ 11557 sym_op->m_src = ut_params->ibuf; 11558 11559 /* digest */ 11560 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11561 ut_params->ibuf, reference->digest.len); 11562 11563 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11564 "no room to append auth tag"); 11565 11566 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11567 ut_params->ibuf, reference->ciphertext.len); 11568 11569 if (auth_generate) 11570 memset(sym_op->auth.digest.data, 0, reference->digest.len); 11571 else 11572 memcpy(sym_op->auth.digest.data, 11573 reference->digest.data, 11574 reference->digest.len); 11575 11576 debug_hexdump(stdout, "digest:", 11577 sym_op->auth.digest.data, 11578 reference->digest.len); 11579 11580 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 11581 reference->iv.data, reference->iv.len); 11582 11583 sym_op->cipher.data.length = 0; 11584 sym_op->cipher.data.offset = 0; 11585 11586 sym_op->auth.data.length = reference->plaintext.len; 11587 sym_op->auth.data.offset = 0; 11588 11589 return 0; 11590 } 11591 11592 static int 11593 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 11594 struct crypto_unittest_params *ut_params, 11595 const struct test_crypto_vector *reference, 11596 unsigned int auth_generate) 11597 { 11598 /* Generate Crypto op data structure */ 11599 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11600 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11601 TEST_ASSERT_NOT_NULL(ut_params->op, 11602 "Failed to allocate pktmbuf offload"); 11603 11604 /* Set crypto operation data parameters */ 11605 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11606 11607 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 11608 11609 /* set crypto operation source mbuf */ 11610 sym_op->m_src = ut_params->ibuf; 11611 11612 /* digest */ 11613 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11614 ut_params->ibuf, reference->digest.len); 11615 11616 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11617 "no room to append auth tag"); 11618 11619 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11620 ut_params->ibuf, reference->ciphertext.len); 11621 11622 if (auth_generate) 11623 memset(sym_op->auth.digest.data, 0, reference->digest.len); 11624 else 11625 memcpy(sym_op->auth.digest.data, 11626 reference->digest.data, 11627 reference->digest.len); 11628 11629 debug_hexdump(stdout, "digest:", 11630 sym_op->auth.digest.data, 11631 reference->digest.len); 11632 11633 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 11634 reference->iv.data, reference->iv.len); 11635 11636 sym_op->cipher.data.length = reference->cipher_len; 11637 sym_op->cipher.data.offset = reference->cipher_offset; 11638 11639 sym_op->auth.data.length = reference->plaintext.len; 11640 sym_op->auth.data.offset = reference->auth_offset; 11641 11642 return 0; 11643 } 11644 11645 static int 11646 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 11647 struct crypto_unittest_params *ut_params, 11648 const struct test_crypto_vector *reference) 11649 { 11650 return create_auth_operation(ts_params, ut_params, reference, 0); 11651 } 11652 11653 static int 11654 create_auth_verify_GMAC_operation( 11655 struct crypto_testsuite_params *ts_params, 11656 struct crypto_unittest_params *ut_params, 11657 const struct test_crypto_vector *reference) 11658 { 11659 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 11660 } 11661 11662 static int 11663 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params, 11664 struct crypto_unittest_params *ut_params, 11665 const struct test_crypto_vector *reference) 11666 { 11667 return create_cipher_auth_operation(ts_params, ut_params, reference, 0); 11668 } 11669 11670 static int 11671 test_authentication_verify_fail_when_data_corruption( 11672 struct crypto_testsuite_params *ts_params, 11673 struct crypto_unittest_params *ut_params, 11674 const struct test_crypto_vector *reference, 11675 unsigned int data_corrupted) 11676 { 11677 int retval; 11678 11679 uint8_t *plaintext; 11680 struct rte_cryptodev_info dev_info; 11681 11682 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11683 uint64_t feat_flags = dev_info.feature_flags; 11684 11685 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11686 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11687 printf("Device doesn't support RAW data-path APIs.\n"); 11688 return -ENOTSUP; 11689 } 11690 11691 /* Verify the capabilities */ 11692 struct rte_cryptodev_sym_capability_idx cap_idx; 11693 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11694 cap_idx.algo.auth = reference->auth_algo; 11695 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11696 &cap_idx) == NULL) 11697 return -ENOTSUP; 11698 11699 11700 /* Create session */ 11701 retval = create_auth_session(ut_params, 11702 ts_params->valid_devs[0], 11703 reference, 11704 RTE_CRYPTO_AUTH_OP_VERIFY); 11705 if (retval < 0) 11706 return retval; 11707 11708 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11709 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 11710 "Failed to allocate input buffer in mempool"); 11711 11712 /* clear mbuf payload */ 11713 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11714 rte_pktmbuf_tailroom(ut_params->ibuf)); 11715 11716 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11717 reference->plaintext.len); 11718 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 11719 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 11720 11721 debug_hexdump(stdout, "plaintext:", plaintext, 11722 reference->plaintext.len); 11723 11724 /* Create operation */ 11725 retval = create_auth_verify_operation(ts_params, ut_params, reference); 11726 11727 if (retval < 0) 11728 return retval; 11729 11730 if (data_corrupted) 11731 data_corruption(plaintext); 11732 else 11733 tag_corruption(plaintext, reference->plaintext.len); 11734 11735 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 11736 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11737 ut_params->op); 11738 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 11739 RTE_CRYPTO_OP_STATUS_SUCCESS, 11740 "authentication not failed"); 11741 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11742 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11743 ut_params->op, 0, 1, 0, 0); 11744 else { 11745 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 11746 ut_params->op); 11747 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 11748 } 11749 11750 return 0; 11751 } 11752 11753 static int 11754 test_authentication_verify_GMAC_fail_when_corruption( 11755 struct crypto_testsuite_params *ts_params, 11756 struct crypto_unittest_params *ut_params, 11757 const struct test_crypto_vector *reference, 11758 unsigned int data_corrupted) 11759 { 11760 int retval; 11761 uint8_t *plaintext; 11762 struct rte_cryptodev_info dev_info; 11763 11764 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11765 uint64_t feat_flags = dev_info.feature_flags; 11766 11767 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11768 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11769 printf("Device doesn't support RAW data-path APIs.\n"); 11770 return -ENOTSUP; 11771 } 11772 11773 /* Verify the capabilities */ 11774 struct rte_cryptodev_sym_capability_idx cap_idx; 11775 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11776 cap_idx.algo.auth = reference->auth_algo; 11777 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11778 &cap_idx) == NULL) 11779 return -ENOTSUP; 11780 11781 /* Create session */ 11782 retval = create_auth_cipher_session(ut_params, 11783 ts_params->valid_devs[0], 11784 reference, 11785 RTE_CRYPTO_AUTH_OP_VERIFY, 11786 RTE_CRYPTO_CIPHER_OP_DECRYPT); 11787 if (retval < 0) 11788 return retval; 11789 11790 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11791 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 11792 "Failed to allocate input buffer in mempool"); 11793 11794 /* clear mbuf payload */ 11795 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11796 rte_pktmbuf_tailroom(ut_params->ibuf)); 11797 11798 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11799 reference->plaintext.len); 11800 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 11801 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 11802 11803 debug_hexdump(stdout, "plaintext:", plaintext, 11804 reference->plaintext.len); 11805 11806 /* Create operation */ 11807 retval = create_auth_verify_GMAC_operation(ts_params, 11808 ut_params, 11809 reference); 11810 11811 if (retval < 0) 11812 return retval; 11813 11814 if (data_corrupted) 11815 data_corruption(plaintext); 11816 else 11817 tag_corruption(plaintext, reference->aad.len); 11818 11819 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 11820 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11821 ut_params->op); 11822 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 11823 RTE_CRYPTO_OP_STATUS_SUCCESS, 11824 "authentication not failed"); 11825 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11826 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11827 ut_params->op, 0, 1, 0, 0); 11828 else { 11829 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 11830 ut_params->op); 11831 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 11832 } 11833 11834 return 0; 11835 } 11836 11837 static int 11838 test_authenticated_decryption_fail_when_corruption( 11839 struct crypto_testsuite_params *ts_params, 11840 struct crypto_unittest_params *ut_params, 11841 const struct test_crypto_vector *reference, 11842 unsigned int data_corrupted) 11843 { 11844 int retval; 11845 11846 uint8_t *ciphertext; 11847 struct rte_cryptodev_info dev_info; 11848 11849 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11850 uint64_t feat_flags = dev_info.feature_flags; 11851 11852 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11853 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11854 printf("Device doesn't support RAW data-path APIs.\n"); 11855 return -ENOTSUP; 11856 } 11857 11858 /* Verify the capabilities */ 11859 struct rte_cryptodev_sym_capability_idx cap_idx; 11860 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11861 cap_idx.algo.auth = reference->auth_algo; 11862 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11863 &cap_idx) == NULL) 11864 return -ENOTSUP; 11865 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11866 cap_idx.algo.cipher = reference->crypto_algo; 11867 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11868 &cap_idx) == NULL) 11869 return -ENOTSUP; 11870 11871 /* Create session */ 11872 retval = create_auth_cipher_session(ut_params, 11873 ts_params->valid_devs[0], 11874 reference, 11875 RTE_CRYPTO_AUTH_OP_VERIFY, 11876 RTE_CRYPTO_CIPHER_OP_DECRYPT); 11877 if (retval < 0) 11878 return retval; 11879 11880 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11881 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 11882 "Failed to allocate input buffer in mempool"); 11883 11884 /* clear mbuf payload */ 11885 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11886 rte_pktmbuf_tailroom(ut_params->ibuf)); 11887 11888 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11889 reference->ciphertext.len); 11890 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 11891 memcpy(ciphertext, reference->ciphertext.data, 11892 reference->ciphertext.len); 11893 11894 /* Create operation */ 11895 retval = create_cipher_auth_verify_operation(ts_params, 11896 ut_params, 11897 reference); 11898 11899 if (retval < 0) 11900 return retval; 11901 11902 if (data_corrupted) 11903 data_corruption(ciphertext); 11904 else 11905 tag_corruption(ciphertext, reference->ciphertext.len); 11906 11907 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 11908 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11909 ut_params->op); 11910 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 11911 RTE_CRYPTO_OP_STATUS_SUCCESS, 11912 "authentication not failed"); 11913 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11914 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11915 ut_params->op, 1, 1, 0, 0); 11916 else { 11917 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 11918 ut_params->op); 11919 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 11920 } 11921 11922 return 0; 11923 } 11924 11925 static int 11926 test_authenticated_encryt_with_esn( 11927 struct crypto_testsuite_params *ts_params, 11928 struct crypto_unittest_params *ut_params, 11929 const struct test_crypto_vector *reference) 11930 { 11931 int retval; 11932 11933 uint8_t *authciphertext, *plaintext, *auth_tag; 11934 uint16_t plaintext_pad_len; 11935 uint8_t cipher_key[reference->cipher_key.len + 1]; 11936 uint8_t auth_key[reference->auth_key.len + 1]; 11937 struct rte_cryptodev_info dev_info; 11938 11939 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11940 uint64_t feat_flags = dev_info.feature_flags; 11941 11942 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11943 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11944 printf("Device doesn't support RAW data-path APIs.\n"); 11945 return -ENOTSUP; 11946 } 11947 11948 /* Verify the capabilities */ 11949 struct rte_cryptodev_sym_capability_idx cap_idx; 11950 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11951 cap_idx.algo.auth = reference->auth_algo; 11952 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11953 &cap_idx) == NULL) 11954 return -ENOTSUP; 11955 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11956 cap_idx.algo.cipher = reference->crypto_algo; 11957 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11958 &cap_idx) == NULL) 11959 return -ENOTSUP; 11960 11961 /* Create session */ 11962 memcpy(cipher_key, reference->cipher_key.data, 11963 reference->cipher_key.len); 11964 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 11965 11966 /* Setup Cipher Parameters */ 11967 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11968 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 11969 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 11970 ut_params->cipher_xform.cipher.key.data = cipher_key; 11971 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 11972 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 11973 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 11974 11975 ut_params->cipher_xform.next = &ut_params->auth_xform; 11976 11977 /* Setup Authentication Parameters */ 11978 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11979 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 11980 ut_params->auth_xform.auth.algo = reference->auth_algo; 11981 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 11982 ut_params->auth_xform.auth.key.data = auth_key; 11983 ut_params->auth_xform.auth.digest_length = reference->digest.len; 11984 ut_params->auth_xform.next = NULL; 11985 11986 /* Create Crypto session*/ 11987 ut_params->sess = rte_cryptodev_sym_session_create( 11988 ts_params->session_mpool); 11989 11990 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 11991 ut_params->sess, 11992 &ut_params->cipher_xform, 11993 ts_params->session_priv_mpool); 11994 11995 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11996 11997 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11998 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 11999 "Failed to allocate input buffer in mempool"); 12000 12001 /* clear mbuf payload */ 12002 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12003 rte_pktmbuf_tailroom(ut_params->ibuf)); 12004 12005 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12006 reference->plaintext.len); 12007 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12008 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 12009 12010 /* Create operation */ 12011 retval = create_cipher_auth_operation(ts_params, 12012 ut_params, 12013 reference, 0); 12014 12015 if (retval < 0) 12016 return retval; 12017 12018 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12019 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12020 ut_params->op); 12021 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12022 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12023 ut_params->op, 1, 1, 0, 0); 12024 else 12025 ut_params->op = process_crypto_request( 12026 ts_params->valid_devs[0], ut_params->op); 12027 12028 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 12029 12030 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12031 "crypto op processing failed"); 12032 12033 plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16); 12034 12035 authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 12036 ut_params->op->sym->auth.data.offset); 12037 auth_tag = authciphertext + plaintext_pad_len; 12038 debug_hexdump(stdout, "ciphertext:", authciphertext, 12039 reference->ciphertext.len); 12040 debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len); 12041 12042 /* Validate obuf */ 12043 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12044 authciphertext, 12045 reference->ciphertext.data, 12046 reference->ciphertext.len, 12047 "Ciphertext data not as expected"); 12048 12049 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12050 auth_tag, 12051 reference->digest.data, 12052 reference->digest.len, 12053 "Generated digest not as expected"); 12054 12055 return TEST_SUCCESS; 12056 12057 } 12058 12059 static int 12060 test_authenticated_decrypt_with_esn( 12061 struct crypto_testsuite_params *ts_params, 12062 struct crypto_unittest_params *ut_params, 12063 const struct test_crypto_vector *reference) 12064 { 12065 int retval; 12066 12067 uint8_t *ciphertext; 12068 uint8_t cipher_key[reference->cipher_key.len + 1]; 12069 uint8_t auth_key[reference->auth_key.len + 1]; 12070 struct rte_cryptodev_info dev_info; 12071 12072 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12073 uint64_t feat_flags = dev_info.feature_flags; 12074 12075 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12076 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12077 printf("Device doesn't support RAW data-path APIs.\n"); 12078 return -ENOTSUP; 12079 } 12080 12081 /* Verify the capabilities */ 12082 struct rte_cryptodev_sym_capability_idx cap_idx; 12083 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12084 cap_idx.algo.auth = reference->auth_algo; 12085 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12086 &cap_idx) == NULL) 12087 return -ENOTSUP; 12088 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12089 cap_idx.algo.cipher = reference->crypto_algo; 12090 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12091 &cap_idx) == NULL) 12092 return -ENOTSUP; 12093 12094 /* Create session */ 12095 memcpy(cipher_key, reference->cipher_key.data, 12096 reference->cipher_key.len); 12097 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 12098 12099 /* Setup Authentication Parameters */ 12100 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12101 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 12102 ut_params->auth_xform.auth.algo = reference->auth_algo; 12103 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 12104 ut_params->auth_xform.auth.key.data = auth_key; 12105 ut_params->auth_xform.auth.digest_length = reference->digest.len; 12106 ut_params->auth_xform.next = &ut_params->cipher_xform; 12107 12108 /* Setup Cipher Parameters */ 12109 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12110 ut_params->cipher_xform.next = NULL; 12111 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 12112 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 12113 ut_params->cipher_xform.cipher.key.data = cipher_key; 12114 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 12115 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 12116 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 12117 12118 /* Create Crypto session*/ 12119 ut_params->sess = rte_cryptodev_sym_session_create( 12120 ts_params->session_mpool); 12121 12122 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12123 ut_params->sess, 12124 &ut_params->auth_xform, 12125 ts_params->session_priv_mpool); 12126 12127 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12128 12129 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12130 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12131 "Failed to allocate input buffer in mempool"); 12132 12133 /* clear mbuf payload */ 12134 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12135 rte_pktmbuf_tailroom(ut_params->ibuf)); 12136 12137 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12138 reference->ciphertext.len); 12139 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 12140 memcpy(ciphertext, reference->ciphertext.data, 12141 reference->ciphertext.len); 12142 12143 /* Create operation */ 12144 retval = create_cipher_auth_verify_operation(ts_params, 12145 ut_params, 12146 reference); 12147 12148 if (retval < 0) 12149 return retval; 12150 12151 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12152 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12153 ut_params->op); 12154 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12155 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12156 ut_params->op, 1, 1, 0, 0); 12157 else 12158 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 12159 ut_params->op); 12160 12161 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 12162 TEST_ASSERT_EQUAL(ut_params->op->status, 12163 RTE_CRYPTO_OP_STATUS_SUCCESS, 12164 "crypto op processing passed"); 12165 12166 ut_params->obuf = ut_params->op->sym->m_src; 12167 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 12168 12169 return 0; 12170 } 12171 12172 static int 12173 create_aead_operation_SGL(enum rte_crypto_aead_operation op, 12174 const struct aead_test_data *tdata, 12175 void *digest_mem, uint64_t digest_phys) 12176 { 12177 struct crypto_testsuite_params *ts_params = &testsuite_params; 12178 struct crypto_unittest_params *ut_params = &unittest_params; 12179 12180 const unsigned int auth_tag_len = tdata->auth_tag.len; 12181 const unsigned int iv_len = tdata->iv.len; 12182 unsigned int aad_len = tdata->aad.len; 12183 unsigned int aad_len_pad = 0; 12184 12185 /* Generate Crypto op data structure */ 12186 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12187 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12188 TEST_ASSERT_NOT_NULL(ut_params->op, 12189 "Failed to allocate symmetric crypto operation struct"); 12190 12191 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12192 12193 sym_op->aead.digest.data = digest_mem; 12194 12195 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 12196 "no room to append digest"); 12197 12198 sym_op->aead.digest.phys_addr = digest_phys; 12199 12200 if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) { 12201 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 12202 auth_tag_len); 12203 debug_hexdump(stdout, "digest:", 12204 sym_op->aead.digest.data, 12205 auth_tag_len); 12206 } 12207 12208 /* Append aad data */ 12209 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 12210 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12211 uint8_t *, IV_OFFSET); 12212 12213 /* Copy IV 1 byte after the IV pointer, according to the API */ 12214 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len); 12215 12216 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16); 12217 12218 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 12219 ut_params->ibuf, aad_len); 12220 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 12221 "no room to prepend aad"); 12222 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 12223 ut_params->ibuf); 12224 12225 memset(sym_op->aead.aad.data, 0, aad_len); 12226 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 12227 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 12228 12229 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 12230 debug_hexdump(stdout, "aad:", 12231 sym_op->aead.aad.data, aad_len); 12232 } else { 12233 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12234 uint8_t *, IV_OFFSET); 12235 12236 rte_memcpy(iv_ptr, tdata->iv.data, iv_len); 12237 12238 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16); 12239 12240 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 12241 ut_params->ibuf, aad_len_pad); 12242 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 12243 "no room to prepend aad"); 12244 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 12245 ut_params->ibuf); 12246 12247 memset(sym_op->aead.aad.data, 0, aad_len); 12248 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 12249 12250 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 12251 debug_hexdump(stdout, "aad:", 12252 sym_op->aead.aad.data, aad_len); 12253 } 12254 12255 sym_op->aead.data.length = tdata->plaintext.len; 12256 sym_op->aead.data.offset = aad_len_pad; 12257 12258 return 0; 12259 } 12260 12261 #define SGL_MAX_NO 16 12262 12263 static int 12264 test_authenticated_encryption_SGL(const struct aead_test_data *tdata, 12265 const int oop, uint32_t fragsz, uint32_t fragsz_oop) 12266 { 12267 struct crypto_testsuite_params *ts_params = &testsuite_params; 12268 struct crypto_unittest_params *ut_params = &unittest_params; 12269 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL; 12270 int retval; 12271 int to_trn = 0; 12272 int to_trn_tbl[SGL_MAX_NO]; 12273 int segs = 1; 12274 unsigned int trn_data = 0; 12275 uint8_t *plaintext, *ciphertext, *auth_tag; 12276 struct rte_cryptodev_info dev_info; 12277 12278 /* Verify the capabilities */ 12279 struct rte_cryptodev_sym_capability_idx cap_idx; 12280 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12281 cap_idx.algo.aead = tdata->algo; 12282 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12283 &cap_idx) == NULL) 12284 return -ENOTSUP; 12285 12286 /* OOP not supported with CPU crypto */ 12287 if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12288 return -ENOTSUP; 12289 12290 /* Detailed check for the particular SGL support flag */ 12291 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12292 if (!oop) { 12293 unsigned int sgl_in = fragsz < tdata->plaintext.len; 12294 if (sgl_in && (!(dev_info.feature_flags & 12295 RTE_CRYPTODEV_FF_IN_PLACE_SGL))) 12296 return -ENOTSUP; 12297 12298 uint64_t feat_flags = dev_info.feature_flags; 12299 12300 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12301 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12302 printf("Device doesn't support RAW data-path APIs.\n"); 12303 return -ENOTSUP; 12304 } 12305 } else { 12306 unsigned int sgl_in = fragsz < tdata->plaintext.len; 12307 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) < 12308 tdata->plaintext.len; 12309 /* Raw data path API does not support OOP */ 12310 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12311 return -ENOTSUP; 12312 if (sgl_in && !sgl_out) { 12313 if (!(dev_info.feature_flags & 12314 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) 12315 return -ENOTSUP; 12316 } else if (!sgl_in && sgl_out) { 12317 if (!(dev_info.feature_flags & 12318 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 12319 return -ENOTSUP; 12320 } else if (sgl_in && sgl_out) { 12321 if (!(dev_info.feature_flags & 12322 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 12323 return -ENOTSUP; 12324 } 12325 } 12326 12327 if (fragsz > tdata->plaintext.len) 12328 fragsz = tdata->plaintext.len; 12329 12330 uint16_t plaintext_len = fragsz; 12331 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 12332 12333 if (fragsz_oop > tdata->plaintext.len) 12334 frag_size_oop = tdata->plaintext.len; 12335 12336 int ecx = 0; 12337 void *digest_mem = NULL; 12338 12339 uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 12340 12341 if (tdata->plaintext.len % fragsz != 0) { 12342 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO) 12343 return 1; 12344 } else { 12345 if (tdata->plaintext.len / fragsz > SGL_MAX_NO) 12346 return 1; 12347 } 12348 12349 /* 12350 * For out-op-place we need to alloc another mbuf 12351 */ 12352 if (oop) { 12353 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12354 rte_pktmbuf_append(ut_params->obuf, 12355 frag_size_oop + prepend_len); 12356 buf_oop = ut_params->obuf; 12357 } 12358 12359 /* Create AEAD session */ 12360 retval = create_aead_session(ts_params->valid_devs[0], 12361 tdata->algo, 12362 RTE_CRYPTO_AEAD_OP_ENCRYPT, 12363 tdata->key.data, tdata->key.len, 12364 tdata->aad.len, tdata->auth_tag.len, 12365 tdata->iv.len); 12366 if (retval < 0) 12367 return retval; 12368 12369 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12370 12371 /* clear mbuf payload */ 12372 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12373 rte_pktmbuf_tailroom(ut_params->ibuf)); 12374 12375 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12376 plaintext_len); 12377 12378 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 12379 12380 trn_data += plaintext_len; 12381 12382 buf = ut_params->ibuf; 12383 12384 /* 12385 * Loop until no more fragments 12386 */ 12387 12388 while (trn_data < tdata->plaintext.len) { 12389 ++segs; 12390 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 12391 (tdata->plaintext.len - trn_data) : fragsz; 12392 12393 to_trn_tbl[ecx++] = to_trn; 12394 12395 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12396 buf = buf->next; 12397 12398 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 12399 rte_pktmbuf_tailroom(buf)); 12400 12401 /* OOP */ 12402 if (oop && !fragsz_oop) { 12403 buf_last_oop = buf_oop->next = 12404 rte_pktmbuf_alloc(ts_params->mbuf_pool); 12405 buf_oop = buf_oop->next; 12406 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 12407 0, rte_pktmbuf_tailroom(buf_oop)); 12408 rte_pktmbuf_append(buf_oop, to_trn); 12409 } 12410 12411 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 12412 to_trn); 12413 12414 memcpy(plaintext, tdata->plaintext.data + trn_data, 12415 to_trn); 12416 trn_data += to_trn; 12417 if (trn_data == tdata->plaintext.len) { 12418 if (oop) { 12419 if (!fragsz_oop) 12420 digest_mem = rte_pktmbuf_append(buf_oop, 12421 tdata->auth_tag.len); 12422 } else 12423 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 12424 tdata->auth_tag.len); 12425 } 12426 } 12427 12428 uint64_t digest_phys = 0; 12429 12430 ut_params->ibuf->nb_segs = segs; 12431 12432 segs = 1; 12433 if (fragsz_oop && oop) { 12434 to_trn = 0; 12435 ecx = 0; 12436 12437 if (frag_size_oop == tdata->plaintext.len) { 12438 digest_mem = rte_pktmbuf_append(ut_params->obuf, 12439 tdata->auth_tag.len); 12440 12441 digest_phys = rte_pktmbuf_iova_offset( 12442 ut_params->obuf, 12443 tdata->plaintext.len + prepend_len); 12444 } 12445 12446 trn_data = frag_size_oop; 12447 while (trn_data < tdata->plaintext.len) { 12448 ++segs; 12449 to_trn = 12450 (tdata->plaintext.len - trn_data < 12451 frag_size_oop) ? 12452 (tdata->plaintext.len - trn_data) : 12453 frag_size_oop; 12454 12455 to_trn_tbl[ecx++] = to_trn; 12456 12457 buf_last_oop = buf_oop->next = 12458 rte_pktmbuf_alloc(ts_params->mbuf_pool); 12459 buf_oop = buf_oop->next; 12460 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 12461 0, rte_pktmbuf_tailroom(buf_oop)); 12462 rte_pktmbuf_append(buf_oop, to_trn); 12463 12464 trn_data += to_trn; 12465 12466 if (trn_data == tdata->plaintext.len) { 12467 digest_mem = rte_pktmbuf_append(buf_oop, 12468 tdata->auth_tag.len); 12469 } 12470 } 12471 12472 ut_params->obuf->nb_segs = segs; 12473 } 12474 12475 /* 12476 * Place digest at the end of the last buffer 12477 */ 12478 if (!digest_phys) 12479 digest_phys = rte_pktmbuf_iova(buf) + to_trn; 12480 if (oop && buf_last_oop) 12481 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn; 12482 12483 if (!digest_mem && !oop) { 12484 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12485 + tdata->auth_tag.len); 12486 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 12487 tdata->plaintext.len); 12488 } 12489 12490 /* Create AEAD operation */ 12491 retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT, 12492 tdata, digest_mem, digest_phys); 12493 12494 if (retval < 0) 12495 return retval; 12496 12497 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12498 12499 ut_params->op->sym->m_src = ut_params->ibuf; 12500 if (oop) 12501 ut_params->op->sym->m_dst = ut_params->obuf; 12502 12503 /* Process crypto operation */ 12504 if (oop == IN_PLACE && 12505 gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12506 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 12507 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12508 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12509 ut_params->op, 0, 0, 0, 0); 12510 else 12511 TEST_ASSERT_NOT_NULL( 12512 process_crypto_request(ts_params->valid_devs[0], 12513 ut_params->op), "failed to process sym crypto op"); 12514 12515 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12516 "crypto op processing failed"); 12517 12518 12519 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 12520 uint8_t *, prepend_len); 12521 if (oop) { 12522 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 12523 uint8_t *, prepend_len); 12524 } 12525 12526 if (fragsz_oop) 12527 fragsz = fragsz_oop; 12528 12529 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12530 ciphertext, 12531 tdata->ciphertext.data, 12532 fragsz, 12533 "Ciphertext data not as expected"); 12534 12535 buf = ut_params->op->sym->m_src->next; 12536 if (oop) 12537 buf = ut_params->op->sym->m_dst->next; 12538 12539 unsigned int off = fragsz; 12540 12541 ecx = 0; 12542 while (buf) { 12543 ciphertext = rte_pktmbuf_mtod(buf, 12544 uint8_t *); 12545 12546 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12547 ciphertext, 12548 tdata->ciphertext.data + off, 12549 to_trn_tbl[ecx], 12550 "Ciphertext data not as expected"); 12551 12552 off += to_trn_tbl[ecx++]; 12553 buf = buf->next; 12554 } 12555 12556 auth_tag = digest_mem; 12557 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12558 auth_tag, 12559 tdata->auth_tag.data, 12560 tdata->auth_tag.len, 12561 "Generated auth tag not as expected"); 12562 12563 return 0; 12564 } 12565 12566 static int 12567 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) 12568 { 12569 return test_authenticated_encryption_SGL( 12570 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400); 12571 } 12572 12573 static int 12574 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void) 12575 { 12576 return test_authenticated_encryption_SGL( 12577 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000); 12578 } 12579 12580 static int 12581 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void) 12582 { 12583 return test_authenticated_encryption_SGL( 12584 &gcm_test_case_8, OUT_OF_PLACE, 400, 12585 gcm_test_case_8.plaintext.len); 12586 } 12587 12588 static int 12589 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void) 12590 { 12591 /* This test is not for OPENSSL PMD */ 12592 if (gbl_driver_id == rte_cryptodev_driver_id_get( 12593 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) 12594 return -ENOTSUP; 12595 12596 return test_authenticated_encryption_SGL( 12597 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0); 12598 } 12599 12600 static int 12601 test_authentication_verify_fail_when_data_corrupted( 12602 struct crypto_testsuite_params *ts_params, 12603 struct crypto_unittest_params *ut_params, 12604 const struct test_crypto_vector *reference) 12605 { 12606 return test_authentication_verify_fail_when_data_corruption( 12607 ts_params, ut_params, reference, 1); 12608 } 12609 12610 static int 12611 test_authentication_verify_fail_when_tag_corrupted( 12612 struct crypto_testsuite_params *ts_params, 12613 struct crypto_unittest_params *ut_params, 12614 const struct test_crypto_vector *reference) 12615 { 12616 return test_authentication_verify_fail_when_data_corruption( 12617 ts_params, ut_params, reference, 0); 12618 } 12619 12620 static int 12621 test_authentication_verify_GMAC_fail_when_data_corrupted( 12622 struct crypto_testsuite_params *ts_params, 12623 struct crypto_unittest_params *ut_params, 12624 const struct test_crypto_vector *reference) 12625 { 12626 return test_authentication_verify_GMAC_fail_when_corruption( 12627 ts_params, ut_params, reference, 1); 12628 } 12629 12630 static int 12631 test_authentication_verify_GMAC_fail_when_tag_corrupted( 12632 struct crypto_testsuite_params *ts_params, 12633 struct crypto_unittest_params *ut_params, 12634 const struct test_crypto_vector *reference) 12635 { 12636 return test_authentication_verify_GMAC_fail_when_corruption( 12637 ts_params, ut_params, reference, 0); 12638 } 12639 12640 static int 12641 test_authenticated_decryption_fail_when_data_corrupted( 12642 struct crypto_testsuite_params *ts_params, 12643 struct crypto_unittest_params *ut_params, 12644 const struct test_crypto_vector *reference) 12645 { 12646 return test_authenticated_decryption_fail_when_corruption( 12647 ts_params, ut_params, reference, 1); 12648 } 12649 12650 static int 12651 test_authenticated_decryption_fail_when_tag_corrupted( 12652 struct crypto_testsuite_params *ts_params, 12653 struct crypto_unittest_params *ut_params, 12654 const struct test_crypto_vector *reference) 12655 { 12656 return test_authenticated_decryption_fail_when_corruption( 12657 ts_params, ut_params, reference, 0); 12658 } 12659 12660 static int 12661 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 12662 { 12663 return test_authentication_verify_fail_when_data_corrupted( 12664 &testsuite_params, &unittest_params, 12665 &hmac_sha1_test_crypto_vector); 12666 } 12667 12668 static int 12669 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 12670 { 12671 return test_authentication_verify_fail_when_tag_corrupted( 12672 &testsuite_params, &unittest_params, 12673 &hmac_sha1_test_crypto_vector); 12674 } 12675 12676 static int 12677 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 12678 { 12679 return test_authentication_verify_GMAC_fail_when_data_corrupted( 12680 &testsuite_params, &unittest_params, 12681 &aes128_gmac_test_vector); 12682 } 12683 12684 static int 12685 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 12686 { 12687 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 12688 &testsuite_params, &unittest_params, 12689 &aes128_gmac_test_vector); 12690 } 12691 12692 static int 12693 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 12694 { 12695 return test_authenticated_decryption_fail_when_data_corrupted( 12696 &testsuite_params, 12697 &unittest_params, 12698 &aes128cbc_hmac_sha1_test_vector); 12699 } 12700 12701 static int 12702 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 12703 { 12704 return test_authenticated_decryption_fail_when_tag_corrupted( 12705 &testsuite_params, 12706 &unittest_params, 12707 &aes128cbc_hmac_sha1_test_vector); 12708 } 12709 12710 static int 12711 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void) 12712 { 12713 return test_authenticated_encryt_with_esn( 12714 &testsuite_params, 12715 &unittest_params, 12716 &aes128cbc_hmac_sha1_aad_test_vector); 12717 } 12718 12719 static int 12720 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void) 12721 { 12722 return test_authenticated_decrypt_with_esn( 12723 &testsuite_params, 12724 &unittest_params, 12725 &aes128cbc_hmac_sha1_aad_test_vector); 12726 } 12727 12728 static int 12729 test_chacha20_poly1305_encrypt_test_case_rfc8439(void) 12730 { 12731 return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439); 12732 } 12733 12734 static int 12735 test_chacha20_poly1305_decrypt_test_case_rfc8439(void) 12736 { 12737 return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439); 12738 } 12739 12740 #ifdef RTE_CRYPTO_SCHEDULER 12741 12742 /* global AESNI worker IDs for the scheduler test */ 12743 uint8_t aesni_ids[2]; 12744 12745 static int 12746 test_scheduler_attach_slave_op(void) 12747 { 12748 struct crypto_testsuite_params *ts_params = &testsuite_params; 12749 uint8_t sched_id = ts_params->valid_devs[0]; 12750 uint32_t nb_devs, i, nb_devs_attached = 0; 12751 int ret; 12752 char vdev_name[32]; 12753 12754 /* create 2 AESNI_MB if necessary */ 12755 nb_devs = rte_cryptodev_device_count_by_driver( 12756 rte_cryptodev_driver_id_get( 12757 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))); 12758 if (nb_devs < 2) { 12759 for (i = nb_devs; i < 2; i++) { 12760 snprintf(vdev_name, sizeof(vdev_name), "%s_%u", 12761 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), 12762 i); 12763 ret = rte_vdev_init(vdev_name, NULL); 12764 12765 TEST_ASSERT(ret == 0, 12766 "Failed to create instance %u of" 12767 " pmd : %s", 12768 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 12769 } 12770 } 12771 12772 /* attach 2 AESNI_MB cdevs */ 12773 for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2; 12774 i++) { 12775 struct rte_cryptodev_info info; 12776 unsigned int session_size; 12777 12778 rte_cryptodev_info_get(i, &info); 12779 if (info.driver_id != rte_cryptodev_driver_id_get( 12780 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) 12781 continue; 12782 12783 session_size = rte_cryptodev_sym_get_private_session_size(i); 12784 /* 12785 * Create the session mempool again, since now there are new devices 12786 * to use the mempool. 12787 */ 12788 if (ts_params->session_mpool) { 12789 rte_mempool_free(ts_params->session_mpool); 12790 ts_params->session_mpool = NULL; 12791 } 12792 if (ts_params->session_priv_mpool) { 12793 rte_mempool_free(ts_params->session_priv_mpool); 12794 ts_params->session_priv_mpool = NULL; 12795 } 12796 12797 if (info.sym.max_nb_sessions != 0 && 12798 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 12799 RTE_LOG(ERR, USER1, 12800 "Device does not support " 12801 "at least %u sessions\n", 12802 MAX_NB_SESSIONS); 12803 return TEST_FAILED; 12804 } 12805 /* 12806 * Create mempool with maximum number of sessions, 12807 * to include the session headers 12808 */ 12809 if (ts_params->session_mpool == NULL) { 12810 ts_params->session_mpool = 12811 rte_cryptodev_sym_session_pool_create( 12812 "test_sess_mp", 12813 MAX_NB_SESSIONS, 0, 0, 0, 12814 SOCKET_ID_ANY); 12815 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 12816 "session mempool allocation failed"); 12817 } 12818 12819 /* 12820 * Create mempool with maximum number of sessions, 12821 * to include device specific session private data 12822 */ 12823 if (ts_params->session_priv_mpool == NULL) { 12824 ts_params->session_priv_mpool = rte_mempool_create( 12825 "test_sess_mp_priv", 12826 MAX_NB_SESSIONS, 12827 session_size, 12828 0, 0, NULL, NULL, NULL, 12829 NULL, SOCKET_ID_ANY, 12830 0); 12831 12832 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 12833 "session mempool allocation failed"); 12834 } 12835 12836 ts_params->qp_conf.mp_session = ts_params->session_mpool; 12837 ts_params->qp_conf.mp_session_private = 12838 ts_params->session_priv_mpool; 12839 12840 ret = rte_cryptodev_scheduler_worker_attach(sched_id, 12841 (uint8_t)i); 12842 12843 TEST_ASSERT(ret == 0, 12844 "Failed to attach device %u of pmd : %s", i, 12845 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 12846 12847 aesni_ids[nb_devs_attached] = (uint8_t)i; 12848 12849 nb_devs_attached++; 12850 } 12851 12852 return 0; 12853 } 12854 12855 static int 12856 test_scheduler_detach_slave_op(void) 12857 { 12858 struct crypto_testsuite_params *ts_params = &testsuite_params; 12859 uint8_t sched_id = ts_params->valid_devs[0]; 12860 uint32_t i; 12861 int ret; 12862 12863 for (i = 0; i < 2; i++) { 12864 ret = rte_cryptodev_scheduler_worker_detach(sched_id, 12865 aesni_ids[i]); 12866 TEST_ASSERT(ret == 0, 12867 "Failed to detach device %u", aesni_ids[i]); 12868 } 12869 12870 return 0; 12871 } 12872 12873 static int 12874 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode) 12875 { 12876 struct crypto_testsuite_params *ts_params = &testsuite_params; 12877 uint8_t sched_id = ts_params->valid_devs[0]; 12878 /* set mode */ 12879 return rte_cryptodev_scheduler_mode_set(sched_id, 12880 scheduler_mode); 12881 } 12882 12883 static int 12884 test_scheduler_mode_roundrobin_op(void) 12885 { 12886 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) == 12887 0, "Failed to set roundrobin mode"); 12888 return 0; 12889 12890 } 12891 12892 static int 12893 test_scheduler_mode_multicore_op(void) 12894 { 12895 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) == 12896 0, "Failed to set multicore mode"); 12897 12898 return 0; 12899 } 12900 12901 static int 12902 test_scheduler_mode_failover_op(void) 12903 { 12904 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) == 12905 0, "Failed to set failover mode"); 12906 12907 return 0; 12908 } 12909 12910 static int 12911 test_scheduler_mode_pkt_size_distr_op(void) 12912 { 12913 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) == 12914 0, "Failed to set pktsize mode"); 12915 12916 return 0; 12917 } 12918 12919 static struct unit_test_suite cryptodev_scheduler_testsuite = { 12920 .suite_name = "Crypto Device Scheduler Unit Test Suite", 12921 .setup = testsuite_setup, 12922 .teardown = testsuite_teardown, 12923 .unit_test_cases = { 12924 /* Multi Core */ 12925 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 12926 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_multicore_op), 12927 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 12928 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 12929 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 12930 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 12931 12932 /* Round Robin */ 12933 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 12934 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_roundrobin_op), 12935 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 12936 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 12937 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 12938 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 12939 12940 /* Fail over */ 12941 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 12942 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_failover_op), 12943 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 12944 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 12945 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 12946 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 12947 12948 /* PKT SIZE */ 12949 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 12950 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_pkt_size_distr_op), 12951 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 12952 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 12953 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 12954 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 12955 12956 TEST_CASES_END() /**< NULL terminate unit test array */ 12957 } 12958 }; 12959 12960 #endif /* RTE_CRYPTO_SCHEDULER */ 12961 12962 static struct unit_test_suite cryptodev_testsuite = { 12963 .suite_name = "Crypto Unit Test Suite", 12964 .setup = testsuite_setup, 12965 .teardown = testsuite_teardown, 12966 .unit_test_cases = { 12967 TEST_CASE_ST(ut_setup, ut_teardown, 12968 test_device_configure_invalid_dev_id), 12969 TEST_CASE_ST(ut_setup, ut_teardown, 12970 test_queue_pair_descriptor_setup), 12971 TEST_CASE_ST(ut_setup, ut_teardown, 12972 test_device_configure_invalid_queue_pair_ids), 12973 12974 TEST_CASE_ST(ut_setup, ut_teardown, 12975 test_multi_session), 12976 TEST_CASE_ST(ut_setup, ut_teardown, 12977 test_multi_session_random_usage), 12978 12979 TEST_CASE_ST(ut_setup, ut_teardown, 12980 test_null_invalid_operation), 12981 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation), 12982 12983 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 12984 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 12985 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 12986 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 12987 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_cipheronly_all), 12988 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_all), 12989 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_docsis_all), 12990 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 12991 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 12992 12993 /** AES CCM Authenticated Encryption 128 bits key */ 12994 TEST_CASE_ST(ut_setup, ut_teardown, 12995 test_AES_CCM_authenticated_encryption_test_case_128_1), 12996 TEST_CASE_ST(ut_setup, ut_teardown, 12997 test_AES_CCM_authenticated_encryption_test_case_128_2), 12998 TEST_CASE_ST(ut_setup, ut_teardown, 12999 test_AES_CCM_authenticated_encryption_test_case_128_3), 13000 13001 /** AES CCM Authenticated Decryption 128 bits key*/ 13002 TEST_CASE_ST(ut_setup, ut_teardown, 13003 test_AES_CCM_authenticated_decryption_test_case_128_1), 13004 TEST_CASE_ST(ut_setup, ut_teardown, 13005 test_AES_CCM_authenticated_decryption_test_case_128_2), 13006 TEST_CASE_ST(ut_setup, ut_teardown, 13007 test_AES_CCM_authenticated_decryption_test_case_128_3), 13008 13009 /** AES CCM Authenticated Encryption 192 bits key */ 13010 TEST_CASE_ST(ut_setup, ut_teardown, 13011 test_AES_CCM_authenticated_encryption_test_case_192_1), 13012 TEST_CASE_ST(ut_setup, ut_teardown, 13013 test_AES_CCM_authenticated_encryption_test_case_192_2), 13014 TEST_CASE_ST(ut_setup, ut_teardown, 13015 test_AES_CCM_authenticated_encryption_test_case_192_3), 13016 13017 /** AES CCM Authenticated Decryption 192 bits key*/ 13018 TEST_CASE_ST(ut_setup, ut_teardown, 13019 test_AES_CCM_authenticated_decryption_test_case_192_1), 13020 TEST_CASE_ST(ut_setup, ut_teardown, 13021 test_AES_CCM_authenticated_decryption_test_case_192_2), 13022 TEST_CASE_ST(ut_setup, ut_teardown, 13023 test_AES_CCM_authenticated_decryption_test_case_192_3), 13024 13025 /** AES CCM Authenticated Encryption 256 bits key */ 13026 TEST_CASE_ST(ut_setup, ut_teardown, 13027 test_AES_CCM_authenticated_encryption_test_case_256_1), 13028 TEST_CASE_ST(ut_setup, ut_teardown, 13029 test_AES_CCM_authenticated_encryption_test_case_256_2), 13030 TEST_CASE_ST(ut_setup, ut_teardown, 13031 test_AES_CCM_authenticated_encryption_test_case_256_3), 13032 13033 /** AES CCM Authenticated Decryption 256 bits key*/ 13034 TEST_CASE_ST(ut_setup, ut_teardown, 13035 test_AES_CCM_authenticated_decryption_test_case_256_1), 13036 TEST_CASE_ST(ut_setup, ut_teardown, 13037 test_AES_CCM_authenticated_decryption_test_case_256_2), 13038 TEST_CASE_ST(ut_setup, ut_teardown, 13039 test_AES_CCM_authenticated_decryption_test_case_256_3), 13040 13041 /** AES GCM Authenticated Encryption */ 13042 TEST_CASE_ST(ut_setup, ut_teardown, 13043 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 13044 TEST_CASE_ST(ut_setup, ut_teardown, 13045 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 13046 TEST_CASE_ST(ut_setup, ut_teardown, 13047 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 13048 TEST_CASE_ST(ut_setup, ut_teardown, 13049 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 13050 TEST_CASE_ST(ut_setup, ut_teardown, 13051 test_AES_GCM_authenticated_encryption_test_case_1), 13052 TEST_CASE_ST(ut_setup, ut_teardown, 13053 test_AES_GCM_authenticated_encryption_test_case_2), 13054 TEST_CASE_ST(ut_setup, ut_teardown, 13055 test_AES_GCM_authenticated_encryption_test_case_3), 13056 TEST_CASE_ST(ut_setup, ut_teardown, 13057 test_AES_GCM_authenticated_encryption_test_case_4), 13058 TEST_CASE_ST(ut_setup, ut_teardown, 13059 test_AES_GCM_authenticated_encryption_test_case_5), 13060 TEST_CASE_ST(ut_setup, ut_teardown, 13061 test_AES_GCM_authenticated_encryption_test_case_6), 13062 TEST_CASE_ST(ut_setup, ut_teardown, 13063 test_AES_GCM_authenticated_encryption_test_case_7), 13064 TEST_CASE_ST(ut_setup, ut_teardown, 13065 test_AES_GCM_authenticated_encryption_test_case_8), 13066 TEST_CASE_ST(ut_setup, ut_teardown, 13067 test_AES_GCM_J0_authenticated_encryption_test_case_1), 13068 13069 /** AES GCM Authenticated Decryption */ 13070 TEST_CASE_ST(ut_setup, ut_teardown, 13071 test_AES_GCM_authenticated_decryption_test_case_1), 13072 TEST_CASE_ST(ut_setup, ut_teardown, 13073 test_AES_GCM_authenticated_decryption_test_case_2), 13074 TEST_CASE_ST(ut_setup, ut_teardown, 13075 test_AES_GCM_authenticated_decryption_test_case_3), 13076 TEST_CASE_ST(ut_setup, ut_teardown, 13077 test_AES_GCM_authenticated_decryption_test_case_4), 13078 TEST_CASE_ST(ut_setup, ut_teardown, 13079 test_AES_GCM_authenticated_decryption_test_case_5), 13080 TEST_CASE_ST(ut_setup, ut_teardown, 13081 test_AES_GCM_authenticated_decryption_test_case_6), 13082 TEST_CASE_ST(ut_setup, ut_teardown, 13083 test_AES_GCM_authenticated_decryption_test_case_7), 13084 TEST_CASE_ST(ut_setup, ut_teardown, 13085 test_AES_GCM_authenticated_decryption_test_case_8), 13086 TEST_CASE_ST(ut_setup, ut_teardown, 13087 test_AES_GCM_J0_authenticated_decryption_test_case_1), 13088 13089 /** AES GCM Authenticated Encryption 192 bits key */ 13090 TEST_CASE_ST(ut_setup, ut_teardown, 13091 test_AES_GCM_auth_encryption_test_case_192_1), 13092 TEST_CASE_ST(ut_setup, ut_teardown, 13093 test_AES_GCM_auth_encryption_test_case_192_2), 13094 TEST_CASE_ST(ut_setup, ut_teardown, 13095 test_AES_GCM_auth_encryption_test_case_192_3), 13096 TEST_CASE_ST(ut_setup, ut_teardown, 13097 test_AES_GCM_auth_encryption_test_case_192_4), 13098 TEST_CASE_ST(ut_setup, ut_teardown, 13099 test_AES_GCM_auth_encryption_test_case_192_5), 13100 TEST_CASE_ST(ut_setup, ut_teardown, 13101 test_AES_GCM_auth_encryption_test_case_192_6), 13102 TEST_CASE_ST(ut_setup, ut_teardown, 13103 test_AES_GCM_auth_encryption_test_case_192_7), 13104 13105 /** AES GCM Authenticated Decryption 192 bits key */ 13106 TEST_CASE_ST(ut_setup, ut_teardown, 13107 test_AES_GCM_auth_decryption_test_case_192_1), 13108 TEST_CASE_ST(ut_setup, ut_teardown, 13109 test_AES_GCM_auth_decryption_test_case_192_2), 13110 TEST_CASE_ST(ut_setup, ut_teardown, 13111 test_AES_GCM_auth_decryption_test_case_192_3), 13112 TEST_CASE_ST(ut_setup, ut_teardown, 13113 test_AES_GCM_auth_decryption_test_case_192_4), 13114 TEST_CASE_ST(ut_setup, ut_teardown, 13115 test_AES_GCM_auth_decryption_test_case_192_5), 13116 TEST_CASE_ST(ut_setup, ut_teardown, 13117 test_AES_GCM_auth_decryption_test_case_192_6), 13118 TEST_CASE_ST(ut_setup, ut_teardown, 13119 test_AES_GCM_auth_decryption_test_case_192_7), 13120 13121 /** AES GCM Authenticated Encryption 256 bits key */ 13122 TEST_CASE_ST(ut_setup, ut_teardown, 13123 test_AES_GCM_auth_encryption_test_case_256_1), 13124 TEST_CASE_ST(ut_setup, ut_teardown, 13125 test_AES_GCM_auth_encryption_test_case_256_2), 13126 TEST_CASE_ST(ut_setup, ut_teardown, 13127 test_AES_GCM_auth_encryption_test_case_256_3), 13128 TEST_CASE_ST(ut_setup, ut_teardown, 13129 test_AES_GCM_auth_encryption_test_case_256_4), 13130 TEST_CASE_ST(ut_setup, ut_teardown, 13131 test_AES_GCM_auth_encryption_test_case_256_5), 13132 TEST_CASE_ST(ut_setup, ut_teardown, 13133 test_AES_GCM_auth_encryption_test_case_256_6), 13134 TEST_CASE_ST(ut_setup, ut_teardown, 13135 test_AES_GCM_auth_encryption_test_case_256_7), 13136 13137 /** AES GCM Authenticated Decryption 256 bits key */ 13138 TEST_CASE_ST(ut_setup, ut_teardown, 13139 test_AES_GCM_auth_decryption_test_case_256_1), 13140 TEST_CASE_ST(ut_setup, ut_teardown, 13141 test_AES_GCM_auth_decryption_test_case_256_2), 13142 TEST_CASE_ST(ut_setup, ut_teardown, 13143 test_AES_GCM_auth_decryption_test_case_256_3), 13144 TEST_CASE_ST(ut_setup, ut_teardown, 13145 test_AES_GCM_auth_decryption_test_case_256_4), 13146 TEST_CASE_ST(ut_setup, ut_teardown, 13147 test_AES_GCM_auth_decryption_test_case_256_5), 13148 TEST_CASE_ST(ut_setup, ut_teardown, 13149 test_AES_GCM_auth_decryption_test_case_256_6), 13150 TEST_CASE_ST(ut_setup, ut_teardown, 13151 test_AES_GCM_auth_decryption_test_case_256_7), 13152 13153 /** AES GCM Authenticated Encryption big aad size */ 13154 TEST_CASE_ST(ut_setup, ut_teardown, 13155 test_AES_GCM_auth_encryption_test_case_aad_1), 13156 TEST_CASE_ST(ut_setup, ut_teardown, 13157 test_AES_GCM_auth_encryption_test_case_aad_2), 13158 13159 /** AES GCM Authenticated Decryption big aad size */ 13160 TEST_CASE_ST(ut_setup, ut_teardown, 13161 test_AES_GCM_auth_decryption_test_case_aad_1), 13162 TEST_CASE_ST(ut_setup, ut_teardown, 13163 test_AES_GCM_auth_decryption_test_case_aad_2), 13164 13165 /** Out of place tests */ 13166 TEST_CASE_ST(ut_setup, ut_teardown, 13167 test_AES_GCM_authenticated_encryption_oop_test_case_1), 13168 TEST_CASE_ST(ut_setup, ut_teardown, 13169 test_AES_GCM_authenticated_decryption_oop_test_case_1), 13170 13171 /** Session-less tests */ 13172 TEST_CASE_ST(ut_setup, ut_teardown, 13173 test_AES_GCM_authenticated_encryption_sessionless_test_case_1), 13174 TEST_CASE_ST(ut_setup, ut_teardown, 13175 test_AES_GCM_authenticated_decryption_sessionless_test_case_1), 13176 13177 /** AES GMAC Authentication */ 13178 TEST_CASE_ST(ut_setup, ut_teardown, 13179 test_AES_GMAC_authentication_test_case_1), 13180 TEST_CASE_ST(ut_setup, ut_teardown, 13181 test_AES_GMAC_authentication_verify_test_case_1), 13182 TEST_CASE_ST(ut_setup, ut_teardown, 13183 test_AES_GMAC_authentication_test_case_2), 13184 TEST_CASE_ST(ut_setup, ut_teardown, 13185 test_AES_GMAC_authentication_verify_test_case_2), 13186 TEST_CASE_ST(ut_setup, ut_teardown, 13187 test_AES_GMAC_authentication_test_case_3), 13188 TEST_CASE_ST(ut_setup, ut_teardown, 13189 test_AES_GMAC_authentication_verify_test_case_3), 13190 TEST_CASE_ST(ut_setup, ut_teardown, 13191 test_AES_GMAC_authentication_test_case_4), 13192 TEST_CASE_ST(ut_setup, ut_teardown, 13193 test_AES_GMAC_authentication_verify_test_case_4), 13194 TEST_CASE_ST(ut_setup, ut_teardown, 13195 test_AES_GMAC_authentication_SGL_40B), 13196 TEST_CASE_ST(ut_setup, ut_teardown, 13197 test_AES_GMAC_authentication_SGL_80B), 13198 TEST_CASE_ST(ut_setup, ut_teardown, 13199 test_AES_GMAC_authentication_SGL_2048B), 13200 TEST_CASE_ST(ut_setup, ut_teardown, 13201 test_AES_GMAC_authentication_SGL_2047B), 13202 13203 /** Chacha20-Poly1305 */ 13204 TEST_CASE_ST(ut_setup, ut_teardown, 13205 test_chacha20_poly1305_encrypt_test_case_rfc8439), 13206 TEST_CASE_ST(ut_setup, ut_teardown, 13207 test_chacha20_poly1305_decrypt_test_case_rfc8439), 13208 /** SNOW 3G encrypt only (UEA2) */ 13209 TEST_CASE_ST(ut_setup, ut_teardown, 13210 test_snow3g_encryption_test_case_1), 13211 TEST_CASE_ST(ut_setup, ut_teardown, 13212 test_snow3g_encryption_test_case_2), 13213 TEST_CASE_ST(ut_setup, ut_teardown, 13214 test_snow3g_encryption_test_case_3), 13215 TEST_CASE_ST(ut_setup, ut_teardown, 13216 test_snow3g_encryption_test_case_4), 13217 TEST_CASE_ST(ut_setup, ut_teardown, 13218 test_snow3g_encryption_test_case_5), 13219 13220 TEST_CASE_ST(ut_setup, ut_teardown, 13221 test_snow3g_encryption_test_case_1_oop), 13222 TEST_CASE_ST(ut_setup, ut_teardown, 13223 test_snow3g_encryption_test_case_1_oop_sgl), 13224 TEST_CASE_ST(ut_setup, ut_teardown, 13225 test_snow3g_encryption_test_case_1_offset_oop), 13226 TEST_CASE_ST(ut_setup, ut_teardown, 13227 test_snow3g_decryption_test_case_1_oop), 13228 13229 /** SNOW 3G generate auth, then encrypt (UEA2) */ 13230 TEST_CASE_ST(ut_setup, ut_teardown, 13231 test_snow3g_auth_cipher_test_case_1), 13232 TEST_CASE_ST(ut_setup, ut_teardown, 13233 test_snow3g_auth_cipher_test_case_2), 13234 TEST_CASE_ST(ut_setup, ut_teardown, 13235 test_snow3g_auth_cipher_test_case_2_oop), 13236 TEST_CASE_ST(ut_setup, ut_teardown, 13237 test_snow3g_auth_cipher_part_digest_enc), 13238 TEST_CASE_ST(ut_setup, ut_teardown, 13239 test_snow3g_auth_cipher_part_digest_enc_oop), 13240 TEST_CASE_ST(ut_setup, ut_teardown, 13241 test_snow3g_auth_cipher_test_case_3_sgl), 13242 TEST_CASE_ST(ut_setup, ut_teardown, 13243 test_snow3g_auth_cipher_test_case_3_oop_sgl), 13244 TEST_CASE_ST(ut_setup, ut_teardown, 13245 test_snow3g_auth_cipher_part_digest_enc_sgl), 13246 TEST_CASE_ST(ut_setup, ut_teardown, 13247 test_snow3g_auth_cipher_part_digest_enc_oop_sgl), 13248 13249 /** SNOW 3G decrypt (UEA2), then verify auth */ 13250 TEST_CASE_ST(ut_setup, ut_teardown, 13251 test_snow3g_auth_cipher_verify_test_case_1), 13252 TEST_CASE_ST(ut_setup, ut_teardown, 13253 test_snow3g_auth_cipher_verify_test_case_2), 13254 TEST_CASE_ST(ut_setup, ut_teardown, 13255 test_snow3g_auth_cipher_verify_test_case_2_oop), 13256 TEST_CASE_ST(ut_setup, ut_teardown, 13257 test_snow3g_auth_cipher_verify_part_digest_enc), 13258 TEST_CASE_ST(ut_setup, ut_teardown, 13259 test_snow3g_auth_cipher_verify_part_digest_enc_oop), 13260 TEST_CASE_ST(ut_setup, ut_teardown, 13261 test_snow3g_auth_cipher_verify_test_case_3_sgl), 13262 TEST_CASE_ST(ut_setup, ut_teardown, 13263 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl), 13264 TEST_CASE_ST(ut_setup, ut_teardown, 13265 test_snow3g_auth_cipher_verify_part_digest_enc_sgl), 13266 TEST_CASE_ST(ut_setup, ut_teardown, 13267 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl), 13268 13269 /** SNOW 3G decrypt only (UEA2) */ 13270 TEST_CASE_ST(ut_setup, ut_teardown, 13271 test_snow3g_decryption_test_case_1), 13272 TEST_CASE_ST(ut_setup, ut_teardown, 13273 test_snow3g_decryption_test_case_2), 13274 TEST_CASE_ST(ut_setup, ut_teardown, 13275 test_snow3g_decryption_test_case_3), 13276 TEST_CASE_ST(ut_setup, ut_teardown, 13277 test_snow3g_decryption_test_case_4), 13278 TEST_CASE_ST(ut_setup, ut_teardown, 13279 test_snow3g_decryption_test_case_5), 13280 TEST_CASE_ST(ut_setup, ut_teardown, 13281 test_snow3g_decryption_with_digest_test_case_1), 13282 TEST_CASE_ST(ut_setup, ut_teardown, 13283 test_snow3g_hash_generate_test_case_1), 13284 TEST_CASE_ST(ut_setup, ut_teardown, 13285 test_snow3g_hash_generate_test_case_2), 13286 TEST_CASE_ST(ut_setup, ut_teardown, 13287 test_snow3g_hash_generate_test_case_3), 13288 /* Tests with buffers which length is not byte-aligned */ 13289 TEST_CASE_ST(ut_setup, ut_teardown, 13290 test_snow3g_hash_generate_test_case_4), 13291 TEST_CASE_ST(ut_setup, ut_teardown, 13292 test_snow3g_hash_generate_test_case_5), 13293 TEST_CASE_ST(ut_setup, ut_teardown, 13294 test_snow3g_hash_generate_test_case_6), 13295 TEST_CASE_ST(ut_setup, ut_teardown, 13296 test_snow3g_hash_verify_test_case_1), 13297 TEST_CASE_ST(ut_setup, ut_teardown, 13298 test_snow3g_hash_verify_test_case_2), 13299 TEST_CASE_ST(ut_setup, ut_teardown, 13300 test_snow3g_hash_verify_test_case_3), 13301 /* Tests with buffers which length is not byte-aligned */ 13302 TEST_CASE_ST(ut_setup, ut_teardown, 13303 test_snow3g_hash_verify_test_case_4), 13304 TEST_CASE_ST(ut_setup, ut_teardown, 13305 test_snow3g_hash_verify_test_case_5), 13306 TEST_CASE_ST(ut_setup, ut_teardown, 13307 test_snow3g_hash_verify_test_case_6), 13308 TEST_CASE_ST(ut_setup, ut_teardown, 13309 test_snow3g_cipher_auth_test_case_1), 13310 TEST_CASE_ST(ut_setup, ut_teardown, 13311 test_snow3g_auth_cipher_with_digest_test_case_1), 13312 13313 /** ZUC encrypt only (EEA3) */ 13314 TEST_CASE_ST(ut_setup, ut_teardown, 13315 test_zuc_encryption_test_case_1), 13316 TEST_CASE_ST(ut_setup, ut_teardown, 13317 test_zuc_encryption_test_case_2), 13318 TEST_CASE_ST(ut_setup, ut_teardown, 13319 test_zuc_encryption_test_case_3), 13320 TEST_CASE_ST(ut_setup, ut_teardown, 13321 test_zuc_encryption_test_case_4), 13322 TEST_CASE_ST(ut_setup, ut_teardown, 13323 test_zuc_encryption_test_case_5), 13324 TEST_CASE_ST(ut_setup, ut_teardown, 13325 test_zuc_encryption_test_case_6_sgl), 13326 13327 /** ZUC authenticate (EIA3) */ 13328 TEST_CASE_ST(ut_setup, ut_teardown, 13329 test_zuc_hash_generate_test_case_1), 13330 TEST_CASE_ST(ut_setup, ut_teardown, 13331 test_zuc_hash_generate_test_case_2), 13332 TEST_CASE_ST(ut_setup, ut_teardown, 13333 test_zuc_hash_generate_test_case_3), 13334 TEST_CASE_ST(ut_setup, ut_teardown, 13335 test_zuc_hash_generate_test_case_4), 13336 TEST_CASE_ST(ut_setup, ut_teardown, 13337 test_zuc_hash_generate_test_case_5), 13338 TEST_CASE_ST(ut_setup, ut_teardown, 13339 test_zuc_hash_generate_test_case_6), 13340 TEST_CASE_ST(ut_setup, ut_teardown, 13341 test_zuc_hash_generate_test_case_7), 13342 TEST_CASE_ST(ut_setup, ut_teardown, 13343 test_zuc_hash_generate_test_case_8), 13344 13345 /** ZUC alg-chain (EEA3/EIA3) */ 13346 TEST_CASE_ST(ut_setup, ut_teardown, 13347 test_zuc_cipher_auth_test_case_1), 13348 TEST_CASE_ST(ut_setup, ut_teardown, 13349 test_zuc_cipher_auth_test_case_2), 13350 13351 /** ZUC generate auth, then encrypt (EEA3) */ 13352 TEST_CASE_ST(ut_setup, ut_teardown, 13353 test_zuc_auth_cipher_test_case_1), 13354 TEST_CASE_ST(ut_setup, ut_teardown, 13355 test_zuc_auth_cipher_test_case_1_oop), 13356 TEST_CASE_ST(ut_setup, ut_teardown, 13357 test_zuc_auth_cipher_test_case_1_sgl), 13358 TEST_CASE_ST(ut_setup, ut_teardown, 13359 test_zuc_auth_cipher_test_case_1_oop_sgl), 13360 13361 /** ZUC decrypt (EEA3), then verify auth */ 13362 TEST_CASE_ST(ut_setup, ut_teardown, 13363 test_zuc_auth_cipher_verify_test_case_1), 13364 TEST_CASE_ST(ut_setup, ut_teardown, 13365 test_zuc_auth_cipher_verify_test_case_1_oop), 13366 TEST_CASE_ST(ut_setup, ut_teardown, 13367 test_zuc_auth_cipher_verify_test_case_1_sgl), 13368 TEST_CASE_ST(ut_setup, ut_teardown, 13369 test_zuc_auth_cipher_verify_test_case_1_oop_sgl), 13370 13371 /** HMAC_MD5 Authentication */ 13372 TEST_CASE_ST(ut_setup, ut_teardown, 13373 test_MD5_HMAC_generate_case_1), 13374 TEST_CASE_ST(ut_setup, ut_teardown, 13375 test_MD5_HMAC_verify_case_1), 13376 TEST_CASE_ST(ut_setup, ut_teardown, 13377 test_MD5_HMAC_generate_case_2), 13378 TEST_CASE_ST(ut_setup, ut_teardown, 13379 test_MD5_HMAC_verify_case_2), 13380 13381 /** KASUMI hash only (UIA1) */ 13382 TEST_CASE_ST(ut_setup, ut_teardown, 13383 test_kasumi_hash_generate_test_case_1), 13384 TEST_CASE_ST(ut_setup, ut_teardown, 13385 test_kasumi_hash_generate_test_case_2), 13386 TEST_CASE_ST(ut_setup, ut_teardown, 13387 test_kasumi_hash_generate_test_case_3), 13388 TEST_CASE_ST(ut_setup, ut_teardown, 13389 test_kasumi_hash_generate_test_case_4), 13390 TEST_CASE_ST(ut_setup, ut_teardown, 13391 test_kasumi_hash_generate_test_case_5), 13392 TEST_CASE_ST(ut_setup, ut_teardown, 13393 test_kasumi_hash_generate_test_case_6), 13394 13395 TEST_CASE_ST(ut_setup, ut_teardown, 13396 test_kasumi_hash_verify_test_case_1), 13397 TEST_CASE_ST(ut_setup, ut_teardown, 13398 test_kasumi_hash_verify_test_case_2), 13399 TEST_CASE_ST(ut_setup, ut_teardown, 13400 test_kasumi_hash_verify_test_case_3), 13401 TEST_CASE_ST(ut_setup, ut_teardown, 13402 test_kasumi_hash_verify_test_case_4), 13403 TEST_CASE_ST(ut_setup, ut_teardown, 13404 test_kasumi_hash_verify_test_case_5), 13405 13406 /** KASUMI encrypt only (UEA1) */ 13407 TEST_CASE_ST(ut_setup, ut_teardown, 13408 test_kasumi_encryption_test_case_1), 13409 TEST_CASE_ST(ut_setup, ut_teardown, 13410 test_kasumi_encryption_test_case_1_sgl), 13411 TEST_CASE_ST(ut_setup, ut_teardown, 13412 test_kasumi_encryption_test_case_1_oop), 13413 TEST_CASE_ST(ut_setup, ut_teardown, 13414 test_kasumi_encryption_test_case_1_oop_sgl), 13415 TEST_CASE_ST(ut_setup, ut_teardown, 13416 test_kasumi_encryption_test_case_2), 13417 TEST_CASE_ST(ut_setup, ut_teardown, 13418 test_kasumi_encryption_test_case_3), 13419 TEST_CASE_ST(ut_setup, ut_teardown, 13420 test_kasumi_encryption_test_case_4), 13421 TEST_CASE_ST(ut_setup, ut_teardown, 13422 test_kasumi_encryption_test_case_5), 13423 13424 /** KASUMI decrypt only (UEA1) */ 13425 TEST_CASE_ST(ut_setup, ut_teardown, 13426 test_kasumi_decryption_test_case_1), 13427 TEST_CASE_ST(ut_setup, ut_teardown, 13428 test_kasumi_decryption_test_case_2), 13429 TEST_CASE_ST(ut_setup, ut_teardown, 13430 test_kasumi_decryption_test_case_3), 13431 TEST_CASE_ST(ut_setup, ut_teardown, 13432 test_kasumi_decryption_test_case_4), 13433 TEST_CASE_ST(ut_setup, ut_teardown, 13434 test_kasumi_decryption_test_case_5), 13435 TEST_CASE_ST(ut_setup, ut_teardown, 13436 test_kasumi_decryption_test_case_1_oop), 13437 13438 TEST_CASE_ST(ut_setup, ut_teardown, 13439 test_kasumi_cipher_auth_test_case_1), 13440 13441 /** KASUMI generate auth, then encrypt (F8) */ 13442 TEST_CASE_ST(ut_setup, ut_teardown, 13443 test_kasumi_auth_cipher_test_case_1), 13444 TEST_CASE_ST(ut_setup, ut_teardown, 13445 test_kasumi_auth_cipher_test_case_2), 13446 TEST_CASE_ST(ut_setup, ut_teardown, 13447 test_kasumi_auth_cipher_test_case_2_oop), 13448 TEST_CASE_ST(ut_setup, ut_teardown, 13449 test_kasumi_auth_cipher_test_case_2_sgl), 13450 TEST_CASE_ST(ut_setup, ut_teardown, 13451 test_kasumi_auth_cipher_test_case_2_oop_sgl), 13452 13453 /** KASUMI decrypt (F8), then verify auth */ 13454 TEST_CASE_ST(ut_setup, ut_teardown, 13455 test_kasumi_auth_cipher_verify_test_case_1), 13456 TEST_CASE_ST(ut_setup, ut_teardown, 13457 test_kasumi_auth_cipher_verify_test_case_2), 13458 TEST_CASE_ST(ut_setup, ut_teardown, 13459 test_kasumi_auth_cipher_verify_test_case_2_oop), 13460 TEST_CASE_ST(ut_setup, ut_teardown, 13461 test_kasumi_auth_cipher_verify_test_case_2_sgl), 13462 TEST_CASE_ST(ut_setup, ut_teardown, 13463 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl), 13464 13465 /** ESN Testcase */ 13466 TEST_CASE_ST(ut_setup, ut_teardown, 13467 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 13468 TEST_CASE_ST(ut_setup, ut_teardown, 13469 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 13470 13471 /** Negative tests */ 13472 TEST_CASE_ST(ut_setup, ut_teardown, 13473 authentication_verify_HMAC_SHA1_fail_data_corrupt), 13474 TEST_CASE_ST(ut_setup, ut_teardown, 13475 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 13476 TEST_CASE_ST(ut_setup, ut_teardown, 13477 test_AES_GCM_auth_encryption_fail_iv_corrupt), 13478 TEST_CASE_ST(ut_setup, ut_teardown, 13479 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 13480 TEST_CASE_ST(ut_setup, ut_teardown, 13481 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 13482 TEST_CASE_ST(ut_setup, ut_teardown, 13483 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 13484 TEST_CASE_ST(ut_setup, ut_teardown, 13485 test_AES_GCM_auth_encryption_fail_aad_corrupt), 13486 TEST_CASE_ST(ut_setup, ut_teardown, 13487 test_AES_GCM_auth_encryption_fail_tag_corrupt), 13488 TEST_CASE_ST(ut_setup, ut_teardown, 13489 test_AES_GCM_auth_decryption_fail_iv_corrupt), 13490 TEST_CASE_ST(ut_setup, ut_teardown, 13491 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 13492 TEST_CASE_ST(ut_setup, ut_teardown, 13493 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 13494 TEST_CASE_ST(ut_setup, ut_teardown, 13495 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 13496 TEST_CASE_ST(ut_setup, ut_teardown, 13497 test_AES_GCM_auth_decryption_fail_aad_corrupt), 13498 TEST_CASE_ST(ut_setup, ut_teardown, 13499 test_AES_GCM_auth_decryption_fail_tag_corrupt), 13500 TEST_CASE_ST(ut_setup, ut_teardown, 13501 authentication_verify_AES128_GMAC_fail_data_corrupt), 13502 TEST_CASE_ST(ut_setup, ut_teardown, 13503 authentication_verify_AES128_GMAC_fail_tag_corrupt), 13504 TEST_CASE_ST(ut_setup, ut_teardown, 13505 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 13506 TEST_CASE_ST(ut_setup, ut_teardown, 13507 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 13508 13509 /** Mixed CIPHER + HASH algorithms */ 13510 /** AUTH AES CMAC + CIPHER AES CTR */ 13511 TEST_CASE_ST(ut_setup, ut_teardown, 13512 test_aes_cmac_aes_ctr_digest_enc_test_case_1), 13513 TEST_CASE_ST(ut_setup, ut_teardown, 13514 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 13515 TEST_CASE_ST(ut_setup, ut_teardown, 13516 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 13517 TEST_CASE_ST(ut_setup, ut_teardown, 13518 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 13519 TEST_CASE_ST(ut_setup, ut_teardown, 13520 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1), 13521 TEST_CASE_ST(ut_setup, ut_teardown, 13522 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 13523 TEST_CASE_ST(ut_setup, ut_teardown, 13524 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 13525 TEST_CASE_ST(ut_setup, ut_teardown, 13526 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 13527 13528 /** AUTH ZUC + CIPHER SNOW3G */ 13529 TEST_CASE_ST(ut_setup, ut_teardown, 13530 test_auth_zuc_cipher_snow_test_case_1), 13531 TEST_CASE_ST(ut_setup, ut_teardown, 13532 test_verify_auth_zuc_cipher_snow_test_case_1), 13533 /** AUTH AES CMAC + CIPHER SNOW3G */ 13534 TEST_CASE_ST(ut_setup, ut_teardown, 13535 test_auth_aes_cmac_cipher_snow_test_case_1), 13536 TEST_CASE_ST(ut_setup, ut_teardown, 13537 test_verify_auth_aes_cmac_cipher_snow_test_case_1), 13538 /** AUTH ZUC + CIPHER AES CTR */ 13539 TEST_CASE_ST(ut_setup, ut_teardown, 13540 test_auth_zuc_cipher_aes_ctr_test_case_1), 13541 TEST_CASE_ST(ut_setup, ut_teardown, 13542 test_verify_auth_zuc_cipher_aes_ctr_test_case_1), 13543 /** AUTH SNOW3G + CIPHER AES CTR */ 13544 TEST_CASE_ST(ut_setup, ut_teardown, 13545 test_auth_snow_cipher_aes_ctr_test_case_1), 13546 TEST_CASE_ST(ut_setup, ut_teardown, 13547 test_verify_auth_snow_cipher_aes_ctr_test_case_1), 13548 /** AUTH SNOW3G + CIPHER ZUC */ 13549 TEST_CASE_ST(ut_setup, ut_teardown, 13550 test_auth_snow_cipher_zuc_test_case_1), 13551 TEST_CASE_ST(ut_setup, ut_teardown, 13552 test_verify_auth_snow_cipher_zuc_test_case_1), 13553 /** AUTH AES CMAC + CIPHER ZUC */ 13554 TEST_CASE_ST(ut_setup, ut_teardown, 13555 test_auth_aes_cmac_cipher_zuc_test_case_1), 13556 TEST_CASE_ST(ut_setup, ut_teardown, 13557 test_verify_auth_aes_cmac_cipher_zuc_test_case_1), 13558 13559 /** AUTH NULL + CIPHER SNOW3G */ 13560 TEST_CASE_ST(ut_setup, ut_teardown, 13561 test_auth_null_cipher_snow_test_case_1), 13562 TEST_CASE_ST(ut_setup, ut_teardown, 13563 test_verify_auth_null_cipher_snow_test_case_1), 13564 /** AUTH NULL + CIPHER ZUC */ 13565 TEST_CASE_ST(ut_setup, ut_teardown, 13566 test_auth_null_cipher_zuc_test_case_1), 13567 TEST_CASE_ST(ut_setup, ut_teardown, 13568 test_verify_auth_null_cipher_zuc_test_case_1), 13569 /** AUTH SNOW3G + CIPHER NULL */ 13570 TEST_CASE_ST(ut_setup, ut_teardown, 13571 test_auth_snow_cipher_null_test_case_1), 13572 TEST_CASE_ST(ut_setup, ut_teardown, 13573 test_verify_auth_snow_cipher_null_test_case_1), 13574 /** AUTH ZUC + CIPHER NULL */ 13575 TEST_CASE_ST(ut_setup, ut_teardown, 13576 test_auth_zuc_cipher_null_test_case_1), 13577 TEST_CASE_ST(ut_setup, ut_teardown, 13578 test_verify_auth_zuc_cipher_null_test_case_1), 13579 /** AUTH NULL + CIPHER AES CTR */ 13580 TEST_CASE_ST(ut_setup, ut_teardown, 13581 test_auth_null_cipher_aes_ctr_test_case_1), 13582 TEST_CASE_ST(ut_setup, ut_teardown, 13583 test_verify_auth_null_cipher_aes_ctr_test_case_1), 13584 /** AUTH AES CMAC + CIPHER NULL */ 13585 TEST_CASE_ST(ut_setup, ut_teardown, 13586 test_auth_aes_cmac_cipher_null_test_case_1), 13587 TEST_CASE_ST(ut_setup, ut_teardown, 13588 test_verify_auth_aes_cmac_cipher_null_test_case_1), 13589 13590 #ifdef RTE_LIB_SECURITY 13591 TEST_CASE_ST(ut_setup_security, ut_teardown, 13592 test_PDCP_PROTO_all), 13593 TEST_CASE_ST(ut_setup_security, ut_teardown, 13594 test_DOCSIS_PROTO_all), 13595 #endif 13596 TEST_CASES_END() /**< NULL terminate unit test array */ 13597 } 13598 }; 13599 13600 static struct unit_test_suite cryptodev_virtio_testsuite = { 13601 .suite_name = "Crypto VIRTIO Unit Test Suite", 13602 .setup = testsuite_setup, 13603 .teardown = testsuite_teardown, 13604 .unit_test_cases = { 13605 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13606 13607 TEST_CASES_END() /**< NULL terminate unit test array */ 13608 } 13609 }; 13610 13611 static struct unit_test_suite cryptodev_caam_jr_testsuite = { 13612 .suite_name = "Crypto CAAM JR Unit Test Suite", 13613 .setup = testsuite_setup, 13614 .teardown = testsuite_teardown, 13615 .unit_test_cases = { 13616 TEST_CASE_ST(ut_setup, ut_teardown, 13617 test_device_configure_invalid_dev_id), 13618 TEST_CASE_ST(ut_setup, ut_teardown, 13619 test_multi_session), 13620 13621 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13622 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 13623 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13624 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 13625 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13626 13627 TEST_CASES_END() /**< NULL terminate unit test array */ 13628 } 13629 }; 13630 13631 static struct unit_test_suite cryptodev_mrvl_testsuite = { 13632 .suite_name = "Crypto Device Marvell Component Test Suite", 13633 .setup = testsuite_setup, 13634 .teardown = testsuite_teardown, 13635 .unit_test_cases = { 13636 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 13637 TEST_CASE_ST(ut_setup, ut_teardown, 13638 test_multi_session_random_usage), 13639 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13640 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13641 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13642 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 13643 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 13644 13645 /** Negative tests */ 13646 TEST_CASE_ST(ut_setup, ut_teardown, 13647 authentication_verify_HMAC_SHA1_fail_data_corrupt), 13648 TEST_CASE_ST(ut_setup, ut_teardown, 13649 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 13650 TEST_CASE_ST(ut_setup, ut_teardown, 13651 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 13652 TEST_CASE_ST(ut_setup, ut_teardown, 13653 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 13654 13655 TEST_CASES_END() /**< NULL terminate unit test array */ 13656 } 13657 }; 13658 13659 static struct unit_test_suite cryptodev_ccp_testsuite = { 13660 .suite_name = "Crypto Device CCP Unit Test Suite", 13661 .setup = testsuite_setup, 13662 .teardown = testsuite_teardown, 13663 .unit_test_cases = { 13664 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 13665 TEST_CASE_ST(ut_setup, ut_teardown, 13666 test_multi_session_random_usage), 13667 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13668 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13669 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 13670 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 13671 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13672 13673 /** Negative tests */ 13674 TEST_CASE_ST(ut_setup, ut_teardown, 13675 authentication_verify_HMAC_SHA1_fail_data_corrupt), 13676 TEST_CASE_ST(ut_setup, ut_teardown, 13677 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 13678 TEST_CASE_ST(ut_setup, ut_teardown, 13679 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 13680 TEST_CASE_ST(ut_setup, ut_teardown, 13681 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 13682 13683 TEST_CASES_END() /**< NULL terminate unit test array */ 13684 } 13685 }; 13686 13687 static int 13688 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/) 13689 { 13690 gbl_driver_id = rte_cryptodev_driver_id_get( 13691 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 13692 13693 if (gbl_driver_id == -1) { 13694 RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n"); 13695 return TEST_SKIPPED; 13696 } 13697 13698 return unit_test_suite_runner(&cryptodev_testsuite); 13699 } 13700 13701 static int 13702 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/) 13703 { 13704 gbl_driver_id = rte_cryptodev_driver_id_get( 13705 RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)); 13706 13707 if (gbl_driver_id == -1) { 13708 RTE_LOG(ERR, USER1, "VIRTIO PMD must be loaded.\n"); 13709 return TEST_FAILED; 13710 } 13711 13712 return unit_test_suite_runner(&cryptodev_virtio_testsuite); 13713 } 13714 13715 static int 13716 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/) 13717 { 13718 gbl_driver_id = rte_cryptodev_driver_id_get( 13719 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 13720 13721 if (gbl_driver_id == -1) { 13722 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 13723 return TEST_SKIPPED; 13724 } 13725 13726 return unit_test_suite_runner(&cryptodev_testsuite); 13727 } 13728 13729 static int 13730 test_cryptodev_cpu_aesni_mb(void) 13731 { 13732 int32_t rc; 13733 enum rte_security_session_action_type at; 13734 13735 gbl_driver_id = rte_cryptodev_driver_id_get( 13736 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 13737 13738 if (gbl_driver_id == -1) { 13739 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 13740 return TEST_SKIPPED; 13741 } 13742 13743 at = gbl_action_type; 13744 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 13745 rc = unit_test_suite_runner(&cryptodev_testsuite); 13746 gbl_action_type = at; 13747 return rc; 13748 } 13749 13750 static int 13751 test_cryptodev_openssl(void) 13752 { 13753 gbl_driver_id = rte_cryptodev_driver_id_get( 13754 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 13755 13756 if (gbl_driver_id == -1) { 13757 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded.\n"); 13758 return TEST_SKIPPED; 13759 } 13760 13761 return unit_test_suite_runner(&cryptodev_testsuite); 13762 } 13763 13764 static int 13765 test_cryptodev_aesni_gcm(void) 13766 { 13767 gbl_driver_id = rte_cryptodev_driver_id_get( 13768 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 13769 13770 if (gbl_driver_id == -1) { 13771 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded.\n"); 13772 return TEST_SKIPPED; 13773 } 13774 13775 return unit_test_suite_runner(&cryptodev_testsuite); 13776 } 13777 13778 static int 13779 test_cryptodev_cpu_aesni_gcm(void) 13780 { 13781 int32_t rc; 13782 enum rte_security_session_action_type at; 13783 13784 gbl_driver_id = rte_cryptodev_driver_id_get( 13785 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 13786 13787 if (gbl_driver_id == -1) { 13788 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded.\n"); 13789 return TEST_SKIPPED; 13790 } 13791 13792 at = gbl_action_type; 13793 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 13794 rc = unit_test_suite_runner(&cryptodev_testsuite); 13795 gbl_action_type = at; 13796 return rc; 13797 } 13798 13799 static int 13800 test_cryptodev_null(void) 13801 { 13802 gbl_driver_id = rte_cryptodev_driver_id_get( 13803 RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 13804 13805 if (gbl_driver_id == -1) { 13806 RTE_LOG(ERR, USER1, "NULL PMD must be loaded.\n"); 13807 return TEST_SKIPPED; 13808 } 13809 13810 return unit_test_suite_runner(&cryptodev_testsuite); 13811 } 13812 13813 static int 13814 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/) 13815 { 13816 gbl_driver_id = rte_cryptodev_driver_id_get( 13817 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 13818 13819 if (gbl_driver_id == -1) { 13820 RTE_LOG(ERR, USER1, "SNOW3G PMD must be loaded.\n"); 13821 return TEST_SKIPPED; 13822 } 13823 13824 return unit_test_suite_runner(&cryptodev_testsuite); 13825 } 13826 13827 static int 13828 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/) 13829 { 13830 gbl_driver_id = rte_cryptodev_driver_id_get( 13831 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 13832 13833 if (gbl_driver_id == -1) { 13834 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded.\n"); 13835 return TEST_SKIPPED; 13836 } 13837 13838 return unit_test_suite_runner(&cryptodev_testsuite); 13839 } 13840 13841 static int 13842 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/) 13843 { 13844 gbl_driver_id = rte_cryptodev_driver_id_get( 13845 RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 13846 13847 if (gbl_driver_id == -1) { 13848 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded.\n"); 13849 return TEST_SKIPPED; 13850 } 13851 13852 return unit_test_suite_runner(&cryptodev_testsuite); 13853 } 13854 13855 static int 13856 test_cryptodev_armv8(void) 13857 { 13858 gbl_driver_id = rte_cryptodev_driver_id_get( 13859 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 13860 13861 if (gbl_driver_id == -1) { 13862 RTE_LOG(ERR, USER1, "ARMV8 PMD must be loaded.\n"); 13863 return TEST_SKIPPED; 13864 } 13865 13866 return unit_test_suite_runner(&cryptodev_testsuite); 13867 } 13868 13869 static int 13870 test_cryptodev_mrvl(void) 13871 { 13872 gbl_driver_id = rte_cryptodev_driver_id_get( 13873 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 13874 13875 if (gbl_driver_id == -1) { 13876 RTE_LOG(ERR, USER1, "MVSAM PMD must be loaded.\n"); 13877 return TEST_SKIPPED; 13878 } 13879 13880 return unit_test_suite_runner(&cryptodev_mrvl_testsuite); 13881 } 13882 13883 #ifdef RTE_CRYPTO_SCHEDULER 13884 13885 static int 13886 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/) 13887 { 13888 gbl_driver_id = rte_cryptodev_driver_id_get( 13889 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 13890 13891 if (gbl_driver_id == -1) { 13892 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n"); 13893 return TEST_SKIPPED; 13894 } 13895 13896 if (rte_cryptodev_driver_id_get( 13897 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) { 13898 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 13899 return TEST_SKIPPED; 13900 } 13901 return unit_test_suite_runner(&cryptodev_scheduler_testsuite); 13902 } 13903 13904 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler); 13905 13906 #endif 13907 13908 static int 13909 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/) 13910 { 13911 gbl_driver_id = rte_cryptodev_driver_id_get( 13912 RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 13913 13914 if (gbl_driver_id == -1) { 13915 RTE_LOG(ERR, USER1, "DPAA2 SEC PMD must be loaded.\n"); 13916 return TEST_SKIPPED; 13917 } 13918 13919 return unit_test_suite_runner(&cryptodev_testsuite); 13920 } 13921 13922 static int 13923 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/) 13924 { 13925 gbl_driver_id = rte_cryptodev_driver_id_get( 13926 RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 13927 13928 if (gbl_driver_id == -1) { 13929 RTE_LOG(ERR, USER1, "DPAA SEC PMD must be loaded.\n"); 13930 return TEST_SKIPPED; 13931 } 13932 13933 return unit_test_suite_runner(&cryptodev_testsuite); 13934 } 13935 13936 static int 13937 test_cryptodev_ccp(void) 13938 { 13939 gbl_driver_id = rte_cryptodev_driver_id_get( 13940 RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 13941 13942 if (gbl_driver_id == -1) { 13943 RTE_LOG(ERR, USER1, "CCP PMD must be loaded.\n"); 13944 return TEST_FAILED; 13945 } 13946 13947 return unit_test_suite_runner(&cryptodev_ccp_testsuite); 13948 } 13949 13950 static int 13951 test_cryptodev_octeontx(void) 13952 { 13953 gbl_driver_id = rte_cryptodev_driver_id_get( 13954 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)); 13955 if (gbl_driver_id == -1) { 13956 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded.\n"); 13957 return TEST_FAILED; 13958 } 13959 return unit_test_suite_runner(&cryptodev_testsuite); 13960 } 13961 13962 static int 13963 test_cryptodev_octeontx2(void) 13964 { 13965 gbl_driver_id = rte_cryptodev_driver_id_get( 13966 RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD)); 13967 if (gbl_driver_id == -1) { 13968 RTE_LOG(ERR, USER1, "OCTEON TX2 PMD must be loaded.\n"); 13969 return TEST_FAILED; 13970 } 13971 return unit_test_suite_runner(&cryptodev_testsuite); 13972 } 13973 13974 static int 13975 test_cryptodev_caam_jr(void /*argv __rte_unused, int argc __rte_unused*/) 13976 { 13977 gbl_driver_id = rte_cryptodev_driver_id_get( 13978 RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)); 13979 13980 if (gbl_driver_id == -1) { 13981 RTE_LOG(ERR, USER1, "CAAM_JR PMD must be loaded.\n"); 13982 return TEST_FAILED; 13983 } 13984 13985 return unit_test_suite_runner(&cryptodev_caam_jr_testsuite); 13986 } 13987 13988 static int 13989 test_cryptodev_nitrox(void) 13990 { 13991 gbl_driver_id = rte_cryptodev_driver_id_get( 13992 RTE_STR(CRYPTODEV_NAME_NITROX_PMD)); 13993 13994 if (gbl_driver_id == -1) { 13995 RTE_LOG(ERR, USER1, "NITROX PMD must be loaded.\n"); 13996 return TEST_FAILED; 13997 } 13998 13999 return unit_test_suite_runner(&cryptodev_testsuite); 14000 } 14001 14002 static int 14003 test_cryptodev_bcmfs(void) 14004 { 14005 gbl_driver_id = rte_cryptodev_driver_id_get( 14006 RTE_STR(CRYPTODEV_NAME_BCMFS_PMD)); 14007 14008 if (gbl_driver_id == -1) { 14009 RTE_LOG(ERR, USER1, "BCMFS PMD must be loaded.\n"); 14010 return TEST_FAILED; 14011 } 14012 14013 return unit_test_suite_runner(&cryptodev_testsuite); 14014 } 14015 14016 static int 14017 test_cryptodev_qat_raw_api(void /*argv __rte_unused, int argc __rte_unused*/) 14018 { 14019 int ret; 14020 14021 gbl_driver_id = rte_cryptodev_driver_id_get( 14022 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 14023 14024 if (gbl_driver_id == -1) { 14025 RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check that both " 14026 "CONFIG_RTE_LIBRTE_PMD_QAT and CONFIG_RTE_LIBRTE_PMD_QAT_SYM " 14027 "are enabled in config file to run this testsuite.\n"); 14028 return TEST_SKIPPED; 14029 } 14030 14031 global_api_test_type = CRYPTODEV_RAW_API_TEST; 14032 ret = unit_test_suite_runner(&cryptodev_testsuite); 14033 global_api_test_type = CRYPTODEV_API_TEST; 14034 14035 return ret; 14036 } 14037 14038 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest, 14039 test_cryptodev_qat_raw_api); 14040 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat); 14041 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 14042 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest, 14043 test_cryptodev_cpu_aesni_mb); 14044 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl); 14045 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 14046 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest, 14047 test_cryptodev_cpu_aesni_gcm); 14048 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null); 14049 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 14050 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 14051 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 14052 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8); 14053 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl); 14054 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec); 14055 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec); 14056 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp); 14057 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio); 14058 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx); 14059 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2); 14060 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr); 14061 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox); 14062 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs); 14063