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 void 166 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused, 167 uint8_t is_op_success) 168 { 169 struct rte_crypto_op *op = user_data; 170 op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS : 171 RTE_CRYPTO_OP_STATUS_ERROR; 172 } 173 174 void 175 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id, 176 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth, 177 uint8_t len_in_bits, uint8_t cipher_iv_len) 178 { 179 struct rte_crypto_sym_op *sop = op->sym; 180 struct rte_crypto_op *ret_op = NULL; 181 struct rte_crypto_vec data_vec[UINT8_MAX]; 182 struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv; 183 union rte_crypto_sym_ofs ofs; 184 struct rte_crypto_sym_vec vec; 185 struct rte_crypto_sgl sgl; 186 uint32_t max_len; 187 union rte_cryptodev_session_ctx sess; 188 uint32_t count = 0; 189 struct rte_crypto_raw_dp_ctx *ctx; 190 uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0, 191 auth_len = 0; 192 int32_t n; 193 uint32_t n_success; 194 int ctx_service_size; 195 int32_t status = 0; 196 int enqueue_status, dequeue_status; 197 198 ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id); 199 if (ctx_service_size < 0) { 200 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 201 return; 202 } 203 204 ctx = malloc(ctx_service_size); 205 if (!ctx) { 206 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 207 return; 208 } 209 210 /* Both are enums, setting crypto_sess will suit any session type */ 211 sess.crypto_sess = op->sym->session; 212 213 if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx, 214 op->sess_type, sess, 0) < 0) { 215 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 216 goto exit; 217 } 218 219 cipher_iv.iova = 0; 220 cipher_iv.va = NULL; 221 aad_auth_iv.iova = 0; 222 aad_auth_iv.va = NULL; 223 digest.iova = 0; 224 digest.va = NULL; 225 sgl.vec = data_vec; 226 vec.num = 1; 227 vec.sgl = &sgl; 228 vec.iv = &cipher_iv; 229 vec.digest = &digest; 230 vec.aad = &aad_auth_iv; 231 vec.status = &status; 232 233 ofs.raw = 0; 234 235 if (is_cipher && is_auth) { 236 cipher_offset = sop->cipher.data.offset; 237 cipher_len = sop->cipher.data.length; 238 auth_offset = sop->auth.data.offset; 239 auth_len = sop->auth.data.length; 240 max_len = RTE_MAX(cipher_offset + cipher_len, 241 auth_offset + auth_len); 242 if (len_in_bits) { 243 max_len = max_len >> 3; 244 cipher_offset = cipher_offset >> 3; 245 auth_offset = auth_offset >> 3; 246 cipher_len = cipher_len >> 3; 247 auth_len = auth_len >> 3; 248 } 249 ofs.ofs.cipher.head = cipher_offset; 250 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 251 ofs.ofs.auth.head = auth_offset; 252 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 253 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 254 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 255 aad_auth_iv.va = rte_crypto_op_ctod_offset( 256 op, void *, IV_OFFSET + cipher_iv_len); 257 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 258 cipher_iv_len); 259 digest.va = (void *)sop->auth.digest.data; 260 digest.iova = sop->auth.digest.phys_addr; 261 262 } else if (is_cipher) { 263 cipher_offset = sop->cipher.data.offset; 264 cipher_len = sop->cipher.data.length; 265 max_len = cipher_len + cipher_offset; 266 if (len_in_bits) { 267 max_len = max_len >> 3; 268 cipher_offset = cipher_offset >> 3; 269 cipher_len = cipher_len >> 3; 270 } 271 ofs.ofs.cipher.head = cipher_offset; 272 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 273 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 274 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 275 276 } else if (is_auth) { 277 auth_offset = sop->auth.data.offset; 278 auth_len = sop->auth.data.length; 279 max_len = auth_len + auth_offset; 280 if (len_in_bits) { 281 max_len = max_len >> 3; 282 auth_offset = auth_offset >> 3; 283 auth_len = auth_len >> 3; 284 } 285 ofs.ofs.auth.head = auth_offset; 286 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 287 aad_auth_iv.va = rte_crypto_op_ctod_offset( 288 op, void *, IV_OFFSET + cipher_iv_len); 289 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 290 cipher_iv_len); 291 digest.va = (void *)sop->auth.digest.data; 292 digest.iova = sop->auth.digest.phys_addr; 293 294 } else { /* aead */ 295 cipher_offset = sop->aead.data.offset; 296 cipher_len = sop->aead.data.length; 297 max_len = cipher_len + cipher_offset; 298 if (len_in_bits) { 299 max_len = max_len >> 3; 300 cipher_offset = cipher_offset >> 3; 301 cipher_len = cipher_len >> 3; 302 } 303 ofs.ofs.cipher.head = cipher_offset; 304 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 305 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 306 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 307 aad_auth_iv.va = (void *)sop->aead.aad.data; 308 aad_auth_iv.iova = sop->aead.aad.phys_addr; 309 digest.va = (void *)sop->aead.digest.data; 310 digest.iova = sop->aead.digest.phys_addr; 311 } 312 313 n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len, 314 data_vec, RTE_DIM(data_vec)); 315 if (n < 0 || n > sop->m_src->nb_segs) { 316 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 317 goto exit; 318 } 319 320 sgl.num = n; 321 322 if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op, 323 &enqueue_status) < 1) { 324 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 325 goto exit; 326 } 327 328 if (enqueue_status == 0) { 329 status = rte_cryptodev_raw_enqueue_done(ctx, 1); 330 if (status < 0) { 331 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 332 goto exit; 333 } 334 } else if (enqueue_status < 0) { 335 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 336 goto exit; 337 } 338 339 n = n_success = 0; 340 while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) { 341 n = rte_cryptodev_raw_dequeue_burst(ctx, 342 NULL, 1, post_process_raw_dp_op, 343 (void **)&ret_op, 0, &n_success, 344 &dequeue_status); 345 if (dequeue_status < 0) { 346 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 347 goto exit; 348 } 349 if (n == 0) 350 rte_pause(); 351 } 352 353 if (n == 1 && dequeue_status == 0) { 354 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) { 355 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 356 goto exit; 357 } 358 } 359 360 op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op || 361 n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR : 362 RTE_CRYPTO_OP_STATUS_SUCCESS; 363 364 exit: 365 free(ctx); 366 } 367 368 static void 369 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op) 370 { 371 int32_t n, st; 372 struct rte_crypto_sym_op *sop; 373 union rte_crypto_sym_ofs ofs; 374 struct rte_crypto_sgl sgl; 375 struct rte_crypto_sym_vec symvec; 376 struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr; 377 struct rte_crypto_vec vec[UINT8_MAX]; 378 379 sop = op->sym; 380 381 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset, 382 sop->aead.data.length, vec, RTE_DIM(vec)); 383 384 if (n < 0 || n != sop->m_src->nb_segs) { 385 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 386 return; 387 } 388 389 sgl.vec = vec; 390 sgl.num = n; 391 symvec.sgl = &sgl; 392 symvec.iv = &iv_ptr; 393 symvec.digest = &digest_ptr; 394 symvec.aad = &aad_ptr; 395 symvec.status = &st; 396 symvec.num = 1; 397 398 /* for CPU crypto the IOVA address is not required */ 399 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 400 digest_ptr.va = (void *)sop->aead.digest.data; 401 aad_ptr.va = (void *)sop->aead.aad.data; 402 403 ofs.raw = 0; 404 405 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 406 &symvec); 407 408 if (n != 1) 409 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 410 else 411 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 412 } 413 414 static void 415 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op) 416 { 417 int32_t n, st; 418 struct rte_crypto_sym_op *sop; 419 union rte_crypto_sym_ofs ofs; 420 struct rte_crypto_sgl sgl; 421 struct rte_crypto_sym_vec symvec; 422 struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr; 423 struct rte_crypto_vec vec[UINT8_MAX]; 424 425 sop = op->sym; 426 427 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset, 428 sop->auth.data.length, vec, RTE_DIM(vec)); 429 430 if (n < 0 || n != sop->m_src->nb_segs) { 431 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 432 return; 433 } 434 435 sgl.vec = vec; 436 sgl.num = n; 437 symvec.sgl = &sgl; 438 symvec.iv = &iv_ptr; 439 symvec.digest = &digest_ptr; 440 symvec.status = &st; 441 symvec.num = 1; 442 443 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 444 digest_ptr.va = (void *)sop->auth.digest.data; 445 446 ofs.raw = 0; 447 ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset; 448 ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) - 449 (sop->cipher.data.offset + sop->cipher.data.length); 450 451 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 452 &symvec); 453 454 if (n != 1) 455 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 456 else 457 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 458 } 459 460 static struct rte_crypto_op * 461 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op) 462 { 463 464 RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO); 465 466 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 467 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n"); 468 return NULL; 469 } 470 471 op = NULL; 472 473 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 474 rte_pause(); 475 476 if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 477 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status); 478 return NULL; 479 } 480 481 return op; 482 } 483 484 static struct crypto_testsuite_params testsuite_params = { NULL }; 485 static struct crypto_unittest_params unittest_params; 486 487 static int 488 testsuite_setup(void) 489 { 490 struct crypto_testsuite_params *ts_params = &testsuite_params; 491 struct rte_cryptodev_info info; 492 uint32_t i = 0, nb_devs, dev_id; 493 int ret; 494 uint16_t qp_id; 495 496 memset(ts_params, 0, sizeof(*ts_params)); 497 498 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 499 if (ts_params->mbuf_pool == NULL) { 500 /* Not already created so create */ 501 ts_params->mbuf_pool = rte_pktmbuf_pool_create( 502 "CRYPTO_MBUFPOOL", 503 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE, 504 rte_socket_id()); 505 if (ts_params->mbuf_pool == NULL) { 506 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n"); 507 return TEST_FAILED; 508 } 509 } 510 511 ts_params->large_mbuf_pool = rte_mempool_lookup( 512 "CRYPTO_LARGE_MBUFPOOL"); 513 if (ts_params->large_mbuf_pool == NULL) { 514 /* Not already created so create */ 515 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create( 516 "CRYPTO_LARGE_MBUFPOOL", 517 1, 0, 0, UINT16_MAX, 518 rte_socket_id()); 519 if (ts_params->large_mbuf_pool == NULL) { 520 RTE_LOG(ERR, USER1, 521 "Can't create CRYPTO_LARGE_MBUFPOOL\n"); 522 return TEST_FAILED; 523 } 524 } 525 526 ts_params->op_mpool = rte_crypto_op_pool_create( 527 "MBUF_CRYPTO_SYM_OP_POOL", 528 RTE_CRYPTO_OP_TYPE_SYMMETRIC, 529 NUM_MBUFS, MBUF_CACHE_SIZE, 530 DEFAULT_NUM_XFORMS * 531 sizeof(struct rte_crypto_sym_xform) + 532 MAXIMUM_IV_LENGTH, 533 rte_socket_id()); 534 if (ts_params->op_mpool == NULL) { 535 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n"); 536 return TEST_FAILED; 537 } 538 539 /* Create an AESNI MB device if required */ 540 if (gbl_driver_id == rte_cryptodev_driver_id_get( 541 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) { 542 nb_devs = rte_cryptodev_device_count_by_driver( 543 rte_cryptodev_driver_id_get( 544 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))); 545 if (nb_devs < 1) { 546 ret = rte_vdev_init( 547 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL); 548 549 TEST_ASSERT(ret == 0, 550 "Failed to create instance of" 551 " pmd : %s", 552 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 553 } 554 } 555 556 /* Create an AESNI GCM device if required */ 557 if (gbl_driver_id == rte_cryptodev_driver_id_get( 558 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))) { 559 nb_devs = rte_cryptodev_device_count_by_driver( 560 rte_cryptodev_driver_id_get( 561 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))); 562 if (nb_devs < 1) { 563 TEST_ASSERT_SUCCESS(rte_vdev_init( 564 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL), 565 "Failed to create instance of" 566 " pmd : %s", 567 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 568 } 569 } 570 571 /* Create a SNOW 3G device if required */ 572 if (gbl_driver_id == rte_cryptodev_driver_id_get( 573 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD))) { 574 nb_devs = rte_cryptodev_device_count_by_driver( 575 rte_cryptodev_driver_id_get( 576 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD))); 577 if (nb_devs < 1) { 578 TEST_ASSERT_SUCCESS(rte_vdev_init( 579 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL), 580 "Failed to create instance of" 581 " pmd : %s", 582 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 583 } 584 } 585 586 /* Create a KASUMI device if required */ 587 if (gbl_driver_id == rte_cryptodev_driver_id_get( 588 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD))) { 589 nb_devs = rte_cryptodev_device_count_by_driver( 590 rte_cryptodev_driver_id_get( 591 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD))); 592 if (nb_devs < 1) { 593 TEST_ASSERT_SUCCESS(rte_vdev_init( 594 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL), 595 "Failed to create instance of" 596 " pmd : %s", 597 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 598 } 599 } 600 601 /* Create a ZUC device if required */ 602 if (gbl_driver_id == rte_cryptodev_driver_id_get( 603 RTE_STR(CRYPTODEV_NAME_ZUC_PMD))) { 604 nb_devs = rte_cryptodev_device_count_by_driver( 605 rte_cryptodev_driver_id_get( 606 RTE_STR(CRYPTODEV_NAME_ZUC_PMD))); 607 if (nb_devs < 1) { 608 TEST_ASSERT_SUCCESS(rte_vdev_init( 609 RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL), 610 "Failed to create instance of" 611 " pmd : %s", 612 RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 613 } 614 } 615 616 /* Create a NULL device if required */ 617 if (gbl_driver_id == rte_cryptodev_driver_id_get( 618 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) { 619 nb_devs = rte_cryptodev_device_count_by_driver( 620 rte_cryptodev_driver_id_get( 621 RTE_STR(CRYPTODEV_NAME_NULL_PMD))); 622 if (nb_devs < 1) { 623 ret = rte_vdev_init( 624 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL); 625 626 TEST_ASSERT(ret == 0, 627 "Failed to create instance of" 628 " pmd : %s", 629 RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 630 } 631 } 632 633 /* Create an OPENSSL device if required */ 634 if (gbl_driver_id == rte_cryptodev_driver_id_get( 635 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) { 636 nb_devs = rte_cryptodev_device_count_by_driver( 637 rte_cryptodev_driver_id_get( 638 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))); 639 if (nb_devs < 1) { 640 ret = rte_vdev_init( 641 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD), 642 NULL); 643 644 TEST_ASSERT(ret == 0, "Failed to create " 645 "instance of pmd : %s", 646 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 647 } 648 } 649 650 /* Create a ARMv8 device if required */ 651 if (gbl_driver_id == rte_cryptodev_driver_id_get( 652 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD))) { 653 nb_devs = rte_cryptodev_device_count_by_driver( 654 rte_cryptodev_driver_id_get( 655 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD))); 656 if (nb_devs < 1) { 657 ret = rte_vdev_init( 658 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD), 659 NULL); 660 661 TEST_ASSERT(ret == 0, "Failed to create " 662 "instance of pmd : %s", 663 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 664 } 665 } 666 667 /* Create a MVSAM device if required */ 668 if (gbl_driver_id == rte_cryptodev_driver_id_get( 669 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD))) { 670 nb_devs = rte_cryptodev_device_count_by_driver( 671 rte_cryptodev_driver_id_get( 672 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD))); 673 if (nb_devs < 1) { 674 ret = rte_vdev_init( 675 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD), 676 NULL); 677 678 TEST_ASSERT(ret == 0, "Failed to create " 679 "instance of pmd : %s", 680 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 681 } 682 } 683 684 /* Create an CCP device if required */ 685 if (gbl_driver_id == rte_cryptodev_driver_id_get( 686 RTE_STR(CRYPTODEV_NAME_CCP_PMD))) { 687 nb_devs = rte_cryptodev_device_count_by_driver( 688 rte_cryptodev_driver_id_get( 689 RTE_STR(CRYPTODEV_NAME_CCP_PMD))); 690 if (nb_devs < 1) { 691 ret = rte_vdev_init( 692 RTE_STR(CRYPTODEV_NAME_CCP_PMD), 693 NULL); 694 695 TEST_ASSERT(ret == 0, "Failed to create " 696 "instance of pmd : %s", 697 RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 698 } 699 } 700 701 #ifdef RTE_CRYPTO_SCHEDULER 702 char vdev_args[VDEV_ARGS_SIZE] = {""}; 703 char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core," 704 "ordering=enable,name=cryptodev_test_scheduler,corelist="}; 705 uint16_t worker_core_count = 0; 706 uint16_t socket_id = 0; 707 708 if (gbl_driver_id == rte_cryptodev_driver_id_get( 709 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) { 710 711 /* Identify the Worker Cores 712 * Use 2 worker cores for the device args 713 */ 714 RTE_LCORE_FOREACH_WORKER(i) { 715 if (worker_core_count > 1) 716 break; 717 snprintf(vdev_args, sizeof(vdev_args), 718 "%s%d", temp_str, i); 719 strcpy(temp_str, vdev_args); 720 strlcat(temp_str, ";", sizeof(temp_str)); 721 worker_core_count++; 722 socket_id = rte_lcore_to_socket_id(i); 723 } 724 if (worker_core_count != 2) { 725 RTE_LOG(ERR, USER1, 726 "Cryptodev scheduler test require at least " 727 "two worker cores to run. " 728 "Please use the correct coremask.\n"); 729 return TEST_FAILED; 730 } 731 strcpy(temp_str, vdev_args); 732 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", 733 temp_str, socket_id); 734 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args); 735 nb_devs = rte_cryptodev_device_count_by_driver( 736 rte_cryptodev_driver_id_get( 737 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))); 738 if (nb_devs < 1) { 739 ret = rte_vdev_init( 740 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD), 741 vdev_args); 742 TEST_ASSERT(ret == 0, 743 "Failed to create instance %u of" 744 " pmd : %s", 745 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 746 } 747 } 748 #endif /* RTE_CRYPTO_SCHEDULER */ 749 750 nb_devs = rte_cryptodev_count(); 751 if (nb_devs < 1) { 752 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 753 return TEST_SKIPPED; 754 } 755 756 /* Create list of valid crypto devs */ 757 for (i = 0; i < nb_devs; i++) { 758 rte_cryptodev_info_get(i, &info); 759 if (info.driver_id == gbl_driver_id) 760 ts_params->valid_devs[ts_params->valid_dev_count++] = i; 761 } 762 763 if (ts_params->valid_dev_count < 1) 764 return TEST_FAILED; 765 766 /* Set up all the qps on the first of the valid devices found */ 767 768 dev_id = ts_params->valid_devs[0]; 769 770 rte_cryptodev_info_get(dev_id, &info); 771 772 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; 773 ts_params->conf.socket_id = SOCKET_ID_ANY; 774 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY; 775 776 unsigned int session_size = 777 rte_cryptodev_sym_get_private_session_size(dev_id); 778 779 #ifdef RTE_LIB_SECURITY 780 unsigned int security_session_size = rte_security_session_get_size( 781 rte_cryptodev_get_sec_ctx(dev_id)); 782 783 if (session_size < security_session_size) 784 session_size = security_session_size; 785 #endif 786 /* 787 * Create mempool with maximum number of sessions. 788 */ 789 if (info.sym.max_nb_sessions != 0 && 790 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 791 RTE_LOG(ERR, USER1, "Device does not support " 792 "at least %u sessions\n", 793 MAX_NB_SESSIONS); 794 return TEST_FAILED; 795 } 796 797 ts_params->session_mpool = rte_cryptodev_sym_session_pool_create( 798 "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0, 799 SOCKET_ID_ANY); 800 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 801 "session mempool allocation failed"); 802 803 ts_params->session_priv_mpool = rte_mempool_create( 804 "test_sess_mp_priv", 805 MAX_NB_SESSIONS, 806 session_size, 807 0, 0, NULL, NULL, NULL, 808 NULL, SOCKET_ID_ANY, 809 0); 810 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 811 "session mempool allocation failed"); 812 813 814 815 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, 816 &ts_params->conf), 817 "Failed to configure cryptodev %u with %u qps", 818 dev_id, ts_params->conf.nb_queue_pairs); 819 820 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 821 ts_params->qp_conf.mp_session = ts_params->session_mpool; 822 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 823 824 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 825 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 826 dev_id, qp_id, &ts_params->qp_conf, 827 rte_cryptodev_socket_id(dev_id)), 828 "Failed to setup queue pair %u on cryptodev %u", 829 qp_id, dev_id); 830 } 831 832 return TEST_SUCCESS; 833 } 834 835 static void 836 testsuite_teardown(void) 837 { 838 struct crypto_testsuite_params *ts_params = &testsuite_params; 839 int res; 840 841 if (ts_params->mbuf_pool != NULL) { 842 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 843 rte_mempool_avail_count(ts_params->mbuf_pool)); 844 } 845 846 if (ts_params->op_mpool != NULL) { 847 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", 848 rte_mempool_avail_count(ts_params->op_mpool)); 849 } 850 851 /* Free session mempools */ 852 if (ts_params->session_priv_mpool != NULL) { 853 rte_mempool_free(ts_params->session_priv_mpool); 854 ts_params->session_priv_mpool = NULL; 855 } 856 857 if (ts_params->session_mpool != NULL) { 858 rte_mempool_free(ts_params->session_mpool); 859 ts_params->session_mpool = NULL; 860 } 861 862 res = rte_cryptodev_close(ts_params->valid_devs[0]); 863 if (res) 864 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res); 865 } 866 867 static int 868 dev_configure_and_start(uint64_t ff_disable) 869 { 870 struct crypto_testsuite_params *ts_params = &testsuite_params; 871 struct crypto_unittest_params *ut_params = &unittest_params; 872 873 uint16_t qp_id; 874 875 /* Clear unit test parameters before running test */ 876 memset(ut_params, 0, sizeof(*ut_params)); 877 878 /* Reconfigure device to default parameters */ 879 ts_params->conf.socket_id = SOCKET_ID_ANY; 880 ts_params->conf.ff_disable = ff_disable; 881 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 882 ts_params->qp_conf.mp_session = ts_params->session_mpool; 883 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 884 885 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 886 &ts_params->conf), 887 "Failed to configure cryptodev %u", 888 ts_params->valid_devs[0]); 889 890 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { 891 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 892 ts_params->valid_devs[0], qp_id, 893 &ts_params->qp_conf, 894 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 895 "Failed to setup queue pair %u on cryptodev %u", 896 qp_id, ts_params->valid_devs[0]); 897 } 898 899 900 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 901 902 /* Start the device */ 903 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 904 "Failed to start cryptodev %u", 905 ts_params->valid_devs[0]); 906 907 return TEST_SUCCESS; 908 } 909 910 static int 911 ut_setup(void) 912 { 913 /* Configure and start the device with security feature disabled */ 914 return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY); 915 } 916 917 static int 918 ut_setup_security(void) 919 { 920 /* Configure and start the device with no features disabled */ 921 return dev_configure_and_start(0); 922 } 923 924 static void 925 ut_teardown(void) 926 { 927 struct crypto_testsuite_params *ts_params = &testsuite_params; 928 struct crypto_unittest_params *ut_params = &unittest_params; 929 struct rte_cryptodev_stats stats; 930 931 /* free crypto session structure */ 932 #ifdef RTE_LIB_SECURITY 933 if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) { 934 if (ut_params->sec_session) { 935 rte_security_session_destroy(rte_cryptodev_get_sec_ctx 936 (ts_params->valid_devs[0]), 937 ut_params->sec_session); 938 ut_params->sec_session = NULL; 939 } 940 } else 941 #endif 942 { 943 if (ut_params->sess) { 944 rte_cryptodev_sym_session_clear( 945 ts_params->valid_devs[0], 946 ut_params->sess); 947 rte_cryptodev_sym_session_free(ut_params->sess); 948 ut_params->sess = NULL; 949 } 950 } 951 952 /* free crypto operation structure */ 953 if (ut_params->op) 954 rte_crypto_op_free(ut_params->op); 955 956 /* 957 * free mbuf - both obuf and ibuf are usually the same, 958 * so check if they point at the same address is necessary, 959 * to avoid freeing the mbuf twice. 960 */ 961 if (ut_params->obuf) { 962 rte_pktmbuf_free(ut_params->obuf); 963 if (ut_params->ibuf == ut_params->obuf) 964 ut_params->ibuf = 0; 965 ut_params->obuf = 0; 966 } 967 if (ut_params->ibuf) { 968 rte_pktmbuf_free(ut_params->ibuf); 969 ut_params->ibuf = 0; 970 } 971 972 if (ts_params->mbuf_pool != NULL) 973 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 974 rte_mempool_avail_count(ts_params->mbuf_pool)); 975 976 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats); 977 978 /* Stop the device */ 979 rte_cryptodev_stop(ts_params->valid_devs[0]); 980 } 981 982 static int 983 test_device_configure_invalid_dev_id(void) 984 { 985 struct crypto_testsuite_params *ts_params = &testsuite_params; 986 uint16_t dev_id, num_devs = 0; 987 988 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 989 "Need at least %d devices for test", 1); 990 991 /* valid dev_id values */ 992 dev_id = ts_params->valid_devs[0]; 993 994 /* Stop the device in case it's started so it can be configured */ 995 rte_cryptodev_stop(dev_id); 996 997 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 998 "Failed test for rte_cryptodev_configure: " 999 "invalid dev_num %u", dev_id); 1000 1001 /* invalid dev_id values */ 1002 dev_id = num_devs; 1003 1004 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1005 "Failed test for rte_cryptodev_configure: " 1006 "invalid dev_num %u", dev_id); 1007 1008 dev_id = 0xff; 1009 1010 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1011 "Failed test for rte_cryptodev_configure:" 1012 "invalid dev_num %u", dev_id); 1013 1014 return TEST_SUCCESS; 1015 } 1016 1017 static int 1018 test_device_configure_invalid_queue_pair_ids(void) 1019 { 1020 struct crypto_testsuite_params *ts_params = &testsuite_params; 1021 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 1022 1023 /* Stop the device in case it's started so it can be configured */ 1024 rte_cryptodev_stop(ts_params->valid_devs[0]); 1025 1026 /* valid - max value queue pairs */ 1027 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1028 1029 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1030 &ts_params->conf), 1031 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1032 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 1033 1034 /* valid - one queue pairs */ 1035 ts_params->conf.nb_queue_pairs = 1; 1036 1037 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1038 &ts_params->conf), 1039 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1040 ts_params->valid_devs[0], 1041 ts_params->conf.nb_queue_pairs); 1042 1043 1044 /* invalid - zero queue pairs */ 1045 ts_params->conf.nb_queue_pairs = 0; 1046 1047 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1048 &ts_params->conf), 1049 "Failed test for rte_cryptodev_configure, dev_id %u," 1050 " invalid qps: %u", 1051 ts_params->valid_devs[0], 1052 ts_params->conf.nb_queue_pairs); 1053 1054 1055 /* invalid - max value supported by field queue pairs */ 1056 ts_params->conf.nb_queue_pairs = UINT16_MAX; 1057 1058 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1059 &ts_params->conf), 1060 "Failed test for rte_cryptodev_configure, dev_id %u," 1061 " invalid qps: %u", 1062 ts_params->valid_devs[0], 1063 ts_params->conf.nb_queue_pairs); 1064 1065 1066 /* invalid - max value + 1 queue pairs */ 1067 ts_params->conf.nb_queue_pairs = orig_nb_qps + 1; 1068 1069 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1070 &ts_params->conf), 1071 "Failed test for rte_cryptodev_configure, dev_id %u," 1072 " invalid qps: %u", 1073 ts_params->valid_devs[0], 1074 ts_params->conf.nb_queue_pairs); 1075 1076 /* revert to original testsuite value */ 1077 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1078 1079 return TEST_SUCCESS; 1080 } 1081 1082 static int 1083 test_queue_pair_descriptor_setup(void) 1084 { 1085 struct crypto_testsuite_params *ts_params = &testsuite_params; 1086 struct rte_cryptodev_qp_conf qp_conf = { 1087 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 1088 }; 1089 uint16_t qp_id; 1090 1091 /* Stop the device in case it's started so it can be configured */ 1092 rte_cryptodev_stop(ts_params->valid_devs[0]); 1093 1094 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1095 &ts_params->conf), 1096 "Failed to configure cryptodev %u", 1097 ts_params->valid_devs[0]); 1098 1099 /* 1100 * Test various ring sizes on this device. memzones can't be 1101 * freed so are re-used if ring is released and re-created. 1102 */ 1103 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/ 1104 qp_conf.mp_session = ts_params->session_mpool; 1105 qp_conf.mp_session_private = ts_params->session_priv_mpool; 1106 1107 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1108 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1109 ts_params->valid_devs[0], qp_id, &qp_conf, 1110 rte_cryptodev_socket_id( 1111 ts_params->valid_devs[0])), 1112 "Failed test for " 1113 "rte_cryptodev_queue_pair_setup: num_inflights " 1114 "%u on qp %u on cryptodev %u", 1115 qp_conf.nb_descriptors, qp_id, 1116 ts_params->valid_devs[0]); 1117 } 1118 1119 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2); 1120 1121 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1122 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1123 ts_params->valid_devs[0], qp_id, &qp_conf, 1124 rte_cryptodev_socket_id( 1125 ts_params->valid_devs[0])), 1126 "Failed test for" 1127 " rte_cryptodev_queue_pair_setup: num_inflights" 1128 " %u on qp %u on cryptodev %u", 1129 qp_conf.nb_descriptors, qp_id, 1130 ts_params->valid_devs[0]); 1131 } 1132 1133 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */ 1134 1135 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1136 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1137 ts_params->valid_devs[0], qp_id, &qp_conf, 1138 rte_cryptodev_socket_id( 1139 ts_params->valid_devs[0])), 1140 "Failed test for " 1141 "rte_cryptodev_queue_pair_setup: num_inflights" 1142 " %u on qp %u on cryptodev %u", 1143 qp_conf.nb_descriptors, qp_id, 1144 ts_params->valid_devs[0]); 1145 } 1146 1147 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 1148 1149 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1150 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1151 ts_params->valid_devs[0], qp_id, &qp_conf, 1152 rte_cryptodev_socket_id( 1153 ts_params->valid_devs[0])), 1154 "Failed test for" 1155 " rte_cryptodev_queue_pair_setup:" 1156 "num_inflights %u on qp %u on cryptodev %u", 1157 qp_conf.nb_descriptors, qp_id, 1158 ts_params->valid_devs[0]); 1159 } 1160 1161 /* test invalid queue pair id */ 1162 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */ 1163 1164 qp_id = ts_params->conf.nb_queue_pairs; /*invalid */ 1165 1166 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1167 ts_params->valid_devs[0], 1168 qp_id, &qp_conf, 1169 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1170 "Failed test for rte_cryptodev_queue_pair_setup:" 1171 "invalid qp %u on cryptodev %u", 1172 qp_id, ts_params->valid_devs[0]); 1173 1174 qp_id = 0xffff; /*invalid*/ 1175 1176 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1177 ts_params->valid_devs[0], 1178 qp_id, &qp_conf, 1179 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1180 "Failed test for rte_cryptodev_queue_pair_setup:" 1181 "invalid qp %u on cryptodev %u", 1182 qp_id, ts_params->valid_devs[0]); 1183 1184 return TEST_SUCCESS; 1185 } 1186 1187 /* ***** Plaintext data for tests ***** */ 1188 1189 const char catch_22_quote_1[] = 1190 "There was only one catch and that was Catch-22, which " 1191 "specified that a concern for one's safety in the face of " 1192 "dangers that were real and immediate was the process of a " 1193 "rational mind. Orr was crazy and could be grounded. All he " 1194 "had to do was ask; and as soon as he did, he would no longer " 1195 "be crazy and would have to fly more missions. Orr would be " 1196 "crazy to fly more missions and sane if he didn't, but if he " 1197 "was sane he had to fly them. If he flew them he was crazy " 1198 "and didn't have to; but if he didn't want to he was sane and " 1199 "had to. Yossarian was moved very deeply by the absolute " 1200 "simplicity of this clause of Catch-22 and let out a " 1201 "respectful whistle. \"That's some catch, that Catch-22\", he " 1202 "observed. \"It's the best there is,\" Doc Daneeka agreed."; 1203 1204 const char catch_22_quote[] = 1205 "What a lousy earth! He wondered how many people were " 1206 "destitute that same night even in his own prosperous country, " 1207 "how many homes were shanties, how many husbands were drunk " 1208 "and wives socked, and how many children were bullied, abused, " 1209 "or abandoned. How many families hungered for food they could " 1210 "not afford to buy? How many hearts were broken? How many " 1211 "suicides would take place that same night, how many people " 1212 "would go insane? How many cockroaches and landlords would " 1213 "triumph? How many winners were losers, successes failures, " 1214 "and rich men poor men? How many wise guys were stupid? How " 1215 "many happy endings were unhappy endings? How many honest men " 1216 "were liars, brave men cowards, loyal men traitors, how many " 1217 "sainted men were corrupt, how many people in positions of " 1218 "trust had sold their souls to bodyguards, how many had never " 1219 "had souls? How many straight-and-narrow paths were crooked " 1220 "paths? How many best families were worst families and how " 1221 "many good people were bad people? When you added them all up " 1222 "and then subtracted, you might be left with only the children, " 1223 "and perhaps with Albert Einstein and an old violinist or " 1224 "sculptor somewhere."; 1225 1226 #define QUOTE_480_BYTES (480) 1227 #define QUOTE_512_BYTES (512) 1228 #define QUOTE_768_BYTES (768) 1229 #define QUOTE_1024_BYTES (1024) 1230 1231 1232 1233 /* ***** SHA1 Hash Tests ***** */ 1234 1235 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1) 1236 1237 static uint8_t hmac_sha1_key[] = { 1238 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 1239 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 1240 0xDE, 0xF4, 0xDE, 0xAD }; 1241 1242 /* ***** SHA224 Hash Tests ***** */ 1243 1244 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224) 1245 1246 1247 /* ***** AES-CBC Cipher Tests ***** */ 1248 1249 #define CIPHER_KEY_LENGTH_AES_CBC (16) 1250 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC) 1251 1252 static uint8_t aes_cbc_key[] = { 1253 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 1254 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A }; 1255 1256 static uint8_t aes_cbc_iv[] = { 1257 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 1258 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; 1259 1260 1261 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */ 1262 1263 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = { 1264 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, 1265 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, 1266 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, 1267 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, 1268 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E, 1269 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08, 1270 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0, 1271 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01, 1272 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57, 1273 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE, 1274 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9, 1275 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9, 1276 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D, 1277 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3, 1278 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46, 1279 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3, 1280 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80, 1281 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92, 1282 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5, 1283 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5, 1284 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2, 1285 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5, 1286 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1287 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76, 1288 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4, 1289 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62, 1290 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4, 1291 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4, 1292 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54, 1293 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61, 1294 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91, 1295 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A, 1296 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF, 1297 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F, 1298 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28, 1299 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E, 1300 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7, 1301 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76, 1302 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6, 1303 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03, 1304 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C, 1305 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2, 1306 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6, 1307 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96, 1308 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6, 1309 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA, 1310 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87, 1311 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55, 1312 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B, 1313 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98, 1314 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53, 1315 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A, 1316 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26, 1317 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36, 1318 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36, 1319 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D, 1320 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E, 1321 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E, 1322 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A, 1323 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6, 1324 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4, 1325 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7, 1326 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1, 1327 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C 1328 }; 1329 1330 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = { 1331 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60, 1332 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1333 0x18, 0x8c, 0x1d, 0x32 1334 }; 1335 1336 1337 /* Multisession Vector context Test */ 1338 /*Begin Session 0 */ 1339 static uint8_t ms_aes_cbc_key0[] = { 1340 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1341 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1342 }; 1343 1344 static uint8_t ms_aes_cbc_iv0[] = { 1345 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1346 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1347 }; 1348 1349 static const uint8_t ms_aes_cbc_cipher0[] = { 1350 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38, 1351 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC, 1352 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB, 1353 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9, 1354 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D, 1355 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4, 1356 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34, 1357 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F, 1358 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99, 1359 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED, 1360 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D, 1361 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24, 1362 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71, 1363 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72, 1364 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E, 1365 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD, 1366 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18, 1367 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6, 1368 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29, 1369 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C, 1370 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96, 1371 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26, 1372 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55, 1373 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46, 1374 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B, 1375 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4, 1376 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7, 1377 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5, 1378 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0, 1379 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E, 1380 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D, 1381 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44, 1382 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76, 1383 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3, 1384 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83, 1385 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85, 1386 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45, 1387 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25, 1388 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A, 1389 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1, 1390 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA, 1391 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3, 1392 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4, 1393 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60, 1394 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A, 1395 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A, 1396 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9, 1397 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55, 1398 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13, 1399 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B, 1400 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1, 1401 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0, 1402 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3, 1403 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23, 1404 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B, 1405 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07, 1406 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB, 1407 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1, 1408 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F, 1409 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F, 1410 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84, 1411 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B, 1412 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17, 1413 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF 1414 }; 1415 1416 1417 static uint8_t ms_hmac_key0[] = { 1418 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1419 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1420 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1421 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1422 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1423 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1424 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1425 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1426 }; 1427 1428 static const uint8_t ms_hmac_digest0[] = { 1429 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51, 1430 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F, 1431 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C, 1432 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4, 1433 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56, 1434 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4, 1435 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23, 1436 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90 1437 }; 1438 1439 /* End Session 0 */ 1440 /* Begin session 1 */ 1441 1442 static uint8_t ms_aes_cbc_key1[] = { 1443 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1444 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1445 }; 1446 1447 static uint8_t ms_aes_cbc_iv1[] = { 1448 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1449 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1450 }; 1451 1452 static const uint8_t ms_aes_cbc_cipher1[] = { 1453 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71, 1454 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23, 1455 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09, 1456 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A, 1457 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C, 1458 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F, 1459 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9, 1460 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66, 1461 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43, 1462 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB, 1463 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23, 1464 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29, 1465 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26, 1466 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F, 1467 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68, 1468 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77, 1469 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8, 1470 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97, 1471 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3, 1472 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90, 1473 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5, 1474 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E, 1475 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45, 1476 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B, 1477 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5, 1478 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D, 1479 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E, 1480 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD, 1481 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE, 1482 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1, 1483 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F, 1484 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25, 1485 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1, 1486 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3, 1487 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE, 1488 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6, 1489 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52, 1490 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA, 1491 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63, 1492 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E, 1493 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA, 1494 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB, 1495 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71, 1496 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF, 1497 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A, 1498 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95, 1499 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73, 1500 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49, 1501 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB, 1502 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B, 1503 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC, 1504 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED, 1505 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02, 1506 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4, 1507 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF, 1508 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82, 1509 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D, 1510 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6, 1511 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9, 1512 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35, 1513 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0, 1514 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53, 1515 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5, 1516 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3 1517 1518 }; 1519 1520 static uint8_t ms_hmac_key1[] = { 1521 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1522 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1523 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1524 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1525 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1526 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1527 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1528 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1529 }; 1530 1531 static const uint8_t ms_hmac_digest1[] = { 1532 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69, 1533 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50, 1534 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20, 1535 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD, 1536 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9, 1537 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4, 1538 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA, 1539 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F 1540 }; 1541 /* End Session 1 */ 1542 /* Begin Session 2 */ 1543 static uint8_t ms_aes_cbc_key2[] = { 1544 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1545 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1546 }; 1547 1548 static uint8_t ms_aes_cbc_iv2[] = { 1549 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1550 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1551 }; 1552 1553 static const uint8_t ms_aes_cbc_cipher2[] = { 1554 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91, 1555 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97, 1556 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8, 1557 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5, 1558 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98, 1559 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69, 1560 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09, 1561 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF, 1562 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44, 1563 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B, 1564 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9, 1565 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34, 1566 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99, 1567 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF, 1568 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC, 1569 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26, 1570 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3, 1571 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF, 1572 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3, 1573 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3, 1574 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA, 1575 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13, 1576 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38, 1577 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71, 1578 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC, 1579 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1, 1580 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E, 1581 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22, 1582 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62, 1583 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72, 1584 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6, 1585 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6, 1586 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44, 1587 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24, 1588 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5, 1589 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E, 1590 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17, 1591 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9, 1592 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D, 1593 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D, 1594 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22, 1595 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9, 1596 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49, 1597 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E, 1598 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B, 1599 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2, 1600 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95, 1601 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07, 1602 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3, 1603 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A, 1604 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57, 1605 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84, 1606 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61, 1607 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF, 1608 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17, 1609 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A, 1610 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1, 1611 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53, 1612 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7, 1613 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2, 1614 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A, 1615 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8, 1616 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70, 1617 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92 1618 }; 1619 1620 static uint8_t ms_hmac_key2[] = { 1621 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1622 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1623 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1624 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1625 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1626 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1627 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1628 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1629 }; 1630 1631 static const uint8_t ms_hmac_digest2[] = { 1632 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF, 1633 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6, 1634 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77, 1635 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27, 1636 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82, 1637 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24, 1638 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E, 1639 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59 1640 }; 1641 1642 /* End Session 2 */ 1643 1644 1645 static int 1646 test_AES_CBC_HMAC_SHA1_encrypt_digest(void) 1647 { 1648 struct crypto_testsuite_params *ts_params = &testsuite_params; 1649 struct crypto_unittest_params *ut_params = &unittest_params; 1650 1651 /* Verify the capabilities */ 1652 struct rte_cryptodev_sym_capability_idx cap_idx; 1653 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1654 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 1655 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 1656 &cap_idx) == NULL) 1657 return -ENOTSUP; 1658 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1659 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 1660 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 1661 &cap_idx) == NULL) 1662 return -ENOTSUP; 1663 1664 /* Generate test mbuf data and space for digest */ 1665 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 1666 catch_22_quote, QUOTE_512_BYTES, 0); 1667 1668 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 1669 DIGEST_BYTE_LENGTH_SHA1); 1670 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 1671 1672 /* Setup Cipher Parameters */ 1673 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1674 ut_params->cipher_xform.next = &ut_params->auth_xform; 1675 1676 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 1677 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 1678 ut_params->cipher_xform.cipher.key.data = aes_cbc_key; 1679 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 1680 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 1681 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 1682 1683 /* Setup HMAC Parameters */ 1684 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1685 1686 ut_params->auth_xform.next = NULL; 1687 1688 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 1689 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 1690 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; 1691 ut_params->auth_xform.auth.key.data = hmac_sha1_key; 1692 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; 1693 1694 ut_params->sess = rte_cryptodev_sym_session_create( 1695 ts_params->session_mpool); 1696 1697 /* Create crypto session*/ 1698 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 1699 ut_params->sess, &ut_params->cipher_xform, 1700 ts_params->session_priv_mpool); 1701 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 1702 1703 /* Generate crypto op data structure */ 1704 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1705 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1706 TEST_ASSERT_NOT_NULL(ut_params->op, 1707 "Failed to allocate symmetric crypto operation struct"); 1708 1709 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 1710 1711 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1712 1713 /* set crypto operation source mbuf */ 1714 sym_op->m_src = ut_params->ibuf; 1715 1716 /* Set crypto operation authentication parameters */ 1717 sym_op->auth.digest.data = ut_params->digest; 1718 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 1719 ut_params->ibuf, QUOTE_512_BYTES); 1720 1721 sym_op->auth.data.offset = 0; 1722 sym_op->auth.data.length = QUOTE_512_BYTES; 1723 1724 /* Copy IV at the end of the crypto operation */ 1725 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 1726 aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC); 1727 1728 /* Set crypto operation cipher parameters */ 1729 sym_op->cipher.data.offset = 0; 1730 sym_op->cipher.data.length = QUOTE_512_BYTES; 1731 1732 /* Process crypto operation */ 1733 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 1734 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 1735 ut_params->op); 1736 else 1737 TEST_ASSERT_NOT_NULL( 1738 process_crypto_request(ts_params->valid_devs[0], 1739 ut_params->op), 1740 "failed to process sym crypto op"); 1741 1742 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1743 "crypto op processing failed"); 1744 1745 /* Validate obuf */ 1746 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 1747 uint8_t *); 1748 1749 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, 1750 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 1751 QUOTE_512_BYTES, 1752 "ciphertext data not as expected"); 1753 1754 uint8_t *digest = ciphertext + QUOTE_512_BYTES; 1755 1756 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, 1757 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, 1758 gbl_driver_id == rte_cryptodev_driver_id_get( 1759 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ? 1760 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : 1761 DIGEST_BYTE_LENGTH_SHA1, 1762 "Generated digest data not as expected"); 1763 1764 return TEST_SUCCESS; 1765 } 1766 1767 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ 1768 1769 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) 1770 1771 static uint8_t hmac_sha512_key[] = { 1772 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1773 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1774 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1775 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60, 1776 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1, 1777 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1778 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76, 1779 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 }; 1780 1781 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = { 1782 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8, 1783 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48, 1784 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8, 1785 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70, 1786 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8, 1787 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E, 1788 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D, 1789 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A }; 1790 1791 1792 1793 static int 1794 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 1795 struct crypto_unittest_params *ut_params, 1796 uint8_t *cipher_key, 1797 uint8_t *hmac_key); 1798 1799 static int 1800 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 1801 struct crypto_unittest_params *ut_params, 1802 struct crypto_testsuite_params *ts_params, 1803 const uint8_t *cipher, 1804 const uint8_t *digest, 1805 const uint8_t *iv); 1806 1807 1808 static int 1809 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 1810 struct crypto_unittest_params *ut_params, 1811 uint8_t *cipher_key, 1812 uint8_t *hmac_key) 1813 { 1814 1815 /* Setup Cipher Parameters */ 1816 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1817 ut_params->cipher_xform.next = NULL; 1818 1819 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 1820 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 1821 ut_params->cipher_xform.cipher.key.data = cipher_key; 1822 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 1823 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 1824 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 1825 1826 /* Setup HMAC Parameters */ 1827 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1828 ut_params->auth_xform.next = &ut_params->cipher_xform; 1829 1830 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 1831 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC; 1832 ut_params->auth_xform.auth.key.data = hmac_key; 1833 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512; 1834 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512; 1835 1836 return TEST_SUCCESS; 1837 } 1838 1839 1840 static int 1841 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 1842 struct crypto_unittest_params *ut_params, 1843 struct crypto_testsuite_params *ts_params, 1844 const uint8_t *cipher, 1845 const uint8_t *digest, 1846 const uint8_t *iv) 1847 { 1848 /* Generate test mbuf data and digest */ 1849 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 1850 (const char *) 1851 cipher, 1852 QUOTE_512_BYTES, 0); 1853 1854 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 1855 DIGEST_BYTE_LENGTH_SHA512); 1856 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 1857 1858 rte_memcpy(ut_params->digest, 1859 digest, 1860 DIGEST_BYTE_LENGTH_SHA512); 1861 1862 /* Generate Crypto op data structure */ 1863 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1864 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1865 TEST_ASSERT_NOT_NULL(ut_params->op, 1866 "Failed to allocate symmetric crypto operation struct"); 1867 1868 rte_crypto_op_attach_sym_session(ut_params->op, sess); 1869 1870 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1871 1872 /* set crypto operation source mbuf */ 1873 sym_op->m_src = ut_params->ibuf; 1874 1875 sym_op->auth.digest.data = ut_params->digest; 1876 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 1877 ut_params->ibuf, QUOTE_512_BYTES); 1878 1879 sym_op->auth.data.offset = 0; 1880 sym_op->auth.data.length = QUOTE_512_BYTES; 1881 1882 /* Copy IV at the end of the crypto operation */ 1883 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 1884 iv, CIPHER_IV_LENGTH_AES_CBC); 1885 1886 sym_op->cipher.data.offset = 0; 1887 sym_op->cipher.data.length = QUOTE_512_BYTES; 1888 1889 /* Process crypto operation */ 1890 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 1891 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 1892 ut_params->op); 1893 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 1894 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 1895 ut_params->op, 1, 1, 0, 0); 1896 else 1897 TEST_ASSERT_NOT_NULL( 1898 process_crypto_request(ts_params->valid_devs[0], 1899 ut_params->op), 1900 "failed to process sym crypto op"); 1901 1902 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1903 "crypto op processing failed"); 1904 1905 ut_params->obuf = ut_params->op->sym->m_src; 1906 1907 /* Validate obuf */ 1908 TEST_ASSERT_BUFFERS_ARE_EQUAL( 1909 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 1910 catch_22_quote, 1911 QUOTE_512_BYTES, 1912 "Plaintext data not as expected"); 1913 1914 /* Validate obuf */ 1915 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1916 "Digest verification failed"); 1917 1918 return TEST_SUCCESS; 1919 } 1920 1921 static int 1922 test_blockcipher(enum blockcipher_test_type test_type) 1923 { 1924 struct crypto_testsuite_params *ts_params = &testsuite_params; 1925 int status; 1926 1927 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1928 ts_params->op_mpool, 1929 ts_params->session_mpool, ts_params->session_priv_mpool, 1930 ts_params->valid_devs[0], 1931 test_type); 1932 1933 if (status == -ENOTSUP) 1934 return status; 1935 1936 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1937 1938 return TEST_SUCCESS; 1939 } 1940 1941 static int 1942 test_AES_cipheronly_all(void) 1943 { 1944 return test_blockcipher(BLKCIPHER_AES_CIPHERONLY_TYPE); 1945 } 1946 1947 static int 1948 test_AES_docsis_all(void) 1949 { 1950 /* Data-path service does not support DOCSIS yet */ 1951 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 1952 return -ENOTSUP; 1953 return test_blockcipher(BLKCIPHER_AES_DOCSIS_TYPE); 1954 } 1955 1956 static int 1957 test_DES_docsis_all(void) 1958 { 1959 /* Data-path service does not support DOCSIS yet */ 1960 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 1961 return -ENOTSUP; 1962 return test_blockcipher(BLKCIPHER_DES_DOCSIS_TYPE); 1963 } 1964 1965 static int 1966 test_DES_cipheronly_all(void) 1967 { 1968 return test_blockcipher(BLKCIPHER_DES_CIPHERONLY_TYPE); 1969 } 1970 1971 static int 1972 test_authonly_all(void) 1973 { 1974 return test_blockcipher(BLKCIPHER_AUTHONLY_TYPE); 1975 } 1976 1977 static int 1978 test_AES_chain_all(void) 1979 { 1980 return test_blockcipher(BLKCIPHER_AES_CHAIN_TYPE); 1981 } 1982 1983 static int 1984 test_3DES_chain_all(void) 1985 { 1986 return test_blockcipher(BLKCIPHER_3DES_CHAIN_TYPE); 1987 } 1988 1989 static int 1990 test_3DES_cipheronly_all(void) 1991 { 1992 return test_blockcipher(BLKCIPHER_3DES_CIPHERONLY_TYPE); 1993 } 1994 1995 /* ***** SNOW 3G Tests ***** */ 1996 static int 1997 create_wireless_algo_hash_session(uint8_t dev_id, 1998 const uint8_t *key, const uint8_t key_len, 1999 const uint8_t iv_len, const uint8_t auth_len, 2000 enum rte_crypto_auth_operation op, 2001 enum rte_crypto_auth_algorithm algo) 2002 { 2003 uint8_t hash_key[key_len]; 2004 int status; 2005 2006 struct crypto_testsuite_params *ts_params = &testsuite_params; 2007 struct crypto_unittest_params *ut_params = &unittest_params; 2008 2009 memcpy(hash_key, key, key_len); 2010 2011 debug_hexdump(stdout, "key:", key, key_len); 2012 2013 /* Setup Authentication Parameters */ 2014 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2015 ut_params->auth_xform.next = NULL; 2016 2017 ut_params->auth_xform.auth.op = op; 2018 ut_params->auth_xform.auth.algo = algo; 2019 ut_params->auth_xform.auth.key.length = key_len; 2020 ut_params->auth_xform.auth.key.data = hash_key; 2021 ut_params->auth_xform.auth.digest_length = auth_len; 2022 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 2023 ut_params->auth_xform.auth.iv.length = iv_len; 2024 ut_params->sess = rte_cryptodev_sym_session_create( 2025 ts_params->session_mpool); 2026 2027 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2028 &ut_params->auth_xform, 2029 ts_params->session_priv_mpool); 2030 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2031 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2032 return 0; 2033 } 2034 2035 static int 2036 create_wireless_algo_cipher_session(uint8_t dev_id, 2037 enum rte_crypto_cipher_operation op, 2038 enum rte_crypto_cipher_algorithm algo, 2039 const uint8_t *key, const uint8_t key_len, 2040 uint8_t iv_len) 2041 { 2042 uint8_t cipher_key[key_len]; 2043 int status; 2044 struct crypto_testsuite_params *ts_params = &testsuite_params; 2045 struct crypto_unittest_params *ut_params = &unittest_params; 2046 2047 memcpy(cipher_key, key, key_len); 2048 2049 /* Setup Cipher Parameters */ 2050 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2051 ut_params->cipher_xform.next = NULL; 2052 2053 ut_params->cipher_xform.cipher.algo = algo; 2054 ut_params->cipher_xform.cipher.op = op; 2055 ut_params->cipher_xform.cipher.key.data = cipher_key; 2056 ut_params->cipher_xform.cipher.key.length = key_len; 2057 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2058 ut_params->cipher_xform.cipher.iv.length = iv_len; 2059 2060 debug_hexdump(stdout, "key:", key, key_len); 2061 2062 /* Create Crypto session */ 2063 ut_params->sess = rte_cryptodev_sym_session_create( 2064 ts_params->session_mpool); 2065 2066 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2067 &ut_params->cipher_xform, 2068 ts_params->session_priv_mpool); 2069 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2070 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2071 return 0; 2072 } 2073 2074 static int 2075 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len, 2076 unsigned int cipher_len, 2077 unsigned int cipher_offset) 2078 { 2079 struct crypto_testsuite_params *ts_params = &testsuite_params; 2080 struct crypto_unittest_params *ut_params = &unittest_params; 2081 2082 /* Generate Crypto op data structure */ 2083 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2084 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2085 TEST_ASSERT_NOT_NULL(ut_params->op, 2086 "Failed to allocate pktmbuf offload"); 2087 2088 /* Set crypto operation data parameters */ 2089 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2090 2091 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2092 2093 /* set crypto operation source mbuf */ 2094 sym_op->m_src = ut_params->ibuf; 2095 2096 /* iv */ 2097 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2098 iv, iv_len); 2099 sym_op->cipher.data.length = cipher_len; 2100 sym_op->cipher.data.offset = cipher_offset; 2101 return 0; 2102 } 2103 2104 static int 2105 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len, 2106 unsigned int cipher_len, 2107 unsigned int cipher_offset) 2108 { 2109 struct crypto_testsuite_params *ts_params = &testsuite_params; 2110 struct crypto_unittest_params *ut_params = &unittest_params; 2111 2112 /* Generate Crypto op data structure */ 2113 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2114 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2115 TEST_ASSERT_NOT_NULL(ut_params->op, 2116 "Failed to allocate pktmbuf offload"); 2117 2118 /* Set crypto operation data parameters */ 2119 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2120 2121 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2122 2123 /* set crypto operation source mbuf */ 2124 sym_op->m_src = ut_params->ibuf; 2125 sym_op->m_dst = ut_params->obuf; 2126 2127 /* iv */ 2128 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2129 iv, iv_len); 2130 sym_op->cipher.data.length = cipher_len; 2131 sym_op->cipher.data.offset = cipher_offset; 2132 return 0; 2133 } 2134 2135 static int 2136 create_wireless_algo_cipher_auth_session(uint8_t dev_id, 2137 enum rte_crypto_cipher_operation cipher_op, 2138 enum rte_crypto_auth_operation auth_op, 2139 enum rte_crypto_auth_algorithm auth_algo, 2140 enum rte_crypto_cipher_algorithm cipher_algo, 2141 const uint8_t *key, uint8_t key_len, 2142 uint8_t auth_iv_len, uint8_t auth_len, 2143 uint8_t cipher_iv_len) 2144 2145 { 2146 uint8_t cipher_auth_key[key_len]; 2147 int status; 2148 2149 struct crypto_testsuite_params *ts_params = &testsuite_params; 2150 struct crypto_unittest_params *ut_params = &unittest_params; 2151 2152 memcpy(cipher_auth_key, key, key_len); 2153 2154 /* Setup Authentication Parameters */ 2155 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2156 ut_params->auth_xform.next = NULL; 2157 2158 ut_params->auth_xform.auth.op = auth_op; 2159 ut_params->auth_xform.auth.algo = auth_algo; 2160 ut_params->auth_xform.auth.key.length = key_len; 2161 /* Hash key = cipher key */ 2162 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2163 ut_params->auth_xform.auth.digest_length = auth_len; 2164 /* Auth IV will be after cipher IV */ 2165 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2166 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2167 2168 /* Setup Cipher Parameters */ 2169 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2170 ut_params->cipher_xform.next = &ut_params->auth_xform; 2171 2172 ut_params->cipher_xform.cipher.algo = cipher_algo; 2173 ut_params->cipher_xform.cipher.op = cipher_op; 2174 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2175 ut_params->cipher_xform.cipher.key.length = key_len; 2176 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2177 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2178 2179 debug_hexdump(stdout, "key:", key, key_len); 2180 2181 /* Create Crypto session*/ 2182 ut_params->sess = rte_cryptodev_sym_session_create( 2183 ts_params->session_mpool); 2184 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2185 2186 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2187 &ut_params->cipher_xform, 2188 ts_params->session_priv_mpool); 2189 if (status == -ENOTSUP) 2190 return status; 2191 2192 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2193 return 0; 2194 } 2195 2196 static int 2197 create_wireless_cipher_auth_session(uint8_t dev_id, 2198 enum rte_crypto_cipher_operation cipher_op, 2199 enum rte_crypto_auth_operation auth_op, 2200 enum rte_crypto_auth_algorithm auth_algo, 2201 enum rte_crypto_cipher_algorithm cipher_algo, 2202 const struct wireless_test_data *tdata) 2203 { 2204 const uint8_t key_len = tdata->key.len; 2205 uint8_t cipher_auth_key[key_len]; 2206 int status; 2207 2208 struct crypto_testsuite_params *ts_params = &testsuite_params; 2209 struct crypto_unittest_params *ut_params = &unittest_params; 2210 const uint8_t *key = tdata->key.data; 2211 const uint8_t auth_len = tdata->digest.len; 2212 uint8_t cipher_iv_len = tdata->cipher_iv.len; 2213 uint8_t auth_iv_len = tdata->auth_iv.len; 2214 2215 memcpy(cipher_auth_key, key, key_len); 2216 2217 /* Setup Authentication Parameters */ 2218 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2219 ut_params->auth_xform.next = NULL; 2220 2221 ut_params->auth_xform.auth.op = auth_op; 2222 ut_params->auth_xform.auth.algo = auth_algo; 2223 ut_params->auth_xform.auth.key.length = key_len; 2224 /* Hash key = cipher key */ 2225 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2226 ut_params->auth_xform.auth.digest_length = auth_len; 2227 /* Auth IV will be after cipher IV */ 2228 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2229 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2230 2231 /* Setup Cipher Parameters */ 2232 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2233 ut_params->cipher_xform.next = &ut_params->auth_xform; 2234 2235 ut_params->cipher_xform.cipher.algo = cipher_algo; 2236 ut_params->cipher_xform.cipher.op = cipher_op; 2237 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2238 ut_params->cipher_xform.cipher.key.length = key_len; 2239 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2240 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2241 2242 2243 debug_hexdump(stdout, "key:", key, key_len); 2244 2245 /* Create Crypto session*/ 2246 ut_params->sess = rte_cryptodev_sym_session_create( 2247 ts_params->session_mpool); 2248 2249 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2250 &ut_params->cipher_xform, 2251 ts_params->session_priv_mpool); 2252 if (status == -ENOTSUP) 2253 return status; 2254 2255 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2256 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2257 return 0; 2258 } 2259 2260 static int 2261 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id, 2262 const struct wireless_test_data *tdata) 2263 { 2264 return create_wireless_cipher_auth_session(dev_id, 2265 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2266 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3, 2267 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata); 2268 } 2269 2270 static int 2271 create_wireless_algo_auth_cipher_session(uint8_t dev_id, 2272 enum rte_crypto_cipher_operation cipher_op, 2273 enum rte_crypto_auth_operation auth_op, 2274 enum rte_crypto_auth_algorithm auth_algo, 2275 enum rte_crypto_cipher_algorithm cipher_algo, 2276 const uint8_t *key, const uint8_t key_len, 2277 uint8_t auth_iv_len, uint8_t auth_len, 2278 uint8_t cipher_iv_len) 2279 { 2280 uint8_t auth_cipher_key[key_len]; 2281 int status; 2282 struct crypto_testsuite_params *ts_params = &testsuite_params; 2283 struct crypto_unittest_params *ut_params = &unittest_params; 2284 2285 memcpy(auth_cipher_key, key, key_len); 2286 2287 /* Setup Authentication Parameters */ 2288 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2289 ut_params->auth_xform.auth.op = auth_op; 2290 ut_params->auth_xform.next = &ut_params->cipher_xform; 2291 ut_params->auth_xform.auth.algo = auth_algo; 2292 ut_params->auth_xform.auth.key.length = key_len; 2293 ut_params->auth_xform.auth.key.data = auth_cipher_key; 2294 ut_params->auth_xform.auth.digest_length = auth_len; 2295 /* Auth IV will be after cipher IV */ 2296 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2297 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2298 2299 /* Setup Cipher Parameters */ 2300 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2301 ut_params->cipher_xform.next = NULL; 2302 ut_params->cipher_xform.cipher.algo = cipher_algo; 2303 ut_params->cipher_xform.cipher.op = cipher_op; 2304 ut_params->cipher_xform.cipher.key.data = auth_cipher_key; 2305 ut_params->cipher_xform.cipher.key.length = key_len; 2306 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2307 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2308 2309 debug_hexdump(stdout, "key:", key, key_len); 2310 2311 /* Create Crypto session*/ 2312 ut_params->sess = rte_cryptodev_sym_session_create( 2313 ts_params->session_mpool); 2314 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2315 2316 if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 2317 ut_params->auth_xform.next = NULL; 2318 ut_params->cipher_xform.next = &ut_params->auth_xform; 2319 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2320 &ut_params->cipher_xform, 2321 ts_params->session_priv_mpool); 2322 2323 } else 2324 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2325 &ut_params->auth_xform, 2326 ts_params->session_priv_mpool); 2327 2328 if (status == -ENOTSUP) 2329 return status; 2330 2331 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2332 2333 return 0; 2334 } 2335 2336 static int 2337 create_wireless_algo_hash_operation(const uint8_t *auth_tag, 2338 unsigned int auth_tag_len, 2339 const uint8_t *iv, unsigned int iv_len, 2340 unsigned int data_pad_len, 2341 enum rte_crypto_auth_operation op, 2342 unsigned int auth_len, unsigned int auth_offset) 2343 { 2344 struct crypto_testsuite_params *ts_params = &testsuite_params; 2345 2346 struct crypto_unittest_params *ut_params = &unittest_params; 2347 2348 /* Generate Crypto op data structure */ 2349 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2350 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2351 TEST_ASSERT_NOT_NULL(ut_params->op, 2352 "Failed to allocate pktmbuf offload"); 2353 2354 /* Set crypto operation data parameters */ 2355 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2356 2357 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2358 2359 /* set crypto operation source mbuf */ 2360 sym_op->m_src = ut_params->ibuf; 2361 2362 /* iv */ 2363 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2364 iv, iv_len); 2365 /* digest */ 2366 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2367 ut_params->ibuf, auth_tag_len); 2368 2369 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2370 "no room to append auth tag"); 2371 ut_params->digest = sym_op->auth.digest.data; 2372 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2373 ut_params->ibuf, data_pad_len); 2374 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2375 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2376 else 2377 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2378 2379 debug_hexdump(stdout, "digest:", 2380 sym_op->auth.digest.data, 2381 auth_tag_len); 2382 2383 sym_op->auth.data.length = auth_len; 2384 sym_op->auth.data.offset = auth_offset; 2385 2386 return 0; 2387 } 2388 2389 static int 2390 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata, 2391 enum rte_crypto_auth_operation op) 2392 { 2393 struct crypto_testsuite_params *ts_params = &testsuite_params; 2394 struct crypto_unittest_params *ut_params = &unittest_params; 2395 2396 const uint8_t *auth_tag = tdata->digest.data; 2397 const unsigned int auth_tag_len = tdata->digest.len; 2398 unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len); 2399 unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2400 2401 const uint8_t *cipher_iv = tdata->cipher_iv.data; 2402 const uint8_t cipher_iv_len = tdata->cipher_iv.len; 2403 const uint8_t *auth_iv = tdata->auth_iv.data; 2404 const uint8_t auth_iv_len = tdata->auth_iv.len; 2405 const unsigned int cipher_len = tdata->validCipherLenInBits.len; 2406 const unsigned int auth_len = tdata->validAuthLenInBits.len; 2407 2408 /* Generate Crypto op data structure */ 2409 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2410 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2411 TEST_ASSERT_NOT_NULL(ut_params->op, 2412 "Failed to allocate pktmbuf offload"); 2413 /* Set crypto operation data parameters */ 2414 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2415 2416 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2417 2418 /* set crypto operation source mbuf */ 2419 sym_op->m_src = ut_params->ibuf; 2420 2421 /* digest */ 2422 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2423 ut_params->ibuf, auth_tag_len); 2424 2425 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2426 "no room to append auth tag"); 2427 ut_params->digest = sym_op->auth.digest.data; 2428 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2429 ut_params->ibuf, data_pad_len); 2430 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2431 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2432 else 2433 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2434 2435 debug_hexdump(stdout, "digest:", 2436 sym_op->auth.digest.data, 2437 auth_tag_len); 2438 2439 /* Copy cipher and auth IVs at the end of the crypto operation */ 2440 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2441 IV_OFFSET); 2442 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2443 iv_ptr += cipher_iv_len; 2444 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2445 2446 sym_op->cipher.data.length = cipher_len; 2447 sym_op->cipher.data.offset = 0; 2448 sym_op->auth.data.length = auth_len; 2449 sym_op->auth.data.offset = 0; 2450 2451 return 0; 2452 } 2453 2454 static int 2455 create_zuc_cipher_hash_generate_operation( 2456 const struct wireless_test_data *tdata) 2457 { 2458 return create_wireless_cipher_hash_operation(tdata, 2459 RTE_CRYPTO_AUTH_OP_GENERATE); 2460 } 2461 2462 static int 2463 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag, 2464 const unsigned auth_tag_len, 2465 const uint8_t *auth_iv, uint8_t auth_iv_len, 2466 unsigned data_pad_len, 2467 enum rte_crypto_auth_operation op, 2468 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2469 const unsigned cipher_len, const unsigned cipher_offset, 2470 const unsigned auth_len, const unsigned auth_offset) 2471 { 2472 struct crypto_testsuite_params *ts_params = &testsuite_params; 2473 struct crypto_unittest_params *ut_params = &unittest_params; 2474 2475 enum rte_crypto_cipher_algorithm cipher_algo = 2476 ut_params->cipher_xform.cipher.algo; 2477 enum rte_crypto_auth_algorithm auth_algo = 2478 ut_params->auth_xform.auth.algo; 2479 2480 /* Generate Crypto op data structure */ 2481 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2482 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2483 TEST_ASSERT_NOT_NULL(ut_params->op, 2484 "Failed to allocate pktmbuf offload"); 2485 /* Set crypto operation data parameters */ 2486 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2487 2488 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2489 2490 /* set crypto operation source mbuf */ 2491 sym_op->m_src = ut_params->ibuf; 2492 2493 /* digest */ 2494 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2495 ut_params->ibuf, auth_tag_len); 2496 2497 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2498 "no room to append auth tag"); 2499 ut_params->digest = sym_op->auth.digest.data; 2500 2501 if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) { 2502 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2503 ut_params->ibuf, data_pad_len); 2504 } else { 2505 struct rte_mbuf *m = ut_params->ibuf; 2506 unsigned int offset = data_pad_len; 2507 2508 while (offset > m->data_len && m->next != NULL) { 2509 offset -= m->data_len; 2510 m = m->next; 2511 } 2512 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2513 m, offset); 2514 } 2515 2516 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2517 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2518 else 2519 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2520 2521 debug_hexdump(stdout, "digest:", 2522 sym_op->auth.digest.data, 2523 auth_tag_len); 2524 2525 /* Copy cipher and auth IVs at the end of the crypto operation */ 2526 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2527 IV_OFFSET); 2528 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2529 iv_ptr += cipher_iv_len; 2530 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2531 2532 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 2533 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 2534 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 2535 sym_op->cipher.data.length = cipher_len; 2536 sym_op->cipher.data.offset = cipher_offset; 2537 } else { 2538 sym_op->cipher.data.length = cipher_len >> 3; 2539 sym_op->cipher.data.offset = cipher_offset >> 3; 2540 } 2541 2542 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 2543 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 2544 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 2545 sym_op->auth.data.length = auth_len; 2546 sym_op->auth.data.offset = auth_offset; 2547 } else { 2548 sym_op->auth.data.length = auth_len >> 3; 2549 sym_op->auth.data.offset = auth_offset >> 3; 2550 } 2551 2552 return 0; 2553 } 2554 2555 static int 2556 create_wireless_algo_auth_cipher_operation( 2557 const uint8_t *auth_tag, unsigned int auth_tag_len, 2558 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2559 const uint8_t *auth_iv, uint8_t auth_iv_len, 2560 unsigned int data_pad_len, 2561 unsigned int cipher_len, unsigned int cipher_offset, 2562 unsigned int auth_len, unsigned int auth_offset, 2563 uint8_t op_mode, uint8_t do_sgl, uint8_t verify) 2564 { 2565 struct crypto_testsuite_params *ts_params = &testsuite_params; 2566 struct crypto_unittest_params *ut_params = &unittest_params; 2567 2568 enum rte_crypto_cipher_algorithm cipher_algo = 2569 ut_params->cipher_xform.cipher.algo; 2570 enum rte_crypto_auth_algorithm auth_algo = 2571 ut_params->auth_xform.auth.algo; 2572 2573 /* Generate Crypto op data structure */ 2574 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2575 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2576 TEST_ASSERT_NOT_NULL(ut_params->op, 2577 "Failed to allocate pktmbuf offload"); 2578 2579 /* Set crypto operation data parameters */ 2580 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2581 2582 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2583 2584 /* set crypto operation mbufs */ 2585 sym_op->m_src = ut_params->ibuf; 2586 if (op_mode == OUT_OF_PLACE) 2587 sym_op->m_dst = ut_params->obuf; 2588 2589 /* digest */ 2590 if (!do_sgl) { 2591 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset( 2592 (op_mode == IN_PLACE ? 2593 ut_params->ibuf : ut_params->obuf), 2594 uint8_t *, data_pad_len); 2595 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2596 (op_mode == IN_PLACE ? 2597 ut_params->ibuf : ut_params->obuf), 2598 data_pad_len); 2599 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2600 } else { 2601 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3); 2602 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ? 2603 sym_op->m_src : sym_op->m_dst); 2604 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) { 2605 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 2606 sgl_buf = sgl_buf->next; 2607 } 2608 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf, 2609 uint8_t *, remaining_off); 2610 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf, 2611 remaining_off); 2612 memset(sym_op->auth.digest.data, 0, remaining_off); 2613 while (sgl_buf->next != NULL) { 2614 memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *), 2615 0, rte_pktmbuf_data_len(sgl_buf)); 2616 sgl_buf = sgl_buf->next; 2617 } 2618 } 2619 2620 /* Copy digest for the verification */ 2621 if (verify) 2622 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2623 2624 /* Copy cipher and auth IVs at the end of the crypto operation */ 2625 uint8_t *iv_ptr = rte_crypto_op_ctod_offset( 2626 ut_params->op, uint8_t *, IV_OFFSET); 2627 2628 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2629 iv_ptr += cipher_iv_len; 2630 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2631 2632 /* Only copy over the offset data needed from src to dst in OOP, 2633 * if the auth and cipher offsets are not aligned 2634 */ 2635 if (op_mode == OUT_OF_PLACE) { 2636 if (cipher_offset > auth_offset) 2637 rte_memcpy( 2638 rte_pktmbuf_mtod_offset( 2639 sym_op->m_dst, 2640 uint8_t *, auth_offset >> 3), 2641 rte_pktmbuf_mtod_offset( 2642 sym_op->m_src, 2643 uint8_t *, auth_offset >> 3), 2644 ((cipher_offset >> 3) - (auth_offset >> 3))); 2645 } 2646 2647 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 2648 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 2649 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 2650 sym_op->cipher.data.length = cipher_len; 2651 sym_op->cipher.data.offset = cipher_offset; 2652 } else { 2653 sym_op->cipher.data.length = cipher_len >> 3; 2654 sym_op->cipher.data.offset = cipher_offset >> 3; 2655 } 2656 2657 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 2658 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 2659 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 2660 sym_op->auth.data.length = auth_len; 2661 sym_op->auth.data.offset = auth_offset; 2662 } else { 2663 sym_op->auth.data.length = auth_len >> 3; 2664 sym_op->auth.data.offset = auth_offset >> 3; 2665 } 2666 2667 return 0; 2668 } 2669 2670 static int 2671 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) 2672 { 2673 struct crypto_testsuite_params *ts_params = &testsuite_params; 2674 struct crypto_unittest_params *ut_params = &unittest_params; 2675 2676 int retval; 2677 unsigned plaintext_pad_len; 2678 unsigned plaintext_len; 2679 uint8_t *plaintext; 2680 struct rte_cryptodev_info dev_info; 2681 2682 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2683 uint64_t feat_flags = dev_info.feature_flags; 2684 2685 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 2686 ((tdata->validAuthLenInBits.len % 8) != 0)) { 2687 printf("Device doesn't support NON-Byte Aligned Data.\n"); 2688 return -ENOTSUP; 2689 } 2690 2691 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 2692 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 2693 printf("Device doesn't support RAW data-path APIs.\n"); 2694 return -ENOTSUP; 2695 } 2696 2697 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2698 return -ENOTSUP; 2699 2700 /* Verify the capabilities */ 2701 struct rte_cryptodev_sym_capability_idx cap_idx; 2702 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2703 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 2704 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2705 &cap_idx) == NULL) 2706 return -ENOTSUP; 2707 2708 /* Create SNOW 3G session */ 2709 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2710 tdata->key.data, tdata->key.len, 2711 tdata->auth_iv.len, tdata->digest.len, 2712 RTE_CRYPTO_AUTH_OP_GENERATE, 2713 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 2714 if (retval < 0) 2715 return retval; 2716 2717 /* alloc mbuf and set payload */ 2718 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2719 2720 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2721 rte_pktmbuf_tailroom(ut_params->ibuf)); 2722 2723 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2724 /* Append data which is padded to a multiple of */ 2725 /* the algorithms block size */ 2726 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2727 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2728 plaintext_pad_len); 2729 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2730 2731 /* Create SNOW 3G operation */ 2732 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 2733 tdata->auth_iv.data, tdata->auth_iv.len, 2734 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 2735 tdata->validAuthLenInBits.len, 2736 0); 2737 if (retval < 0) 2738 return retval; 2739 2740 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2741 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2742 ut_params->op, 0, 1, 1, 0); 2743 else 2744 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2745 ut_params->op); 2746 ut_params->obuf = ut_params->op->sym->m_src; 2747 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2748 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2749 + plaintext_pad_len; 2750 2751 /* Validate obuf */ 2752 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2753 ut_params->digest, 2754 tdata->digest.data, 2755 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 2756 "SNOW 3G Generated auth tag not as expected"); 2757 2758 return 0; 2759 } 2760 2761 static int 2762 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) 2763 { 2764 struct crypto_testsuite_params *ts_params = &testsuite_params; 2765 struct crypto_unittest_params *ut_params = &unittest_params; 2766 2767 int retval; 2768 unsigned plaintext_pad_len; 2769 unsigned plaintext_len; 2770 uint8_t *plaintext; 2771 struct rte_cryptodev_info dev_info; 2772 2773 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2774 uint64_t feat_flags = dev_info.feature_flags; 2775 2776 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 2777 ((tdata->validAuthLenInBits.len % 8) != 0)) { 2778 printf("Device doesn't support NON-Byte Aligned Data.\n"); 2779 return -ENOTSUP; 2780 } 2781 2782 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 2783 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 2784 printf("Device doesn't support RAW data-path APIs.\n"); 2785 return -ENOTSUP; 2786 } 2787 2788 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2789 return -ENOTSUP; 2790 2791 /* Verify the capabilities */ 2792 struct rte_cryptodev_sym_capability_idx cap_idx; 2793 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2794 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 2795 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2796 &cap_idx) == NULL) 2797 return -ENOTSUP; 2798 2799 /* Create SNOW 3G session */ 2800 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2801 tdata->key.data, tdata->key.len, 2802 tdata->auth_iv.len, tdata->digest.len, 2803 RTE_CRYPTO_AUTH_OP_VERIFY, 2804 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 2805 if (retval < 0) 2806 return retval; 2807 /* alloc mbuf and set payload */ 2808 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2809 2810 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2811 rte_pktmbuf_tailroom(ut_params->ibuf)); 2812 2813 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2814 /* Append data which is padded to a multiple of */ 2815 /* the algorithms block size */ 2816 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2817 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2818 plaintext_pad_len); 2819 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2820 2821 /* Create SNOW 3G operation */ 2822 retval = create_wireless_algo_hash_operation(tdata->digest.data, 2823 tdata->digest.len, 2824 tdata->auth_iv.data, tdata->auth_iv.len, 2825 plaintext_pad_len, 2826 RTE_CRYPTO_AUTH_OP_VERIFY, 2827 tdata->validAuthLenInBits.len, 2828 0); 2829 if (retval < 0) 2830 return retval; 2831 2832 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2833 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2834 ut_params->op, 0, 1, 1, 0); 2835 else 2836 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2837 ut_params->op); 2838 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2839 ut_params->obuf = ut_params->op->sym->m_src; 2840 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2841 + plaintext_pad_len; 2842 2843 /* Validate obuf */ 2844 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 2845 return 0; 2846 else 2847 return -1; 2848 2849 return 0; 2850 } 2851 2852 static int 2853 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata) 2854 { 2855 struct crypto_testsuite_params *ts_params = &testsuite_params; 2856 struct crypto_unittest_params *ut_params = &unittest_params; 2857 2858 int retval; 2859 unsigned plaintext_pad_len; 2860 unsigned plaintext_len; 2861 uint8_t *plaintext; 2862 struct rte_cryptodev_info dev_info; 2863 2864 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2865 uint64_t feat_flags = dev_info.feature_flags; 2866 2867 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 2868 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 2869 printf("Device doesn't support RAW data-path APIs.\n"); 2870 return -ENOTSUP; 2871 } 2872 2873 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2874 return -ENOTSUP; 2875 2876 /* Verify the capabilities */ 2877 struct rte_cryptodev_sym_capability_idx cap_idx; 2878 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2879 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 2880 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2881 &cap_idx) == NULL) 2882 return -ENOTSUP; 2883 2884 /* Create KASUMI session */ 2885 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2886 tdata->key.data, tdata->key.len, 2887 0, tdata->digest.len, 2888 RTE_CRYPTO_AUTH_OP_GENERATE, 2889 RTE_CRYPTO_AUTH_KASUMI_F9); 2890 if (retval < 0) 2891 return retval; 2892 2893 /* alloc mbuf and set payload */ 2894 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2895 2896 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2897 rte_pktmbuf_tailroom(ut_params->ibuf)); 2898 2899 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2900 /* Append data which is padded to a multiple of */ 2901 /* the algorithms block size */ 2902 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2903 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2904 plaintext_pad_len); 2905 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2906 2907 /* Create KASUMI operation */ 2908 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 2909 NULL, 0, 2910 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 2911 tdata->plaintext.len, 2912 0); 2913 if (retval < 0) 2914 return retval; 2915 2916 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2917 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2918 ut_params->op); 2919 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2920 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2921 ut_params->op, 0, 1, 1, 0); 2922 else 2923 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2924 ut_params->op); 2925 2926 ut_params->obuf = ut_params->op->sym->m_src; 2927 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2928 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2929 + plaintext_pad_len; 2930 2931 /* Validate obuf */ 2932 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2933 ut_params->digest, 2934 tdata->digest.data, 2935 DIGEST_BYTE_LENGTH_KASUMI_F9, 2936 "KASUMI Generated auth tag not as expected"); 2937 2938 return 0; 2939 } 2940 2941 static int 2942 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata) 2943 { 2944 struct crypto_testsuite_params *ts_params = &testsuite_params; 2945 struct crypto_unittest_params *ut_params = &unittest_params; 2946 2947 int retval; 2948 unsigned plaintext_pad_len; 2949 unsigned plaintext_len; 2950 uint8_t *plaintext; 2951 struct rte_cryptodev_info dev_info; 2952 2953 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2954 uint64_t feat_flags = dev_info.feature_flags; 2955 2956 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 2957 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 2958 printf("Device doesn't support RAW data-path APIs.\n"); 2959 return -ENOTSUP; 2960 } 2961 2962 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2963 return -ENOTSUP; 2964 2965 /* Verify the capabilities */ 2966 struct rte_cryptodev_sym_capability_idx cap_idx; 2967 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2968 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 2969 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2970 &cap_idx) == NULL) 2971 return -ENOTSUP; 2972 2973 /* Create KASUMI session */ 2974 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2975 tdata->key.data, tdata->key.len, 2976 0, tdata->digest.len, 2977 RTE_CRYPTO_AUTH_OP_VERIFY, 2978 RTE_CRYPTO_AUTH_KASUMI_F9); 2979 if (retval < 0) 2980 return retval; 2981 /* alloc mbuf and set payload */ 2982 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2983 2984 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2985 rte_pktmbuf_tailroom(ut_params->ibuf)); 2986 2987 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2988 /* Append data which is padded to a multiple */ 2989 /* of the algorithms block size */ 2990 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2991 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2992 plaintext_pad_len); 2993 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2994 2995 /* Create KASUMI operation */ 2996 retval = create_wireless_algo_hash_operation(tdata->digest.data, 2997 tdata->digest.len, 2998 NULL, 0, 2999 plaintext_pad_len, 3000 RTE_CRYPTO_AUTH_OP_VERIFY, 3001 tdata->plaintext.len, 3002 0); 3003 if (retval < 0) 3004 return retval; 3005 3006 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3007 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3008 ut_params->op, 0, 1, 1, 0); 3009 else 3010 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3011 ut_params->op); 3012 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3013 ut_params->obuf = ut_params->op->sym->m_src; 3014 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3015 + plaintext_pad_len; 3016 3017 /* Validate obuf */ 3018 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3019 return 0; 3020 else 3021 return -1; 3022 3023 return 0; 3024 } 3025 3026 static int 3027 test_snow3g_hash_generate_test_case_1(void) 3028 { 3029 return test_snow3g_authentication(&snow3g_hash_test_case_1); 3030 } 3031 3032 static int 3033 test_snow3g_hash_generate_test_case_2(void) 3034 { 3035 return test_snow3g_authentication(&snow3g_hash_test_case_2); 3036 } 3037 3038 static int 3039 test_snow3g_hash_generate_test_case_3(void) 3040 { 3041 return test_snow3g_authentication(&snow3g_hash_test_case_3); 3042 } 3043 3044 static int 3045 test_snow3g_hash_generate_test_case_4(void) 3046 { 3047 return test_snow3g_authentication(&snow3g_hash_test_case_4); 3048 } 3049 3050 static int 3051 test_snow3g_hash_generate_test_case_5(void) 3052 { 3053 return test_snow3g_authentication(&snow3g_hash_test_case_5); 3054 } 3055 3056 static int 3057 test_snow3g_hash_generate_test_case_6(void) 3058 { 3059 return test_snow3g_authentication(&snow3g_hash_test_case_6); 3060 } 3061 3062 static int 3063 test_snow3g_hash_verify_test_case_1(void) 3064 { 3065 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1); 3066 3067 } 3068 3069 static int 3070 test_snow3g_hash_verify_test_case_2(void) 3071 { 3072 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2); 3073 } 3074 3075 static int 3076 test_snow3g_hash_verify_test_case_3(void) 3077 { 3078 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3); 3079 } 3080 3081 static int 3082 test_snow3g_hash_verify_test_case_4(void) 3083 { 3084 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4); 3085 } 3086 3087 static int 3088 test_snow3g_hash_verify_test_case_5(void) 3089 { 3090 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5); 3091 } 3092 3093 static int 3094 test_snow3g_hash_verify_test_case_6(void) 3095 { 3096 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6); 3097 } 3098 3099 static int 3100 test_kasumi_hash_generate_test_case_1(void) 3101 { 3102 return test_kasumi_authentication(&kasumi_hash_test_case_1); 3103 } 3104 3105 static int 3106 test_kasumi_hash_generate_test_case_2(void) 3107 { 3108 return test_kasumi_authentication(&kasumi_hash_test_case_2); 3109 } 3110 3111 static int 3112 test_kasumi_hash_generate_test_case_3(void) 3113 { 3114 return test_kasumi_authentication(&kasumi_hash_test_case_3); 3115 } 3116 3117 static int 3118 test_kasumi_hash_generate_test_case_4(void) 3119 { 3120 return test_kasumi_authentication(&kasumi_hash_test_case_4); 3121 } 3122 3123 static int 3124 test_kasumi_hash_generate_test_case_5(void) 3125 { 3126 return test_kasumi_authentication(&kasumi_hash_test_case_5); 3127 } 3128 3129 static int 3130 test_kasumi_hash_generate_test_case_6(void) 3131 { 3132 return test_kasumi_authentication(&kasumi_hash_test_case_6); 3133 } 3134 3135 static int 3136 test_kasumi_hash_verify_test_case_1(void) 3137 { 3138 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1); 3139 } 3140 3141 static int 3142 test_kasumi_hash_verify_test_case_2(void) 3143 { 3144 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2); 3145 } 3146 3147 static int 3148 test_kasumi_hash_verify_test_case_3(void) 3149 { 3150 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3); 3151 } 3152 3153 static int 3154 test_kasumi_hash_verify_test_case_4(void) 3155 { 3156 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4); 3157 } 3158 3159 static int 3160 test_kasumi_hash_verify_test_case_5(void) 3161 { 3162 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5); 3163 } 3164 3165 static int 3166 test_kasumi_encryption(const struct kasumi_test_data *tdata) 3167 { 3168 struct crypto_testsuite_params *ts_params = &testsuite_params; 3169 struct crypto_unittest_params *ut_params = &unittest_params; 3170 3171 int retval; 3172 uint8_t *plaintext, *ciphertext; 3173 unsigned plaintext_pad_len; 3174 unsigned plaintext_len; 3175 struct rte_cryptodev_info dev_info; 3176 3177 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3178 uint64_t feat_flags = dev_info.feature_flags; 3179 3180 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3181 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3182 printf("Device doesn't support RAW data-path APIs.\n"); 3183 return -ENOTSUP; 3184 } 3185 3186 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3187 return -ENOTSUP; 3188 3189 /* Verify the capabilities */ 3190 struct rte_cryptodev_sym_capability_idx cap_idx; 3191 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3192 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3193 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3194 &cap_idx) == NULL) 3195 return -ENOTSUP; 3196 3197 /* Create KASUMI session */ 3198 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3199 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3200 RTE_CRYPTO_CIPHER_KASUMI_F8, 3201 tdata->key.data, tdata->key.len, 3202 tdata->cipher_iv.len); 3203 if (retval < 0) 3204 return retval; 3205 3206 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3207 3208 /* Clear mbuf payload */ 3209 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3210 rte_pktmbuf_tailroom(ut_params->ibuf)); 3211 3212 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3213 /* Append data which is padded to a multiple */ 3214 /* of the algorithms block size */ 3215 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3216 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3217 plaintext_pad_len); 3218 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3219 3220 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3221 3222 /* Create KASUMI operation */ 3223 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3224 tdata->cipher_iv.len, 3225 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3226 tdata->validCipherOffsetInBits.len); 3227 if (retval < 0) 3228 return retval; 3229 3230 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3231 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3232 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3233 else 3234 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3235 ut_params->op); 3236 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3237 3238 ut_params->obuf = ut_params->op->sym->m_dst; 3239 if (ut_params->obuf) 3240 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3241 else 3242 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3243 3244 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3245 3246 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3247 (tdata->validCipherOffsetInBits.len >> 3); 3248 /* Validate obuf */ 3249 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3250 ciphertext, 3251 reference_ciphertext, 3252 tdata->validCipherLenInBits.len, 3253 "KASUMI Ciphertext data not as expected"); 3254 return 0; 3255 } 3256 3257 static int 3258 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata) 3259 { 3260 struct crypto_testsuite_params *ts_params = &testsuite_params; 3261 struct crypto_unittest_params *ut_params = &unittest_params; 3262 3263 int retval; 3264 3265 unsigned int plaintext_pad_len; 3266 unsigned int plaintext_len; 3267 3268 uint8_t buffer[10000]; 3269 const uint8_t *ciphertext; 3270 3271 struct rte_cryptodev_info dev_info; 3272 3273 /* Verify the capabilities */ 3274 struct rte_cryptodev_sym_capability_idx cap_idx; 3275 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3276 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3277 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3278 &cap_idx) == NULL) 3279 return -ENOTSUP; 3280 3281 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3282 3283 uint64_t feat_flags = dev_info.feature_flags; 3284 3285 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 3286 printf("Device doesn't support in-place scatter-gather. " 3287 "Test Skipped.\n"); 3288 return -ENOTSUP; 3289 } 3290 3291 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3292 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3293 printf("Device doesn't support RAW data-path APIs.\n"); 3294 return -ENOTSUP; 3295 } 3296 3297 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3298 return -ENOTSUP; 3299 3300 /* Create KASUMI session */ 3301 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3302 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3303 RTE_CRYPTO_CIPHER_KASUMI_F8, 3304 tdata->key.data, tdata->key.len, 3305 tdata->cipher_iv.len); 3306 if (retval < 0) 3307 return retval; 3308 3309 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3310 3311 3312 /* Append data which is padded to a multiple */ 3313 /* of the algorithms block size */ 3314 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3315 3316 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3317 plaintext_pad_len, 10, 0); 3318 3319 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3320 3321 /* Create KASUMI operation */ 3322 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3323 tdata->cipher_iv.len, 3324 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3325 tdata->validCipherOffsetInBits.len); 3326 if (retval < 0) 3327 return retval; 3328 3329 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3330 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3331 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3332 else 3333 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3334 ut_params->op); 3335 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3336 3337 ut_params->obuf = ut_params->op->sym->m_dst; 3338 3339 if (ut_params->obuf) 3340 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3341 plaintext_len, buffer); 3342 else 3343 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3344 tdata->validCipherOffsetInBits.len >> 3, 3345 plaintext_len, buffer); 3346 3347 /* Validate obuf */ 3348 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3349 3350 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3351 (tdata->validCipherOffsetInBits.len >> 3); 3352 /* Validate obuf */ 3353 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3354 ciphertext, 3355 reference_ciphertext, 3356 tdata->validCipherLenInBits.len, 3357 "KASUMI Ciphertext data not as expected"); 3358 return 0; 3359 } 3360 3361 static int 3362 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata) 3363 { 3364 struct crypto_testsuite_params *ts_params = &testsuite_params; 3365 struct crypto_unittest_params *ut_params = &unittest_params; 3366 3367 int retval; 3368 uint8_t *plaintext, *ciphertext; 3369 unsigned plaintext_pad_len; 3370 unsigned plaintext_len; 3371 3372 /* Verify the capabilities */ 3373 struct rte_cryptodev_sym_capability_idx cap_idx; 3374 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3375 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3376 /* Data-path service does not support OOP */ 3377 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3378 &cap_idx) == NULL) 3379 return -ENOTSUP; 3380 3381 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3382 return -ENOTSUP; 3383 3384 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3385 return -ENOTSUP; 3386 3387 /* Create KASUMI session */ 3388 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3389 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3390 RTE_CRYPTO_CIPHER_KASUMI_F8, 3391 tdata->key.data, tdata->key.len, 3392 tdata->cipher_iv.len); 3393 if (retval < 0) 3394 return retval; 3395 3396 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3397 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3398 3399 /* Clear mbuf payload */ 3400 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3401 rte_pktmbuf_tailroom(ut_params->ibuf)); 3402 3403 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3404 /* Append data which is padded to a multiple */ 3405 /* of the algorithms block size */ 3406 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3407 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3408 plaintext_pad_len); 3409 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3410 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3411 3412 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3413 3414 /* Create KASUMI operation */ 3415 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3416 tdata->cipher_iv.len, 3417 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3418 tdata->validCipherOffsetInBits.len); 3419 if (retval < 0) 3420 return retval; 3421 3422 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3423 ut_params->op); 3424 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3425 3426 ut_params->obuf = ut_params->op->sym->m_dst; 3427 if (ut_params->obuf) 3428 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3429 else 3430 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3431 3432 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3433 3434 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3435 (tdata->validCipherOffsetInBits.len >> 3); 3436 /* Validate obuf */ 3437 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3438 ciphertext, 3439 reference_ciphertext, 3440 tdata->validCipherLenInBits.len, 3441 "KASUMI Ciphertext data not as expected"); 3442 return 0; 3443 } 3444 3445 static int 3446 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata) 3447 { 3448 struct crypto_testsuite_params *ts_params = &testsuite_params; 3449 struct crypto_unittest_params *ut_params = &unittest_params; 3450 3451 int retval; 3452 unsigned int plaintext_pad_len; 3453 unsigned int plaintext_len; 3454 3455 const uint8_t *ciphertext; 3456 uint8_t buffer[2048]; 3457 3458 struct rte_cryptodev_info dev_info; 3459 3460 /* Verify the capabilities */ 3461 struct rte_cryptodev_sym_capability_idx cap_idx; 3462 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3463 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3464 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3465 &cap_idx) == NULL) 3466 return -ENOTSUP; 3467 3468 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3469 return -ENOTSUP; 3470 3471 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3472 return -ENOTSUP; 3473 3474 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3475 3476 uint64_t feat_flags = dev_info.feature_flags; 3477 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 3478 printf("Device doesn't support out-of-place scatter-gather " 3479 "in both input and output mbufs. " 3480 "Test Skipped.\n"); 3481 return -ENOTSUP; 3482 } 3483 3484 /* Create KASUMI session */ 3485 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3486 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3487 RTE_CRYPTO_CIPHER_KASUMI_F8, 3488 tdata->key.data, tdata->key.len, 3489 tdata->cipher_iv.len); 3490 if (retval < 0) 3491 return retval; 3492 3493 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3494 /* Append data which is padded to a multiple */ 3495 /* of the algorithms block size */ 3496 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3497 3498 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3499 plaintext_pad_len, 10, 0); 3500 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 3501 plaintext_pad_len, 3, 0); 3502 3503 /* Append data which is padded to a multiple */ 3504 /* of the algorithms block size */ 3505 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3506 3507 /* Create KASUMI operation */ 3508 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3509 tdata->cipher_iv.len, 3510 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3511 tdata->validCipherOffsetInBits.len); 3512 if (retval < 0) 3513 return retval; 3514 3515 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3516 ut_params->op); 3517 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3518 3519 ut_params->obuf = ut_params->op->sym->m_dst; 3520 if (ut_params->obuf) 3521 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3522 plaintext_pad_len, buffer); 3523 else 3524 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3525 tdata->validCipherOffsetInBits.len >> 3, 3526 plaintext_pad_len, buffer); 3527 3528 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3529 (tdata->validCipherOffsetInBits.len >> 3); 3530 /* Validate obuf */ 3531 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3532 ciphertext, 3533 reference_ciphertext, 3534 tdata->validCipherLenInBits.len, 3535 "KASUMI Ciphertext data not as expected"); 3536 return 0; 3537 } 3538 3539 3540 static int 3541 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata) 3542 { 3543 struct crypto_testsuite_params *ts_params = &testsuite_params; 3544 struct crypto_unittest_params *ut_params = &unittest_params; 3545 3546 int retval; 3547 uint8_t *ciphertext, *plaintext; 3548 unsigned ciphertext_pad_len; 3549 unsigned ciphertext_len; 3550 3551 /* Verify the capabilities */ 3552 struct rte_cryptodev_sym_capability_idx cap_idx; 3553 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3554 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3555 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3556 &cap_idx) == NULL) 3557 return -ENOTSUP; 3558 3559 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3560 return -ENOTSUP; 3561 3562 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3563 return -ENOTSUP; 3564 3565 /* Create KASUMI session */ 3566 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3567 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3568 RTE_CRYPTO_CIPHER_KASUMI_F8, 3569 tdata->key.data, tdata->key.len, 3570 tdata->cipher_iv.len); 3571 if (retval < 0) 3572 return retval; 3573 3574 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3575 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3576 3577 /* Clear mbuf payload */ 3578 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3579 rte_pktmbuf_tailroom(ut_params->ibuf)); 3580 3581 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 3582 /* Append data which is padded to a multiple */ 3583 /* of the algorithms block size */ 3584 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 3585 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3586 ciphertext_pad_len); 3587 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 3588 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 3589 3590 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 3591 3592 /* Create KASUMI operation */ 3593 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3594 tdata->cipher_iv.len, 3595 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3596 tdata->validCipherOffsetInBits.len); 3597 if (retval < 0) 3598 return retval; 3599 3600 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3601 ut_params->op); 3602 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3603 3604 ut_params->obuf = ut_params->op->sym->m_dst; 3605 if (ut_params->obuf) 3606 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3607 else 3608 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 3609 3610 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 3611 3612 const uint8_t *reference_plaintext = tdata->plaintext.data + 3613 (tdata->validCipherOffsetInBits.len >> 3); 3614 /* Validate obuf */ 3615 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3616 plaintext, 3617 reference_plaintext, 3618 tdata->validCipherLenInBits.len, 3619 "KASUMI Plaintext data not as expected"); 3620 return 0; 3621 } 3622 3623 static int 3624 test_kasumi_decryption(const struct kasumi_test_data *tdata) 3625 { 3626 struct crypto_testsuite_params *ts_params = &testsuite_params; 3627 struct crypto_unittest_params *ut_params = &unittest_params; 3628 3629 int retval; 3630 uint8_t *ciphertext, *plaintext; 3631 unsigned ciphertext_pad_len; 3632 unsigned ciphertext_len; 3633 struct rte_cryptodev_info dev_info; 3634 3635 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3636 uint64_t feat_flags = dev_info.feature_flags; 3637 3638 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3639 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3640 printf("Device doesn't support RAW data-path APIs.\n"); 3641 return -ENOTSUP; 3642 } 3643 3644 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3645 return -ENOTSUP; 3646 3647 /* Verify the capabilities */ 3648 struct rte_cryptodev_sym_capability_idx cap_idx; 3649 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3650 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3651 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3652 &cap_idx) == NULL) 3653 return -ENOTSUP; 3654 3655 /* Create KASUMI session */ 3656 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3657 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3658 RTE_CRYPTO_CIPHER_KASUMI_F8, 3659 tdata->key.data, tdata->key.len, 3660 tdata->cipher_iv.len); 3661 if (retval < 0) 3662 return retval; 3663 3664 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3665 3666 /* Clear mbuf payload */ 3667 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3668 rte_pktmbuf_tailroom(ut_params->ibuf)); 3669 3670 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 3671 /* Append data which is padded to a multiple */ 3672 /* of the algorithms block size */ 3673 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 3674 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3675 ciphertext_pad_len); 3676 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 3677 3678 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 3679 3680 /* Create KASUMI operation */ 3681 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3682 tdata->cipher_iv.len, 3683 tdata->ciphertext.len, 3684 tdata->validCipherOffsetInBits.len); 3685 if (retval < 0) 3686 return retval; 3687 3688 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3689 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3690 ut_params->op, 1, 0, 1, 0); 3691 else 3692 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3693 ut_params->op); 3694 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3695 3696 ut_params->obuf = ut_params->op->sym->m_dst; 3697 if (ut_params->obuf) 3698 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3699 else 3700 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 3701 3702 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 3703 3704 const uint8_t *reference_plaintext = tdata->plaintext.data + 3705 (tdata->validCipherOffsetInBits.len >> 3); 3706 /* Validate obuf */ 3707 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3708 plaintext, 3709 reference_plaintext, 3710 tdata->validCipherLenInBits.len, 3711 "KASUMI Plaintext data not as expected"); 3712 return 0; 3713 } 3714 3715 static int 3716 test_snow3g_encryption(const struct snow3g_test_data *tdata) 3717 { 3718 struct crypto_testsuite_params *ts_params = &testsuite_params; 3719 struct crypto_unittest_params *ut_params = &unittest_params; 3720 3721 int retval; 3722 uint8_t *plaintext, *ciphertext; 3723 unsigned plaintext_pad_len; 3724 unsigned plaintext_len; 3725 struct rte_cryptodev_info dev_info; 3726 3727 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3728 uint64_t feat_flags = dev_info.feature_flags; 3729 3730 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3731 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3732 printf("Device doesn't support RAW data-path APIs.\n"); 3733 return -ENOTSUP; 3734 } 3735 3736 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3737 return -ENOTSUP; 3738 3739 /* Verify the capabilities */ 3740 struct rte_cryptodev_sym_capability_idx cap_idx; 3741 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3742 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3743 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3744 &cap_idx) == NULL) 3745 return -ENOTSUP; 3746 3747 /* Create SNOW 3G session */ 3748 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3749 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3750 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3751 tdata->key.data, tdata->key.len, 3752 tdata->cipher_iv.len); 3753 if (retval < 0) 3754 return retval; 3755 3756 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3757 3758 /* Clear mbuf payload */ 3759 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3760 rte_pktmbuf_tailroom(ut_params->ibuf)); 3761 3762 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3763 /* Append data which is padded to a multiple of */ 3764 /* the algorithms block size */ 3765 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3766 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3767 plaintext_pad_len); 3768 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3769 3770 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3771 3772 /* Create SNOW 3G operation */ 3773 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3774 tdata->cipher_iv.len, 3775 tdata->validCipherLenInBits.len, 3776 0); 3777 if (retval < 0) 3778 return retval; 3779 3780 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3781 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3782 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3783 else 3784 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3785 ut_params->op); 3786 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3787 3788 ut_params->obuf = ut_params->op->sym->m_dst; 3789 if (ut_params->obuf) 3790 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3791 else 3792 ciphertext = plaintext; 3793 3794 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3795 3796 /* Validate obuf */ 3797 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3798 ciphertext, 3799 tdata->ciphertext.data, 3800 tdata->validDataLenInBits.len, 3801 "SNOW 3G Ciphertext data not as expected"); 3802 return 0; 3803 } 3804 3805 3806 static int 3807 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) 3808 { 3809 struct crypto_testsuite_params *ts_params = &testsuite_params; 3810 struct crypto_unittest_params *ut_params = &unittest_params; 3811 uint8_t *plaintext, *ciphertext; 3812 3813 int retval; 3814 unsigned plaintext_pad_len; 3815 unsigned plaintext_len; 3816 3817 /* Verify the capabilities */ 3818 struct rte_cryptodev_sym_capability_idx cap_idx; 3819 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3820 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3821 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3822 &cap_idx) == NULL) 3823 return -ENOTSUP; 3824 3825 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3826 return -ENOTSUP; 3827 3828 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3829 return -ENOTSUP; 3830 3831 /* Create SNOW 3G session */ 3832 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3833 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3834 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3835 tdata->key.data, tdata->key.len, 3836 tdata->cipher_iv.len); 3837 if (retval < 0) 3838 return retval; 3839 3840 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3841 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3842 3843 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 3844 "Failed to allocate input buffer in mempool"); 3845 TEST_ASSERT_NOT_NULL(ut_params->obuf, 3846 "Failed to allocate output buffer in mempool"); 3847 3848 /* Clear mbuf payload */ 3849 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3850 rte_pktmbuf_tailroom(ut_params->ibuf)); 3851 3852 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3853 /* Append data which is padded to a multiple of */ 3854 /* the algorithms block size */ 3855 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3856 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3857 plaintext_pad_len); 3858 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3859 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3860 3861 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3862 3863 /* Create SNOW 3G operation */ 3864 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3865 tdata->cipher_iv.len, 3866 tdata->validCipherLenInBits.len, 3867 0); 3868 if (retval < 0) 3869 return retval; 3870 3871 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3872 ut_params->op); 3873 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3874 3875 ut_params->obuf = ut_params->op->sym->m_dst; 3876 if (ut_params->obuf) 3877 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3878 else 3879 ciphertext = plaintext; 3880 3881 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3882 3883 /* Validate obuf */ 3884 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3885 ciphertext, 3886 tdata->ciphertext.data, 3887 tdata->validDataLenInBits.len, 3888 "SNOW 3G Ciphertext data not as expected"); 3889 return 0; 3890 } 3891 3892 static int 3893 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata) 3894 { 3895 struct crypto_testsuite_params *ts_params = &testsuite_params; 3896 struct crypto_unittest_params *ut_params = &unittest_params; 3897 3898 int retval; 3899 unsigned int plaintext_pad_len; 3900 unsigned int plaintext_len; 3901 uint8_t buffer[10000]; 3902 const uint8_t *ciphertext; 3903 3904 struct rte_cryptodev_info dev_info; 3905 3906 /* Verify the capabilities */ 3907 struct rte_cryptodev_sym_capability_idx cap_idx; 3908 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3909 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3910 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3911 &cap_idx) == NULL) 3912 return -ENOTSUP; 3913 3914 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3915 return -ENOTSUP; 3916 3917 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3918 return -ENOTSUP; 3919 3920 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3921 3922 uint64_t feat_flags = dev_info.feature_flags; 3923 3924 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 3925 printf("Device doesn't support out-of-place scatter-gather " 3926 "in both input and output mbufs. " 3927 "Test Skipped.\n"); 3928 return -ENOTSUP; 3929 } 3930 3931 /* Create SNOW 3G session */ 3932 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3933 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3934 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3935 tdata->key.data, tdata->key.len, 3936 tdata->cipher_iv.len); 3937 if (retval < 0) 3938 return retval; 3939 3940 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3941 /* Append data which is padded to a multiple of */ 3942 /* the algorithms block size */ 3943 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3944 3945 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3946 plaintext_pad_len, 10, 0); 3947 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 3948 plaintext_pad_len, 3, 0); 3949 3950 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 3951 "Failed to allocate input buffer in mempool"); 3952 TEST_ASSERT_NOT_NULL(ut_params->obuf, 3953 "Failed to allocate output buffer in mempool"); 3954 3955 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3956 3957 /* Create SNOW 3G operation */ 3958 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3959 tdata->cipher_iv.len, 3960 tdata->validCipherLenInBits.len, 3961 0); 3962 if (retval < 0) 3963 return retval; 3964 3965 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3966 ut_params->op); 3967 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3968 3969 ut_params->obuf = ut_params->op->sym->m_dst; 3970 if (ut_params->obuf) 3971 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3972 plaintext_len, buffer); 3973 else 3974 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 3975 plaintext_len, buffer); 3976 3977 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3978 3979 /* Validate obuf */ 3980 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3981 ciphertext, 3982 tdata->ciphertext.data, 3983 tdata->validDataLenInBits.len, 3984 "SNOW 3G Ciphertext data not as expected"); 3985 3986 return 0; 3987 } 3988 3989 /* Shift right a buffer by "offset" bits, "offset" < 8 */ 3990 static void 3991 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) 3992 { 3993 uint8_t curr_byte, prev_byte; 3994 uint32_t length_in_bytes = ceil_byte_length(length + offset); 3995 uint8_t lower_byte_mask = (1 << offset) - 1; 3996 unsigned i; 3997 3998 prev_byte = buffer[0]; 3999 buffer[0] >>= offset; 4000 4001 for (i = 1; i < length_in_bytes; i++) { 4002 curr_byte = buffer[i]; 4003 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | 4004 (curr_byte >> offset); 4005 prev_byte = curr_byte; 4006 } 4007 } 4008 4009 static int 4010 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) 4011 { 4012 struct crypto_testsuite_params *ts_params = &testsuite_params; 4013 struct crypto_unittest_params *ut_params = &unittest_params; 4014 uint8_t *plaintext, *ciphertext; 4015 int retval; 4016 uint32_t plaintext_len; 4017 uint32_t plaintext_pad_len; 4018 uint8_t extra_offset = 4; 4019 uint8_t *expected_ciphertext_shifted; 4020 struct rte_cryptodev_info dev_info; 4021 4022 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4023 uint64_t feat_flags = dev_info.feature_flags; 4024 4025 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4026 ((tdata->validDataLenInBits.len % 8) != 0)) { 4027 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4028 return -ENOTSUP; 4029 } 4030 4031 /* Verify the capabilities */ 4032 struct rte_cryptodev_sym_capability_idx cap_idx; 4033 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4034 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4035 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4036 &cap_idx) == NULL) 4037 return -ENOTSUP; 4038 4039 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4040 return -ENOTSUP; 4041 4042 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4043 return -ENOTSUP; 4044 4045 /* Create SNOW 3G session */ 4046 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4047 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4048 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4049 tdata->key.data, tdata->key.len, 4050 tdata->cipher_iv.len); 4051 if (retval < 0) 4052 return retval; 4053 4054 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4055 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4056 4057 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4058 "Failed to allocate input buffer in mempool"); 4059 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4060 "Failed to allocate output buffer in mempool"); 4061 4062 /* Clear mbuf payload */ 4063 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4064 rte_pktmbuf_tailroom(ut_params->ibuf)); 4065 4066 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset); 4067 /* 4068 * Append data which is padded to a 4069 * multiple of the algorithms block size 4070 */ 4071 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4072 4073 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, 4074 plaintext_pad_len); 4075 4076 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4077 4078 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); 4079 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); 4080 4081 #ifdef RTE_APP_TEST_DEBUG 4082 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); 4083 #endif 4084 /* Create SNOW 3G operation */ 4085 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4086 tdata->cipher_iv.len, 4087 tdata->validCipherLenInBits.len, 4088 extra_offset); 4089 if (retval < 0) 4090 return retval; 4091 4092 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4093 ut_params->op); 4094 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4095 4096 ut_params->obuf = ut_params->op->sym->m_dst; 4097 if (ut_params->obuf) 4098 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4099 else 4100 ciphertext = plaintext; 4101 4102 #ifdef RTE_APP_TEST_DEBUG 4103 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4104 #endif 4105 4106 expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8); 4107 4108 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, 4109 "failed to reserve memory for ciphertext shifted\n"); 4110 4111 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, 4112 ceil_byte_length(tdata->ciphertext.len)); 4113 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, 4114 extra_offset); 4115 /* Validate obuf */ 4116 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4117 ciphertext, 4118 expected_ciphertext_shifted, 4119 tdata->validDataLenInBits.len, 4120 extra_offset, 4121 "SNOW 3G Ciphertext data not as expected"); 4122 return 0; 4123 } 4124 4125 static int test_snow3g_decryption(const struct snow3g_test_data *tdata) 4126 { 4127 struct crypto_testsuite_params *ts_params = &testsuite_params; 4128 struct crypto_unittest_params *ut_params = &unittest_params; 4129 4130 int retval; 4131 4132 uint8_t *plaintext, *ciphertext; 4133 unsigned ciphertext_pad_len; 4134 unsigned ciphertext_len; 4135 struct rte_cryptodev_info dev_info; 4136 4137 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4138 uint64_t feat_flags = dev_info.feature_flags; 4139 4140 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4141 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4142 printf("Device doesn't support RAW data-path APIs.\n"); 4143 return -ENOTSUP; 4144 } 4145 4146 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4147 return -ENOTSUP; 4148 4149 /* Verify the capabilities */ 4150 struct rte_cryptodev_sym_capability_idx cap_idx; 4151 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4152 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4153 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4154 &cap_idx) == NULL) 4155 return -ENOTSUP; 4156 4157 /* Create SNOW 3G session */ 4158 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4159 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4160 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4161 tdata->key.data, tdata->key.len, 4162 tdata->cipher_iv.len); 4163 if (retval < 0) 4164 return retval; 4165 4166 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4167 4168 /* Clear mbuf payload */ 4169 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4170 rte_pktmbuf_tailroom(ut_params->ibuf)); 4171 4172 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4173 /* Append data which is padded to a multiple of */ 4174 /* the algorithms block size */ 4175 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4176 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4177 ciphertext_pad_len); 4178 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4179 4180 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4181 4182 /* Create SNOW 3G operation */ 4183 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4184 tdata->cipher_iv.len, 4185 tdata->validCipherLenInBits.len, 4186 tdata->cipher.offset_bits); 4187 if (retval < 0) 4188 return retval; 4189 4190 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4191 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4192 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4193 else 4194 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4195 ut_params->op); 4196 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4197 ut_params->obuf = ut_params->op->sym->m_dst; 4198 if (ut_params->obuf) 4199 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4200 else 4201 plaintext = ciphertext; 4202 4203 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4204 4205 /* Validate obuf */ 4206 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4207 tdata->plaintext.data, 4208 tdata->validDataLenInBits.len, 4209 "SNOW 3G Plaintext data not as expected"); 4210 return 0; 4211 } 4212 4213 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) 4214 { 4215 struct crypto_testsuite_params *ts_params = &testsuite_params; 4216 struct crypto_unittest_params *ut_params = &unittest_params; 4217 4218 int retval; 4219 4220 uint8_t *plaintext, *ciphertext; 4221 unsigned ciphertext_pad_len; 4222 unsigned ciphertext_len; 4223 4224 /* Verify the capabilities */ 4225 struct rte_cryptodev_sym_capability_idx cap_idx; 4226 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4227 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4228 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4229 &cap_idx) == NULL) 4230 return -ENOTSUP; 4231 4232 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4233 return -ENOTSUP; 4234 4235 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4236 return -ENOTSUP; 4237 4238 /* Create SNOW 3G session */ 4239 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4240 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4241 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4242 tdata->key.data, tdata->key.len, 4243 tdata->cipher_iv.len); 4244 if (retval < 0) 4245 return retval; 4246 4247 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4248 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4249 4250 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4251 "Failed to allocate input buffer"); 4252 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4253 "Failed to allocate output buffer"); 4254 4255 /* Clear mbuf payload */ 4256 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4257 rte_pktmbuf_tailroom(ut_params->ibuf)); 4258 4259 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4260 rte_pktmbuf_tailroom(ut_params->obuf)); 4261 4262 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4263 /* Append data which is padded to a multiple of */ 4264 /* the algorithms block size */ 4265 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4266 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4267 ciphertext_pad_len); 4268 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4269 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4270 4271 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4272 4273 /* Create SNOW 3G operation */ 4274 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4275 tdata->cipher_iv.len, 4276 tdata->validCipherLenInBits.len, 4277 0); 4278 if (retval < 0) 4279 return retval; 4280 4281 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4282 ut_params->op); 4283 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4284 ut_params->obuf = ut_params->op->sym->m_dst; 4285 if (ut_params->obuf) 4286 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4287 else 4288 plaintext = ciphertext; 4289 4290 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4291 4292 /* Validate obuf */ 4293 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4294 tdata->plaintext.data, 4295 tdata->validDataLenInBits.len, 4296 "SNOW 3G Plaintext data not as expected"); 4297 return 0; 4298 } 4299 4300 static int 4301 test_zuc_cipher_auth(const struct wireless_test_data *tdata) 4302 { 4303 struct crypto_testsuite_params *ts_params = &testsuite_params; 4304 struct crypto_unittest_params *ut_params = &unittest_params; 4305 4306 int retval; 4307 4308 uint8_t *plaintext, *ciphertext; 4309 unsigned int plaintext_pad_len; 4310 unsigned int plaintext_len; 4311 4312 struct rte_cryptodev_info dev_info; 4313 struct rte_cryptodev_sym_capability_idx cap_idx; 4314 4315 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4316 uint64_t feat_flags = dev_info.feature_flags; 4317 4318 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4319 ((tdata->validAuthLenInBits.len % 8 != 0) || 4320 (tdata->validDataLenInBits.len % 8 != 0))) { 4321 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4322 return -ENOTSUP; 4323 } 4324 4325 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4326 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4327 printf("Device doesn't support RAW data-path APIs.\n"); 4328 return -ENOTSUP; 4329 } 4330 4331 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4332 return -ENOTSUP; 4333 4334 /* Check if device supports ZUC EEA3 */ 4335 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4336 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 4337 4338 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4339 &cap_idx) == NULL) 4340 return -ENOTSUP; 4341 4342 /* Check if device supports ZUC EIA3 */ 4343 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4344 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 4345 4346 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4347 &cap_idx) == NULL) 4348 return -ENOTSUP; 4349 4350 /* Create ZUC session */ 4351 retval = create_zuc_cipher_auth_encrypt_generate_session( 4352 ts_params->valid_devs[0], 4353 tdata); 4354 if (retval < 0) 4355 return retval; 4356 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4357 4358 /* clear mbuf payload */ 4359 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4360 rte_pktmbuf_tailroom(ut_params->ibuf)); 4361 4362 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4363 /* Append data which is padded to a multiple of */ 4364 /* the algorithms block size */ 4365 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4366 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4367 plaintext_pad_len); 4368 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4369 4370 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4371 4372 /* Create ZUC operation */ 4373 retval = create_zuc_cipher_hash_generate_operation(tdata); 4374 if (retval < 0) 4375 return retval; 4376 4377 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4378 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4379 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4380 else 4381 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4382 ut_params->op); 4383 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4384 ut_params->obuf = ut_params->op->sym->m_src; 4385 if (ut_params->obuf) 4386 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4387 else 4388 ciphertext = plaintext; 4389 4390 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4391 /* Validate obuf */ 4392 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4393 ciphertext, 4394 tdata->ciphertext.data, 4395 tdata->validDataLenInBits.len, 4396 "ZUC Ciphertext data not as expected"); 4397 4398 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4399 + plaintext_pad_len; 4400 4401 /* Validate obuf */ 4402 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4403 ut_params->digest, 4404 tdata->digest.data, 4405 4, 4406 "ZUC Generated auth tag not as expected"); 4407 return 0; 4408 } 4409 4410 static int 4411 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) 4412 { 4413 struct crypto_testsuite_params *ts_params = &testsuite_params; 4414 struct crypto_unittest_params *ut_params = &unittest_params; 4415 4416 int retval; 4417 4418 uint8_t *plaintext, *ciphertext; 4419 unsigned plaintext_pad_len; 4420 unsigned plaintext_len; 4421 struct rte_cryptodev_info dev_info; 4422 4423 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4424 uint64_t feat_flags = dev_info.feature_flags; 4425 4426 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4427 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4428 printf("Device doesn't support RAW data-path APIs.\n"); 4429 return -ENOTSUP; 4430 } 4431 4432 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4433 return -ENOTSUP; 4434 4435 /* Verify the capabilities */ 4436 struct rte_cryptodev_sym_capability_idx cap_idx; 4437 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4438 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4439 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4440 &cap_idx) == NULL) 4441 return -ENOTSUP; 4442 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4443 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4444 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4445 &cap_idx) == NULL) 4446 return -ENOTSUP; 4447 4448 /* Create SNOW 3G session */ 4449 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0], 4450 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4451 RTE_CRYPTO_AUTH_OP_GENERATE, 4452 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4453 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4454 tdata->key.data, tdata->key.len, 4455 tdata->auth_iv.len, tdata->digest.len, 4456 tdata->cipher_iv.len); 4457 if (retval < 0) 4458 return retval; 4459 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4460 4461 /* clear mbuf payload */ 4462 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4463 rte_pktmbuf_tailroom(ut_params->ibuf)); 4464 4465 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4466 /* Append data which is padded to a multiple of */ 4467 /* the algorithms block size */ 4468 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4469 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4470 plaintext_pad_len); 4471 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4472 4473 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4474 4475 /* Create SNOW 3G operation */ 4476 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 4477 tdata->digest.len, tdata->auth_iv.data, 4478 tdata->auth_iv.len, 4479 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 4480 tdata->cipher_iv.data, tdata->cipher_iv.len, 4481 tdata->validCipherLenInBits.len, 4482 0, 4483 tdata->validAuthLenInBits.len, 4484 0 4485 ); 4486 if (retval < 0) 4487 return retval; 4488 4489 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4490 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4491 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4492 else 4493 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4494 ut_params->op); 4495 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4496 ut_params->obuf = ut_params->op->sym->m_src; 4497 if (ut_params->obuf) 4498 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4499 else 4500 ciphertext = plaintext; 4501 4502 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4503 /* Validate obuf */ 4504 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4505 ciphertext, 4506 tdata->ciphertext.data, 4507 tdata->validDataLenInBits.len, 4508 "SNOW 3G Ciphertext data not as expected"); 4509 4510 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4511 + plaintext_pad_len; 4512 4513 /* Validate obuf */ 4514 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4515 ut_params->digest, 4516 tdata->digest.data, 4517 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4518 "SNOW 3G Generated auth tag not as expected"); 4519 return 0; 4520 } 4521 4522 static int 4523 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata, 4524 uint8_t op_mode, uint8_t verify) 4525 { 4526 struct crypto_testsuite_params *ts_params = &testsuite_params; 4527 struct crypto_unittest_params *ut_params = &unittest_params; 4528 4529 int retval; 4530 4531 uint8_t *plaintext = NULL, *ciphertext = NULL; 4532 unsigned int plaintext_pad_len; 4533 unsigned int plaintext_len; 4534 unsigned int ciphertext_pad_len; 4535 unsigned int ciphertext_len; 4536 4537 struct rte_cryptodev_info dev_info; 4538 4539 /* Verify the capabilities */ 4540 struct rte_cryptodev_sym_capability_idx cap_idx; 4541 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4542 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4543 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4544 &cap_idx) == NULL) 4545 return -ENOTSUP; 4546 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4547 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4548 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4549 &cap_idx) == NULL) 4550 return -ENOTSUP; 4551 4552 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4553 return -ENOTSUP; 4554 4555 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4556 4557 uint64_t feat_flags = dev_info.feature_flags; 4558 4559 if (op_mode == OUT_OF_PLACE) { 4560 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 4561 printf("Device doesn't support digest encrypted.\n"); 4562 return -ENOTSUP; 4563 } 4564 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4565 return -ENOTSUP; 4566 } 4567 4568 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4569 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4570 printf("Device doesn't support RAW data-path APIs.\n"); 4571 return -ENOTSUP; 4572 } 4573 4574 /* Create SNOW 3G session */ 4575 retval = create_wireless_algo_auth_cipher_session( 4576 ts_params->valid_devs[0], 4577 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 4578 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 4579 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 4580 : RTE_CRYPTO_AUTH_OP_GENERATE), 4581 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4582 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4583 tdata->key.data, tdata->key.len, 4584 tdata->auth_iv.len, tdata->digest.len, 4585 tdata->cipher_iv.len); 4586 4587 if (retval < 0) 4588 return retval; 4589 4590 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4591 if (op_mode == OUT_OF_PLACE) 4592 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4593 4594 /* clear mbuf payload */ 4595 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4596 rte_pktmbuf_tailroom(ut_params->ibuf)); 4597 if (op_mode == OUT_OF_PLACE) 4598 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4599 rte_pktmbuf_tailroom(ut_params->obuf)); 4600 4601 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4602 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4603 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4604 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4605 4606 if (verify) { 4607 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4608 ciphertext_pad_len); 4609 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4610 if (op_mode == OUT_OF_PLACE) 4611 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4612 debug_hexdump(stdout, "ciphertext:", ciphertext, 4613 ciphertext_len); 4614 } else { 4615 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4616 plaintext_pad_len); 4617 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4618 if (op_mode == OUT_OF_PLACE) 4619 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4620 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4621 } 4622 4623 /* Create SNOW 3G operation */ 4624 retval = create_wireless_algo_auth_cipher_operation( 4625 tdata->digest.data, tdata->digest.len, 4626 tdata->cipher_iv.data, tdata->cipher_iv.len, 4627 tdata->auth_iv.data, tdata->auth_iv.len, 4628 (tdata->digest.offset_bytes == 0 ? 4629 (verify ? ciphertext_pad_len : plaintext_pad_len) 4630 : tdata->digest.offset_bytes), 4631 tdata->validCipherLenInBits.len, 4632 tdata->cipher.offset_bits, 4633 tdata->validAuthLenInBits.len, 4634 tdata->auth.offset_bits, 4635 op_mode, 0, verify); 4636 4637 if (retval < 0) 4638 return retval; 4639 4640 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4641 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4642 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4643 else 4644 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4645 ut_params->op); 4646 4647 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4648 4649 ut_params->obuf = (op_mode == IN_PLACE ? 4650 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 4651 4652 if (verify) { 4653 if (ut_params->obuf) 4654 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 4655 uint8_t *); 4656 else 4657 plaintext = ciphertext + 4658 (tdata->cipher.offset_bits >> 3); 4659 4660 debug_hexdump(stdout, "plaintext:", plaintext, 4661 (tdata->plaintext.len >> 3) - tdata->digest.len); 4662 debug_hexdump(stdout, "plaintext expected:", 4663 tdata->plaintext.data, 4664 (tdata->plaintext.len >> 3) - tdata->digest.len); 4665 } else { 4666 if (ut_params->obuf) 4667 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 4668 uint8_t *); 4669 else 4670 ciphertext = plaintext; 4671 4672 debug_hexdump(stdout, "ciphertext:", ciphertext, 4673 ciphertext_len); 4674 debug_hexdump(stdout, "ciphertext expected:", 4675 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 4676 4677 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4678 + (tdata->digest.offset_bytes == 0 ? 4679 plaintext_pad_len : tdata->digest.offset_bytes); 4680 4681 debug_hexdump(stdout, "digest:", ut_params->digest, 4682 tdata->digest.len); 4683 debug_hexdump(stdout, "digest expected:", tdata->digest.data, 4684 tdata->digest.len); 4685 } 4686 4687 /* Validate obuf */ 4688 if (verify) { 4689 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4690 plaintext, 4691 tdata->plaintext.data, 4692 (tdata->plaintext.len - tdata->cipher.offset_bits - 4693 (tdata->digest.len << 3)), 4694 tdata->cipher.offset_bits, 4695 "SNOW 3G Plaintext data not as expected"); 4696 } else { 4697 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4698 ciphertext, 4699 tdata->ciphertext.data, 4700 (tdata->validDataLenInBits.len - 4701 tdata->cipher.offset_bits), 4702 tdata->cipher.offset_bits, 4703 "SNOW 3G Ciphertext data not as expected"); 4704 4705 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4706 ut_params->digest, 4707 tdata->digest.data, 4708 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4709 "SNOW 3G Generated auth tag not as expected"); 4710 } 4711 return 0; 4712 } 4713 4714 static int 4715 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata, 4716 uint8_t op_mode, uint8_t verify) 4717 { 4718 struct crypto_testsuite_params *ts_params = &testsuite_params; 4719 struct crypto_unittest_params *ut_params = &unittest_params; 4720 4721 int retval; 4722 4723 const uint8_t *plaintext = NULL; 4724 const uint8_t *ciphertext = NULL; 4725 const uint8_t *digest = NULL; 4726 unsigned int plaintext_pad_len; 4727 unsigned int plaintext_len; 4728 unsigned int ciphertext_pad_len; 4729 unsigned int ciphertext_len; 4730 uint8_t buffer[10000]; 4731 uint8_t digest_buffer[10000]; 4732 4733 struct rte_cryptodev_info dev_info; 4734 4735 /* Verify the capabilities */ 4736 struct rte_cryptodev_sym_capability_idx cap_idx; 4737 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4738 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4739 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4740 &cap_idx) == NULL) 4741 return -ENOTSUP; 4742 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4743 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4744 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4745 &cap_idx) == NULL) 4746 return -ENOTSUP; 4747 4748 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4749 return -ENOTSUP; 4750 4751 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4752 4753 uint64_t feat_flags = dev_info.feature_flags; 4754 4755 if (op_mode == IN_PLACE) { 4756 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 4757 printf("Device doesn't support in-place scatter-gather " 4758 "in both input and output mbufs.\n"); 4759 return -ENOTSUP; 4760 } 4761 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4762 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4763 printf("Device doesn't support RAW data-path APIs.\n"); 4764 return -ENOTSUP; 4765 } 4766 } else { 4767 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4768 return -ENOTSUP; 4769 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 4770 printf("Device doesn't support out-of-place scatter-gather " 4771 "in both input and output mbufs.\n"); 4772 return -ENOTSUP; 4773 } 4774 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 4775 printf("Device doesn't support digest encrypted.\n"); 4776 return -ENOTSUP; 4777 } 4778 } 4779 4780 /* Create SNOW 3G session */ 4781 retval = create_wireless_algo_auth_cipher_session( 4782 ts_params->valid_devs[0], 4783 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 4784 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 4785 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 4786 : RTE_CRYPTO_AUTH_OP_GENERATE), 4787 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4788 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4789 tdata->key.data, tdata->key.len, 4790 tdata->auth_iv.len, tdata->digest.len, 4791 tdata->cipher_iv.len); 4792 4793 if (retval < 0) 4794 return retval; 4795 4796 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4797 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4798 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4799 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4800 4801 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4802 plaintext_pad_len, 15, 0); 4803 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4804 "Failed to allocate input buffer in mempool"); 4805 4806 if (op_mode == OUT_OF_PLACE) { 4807 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4808 plaintext_pad_len, 15, 0); 4809 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4810 "Failed to allocate output buffer in mempool"); 4811 } 4812 4813 if (verify) { 4814 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 4815 tdata->ciphertext.data); 4816 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4817 ciphertext_len, buffer); 4818 debug_hexdump(stdout, "ciphertext:", ciphertext, 4819 ciphertext_len); 4820 } else { 4821 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 4822 tdata->plaintext.data); 4823 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 4824 plaintext_len, buffer); 4825 debug_hexdump(stdout, "plaintext:", plaintext, 4826 plaintext_len); 4827 } 4828 memset(buffer, 0, sizeof(buffer)); 4829 4830 /* Create SNOW 3G operation */ 4831 retval = create_wireless_algo_auth_cipher_operation( 4832 tdata->digest.data, tdata->digest.len, 4833 tdata->cipher_iv.data, tdata->cipher_iv.len, 4834 tdata->auth_iv.data, tdata->auth_iv.len, 4835 (tdata->digest.offset_bytes == 0 ? 4836 (verify ? ciphertext_pad_len : plaintext_pad_len) 4837 : tdata->digest.offset_bytes), 4838 tdata->validCipherLenInBits.len, 4839 tdata->cipher.offset_bits, 4840 tdata->validAuthLenInBits.len, 4841 tdata->auth.offset_bits, 4842 op_mode, 1, verify); 4843 4844 if (retval < 0) 4845 return retval; 4846 4847 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4848 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4849 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4850 else 4851 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4852 ut_params->op); 4853 4854 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4855 4856 ut_params->obuf = (op_mode == IN_PLACE ? 4857 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 4858 4859 if (verify) { 4860 if (ut_params->obuf) 4861 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 4862 plaintext_len, buffer); 4863 else 4864 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 4865 plaintext_len, buffer); 4866 4867 debug_hexdump(stdout, "plaintext:", plaintext, 4868 (tdata->plaintext.len >> 3) - tdata->digest.len); 4869 debug_hexdump(stdout, "plaintext expected:", 4870 tdata->plaintext.data, 4871 (tdata->plaintext.len >> 3) - tdata->digest.len); 4872 } else { 4873 if (ut_params->obuf) 4874 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4875 ciphertext_len, buffer); 4876 else 4877 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4878 ciphertext_len, buffer); 4879 4880 debug_hexdump(stdout, "ciphertext:", ciphertext, 4881 ciphertext_len); 4882 debug_hexdump(stdout, "ciphertext expected:", 4883 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 4884 4885 if (ut_params->obuf) 4886 digest = rte_pktmbuf_read(ut_params->obuf, 4887 (tdata->digest.offset_bytes == 0 ? 4888 plaintext_pad_len : tdata->digest.offset_bytes), 4889 tdata->digest.len, digest_buffer); 4890 else 4891 digest = rte_pktmbuf_read(ut_params->ibuf, 4892 (tdata->digest.offset_bytes == 0 ? 4893 plaintext_pad_len : tdata->digest.offset_bytes), 4894 tdata->digest.len, digest_buffer); 4895 4896 debug_hexdump(stdout, "digest:", digest, 4897 tdata->digest.len); 4898 debug_hexdump(stdout, "digest expected:", 4899 tdata->digest.data, tdata->digest.len); 4900 } 4901 4902 /* Validate obuf */ 4903 if (verify) { 4904 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4905 plaintext, 4906 tdata->plaintext.data, 4907 (tdata->plaintext.len - tdata->cipher.offset_bits - 4908 (tdata->digest.len << 3)), 4909 tdata->cipher.offset_bits, 4910 "SNOW 3G Plaintext data not as expected"); 4911 } else { 4912 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4913 ciphertext, 4914 tdata->ciphertext.data, 4915 (tdata->validDataLenInBits.len - 4916 tdata->cipher.offset_bits), 4917 tdata->cipher.offset_bits, 4918 "SNOW 3G Ciphertext data not as expected"); 4919 4920 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4921 digest, 4922 tdata->digest.data, 4923 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4924 "SNOW 3G Generated auth tag not as expected"); 4925 } 4926 return 0; 4927 } 4928 4929 static int 4930 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata, 4931 uint8_t op_mode, uint8_t verify) 4932 { 4933 struct crypto_testsuite_params *ts_params = &testsuite_params; 4934 struct crypto_unittest_params *ut_params = &unittest_params; 4935 4936 int retval; 4937 4938 uint8_t *plaintext = NULL, *ciphertext = NULL; 4939 unsigned int plaintext_pad_len; 4940 unsigned int plaintext_len; 4941 unsigned int ciphertext_pad_len; 4942 unsigned int ciphertext_len; 4943 4944 struct rte_cryptodev_info dev_info; 4945 4946 /* Verify the capabilities */ 4947 struct rte_cryptodev_sym_capability_idx cap_idx; 4948 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4949 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 4950 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4951 &cap_idx) == NULL) 4952 return -ENOTSUP; 4953 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4954 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4955 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4956 &cap_idx) == NULL) 4957 return -ENOTSUP; 4958 4959 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4960 4961 uint64_t feat_flags = dev_info.feature_flags; 4962 4963 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4964 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4965 printf("Device doesn't support RAW data-path APIs.\n"); 4966 return -ENOTSUP; 4967 } 4968 4969 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4970 return -ENOTSUP; 4971 4972 if (op_mode == OUT_OF_PLACE) { 4973 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4974 return -ENOTSUP; 4975 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 4976 printf("Device doesn't support digest encrypted.\n"); 4977 return -ENOTSUP; 4978 } 4979 } 4980 4981 /* Create KASUMI session */ 4982 retval = create_wireless_algo_auth_cipher_session( 4983 ts_params->valid_devs[0], 4984 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 4985 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 4986 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 4987 : RTE_CRYPTO_AUTH_OP_GENERATE), 4988 RTE_CRYPTO_AUTH_KASUMI_F9, 4989 RTE_CRYPTO_CIPHER_KASUMI_F8, 4990 tdata->key.data, tdata->key.len, 4991 0, tdata->digest.len, 4992 tdata->cipher_iv.len); 4993 4994 if (retval < 0) 4995 return retval; 4996 4997 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4998 if (op_mode == OUT_OF_PLACE) 4999 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5000 5001 /* clear mbuf payload */ 5002 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5003 rte_pktmbuf_tailroom(ut_params->ibuf)); 5004 if (op_mode == OUT_OF_PLACE) 5005 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5006 rte_pktmbuf_tailroom(ut_params->obuf)); 5007 5008 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5009 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5010 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5011 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5012 5013 if (verify) { 5014 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5015 ciphertext_pad_len); 5016 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5017 if (op_mode == OUT_OF_PLACE) 5018 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5019 debug_hexdump(stdout, "ciphertext:", ciphertext, 5020 ciphertext_len); 5021 } else { 5022 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5023 plaintext_pad_len); 5024 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5025 if (op_mode == OUT_OF_PLACE) 5026 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5027 debug_hexdump(stdout, "plaintext:", plaintext, 5028 plaintext_len); 5029 } 5030 5031 /* Create KASUMI operation */ 5032 retval = create_wireless_algo_auth_cipher_operation( 5033 tdata->digest.data, tdata->digest.len, 5034 tdata->cipher_iv.data, tdata->cipher_iv.len, 5035 NULL, 0, 5036 (tdata->digest.offset_bytes == 0 ? 5037 (verify ? ciphertext_pad_len : plaintext_pad_len) 5038 : tdata->digest.offset_bytes), 5039 tdata->validCipherLenInBits.len, 5040 tdata->validCipherOffsetInBits.len, 5041 tdata->validAuthLenInBits.len, 5042 0, 5043 op_mode, 0, verify); 5044 5045 if (retval < 0) 5046 return retval; 5047 5048 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5049 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5050 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5051 else 5052 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5053 ut_params->op); 5054 5055 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5056 5057 ut_params->obuf = (op_mode == IN_PLACE ? 5058 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5059 5060 5061 if (verify) { 5062 if (ut_params->obuf) 5063 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5064 uint8_t *); 5065 else 5066 plaintext = ciphertext; 5067 5068 debug_hexdump(stdout, "plaintext:", plaintext, 5069 (tdata->plaintext.len >> 3) - tdata->digest.len); 5070 debug_hexdump(stdout, "plaintext expected:", 5071 tdata->plaintext.data, 5072 (tdata->plaintext.len >> 3) - tdata->digest.len); 5073 } else { 5074 if (ut_params->obuf) 5075 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5076 uint8_t *); 5077 else 5078 ciphertext = plaintext; 5079 5080 debug_hexdump(stdout, "ciphertext:", ciphertext, 5081 ciphertext_len); 5082 debug_hexdump(stdout, "ciphertext expected:", 5083 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5084 5085 ut_params->digest = rte_pktmbuf_mtod( 5086 ut_params->obuf, uint8_t *) + 5087 (tdata->digest.offset_bytes == 0 ? 5088 plaintext_pad_len : tdata->digest.offset_bytes); 5089 5090 debug_hexdump(stdout, "digest:", ut_params->digest, 5091 tdata->digest.len); 5092 debug_hexdump(stdout, "digest expected:", 5093 tdata->digest.data, tdata->digest.len); 5094 } 5095 5096 /* Validate obuf */ 5097 if (verify) { 5098 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5099 plaintext, 5100 tdata->plaintext.data, 5101 tdata->plaintext.len >> 3, 5102 "KASUMI Plaintext data not as expected"); 5103 } else { 5104 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5105 ciphertext, 5106 tdata->ciphertext.data, 5107 tdata->ciphertext.len >> 3, 5108 "KASUMI Ciphertext data not as expected"); 5109 5110 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5111 ut_params->digest, 5112 tdata->digest.data, 5113 DIGEST_BYTE_LENGTH_KASUMI_F9, 5114 "KASUMI Generated auth tag not as expected"); 5115 } 5116 return 0; 5117 } 5118 5119 static int 5120 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata, 5121 uint8_t op_mode, uint8_t verify) 5122 { 5123 struct crypto_testsuite_params *ts_params = &testsuite_params; 5124 struct crypto_unittest_params *ut_params = &unittest_params; 5125 5126 int retval; 5127 5128 const uint8_t *plaintext = NULL; 5129 const uint8_t *ciphertext = NULL; 5130 const uint8_t *digest = NULL; 5131 unsigned int plaintext_pad_len; 5132 unsigned int plaintext_len; 5133 unsigned int ciphertext_pad_len; 5134 unsigned int ciphertext_len; 5135 uint8_t buffer[10000]; 5136 uint8_t digest_buffer[10000]; 5137 5138 struct rte_cryptodev_info dev_info; 5139 5140 /* Verify the capabilities */ 5141 struct rte_cryptodev_sym_capability_idx cap_idx; 5142 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5143 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5144 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5145 &cap_idx) == NULL) 5146 return -ENOTSUP; 5147 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5148 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5149 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5150 &cap_idx) == NULL) 5151 return -ENOTSUP; 5152 5153 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5154 return -ENOTSUP; 5155 5156 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5157 5158 uint64_t feat_flags = dev_info.feature_flags; 5159 5160 if (op_mode == IN_PLACE) { 5161 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5162 printf("Device doesn't support in-place scatter-gather " 5163 "in both input and output mbufs.\n"); 5164 return -ENOTSUP; 5165 } 5166 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5167 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5168 printf("Device doesn't support RAW data-path APIs.\n"); 5169 return -ENOTSUP; 5170 } 5171 } else { 5172 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5173 return -ENOTSUP; 5174 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5175 printf("Device doesn't support out-of-place scatter-gather " 5176 "in both input and output mbufs.\n"); 5177 return -ENOTSUP; 5178 } 5179 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5180 printf("Device doesn't support digest encrypted.\n"); 5181 return -ENOTSUP; 5182 } 5183 } 5184 5185 /* Create KASUMI session */ 5186 retval = create_wireless_algo_auth_cipher_session( 5187 ts_params->valid_devs[0], 5188 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5189 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5190 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5191 : RTE_CRYPTO_AUTH_OP_GENERATE), 5192 RTE_CRYPTO_AUTH_KASUMI_F9, 5193 RTE_CRYPTO_CIPHER_KASUMI_F8, 5194 tdata->key.data, tdata->key.len, 5195 0, tdata->digest.len, 5196 tdata->cipher_iv.len); 5197 5198 if (retval < 0) 5199 return retval; 5200 5201 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5202 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5203 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5204 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5205 5206 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5207 plaintext_pad_len, 15, 0); 5208 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5209 "Failed to allocate input buffer in mempool"); 5210 5211 if (op_mode == OUT_OF_PLACE) { 5212 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5213 plaintext_pad_len, 15, 0); 5214 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5215 "Failed to allocate output buffer in mempool"); 5216 } 5217 5218 if (verify) { 5219 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5220 tdata->ciphertext.data); 5221 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5222 ciphertext_len, buffer); 5223 debug_hexdump(stdout, "ciphertext:", ciphertext, 5224 ciphertext_len); 5225 } else { 5226 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5227 tdata->plaintext.data); 5228 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5229 plaintext_len, buffer); 5230 debug_hexdump(stdout, "plaintext:", plaintext, 5231 plaintext_len); 5232 } 5233 memset(buffer, 0, sizeof(buffer)); 5234 5235 /* Create KASUMI operation */ 5236 retval = create_wireless_algo_auth_cipher_operation( 5237 tdata->digest.data, tdata->digest.len, 5238 tdata->cipher_iv.data, tdata->cipher_iv.len, 5239 NULL, 0, 5240 (tdata->digest.offset_bytes == 0 ? 5241 (verify ? ciphertext_pad_len : plaintext_pad_len) 5242 : tdata->digest.offset_bytes), 5243 tdata->validCipherLenInBits.len, 5244 tdata->validCipherOffsetInBits.len, 5245 tdata->validAuthLenInBits.len, 5246 0, 5247 op_mode, 1, verify); 5248 5249 if (retval < 0) 5250 return retval; 5251 5252 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5253 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5254 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5255 else 5256 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5257 ut_params->op); 5258 5259 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5260 5261 ut_params->obuf = (op_mode == IN_PLACE ? 5262 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5263 5264 if (verify) { 5265 if (ut_params->obuf) 5266 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5267 plaintext_len, buffer); 5268 else 5269 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5270 plaintext_len, buffer); 5271 5272 debug_hexdump(stdout, "plaintext:", plaintext, 5273 (tdata->plaintext.len >> 3) - tdata->digest.len); 5274 debug_hexdump(stdout, "plaintext expected:", 5275 tdata->plaintext.data, 5276 (tdata->plaintext.len >> 3) - tdata->digest.len); 5277 } else { 5278 if (ut_params->obuf) 5279 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5280 ciphertext_len, buffer); 5281 else 5282 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5283 ciphertext_len, buffer); 5284 5285 debug_hexdump(stdout, "ciphertext:", ciphertext, 5286 ciphertext_len); 5287 debug_hexdump(stdout, "ciphertext expected:", 5288 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5289 5290 if (ut_params->obuf) 5291 digest = rte_pktmbuf_read(ut_params->obuf, 5292 (tdata->digest.offset_bytes == 0 ? 5293 plaintext_pad_len : tdata->digest.offset_bytes), 5294 tdata->digest.len, digest_buffer); 5295 else 5296 digest = rte_pktmbuf_read(ut_params->ibuf, 5297 (tdata->digest.offset_bytes == 0 ? 5298 plaintext_pad_len : tdata->digest.offset_bytes), 5299 tdata->digest.len, digest_buffer); 5300 5301 debug_hexdump(stdout, "digest:", digest, 5302 tdata->digest.len); 5303 debug_hexdump(stdout, "digest expected:", 5304 tdata->digest.data, tdata->digest.len); 5305 } 5306 5307 /* Validate obuf */ 5308 if (verify) { 5309 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5310 plaintext, 5311 tdata->plaintext.data, 5312 tdata->plaintext.len >> 3, 5313 "KASUMI Plaintext data not as expected"); 5314 } else { 5315 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5316 ciphertext, 5317 tdata->ciphertext.data, 5318 tdata->validDataLenInBits.len, 5319 "KASUMI Ciphertext data not as expected"); 5320 5321 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5322 digest, 5323 tdata->digest.data, 5324 DIGEST_BYTE_LENGTH_KASUMI_F9, 5325 "KASUMI Generated auth tag not as expected"); 5326 } 5327 return 0; 5328 } 5329 5330 static int 5331 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata) 5332 { 5333 struct crypto_testsuite_params *ts_params = &testsuite_params; 5334 struct crypto_unittest_params *ut_params = &unittest_params; 5335 5336 int retval; 5337 5338 uint8_t *plaintext, *ciphertext; 5339 unsigned plaintext_pad_len; 5340 unsigned plaintext_len; 5341 struct rte_cryptodev_info dev_info; 5342 5343 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5344 uint64_t feat_flags = dev_info.feature_flags; 5345 5346 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5347 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5348 printf("Device doesn't support RAW data-path APIs.\n"); 5349 return -ENOTSUP; 5350 } 5351 5352 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5353 return -ENOTSUP; 5354 5355 /* Verify the capabilities */ 5356 struct rte_cryptodev_sym_capability_idx cap_idx; 5357 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5358 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5359 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5360 &cap_idx) == NULL) 5361 return -ENOTSUP; 5362 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5363 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5364 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5365 &cap_idx) == NULL) 5366 return -ENOTSUP; 5367 5368 /* Create KASUMI session */ 5369 retval = create_wireless_algo_cipher_auth_session( 5370 ts_params->valid_devs[0], 5371 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5372 RTE_CRYPTO_AUTH_OP_GENERATE, 5373 RTE_CRYPTO_AUTH_KASUMI_F9, 5374 RTE_CRYPTO_CIPHER_KASUMI_F8, 5375 tdata->key.data, tdata->key.len, 5376 0, tdata->digest.len, 5377 tdata->cipher_iv.len); 5378 if (retval < 0) 5379 return retval; 5380 5381 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5382 5383 /* clear mbuf payload */ 5384 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5385 rte_pktmbuf_tailroom(ut_params->ibuf)); 5386 5387 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5388 /* Append data which is padded to a multiple of */ 5389 /* the algorithms block size */ 5390 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5391 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5392 plaintext_pad_len); 5393 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5394 5395 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5396 5397 /* Create KASUMI operation */ 5398 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 5399 tdata->digest.len, NULL, 0, 5400 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5401 tdata->cipher_iv.data, tdata->cipher_iv.len, 5402 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 5403 tdata->validCipherOffsetInBits.len, 5404 tdata->validAuthLenInBits.len, 5405 0 5406 ); 5407 if (retval < 0) 5408 return retval; 5409 5410 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5411 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5412 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5413 else 5414 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5415 ut_params->op); 5416 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5417 5418 if (ut_params->op->sym->m_dst) 5419 ut_params->obuf = ut_params->op->sym->m_dst; 5420 else 5421 ut_params->obuf = ut_params->op->sym->m_src; 5422 5423 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 5424 tdata->validCipherOffsetInBits.len >> 3); 5425 5426 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5427 + plaintext_pad_len; 5428 5429 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 5430 (tdata->validCipherOffsetInBits.len >> 3); 5431 /* Validate obuf */ 5432 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5433 ciphertext, 5434 reference_ciphertext, 5435 tdata->validCipherLenInBits.len, 5436 "KASUMI Ciphertext data not as expected"); 5437 5438 /* Validate obuf */ 5439 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5440 ut_params->digest, 5441 tdata->digest.data, 5442 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5443 "KASUMI Generated auth tag not as expected"); 5444 return 0; 5445 } 5446 5447 static int 5448 test_zuc_encryption(const struct wireless_test_data *tdata) 5449 { 5450 struct crypto_testsuite_params *ts_params = &testsuite_params; 5451 struct crypto_unittest_params *ut_params = &unittest_params; 5452 5453 int retval; 5454 uint8_t *plaintext, *ciphertext; 5455 unsigned plaintext_pad_len; 5456 unsigned plaintext_len; 5457 struct rte_cryptodev_info dev_info; 5458 5459 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5460 uint64_t feat_flags = dev_info.feature_flags; 5461 5462 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5463 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5464 printf("Device doesn't support RAW data-path APIs.\n"); 5465 return -ENOTSUP; 5466 } 5467 5468 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5469 return -ENOTSUP; 5470 5471 struct rte_cryptodev_sym_capability_idx cap_idx; 5472 5473 /* Check if device supports ZUC EEA3 */ 5474 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5475 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 5476 5477 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5478 &cap_idx) == NULL) 5479 return -ENOTSUP; 5480 5481 /* Create ZUC session */ 5482 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 5483 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5484 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5485 tdata->key.data, tdata->key.len, 5486 tdata->cipher_iv.len); 5487 if (retval < 0) 5488 return retval; 5489 5490 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5491 5492 /* Clear mbuf payload */ 5493 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5494 rte_pktmbuf_tailroom(ut_params->ibuf)); 5495 5496 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5497 /* Append data which is padded to a multiple */ 5498 /* of the algorithms block size */ 5499 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 5500 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5501 plaintext_pad_len); 5502 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5503 5504 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5505 5506 /* Create ZUC operation */ 5507 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 5508 tdata->cipher_iv.len, 5509 tdata->plaintext.len, 5510 0); 5511 if (retval < 0) 5512 return retval; 5513 5514 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5515 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5516 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 5517 else 5518 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5519 ut_params->op); 5520 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5521 5522 ut_params->obuf = ut_params->op->sym->m_dst; 5523 if (ut_params->obuf) 5524 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 5525 else 5526 ciphertext = plaintext; 5527 5528 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 5529 5530 /* Validate obuf */ 5531 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5532 ciphertext, 5533 tdata->ciphertext.data, 5534 tdata->validCipherLenInBits.len, 5535 "ZUC Ciphertext data not as expected"); 5536 return 0; 5537 } 5538 5539 static int 5540 test_zuc_encryption_sgl(const struct wireless_test_data *tdata) 5541 { 5542 struct crypto_testsuite_params *ts_params = &testsuite_params; 5543 struct crypto_unittest_params *ut_params = &unittest_params; 5544 5545 int retval; 5546 5547 unsigned int plaintext_pad_len; 5548 unsigned int plaintext_len; 5549 const uint8_t *ciphertext; 5550 uint8_t ciphertext_buffer[2048]; 5551 struct rte_cryptodev_info dev_info; 5552 5553 struct rte_cryptodev_sym_capability_idx cap_idx; 5554 5555 /* Check if device supports ZUC EEA3 */ 5556 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5557 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 5558 5559 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5560 &cap_idx) == NULL) 5561 return -ENOTSUP; 5562 5563 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5564 return -ENOTSUP; 5565 5566 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5567 5568 uint64_t feat_flags = dev_info.feature_flags; 5569 5570 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5571 printf("Device doesn't support in-place scatter-gather. " 5572 "Test Skipped.\n"); 5573 return -ENOTSUP; 5574 } 5575 5576 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5577 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5578 printf("Device doesn't support RAW data-path APIs.\n"); 5579 return -ENOTSUP; 5580 } 5581 5582 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5583 5584 /* Append data which is padded to a multiple */ 5585 /* of the algorithms block size */ 5586 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 5587 5588 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5589 plaintext_pad_len, 10, 0); 5590 5591 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5592 tdata->plaintext.data); 5593 5594 /* Create ZUC session */ 5595 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 5596 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5597 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5598 tdata->key.data, tdata->key.len, 5599 tdata->cipher_iv.len); 5600 if (retval < 0) 5601 return retval; 5602 5603 /* Clear mbuf payload */ 5604 5605 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 5606 5607 /* Create ZUC operation */ 5608 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 5609 tdata->cipher_iv.len, tdata->plaintext.len, 5610 0); 5611 if (retval < 0) 5612 return retval; 5613 5614 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5615 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5616 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 5617 else 5618 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5619 ut_params->op); 5620 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5621 5622 ut_params->obuf = ut_params->op->sym->m_dst; 5623 if (ut_params->obuf) 5624 ciphertext = rte_pktmbuf_read(ut_params->obuf, 5625 0, plaintext_len, ciphertext_buffer); 5626 else 5627 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 5628 0, plaintext_len, ciphertext_buffer); 5629 5630 /* Validate obuf */ 5631 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 5632 5633 /* Validate obuf */ 5634 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5635 ciphertext, 5636 tdata->ciphertext.data, 5637 tdata->validCipherLenInBits.len, 5638 "ZUC Ciphertext data not as expected"); 5639 5640 return 0; 5641 } 5642 5643 static int 5644 test_zuc_authentication(const struct wireless_test_data *tdata) 5645 { 5646 struct crypto_testsuite_params *ts_params = &testsuite_params; 5647 struct crypto_unittest_params *ut_params = &unittest_params; 5648 5649 int retval; 5650 unsigned plaintext_pad_len; 5651 unsigned plaintext_len; 5652 uint8_t *plaintext; 5653 5654 struct rte_cryptodev_sym_capability_idx cap_idx; 5655 struct rte_cryptodev_info dev_info; 5656 5657 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5658 uint64_t feat_flags = dev_info.feature_flags; 5659 5660 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 5661 (tdata->validAuthLenInBits.len % 8 != 0)) { 5662 printf("Device doesn't support NON-Byte Aligned Data.\n"); 5663 return -ENOTSUP; 5664 } 5665 5666 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5667 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5668 printf("Device doesn't support RAW data-path APIs.\n"); 5669 return -ENOTSUP; 5670 } 5671 5672 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5673 return -ENOTSUP; 5674 5675 /* Check if device supports ZUC EIA3 */ 5676 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5677 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 5678 5679 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5680 &cap_idx) == NULL) 5681 return -ENOTSUP; 5682 5683 /* Create ZUC session */ 5684 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 5685 tdata->key.data, tdata->key.len, 5686 tdata->auth_iv.len, tdata->digest.len, 5687 RTE_CRYPTO_AUTH_OP_GENERATE, 5688 RTE_CRYPTO_AUTH_ZUC_EIA3); 5689 if (retval < 0) 5690 return retval; 5691 5692 /* alloc mbuf and set payload */ 5693 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5694 5695 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5696 rte_pktmbuf_tailroom(ut_params->ibuf)); 5697 5698 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5699 /* Append data which is padded to a multiple of */ 5700 /* the algorithms block size */ 5701 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 5702 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5703 plaintext_pad_len); 5704 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5705 5706 /* Create ZUC operation */ 5707 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 5708 tdata->auth_iv.data, tdata->auth_iv.len, 5709 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5710 tdata->validAuthLenInBits.len, 5711 0); 5712 if (retval < 0) 5713 return retval; 5714 5715 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5716 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5717 ut_params->op, 0, 1, 1, 0); 5718 else 5719 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5720 ut_params->op); 5721 ut_params->obuf = ut_params->op->sym->m_src; 5722 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5723 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5724 + plaintext_pad_len; 5725 5726 /* Validate obuf */ 5727 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5728 ut_params->digest, 5729 tdata->digest.data, 5730 tdata->digest.len, 5731 "ZUC Generated auth tag not as expected"); 5732 5733 return 0; 5734 } 5735 5736 static int 5737 test_zuc_auth_cipher(const struct wireless_test_data *tdata, 5738 uint8_t op_mode, uint8_t verify) 5739 { 5740 struct crypto_testsuite_params *ts_params = &testsuite_params; 5741 struct crypto_unittest_params *ut_params = &unittest_params; 5742 5743 int retval; 5744 5745 uint8_t *plaintext = NULL, *ciphertext = NULL; 5746 unsigned int plaintext_pad_len; 5747 unsigned int plaintext_len; 5748 unsigned int ciphertext_pad_len; 5749 unsigned int ciphertext_len; 5750 5751 struct rte_cryptodev_info dev_info; 5752 struct rte_cryptodev_sym_capability_idx cap_idx; 5753 5754 /* Check if device supports ZUC EIA3 */ 5755 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5756 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 5757 5758 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5759 &cap_idx) == NULL) 5760 return -ENOTSUP; 5761 5762 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5763 5764 uint64_t feat_flags = dev_info.feature_flags; 5765 5766 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5767 printf("Device doesn't support digest encrypted.\n"); 5768 return -ENOTSUP; 5769 } 5770 if (op_mode == IN_PLACE) { 5771 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5772 printf("Device doesn't support in-place scatter-gather " 5773 "in both input and output mbufs.\n"); 5774 return -ENOTSUP; 5775 } 5776 5777 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5778 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5779 printf("Device doesn't support RAW data-path APIs.\n"); 5780 return -ENOTSUP; 5781 } 5782 } else { 5783 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5784 return -ENOTSUP; 5785 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5786 printf("Device doesn't support out-of-place scatter-gather " 5787 "in both input and output mbufs.\n"); 5788 return -ENOTSUP; 5789 } 5790 } 5791 5792 /* Create ZUC session */ 5793 retval = create_wireless_algo_auth_cipher_session( 5794 ts_params->valid_devs[0], 5795 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5796 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5797 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5798 : RTE_CRYPTO_AUTH_OP_GENERATE), 5799 RTE_CRYPTO_AUTH_ZUC_EIA3, 5800 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5801 tdata->key.data, tdata->key.len, 5802 tdata->auth_iv.len, tdata->digest.len, 5803 tdata->cipher_iv.len); 5804 5805 if (retval < 0) 5806 return retval; 5807 5808 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5809 if (op_mode == OUT_OF_PLACE) 5810 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5811 5812 /* clear mbuf payload */ 5813 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5814 rte_pktmbuf_tailroom(ut_params->ibuf)); 5815 if (op_mode == OUT_OF_PLACE) 5816 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5817 rte_pktmbuf_tailroom(ut_params->obuf)); 5818 5819 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5820 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5821 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5822 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5823 5824 if (verify) { 5825 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5826 ciphertext_pad_len); 5827 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5828 if (op_mode == OUT_OF_PLACE) 5829 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5830 debug_hexdump(stdout, "ciphertext:", ciphertext, 5831 ciphertext_len); 5832 } else { 5833 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5834 plaintext_pad_len); 5835 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5836 if (op_mode == OUT_OF_PLACE) 5837 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5838 debug_hexdump(stdout, "plaintext:", plaintext, 5839 plaintext_len); 5840 } 5841 5842 /* Create ZUC operation */ 5843 retval = create_wireless_algo_auth_cipher_operation( 5844 tdata->digest.data, tdata->digest.len, 5845 tdata->cipher_iv.data, tdata->cipher_iv.len, 5846 tdata->auth_iv.data, tdata->auth_iv.len, 5847 (tdata->digest.offset_bytes == 0 ? 5848 (verify ? ciphertext_pad_len : plaintext_pad_len) 5849 : tdata->digest.offset_bytes), 5850 tdata->validCipherLenInBits.len, 5851 tdata->validCipherOffsetInBits.len, 5852 tdata->validAuthLenInBits.len, 5853 0, 5854 op_mode, 0, verify); 5855 5856 if (retval < 0) 5857 return retval; 5858 5859 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5860 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5861 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5862 else 5863 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5864 ut_params->op); 5865 5866 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5867 5868 ut_params->obuf = (op_mode == IN_PLACE ? 5869 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5870 5871 5872 if (verify) { 5873 if (ut_params->obuf) 5874 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5875 uint8_t *); 5876 else 5877 plaintext = ciphertext; 5878 5879 debug_hexdump(stdout, "plaintext:", plaintext, 5880 (tdata->plaintext.len >> 3) - tdata->digest.len); 5881 debug_hexdump(stdout, "plaintext expected:", 5882 tdata->plaintext.data, 5883 (tdata->plaintext.len >> 3) - tdata->digest.len); 5884 } else { 5885 if (ut_params->obuf) 5886 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5887 uint8_t *); 5888 else 5889 ciphertext = plaintext; 5890 5891 debug_hexdump(stdout, "ciphertext:", ciphertext, 5892 ciphertext_len); 5893 debug_hexdump(stdout, "ciphertext expected:", 5894 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5895 5896 ut_params->digest = rte_pktmbuf_mtod( 5897 ut_params->obuf, uint8_t *) + 5898 (tdata->digest.offset_bytes == 0 ? 5899 plaintext_pad_len : tdata->digest.offset_bytes); 5900 5901 debug_hexdump(stdout, "digest:", ut_params->digest, 5902 tdata->digest.len); 5903 debug_hexdump(stdout, "digest expected:", 5904 tdata->digest.data, tdata->digest.len); 5905 } 5906 5907 /* Validate obuf */ 5908 if (verify) { 5909 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5910 plaintext, 5911 tdata->plaintext.data, 5912 tdata->plaintext.len >> 3, 5913 "ZUC Plaintext data not as expected"); 5914 } else { 5915 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5916 ciphertext, 5917 tdata->ciphertext.data, 5918 tdata->ciphertext.len >> 3, 5919 "ZUC Ciphertext data not as expected"); 5920 5921 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5922 ut_params->digest, 5923 tdata->digest.data, 5924 DIGEST_BYTE_LENGTH_KASUMI_F9, 5925 "ZUC Generated auth tag not as expected"); 5926 } 5927 return 0; 5928 } 5929 5930 static int 5931 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata, 5932 uint8_t op_mode, uint8_t verify) 5933 { 5934 struct crypto_testsuite_params *ts_params = &testsuite_params; 5935 struct crypto_unittest_params *ut_params = &unittest_params; 5936 5937 int retval; 5938 5939 const uint8_t *plaintext = NULL; 5940 const uint8_t *ciphertext = NULL; 5941 const uint8_t *digest = NULL; 5942 unsigned int plaintext_pad_len; 5943 unsigned int plaintext_len; 5944 unsigned int ciphertext_pad_len; 5945 unsigned int ciphertext_len; 5946 uint8_t buffer[10000]; 5947 uint8_t digest_buffer[10000]; 5948 5949 struct rte_cryptodev_info dev_info; 5950 struct rte_cryptodev_sym_capability_idx cap_idx; 5951 5952 /* Check if device supports ZUC EIA3 */ 5953 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5954 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 5955 5956 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5957 &cap_idx) == NULL) 5958 return -ENOTSUP; 5959 5960 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5961 5962 uint64_t feat_flags = dev_info.feature_flags; 5963 5964 if (op_mode == IN_PLACE) { 5965 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5966 printf("Device doesn't support in-place scatter-gather " 5967 "in both input and output mbufs.\n"); 5968 return -ENOTSUP; 5969 } 5970 5971 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5972 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5973 printf("Device doesn't support RAW data-path APIs.\n"); 5974 return -ENOTSUP; 5975 } 5976 } else { 5977 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5978 return -ENOTSUP; 5979 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5980 printf("Device doesn't support out-of-place scatter-gather " 5981 "in both input and output mbufs.\n"); 5982 return -ENOTSUP; 5983 } 5984 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5985 printf("Device doesn't support digest encrypted.\n"); 5986 return -ENOTSUP; 5987 } 5988 } 5989 5990 /* Create ZUC session */ 5991 retval = create_wireless_algo_auth_cipher_session( 5992 ts_params->valid_devs[0], 5993 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5994 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5995 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5996 : RTE_CRYPTO_AUTH_OP_GENERATE), 5997 RTE_CRYPTO_AUTH_ZUC_EIA3, 5998 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5999 tdata->key.data, tdata->key.len, 6000 tdata->auth_iv.len, tdata->digest.len, 6001 tdata->cipher_iv.len); 6002 6003 if (retval < 0) 6004 return retval; 6005 6006 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 6007 plaintext_len = ceil_byte_length(tdata->plaintext.len); 6008 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6009 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6010 6011 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 6012 plaintext_pad_len, 15, 0); 6013 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 6014 "Failed to allocate input buffer in mempool"); 6015 6016 if (op_mode == OUT_OF_PLACE) { 6017 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 6018 plaintext_pad_len, 15, 0); 6019 TEST_ASSERT_NOT_NULL(ut_params->obuf, 6020 "Failed to allocate output buffer in mempool"); 6021 } 6022 6023 if (verify) { 6024 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6025 tdata->ciphertext.data); 6026 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6027 ciphertext_len, buffer); 6028 debug_hexdump(stdout, "ciphertext:", ciphertext, 6029 ciphertext_len); 6030 } else { 6031 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6032 tdata->plaintext.data); 6033 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6034 plaintext_len, buffer); 6035 debug_hexdump(stdout, "plaintext:", plaintext, 6036 plaintext_len); 6037 } 6038 memset(buffer, 0, sizeof(buffer)); 6039 6040 /* Create ZUC operation */ 6041 retval = create_wireless_algo_auth_cipher_operation( 6042 tdata->digest.data, tdata->digest.len, 6043 tdata->cipher_iv.data, tdata->cipher_iv.len, 6044 NULL, 0, 6045 (tdata->digest.offset_bytes == 0 ? 6046 (verify ? ciphertext_pad_len : plaintext_pad_len) 6047 : tdata->digest.offset_bytes), 6048 tdata->validCipherLenInBits.len, 6049 tdata->validCipherOffsetInBits.len, 6050 tdata->validAuthLenInBits.len, 6051 0, 6052 op_mode, 1, verify); 6053 6054 if (retval < 0) 6055 return retval; 6056 6057 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6058 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6059 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 6060 else 6061 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6062 ut_params->op); 6063 6064 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6065 6066 ut_params->obuf = (op_mode == IN_PLACE ? 6067 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6068 6069 if (verify) { 6070 if (ut_params->obuf) 6071 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 6072 plaintext_len, buffer); 6073 else 6074 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6075 plaintext_len, buffer); 6076 6077 debug_hexdump(stdout, "plaintext:", plaintext, 6078 (tdata->plaintext.len >> 3) - tdata->digest.len); 6079 debug_hexdump(stdout, "plaintext expected:", 6080 tdata->plaintext.data, 6081 (tdata->plaintext.len >> 3) - tdata->digest.len); 6082 } else { 6083 if (ut_params->obuf) 6084 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 6085 ciphertext_len, buffer); 6086 else 6087 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6088 ciphertext_len, buffer); 6089 6090 debug_hexdump(stdout, "ciphertext:", ciphertext, 6091 ciphertext_len); 6092 debug_hexdump(stdout, "ciphertext expected:", 6093 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6094 6095 if (ut_params->obuf) 6096 digest = rte_pktmbuf_read(ut_params->obuf, 6097 (tdata->digest.offset_bytes == 0 ? 6098 plaintext_pad_len : tdata->digest.offset_bytes), 6099 tdata->digest.len, digest_buffer); 6100 else 6101 digest = rte_pktmbuf_read(ut_params->ibuf, 6102 (tdata->digest.offset_bytes == 0 ? 6103 plaintext_pad_len : tdata->digest.offset_bytes), 6104 tdata->digest.len, digest_buffer); 6105 6106 debug_hexdump(stdout, "digest:", digest, 6107 tdata->digest.len); 6108 debug_hexdump(stdout, "digest expected:", 6109 tdata->digest.data, tdata->digest.len); 6110 } 6111 6112 /* Validate obuf */ 6113 if (verify) { 6114 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6115 plaintext, 6116 tdata->plaintext.data, 6117 tdata->plaintext.len >> 3, 6118 "ZUC Plaintext data not as expected"); 6119 } else { 6120 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6121 ciphertext, 6122 tdata->ciphertext.data, 6123 tdata->validDataLenInBits.len, 6124 "ZUC Ciphertext data not as expected"); 6125 6126 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6127 digest, 6128 tdata->digest.data, 6129 DIGEST_BYTE_LENGTH_KASUMI_F9, 6130 "ZUC Generated auth tag not as expected"); 6131 } 6132 return 0; 6133 } 6134 6135 static int 6136 test_kasumi_encryption_test_case_1(void) 6137 { 6138 return test_kasumi_encryption(&kasumi_test_case_1); 6139 } 6140 6141 static int 6142 test_kasumi_encryption_test_case_1_sgl(void) 6143 { 6144 return test_kasumi_encryption_sgl(&kasumi_test_case_1); 6145 } 6146 6147 static int 6148 test_kasumi_encryption_test_case_1_oop(void) 6149 { 6150 return test_kasumi_encryption_oop(&kasumi_test_case_1); 6151 } 6152 6153 static int 6154 test_kasumi_encryption_test_case_1_oop_sgl(void) 6155 { 6156 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1); 6157 } 6158 6159 static int 6160 test_kasumi_encryption_test_case_2(void) 6161 { 6162 return test_kasumi_encryption(&kasumi_test_case_2); 6163 } 6164 6165 static int 6166 test_kasumi_encryption_test_case_3(void) 6167 { 6168 return test_kasumi_encryption(&kasumi_test_case_3); 6169 } 6170 6171 static int 6172 test_kasumi_encryption_test_case_4(void) 6173 { 6174 return test_kasumi_encryption(&kasumi_test_case_4); 6175 } 6176 6177 static int 6178 test_kasumi_encryption_test_case_5(void) 6179 { 6180 return test_kasumi_encryption(&kasumi_test_case_5); 6181 } 6182 6183 static int 6184 test_kasumi_decryption_test_case_1(void) 6185 { 6186 return test_kasumi_decryption(&kasumi_test_case_1); 6187 } 6188 6189 static int 6190 test_kasumi_decryption_test_case_1_oop(void) 6191 { 6192 return test_kasumi_decryption_oop(&kasumi_test_case_1); 6193 } 6194 6195 static int 6196 test_kasumi_decryption_test_case_2(void) 6197 { 6198 return test_kasumi_decryption(&kasumi_test_case_2); 6199 } 6200 6201 static int 6202 test_kasumi_decryption_test_case_3(void) 6203 { 6204 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6205 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6206 return -ENOTSUP; 6207 return test_kasumi_decryption(&kasumi_test_case_3); 6208 } 6209 6210 static int 6211 test_kasumi_decryption_test_case_4(void) 6212 { 6213 return test_kasumi_decryption(&kasumi_test_case_4); 6214 } 6215 6216 static int 6217 test_kasumi_decryption_test_case_5(void) 6218 { 6219 return test_kasumi_decryption(&kasumi_test_case_5); 6220 } 6221 static int 6222 test_snow3g_encryption_test_case_1(void) 6223 { 6224 return test_snow3g_encryption(&snow3g_test_case_1); 6225 } 6226 6227 static int 6228 test_snow3g_encryption_test_case_1_oop(void) 6229 { 6230 return test_snow3g_encryption_oop(&snow3g_test_case_1); 6231 } 6232 6233 static int 6234 test_snow3g_encryption_test_case_1_oop_sgl(void) 6235 { 6236 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1); 6237 } 6238 6239 6240 static int 6241 test_snow3g_encryption_test_case_1_offset_oop(void) 6242 { 6243 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); 6244 } 6245 6246 static int 6247 test_snow3g_encryption_test_case_2(void) 6248 { 6249 return test_snow3g_encryption(&snow3g_test_case_2); 6250 } 6251 6252 static int 6253 test_snow3g_encryption_test_case_3(void) 6254 { 6255 return test_snow3g_encryption(&snow3g_test_case_3); 6256 } 6257 6258 static int 6259 test_snow3g_encryption_test_case_4(void) 6260 { 6261 return test_snow3g_encryption(&snow3g_test_case_4); 6262 } 6263 6264 static int 6265 test_snow3g_encryption_test_case_5(void) 6266 { 6267 return test_snow3g_encryption(&snow3g_test_case_5); 6268 } 6269 6270 static int 6271 test_snow3g_decryption_test_case_1(void) 6272 { 6273 return test_snow3g_decryption(&snow3g_test_case_1); 6274 } 6275 6276 static int 6277 test_snow3g_decryption_test_case_1_oop(void) 6278 { 6279 return test_snow3g_decryption_oop(&snow3g_test_case_1); 6280 } 6281 6282 static int 6283 test_snow3g_decryption_test_case_2(void) 6284 { 6285 return test_snow3g_decryption(&snow3g_test_case_2); 6286 } 6287 6288 static int 6289 test_snow3g_decryption_test_case_3(void) 6290 { 6291 return test_snow3g_decryption(&snow3g_test_case_3); 6292 } 6293 6294 static int 6295 test_snow3g_decryption_test_case_4(void) 6296 { 6297 return test_snow3g_decryption(&snow3g_test_case_4); 6298 } 6299 6300 static int 6301 test_snow3g_decryption_test_case_5(void) 6302 { 6303 return test_snow3g_decryption(&snow3g_test_case_5); 6304 } 6305 6306 /* 6307 * Function prepares snow3g_hash_test_data from snow3g_test_data. 6308 * Pattern digest from snow3g_test_data must be allocated as 6309 * 4 last bytes in plaintext. 6310 */ 6311 static void 6312 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern, 6313 struct snow3g_hash_test_data *output) 6314 { 6315 if ((pattern != NULL) && (output != NULL)) { 6316 output->key.len = pattern->key.len; 6317 6318 memcpy(output->key.data, 6319 pattern->key.data, pattern->key.len); 6320 6321 output->auth_iv.len = pattern->auth_iv.len; 6322 6323 memcpy(output->auth_iv.data, 6324 pattern->auth_iv.data, pattern->auth_iv.len); 6325 6326 output->plaintext.len = pattern->plaintext.len; 6327 6328 memcpy(output->plaintext.data, 6329 pattern->plaintext.data, pattern->plaintext.len >> 3); 6330 6331 output->digest.len = pattern->digest.len; 6332 6333 memcpy(output->digest.data, 6334 &pattern->plaintext.data[pattern->digest.offset_bytes], 6335 pattern->digest.len); 6336 6337 output->validAuthLenInBits.len = 6338 pattern->validAuthLenInBits.len; 6339 } 6340 } 6341 6342 /* 6343 * Test case verify computed cipher and digest from snow3g_test_case_7 data. 6344 */ 6345 static int 6346 test_snow3g_decryption_with_digest_test_case_1(void) 6347 { 6348 struct snow3g_hash_test_data snow3g_hash_data; 6349 struct rte_cryptodev_info dev_info; 6350 struct crypto_testsuite_params *ts_params = &testsuite_params; 6351 6352 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6353 uint64_t feat_flags = dev_info.feature_flags; 6354 6355 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6356 printf("Device doesn't support encrypted digest operations.\n"); 6357 return -ENOTSUP; 6358 } 6359 6360 /* 6361 * Function prepare data for hash veryfication test case. 6362 * Digest is allocated in 4 last bytes in plaintext, pattern. 6363 */ 6364 snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data); 6365 6366 return test_snow3g_decryption(&snow3g_test_case_7) & 6367 test_snow3g_authentication_verify(&snow3g_hash_data); 6368 } 6369 6370 static int 6371 test_snow3g_cipher_auth_test_case_1(void) 6372 { 6373 return test_snow3g_cipher_auth(&snow3g_test_case_3); 6374 } 6375 6376 static int 6377 test_snow3g_auth_cipher_test_case_1(void) 6378 { 6379 return test_snow3g_auth_cipher( 6380 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0); 6381 } 6382 6383 static int 6384 test_snow3g_auth_cipher_test_case_2(void) 6385 { 6386 return test_snow3g_auth_cipher( 6387 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0); 6388 } 6389 6390 static int 6391 test_snow3g_auth_cipher_test_case_2_oop(void) 6392 { 6393 return test_snow3g_auth_cipher( 6394 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6395 } 6396 6397 static int 6398 test_snow3g_auth_cipher_part_digest_enc(void) 6399 { 6400 return test_snow3g_auth_cipher( 6401 &snow3g_auth_cipher_partial_digest_encryption, 6402 IN_PLACE, 0); 6403 } 6404 6405 static int 6406 test_snow3g_auth_cipher_part_digest_enc_oop(void) 6407 { 6408 return test_snow3g_auth_cipher( 6409 &snow3g_auth_cipher_partial_digest_encryption, 6410 OUT_OF_PLACE, 0); 6411 } 6412 6413 static int 6414 test_snow3g_auth_cipher_test_case_3_sgl(void) 6415 { 6416 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6417 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6418 return -ENOTSUP; 6419 return test_snow3g_auth_cipher_sgl( 6420 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0); 6421 } 6422 6423 static int 6424 test_snow3g_auth_cipher_test_case_3_oop_sgl(void) 6425 { 6426 return test_snow3g_auth_cipher_sgl( 6427 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0); 6428 } 6429 6430 static int 6431 test_snow3g_auth_cipher_part_digest_enc_sgl(void) 6432 { 6433 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6434 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6435 return -ENOTSUP; 6436 return test_snow3g_auth_cipher_sgl( 6437 &snow3g_auth_cipher_partial_digest_encryption, 6438 IN_PLACE, 0); 6439 } 6440 6441 static int 6442 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void) 6443 { 6444 return test_snow3g_auth_cipher_sgl( 6445 &snow3g_auth_cipher_partial_digest_encryption, 6446 OUT_OF_PLACE, 0); 6447 } 6448 6449 static int 6450 test_snow3g_auth_cipher_verify_test_case_1(void) 6451 { 6452 return test_snow3g_auth_cipher( 6453 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1); 6454 } 6455 6456 static int 6457 test_snow3g_auth_cipher_verify_test_case_2(void) 6458 { 6459 return test_snow3g_auth_cipher( 6460 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1); 6461 } 6462 6463 static int 6464 test_snow3g_auth_cipher_verify_test_case_2_oop(void) 6465 { 6466 return test_snow3g_auth_cipher( 6467 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 6468 } 6469 6470 static int 6471 test_snow3g_auth_cipher_verify_part_digest_enc(void) 6472 { 6473 return test_snow3g_auth_cipher( 6474 &snow3g_auth_cipher_partial_digest_encryption, 6475 IN_PLACE, 1); 6476 } 6477 6478 static int 6479 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void) 6480 { 6481 return test_snow3g_auth_cipher( 6482 &snow3g_auth_cipher_partial_digest_encryption, 6483 OUT_OF_PLACE, 1); 6484 } 6485 6486 static int 6487 test_snow3g_auth_cipher_verify_test_case_3_sgl(void) 6488 { 6489 return test_snow3g_auth_cipher_sgl( 6490 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1); 6491 } 6492 6493 static int 6494 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void) 6495 { 6496 return test_snow3g_auth_cipher_sgl( 6497 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1); 6498 } 6499 6500 static int 6501 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void) 6502 { 6503 return test_snow3g_auth_cipher_sgl( 6504 &snow3g_auth_cipher_partial_digest_encryption, 6505 IN_PLACE, 1); 6506 } 6507 6508 static int 6509 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void) 6510 { 6511 return test_snow3g_auth_cipher_sgl( 6512 &snow3g_auth_cipher_partial_digest_encryption, 6513 OUT_OF_PLACE, 1); 6514 } 6515 6516 static int 6517 test_snow3g_auth_cipher_with_digest_test_case_1(void) 6518 { 6519 return test_snow3g_auth_cipher( 6520 &snow3g_test_case_7, IN_PLACE, 0); 6521 } 6522 6523 static int 6524 test_kasumi_auth_cipher_test_case_1(void) 6525 { 6526 return test_kasumi_auth_cipher( 6527 &kasumi_test_case_3, IN_PLACE, 0); 6528 } 6529 6530 static int 6531 test_kasumi_auth_cipher_test_case_2(void) 6532 { 6533 return test_kasumi_auth_cipher( 6534 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 6535 } 6536 6537 static int 6538 test_kasumi_auth_cipher_test_case_2_oop(void) 6539 { 6540 return test_kasumi_auth_cipher( 6541 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6542 } 6543 6544 static int 6545 test_kasumi_auth_cipher_test_case_2_sgl(void) 6546 { 6547 return test_kasumi_auth_cipher_sgl( 6548 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 6549 } 6550 6551 static int 6552 test_kasumi_auth_cipher_test_case_2_oop_sgl(void) 6553 { 6554 return test_kasumi_auth_cipher_sgl( 6555 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6556 } 6557 6558 static int 6559 test_kasumi_auth_cipher_verify_test_case_1(void) 6560 { 6561 return test_kasumi_auth_cipher( 6562 &kasumi_test_case_3, IN_PLACE, 1); 6563 } 6564 6565 static int 6566 test_kasumi_auth_cipher_verify_test_case_2(void) 6567 { 6568 return test_kasumi_auth_cipher( 6569 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 6570 } 6571 6572 static int 6573 test_kasumi_auth_cipher_verify_test_case_2_oop(void) 6574 { 6575 return test_kasumi_auth_cipher( 6576 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 6577 } 6578 6579 static int 6580 test_kasumi_auth_cipher_verify_test_case_2_sgl(void) 6581 { 6582 return test_kasumi_auth_cipher_sgl( 6583 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 6584 } 6585 6586 static int 6587 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void) 6588 { 6589 return test_kasumi_auth_cipher_sgl( 6590 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 6591 } 6592 6593 static int 6594 test_kasumi_cipher_auth_test_case_1(void) 6595 { 6596 return test_kasumi_cipher_auth(&kasumi_test_case_6); 6597 } 6598 6599 static int 6600 test_zuc_encryption_test_case_1(void) 6601 { 6602 return test_zuc_encryption(&zuc_test_case_cipher_193b); 6603 } 6604 6605 static int 6606 test_zuc_encryption_test_case_2(void) 6607 { 6608 return test_zuc_encryption(&zuc_test_case_cipher_800b); 6609 } 6610 6611 static int 6612 test_zuc_encryption_test_case_3(void) 6613 { 6614 return test_zuc_encryption(&zuc_test_case_cipher_1570b); 6615 } 6616 6617 static int 6618 test_zuc_encryption_test_case_4(void) 6619 { 6620 return test_zuc_encryption(&zuc_test_case_cipher_2798b); 6621 } 6622 6623 static int 6624 test_zuc_encryption_test_case_5(void) 6625 { 6626 return test_zuc_encryption(&zuc_test_case_cipher_4019b); 6627 } 6628 6629 static int 6630 test_zuc_encryption_test_case_6_sgl(void) 6631 { 6632 return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b); 6633 } 6634 6635 static int 6636 test_zuc_hash_generate_test_case_1(void) 6637 { 6638 return test_zuc_authentication(&zuc_test_case_auth_1b); 6639 } 6640 6641 static int 6642 test_zuc_hash_generate_test_case_2(void) 6643 { 6644 return test_zuc_authentication(&zuc_test_case_auth_90b); 6645 } 6646 6647 static int 6648 test_zuc_hash_generate_test_case_3(void) 6649 { 6650 return test_zuc_authentication(&zuc_test_case_auth_577b); 6651 } 6652 6653 static int 6654 test_zuc_hash_generate_test_case_4(void) 6655 { 6656 return test_zuc_authentication(&zuc_test_case_auth_2079b); 6657 } 6658 6659 static int 6660 test_zuc_hash_generate_test_case_5(void) 6661 { 6662 return test_zuc_authentication(&zuc_test_auth_5670b); 6663 } 6664 6665 static int 6666 test_zuc_hash_generate_test_case_6(void) 6667 { 6668 return test_zuc_authentication(&zuc_test_case_auth_128b); 6669 } 6670 6671 static int 6672 test_zuc_hash_generate_test_case_7(void) 6673 { 6674 return test_zuc_authentication(&zuc_test_case_auth_2080b); 6675 } 6676 6677 static int 6678 test_zuc_hash_generate_test_case_8(void) 6679 { 6680 return test_zuc_authentication(&zuc_test_case_auth_584b); 6681 } 6682 6683 static int 6684 test_zuc_cipher_auth_test_case_1(void) 6685 { 6686 return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b); 6687 } 6688 6689 static int 6690 test_zuc_cipher_auth_test_case_2(void) 6691 { 6692 return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b); 6693 } 6694 6695 static int 6696 test_zuc_auth_cipher_test_case_1(void) 6697 { 6698 return test_zuc_auth_cipher( 6699 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 6700 } 6701 6702 static int 6703 test_zuc_auth_cipher_test_case_1_oop(void) 6704 { 6705 return test_zuc_auth_cipher( 6706 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 6707 } 6708 6709 static int 6710 test_zuc_auth_cipher_test_case_1_sgl(void) 6711 { 6712 return test_zuc_auth_cipher_sgl( 6713 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 6714 } 6715 6716 static int 6717 test_zuc_auth_cipher_test_case_1_oop_sgl(void) 6718 { 6719 return test_zuc_auth_cipher_sgl( 6720 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 6721 } 6722 6723 static int 6724 test_zuc_auth_cipher_verify_test_case_1(void) 6725 { 6726 return test_zuc_auth_cipher( 6727 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 6728 } 6729 6730 static int 6731 test_zuc_auth_cipher_verify_test_case_1_oop(void) 6732 { 6733 return test_zuc_auth_cipher( 6734 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 6735 } 6736 6737 static int 6738 test_zuc_auth_cipher_verify_test_case_1_sgl(void) 6739 { 6740 return test_zuc_auth_cipher_sgl( 6741 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 6742 } 6743 6744 static int 6745 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void) 6746 { 6747 return test_zuc_auth_cipher_sgl( 6748 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 6749 } 6750 6751 static int 6752 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata) 6753 { 6754 uint8_t dev_id = testsuite_params.valid_devs[0]; 6755 6756 struct rte_cryptodev_sym_capability_idx cap_idx; 6757 6758 /* Check if device supports particular cipher algorithm */ 6759 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 6760 cap_idx.algo.cipher = tdata->cipher_algo; 6761 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 6762 return -ENOTSUP; 6763 6764 /* Check if device supports particular hash algorithm */ 6765 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 6766 cap_idx.algo.auth = tdata->auth_algo; 6767 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 6768 return -ENOTSUP; 6769 6770 return 0; 6771 } 6772 6773 static int 6774 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata, 6775 uint8_t op_mode, uint8_t verify) 6776 { 6777 struct crypto_testsuite_params *ts_params = &testsuite_params; 6778 struct crypto_unittest_params *ut_params = &unittest_params; 6779 6780 int retval; 6781 6782 uint8_t *plaintext = NULL, *ciphertext = NULL; 6783 unsigned int plaintext_pad_len; 6784 unsigned int plaintext_len; 6785 unsigned int ciphertext_pad_len; 6786 unsigned int ciphertext_len; 6787 6788 struct rte_cryptodev_info dev_info; 6789 struct rte_crypto_op *op; 6790 6791 /* Check if device supports particular algorithms separately */ 6792 if (test_mixed_check_if_unsupported(tdata)) 6793 return -ENOTSUP; 6794 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6795 return -ENOTSUP; 6796 6797 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6798 6799 uint64_t feat_flags = dev_info.feature_flags; 6800 6801 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6802 printf("Device doesn't support digest encrypted.\n"); 6803 return -ENOTSUP; 6804 } 6805 6806 /* Create the session */ 6807 if (verify) 6808 retval = create_wireless_algo_cipher_auth_session( 6809 ts_params->valid_devs[0], 6810 RTE_CRYPTO_CIPHER_OP_DECRYPT, 6811 RTE_CRYPTO_AUTH_OP_VERIFY, 6812 tdata->auth_algo, 6813 tdata->cipher_algo, 6814 tdata->auth_key.data, tdata->auth_key.len, 6815 tdata->auth_iv.len, tdata->digest_enc.len, 6816 tdata->cipher_iv.len); 6817 else 6818 retval = create_wireless_algo_auth_cipher_session( 6819 ts_params->valid_devs[0], 6820 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6821 RTE_CRYPTO_AUTH_OP_GENERATE, 6822 tdata->auth_algo, 6823 tdata->cipher_algo, 6824 tdata->auth_key.data, tdata->auth_key.len, 6825 tdata->auth_iv.len, tdata->digest_enc.len, 6826 tdata->cipher_iv.len); 6827 if (retval < 0) 6828 return retval; 6829 6830 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6831 if (op_mode == OUT_OF_PLACE) 6832 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6833 6834 /* clear mbuf payload */ 6835 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6836 rte_pktmbuf_tailroom(ut_params->ibuf)); 6837 if (op_mode == OUT_OF_PLACE) { 6838 6839 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 6840 rte_pktmbuf_tailroom(ut_params->obuf)); 6841 } 6842 6843 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 6844 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 6845 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6846 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6847 6848 if (verify) { 6849 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6850 ciphertext_pad_len); 6851 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6852 if (op_mode == OUT_OF_PLACE) 6853 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 6854 debug_hexdump(stdout, "ciphertext:", ciphertext, 6855 ciphertext_len); 6856 } else { 6857 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6858 plaintext_pad_len); 6859 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6860 if (op_mode == OUT_OF_PLACE) 6861 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 6862 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6863 } 6864 6865 /* Create the operation */ 6866 retval = create_wireless_algo_auth_cipher_operation( 6867 tdata->digest_enc.data, tdata->digest_enc.len, 6868 tdata->cipher_iv.data, tdata->cipher_iv.len, 6869 tdata->auth_iv.data, tdata->auth_iv.len, 6870 (tdata->digest_enc.offset == 0 ? 6871 plaintext_pad_len 6872 : tdata->digest_enc.offset), 6873 tdata->validCipherLen.len_bits, 6874 tdata->cipher.offset_bits, 6875 tdata->validAuthLen.len_bits, 6876 tdata->auth.offset_bits, 6877 op_mode, 0, verify); 6878 6879 if (retval < 0) 6880 return retval; 6881 6882 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 6883 6884 /* Check if the op failed because the device doesn't */ 6885 /* support this particular combination of algorithms */ 6886 if (op == NULL && ut_params->op->status == 6887 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 6888 printf("Device doesn't support this mixed combination. " 6889 "Test Skipped.\n"); 6890 return -ENOTSUP; 6891 } 6892 ut_params->op = op; 6893 6894 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6895 6896 ut_params->obuf = (op_mode == IN_PLACE ? 6897 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6898 6899 if (verify) { 6900 if (ut_params->obuf) 6901 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 6902 uint8_t *); 6903 else 6904 plaintext = ciphertext + 6905 (tdata->cipher.offset_bits >> 3); 6906 6907 debug_hexdump(stdout, "plaintext:", plaintext, 6908 tdata->plaintext.len_bits >> 3); 6909 debug_hexdump(stdout, "plaintext expected:", 6910 tdata->plaintext.data, 6911 tdata->plaintext.len_bits >> 3); 6912 } else { 6913 if (ut_params->obuf) 6914 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 6915 uint8_t *); 6916 else 6917 ciphertext = plaintext; 6918 6919 debug_hexdump(stdout, "ciphertext:", ciphertext, 6920 ciphertext_len); 6921 debug_hexdump(stdout, "ciphertext expected:", 6922 tdata->ciphertext.data, 6923 tdata->ciphertext.len_bits >> 3); 6924 6925 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 6926 + (tdata->digest_enc.offset == 0 ? 6927 plaintext_pad_len : tdata->digest_enc.offset); 6928 6929 debug_hexdump(stdout, "digest:", ut_params->digest, 6930 tdata->digest_enc.len); 6931 debug_hexdump(stdout, "digest expected:", 6932 tdata->digest_enc.data, 6933 tdata->digest_enc.len); 6934 } 6935 6936 /* Validate obuf */ 6937 if (verify) { 6938 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6939 plaintext, 6940 tdata->plaintext.data, 6941 tdata->plaintext.len_bits >> 3, 6942 "Plaintext data not as expected"); 6943 } else { 6944 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6945 ciphertext, 6946 tdata->ciphertext.data, 6947 tdata->validDataLen.len_bits, 6948 "Ciphertext data not as expected"); 6949 6950 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6951 ut_params->digest, 6952 tdata->digest_enc.data, 6953 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 6954 "Generated auth tag not as expected"); 6955 } 6956 6957 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 6958 "crypto op processing failed"); 6959 6960 return 0; 6961 } 6962 6963 static int 6964 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata, 6965 uint8_t op_mode, uint8_t verify) 6966 { 6967 struct crypto_testsuite_params *ts_params = &testsuite_params; 6968 struct crypto_unittest_params *ut_params = &unittest_params; 6969 6970 int retval; 6971 6972 const uint8_t *plaintext = NULL; 6973 const uint8_t *ciphertext = NULL; 6974 const uint8_t *digest = NULL; 6975 unsigned int plaintext_pad_len; 6976 unsigned int plaintext_len; 6977 unsigned int ciphertext_pad_len; 6978 unsigned int ciphertext_len; 6979 uint8_t buffer[10000]; 6980 uint8_t digest_buffer[10000]; 6981 6982 struct rte_cryptodev_info dev_info; 6983 struct rte_crypto_op *op; 6984 6985 /* Check if device supports particular algorithms */ 6986 if (test_mixed_check_if_unsupported(tdata)) 6987 return -ENOTSUP; 6988 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6989 return -ENOTSUP; 6990 6991 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6992 6993 uint64_t feat_flags = dev_info.feature_flags; 6994 6995 if (op_mode == IN_PLACE) { 6996 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6997 printf("Device doesn't support in-place scatter-gather " 6998 "in both input and output mbufs.\n"); 6999 return -ENOTSUP; 7000 } 7001 } else { 7002 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 7003 printf("Device doesn't support out-of-place scatter-gather " 7004 "in both input and output mbufs.\n"); 7005 return -ENOTSUP; 7006 } 7007 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 7008 printf("Device doesn't support digest encrypted.\n"); 7009 return -ENOTSUP; 7010 } 7011 } 7012 7013 /* Create the session */ 7014 if (verify) 7015 retval = create_wireless_algo_cipher_auth_session( 7016 ts_params->valid_devs[0], 7017 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7018 RTE_CRYPTO_AUTH_OP_VERIFY, 7019 tdata->auth_algo, 7020 tdata->cipher_algo, 7021 tdata->auth_key.data, tdata->auth_key.len, 7022 tdata->auth_iv.len, tdata->digest_enc.len, 7023 tdata->cipher_iv.len); 7024 else 7025 retval = create_wireless_algo_auth_cipher_session( 7026 ts_params->valid_devs[0], 7027 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7028 RTE_CRYPTO_AUTH_OP_GENERATE, 7029 tdata->auth_algo, 7030 tdata->cipher_algo, 7031 tdata->auth_key.data, tdata->auth_key.len, 7032 tdata->auth_iv.len, tdata->digest_enc.len, 7033 tdata->cipher_iv.len); 7034 if (retval < 0) 7035 return retval; 7036 7037 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 7038 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 7039 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 7040 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 7041 7042 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 7043 ciphertext_pad_len, 15, 0); 7044 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 7045 "Failed to allocate input buffer in mempool"); 7046 7047 if (op_mode == OUT_OF_PLACE) { 7048 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 7049 plaintext_pad_len, 15, 0); 7050 TEST_ASSERT_NOT_NULL(ut_params->obuf, 7051 "Failed to allocate output buffer in mempool"); 7052 } 7053 7054 if (verify) { 7055 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 7056 tdata->ciphertext.data); 7057 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7058 ciphertext_len, buffer); 7059 debug_hexdump(stdout, "ciphertext:", ciphertext, 7060 ciphertext_len); 7061 } else { 7062 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 7063 tdata->plaintext.data); 7064 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7065 plaintext_len, buffer); 7066 debug_hexdump(stdout, "plaintext:", plaintext, 7067 plaintext_len); 7068 } 7069 memset(buffer, 0, sizeof(buffer)); 7070 7071 /* Create the operation */ 7072 retval = create_wireless_algo_auth_cipher_operation( 7073 tdata->digest_enc.data, tdata->digest_enc.len, 7074 tdata->cipher_iv.data, tdata->cipher_iv.len, 7075 tdata->auth_iv.data, tdata->auth_iv.len, 7076 (tdata->digest_enc.offset == 0 ? 7077 plaintext_pad_len 7078 : tdata->digest_enc.offset), 7079 tdata->validCipherLen.len_bits, 7080 tdata->cipher.offset_bits, 7081 tdata->validAuthLen.len_bits, 7082 tdata->auth.offset_bits, 7083 op_mode, 1, verify); 7084 7085 if (retval < 0) 7086 return retval; 7087 7088 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 7089 7090 /* Check if the op failed because the device doesn't */ 7091 /* support this particular combination of algorithms */ 7092 if (op == NULL && ut_params->op->status == 7093 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 7094 printf("Device doesn't support this mixed combination. " 7095 "Test Skipped.\n"); 7096 return -ENOTSUP; 7097 } 7098 ut_params->op = op; 7099 7100 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 7101 7102 ut_params->obuf = (op_mode == IN_PLACE ? 7103 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 7104 7105 if (verify) { 7106 if (ut_params->obuf) 7107 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 7108 plaintext_len, buffer); 7109 else 7110 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7111 plaintext_len, buffer); 7112 7113 debug_hexdump(stdout, "plaintext:", plaintext, 7114 (tdata->plaintext.len_bits >> 3) - 7115 tdata->digest_enc.len); 7116 debug_hexdump(stdout, "plaintext expected:", 7117 tdata->plaintext.data, 7118 (tdata->plaintext.len_bits >> 3) - 7119 tdata->digest_enc.len); 7120 } else { 7121 if (ut_params->obuf) 7122 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 7123 ciphertext_len, buffer); 7124 else 7125 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7126 ciphertext_len, buffer); 7127 7128 debug_hexdump(stdout, "ciphertext:", ciphertext, 7129 ciphertext_len); 7130 debug_hexdump(stdout, "ciphertext expected:", 7131 tdata->ciphertext.data, 7132 tdata->ciphertext.len_bits >> 3); 7133 7134 if (ut_params->obuf) 7135 digest = rte_pktmbuf_read(ut_params->obuf, 7136 (tdata->digest_enc.offset == 0 ? 7137 plaintext_pad_len : 7138 tdata->digest_enc.offset), 7139 tdata->digest_enc.len, digest_buffer); 7140 else 7141 digest = rte_pktmbuf_read(ut_params->ibuf, 7142 (tdata->digest_enc.offset == 0 ? 7143 plaintext_pad_len : 7144 tdata->digest_enc.offset), 7145 tdata->digest_enc.len, digest_buffer); 7146 7147 debug_hexdump(stdout, "digest:", digest, 7148 tdata->digest_enc.len); 7149 debug_hexdump(stdout, "digest expected:", 7150 tdata->digest_enc.data, tdata->digest_enc.len); 7151 } 7152 7153 /* Validate obuf */ 7154 if (verify) { 7155 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7156 plaintext, 7157 tdata->plaintext.data, 7158 tdata->plaintext.len_bits >> 3, 7159 "Plaintext data not as expected"); 7160 } else { 7161 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7162 ciphertext, 7163 tdata->ciphertext.data, 7164 tdata->validDataLen.len_bits, 7165 "Ciphertext data not as expected"); 7166 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7167 digest, 7168 tdata->digest_enc.data, 7169 tdata->digest_enc.len, 7170 "Generated auth tag not as expected"); 7171 } 7172 7173 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7174 "crypto op processing failed"); 7175 7176 return 0; 7177 } 7178 7179 /** AUTH AES CMAC + CIPHER AES CTR */ 7180 7181 static int 7182 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7183 { 7184 return test_mixed_auth_cipher( 7185 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7186 } 7187 7188 static int 7189 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7190 { 7191 return test_mixed_auth_cipher( 7192 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7193 } 7194 7195 static int 7196 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7197 { 7198 return test_mixed_auth_cipher_sgl( 7199 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7200 } 7201 7202 static int 7203 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7204 { 7205 return test_mixed_auth_cipher_sgl( 7206 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7207 } 7208 7209 static int 7210 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7211 { 7212 return test_mixed_auth_cipher( 7213 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7214 } 7215 7216 static int 7217 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7218 { 7219 return test_mixed_auth_cipher( 7220 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7221 } 7222 7223 static int 7224 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7225 { 7226 return test_mixed_auth_cipher_sgl( 7227 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7228 } 7229 7230 static int 7231 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7232 { 7233 return test_mixed_auth_cipher_sgl( 7234 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7235 } 7236 7237 /** MIXED AUTH + CIPHER */ 7238 7239 static int 7240 test_auth_zuc_cipher_snow_test_case_1(void) 7241 { 7242 return test_mixed_auth_cipher( 7243 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7244 } 7245 7246 static int 7247 test_verify_auth_zuc_cipher_snow_test_case_1(void) 7248 { 7249 return test_mixed_auth_cipher( 7250 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7251 } 7252 7253 static int 7254 test_auth_aes_cmac_cipher_snow_test_case_1(void) 7255 { 7256 return test_mixed_auth_cipher( 7257 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7258 } 7259 7260 static int 7261 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void) 7262 { 7263 return test_mixed_auth_cipher( 7264 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7265 } 7266 7267 static int 7268 test_auth_zuc_cipher_aes_ctr_test_case_1(void) 7269 { 7270 return test_mixed_auth_cipher( 7271 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7272 } 7273 7274 static int 7275 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void) 7276 { 7277 return test_mixed_auth_cipher( 7278 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7279 } 7280 7281 static int 7282 test_auth_snow_cipher_aes_ctr_test_case_1(void) 7283 { 7284 return test_mixed_auth_cipher( 7285 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7286 } 7287 7288 static int 7289 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void) 7290 { 7291 return test_mixed_auth_cipher( 7292 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7293 } 7294 7295 static int 7296 test_auth_snow_cipher_zuc_test_case_1(void) 7297 { 7298 return test_mixed_auth_cipher( 7299 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7300 } 7301 7302 static int 7303 test_verify_auth_snow_cipher_zuc_test_case_1(void) 7304 { 7305 return test_mixed_auth_cipher( 7306 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7307 } 7308 7309 static int 7310 test_auth_aes_cmac_cipher_zuc_test_case_1(void) 7311 { 7312 return test_mixed_auth_cipher( 7313 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7314 } 7315 7316 static int 7317 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void) 7318 { 7319 return test_mixed_auth_cipher( 7320 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7321 } 7322 7323 static int 7324 test_auth_null_cipher_snow_test_case_1(void) 7325 { 7326 return test_mixed_auth_cipher( 7327 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7328 } 7329 7330 static int 7331 test_verify_auth_null_cipher_snow_test_case_1(void) 7332 { 7333 return test_mixed_auth_cipher( 7334 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7335 } 7336 7337 static int 7338 test_auth_null_cipher_zuc_test_case_1(void) 7339 { 7340 return test_mixed_auth_cipher( 7341 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7342 } 7343 7344 static int 7345 test_verify_auth_null_cipher_zuc_test_case_1(void) 7346 { 7347 return test_mixed_auth_cipher( 7348 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7349 } 7350 7351 static int 7352 test_auth_snow_cipher_null_test_case_1(void) 7353 { 7354 return test_mixed_auth_cipher( 7355 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7356 } 7357 7358 static int 7359 test_verify_auth_snow_cipher_null_test_case_1(void) 7360 { 7361 return test_mixed_auth_cipher( 7362 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7363 } 7364 7365 static int 7366 test_auth_zuc_cipher_null_test_case_1(void) 7367 { 7368 return test_mixed_auth_cipher( 7369 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7370 } 7371 7372 static int 7373 test_verify_auth_zuc_cipher_null_test_case_1(void) 7374 { 7375 return test_mixed_auth_cipher( 7376 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7377 } 7378 7379 static int 7380 test_auth_null_cipher_aes_ctr_test_case_1(void) 7381 { 7382 return test_mixed_auth_cipher( 7383 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7384 } 7385 7386 static int 7387 test_verify_auth_null_cipher_aes_ctr_test_case_1(void) 7388 { 7389 return test_mixed_auth_cipher( 7390 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7391 } 7392 7393 static int 7394 test_auth_aes_cmac_cipher_null_test_case_1(void) 7395 { 7396 return test_mixed_auth_cipher( 7397 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7398 } 7399 7400 static int 7401 test_verify_auth_aes_cmac_cipher_null_test_case_1(void) 7402 { 7403 return test_mixed_auth_cipher( 7404 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7405 } 7406 7407 /* ***** AEAD algorithm Tests ***** */ 7408 7409 static int 7410 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo, 7411 enum rte_crypto_aead_operation op, 7412 const uint8_t *key, const uint8_t key_len, 7413 const uint16_t aad_len, const uint8_t auth_len, 7414 uint8_t iv_len) 7415 { 7416 uint8_t aead_key[key_len]; 7417 7418 struct crypto_testsuite_params *ts_params = &testsuite_params; 7419 struct crypto_unittest_params *ut_params = &unittest_params; 7420 7421 memcpy(aead_key, key, key_len); 7422 7423 /* Setup AEAD Parameters */ 7424 ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 7425 ut_params->aead_xform.next = NULL; 7426 ut_params->aead_xform.aead.algo = algo; 7427 ut_params->aead_xform.aead.op = op; 7428 ut_params->aead_xform.aead.key.data = aead_key; 7429 ut_params->aead_xform.aead.key.length = key_len; 7430 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 7431 ut_params->aead_xform.aead.iv.length = iv_len; 7432 ut_params->aead_xform.aead.digest_length = auth_len; 7433 ut_params->aead_xform.aead.aad_length = aad_len; 7434 7435 debug_hexdump(stdout, "key:", key, key_len); 7436 7437 /* Create Crypto session*/ 7438 ut_params->sess = rte_cryptodev_sym_session_create( 7439 ts_params->session_mpool); 7440 7441 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 7442 &ut_params->aead_xform, 7443 ts_params->session_priv_mpool); 7444 7445 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 7446 7447 return 0; 7448 } 7449 7450 static int 7451 create_aead_xform(struct rte_crypto_op *op, 7452 enum rte_crypto_aead_algorithm algo, 7453 enum rte_crypto_aead_operation aead_op, 7454 uint8_t *key, const uint8_t key_len, 7455 const uint8_t aad_len, const uint8_t auth_len, 7456 uint8_t iv_len) 7457 { 7458 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1), 7459 "failed to allocate space for crypto transform"); 7460 7461 struct rte_crypto_sym_op *sym_op = op->sym; 7462 7463 /* Setup AEAD Parameters */ 7464 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD; 7465 sym_op->xform->next = NULL; 7466 sym_op->xform->aead.algo = algo; 7467 sym_op->xform->aead.op = aead_op; 7468 sym_op->xform->aead.key.data = key; 7469 sym_op->xform->aead.key.length = key_len; 7470 sym_op->xform->aead.iv.offset = IV_OFFSET; 7471 sym_op->xform->aead.iv.length = iv_len; 7472 sym_op->xform->aead.digest_length = auth_len; 7473 sym_op->xform->aead.aad_length = aad_len; 7474 7475 debug_hexdump(stdout, "key:", key, key_len); 7476 7477 return 0; 7478 } 7479 7480 static int 7481 create_aead_operation(enum rte_crypto_aead_operation op, 7482 const struct aead_test_data *tdata) 7483 { 7484 struct crypto_testsuite_params *ts_params = &testsuite_params; 7485 struct crypto_unittest_params *ut_params = &unittest_params; 7486 7487 uint8_t *plaintext, *ciphertext; 7488 unsigned int aad_pad_len, plaintext_pad_len; 7489 7490 /* Generate Crypto op data structure */ 7491 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 7492 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 7493 TEST_ASSERT_NOT_NULL(ut_params->op, 7494 "Failed to allocate symmetric crypto operation struct"); 7495 7496 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 7497 7498 /* Append aad data */ 7499 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 7500 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16); 7501 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7502 aad_pad_len); 7503 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 7504 "no room to append aad"); 7505 7506 sym_op->aead.aad.phys_addr = 7507 rte_pktmbuf_iova(ut_params->ibuf); 7508 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 7509 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len); 7510 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 7511 tdata->aad.len); 7512 7513 /* Append IV at the end of the crypto operation*/ 7514 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 7515 uint8_t *, IV_OFFSET); 7516 7517 /* Copy IV 1 byte after the IV pointer, according to the API */ 7518 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len); 7519 debug_hexdump(stdout, "iv:", iv_ptr, 7520 tdata->iv.len); 7521 } else { 7522 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 7523 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7524 aad_pad_len); 7525 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 7526 "no room to append aad"); 7527 7528 sym_op->aead.aad.phys_addr = 7529 rte_pktmbuf_iova(ut_params->ibuf); 7530 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len); 7531 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 7532 tdata->aad.len); 7533 7534 /* Append IV at the end of the crypto operation*/ 7535 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 7536 uint8_t *, IV_OFFSET); 7537 7538 if (tdata->iv.len == 0) { 7539 rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH); 7540 debug_hexdump(stdout, "iv:", iv_ptr, 7541 AES_GCM_J0_LENGTH); 7542 } else { 7543 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 7544 debug_hexdump(stdout, "iv:", iv_ptr, 7545 tdata->iv.len); 7546 } 7547 } 7548 7549 /* Append plaintext/ciphertext */ 7550 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 7551 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 7552 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7553 plaintext_pad_len); 7554 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 7555 7556 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 7557 debug_hexdump(stdout, "plaintext:", plaintext, 7558 tdata->plaintext.len); 7559 7560 if (ut_params->obuf) { 7561 ciphertext = (uint8_t *)rte_pktmbuf_append( 7562 ut_params->obuf, 7563 plaintext_pad_len + aad_pad_len); 7564 TEST_ASSERT_NOT_NULL(ciphertext, 7565 "no room to append ciphertext"); 7566 7567 memset(ciphertext + aad_pad_len, 0, 7568 tdata->ciphertext.len); 7569 } 7570 } else { 7571 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); 7572 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7573 plaintext_pad_len); 7574 TEST_ASSERT_NOT_NULL(ciphertext, 7575 "no room to append ciphertext"); 7576 7577 memcpy(ciphertext, tdata->ciphertext.data, 7578 tdata->ciphertext.len); 7579 debug_hexdump(stdout, "ciphertext:", ciphertext, 7580 tdata->ciphertext.len); 7581 7582 if (ut_params->obuf) { 7583 plaintext = (uint8_t *)rte_pktmbuf_append( 7584 ut_params->obuf, 7585 plaintext_pad_len + aad_pad_len); 7586 TEST_ASSERT_NOT_NULL(plaintext, 7587 "no room to append plaintext"); 7588 7589 memset(plaintext + aad_pad_len, 0, 7590 tdata->plaintext.len); 7591 } 7592 } 7593 7594 /* Append digest data */ 7595 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 7596 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 7597 ut_params->obuf ? ut_params->obuf : 7598 ut_params->ibuf, 7599 tdata->auth_tag.len); 7600 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 7601 "no room to append digest"); 7602 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len); 7603 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 7604 ut_params->obuf ? ut_params->obuf : 7605 ut_params->ibuf, 7606 plaintext_pad_len + 7607 aad_pad_len); 7608 } else { 7609 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 7610 ut_params->ibuf, tdata->auth_tag.len); 7611 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 7612 "no room to append digest"); 7613 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 7614 ut_params->ibuf, 7615 plaintext_pad_len + aad_pad_len); 7616 7617 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 7618 tdata->auth_tag.len); 7619 debug_hexdump(stdout, "digest:", 7620 sym_op->aead.digest.data, 7621 tdata->auth_tag.len); 7622 } 7623 7624 sym_op->aead.data.length = tdata->plaintext.len; 7625 sym_op->aead.data.offset = aad_pad_len; 7626 7627 return 0; 7628 } 7629 7630 static int 7631 test_authenticated_encryption(const struct aead_test_data *tdata) 7632 { 7633 struct crypto_testsuite_params *ts_params = &testsuite_params; 7634 struct crypto_unittest_params *ut_params = &unittest_params; 7635 7636 int retval; 7637 uint8_t *ciphertext, *auth_tag; 7638 uint16_t plaintext_pad_len; 7639 uint32_t i; 7640 struct rte_cryptodev_info dev_info; 7641 7642 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7643 uint64_t feat_flags = dev_info.feature_flags; 7644 7645 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 7646 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 7647 printf("Device doesn't support RAW data-path APIs.\n"); 7648 return -ENOTSUP; 7649 } 7650 7651 /* Verify the capabilities */ 7652 struct rte_cryptodev_sym_capability_idx cap_idx; 7653 const struct rte_cryptodev_symmetric_capability *capability; 7654 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 7655 cap_idx.algo.aead = tdata->algo; 7656 capability = rte_cryptodev_sym_capability_get( 7657 ts_params->valid_devs[0], &cap_idx); 7658 if (capability == NULL) 7659 return -ENOTSUP; 7660 if (rte_cryptodev_sym_capability_check_aead( 7661 capability, tdata->key.len, tdata->auth_tag.len, 7662 tdata->aad.len, tdata->iv.len)) 7663 return -ENOTSUP; 7664 7665 /* Create AEAD session */ 7666 retval = create_aead_session(ts_params->valid_devs[0], 7667 tdata->algo, 7668 RTE_CRYPTO_AEAD_OP_ENCRYPT, 7669 tdata->key.data, tdata->key.len, 7670 tdata->aad.len, tdata->auth_tag.len, 7671 tdata->iv.len); 7672 if (retval < 0) 7673 return retval; 7674 7675 if (tdata->aad.len > MBUF_SIZE) { 7676 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 7677 /* Populate full size of add data */ 7678 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 7679 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 7680 } else 7681 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7682 7683 /* clear mbuf payload */ 7684 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7685 rte_pktmbuf_tailroom(ut_params->ibuf)); 7686 7687 /* Create AEAD operation */ 7688 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 7689 if (retval < 0) 7690 return retval; 7691 7692 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 7693 7694 ut_params->op->sym->m_src = ut_params->ibuf; 7695 7696 /* Process crypto operation */ 7697 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 7698 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 7699 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7700 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 7701 ut_params->op, 0, 0, 0, 0); 7702 else 7703 TEST_ASSERT_NOT_NULL( 7704 process_crypto_request(ts_params->valid_devs[0], 7705 ut_params->op), "failed to process sym crypto op"); 7706 7707 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7708 "crypto op processing failed"); 7709 7710 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 7711 7712 if (ut_params->op->sym->m_dst) { 7713 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 7714 uint8_t *); 7715 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 7716 uint8_t *, plaintext_pad_len); 7717 } else { 7718 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 7719 uint8_t *, 7720 ut_params->op->sym->cipher.data.offset); 7721 auth_tag = ciphertext + plaintext_pad_len; 7722 } 7723 7724 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 7725 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 7726 7727 /* Validate obuf */ 7728 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7729 ciphertext, 7730 tdata->ciphertext.data, 7731 tdata->ciphertext.len, 7732 "Ciphertext data not as expected"); 7733 7734 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7735 auth_tag, 7736 tdata->auth_tag.data, 7737 tdata->auth_tag.len, 7738 "Generated auth tag not as expected"); 7739 7740 return 0; 7741 7742 } 7743 7744 #ifdef RTE_LIB_SECURITY 7745 static int 7746 security_proto_supported(enum rte_security_session_action_type action, 7747 enum rte_security_session_protocol proto) 7748 { 7749 struct crypto_testsuite_params *ts_params = &testsuite_params; 7750 7751 const struct rte_security_capability *capabilities; 7752 const struct rte_security_capability *capability; 7753 uint16_t i = 0; 7754 7755 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 7756 rte_cryptodev_get_sec_ctx( 7757 ts_params->valid_devs[0]); 7758 7759 7760 capabilities = rte_security_capabilities_get(ctx); 7761 7762 if (capabilities == NULL) 7763 return -ENOTSUP; 7764 7765 while ((capability = &capabilities[i++])->action != 7766 RTE_SECURITY_ACTION_TYPE_NONE) { 7767 if (capability->action == action && 7768 capability->protocol == proto) 7769 return 0; 7770 } 7771 7772 return -ENOTSUP; 7773 } 7774 7775 /* Basic algorithm run function for async inplace mode. 7776 * Creates a session from input parameters and runs one operation 7777 * on input_vec. Checks the output of the crypto operation against 7778 * output_vec. 7779 */ 7780 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc, 7781 enum rte_crypto_auth_operation opa, 7782 const uint8_t *input_vec, unsigned int input_vec_len, 7783 const uint8_t *output_vec, 7784 unsigned int output_vec_len, 7785 enum rte_crypto_cipher_algorithm cipher_alg, 7786 const uint8_t *cipher_key, uint32_t cipher_key_len, 7787 enum rte_crypto_auth_algorithm auth_alg, 7788 const uint8_t *auth_key, uint32_t auth_key_len, 7789 uint8_t bearer, enum rte_security_pdcp_domain domain, 7790 uint8_t packet_direction, uint8_t sn_size, 7791 uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap) 7792 { 7793 struct crypto_testsuite_params *ts_params = &testsuite_params; 7794 struct crypto_unittest_params *ut_params = &unittest_params; 7795 uint8_t *plaintext; 7796 int ret = TEST_SUCCESS; 7797 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 7798 rte_cryptodev_get_sec_ctx( 7799 ts_params->valid_devs[0]); 7800 7801 /* Verify the capabilities */ 7802 struct rte_security_capability_idx sec_cap_idx; 7803 7804 sec_cap_idx.action = ut_params->type; 7805 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 7806 sec_cap_idx.pdcp.domain = domain; 7807 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 7808 return -ENOTSUP; 7809 7810 /* Generate test mbuf data */ 7811 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7812 7813 /* clear mbuf payload */ 7814 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7815 rte_pktmbuf_tailroom(ut_params->ibuf)); 7816 7817 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7818 input_vec_len); 7819 memcpy(plaintext, input_vec, input_vec_len); 7820 7821 /* Out of place support */ 7822 if (oop) { 7823 /* 7824 * For out-op-place we need to alloc another mbuf 7825 */ 7826 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7827 rte_pktmbuf_append(ut_params->obuf, output_vec_len); 7828 } 7829 7830 /* Setup Cipher Parameters */ 7831 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 7832 ut_params->cipher_xform.cipher.algo = cipher_alg; 7833 ut_params->cipher_xform.cipher.op = opc; 7834 ut_params->cipher_xform.cipher.key.data = cipher_key; 7835 ut_params->cipher_xform.cipher.key.length = cipher_key_len; 7836 ut_params->cipher_xform.cipher.iv.length = 7837 packet_direction ? 4 : 0; 7838 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 7839 7840 /* Setup HMAC Parameters if ICV header is required */ 7841 if (auth_alg != 0) { 7842 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 7843 ut_params->auth_xform.next = NULL; 7844 ut_params->auth_xform.auth.algo = auth_alg; 7845 ut_params->auth_xform.auth.op = opa; 7846 ut_params->auth_xform.auth.key.data = auth_key; 7847 ut_params->auth_xform.auth.key.length = auth_key_len; 7848 7849 ut_params->cipher_xform.next = &ut_params->auth_xform; 7850 } else { 7851 ut_params->cipher_xform.next = NULL; 7852 } 7853 7854 struct rte_security_session_conf sess_conf = { 7855 .action_type = ut_params->type, 7856 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 7857 {.pdcp = { 7858 .bearer = bearer, 7859 .domain = domain, 7860 .pkt_dir = packet_direction, 7861 .sn_size = sn_size, 7862 .hfn = packet_direction ? 0 : hfn, 7863 /** 7864 * hfn can be set as pdcp_test_hfn[i] 7865 * if hfn_ovrd is not set. Here, PDCP 7866 * packet direction is just used to 7867 * run half of the cases with session 7868 * HFN and other half with per packet 7869 * HFN. 7870 */ 7871 .hfn_threshold = hfn_threshold, 7872 .hfn_ovrd = packet_direction ? 1 : 0, 7873 .sdap_enabled = sdap, 7874 } }, 7875 .crypto_xform = &ut_params->cipher_xform 7876 }; 7877 7878 /* Create security session */ 7879 ut_params->sec_session = rte_security_session_create(ctx, 7880 &sess_conf, ts_params->session_mpool, 7881 ts_params->session_priv_mpool); 7882 7883 if (!ut_params->sec_session) { 7884 printf("TestCase %s()-%d line %d failed %s: ", 7885 __func__, i, __LINE__, "Failed to allocate session"); 7886 ret = TEST_FAILED; 7887 goto on_err; 7888 } 7889 7890 /* Generate crypto op data structure */ 7891 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 7892 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 7893 if (!ut_params->op) { 7894 printf("TestCase %s()-%d line %d failed %s: ", 7895 __func__, i, __LINE__, 7896 "Failed to allocate symmetric crypto operation struct"); 7897 ret = TEST_FAILED; 7898 goto on_err; 7899 } 7900 7901 uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op, 7902 uint32_t *, IV_OFFSET); 7903 *per_pkt_hfn = packet_direction ? hfn : 0; 7904 7905 rte_security_attach_session(ut_params->op, ut_params->sec_session); 7906 7907 /* set crypto operation source mbuf */ 7908 ut_params->op->sym->m_src = ut_params->ibuf; 7909 if (oop) 7910 ut_params->op->sym->m_dst = ut_params->obuf; 7911 7912 /* Process crypto operation */ 7913 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) 7914 == NULL) { 7915 printf("TestCase %s()-%d line %d failed %s: ", 7916 __func__, i, __LINE__, 7917 "failed to process sym crypto op"); 7918 ret = TEST_FAILED; 7919 goto on_err; 7920 } 7921 7922 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 7923 printf("TestCase %s()-%d line %d failed %s: ", 7924 __func__, i, __LINE__, "crypto op processing failed"); 7925 ret = TEST_FAILED; 7926 goto on_err; 7927 } 7928 7929 /* Validate obuf */ 7930 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 7931 uint8_t *); 7932 if (oop) { 7933 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 7934 uint8_t *); 7935 } 7936 7937 if (memcmp(ciphertext, output_vec, output_vec_len)) { 7938 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 7939 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len); 7940 rte_hexdump(stdout, "reference", output_vec, output_vec_len); 7941 ret = TEST_FAILED; 7942 goto on_err; 7943 } 7944 7945 on_err: 7946 rte_crypto_op_free(ut_params->op); 7947 ut_params->op = NULL; 7948 7949 if (ut_params->sec_session) 7950 rte_security_session_destroy(ctx, ut_params->sec_session); 7951 ut_params->sec_session = NULL; 7952 7953 rte_pktmbuf_free(ut_params->ibuf); 7954 ut_params->ibuf = NULL; 7955 if (oop) { 7956 rte_pktmbuf_free(ut_params->obuf); 7957 ut_params->obuf = NULL; 7958 } 7959 7960 return ret; 7961 } 7962 7963 static int 7964 test_pdcp_proto_SGL(int i, int oop, 7965 enum rte_crypto_cipher_operation opc, 7966 enum rte_crypto_auth_operation opa, 7967 uint8_t *input_vec, 7968 unsigned int input_vec_len, 7969 uint8_t *output_vec, 7970 unsigned int output_vec_len, 7971 uint32_t fragsz, 7972 uint32_t fragsz_oop) 7973 { 7974 struct crypto_testsuite_params *ts_params = &testsuite_params; 7975 struct crypto_unittest_params *ut_params = &unittest_params; 7976 uint8_t *plaintext; 7977 struct rte_mbuf *buf, *buf_oop = NULL; 7978 int ret = TEST_SUCCESS; 7979 int to_trn = 0; 7980 int to_trn_tbl[16]; 7981 int segs = 1; 7982 unsigned int trn_data = 0; 7983 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 7984 rte_cryptodev_get_sec_ctx( 7985 ts_params->valid_devs[0]); 7986 7987 /* Verify the capabilities */ 7988 struct rte_security_capability_idx sec_cap_idx; 7989 7990 sec_cap_idx.action = ut_params->type; 7991 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 7992 sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain; 7993 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 7994 return -ENOTSUP; 7995 7996 if (fragsz > input_vec_len) 7997 fragsz = input_vec_len; 7998 7999 uint16_t plaintext_len = fragsz; 8000 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 8001 8002 if (fragsz_oop > output_vec_len) 8003 frag_size_oop = output_vec_len; 8004 8005 int ecx = 0; 8006 if (input_vec_len % fragsz != 0) { 8007 if (input_vec_len / fragsz + 1 > 16) 8008 return 1; 8009 } else if (input_vec_len / fragsz > 16) 8010 return 1; 8011 8012 /* Out of place support */ 8013 if (oop) { 8014 /* 8015 * For out-op-place we need to alloc another mbuf 8016 */ 8017 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8018 rte_pktmbuf_append(ut_params->obuf, frag_size_oop); 8019 buf_oop = ut_params->obuf; 8020 } 8021 8022 /* Generate test mbuf data */ 8023 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8024 8025 /* clear mbuf payload */ 8026 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8027 rte_pktmbuf_tailroom(ut_params->ibuf)); 8028 8029 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8030 plaintext_len); 8031 memcpy(plaintext, input_vec, plaintext_len); 8032 trn_data += plaintext_len; 8033 8034 buf = ut_params->ibuf; 8035 8036 /* 8037 * Loop until no more fragments 8038 */ 8039 8040 while (trn_data < input_vec_len) { 8041 ++segs; 8042 to_trn = (input_vec_len - trn_data < fragsz) ? 8043 (input_vec_len - trn_data) : fragsz; 8044 8045 to_trn_tbl[ecx++] = to_trn; 8046 8047 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8048 buf = buf->next; 8049 8050 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 8051 rte_pktmbuf_tailroom(buf)); 8052 8053 /* OOP */ 8054 if (oop && !fragsz_oop) { 8055 buf_oop->next = 8056 rte_pktmbuf_alloc(ts_params->mbuf_pool); 8057 buf_oop = buf_oop->next; 8058 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 8059 0, rte_pktmbuf_tailroom(buf_oop)); 8060 rte_pktmbuf_append(buf_oop, to_trn); 8061 } 8062 8063 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 8064 to_trn); 8065 8066 memcpy(plaintext, input_vec + trn_data, to_trn); 8067 trn_data += to_trn; 8068 } 8069 8070 ut_params->ibuf->nb_segs = segs; 8071 8072 segs = 1; 8073 if (fragsz_oop && oop) { 8074 to_trn = 0; 8075 ecx = 0; 8076 8077 trn_data = frag_size_oop; 8078 while (trn_data < output_vec_len) { 8079 ++segs; 8080 to_trn = 8081 (output_vec_len - trn_data < 8082 frag_size_oop) ? 8083 (output_vec_len - trn_data) : 8084 frag_size_oop; 8085 8086 to_trn_tbl[ecx++] = to_trn; 8087 8088 buf_oop->next = 8089 rte_pktmbuf_alloc(ts_params->mbuf_pool); 8090 buf_oop = buf_oop->next; 8091 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 8092 0, rte_pktmbuf_tailroom(buf_oop)); 8093 rte_pktmbuf_append(buf_oop, to_trn); 8094 8095 trn_data += to_trn; 8096 } 8097 ut_params->obuf->nb_segs = segs; 8098 } 8099 8100 /* Setup Cipher Parameters */ 8101 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8102 ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg; 8103 ut_params->cipher_xform.cipher.op = opc; 8104 ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i]; 8105 ut_params->cipher_xform.cipher.key.length = 8106 pdcp_test_params[i].cipher_key_len; 8107 ut_params->cipher_xform.cipher.iv.length = 0; 8108 8109 /* Setup HMAC Parameters if ICV header is required */ 8110 if (pdcp_test_params[i].auth_alg != 0) { 8111 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8112 ut_params->auth_xform.next = NULL; 8113 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg; 8114 ut_params->auth_xform.auth.op = opa; 8115 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i]; 8116 ut_params->auth_xform.auth.key.length = 8117 pdcp_test_params[i].auth_key_len; 8118 8119 ut_params->cipher_xform.next = &ut_params->auth_xform; 8120 } else { 8121 ut_params->cipher_xform.next = NULL; 8122 } 8123 8124 struct rte_security_session_conf sess_conf = { 8125 .action_type = ut_params->type, 8126 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 8127 {.pdcp = { 8128 .bearer = pdcp_test_bearer[i], 8129 .domain = pdcp_test_params[i].domain, 8130 .pkt_dir = pdcp_test_packet_direction[i], 8131 .sn_size = pdcp_test_data_sn_size[i], 8132 .hfn = pdcp_test_hfn[i], 8133 .hfn_threshold = pdcp_test_hfn_threshold[i], 8134 .hfn_ovrd = 0, 8135 } }, 8136 .crypto_xform = &ut_params->cipher_xform 8137 }; 8138 8139 /* Create security session */ 8140 ut_params->sec_session = rte_security_session_create(ctx, 8141 &sess_conf, ts_params->session_mpool, 8142 ts_params->session_priv_mpool); 8143 8144 if (!ut_params->sec_session) { 8145 printf("TestCase %s()-%d line %d failed %s: ", 8146 __func__, i, __LINE__, "Failed to allocate session"); 8147 ret = TEST_FAILED; 8148 goto on_err; 8149 } 8150 8151 /* Generate crypto op data structure */ 8152 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8153 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8154 if (!ut_params->op) { 8155 printf("TestCase %s()-%d line %d failed %s: ", 8156 __func__, i, __LINE__, 8157 "Failed to allocate symmetric crypto operation struct"); 8158 ret = TEST_FAILED; 8159 goto on_err; 8160 } 8161 8162 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8163 8164 /* set crypto operation source mbuf */ 8165 ut_params->op->sym->m_src = ut_params->ibuf; 8166 if (oop) 8167 ut_params->op->sym->m_dst = ut_params->obuf; 8168 8169 /* Process crypto operation */ 8170 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) 8171 == NULL) { 8172 printf("TestCase %s()-%d line %d failed %s: ", 8173 __func__, i, __LINE__, 8174 "failed to process sym crypto op"); 8175 ret = TEST_FAILED; 8176 goto on_err; 8177 } 8178 8179 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8180 printf("TestCase %s()-%d line %d failed %s: ", 8181 __func__, i, __LINE__, "crypto op processing failed"); 8182 ret = TEST_FAILED; 8183 goto on_err; 8184 } 8185 8186 /* Validate obuf */ 8187 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 8188 uint8_t *); 8189 if (oop) { 8190 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8191 uint8_t *); 8192 } 8193 if (fragsz_oop) 8194 fragsz = frag_size_oop; 8195 if (memcmp(ciphertext, output_vec, fragsz)) { 8196 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8197 rte_hexdump(stdout, "encrypted", ciphertext, fragsz); 8198 rte_hexdump(stdout, "reference", output_vec, fragsz); 8199 ret = TEST_FAILED; 8200 goto on_err; 8201 } 8202 8203 buf = ut_params->op->sym->m_src->next; 8204 if (oop) 8205 buf = ut_params->op->sym->m_dst->next; 8206 8207 unsigned int off = fragsz; 8208 8209 ecx = 0; 8210 while (buf) { 8211 ciphertext = rte_pktmbuf_mtod(buf, 8212 uint8_t *); 8213 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) { 8214 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8215 rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]); 8216 rte_hexdump(stdout, "reference", output_vec + off, 8217 to_trn_tbl[ecx]); 8218 ret = TEST_FAILED; 8219 goto on_err; 8220 } 8221 off += to_trn_tbl[ecx++]; 8222 buf = buf->next; 8223 } 8224 on_err: 8225 rte_crypto_op_free(ut_params->op); 8226 ut_params->op = NULL; 8227 8228 if (ut_params->sec_session) 8229 rte_security_session_destroy(ctx, ut_params->sec_session); 8230 ut_params->sec_session = NULL; 8231 8232 rte_pktmbuf_free(ut_params->ibuf); 8233 ut_params->ibuf = NULL; 8234 if (oop) { 8235 rte_pktmbuf_free(ut_params->obuf); 8236 ut_params->obuf = NULL; 8237 } 8238 8239 return ret; 8240 } 8241 8242 int 8243 test_pdcp_proto_cplane_encap(int i) 8244 { 8245 return test_pdcp_proto( 8246 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8247 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8248 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8249 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8250 pdcp_test_params[i].cipher_key_len, 8251 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8252 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8253 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8254 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8255 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8256 } 8257 8258 int 8259 test_pdcp_proto_uplane_encap(int i) 8260 { 8261 return test_pdcp_proto( 8262 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8263 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8264 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 8265 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8266 pdcp_test_params[i].cipher_key_len, 8267 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8268 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8269 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8270 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8271 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8272 } 8273 8274 int 8275 test_pdcp_proto_uplane_encap_with_int(int i) 8276 { 8277 return test_pdcp_proto( 8278 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8279 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8280 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8281 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8282 pdcp_test_params[i].cipher_key_len, 8283 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8284 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8285 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8286 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8287 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8288 } 8289 8290 int 8291 test_pdcp_proto_cplane_decap(int i) 8292 { 8293 return test_pdcp_proto( 8294 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8295 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8296 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8297 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8298 pdcp_test_params[i].cipher_key_len, 8299 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8300 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8301 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8302 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8303 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8304 } 8305 8306 int 8307 test_pdcp_proto_uplane_decap(int i) 8308 { 8309 return test_pdcp_proto( 8310 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8311 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 8312 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8313 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8314 pdcp_test_params[i].cipher_key_len, 8315 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8316 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8317 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8318 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8319 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8320 } 8321 8322 int 8323 test_pdcp_proto_uplane_decap_with_int(int i) 8324 { 8325 return test_pdcp_proto( 8326 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8327 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8328 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8329 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8330 pdcp_test_params[i].cipher_key_len, 8331 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8332 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8333 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8334 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8335 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8336 } 8337 8338 static int 8339 test_PDCP_PROTO_SGL_in_place_32B(void) 8340 { 8341 /* i can be used for running any PDCP case 8342 * In this case it is uplane 12-bit AES-SNOW DL encap 8343 */ 8344 int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK; 8345 return test_pdcp_proto_SGL(i, IN_PLACE, 8346 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8347 RTE_CRYPTO_AUTH_OP_GENERATE, 8348 pdcp_test_data_in[i], 8349 pdcp_test_data_in_len[i], 8350 pdcp_test_data_out[i], 8351 pdcp_test_data_in_len[i]+4, 8352 32, 0); 8353 } 8354 static int 8355 test_PDCP_PROTO_SGL_oop_32B_128B(void) 8356 { 8357 /* i can be used for running any PDCP case 8358 * In this case it is uplane 18-bit NULL-NULL DL encap 8359 */ 8360 int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK; 8361 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8362 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8363 RTE_CRYPTO_AUTH_OP_GENERATE, 8364 pdcp_test_data_in[i], 8365 pdcp_test_data_in_len[i], 8366 pdcp_test_data_out[i], 8367 pdcp_test_data_in_len[i]+4, 8368 32, 128); 8369 } 8370 static int 8371 test_PDCP_PROTO_SGL_oop_32B_40B(void) 8372 { 8373 /* i can be used for running any PDCP case 8374 * In this case it is uplane 18-bit AES DL encap 8375 */ 8376 int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET 8377 + DOWNLINK; 8378 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8379 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8380 RTE_CRYPTO_AUTH_OP_GENERATE, 8381 pdcp_test_data_in[i], 8382 pdcp_test_data_in_len[i], 8383 pdcp_test_data_out[i], 8384 pdcp_test_data_in_len[i], 8385 32, 40); 8386 } 8387 static int 8388 test_PDCP_PROTO_SGL_oop_128B_32B(void) 8389 { 8390 /* i can be used for running any PDCP case 8391 * In this case it is cplane 12-bit AES-ZUC DL encap 8392 */ 8393 int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK; 8394 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8395 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8396 RTE_CRYPTO_AUTH_OP_GENERATE, 8397 pdcp_test_data_in[i], 8398 pdcp_test_data_in_len[i], 8399 pdcp_test_data_out[i], 8400 pdcp_test_data_in_len[i]+4, 8401 128, 32); 8402 } 8403 8404 static int 8405 test_PDCP_SDAP_PROTO_encap_all(void) 8406 { 8407 int i = 0, size = 0; 8408 int err, all_err = TEST_SUCCESS; 8409 const struct pdcp_sdap_test *cur_test; 8410 8411 size = ARRAY_SIZE(list_pdcp_sdap_tests); 8412 8413 for (i = 0; i < size; i++) { 8414 cur_test = &list_pdcp_sdap_tests[i]; 8415 err = test_pdcp_proto( 8416 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8417 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 8418 cur_test->in_len, cur_test->data_out, 8419 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 8420 cur_test->param.cipher_alg, cur_test->cipher_key, 8421 cur_test->param.cipher_key_len, 8422 cur_test->param.auth_alg, 8423 cur_test->auth_key, cur_test->param.auth_key_len, 8424 cur_test->bearer, cur_test->param.domain, 8425 cur_test->packet_direction, cur_test->sn_size, 8426 cur_test->hfn, 8427 cur_test->hfn_threshold, SDAP_ENABLED); 8428 if (err) { 8429 printf("\t%d) %s: Encapsulation failed\n", 8430 cur_test->test_idx, 8431 cur_test->param.name); 8432 err = TEST_FAILED; 8433 } else { 8434 printf("\t%d) %s: Encap PASS\n", cur_test->test_idx, 8435 cur_test->param.name); 8436 err = TEST_SUCCESS; 8437 } 8438 all_err += err; 8439 } 8440 8441 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 8442 8443 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 8444 } 8445 8446 static int 8447 test_PDCP_SDAP_PROTO_decap_all(void) 8448 { 8449 int i = 0, size = 0; 8450 int err, all_err = TEST_SUCCESS; 8451 const struct pdcp_sdap_test *cur_test; 8452 8453 size = ARRAY_SIZE(list_pdcp_sdap_tests); 8454 8455 for (i = 0; i < size; i++) { 8456 cur_test = &list_pdcp_sdap_tests[i]; 8457 err = test_pdcp_proto( 8458 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, 8459 RTE_CRYPTO_AUTH_OP_VERIFY, 8460 cur_test->data_out, 8461 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 8462 cur_test->data_in, cur_test->in_len, 8463 cur_test->param.cipher_alg, 8464 cur_test->cipher_key, cur_test->param.cipher_key_len, 8465 cur_test->param.auth_alg, cur_test->auth_key, 8466 cur_test->param.auth_key_len, cur_test->bearer, 8467 cur_test->param.domain, cur_test->packet_direction, 8468 cur_test->sn_size, cur_test->hfn, 8469 cur_test->hfn_threshold, SDAP_ENABLED); 8470 if (err) { 8471 printf("\t%d) %s: Decapsulation failed\n", 8472 cur_test->test_idx, 8473 cur_test->param.name); 8474 err = TEST_FAILED; 8475 } else { 8476 printf("\t%d) %s: Decap PASS\n", cur_test->test_idx, 8477 cur_test->param.name); 8478 err = TEST_SUCCESS; 8479 } 8480 all_err += err; 8481 } 8482 8483 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 8484 8485 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 8486 } 8487 8488 static int 8489 test_PDCP_PROTO_all(void) 8490 { 8491 struct crypto_testsuite_params *ts_params = &testsuite_params; 8492 struct crypto_unittest_params *ut_params = &unittest_params; 8493 struct rte_cryptodev_info dev_info; 8494 int status; 8495 8496 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8497 uint64_t feat_flags = dev_info.feature_flags; 8498 8499 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 8500 return -ENOTSUP; 8501 8502 /* Set action type */ 8503 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 8504 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 8505 gbl_action_type; 8506 8507 if (security_proto_supported(ut_params->type, 8508 RTE_SECURITY_PROTOCOL_PDCP) < 0) 8509 return -ENOTSUP; 8510 8511 status = test_PDCP_PROTO_cplane_encap_all(); 8512 status += test_PDCP_PROTO_cplane_decap_all(); 8513 status += test_PDCP_PROTO_uplane_encap_all(); 8514 status += test_PDCP_PROTO_uplane_decap_all(); 8515 status += test_PDCP_PROTO_SGL_in_place_32B(); 8516 status += test_PDCP_PROTO_SGL_oop_32B_128B(); 8517 status += test_PDCP_PROTO_SGL_oop_32B_40B(); 8518 status += test_PDCP_PROTO_SGL_oop_128B_32B(); 8519 status += test_PDCP_SDAP_PROTO_encap_all(); 8520 status += test_PDCP_SDAP_PROTO_decap_all(); 8521 8522 if (status) 8523 return TEST_FAILED; 8524 else 8525 return TEST_SUCCESS; 8526 } 8527 8528 static int 8529 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td) 8530 { 8531 struct crypto_testsuite_params *ts_params = &testsuite_params; 8532 struct crypto_unittest_params *ut_params = &unittest_params; 8533 uint8_t *plaintext, *ciphertext; 8534 uint8_t *iv_ptr; 8535 int32_t cipher_len, crc_len; 8536 uint32_t crc_data_len; 8537 int ret = TEST_SUCCESS; 8538 8539 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8540 rte_cryptodev_get_sec_ctx( 8541 ts_params->valid_devs[0]); 8542 8543 /* Verify the capabilities */ 8544 struct rte_security_capability_idx sec_cap_idx; 8545 const struct rte_security_capability *sec_cap; 8546 const struct rte_cryptodev_capabilities *crypto_cap; 8547 const struct rte_cryptodev_symmetric_capability *sym_cap; 8548 int j = 0; 8549 8550 sec_cap_idx.action = ut_params->type; 8551 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 8552 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK; 8553 8554 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 8555 if (sec_cap == NULL) 8556 return -ENOTSUP; 8557 8558 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 8559 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 8560 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 8561 crypto_cap->sym.xform_type == 8562 RTE_CRYPTO_SYM_XFORM_CIPHER && 8563 crypto_cap->sym.cipher.algo == 8564 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 8565 sym_cap = &crypto_cap->sym; 8566 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 8567 d_td->key.len, 8568 d_td->iv.len) == 0) 8569 break; 8570 } 8571 } 8572 8573 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 8574 return -ENOTSUP; 8575 8576 /* Setup source mbuf payload */ 8577 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8578 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8579 rte_pktmbuf_tailroom(ut_params->ibuf)); 8580 8581 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8582 d_td->ciphertext.len); 8583 8584 memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len); 8585 8586 /* Setup cipher session parameters */ 8587 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8588 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 8589 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 8590 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 8591 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 8592 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 8593 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 8594 ut_params->cipher_xform.next = NULL; 8595 8596 /* Setup DOCSIS session parameters */ 8597 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK; 8598 8599 struct rte_security_session_conf sess_conf = { 8600 .action_type = ut_params->type, 8601 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 8602 .docsis = ut_params->docsis_xform, 8603 .crypto_xform = &ut_params->cipher_xform, 8604 }; 8605 8606 /* Create security session */ 8607 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 8608 ts_params->session_mpool, 8609 ts_params->session_priv_mpool); 8610 8611 if (!ut_params->sec_session) { 8612 printf("TestCase %s(%d) line %d: %s\n", 8613 __func__, i, __LINE__, "failed to allocate session"); 8614 ret = TEST_FAILED; 8615 goto on_err; 8616 } 8617 8618 /* Generate crypto op data structure */ 8619 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8620 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8621 if (!ut_params->op) { 8622 printf("TestCase %s(%d) line %d: %s\n", 8623 __func__, i, __LINE__, 8624 "failed to allocate symmetric crypto operation"); 8625 ret = TEST_FAILED; 8626 goto on_err; 8627 } 8628 8629 /* Setup CRC operation parameters */ 8630 crc_len = d_td->ciphertext.no_crc == false ? 8631 (d_td->ciphertext.len - 8632 d_td->ciphertext.crc_offset - 8633 RTE_ETHER_CRC_LEN) : 8634 0; 8635 crc_len = crc_len > 0 ? crc_len : 0; 8636 crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN; 8637 ut_params->op->sym->auth.data.length = crc_len; 8638 ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset; 8639 8640 /* Setup cipher operation parameters */ 8641 cipher_len = d_td->ciphertext.no_cipher == false ? 8642 (d_td->ciphertext.len - 8643 d_td->ciphertext.cipher_offset) : 8644 0; 8645 cipher_len = cipher_len > 0 ? cipher_len : 0; 8646 ut_params->op->sym->cipher.data.length = cipher_len; 8647 ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset; 8648 8649 /* Setup cipher IV */ 8650 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 8651 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 8652 8653 /* Attach session to operation */ 8654 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8655 8656 /* Set crypto operation mbufs */ 8657 ut_params->op->sym->m_src = ut_params->ibuf; 8658 ut_params->op->sym->m_dst = NULL; 8659 8660 /* Process crypto operation */ 8661 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 8662 NULL) { 8663 printf("TestCase %s(%d) line %d: %s\n", 8664 __func__, i, __LINE__, 8665 "failed to process security crypto op"); 8666 ret = TEST_FAILED; 8667 goto on_err; 8668 } 8669 8670 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8671 printf("TestCase %s(%d) line %d: %s\n", 8672 __func__, i, __LINE__, "crypto op processing failed"); 8673 ret = TEST_FAILED; 8674 goto on_err; 8675 } 8676 8677 /* Validate plaintext */ 8678 plaintext = ciphertext; 8679 8680 if (memcmp(plaintext, d_td->plaintext.data, 8681 d_td->plaintext.len - crc_data_len)) { 8682 printf("TestCase %s(%d) line %d: %s\n", 8683 __func__, i, __LINE__, "plaintext not as expected\n"); 8684 rte_hexdump(stdout, "expected", d_td->plaintext.data, 8685 d_td->plaintext.len); 8686 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len); 8687 ret = TEST_FAILED; 8688 goto on_err; 8689 } 8690 8691 on_err: 8692 rte_crypto_op_free(ut_params->op); 8693 ut_params->op = NULL; 8694 8695 if (ut_params->sec_session) 8696 rte_security_session_destroy(ctx, ut_params->sec_session); 8697 ut_params->sec_session = NULL; 8698 8699 rte_pktmbuf_free(ut_params->ibuf); 8700 ut_params->ibuf = NULL; 8701 8702 return ret; 8703 } 8704 8705 static int 8706 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td) 8707 { 8708 struct crypto_testsuite_params *ts_params = &testsuite_params; 8709 struct crypto_unittest_params *ut_params = &unittest_params; 8710 uint8_t *plaintext, *ciphertext; 8711 uint8_t *iv_ptr; 8712 int32_t cipher_len, crc_len; 8713 int ret = TEST_SUCCESS; 8714 8715 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8716 rte_cryptodev_get_sec_ctx( 8717 ts_params->valid_devs[0]); 8718 8719 /* Verify the capabilities */ 8720 struct rte_security_capability_idx sec_cap_idx; 8721 const struct rte_security_capability *sec_cap; 8722 const struct rte_cryptodev_capabilities *crypto_cap; 8723 const struct rte_cryptodev_symmetric_capability *sym_cap; 8724 int j = 0; 8725 8726 sec_cap_idx.action = ut_params->type; 8727 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 8728 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 8729 8730 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 8731 if (sec_cap == NULL) 8732 return -ENOTSUP; 8733 8734 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 8735 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 8736 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 8737 crypto_cap->sym.xform_type == 8738 RTE_CRYPTO_SYM_XFORM_CIPHER && 8739 crypto_cap->sym.cipher.algo == 8740 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 8741 sym_cap = &crypto_cap->sym; 8742 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 8743 d_td->key.len, 8744 d_td->iv.len) == 0) 8745 break; 8746 } 8747 } 8748 8749 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 8750 return -ENOTSUP; 8751 8752 /* Setup source mbuf payload */ 8753 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8754 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8755 rte_pktmbuf_tailroom(ut_params->ibuf)); 8756 8757 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8758 d_td->plaintext.len); 8759 8760 memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len); 8761 8762 /* Setup cipher session parameters */ 8763 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8764 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 8765 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 8766 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 8767 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 8768 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 8769 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 8770 ut_params->cipher_xform.next = NULL; 8771 8772 /* Setup DOCSIS session parameters */ 8773 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 8774 8775 struct rte_security_session_conf sess_conf = { 8776 .action_type = ut_params->type, 8777 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 8778 .docsis = ut_params->docsis_xform, 8779 .crypto_xform = &ut_params->cipher_xform, 8780 }; 8781 8782 /* Create security session */ 8783 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 8784 ts_params->session_mpool, 8785 ts_params->session_priv_mpool); 8786 8787 if (!ut_params->sec_session) { 8788 printf("TestCase %s(%d) line %d: %s\n", 8789 __func__, i, __LINE__, "failed to allocate session"); 8790 ret = TEST_FAILED; 8791 goto on_err; 8792 } 8793 8794 /* Generate crypto op data structure */ 8795 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8796 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8797 if (!ut_params->op) { 8798 printf("TestCase %s(%d) line %d: %s\n", 8799 __func__, i, __LINE__, 8800 "failed to allocate security crypto operation"); 8801 ret = TEST_FAILED; 8802 goto on_err; 8803 } 8804 8805 /* Setup CRC operation parameters */ 8806 crc_len = d_td->plaintext.no_crc == false ? 8807 (d_td->plaintext.len - 8808 d_td->plaintext.crc_offset - 8809 RTE_ETHER_CRC_LEN) : 8810 0; 8811 crc_len = crc_len > 0 ? crc_len : 0; 8812 ut_params->op->sym->auth.data.length = crc_len; 8813 ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset; 8814 8815 /* Setup cipher operation parameters */ 8816 cipher_len = d_td->plaintext.no_cipher == false ? 8817 (d_td->plaintext.len - 8818 d_td->plaintext.cipher_offset) : 8819 0; 8820 cipher_len = cipher_len > 0 ? cipher_len : 0; 8821 ut_params->op->sym->cipher.data.length = cipher_len; 8822 ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset; 8823 8824 /* Setup cipher IV */ 8825 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 8826 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 8827 8828 /* Attach session to operation */ 8829 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8830 8831 /* Set crypto operation mbufs */ 8832 ut_params->op->sym->m_src = ut_params->ibuf; 8833 ut_params->op->sym->m_dst = NULL; 8834 8835 /* Process crypto operation */ 8836 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 8837 NULL) { 8838 printf("TestCase %s(%d) line %d: %s\n", 8839 __func__, i, __LINE__, 8840 "failed to process security crypto op"); 8841 ret = TEST_FAILED; 8842 goto on_err; 8843 } 8844 8845 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8846 printf("TestCase %s(%d) line %d: %s\n", 8847 __func__, i, __LINE__, "crypto op processing failed"); 8848 ret = TEST_FAILED; 8849 goto on_err; 8850 } 8851 8852 /* Validate ciphertext */ 8853 ciphertext = plaintext; 8854 8855 if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) { 8856 printf("TestCase %s(%d) line %d: %s\n", 8857 __func__, i, __LINE__, "ciphertext not as expected\n"); 8858 rte_hexdump(stdout, "expected", d_td->ciphertext.data, 8859 d_td->ciphertext.len); 8860 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len); 8861 ret = TEST_FAILED; 8862 goto on_err; 8863 } 8864 8865 on_err: 8866 rte_crypto_op_free(ut_params->op); 8867 ut_params->op = NULL; 8868 8869 if (ut_params->sec_session) 8870 rte_security_session_destroy(ctx, ut_params->sec_session); 8871 ut_params->sec_session = NULL; 8872 8873 rte_pktmbuf_free(ut_params->ibuf); 8874 ut_params->ibuf = NULL; 8875 8876 return ret; 8877 } 8878 8879 #define TEST_DOCSIS_COUNT(func) do { \ 8880 int ret = func; \ 8881 if (ret == TEST_SUCCESS) { \ 8882 printf("\t%2d)", n++); \ 8883 printf("+++++ PASSED:" #func"\n"); \ 8884 p++; \ 8885 } else if (ret == -ENOTSUP) { \ 8886 printf("\t%2d)", n++); \ 8887 printf("~~~~~ UNSUPP:" #func"\n"); \ 8888 u++; \ 8889 } else { \ 8890 printf("\t%2d)", n++); \ 8891 printf("----- FAILED:" #func"\n"); \ 8892 f++; \ 8893 } \ 8894 } while (0) 8895 8896 static int 8897 test_DOCSIS_PROTO_uplink_all(void) 8898 { 8899 int p = 0, u = 0, f = 0, n = 0; 8900 8901 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1)); 8902 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2)); 8903 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3)); 8904 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4)); 8905 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5)); 8906 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6)); 8907 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7)); 8908 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8)); 8909 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9)); 8910 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10)); 8911 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11)); 8912 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12)); 8913 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13)); 8914 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14)); 8915 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15)); 8916 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16)); 8917 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17)); 8918 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18)); 8919 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19)); 8920 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20)); 8921 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21)); 8922 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22)); 8923 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23)); 8924 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24)); 8925 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25)); 8926 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26)); 8927 8928 if (f) 8929 printf("## %s: %d passed out of %d (%d unsupported)\n", 8930 __func__, p, n, u); 8931 8932 return f; 8933 }; 8934 8935 static int 8936 test_DOCSIS_PROTO_downlink_all(void) 8937 { 8938 int p = 0, u = 0, f = 0, n = 0; 8939 8940 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1)); 8941 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2)); 8942 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3)); 8943 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4)); 8944 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5)); 8945 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6)); 8946 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7)); 8947 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8)); 8948 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9)); 8949 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10)); 8950 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11)); 8951 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12)); 8952 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13)); 8953 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14)); 8954 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15)); 8955 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16)); 8956 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17)); 8957 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18)); 8958 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19)); 8959 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20)); 8960 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21)); 8961 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22)); 8962 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23)); 8963 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24)); 8964 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25)); 8965 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26)); 8966 8967 if (f) 8968 printf("## %s: %d passed out of %d (%d unsupported)\n", 8969 __func__, p, n, u); 8970 8971 return f; 8972 }; 8973 8974 static int 8975 test_DOCSIS_PROTO_all(void) 8976 { 8977 struct crypto_testsuite_params *ts_params = &testsuite_params; 8978 struct crypto_unittest_params *ut_params = &unittest_params; 8979 struct rte_cryptodev_info dev_info; 8980 int status; 8981 8982 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8983 uint64_t feat_flags = dev_info.feature_flags; 8984 8985 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 8986 return -ENOTSUP; 8987 8988 /* Set action type */ 8989 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 8990 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 8991 gbl_action_type; 8992 8993 if (security_proto_supported(ut_params->type, 8994 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 8995 return -ENOTSUP; 8996 8997 status = test_DOCSIS_PROTO_uplink_all(); 8998 status += test_DOCSIS_PROTO_downlink_all(); 8999 9000 if (status) 9001 return TEST_FAILED; 9002 else 9003 return TEST_SUCCESS; 9004 } 9005 #endif 9006 9007 static int 9008 test_AES_GCM_authenticated_encryption_test_case_1(void) 9009 { 9010 return test_authenticated_encryption(&gcm_test_case_1); 9011 } 9012 9013 static int 9014 test_AES_GCM_authenticated_encryption_test_case_2(void) 9015 { 9016 return test_authenticated_encryption(&gcm_test_case_2); 9017 } 9018 9019 static int 9020 test_AES_GCM_authenticated_encryption_test_case_3(void) 9021 { 9022 return test_authenticated_encryption(&gcm_test_case_3); 9023 } 9024 9025 static int 9026 test_AES_GCM_authenticated_encryption_test_case_4(void) 9027 { 9028 return test_authenticated_encryption(&gcm_test_case_4); 9029 } 9030 9031 static int 9032 test_AES_GCM_authenticated_encryption_test_case_5(void) 9033 { 9034 return test_authenticated_encryption(&gcm_test_case_5); 9035 } 9036 9037 static int 9038 test_AES_GCM_authenticated_encryption_test_case_6(void) 9039 { 9040 return test_authenticated_encryption(&gcm_test_case_6); 9041 } 9042 9043 static int 9044 test_AES_GCM_authenticated_encryption_test_case_7(void) 9045 { 9046 return test_authenticated_encryption(&gcm_test_case_7); 9047 } 9048 9049 static int 9050 test_AES_GCM_authenticated_encryption_test_case_8(void) 9051 { 9052 return test_authenticated_encryption(&gcm_test_case_8); 9053 } 9054 9055 static int 9056 test_AES_GCM_J0_authenticated_encryption_test_case_1(void) 9057 { 9058 return test_authenticated_encryption(&gcm_J0_test_case_1); 9059 } 9060 9061 static int 9062 test_AES_GCM_auth_encryption_test_case_192_1(void) 9063 { 9064 return test_authenticated_encryption(&gcm_test_case_192_1); 9065 } 9066 9067 static int 9068 test_AES_GCM_auth_encryption_test_case_192_2(void) 9069 { 9070 return test_authenticated_encryption(&gcm_test_case_192_2); 9071 } 9072 9073 static int 9074 test_AES_GCM_auth_encryption_test_case_192_3(void) 9075 { 9076 return test_authenticated_encryption(&gcm_test_case_192_3); 9077 } 9078 9079 static int 9080 test_AES_GCM_auth_encryption_test_case_192_4(void) 9081 { 9082 return test_authenticated_encryption(&gcm_test_case_192_4); 9083 } 9084 9085 static int 9086 test_AES_GCM_auth_encryption_test_case_192_5(void) 9087 { 9088 return test_authenticated_encryption(&gcm_test_case_192_5); 9089 } 9090 9091 static int 9092 test_AES_GCM_auth_encryption_test_case_192_6(void) 9093 { 9094 return test_authenticated_encryption(&gcm_test_case_192_6); 9095 } 9096 9097 static int 9098 test_AES_GCM_auth_encryption_test_case_192_7(void) 9099 { 9100 return test_authenticated_encryption(&gcm_test_case_192_7); 9101 } 9102 9103 static int 9104 test_AES_GCM_auth_encryption_test_case_256_1(void) 9105 { 9106 return test_authenticated_encryption(&gcm_test_case_256_1); 9107 } 9108 9109 static int 9110 test_AES_GCM_auth_encryption_test_case_256_2(void) 9111 { 9112 return test_authenticated_encryption(&gcm_test_case_256_2); 9113 } 9114 9115 static int 9116 test_AES_GCM_auth_encryption_test_case_256_3(void) 9117 { 9118 return test_authenticated_encryption(&gcm_test_case_256_3); 9119 } 9120 9121 static int 9122 test_AES_GCM_auth_encryption_test_case_256_4(void) 9123 { 9124 return test_authenticated_encryption(&gcm_test_case_256_4); 9125 } 9126 9127 static int 9128 test_AES_GCM_auth_encryption_test_case_256_5(void) 9129 { 9130 return test_authenticated_encryption(&gcm_test_case_256_5); 9131 } 9132 9133 static int 9134 test_AES_GCM_auth_encryption_test_case_256_6(void) 9135 { 9136 return test_authenticated_encryption(&gcm_test_case_256_6); 9137 } 9138 9139 static int 9140 test_AES_GCM_auth_encryption_test_case_256_7(void) 9141 { 9142 return test_authenticated_encryption(&gcm_test_case_256_7); 9143 } 9144 9145 static int 9146 test_AES_GCM_auth_encryption_test_case_aad_1(void) 9147 { 9148 return test_authenticated_encryption(&gcm_test_case_aad_1); 9149 } 9150 9151 static int 9152 test_AES_GCM_auth_encryption_test_case_aad_2(void) 9153 { 9154 return test_authenticated_encryption(&gcm_test_case_aad_2); 9155 } 9156 9157 static int 9158 test_AES_GCM_auth_encryption_fail_iv_corrupt(void) 9159 { 9160 struct aead_test_data tdata; 9161 int res; 9162 9163 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9164 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9165 tdata.iv.data[0] += 1; 9166 res = test_authenticated_encryption(&tdata); 9167 if (res == -ENOTSUP) 9168 return res; 9169 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9170 return TEST_SUCCESS; 9171 } 9172 9173 static int 9174 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void) 9175 { 9176 struct aead_test_data tdata; 9177 int res; 9178 9179 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9180 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9181 tdata.plaintext.data[0] += 1; 9182 res = test_authenticated_encryption(&tdata); 9183 if (res == -ENOTSUP) 9184 return res; 9185 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9186 return TEST_SUCCESS; 9187 } 9188 9189 static int 9190 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void) 9191 { 9192 struct aead_test_data tdata; 9193 int res; 9194 9195 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9196 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9197 tdata.ciphertext.data[0] += 1; 9198 res = test_authenticated_encryption(&tdata); 9199 if (res == -ENOTSUP) 9200 return res; 9201 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9202 return TEST_SUCCESS; 9203 } 9204 9205 static int 9206 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void) 9207 { 9208 struct aead_test_data tdata; 9209 int res; 9210 9211 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9212 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9213 tdata.aad.len += 1; 9214 res = test_authenticated_encryption(&tdata); 9215 if (res == -ENOTSUP) 9216 return res; 9217 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9218 return TEST_SUCCESS; 9219 } 9220 9221 static int 9222 test_AES_GCM_auth_encryption_fail_aad_corrupt(void) 9223 { 9224 struct aead_test_data tdata; 9225 uint8_t aad[gcm_test_case_7.aad.len]; 9226 int res; 9227 9228 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9229 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9230 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 9231 aad[0] += 1; 9232 tdata.aad.data = aad; 9233 res = test_authenticated_encryption(&tdata); 9234 if (res == -ENOTSUP) 9235 return res; 9236 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9237 return TEST_SUCCESS; 9238 } 9239 9240 static int 9241 test_AES_GCM_auth_encryption_fail_tag_corrupt(void) 9242 { 9243 struct aead_test_data tdata; 9244 int res; 9245 9246 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9247 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9248 tdata.auth_tag.data[0] += 1; 9249 res = test_authenticated_encryption(&tdata); 9250 if (res == -ENOTSUP) 9251 return res; 9252 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9253 return TEST_SUCCESS; 9254 } 9255 9256 static int 9257 test_authenticated_decryption(const struct aead_test_data *tdata) 9258 { 9259 struct crypto_testsuite_params *ts_params = &testsuite_params; 9260 struct crypto_unittest_params *ut_params = &unittest_params; 9261 9262 int retval; 9263 uint8_t *plaintext; 9264 uint32_t i; 9265 struct rte_cryptodev_info dev_info; 9266 9267 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9268 uint64_t feat_flags = dev_info.feature_flags; 9269 9270 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9271 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9272 printf("Device doesn't support RAW data-path APIs.\n"); 9273 return -ENOTSUP; 9274 } 9275 9276 /* Verify the capabilities */ 9277 struct rte_cryptodev_sym_capability_idx cap_idx; 9278 const struct rte_cryptodev_symmetric_capability *capability; 9279 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9280 cap_idx.algo.aead = tdata->algo; 9281 capability = rte_cryptodev_sym_capability_get( 9282 ts_params->valid_devs[0], &cap_idx); 9283 if (capability == NULL) 9284 return -ENOTSUP; 9285 if (rte_cryptodev_sym_capability_check_aead( 9286 capability, tdata->key.len, tdata->auth_tag.len, 9287 tdata->aad.len, tdata->iv.len)) 9288 return -ENOTSUP; 9289 9290 /* Create AEAD session */ 9291 retval = create_aead_session(ts_params->valid_devs[0], 9292 tdata->algo, 9293 RTE_CRYPTO_AEAD_OP_DECRYPT, 9294 tdata->key.data, tdata->key.len, 9295 tdata->aad.len, tdata->auth_tag.len, 9296 tdata->iv.len); 9297 if (retval < 0) 9298 return retval; 9299 9300 /* alloc mbuf and set payload */ 9301 if (tdata->aad.len > MBUF_SIZE) { 9302 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 9303 /* Populate full size of add data */ 9304 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 9305 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 9306 } else 9307 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9308 9309 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9310 rte_pktmbuf_tailroom(ut_params->ibuf)); 9311 9312 /* Create AEAD operation */ 9313 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 9314 if (retval < 0) 9315 return retval; 9316 9317 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9318 9319 ut_params->op->sym->m_src = ut_params->ibuf; 9320 9321 /* Process crypto operation */ 9322 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9323 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 9324 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 9325 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 9326 ut_params->op, 0, 0, 0, 0); 9327 else 9328 TEST_ASSERT_NOT_NULL( 9329 process_crypto_request(ts_params->valid_devs[0], 9330 ut_params->op), "failed to process sym crypto op"); 9331 9332 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9333 "crypto op processing failed"); 9334 9335 if (ut_params->op->sym->m_dst) 9336 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 9337 uint8_t *); 9338 else 9339 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 9340 uint8_t *, 9341 ut_params->op->sym->cipher.data.offset); 9342 9343 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 9344 9345 /* Validate obuf */ 9346 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9347 plaintext, 9348 tdata->plaintext.data, 9349 tdata->plaintext.len, 9350 "Plaintext data not as expected"); 9351 9352 TEST_ASSERT_EQUAL(ut_params->op->status, 9353 RTE_CRYPTO_OP_STATUS_SUCCESS, 9354 "Authentication failed"); 9355 9356 return 0; 9357 } 9358 9359 static int 9360 test_AES_GCM_authenticated_decryption_test_case_1(void) 9361 { 9362 return test_authenticated_decryption(&gcm_test_case_1); 9363 } 9364 9365 static int 9366 test_AES_GCM_authenticated_decryption_test_case_2(void) 9367 { 9368 return test_authenticated_decryption(&gcm_test_case_2); 9369 } 9370 9371 static int 9372 test_AES_GCM_authenticated_decryption_test_case_3(void) 9373 { 9374 return test_authenticated_decryption(&gcm_test_case_3); 9375 } 9376 9377 static int 9378 test_AES_GCM_authenticated_decryption_test_case_4(void) 9379 { 9380 return test_authenticated_decryption(&gcm_test_case_4); 9381 } 9382 9383 static int 9384 test_AES_GCM_authenticated_decryption_test_case_5(void) 9385 { 9386 return test_authenticated_decryption(&gcm_test_case_5); 9387 } 9388 9389 static int 9390 test_AES_GCM_authenticated_decryption_test_case_6(void) 9391 { 9392 return test_authenticated_decryption(&gcm_test_case_6); 9393 } 9394 9395 static int 9396 test_AES_GCM_authenticated_decryption_test_case_7(void) 9397 { 9398 return test_authenticated_decryption(&gcm_test_case_7); 9399 } 9400 9401 static int 9402 test_AES_GCM_authenticated_decryption_test_case_8(void) 9403 { 9404 return test_authenticated_decryption(&gcm_test_case_8); 9405 } 9406 9407 static int 9408 test_AES_GCM_J0_authenticated_decryption_test_case_1(void) 9409 { 9410 return test_authenticated_decryption(&gcm_J0_test_case_1); 9411 } 9412 9413 static int 9414 test_AES_GCM_auth_decryption_test_case_192_1(void) 9415 { 9416 return test_authenticated_decryption(&gcm_test_case_192_1); 9417 } 9418 9419 static int 9420 test_AES_GCM_auth_decryption_test_case_192_2(void) 9421 { 9422 return test_authenticated_decryption(&gcm_test_case_192_2); 9423 } 9424 9425 static int 9426 test_AES_GCM_auth_decryption_test_case_192_3(void) 9427 { 9428 return test_authenticated_decryption(&gcm_test_case_192_3); 9429 } 9430 9431 static int 9432 test_AES_GCM_auth_decryption_test_case_192_4(void) 9433 { 9434 return test_authenticated_decryption(&gcm_test_case_192_4); 9435 } 9436 9437 static int 9438 test_AES_GCM_auth_decryption_test_case_192_5(void) 9439 { 9440 return test_authenticated_decryption(&gcm_test_case_192_5); 9441 } 9442 9443 static int 9444 test_AES_GCM_auth_decryption_test_case_192_6(void) 9445 { 9446 return test_authenticated_decryption(&gcm_test_case_192_6); 9447 } 9448 9449 static int 9450 test_AES_GCM_auth_decryption_test_case_192_7(void) 9451 { 9452 return test_authenticated_decryption(&gcm_test_case_192_7); 9453 } 9454 9455 static int 9456 test_AES_GCM_auth_decryption_test_case_256_1(void) 9457 { 9458 return test_authenticated_decryption(&gcm_test_case_256_1); 9459 } 9460 9461 static int 9462 test_AES_GCM_auth_decryption_test_case_256_2(void) 9463 { 9464 return test_authenticated_decryption(&gcm_test_case_256_2); 9465 } 9466 9467 static int 9468 test_AES_GCM_auth_decryption_test_case_256_3(void) 9469 { 9470 return test_authenticated_decryption(&gcm_test_case_256_3); 9471 } 9472 9473 static int 9474 test_AES_GCM_auth_decryption_test_case_256_4(void) 9475 { 9476 return test_authenticated_decryption(&gcm_test_case_256_4); 9477 } 9478 9479 static int 9480 test_AES_GCM_auth_decryption_test_case_256_5(void) 9481 { 9482 return test_authenticated_decryption(&gcm_test_case_256_5); 9483 } 9484 9485 static int 9486 test_AES_GCM_auth_decryption_test_case_256_6(void) 9487 { 9488 return test_authenticated_decryption(&gcm_test_case_256_6); 9489 } 9490 9491 static int 9492 test_AES_GCM_auth_decryption_test_case_256_7(void) 9493 { 9494 return test_authenticated_decryption(&gcm_test_case_256_7); 9495 } 9496 9497 static int 9498 test_AES_GCM_auth_decryption_test_case_aad_1(void) 9499 { 9500 return test_authenticated_decryption(&gcm_test_case_aad_1); 9501 } 9502 9503 static int 9504 test_AES_GCM_auth_decryption_test_case_aad_2(void) 9505 { 9506 return test_authenticated_decryption(&gcm_test_case_aad_2); 9507 } 9508 9509 static int 9510 test_AES_GCM_auth_decryption_fail_iv_corrupt(void) 9511 { 9512 struct aead_test_data tdata; 9513 int res; 9514 9515 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9516 tdata.iv.data[0] += 1; 9517 res = test_authenticated_decryption(&tdata); 9518 if (res == -ENOTSUP) 9519 return res; 9520 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9521 return TEST_SUCCESS; 9522 } 9523 9524 static int 9525 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void) 9526 { 9527 struct aead_test_data tdata; 9528 int res; 9529 9530 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9531 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9532 tdata.plaintext.data[0] += 1; 9533 res = test_authenticated_decryption(&tdata); 9534 if (res == -ENOTSUP) 9535 return res; 9536 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9537 return TEST_SUCCESS; 9538 } 9539 9540 static int 9541 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void) 9542 { 9543 struct aead_test_data tdata; 9544 int res; 9545 9546 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9547 tdata.ciphertext.data[0] += 1; 9548 res = test_authenticated_decryption(&tdata); 9549 if (res == -ENOTSUP) 9550 return res; 9551 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9552 return TEST_SUCCESS; 9553 } 9554 9555 static int 9556 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void) 9557 { 9558 struct aead_test_data tdata; 9559 int res; 9560 9561 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9562 tdata.aad.len += 1; 9563 res = test_authenticated_decryption(&tdata); 9564 if (res == -ENOTSUP) 9565 return res; 9566 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9567 return TEST_SUCCESS; 9568 } 9569 9570 static int 9571 test_AES_GCM_auth_decryption_fail_aad_corrupt(void) 9572 { 9573 struct aead_test_data tdata; 9574 uint8_t aad[gcm_test_case_7.aad.len]; 9575 int res; 9576 9577 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9578 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 9579 aad[0] += 1; 9580 tdata.aad.data = aad; 9581 res = test_authenticated_decryption(&tdata); 9582 if (res == -ENOTSUP) 9583 return res; 9584 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9585 return TEST_SUCCESS; 9586 } 9587 9588 static int 9589 test_AES_GCM_auth_decryption_fail_tag_corrupt(void) 9590 { 9591 struct aead_test_data tdata; 9592 int res; 9593 9594 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9595 tdata.auth_tag.data[0] += 1; 9596 res = test_authenticated_decryption(&tdata); 9597 if (res == -ENOTSUP) 9598 return res; 9599 TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed"); 9600 return TEST_SUCCESS; 9601 } 9602 9603 static int 9604 test_authenticated_encryption_oop(const struct aead_test_data *tdata) 9605 { 9606 struct crypto_testsuite_params *ts_params = &testsuite_params; 9607 struct crypto_unittest_params *ut_params = &unittest_params; 9608 9609 int retval; 9610 uint8_t *ciphertext, *auth_tag; 9611 uint16_t plaintext_pad_len; 9612 9613 /* Verify the capabilities */ 9614 struct rte_cryptodev_sym_capability_idx cap_idx; 9615 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9616 cap_idx.algo.aead = tdata->algo; 9617 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9618 &cap_idx) == NULL) 9619 return -ENOTSUP; 9620 9621 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 9622 return -ENOTSUP; 9623 9624 /* not supported with CPU crypto */ 9625 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9626 return -ENOTSUP; 9627 9628 /* Create AEAD session */ 9629 retval = create_aead_session(ts_params->valid_devs[0], 9630 tdata->algo, 9631 RTE_CRYPTO_AEAD_OP_ENCRYPT, 9632 tdata->key.data, tdata->key.len, 9633 tdata->aad.len, tdata->auth_tag.len, 9634 tdata->iv.len); 9635 if (retval < 0) 9636 return retval; 9637 9638 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9639 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9640 9641 /* clear mbuf payload */ 9642 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9643 rte_pktmbuf_tailroom(ut_params->ibuf)); 9644 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 9645 rte_pktmbuf_tailroom(ut_params->obuf)); 9646 9647 /* Create AEAD operation */ 9648 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 9649 if (retval < 0) 9650 return retval; 9651 9652 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9653 9654 ut_params->op->sym->m_src = ut_params->ibuf; 9655 ut_params->op->sym->m_dst = ut_params->obuf; 9656 9657 /* Process crypto operation */ 9658 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 9659 ut_params->op), "failed to process sym crypto op"); 9660 9661 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9662 "crypto op processing failed"); 9663 9664 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 9665 9666 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 9667 ut_params->op->sym->cipher.data.offset); 9668 auth_tag = ciphertext + plaintext_pad_len; 9669 9670 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 9671 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 9672 9673 /* Validate obuf */ 9674 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9675 ciphertext, 9676 tdata->ciphertext.data, 9677 tdata->ciphertext.len, 9678 "Ciphertext data not as expected"); 9679 9680 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9681 auth_tag, 9682 tdata->auth_tag.data, 9683 tdata->auth_tag.len, 9684 "Generated auth tag not as expected"); 9685 9686 return 0; 9687 9688 } 9689 9690 static int 9691 test_AES_GCM_authenticated_encryption_oop_test_case_1(void) 9692 { 9693 return test_authenticated_encryption_oop(&gcm_test_case_5); 9694 } 9695 9696 static int 9697 test_authenticated_decryption_oop(const struct aead_test_data *tdata) 9698 { 9699 struct crypto_testsuite_params *ts_params = &testsuite_params; 9700 struct crypto_unittest_params *ut_params = &unittest_params; 9701 9702 int retval; 9703 uint8_t *plaintext; 9704 9705 /* Verify the capabilities */ 9706 struct rte_cryptodev_sym_capability_idx cap_idx; 9707 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9708 cap_idx.algo.aead = tdata->algo; 9709 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9710 &cap_idx) == NULL) 9711 return -ENOTSUP; 9712 9713 /* not supported with CPU crypto and raw data-path APIs*/ 9714 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO || 9715 global_api_test_type == CRYPTODEV_RAW_API_TEST) 9716 return -ENOTSUP; 9717 9718 /* Create AEAD session */ 9719 retval = create_aead_session(ts_params->valid_devs[0], 9720 tdata->algo, 9721 RTE_CRYPTO_AEAD_OP_DECRYPT, 9722 tdata->key.data, tdata->key.len, 9723 tdata->aad.len, tdata->auth_tag.len, 9724 tdata->iv.len); 9725 if (retval < 0) 9726 return retval; 9727 9728 /* alloc mbuf and set payload */ 9729 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9730 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9731 9732 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9733 rte_pktmbuf_tailroom(ut_params->ibuf)); 9734 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 9735 rte_pktmbuf_tailroom(ut_params->obuf)); 9736 9737 /* Create AEAD operation */ 9738 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 9739 if (retval < 0) 9740 return retval; 9741 9742 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9743 9744 ut_params->op->sym->m_src = ut_params->ibuf; 9745 ut_params->op->sym->m_dst = ut_params->obuf; 9746 9747 /* Process crypto operation */ 9748 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 9749 ut_params->op), "failed to process sym crypto op"); 9750 9751 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9752 "crypto op processing failed"); 9753 9754 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 9755 ut_params->op->sym->cipher.data.offset); 9756 9757 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 9758 9759 /* Validate obuf */ 9760 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9761 plaintext, 9762 tdata->plaintext.data, 9763 tdata->plaintext.len, 9764 "Plaintext data not as expected"); 9765 9766 TEST_ASSERT_EQUAL(ut_params->op->status, 9767 RTE_CRYPTO_OP_STATUS_SUCCESS, 9768 "Authentication failed"); 9769 return 0; 9770 } 9771 9772 static int 9773 test_AES_GCM_authenticated_decryption_oop_test_case_1(void) 9774 { 9775 return test_authenticated_decryption_oop(&gcm_test_case_5); 9776 } 9777 9778 static int 9779 test_authenticated_encryption_sessionless( 9780 const struct aead_test_data *tdata) 9781 { 9782 struct crypto_testsuite_params *ts_params = &testsuite_params; 9783 struct crypto_unittest_params *ut_params = &unittest_params; 9784 9785 int retval; 9786 uint8_t *ciphertext, *auth_tag; 9787 uint16_t plaintext_pad_len; 9788 uint8_t key[tdata->key.len + 1]; 9789 struct rte_cryptodev_info dev_info; 9790 9791 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9792 uint64_t feat_flags = dev_info.feature_flags; 9793 9794 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 9795 printf("Device doesn't support Sessionless ops.\n"); 9796 return -ENOTSUP; 9797 } 9798 9799 /* not supported with CPU crypto */ 9800 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9801 return -ENOTSUP; 9802 9803 /* Verify the capabilities */ 9804 struct rte_cryptodev_sym_capability_idx cap_idx; 9805 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9806 cap_idx.algo.aead = tdata->algo; 9807 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9808 &cap_idx) == NULL) 9809 return -ENOTSUP; 9810 9811 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9812 9813 /* clear mbuf payload */ 9814 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9815 rte_pktmbuf_tailroom(ut_params->ibuf)); 9816 9817 /* Create AEAD operation */ 9818 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 9819 if (retval < 0) 9820 return retval; 9821 9822 /* Create GCM xform */ 9823 memcpy(key, tdata->key.data, tdata->key.len); 9824 retval = create_aead_xform(ut_params->op, 9825 tdata->algo, 9826 RTE_CRYPTO_AEAD_OP_ENCRYPT, 9827 key, tdata->key.len, 9828 tdata->aad.len, tdata->auth_tag.len, 9829 tdata->iv.len); 9830 if (retval < 0) 9831 return retval; 9832 9833 ut_params->op->sym->m_src = ut_params->ibuf; 9834 9835 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 9836 RTE_CRYPTO_OP_SESSIONLESS, 9837 "crypto op session type not sessionless"); 9838 9839 /* Process crypto operation */ 9840 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 9841 ut_params->op), "failed to process sym crypto op"); 9842 9843 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 9844 9845 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9846 "crypto op status not success"); 9847 9848 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 9849 9850 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 9851 ut_params->op->sym->cipher.data.offset); 9852 auth_tag = ciphertext + plaintext_pad_len; 9853 9854 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 9855 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 9856 9857 /* Validate obuf */ 9858 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9859 ciphertext, 9860 tdata->ciphertext.data, 9861 tdata->ciphertext.len, 9862 "Ciphertext data not as expected"); 9863 9864 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9865 auth_tag, 9866 tdata->auth_tag.data, 9867 tdata->auth_tag.len, 9868 "Generated auth tag not as expected"); 9869 9870 return 0; 9871 9872 } 9873 9874 static int 9875 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void) 9876 { 9877 return test_authenticated_encryption_sessionless( 9878 &gcm_test_case_5); 9879 } 9880 9881 static int 9882 test_authenticated_decryption_sessionless( 9883 const struct aead_test_data *tdata) 9884 { 9885 struct crypto_testsuite_params *ts_params = &testsuite_params; 9886 struct crypto_unittest_params *ut_params = &unittest_params; 9887 9888 int retval; 9889 uint8_t *plaintext; 9890 uint8_t key[tdata->key.len + 1]; 9891 struct rte_cryptodev_info dev_info; 9892 9893 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9894 uint64_t feat_flags = dev_info.feature_flags; 9895 9896 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 9897 printf("Device doesn't support Sessionless ops.\n"); 9898 return -ENOTSUP; 9899 } 9900 9901 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9902 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9903 printf("Device doesn't support RAW data-path APIs.\n"); 9904 return -ENOTSUP; 9905 } 9906 9907 /* not supported with CPU crypto */ 9908 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9909 return -ENOTSUP; 9910 9911 /* Verify the capabilities */ 9912 struct rte_cryptodev_sym_capability_idx cap_idx; 9913 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9914 cap_idx.algo.aead = tdata->algo; 9915 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9916 &cap_idx) == NULL) 9917 return -ENOTSUP; 9918 9919 /* alloc mbuf and set payload */ 9920 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9921 9922 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9923 rte_pktmbuf_tailroom(ut_params->ibuf)); 9924 9925 /* Create AEAD operation */ 9926 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 9927 if (retval < 0) 9928 return retval; 9929 9930 /* Create AEAD xform */ 9931 memcpy(key, tdata->key.data, tdata->key.len); 9932 retval = create_aead_xform(ut_params->op, 9933 tdata->algo, 9934 RTE_CRYPTO_AEAD_OP_DECRYPT, 9935 key, tdata->key.len, 9936 tdata->aad.len, tdata->auth_tag.len, 9937 tdata->iv.len); 9938 if (retval < 0) 9939 return retval; 9940 9941 ut_params->op->sym->m_src = ut_params->ibuf; 9942 9943 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 9944 RTE_CRYPTO_OP_SESSIONLESS, 9945 "crypto op session type not sessionless"); 9946 9947 /* Process crypto operation */ 9948 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 9949 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 9950 ut_params->op, 0, 0, 0, 0); 9951 else 9952 TEST_ASSERT_NOT_NULL(process_crypto_request( 9953 ts_params->valid_devs[0], ut_params->op), 9954 "failed to process sym crypto op"); 9955 9956 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 9957 9958 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9959 "crypto op status not success"); 9960 9961 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 9962 ut_params->op->sym->cipher.data.offset); 9963 9964 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 9965 9966 /* Validate obuf */ 9967 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9968 plaintext, 9969 tdata->plaintext.data, 9970 tdata->plaintext.len, 9971 "Plaintext data not as expected"); 9972 9973 TEST_ASSERT_EQUAL(ut_params->op->status, 9974 RTE_CRYPTO_OP_STATUS_SUCCESS, 9975 "Authentication failed"); 9976 return 0; 9977 } 9978 9979 static int 9980 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void) 9981 { 9982 return test_authenticated_decryption_sessionless( 9983 &gcm_test_case_5); 9984 } 9985 9986 static int 9987 test_AES_CCM_authenticated_encryption_test_case_128_1(void) 9988 { 9989 return test_authenticated_encryption(&ccm_test_case_128_1); 9990 } 9991 9992 static int 9993 test_AES_CCM_authenticated_encryption_test_case_128_2(void) 9994 { 9995 return test_authenticated_encryption(&ccm_test_case_128_2); 9996 } 9997 9998 static int 9999 test_AES_CCM_authenticated_encryption_test_case_128_3(void) 10000 { 10001 return test_authenticated_encryption(&ccm_test_case_128_3); 10002 } 10003 10004 static int 10005 test_AES_CCM_authenticated_decryption_test_case_128_1(void) 10006 { 10007 return test_authenticated_decryption(&ccm_test_case_128_1); 10008 } 10009 10010 static int 10011 test_AES_CCM_authenticated_decryption_test_case_128_2(void) 10012 { 10013 return test_authenticated_decryption(&ccm_test_case_128_2); 10014 } 10015 10016 static int 10017 test_AES_CCM_authenticated_decryption_test_case_128_3(void) 10018 { 10019 return test_authenticated_decryption(&ccm_test_case_128_3); 10020 } 10021 10022 static int 10023 test_AES_CCM_authenticated_encryption_test_case_192_1(void) 10024 { 10025 return test_authenticated_encryption(&ccm_test_case_192_1); 10026 } 10027 10028 static int 10029 test_AES_CCM_authenticated_encryption_test_case_192_2(void) 10030 { 10031 return test_authenticated_encryption(&ccm_test_case_192_2); 10032 } 10033 10034 static int 10035 test_AES_CCM_authenticated_encryption_test_case_192_3(void) 10036 { 10037 return test_authenticated_encryption(&ccm_test_case_192_3); 10038 } 10039 10040 static int 10041 test_AES_CCM_authenticated_decryption_test_case_192_1(void) 10042 { 10043 return test_authenticated_decryption(&ccm_test_case_192_1); 10044 } 10045 10046 static int 10047 test_AES_CCM_authenticated_decryption_test_case_192_2(void) 10048 { 10049 return test_authenticated_decryption(&ccm_test_case_192_2); 10050 } 10051 10052 static int 10053 test_AES_CCM_authenticated_decryption_test_case_192_3(void) 10054 { 10055 return test_authenticated_decryption(&ccm_test_case_192_3); 10056 } 10057 10058 static int 10059 test_AES_CCM_authenticated_encryption_test_case_256_1(void) 10060 { 10061 return test_authenticated_encryption(&ccm_test_case_256_1); 10062 } 10063 10064 static int 10065 test_AES_CCM_authenticated_encryption_test_case_256_2(void) 10066 { 10067 return test_authenticated_encryption(&ccm_test_case_256_2); 10068 } 10069 10070 static int 10071 test_AES_CCM_authenticated_encryption_test_case_256_3(void) 10072 { 10073 return test_authenticated_encryption(&ccm_test_case_256_3); 10074 } 10075 10076 static int 10077 test_AES_CCM_authenticated_decryption_test_case_256_1(void) 10078 { 10079 return test_authenticated_decryption(&ccm_test_case_256_1); 10080 } 10081 10082 static int 10083 test_AES_CCM_authenticated_decryption_test_case_256_2(void) 10084 { 10085 return test_authenticated_decryption(&ccm_test_case_256_2); 10086 } 10087 10088 static int 10089 test_AES_CCM_authenticated_decryption_test_case_256_3(void) 10090 { 10091 return test_authenticated_decryption(&ccm_test_case_256_3); 10092 } 10093 10094 static int 10095 test_stats(void) 10096 { 10097 struct crypto_testsuite_params *ts_params = &testsuite_params; 10098 struct rte_cryptodev_stats stats; 10099 10100 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10101 return -ENOTSUP; 10102 10103 /* Verify the capabilities */ 10104 struct rte_cryptodev_sym_capability_idx cap_idx; 10105 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10106 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 10107 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10108 &cap_idx) == NULL) 10109 return -ENOTSUP; 10110 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10111 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 10112 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10113 &cap_idx) == NULL) 10114 return -ENOTSUP; 10115 10116 if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 10117 == -ENOTSUP) 10118 return -ENOTSUP; 10119 10120 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 10121 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 10122 &stats) == -ENODEV), 10123 "rte_cryptodev_stats_get invalid dev failed"); 10124 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 10125 "rte_cryptodev_stats_get invalid Param failed"); 10126 10127 /* Test expected values */ 10128 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 10129 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 10130 &stats), 10131 "rte_cryptodev_stats_get failed"); 10132 TEST_ASSERT((stats.enqueued_count == 1), 10133 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10134 TEST_ASSERT((stats.dequeued_count == 1), 10135 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10136 TEST_ASSERT((stats.enqueue_err_count == 0), 10137 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10138 TEST_ASSERT((stats.dequeue_err_count == 0), 10139 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10140 10141 /* invalid device but should ignore and not reset device stats*/ 10142 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 10143 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 10144 &stats), 10145 "rte_cryptodev_stats_get failed"); 10146 TEST_ASSERT((stats.enqueued_count == 1), 10147 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10148 10149 /* check that a valid reset clears stats */ 10150 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 10151 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 10152 &stats), 10153 "rte_cryptodev_stats_get failed"); 10154 TEST_ASSERT((stats.enqueued_count == 0), 10155 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10156 TEST_ASSERT((stats.dequeued_count == 0), 10157 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10158 10159 return TEST_SUCCESS; 10160 } 10161 10162 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 10163 struct crypto_unittest_params *ut_params, 10164 enum rte_crypto_auth_operation op, 10165 const struct HMAC_MD5_vector *test_case) 10166 { 10167 uint8_t key[64]; 10168 10169 memcpy(key, test_case->key.data, test_case->key.len); 10170 10171 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10172 ut_params->auth_xform.next = NULL; 10173 ut_params->auth_xform.auth.op = op; 10174 10175 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 10176 10177 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 10178 ut_params->auth_xform.auth.key.length = test_case->key.len; 10179 ut_params->auth_xform.auth.key.data = key; 10180 10181 ut_params->sess = rte_cryptodev_sym_session_create( 10182 ts_params->session_mpool); 10183 10184 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10185 ut_params->sess, &ut_params->auth_xform, 10186 ts_params->session_priv_mpool); 10187 10188 if (ut_params->sess == NULL) 10189 return TEST_FAILED; 10190 10191 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10192 10193 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10194 rte_pktmbuf_tailroom(ut_params->ibuf)); 10195 10196 return 0; 10197 } 10198 10199 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 10200 const struct HMAC_MD5_vector *test_case, 10201 uint8_t **plaintext) 10202 { 10203 uint16_t plaintext_pad_len; 10204 10205 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 10206 10207 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 10208 16); 10209 10210 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10211 plaintext_pad_len); 10212 memcpy(*plaintext, test_case->plaintext.data, 10213 test_case->plaintext.len); 10214 10215 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 10216 ut_params->ibuf, MD5_DIGEST_LEN); 10217 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 10218 "no room to append digest"); 10219 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 10220 ut_params->ibuf, plaintext_pad_len); 10221 10222 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 10223 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 10224 test_case->auth_tag.len); 10225 } 10226 10227 sym_op->auth.data.offset = 0; 10228 sym_op->auth.data.length = test_case->plaintext.len; 10229 10230 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10231 ut_params->op->sym->m_src = ut_params->ibuf; 10232 10233 return 0; 10234 } 10235 10236 static int 10237 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 10238 { 10239 uint16_t plaintext_pad_len; 10240 uint8_t *plaintext, *auth_tag; 10241 10242 struct crypto_testsuite_params *ts_params = &testsuite_params; 10243 struct crypto_unittest_params *ut_params = &unittest_params; 10244 struct rte_cryptodev_info dev_info; 10245 10246 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10247 uint64_t feat_flags = dev_info.feature_flags; 10248 10249 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10250 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10251 printf("Device doesn't support RAW data-path APIs.\n"); 10252 return -ENOTSUP; 10253 } 10254 10255 /* Verify the capabilities */ 10256 struct rte_cryptodev_sym_capability_idx cap_idx; 10257 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10258 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 10259 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10260 &cap_idx) == NULL) 10261 return -ENOTSUP; 10262 10263 if (MD5_HMAC_create_session(ts_params, ut_params, 10264 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 10265 return TEST_FAILED; 10266 10267 /* Generate Crypto op data structure */ 10268 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10269 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10270 TEST_ASSERT_NOT_NULL(ut_params->op, 10271 "Failed to allocate symmetric crypto operation struct"); 10272 10273 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 10274 16); 10275 10276 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 10277 return TEST_FAILED; 10278 10279 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10280 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 10281 ut_params->op); 10282 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10283 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10284 ut_params->op, 0, 1, 0, 0); 10285 else 10286 TEST_ASSERT_NOT_NULL( 10287 process_crypto_request(ts_params->valid_devs[0], 10288 ut_params->op), 10289 "failed to process sym crypto op"); 10290 10291 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10292 "crypto op processing failed"); 10293 10294 if (ut_params->op->sym->m_dst) { 10295 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 10296 uint8_t *, plaintext_pad_len); 10297 } else { 10298 auth_tag = plaintext + plaintext_pad_len; 10299 } 10300 10301 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10302 auth_tag, 10303 test_case->auth_tag.data, 10304 test_case->auth_tag.len, 10305 "HMAC_MD5 generated tag not as expected"); 10306 10307 return TEST_SUCCESS; 10308 } 10309 10310 static int 10311 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 10312 { 10313 uint8_t *plaintext; 10314 10315 struct crypto_testsuite_params *ts_params = &testsuite_params; 10316 struct crypto_unittest_params *ut_params = &unittest_params; 10317 struct rte_cryptodev_info dev_info; 10318 10319 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10320 uint64_t feat_flags = dev_info.feature_flags; 10321 10322 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10323 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10324 printf("Device doesn't support RAW data-path APIs.\n"); 10325 return -ENOTSUP; 10326 } 10327 10328 /* Verify the capabilities */ 10329 struct rte_cryptodev_sym_capability_idx cap_idx; 10330 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10331 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 10332 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10333 &cap_idx) == NULL) 10334 return -ENOTSUP; 10335 10336 if (MD5_HMAC_create_session(ts_params, ut_params, 10337 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 10338 return TEST_FAILED; 10339 } 10340 10341 /* Generate Crypto op data structure */ 10342 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10343 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10344 TEST_ASSERT_NOT_NULL(ut_params->op, 10345 "Failed to allocate symmetric crypto operation struct"); 10346 10347 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 10348 return TEST_FAILED; 10349 10350 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10351 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 10352 ut_params->op); 10353 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10354 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10355 ut_params->op, 0, 1, 0, 0); 10356 else 10357 TEST_ASSERT_NOT_NULL( 10358 process_crypto_request(ts_params->valid_devs[0], 10359 ut_params->op), 10360 "failed to process sym crypto op"); 10361 10362 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10363 "HMAC_MD5 crypto op processing failed"); 10364 10365 return TEST_SUCCESS; 10366 } 10367 10368 static int 10369 test_MD5_HMAC_generate_case_1(void) 10370 { 10371 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 10372 } 10373 10374 static int 10375 test_MD5_HMAC_verify_case_1(void) 10376 { 10377 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 10378 } 10379 10380 static int 10381 test_MD5_HMAC_generate_case_2(void) 10382 { 10383 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 10384 } 10385 10386 static int 10387 test_MD5_HMAC_verify_case_2(void) 10388 { 10389 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 10390 } 10391 10392 static int 10393 test_multi_session(void) 10394 { 10395 struct crypto_testsuite_params *ts_params = &testsuite_params; 10396 struct crypto_unittest_params *ut_params = &unittest_params; 10397 10398 struct rte_cryptodev_info dev_info; 10399 struct rte_cryptodev_sym_session **sessions; 10400 10401 uint16_t i; 10402 10403 /* Verify the capabilities */ 10404 struct rte_cryptodev_sym_capability_idx cap_idx; 10405 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10406 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 10407 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10408 &cap_idx) == NULL) 10409 return -ENOTSUP; 10410 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10411 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 10412 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10413 &cap_idx) == NULL) 10414 return -ENOTSUP; 10415 10416 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 10417 aes_cbc_key, hmac_sha512_key); 10418 10419 10420 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10421 10422 sessions = rte_malloc(NULL, 10423 (sizeof(struct rte_cryptodev_sym_session *) * 10424 MAX_NB_SESSIONS) + 1, 0); 10425 10426 /* Create multiple crypto sessions*/ 10427 for (i = 0; i < MAX_NB_SESSIONS; i++) { 10428 10429 sessions[i] = rte_cryptodev_sym_session_create( 10430 ts_params->session_mpool); 10431 10432 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10433 sessions[i], &ut_params->auth_xform, 10434 ts_params->session_priv_mpool); 10435 TEST_ASSERT_NOT_NULL(sessions[i], 10436 "Session creation failed at session number %u", 10437 i); 10438 10439 /* Attempt to send a request on each session */ 10440 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform( 10441 sessions[i], 10442 ut_params, 10443 ts_params, 10444 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 10445 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 10446 aes_cbc_iv), 10447 "Failed to perform decrypt on request number %u.", i); 10448 /* free crypto operation structure */ 10449 if (ut_params->op) 10450 rte_crypto_op_free(ut_params->op); 10451 10452 /* 10453 * free mbuf - both obuf and ibuf are usually the same, 10454 * so check if they point at the same address is necessary, 10455 * to avoid freeing the mbuf twice. 10456 */ 10457 if (ut_params->obuf) { 10458 rte_pktmbuf_free(ut_params->obuf); 10459 if (ut_params->ibuf == ut_params->obuf) 10460 ut_params->ibuf = 0; 10461 ut_params->obuf = 0; 10462 } 10463 if (ut_params->ibuf) { 10464 rte_pktmbuf_free(ut_params->ibuf); 10465 ut_params->ibuf = 0; 10466 } 10467 } 10468 10469 /* Next session create should fail */ 10470 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10471 sessions[i], &ut_params->auth_xform, 10472 ts_params->session_priv_mpool); 10473 TEST_ASSERT_NULL(sessions[i], 10474 "Session creation succeeded unexpectedly!"); 10475 10476 for (i = 0; i < MAX_NB_SESSIONS; i++) { 10477 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 10478 sessions[i]); 10479 rte_cryptodev_sym_session_free(sessions[i]); 10480 } 10481 10482 rte_free(sessions); 10483 10484 return TEST_SUCCESS; 10485 } 10486 10487 struct multi_session_params { 10488 struct crypto_unittest_params ut_params; 10489 uint8_t *cipher_key; 10490 uint8_t *hmac_key; 10491 const uint8_t *cipher; 10492 const uint8_t *digest; 10493 uint8_t *iv; 10494 }; 10495 10496 #define MB_SESSION_NUMBER 3 10497 10498 static int 10499 test_multi_session_random_usage(void) 10500 { 10501 struct crypto_testsuite_params *ts_params = &testsuite_params; 10502 struct rte_cryptodev_info dev_info; 10503 struct rte_cryptodev_sym_session **sessions; 10504 uint32_t i, j; 10505 struct multi_session_params ut_paramz[] = { 10506 10507 { 10508 .cipher_key = ms_aes_cbc_key0, 10509 .hmac_key = ms_hmac_key0, 10510 .cipher = ms_aes_cbc_cipher0, 10511 .digest = ms_hmac_digest0, 10512 .iv = ms_aes_cbc_iv0 10513 }, 10514 { 10515 .cipher_key = ms_aes_cbc_key1, 10516 .hmac_key = ms_hmac_key1, 10517 .cipher = ms_aes_cbc_cipher1, 10518 .digest = ms_hmac_digest1, 10519 .iv = ms_aes_cbc_iv1 10520 }, 10521 { 10522 .cipher_key = ms_aes_cbc_key2, 10523 .hmac_key = ms_hmac_key2, 10524 .cipher = ms_aes_cbc_cipher2, 10525 .digest = ms_hmac_digest2, 10526 .iv = ms_aes_cbc_iv2 10527 }, 10528 10529 }; 10530 10531 /* Verify the capabilities */ 10532 struct rte_cryptodev_sym_capability_idx cap_idx; 10533 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10534 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 10535 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10536 &cap_idx) == NULL) 10537 return -ENOTSUP; 10538 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10539 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 10540 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10541 &cap_idx) == NULL) 10542 return -ENOTSUP; 10543 10544 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10545 10546 sessions = rte_malloc(NULL, 10547 (sizeof(struct rte_cryptodev_sym_session *) 10548 * MAX_NB_SESSIONS) + 1, 0); 10549 10550 for (i = 0; i < MB_SESSION_NUMBER; i++) { 10551 sessions[i] = rte_cryptodev_sym_session_create( 10552 ts_params->session_mpool); 10553 10554 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params, 10555 sizeof(struct crypto_unittest_params)); 10556 10557 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 10558 &ut_paramz[i].ut_params, 10559 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 10560 10561 /* Create multiple crypto sessions*/ 10562 rte_cryptodev_sym_session_init( 10563 ts_params->valid_devs[0], 10564 sessions[i], 10565 &ut_paramz[i].ut_params.auth_xform, 10566 ts_params->session_priv_mpool); 10567 10568 TEST_ASSERT_NOT_NULL(sessions[i], 10569 "Session creation failed at session number %u", 10570 i); 10571 10572 } 10573 10574 srand(time(NULL)); 10575 for (i = 0; i < 40000; i++) { 10576 10577 j = rand() % MB_SESSION_NUMBER; 10578 10579 TEST_ASSERT_SUCCESS( 10580 test_AES_CBC_HMAC_SHA512_decrypt_perform( 10581 sessions[j], 10582 &ut_paramz[j].ut_params, 10583 ts_params, ut_paramz[j].cipher, 10584 ut_paramz[j].digest, 10585 ut_paramz[j].iv), 10586 "Failed to perform decrypt on request number %u.", i); 10587 10588 if (ut_paramz[j].ut_params.op) 10589 rte_crypto_op_free(ut_paramz[j].ut_params.op); 10590 10591 /* 10592 * free mbuf - both obuf and ibuf are usually the same, 10593 * so check if they point at the same address is necessary, 10594 * to avoid freeing the mbuf twice. 10595 */ 10596 if (ut_paramz[j].ut_params.obuf) { 10597 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 10598 if (ut_paramz[j].ut_params.ibuf 10599 == ut_paramz[j].ut_params.obuf) 10600 ut_paramz[j].ut_params.ibuf = 0; 10601 ut_paramz[j].ut_params.obuf = 0; 10602 } 10603 if (ut_paramz[j].ut_params.ibuf) { 10604 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 10605 ut_paramz[j].ut_params.ibuf = 0; 10606 } 10607 } 10608 10609 for (i = 0; i < MB_SESSION_NUMBER; i++) { 10610 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 10611 sessions[i]); 10612 rte_cryptodev_sym_session_free(sessions[i]); 10613 } 10614 10615 rte_free(sessions); 10616 10617 return TEST_SUCCESS; 10618 } 10619 10620 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab, 10621 0xab, 0xab, 0xab, 0xab, 10622 0xab, 0xab, 0xab, 0xab, 10623 0xab, 0xab, 0xab, 0xab}; 10624 10625 static int 10626 test_null_invalid_operation(void) 10627 { 10628 struct crypto_testsuite_params *ts_params = &testsuite_params; 10629 struct crypto_unittest_params *ut_params = &unittest_params; 10630 int ret; 10631 10632 /* This test is for NULL PMD only */ 10633 if (gbl_driver_id != rte_cryptodev_driver_id_get( 10634 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 10635 return -ENOTSUP; 10636 10637 /* Setup Cipher Parameters */ 10638 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10639 ut_params->cipher_xform.next = NULL; 10640 10641 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 10642 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 10643 10644 ut_params->sess = rte_cryptodev_sym_session_create( 10645 ts_params->session_mpool); 10646 10647 /* Create Crypto session*/ 10648 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10649 ut_params->sess, &ut_params->cipher_xform, 10650 ts_params->session_priv_mpool); 10651 TEST_ASSERT(ret < 0, 10652 "Session creation succeeded unexpectedly"); 10653 10654 10655 /* Setup HMAC Parameters */ 10656 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10657 ut_params->auth_xform.next = NULL; 10658 10659 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 10660 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 10661 10662 ut_params->sess = rte_cryptodev_sym_session_create( 10663 ts_params->session_mpool); 10664 10665 /* Create Crypto session*/ 10666 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10667 ut_params->sess, &ut_params->auth_xform, 10668 ts_params->session_priv_mpool); 10669 TEST_ASSERT(ret < 0, 10670 "Session creation succeeded unexpectedly"); 10671 10672 return TEST_SUCCESS; 10673 } 10674 10675 10676 #define NULL_BURST_LENGTH (32) 10677 10678 static int 10679 test_null_burst_operation(void) 10680 { 10681 struct crypto_testsuite_params *ts_params = &testsuite_params; 10682 struct crypto_unittest_params *ut_params = &unittest_params; 10683 10684 unsigned i, burst_len = NULL_BURST_LENGTH; 10685 10686 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 10687 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 10688 10689 /* This test is for NULL PMD only */ 10690 if (gbl_driver_id != rte_cryptodev_driver_id_get( 10691 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 10692 return -ENOTSUP; 10693 10694 /* Setup Cipher Parameters */ 10695 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10696 ut_params->cipher_xform.next = &ut_params->auth_xform; 10697 10698 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 10699 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 10700 10701 /* Setup HMAC Parameters */ 10702 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10703 ut_params->auth_xform.next = NULL; 10704 10705 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 10706 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 10707 10708 ut_params->sess = rte_cryptodev_sym_session_create( 10709 ts_params->session_mpool); 10710 10711 /* Create Crypto session*/ 10712 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10713 ut_params->sess, &ut_params->cipher_xform, 10714 ts_params->session_priv_mpool); 10715 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 10716 10717 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 10718 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 10719 burst_len, "failed to generate burst of crypto ops"); 10720 10721 /* Generate an operation for each mbuf in burst */ 10722 for (i = 0; i < burst_len; i++) { 10723 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10724 10725 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 10726 10727 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 10728 sizeof(unsigned)); 10729 *data = i; 10730 10731 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 10732 10733 burst[i]->sym->m_src = m; 10734 } 10735 10736 /* Process crypto operation */ 10737 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 10738 0, burst, burst_len), 10739 burst_len, 10740 "Error enqueuing burst"); 10741 10742 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 10743 0, burst_dequeued, burst_len), 10744 burst_len, 10745 "Error dequeuing burst"); 10746 10747 10748 for (i = 0; i < burst_len; i++) { 10749 TEST_ASSERT_EQUAL( 10750 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 10751 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 10752 uint32_t *), 10753 "data not as expected"); 10754 10755 rte_pktmbuf_free(burst[i]->sym->m_src); 10756 rte_crypto_op_free(burst[i]); 10757 } 10758 10759 return TEST_SUCCESS; 10760 } 10761 10762 static uint16_t 10763 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 10764 uint16_t nb_ops, void *user_param) 10765 { 10766 RTE_SET_USED(dev_id); 10767 RTE_SET_USED(qp_id); 10768 RTE_SET_USED(ops); 10769 RTE_SET_USED(user_param); 10770 10771 printf("crypto enqueue callback called\n"); 10772 return nb_ops; 10773 } 10774 10775 static uint16_t 10776 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 10777 uint16_t nb_ops, void *user_param) 10778 { 10779 RTE_SET_USED(dev_id); 10780 RTE_SET_USED(qp_id); 10781 RTE_SET_USED(ops); 10782 RTE_SET_USED(user_param); 10783 10784 printf("crypto dequeue callback called\n"); 10785 return nb_ops; 10786 } 10787 10788 /* 10789 * Thread using enqueue/dequeue callback with RCU. 10790 */ 10791 static int 10792 test_enqdeq_callback_thread(void *arg) 10793 { 10794 RTE_SET_USED(arg); 10795 /* DP thread calls rte_cryptodev_enqueue_burst()/ 10796 * rte_cryptodev_dequeue_burst() and invokes callback. 10797 */ 10798 test_null_burst_operation(); 10799 return 0; 10800 } 10801 10802 static int 10803 test_enq_callback_setup(void) 10804 { 10805 struct crypto_testsuite_params *ts_params = &testsuite_params; 10806 struct rte_cryptodev_info dev_info; 10807 struct rte_cryptodev_qp_conf qp_conf = { 10808 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 10809 }; 10810 10811 struct rte_cryptodev_cb *cb; 10812 uint16_t qp_id = 0; 10813 10814 /* Stop the device in case it's started so it can be configured */ 10815 rte_cryptodev_stop(ts_params->valid_devs[0]); 10816 10817 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10818 10819 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 10820 &ts_params->conf), 10821 "Failed to configure cryptodev %u", 10822 ts_params->valid_devs[0]); 10823 10824 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 10825 qp_conf.mp_session = ts_params->session_mpool; 10826 qp_conf.mp_session_private = ts_params->session_priv_mpool; 10827 10828 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 10829 ts_params->valid_devs[0], qp_id, &qp_conf, 10830 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 10831 "Failed test for " 10832 "rte_cryptodev_queue_pair_setup: num_inflights " 10833 "%u on qp %u on cryptodev %u", 10834 qp_conf.nb_descriptors, qp_id, 10835 ts_params->valid_devs[0]); 10836 10837 /* Test with invalid crypto device */ 10838 cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS, 10839 qp_id, test_enq_callback, NULL); 10840 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 10841 "cryptodev %u did not fail", 10842 qp_id, RTE_CRYPTO_MAX_DEVS); 10843 10844 /* Test with invalid queue pair */ 10845 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 10846 dev_info.max_nb_queue_pairs + 1, 10847 test_enq_callback, NULL); 10848 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 10849 "cryptodev %u did not fail", 10850 dev_info.max_nb_queue_pairs + 1, 10851 ts_params->valid_devs[0]); 10852 10853 /* Test with NULL callback */ 10854 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 10855 qp_id, NULL, NULL); 10856 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 10857 "cryptodev %u did not fail", 10858 qp_id, ts_params->valid_devs[0]); 10859 10860 /* Test with valid configuration */ 10861 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 10862 qp_id, test_enq_callback, NULL); 10863 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 10864 "qp %u on cryptodev %u", 10865 qp_id, ts_params->valid_devs[0]); 10866 10867 rte_cryptodev_start(ts_params->valid_devs[0]); 10868 10869 /* Launch a thread */ 10870 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 10871 rte_get_next_lcore(-1, 1, 0)); 10872 10873 /* Wait until reader exited. */ 10874 rte_eal_mp_wait_lcore(); 10875 10876 /* Test with invalid crypto device */ 10877 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 10878 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 10879 "Expected call to fail as crypto device is invalid"); 10880 10881 /* Test with invalid queue pair */ 10882 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 10883 ts_params->valid_devs[0], 10884 dev_info.max_nb_queue_pairs + 1, cb), 10885 "Expected call to fail as queue pair is invalid"); 10886 10887 /* Test with NULL callback */ 10888 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 10889 ts_params->valid_devs[0], qp_id, NULL), 10890 "Expected call to fail as callback is NULL"); 10891 10892 /* Test with valid configuration */ 10893 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback( 10894 ts_params->valid_devs[0], qp_id, cb), 10895 "Failed test to remove callback on " 10896 "qp %u on cryptodev %u", 10897 qp_id, ts_params->valid_devs[0]); 10898 10899 return TEST_SUCCESS; 10900 } 10901 10902 static int 10903 test_deq_callback_setup(void) 10904 { 10905 struct crypto_testsuite_params *ts_params = &testsuite_params; 10906 struct rte_cryptodev_info dev_info; 10907 struct rte_cryptodev_qp_conf qp_conf = { 10908 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 10909 }; 10910 10911 struct rte_cryptodev_cb *cb; 10912 uint16_t qp_id = 0; 10913 10914 /* Stop the device in case it's started so it can be configured */ 10915 rte_cryptodev_stop(ts_params->valid_devs[0]); 10916 10917 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10918 10919 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 10920 &ts_params->conf), 10921 "Failed to configure cryptodev %u", 10922 ts_params->valid_devs[0]); 10923 10924 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 10925 qp_conf.mp_session = ts_params->session_mpool; 10926 qp_conf.mp_session_private = ts_params->session_priv_mpool; 10927 10928 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 10929 ts_params->valid_devs[0], qp_id, &qp_conf, 10930 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 10931 "Failed test for " 10932 "rte_cryptodev_queue_pair_setup: num_inflights " 10933 "%u on qp %u on cryptodev %u", 10934 qp_conf.nb_descriptors, qp_id, 10935 ts_params->valid_devs[0]); 10936 10937 /* Test with invalid crypto device */ 10938 cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS, 10939 qp_id, test_deq_callback, NULL); 10940 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 10941 "cryptodev %u did not fail", 10942 qp_id, RTE_CRYPTO_MAX_DEVS); 10943 10944 /* Test with invalid queue pair */ 10945 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 10946 dev_info.max_nb_queue_pairs + 1, 10947 test_deq_callback, NULL); 10948 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 10949 "cryptodev %u did not fail", 10950 dev_info.max_nb_queue_pairs + 1, 10951 ts_params->valid_devs[0]); 10952 10953 /* Test with NULL callback */ 10954 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 10955 qp_id, NULL, NULL); 10956 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 10957 "cryptodev %u did not fail", 10958 qp_id, ts_params->valid_devs[0]); 10959 10960 /* Test with valid configuration */ 10961 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 10962 qp_id, test_deq_callback, NULL); 10963 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 10964 "qp %u on cryptodev %u", 10965 qp_id, ts_params->valid_devs[0]); 10966 10967 rte_cryptodev_start(ts_params->valid_devs[0]); 10968 10969 /* Launch a thread */ 10970 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 10971 rte_get_next_lcore(-1, 1, 0)); 10972 10973 /* Wait until reader exited. */ 10974 rte_eal_mp_wait_lcore(); 10975 10976 /* Test with invalid crypto device */ 10977 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 10978 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 10979 "Expected call to fail as crypto device is invalid"); 10980 10981 /* Test with invalid queue pair */ 10982 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 10983 ts_params->valid_devs[0], 10984 dev_info.max_nb_queue_pairs + 1, cb), 10985 "Expected call to fail as queue pair is invalid"); 10986 10987 /* Test with NULL callback */ 10988 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 10989 ts_params->valid_devs[0], qp_id, NULL), 10990 "Expected call to fail as callback is NULL"); 10991 10992 /* Test with valid configuration */ 10993 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback( 10994 ts_params->valid_devs[0], qp_id, cb), 10995 "Failed test to remove callback on " 10996 "qp %u on cryptodev %u", 10997 qp_id, ts_params->valid_devs[0]); 10998 10999 return TEST_SUCCESS; 11000 } 11001 11002 static void 11003 generate_gmac_large_plaintext(uint8_t *data) 11004 { 11005 uint16_t i; 11006 11007 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 11008 memcpy(&data[i], &data[0], 32); 11009 } 11010 11011 static int 11012 create_gmac_operation(enum rte_crypto_auth_operation op, 11013 const struct gmac_test_data *tdata) 11014 { 11015 struct crypto_testsuite_params *ts_params = &testsuite_params; 11016 struct crypto_unittest_params *ut_params = &unittest_params; 11017 struct rte_crypto_sym_op *sym_op; 11018 11019 uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 11020 11021 /* Generate Crypto op data structure */ 11022 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11023 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11024 TEST_ASSERT_NOT_NULL(ut_params->op, 11025 "Failed to allocate symmetric crypto operation struct"); 11026 11027 sym_op = ut_params->op->sym; 11028 11029 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11030 ut_params->ibuf, tdata->gmac_tag.len); 11031 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11032 "no room to append digest"); 11033 11034 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11035 ut_params->ibuf, plaintext_pad_len); 11036 11037 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 11038 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 11039 tdata->gmac_tag.len); 11040 debug_hexdump(stdout, "digest:", 11041 sym_op->auth.digest.data, 11042 tdata->gmac_tag.len); 11043 } 11044 11045 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 11046 uint8_t *, IV_OFFSET); 11047 11048 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 11049 11050 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 11051 11052 sym_op->cipher.data.length = 0; 11053 sym_op->cipher.data.offset = 0; 11054 11055 sym_op->auth.data.offset = 0; 11056 sym_op->auth.data.length = tdata->plaintext.len; 11057 11058 return 0; 11059 } 11060 11061 static int 11062 create_gmac_operation_sgl(enum rte_crypto_auth_operation op, 11063 const struct gmac_test_data *tdata, 11064 void *digest_mem, uint64_t digest_phys) 11065 { 11066 struct crypto_testsuite_params *ts_params = &testsuite_params; 11067 struct crypto_unittest_params *ut_params = &unittest_params; 11068 struct rte_crypto_sym_op *sym_op; 11069 11070 /* Generate Crypto op data structure */ 11071 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11072 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11073 TEST_ASSERT_NOT_NULL(ut_params->op, 11074 "Failed to allocate symmetric crypto operation struct"); 11075 11076 sym_op = ut_params->op->sym; 11077 11078 sym_op->auth.digest.data = digest_mem; 11079 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11080 "no room to append digest"); 11081 11082 sym_op->auth.digest.phys_addr = digest_phys; 11083 11084 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 11085 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 11086 tdata->gmac_tag.len); 11087 debug_hexdump(stdout, "digest:", 11088 sym_op->auth.digest.data, 11089 tdata->gmac_tag.len); 11090 } 11091 11092 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 11093 uint8_t *, IV_OFFSET); 11094 11095 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 11096 11097 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 11098 11099 sym_op->cipher.data.length = 0; 11100 sym_op->cipher.data.offset = 0; 11101 11102 sym_op->auth.data.offset = 0; 11103 sym_op->auth.data.length = tdata->plaintext.len; 11104 11105 return 0; 11106 } 11107 11108 static int create_gmac_session(uint8_t dev_id, 11109 const struct gmac_test_data *tdata, 11110 enum rte_crypto_auth_operation auth_op) 11111 { 11112 uint8_t auth_key[tdata->key.len]; 11113 11114 struct crypto_testsuite_params *ts_params = &testsuite_params; 11115 struct crypto_unittest_params *ut_params = &unittest_params; 11116 11117 memcpy(auth_key, tdata->key.data, tdata->key.len); 11118 11119 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11120 ut_params->auth_xform.next = NULL; 11121 11122 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 11123 ut_params->auth_xform.auth.op = auth_op; 11124 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 11125 ut_params->auth_xform.auth.key.length = tdata->key.len; 11126 ut_params->auth_xform.auth.key.data = auth_key; 11127 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 11128 ut_params->auth_xform.auth.iv.length = tdata->iv.len; 11129 11130 11131 ut_params->sess = rte_cryptodev_sym_session_create( 11132 ts_params->session_mpool); 11133 11134 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 11135 &ut_params->auth_xform, 11136 ts_params->session_priv_mpool); 11137 11138 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11139 11140 return 0; 11141 } 11142 11143 static int 11144 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 11145 { 11146 struct crypto_testsuite_params *ts_params = &testsuite_params; 11147 struct crypto_unittest_params *ut_params = &unittest_params; 11148 struct rte_cryptodev_info dev_info; 11149 11150 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11151 uint64_t feat_flags = dev_info.feature_flags; 11152 11153 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11154 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11155 printf("Device doesn't support RAW data-path APIs.\n"); 11156 return -ENOTSUP; 11157 } 11158 11159 int retval; 11160 11161 uint8_t *auth_tag, *plaintext; 11162 uint16_t plaintext_pad_len; 11163 11164 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 11165 "No GMAC length in the source data"); 11166 11167 /* Verify the capabilities */ 11168 struct rte_cryptodev_sym_capability_idx cap_idx; 11169 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11170 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 11171 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11172 &cap_idx) == NULL) 11173 return -ENOTSUP; 11174 11175 retval = create_gmac_session(ts_params->valid_devs[0], 11176 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 11177 11178 if (retval < 0) 11179 return retval; 11180 11181 if (tdata->plaintext.len > MBUF_SIZE) 11182 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 11183 else 11184 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11185 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 11186 "Failed to allocate input buffer in mempool"); 11187 11188 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11189 rte_pktmbuf_tailroom(ut_params->ibuf)); 11190 11191 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 11192 /* 11193 * Runtime generate the large plain text instead of use hard code 11194 * plain text vector. It is done to avoid create huge source file 11195 * with the test vector. 11196 */ 11197 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 11198 generate_gmac_large_plaintext(tdata->plaintext.data); 11199 11200 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11201 plaintext_pad_len); 11202 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 11203 11204 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 11205 debug_hexdump(stdout, "plaintext:", plaintext, 11206 tdata->plaintext.len); 11207 11208 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 11209 tdata); 11210 11211 if (retval < 0) 11212 return retval; 11213 11214 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11215 11216 ut_params->op->sym->m_src = ut_params->ibuf; 11217 11218 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11219 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11220 ut_params->op); 11221 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11222 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11223 ut_params->op, 0, 1, 0, 0); 11224 else 11225 TEST_ASSERT_NOT_NULL( 11226 process_crypto_request(ts_params->valid_devs[0], 11227 ut_params->op), "failed to process sym crypto op"); 11228 11229 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11230 "crypto op processing failed"); 11231 11232 if (ut_params->op->sym->m_dst) { 11233 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 11234 uint8_t *, plaintext_pad_len); 11235 } else { 11236 auth_tag = plaintext + plaintext_pad_len; 11237 } 11238 11239 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 11240 11241 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11242 auth_tag, 11243 tdata->gmac_tag.data, 11244 tdata->gmac_tag.len, 11245 "GMAC Generated auth tag not as expected"); 11246 11247 return 0; 11248 } 11249 11250 static int 11251 test_AES_GMAC_authentication_test_case_1(void) 11252 { 11253 return test_AES_GMAC_authentication(&gmac_test_case_1); 11254 } 11255 11256 static int 11257 test_AES_GMAC_authentication_test_case_2(void) 11258 { 11259 return test_AES_GMAC_authentication(&gmac_test_case_2); 11260 } 11261 11262 static int 11263 test_AES_GMAC_authentication_test_case_3(void) 11264 { 11265 return test_AES_GMAC_authentication(&gmac_test_case_3); 11266 } 11267 11268 static int 11269 test_AES_GMAC_authentication_test_case_4(void) 11270 { 11271 return test_AES_GMAC_authentication(&gmac_test_case_4); 11272 } 11273 11274 static int 11275 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 11276 { 11277 struct crypto_testsuite_params *ts_params = &testsuite_params; 11278 struct crypto_unittest_params *ut_params = &unittest_params; 11279 int retval; 11280 uint32_t plaintext_pad_len; 11281 uint8_t *plaintext; 11282 struct rte_cryptodev_info dev_info; 11283 11284 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11285 uint64_t feat_flags = dev_info.feature_flags; 11286 11287 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11288 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11289 printf("Device doesn't support RAW data-path APIs.\n"); 11290 return -ENOTSUP; 11291 } 11292 11293 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 11294 "No GMAC length in the source data"); 11295 11296 /* Verify the capabilities */ 11297 struct rte_cryptodev_sym_capability_idx cap_idx; 11298 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11299 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 11300 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11301 &cap_idx) == NULL) 11302 return -ENOTSUP; 11303 11304 retval = create_gmac_session(ts_params->valid_devs[0], 11305 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 11306 11307 if (retval < 0) 11308 return retval; 11309 11310 if (tdata->plaintext.len > MBUF_SIZE) 11311 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 11312 else 11313 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11314 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 11315 "Failed to allocate input buffer in mempool"); 11316 11317 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11318 rte_pktmbuf_tailroom(ut_params->ibuf)); 11319 11320 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 11321 11322 /* 11323 * Runtime generate the large plain text instead of use hard code 11324 * plain text vector. It is done to avoid create huge source file 11325 * with the test vector. 11326 */ 11327 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 11328 generate_gmac_large_plaintext(tdata->plaintext.data); 11329 11330 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11331 plaintext_pad_len); 11332 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 11333 11334 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 11335 debug_hexdump(stdout, "plaintext:", plaintext, 11336 tdata->plaintext.len); 11337 11338 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 11339 tdata); 11340 11341 if (retval < 0) 11342 return retval; 11343 11344 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11345 11346 ut_params->op->sym->m_src = ut_params->ibuf; 11347 11348 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11349 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11350 ut_params->op); 11351 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11352 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11353 ut_params->op, 0, 1, 0, 0); 11354 else 11355 TEST_ASSERT_NOT_NULL( 11356 process_crypto_request(ts_params->valid_devs[0], 11357 ut_params->op), "failed to process sym crypto op"); 11358 11359 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11360 "crypto op processing failed"); 11361 11362 return 0; 11363 11364 } 11365 11366 static int 11367 test_AES_GMAC_authentication_verify_test_case_1(void) 11368 { 11369 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 11370 } 11371 11372 static int 11373 test_AES_GMAC_authentication_verify_test_case_2(void) 11374 { 11375 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 11376 } 11377 11378 static int 11379 test_AES_GMAC_authentication_verify_test_case_3(void) 11380 { 11381 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 11382 } 11383 11384 static int 11385 test_AES_GMAC_authentication_verify_test_case_4(void) 11386 { 11387 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 11388 } 11389 11390 static int 11391 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata, 11392 uint32_t fragsz) 11393 { 11394 struct crypto_testsuite_params *ts_params = &testsuite_params; 11395 struct crypto_unittest_params *ut_params = &unittest_params; 11396 struct rte_cryptodev_info dev_info; 11397 uint64_t feature_flags; 11398 unsigned int trn_data = 0; 11399 void *digest_mem = NULL; 11400 uint32_t segs = 1; 11401 unsigned int to_trn = 0; 11402 struct rte_mbuf *buf = NULL; 11403 uint8_t *auth_tag, *plaintext; 11404 int retval; 11405 11406 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 11407 "No GMAC length in the source data"); 11408 11409 /* Verify the capabilities */ 11410 struct rte_cryptodev_sym_capability_idx cap_idx; 11411 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11412 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 11413 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11414 &cap_idx) == NULL) 11415 return -ENOTSUP; 11416 11417 /* Check for any input SGL support */ 11418 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11419 feature_flags = dev_info.feature_flags; 11420 11421 if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) || 11422 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) || 11423 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))) 11424 return -ENOTSUP; 11425 11426 if (fragsz > tdata->plaintext.len) 11427 fragsz = tdata->plaintext.len; 11428 11429 uint16_t plaintext_len = fragsz; 11430 11431 retval = create_gmac_session(ts_params->valid_devs[0], 11432 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 11433 11434 if (retval < 0) 11435 return retval; 11436 11437 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11438 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 11439 "Failed to allocate input buffer in mempool"); 11440 11441 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11442 rte_pktmbuf_tailroom(ut_params->ibuf)); 11443 11444 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11445 plaintext_len); 11446 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 11447 11448 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 11449 11450 trn_data += plaintext_len; 11451 11452 buf = ut_params->ibuf; 11453 11454 /* 11455 * Loop until no more fragments 11456 */ 11457 11458 while (trn_data < tdata->plaintext.len) { 11459 ++segs; 11460 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 11461 (tdata->plaintext.len - trn_data) : fragsz; 11462 11463 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11464 buf = buf->next; 11465 11466 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 11467 rte_pktmbuf_tailroom(buf)); 11468 11469 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 11470 to_trn); 11471 11472 memcpy(plaintext, tdata->plaintext.data + trn_data, 11473 to_trn); 11474 trn_data += to_trn; 11475 if (trn_data == tdata->plaintext.len) 11476 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 11477 tdata->gmac_tag.len); 11478 } 11479 ut_params->ibuf->nb_segs = segs; 11480 11481 /* 11482 * Place digest at the end of the last buffer 11483 */ 11484 uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn; 11485 11486 if (!digest_mem) { 11487 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11488 + tdata->gmac_tag.len); 11489 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 11490 tdata->plaintext.len); 11491 } 11492 11493 retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE, 11494 tdata, digest_mem, digest_phys); 11495 11496 if (retval < 0) 11497 return retval; 11498 11499 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11500 11501 ut_params->op->sym->m_src = ut_params->ibuf; 11502 11503 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11504 return -ENOTSUP; 11505 11506 TEST_ASSERT_NOT_NULL( 11507 process_crypto_request(ts_params->valid_devs[0], 11508 ut_params->op), "failed to process sym crypto op"); 11509 11510 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11511 "crypto op processing failed"); 11512 11513 auth_tag = digest_mem; 11514 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 11515 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11516 auth_tag, 11517 tdata->gmac_tag.data, 11518 tdata->gmac_tag.len, 11519 "GMAC Generated auth tag not as expected"); 11520 11521 return 0; 11522 } 11523 11524 /* Segment size not multiple of block size (16B) */ 11525 static int 11526 test_AES_GMAC_authentication_SGL_40B(void) 11527 { 11528 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40); 11529 } 11530 11531 static int 11532 test_AES_GMAC_authentication_SGL_80B(void) 11533 { 11534 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80); 11535 } 11536 11537 static int 11538 test_AES_GMAC_authentication_SGL_2048B(void) 11539 { 11540 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048); 11541 } 11542 11543 /* Segment size not multiple of block size (16B) */ 11544 static int 11545 test_AES_GMAC_authentication_SGL_2047B(void) 11546 { 11547 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047); 11548 } 11549 11550 struct test_crypto_vector { 11551 enum rte_crypto_cipher_algorithm crypto_algo; 11552 unsigned int cipher_offset; 11553 unsigned int cipher_len; 11554 11555 struct { 11556 uint8_t data[64]; 11557 unsigned int len; 11558 } cipher_key; 11559 11560 struct { 11561 uint8_t data[64]; 11562 unsigned int len; 11563 } iv; 11564 11565 struct { 11566 const uint8_t *data; 11567 unsigned int len; 11568 } plaintext; 11569 11570 struct { 11571 const uint8_t *data; 11572 unsigned int len; 11573 } ciphertext; 11574 11575 enum rte_crypto_auth_algorithm auth_algo; 11576 unsigned int auth_offset; 11577 11578 struct { 11579 uint8_t data[128]; 11580 unsigned int len; 11581 } auth_key; 11582 11583 struct { 11584 const uint8_t *data; 11585 unsigned int len; 11586 } aad; 11587 11588 struct { 11589 uint8_t data[128]; 11590 unsigned int len; 11591 } digest; 11592 }; 11593 11594 static const struct test_crypto_vector 11595 hmac_sha1_test_crypto_vector = { 11596 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 11597 .plaintext = { 11598 .data = plaintext_hash, 11599 .len = 512 11600 }, 11601 .auth_key = { 11602 .data = { 11603 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 11604 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 11605 0xDE, 0xF4, 0xDE, 0xAD 11606 }, 11607 .len = 20 11608 }, 11609 .digest = { 11610 .data = { 11611 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 11612 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 11613 0x3F, 0x91, 0x64, 0x59 11614 }, 11615 .len = 20 11616 } 11617 }; 11618 11619 static const struct test_crypto_vector 11620 aes128_gmac_test_vector = { 11621 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 11622 .plaintext = { 11623 .data = plaintext_hash, 11624 .len = 512 11625 }, 11626 .iv = { 11627 .data = { 11628 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 11629 0x08, 0x09, 0x0A, 0x0B 11630 }, 11631 .len = 12 11632 }, 11633 .auth_key = { 11634 .data = { 11635 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 11636 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 11637 }, 11638 .len = 16 11639 }, 11640 .digest = { 11641 .data = { 11642 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 11643 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 11644 }, 11645 .len = 16 11646 } 11647 }; 11648 11649 static const struct test_crypto_vector 11650 aes128cbc_hmac_sha1_test_vector = { 11651 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 11652 .cipher_offset = 0, 11653 .cipher_len = 512, 11654 .cipher_key = { 11655 .data = { 11656 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 11657 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 11658 }, 11659 .len = 16 11660 }, 11661 .iv = { 11662 .data = { 11663 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 11664 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 11665 }, 11666 .len = 16 11667 }, 11668 .plaintext = { 11669 .data = plaintext_hash, 11670 .len = 512 11671 }, 11672 .ciphertext = { 11673 .data = ciphertext512_aes128cbc, 11674 .len = 512 11675 }, 11676 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 11677 .auth_offset = 0, 11678 .auth_key = { 11679 .data = { 11680 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 11681 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 11682 0xDE, 0xF4, 0xDE, 0xAD 11683 }, 11684 .len = 20 11685 }, 11686 .digest = { 11687 .data = { 11688 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 11689 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 11690 0x18, 0x8C, 0x1D, 0x32 11691 }, 11692 .len = 20 11693 } 11694 }; 11695 11696 static const struct test_crypto_vector 11697 aes128cbc_hmac_sha1_aad_test_vector = { 11698 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 11699 .cipher_offset = 8, 11700 .cipher_len = 496, 11701 .cipher_key = { 11702 .data = { 11703 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 11704 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 11705 }, 11706 .len = 16 11707 }, 11708 .iv = { 11709 .data = { 11710 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 11711 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 11712 }, 11713 .len = 16 11714 }, 11715 .plaintext = { 11716 .data = plaintext_hash, 11717 .len = 512 11718 }, 11719 .ciphertext = { 11720 .data = ciphertext512_aes128cbc_aad, 11721 .len = 512 11722 }, 11723 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 11724 .auth_offset = 0, 11725 .auth_key = { 11726 .data = { 11727 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 11728 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 11729 0xDE, 0xF4, 0xDE, 0xAD 11730 }, 11731 .len = 20 11732 }, 11733 .digest = { 11734 .data = { 11735 0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F, 11736 0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B, 11737 0x62, 0x0F, 0xFB, 0x10 11738 }, 11739 .len = 20 11740 } 11741 }; 11742 11743 static void 11744 data_corruption(uint8_t *data) 11745 { 11746 data[0] += 1; 11747 } 11748 11749 static void 11750 tag_corruption(uint8_t *data, unsigned int tag_offset) 11751 { 11752 data[tag_offset] += 1; 11753 } 11754 11755 static int 11756 create_auth_session(struct crypto_unittest_params *ut_params, 11757 uint8_t dev_id, 11758 const struct test_crypto_vector *reference, 11759 enum rte_crypto_auth_operation auth_op) 11760 { 11761 struct crypto_testsuite_params *ts_params = &testsuite_params; 11762 uint8_t auth_key[reference->auth_key.len + 1]; 11763 11764 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 11765 11766 /* Setup Authentication Parameters */ 11767 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11768 ut_params->auth_xform.auth.op = auth_op; 11769 ut_params->auth_xform.next = NULL; 11770 ut_params->auth_xform.auth.algo = reference->auth_algo; 11771 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 11772 ut_params->auth_xform.auth.key.data = auth_key; 11773 ut_params->auth_xform.auth.digest_length = reference->digest.len; 11774 11775 /* Create Crypto session*/ 11776 ut_params->sess = rte_cryptodev_sym_session_create( 11777 ts_params->session_mpool); 11778 11779 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 11780 &ut_params->auth_xform, 11781 ts_params->session_priv_mpool); 11782 11783 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11784 11785 return 0; 11786 } 11787 11788 static int 11789 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 11790 uint8_t dev_id, 11791 const struct test_crypto_vector *reference, 11792 enum rte_crypto_auth_operation auth_op, 11793 enum rte_crypto_cipher_operation cipher_op) 11794 { 11795 struct crypto_testsuite_params *ts_params = &testsuite_params; 11796 uint8_t cipher_key[reference->cipher_key.len + 1]; 11797 uint8_t auth_key[reference->auth_key.len + 1]; 11798 11799 memcpy(cipher_key, reference->cipher_key.data, 11800 reference->cipher_key.len); 11801 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 11802 11803 /* Setup Authentication Parameters */ 11804 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11805 ut_params->auth_xform.auth.op = auth_op; 11806 ut_params->auth_xform.auth.algo = reference->auth_algo; 11807 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 11808 ut_params->auth_xform.auth.key.data = auth_key; 11809 ut_params->auth_xform.auth.digest_length = reference->digest.len; 11810 11811 if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) { 11812 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 11813 ut_params->auth_xform.auth.iv.length = reference->iv.len; 11814 } else { 11815 ut_params->auth_xform.next = &ut_params->cipher_xform; 11816 11817 /* Setup Cipher Parameters */ 11818 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11819 ut_params->cipher_xform.next = NULL; 11820 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 11821 ut_params->cipher_xform.cipher.op = cipher_op; 11822 ut_params->cipher_xform.cipher.key.data = cipher_key; 11823 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 11824 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 11825 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 11826 } 11827 11828 /* Create Crypto session*/ 11829 ut_params->sess = rte_cryptodev_sym_session_create( 11830 ts_params->session_mpool); 11831 11832 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 11833 &ut_params->auth_xform, 11834 ts_params->session_priv_mpool); 11835 11836 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11837 11838 return 0; 11839 } 11840 11841 static int 11842 create_auth_operation(struct crypto_testsuite_params *ts_params, 11843 struct crypto_unittest_params *ut_params, 11844 const struct test_crypto_vector *reference, 11845 unsigned int auth_generate) 11846 { 11847 /* Generate Crypto op data structure */ 11848 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11849 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11850 TEST_ASSERT_NOT_NULL(ut_params->op, 11851 "Failed to allocate pktmbuf offload"); 11852 11853 /* Set crypto operation data parameters */ 11854 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11855 11856 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 11857 11858 /* set crypto operation source mbuf */ 11859 sym_op->m_src = ut_params->ibuf; 11860 11861 /* digest */ 11862 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11863 ut_params->ibuf, reference->digest.len); 11864 11865 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11866 "no room to append auth tag"); 11867 11868 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11869 ut_params->ibuf, reference->plaintext.len); 11870 11871 if (auth_generate) 11872 memset(sym_op->auth.digest.data, 0, reference->digest.len); 11873 else 11874 memcpy(sym_op->auth.digest.data, 11875 reference->digest.data, 11876 reference->digest.len); 11877 11878 debug_hexdump(stdout, "digest:", 11879 sym_op->auth.digest.data, 11880 reference->digest.len); 11881 11882 sym_op->auth.data.length = reference->plaintext.len; 11883 sym_op->auth.data.offset = 0; 11884 11885 return 0; 11886 } 11887 11888 static int 11889 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 11890 struct crypto_unittest_params *ut_params, 11891 const struct test_crypto_vector *reference, 11892 unsigned int auth_generate) 11893 { 11894 /* Generate Crypto op data structure */ 11895 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11896 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11897 TEST_ASSERT_NOT_NULL(ut_params->op, 11898 "Failed to allocate pktmbuf offload"); 11899 11900 /* Set crypto operation data parameters */ 11901 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11902 11903 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 11904 11905 /* set crypto operation source mbuf */ 11906 sym_op->m_src = ut_params->ibuf; 11907 11908 /* digest */ 11909 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11910 ut_params->ibuf, reference->digest.len); 11911 11912 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11913 "no room to append auth tag"); 11914 11915 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11916 ut_params->ibuf, reference->ciphertext.len); 11917 11918 if (auth_generate) 11919 memset(sym_op->auth.digest.data, 0, reference->digest.len); 11920 else 11921 memcpy(sym_op->auth.digest.data, 11922 reference->digest.data, 11923 reference->digest.len); 11924 11925 debug_hexdump(stdout, "digest:", 11926 sym_op->auth.digest.data, 11927 reference->digest.len); 11928 11929 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 11930 reference->iv.data, reference->iv.len); 11931 11932 sym_op->cipher.data.length = 0; 11933 sym_op->cipher.data.offset = 0; 11934 11935 sym_op->auth.data.length = reference->plaintext.len; 11936 sym_op->auth.data.offset = 0; 11937 11938 return 0; 11939 } 11940 11941 static int 11942 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 11943 struct crypto_unittest_params *ut_params, 11944 const struct test_crypto_vector *reference, 11945 unsigned int auth_generate) 11946 { 11947 /* Generate Crypto op data structure */ 11948 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11949 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11950 TEST_ASSERT_NOT_NULL(ut_params->op, 11951 "Failed to allocate pktmbuf offload"); 11952 11953 /* Set crypto operation data parameters */ 11954 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11955 11956 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 11957 11958 /* set crypto operation source mbuf */ 11959 sym_op->m_src = ut_params->ibuf; 11960 11961 /* digest */ 11962 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11963 ut_params->ibuf, reference->digest.len); 11964 11965 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11966 "no room to append auth tag"); 11967 11968 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11969 ut_params->ibuf, reference->ciphertext.len); 11970 11971 if (auth_generate) 11972 memset(sym_op->auth.digest.data, 0, reference->digest.len); 11973 else 11974 memcpy(sym_op->auth.digest.data, 11975 reference->digest.data, 11976 reference->digest.len); 11977 11978 debug_hexdump(stdout, "digest:", 11979 sym_op->auth.digest.data, 11980 reference->digest.len); 11981 11982 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 11983 reference->iv.data, reference->iv.len); 11984 11985 sym_op->cipher.data.length = reference->cipher_len; 11986 sym_op->cipher.data.offset = reference->cipher_offset; 11987 11988 sym_op->auth.data.length = reference->plaintext.len; 11989 sym_op->auth.data.offset = reference->auth_offset; 11990 11991 return 0; 11992 } 11993 11994 static int 11995 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 11996 struct crypto_unittest_params *ut_params, 11997 const struct test_crypto_vector *reference) 11998 { 11999 return create_auth_operation(ts_params, ut_params, reference, 0); 12000 } 12001 12002 static int 12003 create_auth_verify_GMAC_operation( 12004 struct crypto_testsuite_params *ts_params, 12005 struct crypto_unittest_params *ut_params, 12006 const struct test_crypto_vector *reference) 12007 { 12008 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 12009 } 12010 12011 static int 12012 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params, 12013 struct crypto_unittest_params *ut_params, 12014 const struct test_crypto_vector *reference) 12015 { 12016 return create_cipher_auth_operation(ts_params, ut_params, reference, 0); 12017 } 12018 12019 static int 12020 test_authentication_verify_fail_when_data_corruption( 12021 struct crypto_testsuite_params *ts_params, 12022 struct crypto_unittest_params *ut_params, 12023 const struct test_crypto_vector *reference, 12024 unsigned int data_corrupted) 12025 { 12026 int retval; 12027 12028 uint8_t *plaintext; 12029 struct rte_cryptodev_info dev_info; 12030 12031 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12032 uint64_t feat_flags = dev_info.feature_flags; 12033 12034 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12035 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12036 printf("Device doesn't support RAW data-path APIs.\n"); 12037 return -ENOTSUP; 12038 } 12039 12040 /* Verify the capabilities */ 12041 struct rte_cryptodev_sym_capability_idx cap_idx; 12042 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12043 cap_idx.algo.auth = reference->auth_algo; 12044 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12045 &cap_idx) == NULL) 12046 return -ENOTSUP; 12047 12048 12049 /* Create session */ 12050 retval = create_auth_session(ut_params, 12051 ts_params->valid_devs[0], 12052 reference, 12053 RTE_CRYPTO_AUTH_OP_VERIFY); 12054 if (retval < 0) 12055 return retval; 12056 12057 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12058 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12059 "Failed to allocate input buffer in mempool"); 12060 12061 /* clear mbuf payload */ 12062 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12063 rte_pktmbuf_tailroom(ut_params->ibuf)); 12064 12065 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12066 reference->plaintext.len); 12067 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12068 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 12069 12070 debug_hexdump(stdout, "plaintext:", plaintext, 12071 reference->plaintext.len); 12072 12073 /* Create operation */ 12074 retval = create_auth_verify_operation(ts_params, ut_params, reference); 12075 12076 if (retval < 0) 12077 return retval; 12078 12079 if (data_corrupted) 12080 data_corruption(plaintext); 12081 else 12082 tag_corruption(plaintext, reference->plaintext.len); 12083 12084 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 12085 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12086 ut_params->op); 12087 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 12088 RTE_CRYPTO_OP_STATUS_SUCCESS, 12089 "authentication not failed"); 12090 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12091 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12092 ut_params->op, 0, 1, 0, 0); 12093 else { 12094 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 12095 ut_params->op); 12096 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 12097 } 12098 12099 return 0; 12100 } 12101 12102 static int 12103 test_authentication_verify_GMAC_fail_when_corruption( 12104 struct crypto_testsuite_params *ts_params, 12105 struct crypto_unittest_params *ut_params, 12106 const struct test_crypto_vector *reference, 12107 unsigned int data_corrupted) 12108 { 12109 int retval; 12110 uint8_t *plaintext; 12111 struct rte_cryptodev_info dev_info; 12112 12113 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12114 uint64_t feat_flags = dev_info.feature_flags; 12115 12116 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12117 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12118 printf("Device doesn't support RAW data-path APIs.\n"); 12119 return -ENOTSUP; 12120 } 12121 12122 /* Verify the capabilities */ 12123 struct rte_cryptodev_sym_capability_idx cap_idx; 12124 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12125 cap_idx.algo.auth = reference->auth_algo; 12126 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12127 &cap_idx) == NULL) 12128 return -ENOTSUP; 12129 12130 /* Create session */ 12131 retval = create_auth_cipher_session(ut_params, 12132 ts_params->valid_devs[0], 12133 reference, 12134 RTE_CRYPTO_AUTH_OP_VERIFY, 12135 RTE_CRYPTO_CIPHER_OP_DECRYPT); 12136 if (retval < 0) 12137 return retval; 12138 12139 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12140 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12141 "Failed to allocate input buffer in mempool"); 12142 12143 /* clear mbuf payload */ 12144 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12145 rte_pktmbuf_tailroom(ut_params->ibuf)); 12146 12147 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12148 reference->plaintext.len); 12149 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12150 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 12151 12152 debug_hexdump(stdout, "plaintext:", plaintext, 12153 reference->plaintext.len); 12154 12155 /* Create operation */ 12156 retval = create_auth_verify_GMAC_operation(ts_params, 12157 ut_params, 12158 reference); 12159 12160 if (retval < 0) 12161 return retval; 12162 12163 if (data_corrupted) 12164 data_corruption(plaintext); 12165 else 12166 tag_corruption(plaintext, reference->aad.len); 12167 12168 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 12169 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12170 ut_params->op); 12171 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 12172 RTE_CRYPTO_OP_STATUS_SUCCESS, 12173 "authentication not failed"); 12174 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12175 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12176 ut_params->op, 0, 1, 0, 0); 12177 else { 12178 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 12179 ut_params->op); 12180 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 12181 } 12182 12183 return 0; 12184 } 12185 12186 static int 12187 test_authenticated_decryption_fail_when_corruption( 12188 struct crypto_testsuite_params *ts_params, 12189 struct crypto_unittest_params *ut_params, 12190 const struct test_crypto_vector *reference, 12191 unsigned int data_corrupted) 12192 { 12193 int retval; 12194 12195 uint8_t *ciphertext; 12196 struct rte_cryptodev_info dev_info; 12197 12198 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12199 uint64_t feat_flags = dev_info.feature_flags; 12200 12201 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12202 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12203 printf("Device doesn't support RAW data-path APIs.\n"); 12204 return -ENOTSUP; 12205 } 12206 12207 /* Verify the capabilities */ 12208 struct rte_cryptodev_sym_capability_idx cap_idx; 12209 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12210 cap_idx.algo.auth = reference->auth_algo; 12211 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12212 &cap_idx) == NULL) 12213 return -ENOTSUP; 12214 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12215 cap_idx.algo.cipher = reference->crypto_algo; 12216 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12217 &cap_idx) == NULL) 12218 return -ENOTSUP; 12219 12220 /* Create session */ 12221 retval = create_auth_cipher_session(ut_params, 12222 ts_params->valid_devs[0], 12223 reference, 12224 RTE_CRYPTO_AUTH_OP_VERIFY, 12225 RTE_CRYPTO_CIPHER_OP_DECRYPT); 12226 if (retval < 0) 12227 return retval; 12228 12229 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12230 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12231 "Failed to allocate input buffer in mempool"); 12232 12233 /* clear mbuf payload */ 12234 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12235 rte_pktmbuf_tailroom(ut_params->ibuf)); 12236 12237 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12238 reference->ciphertext.len); 12239 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 12240 memcpy(ciphertext, reference->ciphertext.data, 12241 reference->ciphertext.len); 12242 12243 /* Create operation */ 12244 retval = create_cipher_auth_verify_operation(ts_params, 12245 ut_params, 12246 reference); 12247 12248 if (retval < 0) 12249 return retval; 12250 12251 if (data_corrupted) 12252 data_corruption(ciphertext); 12253 else 12254 tag_corruption(ciphertext, reference->ciphertext.len); 12255 12256 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 12257 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12258 ut_params->op); 12259 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 12260 RTE_CRYPTO_OP_STATUS_SUCCESS, 12261 "authentication not failed"); 12262 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12263 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12264 ut_params->op, 1, 1, 0, 0); 12265 else { 12266 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 12267 ut_params->op); 12268 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 12269 } 12270 12271 return 0; 12272 } 12273 12274 static int 12275 test_authenticated_encryt_with_esn( 12276 struct crypto_testsuite_params *ts_params, 12277 struct crypto_unittest_params *ut_params, 12278 const struct test_crypto_vector *reference) 12279 { 12280 int retval; 12281 12282 uint8_t *authciphertext, *plaintext, *auth_tag; 12283 uint16_t plaintext_pad_len; 12284 uint8_t cipher_key[reference->cipher_key.len + 1]; 12285 uint8_t auth_key[reference->auth_key.len + 1]; 12286 struct rte_cryptodev_info dev_info; 12287 12288 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12289 uint64_t feat_flags = dev_info.feature_flags; 12290 12291 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12292 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12293 printf("Device doesn't support RAW data-path APIs.\n"); 12294 return -ENOTSUP; 12295 } 12296 12297 /* Verify the capabilities */ 12298 struct rte_cryptodev_sym_capability_idx cap_idx; 12299 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12300 cap_idx.algo.auth = reference->auth_algo; 12301 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12302 &cap_idx) == NULL) 12303 return -ENOTSUP; 12304 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12305 cap_idx.algo.cipher = reference->crypto_algo; 12306 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12307 &cap_idx) == NULL) 12308 return -ENOTSUP; 12309 12310 /* Create session */ 12311 memcpy(cipher_key, reference->cipher_key.data, 12312 reference->cipher_key.len); 12313 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 12314 12315 /* Setup Cipher Parameters */ 12316 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12317 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 12318 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 12319 ut_params->cipher_xform.cipher.key.data = cipher_key; 12320 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 12321 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 12322 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 12323 12324 ut_params->cipher_xform.next = &ut_params->auth_xform; 12325 12326 /* Setup Authentication Parameters */ 12327 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12328 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 12329 ut_params->auth_xform.auth.algo = reference->auth_algo; 12330 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 12331 ut_params->auth_xform.auth.key.data = auth_key; 12332 ut_params->auth_xform.auth.digest_length = reference->digest.len; 12333 ut_params->auth_xform.next = NULL; 12334 12335 /* Create Crypto session*/ 12336 ut_params->sess = rte_cryptodev_sym_session_create( 12337 ts_params->session_mpool); 12338 12339 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12340 ut_params->sess, 12341 &ut_params->cipher_xform, 12342 ts_params->session_priv_mpool); 12343 12344 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12345 12346 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12347 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12348 "Failed to allocate input buffer in mempool"); 12349 12350 /* clear mbuf payload */ 12351 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12352 rte_pktmbuf_tailroom(ut_params->ibuf)); 12353 12354 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12355 reference->plaintext.len); 12356 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12357 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 12358 12359 /* Create operation */ 12360 retval = create_cipher_auth_operation(ts_params, 12361 ut_params, 12362 reference, 0); 12363 12364 if (retval < 0) 12365 return retval; 12366 12367 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12368 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12369 ut_params->op); 12370 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12371 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12372 ut_params->op, 1, 1, 0, 0); 12373 else 12374 ut_params->op = process_crypto_request( 12375 ts_params->valid_devs[0], ut_params->op); 12376 12377 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 12378 12379 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12380 "crypto op processing failed"); 12381 12382 plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16); 12383 12384 authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 12385 ut_params->op->sym->auth.data.offset); 12386 auth_tag = authciphertext + plaintext_pad_len; 12387 debug_hexdump(stdout, "ciphertext:", authciphertext, 12388 reference->ciphertext.len); 12389 debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len); 12390 12391 /* Validate obuf */ 12392 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12393 authciphertext, 12394 reference->ciphertext.data, 12395 reference->ciphertext.len, 12396 "Ciphertext data not as expected"); 12397 12398 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12399 auth_tag, 12400 reference->digest.data, 12401 reference->digest.len, 12402 "Generated digest not as expected"); 12403 12404 return TEST_SUCCESS; 12405 12406 } 12407 12408 static int 12409 test_authenticated_decrypt_with_esn( 12410 struct crypto_testsuite_params *ts_params, 12411 struct crypto_unittest_params *ut_params, 12412 const struct test_crypto_vector *reference) 12413 { 12414 int retval; 12415 12416 uint8_t *ciphertext; 12417 uint8_t cipher_key[reference->cipher_key.len + 1]; 12418 uint8_t auth_key[reference->auth_key.len + 1]; 12419 struct rte_cryptodev_info dev_info; 12420 12421 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12422 uint64_t feat_flags = dev_info.feature_flags; 12423 12424 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12425 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12426 printf("Device doesn't support RAW data-path APIs.\n"); 12427 return -ENOTSUP; 12428 } 12429 12430 /* Verify the capabilities */ 12431 struct rte_cryptodev_sym_capability_idx cap_idx; 12432 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12433 cap_idx.algo.auth = reference->auth_algo; 12434 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12435 &cap_idx) == NULL) 12436 return -ENOTSUP; 12437 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12438 cap_idx.algo.cipher = reference->crypto_algo; 12439 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12440 &cap_idx) == NULL) 12441 return -ENOTSUP; 12442 12443 /* Create session */ 12444 memcpy(cipher_key, reference->cipher_key.data, 12445 reference->cipher_key.len); 12446 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 12447 12448 /* Setup Authentication Parameters */ 12449 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12450 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 12451 ut_params->auth_xform.auth.algo = reference->auth_algo; 12452 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 12453 ut_params->auth_xform.auth.key.data = auth_key; 12454 ut_params->auth_xform.auth.digest_length = reference->digest.len; 12455 ut_params->auth_xform.next = &ut_params->cipher_xform; 12456 12457 /* Setup Cipher Parameters */ 12458 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12459 ut_params->cipher_xform.next = NULL; 12460 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 12461 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 12462 ut_params->cipher_xform.cipher.key.data = cipher_key; 12463 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 12464 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 12465 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 12466 12467 /* Create Crypto session*/ 12468 ut_params->sess = rte_cryptodev_sym_session_create( 12469 ts_params->session_mpool); 12470 12471 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12472 ut_params->sess, 12473 &ut_params->auth_xform, 12474 ts_params->session_priv_mpool); 12475 12476 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12477 12478 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12479 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12480 "Failed to allocate input buffer in mempool"); 12481 12482 /* clear mbuf payload */ 12483 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12484 rte_pktmbuf_tailroom(ut_params->ibuf)); 12485 12486 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12487 reference->ciphertext.len); 12488 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 12489 memcpy(ciphertext, reference->ciphertext.data, 12490 reference->ciphertext.len); 12491 12492 /* Create operation */ 12493 retval = create_cipher_auth_verify_operation(ts_params, 12494 ut_params, 12495 reference); 12496 12497 if (retval < 0) 12498 return retval; 12499 12500 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12501 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12502 ut_params->op); 12503 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12504 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12505 ut_params->op, 1, 1, 0, 0); 12506 else 12507 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 12508 ut_params->op); 12509 12510 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 12511 TEST_ASSERT_EQUAL(ut_params->op->status, 12512 RTE_CRYPTO_OP_STATUS_SUCCESS, 12513 "crypto op processing passed"); 12514 12515 ut_params->obuf = ut_params->op->sym->m_src; 12516 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 12517 12518 return 0; 12519 } 12520 12521 static int 12522 create_aead_operation_SGL(enum rte_crypto_aead_operation op, 12523 const struct aead_test_data *tdata, 12524 void *digest_mem, uint64_t digest_phys) 12525 { 12526 struct crypto_testsuite_params *ts_params = &testsuite_params; 12527 struct crypto_unittest_params *ut_params = &unittest_params; 12528 12529 const unsigned int auth_tag_len = tdata->auth_tag.len; 12530 const unsigned int iv_len = tdata->iv.len; 12531 unsigned int aad_len = tdata->aad.len; 12532 unsigned int aad_len_pad = 0; 12533 12534 /* Generate Crypto op data structure */ 12535 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12536 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12537 TEST_ASSERT_NOT_NULL(ut_params->op, 12538 "Failed to allocate symmetric crypto operation struct"); 12539 12540 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12541 12542 sym_op->aead.digest.data = digest_mem; 12543 12544 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 12545 "no room to append digest"); 12546 12547 sym_op->aead.digest.phys_addr = digest_phys; 12548 12549 if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) { 12550 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 12551 auth_tag_len); 12552 debug_hexdump(stdout, "digest:", 12553 sym_op->aead.digest.data, 12554 auth_tag_len); 12555 } 12556 12557 /* Append aad data */ 12558 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 12559 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12560 uint8_t *, IV_OFFSET); 12561 12562 /* Copy IV 1 byte after the IV pointer, according to the API */ 12563 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len); 12564 12565 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16); 12566 12567 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 12568 ut_params->ibuf, aad_len); 12569 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 12570 "no room to prepend aad"); 12571 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 12572 ut_params->ibuf); 12573 12574 memset(sym_op->aead.aad.data, 0, aad_len); 12575 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 12576 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 12577 12578 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 12579 debug_hexdump(stdout, "aad:", 12580 sym_op->aead.aad.data, aad_len); 12581 } else { 12582 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12583 uint8_t *, IV_OFFSET); 12584 12585 rte_memcpy(iv_ptr, tdata->iv.data, iv_len); 12586 12587 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16); 12588 12589 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 12590 ut_params->ibuf, aad_len_pad); 12591 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 12592 "no room to prepend aad"); 12593 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 12594 ut_params->ibuf); 12595 12596 memset(sym_op->aead.aad.data, 0, aad_len); 12597 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 12598 12599 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 12600 debug_hexdump(stdout, "aad:", 12601 sym_op->aead.aad.data, aad_len); 12602 } 12603 12604 sym_op->aead.data.length = tdata->plaintext.len; 12605 sym_op->aead.data.offset = aad_len_pad; 12606 12607 return 0; 12608 } 12609 12610 #define SGL_MAX_NO 16 12611 12612 static int 12613 test_authenticated_encryption_SGL(const struct aead_test_data *tdata, 12614 const int oop, uint32_t fragsz, uint32_t fragsz_oop) 12615 { 12616 struct crypto_testsuite_params *ts_params = &testsuite_params; 12617 struct crypto_unittest_params *ut_params = &unittest_params; 12618 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL; 12619 int retval; 12620 int to_trn = 0; 12621 int to_trn_tbl[SGL_MAX_NO]; 12622 int segs = 1; 12623 unsigned int trn_data = 0; 12624 uint8_t *plaintext, *ciphertext, *auth_tag; 12625 struct rte_cryptodev_info dev_info; 12626 12627 /* Verify the capabilities */ 12628 struct rte_cryptodev_sym_capability_idx cap_idx; 12629 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12630 cap_idx.algo.aead = tdata->algo; 12631 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12632 &cap_idx) == NULL) 12633 return -ENOTSUP; 12634 12635 /* OOP not supported with CPU crypto */ 12636 if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12637 return -ENOTSUP; 12638 12639 /* Detailed check for the particular SGL support flag */ 12640 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12641 if (!oop) { 12642 unsigned int sgl_in = fragsz < tdata->plaintext.len; 12643 if (sgl_in && (!(dev_info.feature_flags & 12644 RTE_CRYPTODEV_FF_IN_PLACE_SGL))) 12645 return -ENOTSUP; 12646 12647 uint64_t feat_flags = dev_info.feature_flags; 12648 12649 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12650 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12651 printf("Device doesn't support RAW data-path APIs.\n"); 12652 return -ENOTSUP; 12653 } 12654 } else { 12655 unsigned int sgl_in = fragsz < tdata->plaintext.len; 12656 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) < 12657 tdata->plaintext.len; 12658 /* Raw data path API does not support OOP */ 12659 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12660 return -ENOTSUP; 12661 if (sgl_in && !sgl_out) { 12662 if (!(dev_info.feature_flags & 12663 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) 12664 return -ENOTSUP; 12665 } else if (!sgl_in && sgl_out) { 12666 if (!(dev_info.feature_flags & 12667 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 12668 return -ENOTSUP; 12669 } else if (sgl_in && sgl_out) { 12670 if (!(dev_info.feature_flags & 12671 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 12672 return -ENOTSUP; 12673 } 12674 } 12675 12676 if (fragsz > tdata->plaintext.len) 12677 fragsz = tdata->plaintext.len; 12678 12679 uint16_t plaintext_len = fragsz; 12680 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 12681 12682 if (fragsz_oop > tdata->plaintext.len) 12683 frag_size_oop = tdata->plaintext.len; 12684 12685 int ecx = 0; 12686 void *digest_mem = NULL; 12687 12688 uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 12689 12690 if (tdata->plaintext.len % fragsz != 0) { 12691 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO) 12692 return 1; 12693 } else { 12694 if (tdata->plaintext.len / fragsz > SGL_MAX_NO) 12695 return 1; 12696 } 12697 12698 /* 12699 * For out-op-place we need to alloc another mbuf 12700 */ 12701 if (oop) { 12702 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12703 rte_pktmbuf_append(ut_params->obuf, 12704 frag_size_oop + prepend_len); 12705 buf_oop = ut_params->obuf; 12706 } 12707 12708 /* Create AEAD session */ 12709 retval = create_aead_session(ts_params->valid_devs[0], 12710 tdata->algo, 12711 RTE_CRYPTO_AEAD_OP_ENCRYPT, 12712 tdata->key.data, tdata->key.len, 12713 tdata->aad.len, tdata->auth_tag.len, 12714 tdata->iv.len); 12715 if (retval < 0) 12716 return retval; 12717 12718 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12719 12720 /* clear mbuf payload */ 12721 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12722 rte_pktmbuf_tailroom(ut_params->ibuf)); 12723 12724 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12725 plaintext_len); 12726 12727 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 12728 12729 trn_data += plaintext_len; 12730 12731 buf = ut_params->ibuf; 12732 12733 /* 12734 * Loop until no more fragments 12735 */ 12736 12737 while (trn_data < tdata->plaintext.len) { 12738 ++segs; 12739 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 12740 (tdata->plaintext.len - trn_data) : fragsz; 12741 12742 to_trn_tbl[ecx++] = to_trn; 12743 12744 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12745 buf = buf->next; 12746 12747 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 12748 rte_pktmbuf_tailroom(buf)); 12749 12750 /* OOP */ 12751 if (oop && !fragsz_oop) { 12752 buf_last_oop = buf_oop->next = 12753 rte_pktmbuf_alloc(ts_params->mbuf_pool); 12754 buf_oop = buf_oop->next; 12755 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 12756 0, rte_pktmbuf_tailroom(buf_oop)); 12757 rte_pktmbuf_append(buf_oop, to_trn); 12758 } 12759 12760 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 12761 to_trn); 12762 12763 memcpy(plaintext, tdata->plaintext.data + trn_data, 12764 to_trn); 12765 trn_data += to_trn; 12766 if (trn_data == tdata->plaintext.len) { 12767 if (oop) { 12768 if (!fragsz_oop) 12769 digest_mem = rte_pktmbuf_append(buf_oop, 12770 tdata->auth_tag.len); 12771 } else 12772 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 12773 tdata->auth_tag.len); 12774 } 12775 } 12776 12777 uint64_t digest_phys = 0; 12778 12779 ut_params->ibuf->nb_segs = segs; 12780 12781 segs = 1; 12782 if (fragsz_oop && oop) { 12783 to_trn = 0; 12784 ecx = 0; 12785 12786 if (frag_size_oop == tdata->plaintext.len) { 12787 digest_mem = rte_pktmbuf_append(ut_params->obuf, 12788 tdata->auth_tag.len); 12789 12790 digest_phys = rte_pktmbuf_iova_offset( 12791 ut_params->obuf, 12792 tdata->plaintext.len + prepend_len); 12793 } 12794 12795 trn_data = frag_size_oop; 12796 while (trn_data < tdata->plaintext.len) { 12797 ++segs; 12798 to_trn = 12799 (tdata->plaintext.len - trn_data < 12800 frag_size_oop) ? 12801 (tdata->plaintext.len - trn_data) : 12802 frag_size_oop; 12803 12804 to_trn_tbl[ecx++] = to_trn; 12805 12806 buf_last_oop = buf_oop->next = 12807 rte_pktmbuf_alloc(ts_params->mbuf_pool); 12808 buf_oop = buf_oop->next; 12809 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 12810 0, rte_pktmbuf_tailroom(buf_oop)); 12811 rte_pktmbuf_append(buf_oop, to_trn); 12812 12813 trn_data += to_trn; 12814 12815 if (trn_data == tdata->plaintext.len) { 12816 digest_mem = rte_pktmbuf_append(buf_oop, 12817 tdata->auth_tag.len); 12818 } 12819 } 12820 12821 ut_params->obuf->nb_segs = segs; 12822 } 12823 12824 /* 12825 * Place digest at the end of the last buffer 12826 */ 12827 if (!digest_phys) 12828 digest_phys = rte_pktmbuf_iova(buf) + to_trn; 12829 if (oop && buf_last_oop) 12830 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn; 12831 12832 if (!digest_mem && !oop) { 12833 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12834 + tdata->auth_tag.len); 12835 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 12836 tdata->plaintext.len); 12837 } 12838 12839 /* Create AEAD operation */ 12840 retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT, 12841 tdata, digest_mem, digest_phys); 12842 12843 if (retval < 0) 12844 return retval; 12845 12846 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12847 12848 ut_params->op->sym->m_src = ut_params->ibuf; 12849 if (oop) 12850 ut_params->op->sym->m_dst = ut_params->obuf; 12851 12852 /* Process crypto operation */ 12853 if (oop == IN_PLACE && 12854 gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12855 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 12856 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12857 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12858 ut_params->op, 0, 0, 0, 0); 12859 else 12860 TEST_ASSERT_NOT_NULL( 12861 process_crypto_request(ts_params->valid_devs[0], 12862 ut_params->op), "failed to process sym crypto op"); 12863 12864 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12865 "crypto op processing failed"); 12866 12867 12868 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 12869 uint8_t *, prepend_len); 12870 if (oop) { 12871 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 12872 uint8_t *, prepend_len); 12873 } 12874 12875 if (fragsz_oop) 12876 fragsz = fragsz_oop; 12877 12878 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12879 ciphertext, 12880 tdata->ciphertext.data, 12881 fragsz, 12882 "Ciphertext data not as expected"); 12883 12884 buf = ut_params->op->sym->m_src->next; 12885 if (oop) 12886 buf = ut_params->op->sym->m_dst->next; 12887 12888 unsigned int off = fragsz; 12889 12890 ecx = 0; 12891 while (buf) { 12892 ciphertext = rte_pktmbuf_mtod(buf, 12893 uint8_t *); 12894 12895 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12896 ciphertext, 12897 tdata->ciphertext.data + off, 12898 to_trn_tbl[ecx], 12899 "Ciphertext data not as expected"); 12900 12901 off += to_trn_tbl[ecx++]; 12902 buf = buf->next; 12903 } 12904 12905 auth_tag = digest_mem; 12906 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12907 auth_tag, 12908 tdata->auth_tag.data, 12909 tdata->auth_tag.len, 12910 "Generated auth tag not as expected"); 12911 12912 return 0; 12913 } 12914 12915 static int 12916 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) 12917 { 12918 return test_authenticated_encryption_SGL( 12919 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400); 12920 } 12921 12922 static int 12923 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void) 12924 { 12925 return test_authenticated_encryption_SGL( 12926 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000); 12927 } 12928 12929 static int 12930 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void) 12931 { 12932 return test_authenticated_encryption_SGL( 12933 &gcm_test_case_8, OUT_OF_PLACE, 400, 12934 gcm_test_case_8.plaintext.len); 12935 } 12936 12937 static int 12938 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void) 12939 { 12940 /* This test is not for OPENSSL PMD */ 12941 if (gbl_driver_id == rte_cryptodev_driver_id_get( 12942 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) 12943 return -ENOTSUP; 12944 12945 return test_authenticated_encryption_SGL( 12946 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0); 12947 } 12948 12949 static int 12950 test_authentication_verify_fail_when_data_corrupted( 12951 struct crypto_testsuite_params *ts_params, 12952 struct crypto_unittest_params *ut_params, 12953 const struct test_crypto_vector *reference) 12954 { 12955 return test_authentication_verify_fail_when_data_corruption( 12956 ts_params, ut_params, reference, 1); 12957 } 12958 12959 static int 12960 test_authentication_verify_fail_when_tag_corrupted( 12961 struct crypto_testsuite_params *ts_params, 12962 struct crypto_unittest_params *ut_params, 12963 const struct test_crypto_vector *reference) 12964 { 12965 return test_authentication_verify_fail_when_data_corruption( 12966 ts_params, ut_params, reference, 0); 12967 } 12968 12969 static int 12970 test_authentication_verify_GMAC_fail_when_data_corrupted( 12971 struct crypto_testsuite_params *ts_params, 12972 struct crypto_unittest_params *ut_params, 12973 const struct test_crypto_vector *reference) 12974 { 12975 return test_authentication_verify_GMAC_fail_when_corruption( 12976 ts_params, ut_params, reference, 1); 12977 } 12978 12979 static int 12980 test_authentication_verify_GMAC_fail_when_tag_corrupted( 12981 struct crypto_testsuite_params *ts_params, 12982 struct crypto_unittest_params *ut_params, 12983 const struct test_crypto_vector *reference) 12984 { 12985 return test_authentication_verify_GMAC_fail_when_corruption( 12986 ts_params, ut_params, reference, 0); 12987 } 12988 12989 static int 12990 test_authenticated_decryption_fail_when_data_corrupted( 12991 struct crypto_testsuite_params *ts_params, 12992 struct crypto_unittest_params *ut_params, 12993 const struct test_crypto_vector *reference) 12994 { 12995 return test_authenticated_decryption_fail_when_corruption( 12996 ts_params, ut_params, reference, 1); 12997 } 12998 12999 static int 13000 test_authenticated_decryption_fail_when_tag_corrupted( 13001 struct crypto_testsuite_params *ts_params, 13002 struct crypto_unittest_params *ut_params, 13003 const struct test_crypto_vector *reference) 13004 { 13005 return test_authenticated_decryption_fail_when_corruption( 13006 ts_params, ut_params, reference, 0); 13007 } 13008 13009 static int 13010 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 13011 { 13012 return test_authentication_verify_fail_when_data_corrupted( 13013 &testsuite_params, &unittest_params, 13014 &hmac_sha1_test_crypto_vector); 13015 } 13016 13017 static int 13018 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 13019 { 13020 return test_authentication_verify_fail_when_tag_corrupted( 13021 &testsuite_params, &unittest_params, 13022 &hmac_sha1_test_crypto_vector); 13023 } 13024 13025 static int 13026 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 13027 { 13028 return test_authentication_verify_GMAC_fail_when_data_corrupted( 13029 &testsuite_params, &unittest_params, 13030 &aes128_gmac_test_vector); 13031 } 13032 13033 static int 13034 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 13035 { 13036 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 13037 &testsuite_params, &unittest_params, 13038 &aes128_gmac_test_vector); 13039 } 13040 13041 static int 13042 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 13043 { 13044 return test_authenticated_decryption_fail_when_data_corrupted( 13045 &testsuite_params, 13046 &unittest_params, 13047 &aes128cbc_hmac_sha1_test_vector); 13048 } 13049 13050 static int 13051 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 13052 { 13053 return test_authenticated_decryption_fail_when_tag_corrupted( 13054 &testsuite_params, 13055 &unittest_params, 13056 &aes128cbc_hmac_sha1_test_vector); 13057 } 13058 13059 static int 13060 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void) 13061 { 13062 return test_authenticated_encryt_with_esn( 13063 &testsuite_params, 13064 &unittest_params, 13065 &aes128cbc_hmac_sha1_aad_test_vector); 13066 } 13067 13068 static int 13069 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void) 13070 { 13071 return test_authenticated_decrypt_with_esn( 13072 &testsuite_params, 13073 &unittest_params, 13074 &aes128cbc_hmac_sha1_aad_test_vector); 13075 } 13076 13077 static int 13078 test_chacha20_poly1305_encrypt_test_case_rfc8439(void) 13079 { 13080 return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439); 13081 } 13082 13083 static int 13084 test_chacha20_poly1305_decrypt_test_case_rfc8439(void) 13085 { 13086 return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439); 13087 } 13088 13089 #ifdef RTE_CRYPTO_SCHEDULER 13090 13091 /* global AESNI worker IDs for the scheduler test */ 13092 uint8_t aesni_ids[2]; 13093 13094 static int 13095 test_scheduler_attach_slave_op(void) 13096 { 13097 struct crypto_testsuite_params *ts_params = &testsuite_params; 13098 uint8_t sched_id = ts_params->valid_devs[0]; 13099 uint32_t nb_devs, i, nb_devs_attached = 0; 13100 int ret; 13101 char vdev_name[32]; 13102 13103 /* create 2 AESNI_MB if necessary */ 13104 nb_devs = rte_cryptodev_device_count_by_driver( 13105 rte_cryptodev_driver_id_get( 13106 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))); 13107 if (nb_devs < 2) { 13108 for (i = nb_devs; i < 2; i++) { 13109 snprintf(vdev_name, sizeof(vdev_name), "%s_%u", 13110 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), 13111 i); 13112 ret = rte_vdev_init(vdev_name, NULL); 13113 13114 TEST_ASSERT(ret == 0, 13115 "Failed to create instance %u of" 13116 " pmd : %s", 13117 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 13118 } 13119 } 13120 13121 /* attach 2 AESNI_MB cdevs */ 13122 for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2; 13123 i++) { 13124 struct rte_cryptodev_info info; 13125 unsigned int session_size; 13126 13127 rte_cryptodev_info_get(i, &info); 13128 if (info.driver_id != rte_cryptodev_driver_id_get( 13129 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) 13130 continue; 13131 13132 session_size = rte_cryptodev_sym_get_private_session_size(i); 13133 /* 13134 * Create the session mempool again, since now there are new devices 13135 * to use the mempool. 13136 */ 13137 if (ts_params->session_mpool) { 13138 rte_mempool_free(ts_params->session_mpool); 13139 ts_params->session_mpool = NULL; 13140 } 13141 if (ts_params->session_priv_mpool) { 13142 rte_mempool_free(ts_params->session_priv_mpool); 13143 ts_params->session_priv_mpool = NULL; 13144 } 13145 13146 if (info.sym.max_nb_sessions != 0 && 13147 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 13148 RTE_LOG(ERR, USER1, 13149 "Device does not support " 13150 "at least %u sessions\n", 13151 MAX_NB_SESSIONS); 13152 return TEST_FAILED; 13153 } 13154 /* 13155 * Create mempool with maximum number of sessions, 13156 * to include the session headers 13157 */ 13158 if (ts_params->session_mpool == NULL) { 13159 ts_params->session_mpool = 13160 rte_cryptodev_sym_session_pool_create( 13161 "test_sess_mp", 13162 MAX_NB_SESSIONS, 0, 0, 0, 13163 SOCKET_ID_ANY); 13164 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 13165 "session mempool allocation failed"); 13166 } 13167 13168 /* 13169 * Create mempool with maximum number of sessions, 13170 * to include device specific session private data 13171 */ 13172 if (ts_params->session_priv_mpool == NULL) { 13173 ts_params->session_priv_mpool = rte_mempool_create( 13174 "test_sess_mp_priv", 13175 MAX_NB_SESSIONS, 13176 session_size, 13177 0, 0, NULL, NULL, NULL, 13178 NULL, SOCKET_ID_ANY, 13179 0); 13180 13181 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 13182 "session mempool allocation failed"); 13183 } 13184 13185 ts_params->qp_conf.mp_session = ts_params->session_mpool; 13186 ts_params->qp_conf.mp_session_private = 13187 ts_params->session_priv_mpool; 13188 13189 ret = rte_cryptodev_scheduler_worker_attach(sched_id, 13190 (uint8_t)i); 13191 13192 TEST_ASSERT(ret == 0, 13193 "Failed to attach device %u of pmd : %s", i, 13194 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 13195 13196 aesni_ids[nb_devs_attached] = (uint8_t)i; 13197 13198 nb_devs_attached++; 13199 } 13200 13201 return 0; 13202 } 13203 13204 static int 13205 test_scheduler_detach_slave_op(void) 13206 { 13207 struct crypto_testsuite_params *ts_params = &testsuite_params; 13208 uint8_t sched_id = ts_params->valid_devs[0]; 13209 uint32_t i; 13210 int ret; 13211 13212 for (i = 0; i < 2; i++) { 13213 ret = rte_cryptodev_scheduler_worker_detach(sched_id, 13214 aesni_ids[i]); 13215 TEST_ASSERT(ret == 0, 13216 "Failed to detach device %u", aesni_ids[i]); 13217 } 13218 13219 return 0; 13220 } 13221 13222 static int 13223 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode) 13224 { 13225 struct crypto_testsuite_params *ts_params = &testsuite_params; 13226 uint8_t sched_id = ts_params->valid_devs[0]; 13227 /* set mode */ 13228 return rte_cryptodev_scheduler_mode_set(sched_id, 13229 scheduler_mode); 13230 } 13231 13232 static int 13233 test_scheduler_mode_roundrobin_op(void) 13234 { 13235 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) == 13236 0, "Failed to set roundrobin mode"); 13237 return 0; 13238 13239 } 13240 13241 static int 13242 test_scheduler_mode_multicore_op(void) 13243 { 13244 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) == 13245 0, "Failed to set multicore mode"); 13246 13247 return 0; 13248 } 13249 13250 static int 13251 test_scheduler_mode_failover_op(void) 13252 { 13253 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) == 13254 0, "Failed to set failover mode"); 13255 13256 return 0; 13257 } 13258 13259 static int 13260 test_scheduler_mode_pkt_size_distr_op(void) 13261 { 13262 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) == 13263 0, "Failed to set pktsize mode"); 13264 13265 return 0; 13266 } 13267 13268 static struct unit_test_suite cryptodev_scheduler_testsuite = { 13269 .suite_name = "Crypto Device Scheduler Unit Test Suite", 13270 .setup = testsuite_setup, 13271 .teardown = testsuite_teardown, 13272 .unit_test_cases = { 13273 /* Multi Core */ 13274 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 13275 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_multicore_op), 13276 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13277 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13278 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13279 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 13280 13281 /* Round Robin */ 13282 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 13283 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_roundrobin_op), 13284 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13285 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13286 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13287 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 13288 13289 /* Fail over */ 13290 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 13291 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_failover_op), 13292 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13293 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13294 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13295 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 13296 13297 /* PKT SIZE */ 13298 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 13299 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_pkt_size_distr_op), 13300 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13301 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13302 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13303 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 13304 13305 TEST_CASES_END() /**< NULL terminate unit test array */ 13306 } 13307 }; 13308 13309 #endif /* RTE_CRYPTO_SCHEDULER */ 13310 13311 static struct unit_test_suite cryptodev_testsuite = { 13312 .suite_name = "Crypto Unit Test Suite", 13313 .setup = testsuite_setup, 13314 .teardown = testsuite_teardown, 13315 .unit_test_cases = { 13316 TEST_CASE_ST(ut_setup, ut_teardown, 13317 test_device_configure_invalid_dev_id), 13318 TEST_CASE_ST(ut_setup, ut_teardown, 13319 test_queue_pair_descriptor_setup), 13320 TEST_CASE_ST(ut_setup, ut_teardown, 13321 test_device_configure_invalid_queue_pair_ids), 13322 TEST_CASE_ST(ut_setup, ut_teardown, 13323 test_multi_session), 13324 TEST_CASE_ST(ut_setup, ut_teardown, 13325 test_multi_session_random_usage), 13326 13327 TEST_CASE_ST(ut_setup, ut_teardown, 13328 test_null_invalid_operation), 13329 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation), 13330 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13331 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13332 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 13333 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 13334 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_cipheronly_all), 13335 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_all), 13336 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_docsis_all), 13337 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13338 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 13339 13340 /** AES CCM Authenticated Encryption 128 bits key */ 13341 TEST_CASE_ST(ut_setup, ut_teardown, 13342 test_AES_CCM_authenticated_encryption_test_case_128_1), 13343 TEST_CASE_ST(ut_setup, ut_teardown, 13344 test_AES_CCM_authenticated_encryption_test_case_128_2), 13345 TEST_CASE_ST(ut_setup, ut_teardown, 13346 test_AES_CCM_authenticated_encryption_test_case_128_3), 13347 13348 /** AES CCM Authenticated Decryption 128 bits key*/ 13349 TEST_CASE_ST(ut_setup, ut_teardown, 13350 test_AES_CCM_authenticated_decryption_test_case_128_1), 13351 TEST_CASE_ST(ut_setup, ut_teardown, 13352 test_AES_CCM_authenticated_decryption_test_case_128_2), 13353 TEST_CASE_ST(ut_setup, ut_teardown, 13354 test_AES_CCM_authenticated_decryption_test_case_128_3), 13355 13356 /** AES CCM Authenticated Encryption 192 bits key */ 13357 TEST_CASE_ST(ut_setup, ut_teardown, 13358 test_AES_CCM_authenticated_encryption_test_case_192_1), 13359 TEST_CASE_ST(ut_setup, ut_teardown, 13360 test_AES_CCM_authenticated_encryption_test_case_192_2), 13361 TEST_CASE_ST(ut_setup, ut_teardown, 13362 test_AES_CCM_authenticated_encryption_test_case_192_3), 13363 13364 /** AES CCM Authenticated Decryption 192 bits key*/ 13365 TEST_CASE_ST(ut_setup, ut_teardown, 13366 test_AES_CCM_authenticated_decryption_test_case_192_1), 13367 TEST_CASE_ST(ut_setup, ut_teardown, 13368 test_AES_CCM_authenticated_decryption_test_case_192_2), 13369 TEST_CASE_ST(ut_setup, ut_teardown, 13370 test_AES_CCM_authenticated_decryption_test_case_192_3), 13371 13372 /** AES CCM Authenticated Encryption 256 bits key */ 13373 TEST_CASE_ST(ut_setup, ut_teardown, 13374 test_AES_CCM_authenticated_encryption_test_case_256_1), 13375 TEST_CASE_ST(ut_setup, ut_teardown, 13376 test_AES_CCM_authenticated_encryption_test_case_256_2), 13377 TEST_CASE_ST(ut_setup, ut_teardown, 13378 test_AES_CCM_authenticated_encryption_test_case_256_3), 13379 13380 /** AES CCM Authenticated Decryption 256 bits key*/ 13381 TEST_CASE_ST(ut_setup, ut_teardown, 13382 test_AES_CCM_authenticated_decryption_test_case_256_1), 13383 TEST_CASE_ST(ut_setup, ut_teardown, 13384 test_AES_CCM_authenticated_decryption_test_case_256_2), 13385 TEST_CASE_ST(ut_setup, ut_teardown, 13386 test_AES_CCM_authenticated_decryption_test_case_256_3), 13387 13388 /** AES GCM Authenticated Encryption */ 13389 TEST_CASE_ST(ut_setup, ut_teardown, 13390 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 13391 TEST_CASE_ST(ut_setup, ut_teardown, 13392 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 13393 TEST_CASE_ST(ut_setup, ut_teardown, 13394 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 13395 TEST_CASE_ST(ut_setup, ut_teardown, 13396 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 13397 TEST_CASE_ST(ut_setup, ut_teardown, 13398 test_AES_GCM_authenticated_encryption_test_case_1), 13399 TEST_CASE_ST(ut_setup, ut_teardown, 13400 test_AES_GCM_authenticated_encryption_test_case_2), 13401 TEST_CASE_ST(ut_setup, ut_teardown, 13402 test_AES_GCM_authenticated_encryption_test_case_3), 13403 TEST_CASE_ST(ut_setup, ut_teardown, 13404 test_AES_GCM_authenticated_encryption_test_case_4), 13405 TEST_CASE_ST(ut_setup, ut_teardown, 13406 test_AES_GCM_authenticated_encryption_test_case_5), 13407 TEST_CASE_ST(ut_setup, ut_teardown, 13408 test_AES_GCM_authenticated_encryption_test_case_6), 13409 TEST_CASE_ST(ut_setup, ut_teardown, 13410 test_AES_GCM_authenticated_encryption_test_case_7), 13411 TEST_CASE_ST(ut_setup, ut_teardown, 13412 test_AES_GCM_authenticated_encryption_test_case_8), 13413 TEST_CASE_ST(ut_setup, ut_teardown, 13414 test_AES_GCM_J0_authenticated_encryption_test_case_1), 13415 13416 /** AES GCM Authenticated Decryption */ 13417 TEST_CASE_ST(ut_setup, ut_teardown, 13418 test_AES_GCM_authenticated_decryption_test_case_1), 13419 TEST_CASE_ST(ut_setup, ut_teardown, 13420 test_AES_GCM_authenticated_decryption_test_case_2), 13421 TEST_CASE_ST(ut_setup, ut_teardown, 13422 test_AES_GCM_authenticated_decryption_test_case_3), 13423 TEST_CASE_ST(ut_setup, ut_teardown, 13424 test_AES_GCM_authenticated_decryption_test_case_4), 13425 TEST_CASE_ST(ut_setup, ut_teardown, 13426 test_AES_GCM_authenticated_decryption_test_case_5), 13427 TEST_CASE_ST(ut_setup, ut_teardown, 13428 test_AES_GCM_authenticated_decryption_test_case_6), 13429 TEST_CASE_ST(ut_setup, ut_teardown, 13430 test_AES_GCM_authenticated_decryption_test_case_7), 13431 TEST_CASE_ST(ut_setup, ut_teardown, 13432 test_AES_GCM_authenticated_decryption_test_case_8), 13433 TEST_CASE_ST(ut_setup, ut_teardown, 13434 test_AES_GCM_J0_authenticated_decryption_test_case_1), 13435 13436 /** AES GCM Authenticated Encryption 192 bits key */ 13437 TEST_CASE_ST(ut_setup, ut_teardown, 13438 test_AES_GCM_auth_encryption_test_case_192_1), 13439 TEST_CASE_ST(ut_setup, ut_teardown, 13440 test_AES_GCM_auth_encryption_test_case_192_2), 13441 TEST_CASE_ST(ut_setup, ut_teardown, 13442 test_AES_GCM_auth_encryption_test_case_192_3), 13443 TEST_CASE_ST(ut_setup, ut_teardown, 13444 test_AES_GCM_auth_encryption_test_case_192_4), 13445 TEST_CASE_ST(ut_setup, ut_teardown, 13446 test_AES_GCM_auth_encryption_test_case_192_5), 13447 TEST_CASE_ST(ut_setup, ut_teardown, 13448 test_AES_GCM_auth_encryption_test_case_192_6), 13449 TEST_CASE_ST(ut_setup, ut_teardown, 13450 test_AES_GCM_auth_encryption_test_case_192_7), 13451 13452 /** AES GCM Authenticated Decryption 192 bits key */ 13453 TEST_CASE_ST(ut_setup, ut_teardown, 13454 test_AES_GCM_auth_decryption_test_case_192_1), 13455 TEST_CASE_ST(ut_setup, ut_teardown, 13456 test_AES_GCM_auth_decryption_test_case_192_2), 13457 TEST_CASE_ST(ut_setup, ut_teardown, 13458 test_AES_GCM_auth_decryption_test_case_192_3), 13459 TEST_CASE_ST(ut_setup, ut_teardown, 13460 test_AES_GCM_auth_decryption_test_case_192_4), 13461 TEST_CASE_ST(ut_setup, ut_teardown, 13462 test_AES_GCM_auth_decryption_test_case_192_5), 13463 TEST_CASE_ST(ut_setup, ut_teardown, 13464 test_AES_GCM_auth_decryption_test_case_192_6), 13465 TEST_CASE_ST(ut_setup, ut_teardown, 13466 test_AES_GCM_auth_decryption_test_case_192_7), 13467 13468 /** AES GCM Authenticated Encryption 256 bits key */ 13469 TEST_CASE_ST(ut_setup, ut_teardown, 13470 test_AES_GCM_auth_encryption_test_case_256_1), 13471 TEST_CASE_ST(ut_setup, ut_teardown, 13472 test_AES_GCM_auth_encryption_test_case_256_2), 13473 TEST_CASE_ST(ut_setup, ut_teardown, 13474 test_AES_GCM_auth_encryption_test_case_256_3), 13475 TEST_CASE_ST(ut_setup, ut_teardown, 13476 test_AES_GCM_auth_encryption_test_case_256_4), 13477 TEST_CASE_ST(ut_setup, ut_teardown, 13478 test_AES_GCM_auth_encryption_test_case_256_5), 13479 TEST_CASE_ST(ut_setup, ut_teardown, 13480 test_AES_GCM_auth_encryption_test_case_256_6), 13481 TEST_CASE_ST(ut_setup, ut_teardown, 13482 test_AES_GCM_auth_encryption_test_case_256_7), 13483 13484 /** AES GCM Authenticated Decryption 256 bits key */ 13485 TEST_CASE_ST(ut_setup, ut_teardown, 13486 test_AES_GCM_auth_decryption_test_case_256_1), 13487 TEST_CASE_ST(ut_setup, ut_teardown, 13488 test_AES_GCM_auth_decryption_test_case_256_2), 13489 TEST_CASE_ST(ut_setup, ut_teardown, 13490 test_AES_GCM_auth_decryption_test_case_256_3), 13491 TEST_CASE_ST(ut_setup, ut_teardown, 13492 test_AES_GCM_auth_decryption_test_case_256_4), 13493 TEST_CASE_ST(ut_setup, ut_teardown, 13494 test_AES_GCM_auth_decryption_test_case_256_5), 13495 TEST_CASE_ST(ut_setup, ut_teardown, 13496 test_AES_GCM_auth_decryption_test_case_256_6), 13497 TEST_CASE_ST(ut_setup, ut_teardown, 13498 test_AES_GCM_auth_decryption_test_case_256_7), 13499 13500 /** AES GCM Authenticated Encryption big aad size */ 13501 TEST_CASE_ST(ut_setup, ut_teardown, 13502 test_AES_GCM_auth_encryption_test_case_aad_1), 13503 TEST_CASE_ST(ut_setup, ut_teardown, 13504 test_AES_GCM_auth_encryption_test_case_aad_2), 13505 13506 /** AES GCM Authenticated Decryption big aad size */ 13507 TEST_CASE_ST(ut_setup, ut_teardown, 13508 test_AES_GCM_auth_decryption_test_case_aad_1), 13509 TEST_CASE_ST(ut_setup, ut_teardown, 13510 test_AES_GCM_auth_decryption_test_case_aad_2), 13511 13512 /** Out of place tests */ 13513 TEST_CASE_ST(ut_setup, ut_teardown, 13514 test_AES_GCM_authenticated_encryption_oop_test_case_1), 13515 TEST_CASE_ST(ut_setup, ut_teardown, 13516 test_AES_GCM_authenticated_decryption_oop_test_case_1), 13517 13518 /** Session-less tests */ 13519 TEST_CASE_ST(ut_setup, ut_teardown, 13520 test_AES_GCM_authenticated_encryption_sessionless_test_case_1), 13521 TEST_CASE_ST(ut_setup, ut_teardown, 13522 test_AES_GCM_authenticated_decryption_sessionless_test_case_1), 13523 13524 /** AES GMAC Authentication */ 13525 TEST_CASE_ST(ut_setup, ut_teardown, 13526 test_AES_GMAC_authentication_test_case_1), 13527 TEST_CASE_ST(ut_setup, ut_teardown, 13528 test_AES_GMAC_authentication_verify_test_case_1), 13529 TEST_CASE_ST(ut_setup, ut_teardown, 13530 test_AES_GMAC_authentication_test_case_2), 13531 TEST_CASE_ST(ut_setup, ut_teardown, 13532 test_AES_GMAC_authentication_verify_test_case_2), 13533 TEST_CASE_ST(ut_setup, ut_teardown, 13534 test_AES_GMAC_authentication_test_case_3), 13535 TEST_CASE_ST(ut_setup, ut_teardown, 13536 test_AES_GMAC_authentication_verify_test_case_3), 13537 TEST_CASE_ST(ut_setup, ut_teardown, 13538 test_AES_GMAC_authentication_test_case_4), 13539 TEST_CASE_ST(ut_setup, ut_teardown, 13540 test_AES_GMAC_authentication_verify_test_case_4), 13541 TEST_CASE_ST(ut_setup, ut_teardown, 13542 test_AES_GMAC_authentication_SGL_40B), 13543 TEST_CASE_ST(ut_setup, ut_teardown, 13544 test_AES_GMAC_authentication_SGL_80B), 13545 TEST_CASE_ST(ut_setup, ut_teardown, 13546 test_AES_GMAC_authentication_SGL_2048B), 13547 TEST_CASE_ST(ut_setup, ut_teardown, 13548 test_AES_GMAC_authentication_SGL_2047B), 13549 13550 /** Chacha20-Poly1305 */ 13551 TEST_CASE_ST(ut_setup, ut_teardown, 13552 test_chacha20_poly1305_encrypt_test_case_rfc8439), 13553 TEST_CASE_ST(ut_setup, ut_teardown, 13554 test_chacha20_poly1305_decrypt_test_case_rfc8439), 13555 /** SNOW 3G encrypt only (UEA2) */ 13556 TEST_CASE_ST(ut_setup, ut_teardown, 13557 test_snow3g_encryption_test_case_1), 13558 TEST_CASE_ST(ut_setup, ut_teardown, 13559 test_snow3g_encryption_test_case_2), 13560 TEST_CASE_ST(ut_setup, ut_teardown, 13561 test_snow3g_encryption_test_case_3), 13562 TEST_CASE_ST(ut_setup, ut_teardown, 13563 test_snow3g_encryption_test_case_4), 13564 TEST_CASE_ST(ut_setup, ut_teardown, 13565 test_snow3g_encryption_test_case_5), 13566 13567 TEST_CASE_ST(ut_setup, ut_teardown, 13568 test_snow3g_encryption_test_case_1_oop), 13569 TEST_CASE_ST(ut_setup, ut_teardown, 13570 test_snow3g_encryption_test_case_1_oop_sgl), 13571 TEST_CASE_ST(ut_setup, ut_teardown, 13572 test_snow3g_encryption_test_case_1_offset_oop), 13573 TEST_CASE_ST(ut_setup, ut_teardown, 13574 test_snow3g_decryption_test_case_1_oop), 13575 13576 /** SNOW 3G generate auth, then encrypt (UEA2) */ 13577 TEST_CASE_ST(ut_setup, ut_teardown, 13578 test_snow3g_auth_cipher_test_case_1), 13579 TEST_CASE_ST(ut_setup, ut_teardown, 13580 test_snow3g_auth_cipher_test_case_2), 13581 TEST_CASE_ST(ut_setup, ut_teardown, 13582 test_snow3g_auth_cipher_test_case_2_oop), 13583 TEST_CASE_ST(ut_setup, ut_teardown, 13584 test_snow3g_auth_cipher_part_digest_enc), 13585 TEST_CASE_ST(ut_setup, ut_teardown, 13586 test_snow3g_auth_cipher_part_digest_enc_oop), 13587 TEST_CASE_ST(ut_setup, ut_teardown, 13588 test_snow3g_auth_cipher_test_case_3_sgl), 13589 TEST_CASE_ST(ut_setup, ut_teardown, 13590 test_snow3g_auth_cipher_test_case_3_oop_sgl), 13591 TEST_CASE_ST(ut_setup, ut_teardown, 13592 test_snow3g_auth_cipher_part_digest_enc_sgl), 13593 TEST_CASE_ST(ut_setup, ut_teardown, 13594 test_snow3g_auth_cipher_part_digest_enc_oop_sgl), 13595 13596 /** SNOW 3G decrypt (UEA2), then verify auth */ 13597 TEST_CASE_ST(ut_setup, ut_teardown, 13598 test_snow3g_auth_cipher_verify_test_case_1), 13599 TEST_CASE_ST(ut_setup, ut_teardown, 13600 test_snow3g_auth_cipher_verify_test_case_2), 13601 TEST_CASE_ST(ut_setup, ut_teardown, 13602 test_snow3g_auth_cipher_verify_test_case_2_oop), 13603 TEST_CASE_ST(ut_setup, ut_teardown, 13604 test_snow3g_auth_cipher_verify_part_digest_enc), 13605 TEST_CASE_ST(ut_setup, ut_teardown, 13606 test_snow3g_auth_cipher_verify_part_digest_enc_oop), 13607 TEST_CASE_ST(ut_setup, ut_teardown, 13608 test_snow3g_auth_cipher_verify_test_case_3_sgl), 13609 TEST_CASE_ST(ut_setup, ut_teardown, 13610 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl), 13611 TEST_CASE_ST(ut_setup, ut_teardown, 13612 test_snow3g_auth_cipher_verify_part_digest_enc_sgl), 13613 TEST_CASE_ST(ut_setup, ut_teardown, 13614 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl), 13615 13616 /** SNOW 3G decrypt only (UEA2) */ 13617 TEST_CASE_ST(ut_setup, ut_teardown, 13618 test_snow3g_decryption_test_case_1), 13619 TEST_CASE_ST(ut_setup, ut_teardown, 13620 test_snow3g_decryption_test_case_2), 13621 TEST_CASE_ST(ut_setup, ut_teardown, 13622 test_snow3g_decryption_test_case_3), 13623 TEST_CASE_ST(ut_setup, ut_teardown, 13624 test_snow3g_decryption_test_case_4), 13625 TEST_CASE_ST(ut_setup, ut_teardown, 13626 test_snow3g_decryption_test_case_5), 13627 TEST_CASE_ST(ut_setup, ut_teardown, 13628 test_snow3g_decryption_with_digest_test_case_1), 13629 TEST_CASE_ST(ut_setup, ut_teardown, 13630 test_snow3g_hash_generate_test_case_1), 13631 TEST_CASE_ST(ut_setup, ut_teardown, 13632 test_snow3g_hash_generate_test_case_2), 13633 TEST_CASE_ST(ut_setup, ut_teardown, 13634 test_snow3g_hash_generate_test_case_3), 13635 /* Tests with buffers which length is not byte-aligned */ 13636 TEST_CASE_ST(ut_setup, ut_teardown, 13637 test_snow3g_hash_generate_test_case_4), 13638 TEST_CASE_ST(ut_setup, ut_teardown, 13639 test_snow3g_hash_generate_test_case_5), 13640 TEST_CASE_ST(ut_setup, ut_teardown, 13641 test_snow3g_hash_generate_test_case_6), 13642 TEST_CASE_ST(ut_setup, ut_teardown, 13643 test_snow3g_hash_verify_test_case_1), 13644 TEST_CASE_ST(ut_setup, ut_teardown, 13645 test_snow3g_hash_verify_test_case_2), 13646 TEST_CASE_ST(ut_setup, ut_teardown, 13647 test_snow3g_hash_verify_test_case_3), 13648 /* Tests with buffers which length is not byte-aligned */ 13649 TEST_CASE_ST(ut_setup, ut_teardown, 13650 test_snow3g_hash_verify_test_case_4), 13651 TEST_CASE_ST(ut_setup, ut_teardown, 13652 test_snow3g_hash_verify_test_case_5), 13653 TEST_CASE_ST(ut_setup, ut_teardown, 13654 test_snow3g_hash_verify_test_case_6), 13655 TEST_CASE_ST(ut_setup, ut_teardown, 13656 test_snow3g_cipher_auth_test_case_1), 13657 TEST_CASE_ST(ut_setup, ut_teardown, 13658 test_snow3g_auth_cipher_with_digest_test_case_1), 13659 13660 /** ZUC encrypt only (EEA3) */ 13661 TEST_CASE_ST(ut_setup, ut_teardown, 13662 test_zuc_encryption_test_case_1), 13663 TEST_CASE_ST(ut_setup, ut_teardown, 13664 test_zuc_encryption_test_case_2), 13665 TEST_CASE_ST(ut_setup, ut_teardown, 13666 test_zuc_encryption_test_case_3), 13667 TEST_CASE_ST(ut_setup, ut_teardown, 13668 test_zuc_encryption_test_case_4), 13669 TEST_CASE_ST(ut_setup, ut_teardown, 13670 test_zuc_encryption_test_case_5), 13671 TEST_CASE_ST(ut_setup, ut_teardown, 13672 test_zuc_encryption_test_case_6_sgl), 13673 13674 /** ZUC authenticate (EIA3) */ 13675 TEST_CASE_ST(ut_setup, ut_teardown, 13676 test_zuc_hash_generate_test_case_1), 13677 TEST_CASE_ST(ut_setup, ut_teardown, 13678 test_zuc_hash_generate_test_case_2), 13679 TEST_CASE_ST(ut_setup, ut_teardown, 13680 test_zuc_hash_generate_test_case_3), 13681 TEST_CASE_ST(ut_setup, ut_teardown, 13682 test_zuc_hash_generate_test_case_4), 13683 TEST_CASE_ST(ut_setup, ut_teardown, 13684 test_zuc_hash_generate_test_case_5), 13685 TEST_CASE_ST(ut_setup, ut_teardown, 13686 test_zuc_hash_generate_test_case_6), 13687 TEST_CASE_ST(ut_setup, ut_teardown, 13688 test_zuc_hash_generate_test_case_7), 13689 TEST_CASE_ST(ut_setup, ut_teardown, 13690 test_zuc_hash_generate_test_case_8), 13691 13692 /** ZUC alg-chain (EEA3/EIA3) */ 13693 TEST_CASE_ST(ut_setup, ut_teardown, 13694 test_zuc_cipher_auth_test_case_1), 13695 TEST_CASE_ST(ut_setup, ut_teardown, 13696 test_zuc_cipher_auth_test_case_2), 13697 13698 /** ZUC generate auth, then encrypt (EEA3) */ 13699 TEST_CASE_ST(ut_setup, ut_teardown, 13700 test_zuc_auth_cipher_test_case_1), 13701 TEST_CASE_ST(ut_setup, ut_teardown, 13702 test_zuc_auth_cipher_test_case_1_oop), 13703 TEST_CASE_ST(ut_setup, ut_teardown, 13704 test_zuc_auth_cipher_test_case_1_sgl), 13705 TEST_CASE_ST(ut_setup, ut_teardown, 13706 test_zuc_auth_cipher_test_case_1_oop_sgl), 13707 13708 /** ZUC decrypt (EEA3), then verify auth */ 13709 TEST_CASE_ST(ut_setup, ut_teardown, 13710 test_zuc_auth_cipher_verify_test_case_1), 13711 TEST_CASE_ST(ut_setup, ut_teardown, 13712 test_zuc_auth_cipher_verify_test_case_1_oop), 13713 TEST_CASE_ST(ut_setup, ut_teardown, 13714 test_zuc_auth_cipher_verify_test_case_1_sgl), 13715 TEST_CASE_ST(ut_setup, ut_teardown, 13716 test_zuc_auth_cipher_verify_test_case_1_oop_sgl), 13717 13718 /** HMAC_MD5 Authentication */ 13719 TEST_CASE_ST(ut_setup, ut_teardown, 13720 test_MD5_HMAC_generate_case_1), 13721 TEST_CASE_ST(ut_setup, ut_teardown, 13722 test_MD5_HMAC_verify_case_1), 13723 TEST_CASE_ST(ut_setup, ut_teardown, 13724 test_MD5_HMAC_generate_case_2), 13725 TEST_CASE_ST(ut_setup, ut_teardown, 13726 test_MD5_HMAC_verify_case_2), 13727 13728 /** KASUMI hash only (UIA1) */ 13729 TEST_CASE_ST(ut_setup, ut_teardown, 13730 test_kasumi_hash_generate_test_case_1), 13731 TEST_CASE_ST(ut_setup, ut_teardown, 13732 test_kasumi_hash_generate_test_case_2), 13733 TEST_CASE_ST(ut_setup, ut_teardown, 13734 test_kasumi_hash_generate_test_case_3), 13735 TEST_CASE_ST(ut_setup, ut_teardown, 13736 test_kasumi_hash_generate_test_case_4), 13737 TEST_CASE_ST(ut_setup, ut_teardown, 13738 test_kasumi_hash_generate_test_case_5), 13739 TEST_CASE_ST(ut_setup, ut_teardown, 13740 test_kasumi_hash_generate_test_case_6), 13741 13742 TEST_CASE_ST(ut_setup, ut_teardown, 13743 test_kasumi_hash_verify_test_case_1), 13744 TEST_CASE_ST(ut_setup, ut_teardown, 13745 test_kasumi_hash_verify_test_case_2), 13746 TEST_CASE_ST(ut_setup, ut_teardown, 13747 test_kasumi_hash_verify_test_case_3), 13748 TEST_CASE_ST(ut_setup, ut_teardown, 13749 test_kasumi_hash_verify_test_case_4), 13750 TEST_CASE_ST(ut_setup, ut_teardown, 13751 test_kasumi_hash_verify_test_case_5), 13752 13753 /** KASUMI encrypt only (UEA1) */ 13754 TEST_CASE_ST(ut_setup, ut_teardown, 13755 test_kasumi_encryption_test_case_1), 13756 TEST_CASE_ST(ut_setup, ut_teardown, 13757 test_kasumi_encryption_test_case_1_sgl), 13758 TEST_CASE_ST(ut_setup, ut_teardown, 13759 test_kasumi_encryption_test_case_1_oop), 13760 TEST_CASE_ST(ut_setup, ut_teardown, 13761 test_kasumi_encryption_test_case_1_oop_sgl), 13762 TEST_CASE_ST(ut_setup, ut_teardown, 13763 test_kasumi_encryption_test_case_2), 13764 TEST_CASE_ST(ut_setup, ut_teardown, 13765 test_kasumi_encryption_test_case_3), 13766 TEST_CASE_ST(ut_setup, ut_teardown, 13767 test_kasumi_encryption_test_case_4), 13768 TEST_CASE_ST(ut_setup, ut_teardown, 13769 test_kasumi_encryption_test_case_5), 13770 13771 /** KASUMI decrypt only (UEA1) */ 13772 TEST_CASE_ST(ut_setup, ut_teardown, 13773 test_kasumi_decryption_test_case_1), 13774 TEST_CASE_ST(ut_setup, ut_teardown, 13775 test_kasumi_decryption_test_case_2), 13776 TEST_CASE_ST(ut_setup, ut_teardown, 13777 test_kasumi_decryption_test_case_3), 13778 TEST_CASE_ST(ut_setup, ut_teardown, 13779 test_kasumi_decryption_test_case_4), 13780 TEST_CASE_ST(ut_setup, ut_teardown, 13781 test_kasumi_decryption_test_case_5), 13782 TEST_CASE_ST(ut_setup, ut_teardown, 13783 test_kasumi_decryption_test_case_1_oop), 13784 13785 TEST_CASE_ST(ut_setup, ut_teardown, 13786 test_kasumi_cipher_auth_test_case_1), 13787 13788 /** KASUMI generate auth, then encrypt (F8) */ 13789 TEST_CASE_ST(ut_setup, ut_teardown, 13790 test_kasumi_auth_cipher_test_case_1), 13791 TEST_CASE_ST(ut_setup, ut_teardown, 13792 test_kasumi_auth_cipher_test_case_2), 13793 TEST_CASE_ST(ut_setup, ut_teardown, 13794 test_kasumi_auth_cipher_test_case_2_oop), 13795 TEST_CASE_ST(ut_setup, ut_teardown, 13796 test_kasumi_auth_cipher_test_case_2_sgl), 13797 TEST_CASE_ST(ut_setup, ut_teardown, 13798 test_kasumi_auth_cipher_test_case_2_oop_sgl), 13799 13800 /** KASUMI decrypt (F8), then verify auth */ 13801 TEST_CASE_ST(ut_setup, ut_teardown, 13802 test_kasumi_auth_cipher_verify_test_case_1), 13803 TEST_CASE_ST(ut_setup, ut_teardown, 13804 test_kasumi_auth_cipher_verify_test_case_2), 13805 TEST_CASE_ST(ut_setup, ut_teardown, 13806 test_kasumi_auth_cipher_verify_test_case_2_oop), 13807 TEST_CASE_ST(ut_setup, ut_teardown, 13808 test_kasumi_auth_cipher_verify_test_case_2_sgl), 13809 TEST_CASE_ST(ut_setup, ut_teardown, 13810 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl), 13811 13812 /** ESN Testcase */ 13813 TEST_CASE_ST(ut_setup, ut_teardown, 13814 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 13815 TEST_CASE_ST(ut_setup, ut_teardown, 13816 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 13817 13818 /** Negative tests */ 13819 TEST_CASE_ST(ut_setup, ut_teardown, 13820 authentication_verify_HMAC_SHA1_fail_data_corrupt), 13821 TEST_CASE_ST(ut_setup, ut_teardown, 13822 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 13823 TEST_CASE_ST(ut_setup, ut_teardown, 13824 test_AES_GCM_auth_encryption_fail_iv_corrupt), 13825 TEST_CASE_ST(ut_setup, ut_teardown, 13826 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 13827 TEST_CASE_ST(ut_setup, ut_teardown, 13828 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 13829 TEST_CASE_ST(ut_setup, ut_teardown, 13830 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 13831 TEST_CASE_ST(ut_setup, ut_teardown, 13832 test_AES_GCM_auth_encryption_fail_aad_corrupt), 13833 TEST_CASE_ST(ut_setup, ut_teardown, 13834 test_AES_GCM_auth_encryption_fail_tag_corrupt), 13835 TEST_CASE_ST(ut_setup, ut_teardown, 13836 test_AES_GCM_auth_decryption_fail_iv_corrupt), 13837 TEST_CASE_ST(ut_setup, ut_teardown, 13838 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 13839 TEST_CASE_ST(ut_setup, ut_teardown, 13840 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 13841 TEST_CASE_ST(ut_setup, ut_teardown, 13842 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 13843 TEST_CASE_ST(ut_setup, ut_teardown, 13844 test_AES_GCM_auth_decryption_fail_aad_corrupt), 13845 TEST_CASE_ST(ut_setup, ut_teardown, 13846 test_AES_GCM_auth_decryption_fail_tag_corrupt), 13847 TEST_CASE_ST(ut_setup, ut_teardown, 13848 authentication_verify_AES128_GMAC_fail_data_corrupt), 13849 TEST_CASE_ST(ut_setup, ut_teardown, 13850 authentication_verify_AES128_GMAC_fail_tag_corrupt), 13851 TEST_CASE_ST(ut_setup, ut_teardown, 13852 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 13853 TEST_CASE_ST(ut_setup, ut_teardown, 13854 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 13855 13856 /** Mixed CIPHER + HASH algorithms */ 13857 /** AUTH AES CMAC + CIPHER AES CTR */ 13858 TEST_CASE_ST(ut_setup, ut_teardown, 13859 test_aes_cmac_aes_ctr_digest_enc_test_case_1), 13860 TEST_CASE_ST(ut_setup, ut_teardown, 13861 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 13862 TEST_CASE_ST(ut_setup, ut_teardown, 13863 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 13864 TEST_CASE_ST(ut_setup, ut_teardown, 13865 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 13866 TEST_CASE_ST(ut_setup, ut_teardown, 13867 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1), 13868 TEST_CASE_ST(ut_setup, ut_teardown, 13869 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 13870 TEST_CASE_ST(ut_setup, ut_teardown, 13871 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 13872 TEST_CASE_ST(ut_setup, ut_teardown, 13873 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 13874 13875 /** AUTH ZUC + CIPHER SNOW3G */ 13876 TEST_CASE_ST(ut_setup, ut_teardown, 13877 test_auth_zuc_cipher_snow_test_case_1), 13878 TEST_CASE_ST(ut_setup, ut_teardown, 13879 test_verify_auth_zuc_cipher_snow_test_case_1), 13880 /** AUTH AES CMAC + CIPHER SNOW3G */ 13881 TEST_CASE_ST(ut_setup, ut_teardown, 13882 test_auth_aes_cmac_cipher_snow_test_case_1), 13883 TEST_CASE_ST(ut_setup, ut_teardown, 13884 test_verify_auth_aes_cmac_cipher_snow_test_case_1), 13885 /** AUTH ZUC + CIPHER AES CTR */ 13886 TEST_CASE_ST(ut_setup, ut_teardown, 13887 test_auth_zuc_cipher_aes_ctr_test_case_1), 13888 TEST_CASE_ST(ut_setup, ut_teardown, 13889 test_verify_auth_zuc_cipher_aes_ctr_test_case_1), 13890 /** AUTH SNOW3G + CIPHER AES CTR */ 13891 TEST_CASE_ST(ut_setup, ut_teardown, 13892 test_auth_snow_cipher_aes_ctr_test_case_1), 13893 TEST_CASE_ST(ut_setup, ut_teardown, 13894 test_verify_auth_snow_cipher_aes_ctr_test_case_1), 13895 /** AUTH SNOW3G + CIPHER ZUC */ 13896 TEST_CASE_ST(ut_setup, ut_teardown, 13897 test_auth_snow_cipher_zuc_test_case_1), 13898 TEST_CASE_ST(ut_setup, ut_teardown, 13899 test_verify_auth_snow_cipher_zuc_test_case_1), 13900 /** AUTH AES CMAC + CIPHER ZUC */ 13901 TEST_CASE_ST(ut_setup, ut_teardown, 13902 test_auth_aes_cmac_cipher_zuc_test_case_1), 13903 TEST_CASE_ST(ut_setup, ut_teardown, 13904 test_verify_auth_aes_cmac_cipher_zuc_test_case_1), 13905 13906 /** AUTH NULL + CIPHER SNOW3G */ 13907 TEST_CASE_ST(ut_setup, ut_teardown, 13908 test_auth_null_cipher_snow_test_case_1), 13909 TEST_CASE_ST(ut_setup, ut_teardown, 13910 test_verify_auth_null_cipher_snow_test_case_1), 13911 /** AUTH NULL + CIPHER ZUC */ 13912 TEST_CASE_ST(ut_setup, ut_teardown, 13913 test_auth_null_cipher_zuc_test_case_1), 13914 TEST_CASE_ST(ut_setup, ut_teardown, 13915 test_verify_auth_null_cipher_zuc_test_case_1), 13916 /** AUTH SNOW3G + CIPHER NULL */ 13917 TEST_CASE_ST(ut_setup, ut_teardown, 13918 test_auth_snow_cipher_null_test_case_1), 13919 TEST_CASE_ST(ut_setup, ut_teardown, 13920 test_verify_auth_snow_cipher_null_test_case_1), 13921 /** AUTH ZUC + CIPHER NULL */ 13922 TEST_CASE_ST(ut_setup, ut_teardown, 13923 test_auth_zuc_cipher_null_test_case_1), 13924 TEST_CASE_ST(ut_setup, ut_teardown, 13925 test_verify_auth_zuc_cipher_null_test_case_1), 13926 /** AUTH NULL + CIPHER AES CTR */ 13927 TEST_CASE_ST(ut_setup, ut_teardown, 13928 test_auth_null_cipher_aes_ctr_test_case_1), 13929 TEST_CASE_ST(ut_setup, ut_teardown, 13930 test_verify_auth_null_cipher_aes_ctr_test_case_1), 13931 /** AUTH AES CMAC + CIPHER NULL */ 13932 TEST_CASE_ST(ut_setup, ut_teardown, 13933 test_auth_aes_cmac_cipher_null_test_case_1), 13934 TEST_CASE_ST(ut_setup, ut_teardown, 13935 test_verify_auth_aes_cmac_cipher_null_test_case_1), 13936 13937 #ifdef RTE_LIB_SECURITY 13938 TEST_CASE_ST(ut_setup_security, ut_teardown, 13939 test_PDCP_PROTO_all), 13940 TEST_CASE_ST(ut_setup_security, ut_teardown, 13941 test_DOCSIS_PROTO_all), 13942 #endif 13943 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup), 13944 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup), 13945 TEST_CASES_END() /**< NULL terminate unit test array */ 13946 } 13947 }; 13948 13949 static struct unit_test_suite cryptodev_virtio_testsuite = { 13950 .suite_name = "Crypto VIRTIO Unit Test Suite", 13951 .setup = testsuite_setup, 13952 .teardown = testsuite_teardown, 13953 .unit_test_cases = { 13954 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13955 13956 TEST_CASES_END() /**< NULL terminate unit test array */ 13957 } 13958 }; 13959 13960 static struct unit_test_suite cryptodev_caam_jr_testsuite = { 13961 .suite_name = "Crypto CAAM JR Unit Test Suite", 13962 .setup = testsuite_setup, 13963 .teardown = testsuite_teardown, 13964 .unit_test_cases = { 13965 TEST_CASE_ST(ut_setup, ut_teardown, 13966 test_device_configure_invalid_dev_id), 13967 TEST_CASE_ST(ut_setup, ut_teardown, 13968 test_multi_session), 13969 13970 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13971 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 13972 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13973 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 13974 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13975 13976 TEST_CASES_END() /**< NULL terminate unit test array */ 13977 } 13978 }; 13979 13980 static struct unit_test_suite cryptodev_mrvl_testsuite = { 13981 .suite_name = "Crypto Device Marvell Component Test Suite", 13982 .setup = testsuite_setup, 13983 .teardown = testsuite_teardown, 13984 .unit_test_cases = { 13985 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 13986 TEST_CASE_ST(ut_setup, ut_teardown, 13987 test_multi_session_random_usage), 13988 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13989 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13990 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13991 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 13992 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 13993 13994 /** Negative tests */ 13995 TEST_CASE_ST(ut_setup, ut_teardown, 13996 authentication_verify_HMAC_SHA1_fail_data_corrupt), 13997 TEST_CASE_ST(ut_setup, ut_teardown, 13998 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 13999 TEST_CASE_ST(ut_setup, ut_teardown, 14000 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 14001 TEST_CASE_ST(ut_setup, ut_teardown, 14002 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 14003 14004 TEST_CASES_END() /**< NULL terminate unit test array */ 14005 } 14006 }; 14007 14008 static struct unit_test_suite cryptodev_ccp_testsuite = { 14009 .suite_name = "Crypto Device CCP Unit Test Suite", 14010 .setup = testsuite_setup, 14011 .teardown = testsuite_teardown, 14012 .unit_test_cases = { 14013 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 14014 TEST_CASE_ST(ut_setup, ut_teardown, 14015 test_multi_session_random_usage), 14016 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 14017 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 14018 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 14019 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 14020 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 14021 14022 /** Negative tests */ 14023 TEST_CASE_ST(ut_setup, ut_teardown, 14024 authentication_verify_HMAC_SHA1_fail_data_corrupt), 14025 TEST_CASE_ST(ut_setup, ut_teardown, 14026 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 14027 TEST_CASE_ST(ut_setup, ut_teardown, 14028 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 14029 TEST_CASE_ST(ut_setup, ut_teardown, 14030 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 14031 14032 TEST_CASES_END() /**< NULL terminate unit test array */ 14033 } 14034 }; 14035 14036 static int 14037 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/) 14038 { 14039 gbl_driver_id = rte_cryptodev_driver_id_get( 14040 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 14041 14042 if (gbl_driver_id == -1) { 14043 RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n"); 14044 return TEST_SKIPPED; 14045 } 14046 14047 return unit_test_suite_runner(&cryptodev_testsuite); 14048 } 14049 14050 static int 14051 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/) 14052 { 14053 gbl_driver_id = rte_cryptodev_driver_id_get( 14054 RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)); 14055 14056 if (gbl_driver_id == -1) { 14057 RTE_LOG(ERR, USER1, "VIRTIO PMD must be loaded.\n"); 14058 return TEST_FAILED; 14059 } 14060 14061 return unit_test_suite_runner(&cryptodev_virtio_testsuite); 14062 } 14063 14064 static int 14065 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/) 14066 { 14067 gbl_driver_id = rte_cryptodev_driver_id_get( 14068 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 14069 14070 if (gbl_driver_id == -1) { 14071 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 14072 return TEST_SKIPPED; 14073 } 14074 14075 return unit_test_suite_runner(&cryptodev_testsuite); 14076 } 14077 14078 static int 14079 test_cryptodev_cpu_aesni_mb(void) 14080 { 14081 int32_t rc; 14082 enum rte_security_session_action_type at; 14083 14084 gbl_driver_id = rte_cryptodev_driver_id_get( 14085 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 14086 14087 if (gbl_driver_id == -1) { 14088 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 14089 return TEST_SKIPPED; 14090 } 14091 14092 at = gbl_action_type; 14093 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 14094 rc = unit_test_suite_runner(&cryptodev_testsuite); 14095 gbl_action_type = at; 14096 return rc; 14097 } 14098 14099 static int 14100 test_cryptodev_openssl(void) 14101 { 14102 gbl_driver_id = rte_cryptodev_driver_id_get( 14103 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 14104 14105 if (gbl_driver_id == -1) { 14106 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded.\n"); 14107 return TEST_SKIPPED; 14108 } 14109 14110 return unit_test_suite_runner(&cryptodev_testsuite); 14111 } 14112 14113 static int 14114 test_cryptodev_aesni_gcm(void) 14115 { 14116 gbl_driver_id = rte_cryptodev_driver_id_get( 14117 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 14118 14119 if (gbl_driver_id == -1) { 14120 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded.\n"); 14121 return TEST_SKIPPED; 14122 } 14123 14124 return unit_test_suite_runner(&cryptodev_testsuite); 14125 } 14126 14127 static int 14128 test_cryptodev_cpu_aesni_gcm(void) 14129 { 14130 int32_t rc; 14131 enum rte_security_session_action_type at; 14132 14133 gbl_driver_id = rte_cryptodev_driver_id_get( 14134 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 14135 14136 if (gbl_driver_id == -1) { 14137 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded.\n"); 14138 return TEST_SKIPPED; 14139 } 14140 14141 at = gbl_action_type; 14142 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 14143 rc = unit_test_suite_runner(&cryptodev_testsuite); 14144 gbl_action_type = at; 14145 return rc; 14146 } 14147 14148 static int 14149 test_cryptodev_null(void) 14150 { 14151 gbl_driver_id = rte_cryptodev_driver_id_get( 14152 RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 14153 14154 if (gbl_driver_id == -1) { 14155 RTE_LOG(ERR, USER1, "NULL PMD must be loaded.\n"); 14156 return TEST_SKIPPED; 14157 } 14158 14159 return unit_test_suite_runner(&cryptodev_testsuite); 14160 } 14161 14162 static int 14163 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/) 14164 { 14165 gbl_driver_id = rte_cryptodev_driver_id_get( 14166 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 14167 14168 if (gbl_driver_id == -1) { 14169 RTE_LOG(ERR, USER1, "SNOW3G PMD must be loaded.\n"); 14170 return TEST_SKIPPED; 14171 } 14172 14173 return unit_test_suite_runner(&cryptodev_testsuite); 14174 } 14175 14176 static int 14177 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/) 14178 { 14179 gbl_driver_id = rte_cryptodev_driver_id_get( 14180 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 14181 14182 if (gbl_driver_id == -1) { 14183 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded.\n"); 14184 return TEST_SKIPPED; 14185 } 14186 14187 return unit_test_suite_runner(&cryptodev_testsuite); 14188 } 14189 14190 static int 14191 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/) 14192 { 14193 gbl_driver_id = rte_cryptodev_driver_id_get( 14194 RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 14195 14196 if (gbl_driver_id == -1) { 14197 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded.\n"); 14198 return TEST_SKIPPED; 14199 } 14200 14201 return unit_test_suite_runner(&cryptodev_testsuite); 14202 } 14203 14204 static int 14205 test_cryptodev_armv8(void) 14206 { 14207 gbl_driver_id = rte_cryptodev_driver_id_get( 14208 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 14209 14210 if (gbl_driver_id == -1) { 14211 RTE_LOG(ERR, USER1, "ARMV8 PMD must be loaded.\n"); 14212 return TEST_SKIPPED; 14213 } 14214 14215 return unit_test_suite_runner(&cryptodev_testsuite); 14216 } 14217 14218 static int 14219 test_cryptodev_mrvl(void) 14220 { 14221 gbl_driver_id = rte_cryptodev_driver_id_get( 14222 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 14223 14224 if (gbl_driver_id == -1) { 14225 RTE_LOG(ERR, USER1, "MVSAM PMD must be loaded.\n"); 14226 return TEST_SKIPPED; 14227 } 14228 14229 return unit_test_suite_runner(&cryptodev_mrvl_testsuite); 14230 } 14231 14232 #ifdef RTE_CRYPTO_SCHEDULER 14233 14234 static int 14235 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/) 14236 { 14237 gbl_driver_id = rte_cryptodev_driver_id_get( 14238 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 14239 14240 if (gbl_driver_id == -1) { 14241 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n"); 14242 return TEST_SKIPPED; 14243 } 14244 14245 if (rte_cryptodev_driver_id_get( 14246 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) { 14247 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 14248 return TEST_SKIPPED; 14249 } 14250 return unit_test_suite_runner(&cryptodev_scheduler_testsuite); 14251 } 14252 14253 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler); 14254 14255 #endif 14256 14257 static int 14258 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/) 14259 { 14260 gbl_driver_id = rte_cryptodev_driver_id_get( 14261 RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 14262 14263 if (gbl_driver_id == -1) { 14264 RTE_LOG(ERR, USER1, "DPAA2 SEC PMD must be loaded.\n"); 14265 return TEST_SKIPPED; 14266 } 14267 14268 return unit_test_suite_runner(&cryptodev_testsuite); 14269 } 14270 14271 static int 14272 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/) 14273 { 14274 gbl_driver_id = rte_cryptodev_driver_id_get( 14275 RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 14276 14277 if (gbl_driver_id == -1) { 14278 RTE_LOG(ERR, USER1, "DPAA SEC PMD must be loaded.\n"); 14279 return TEST_SKIPPED; 14280 } 14281 14282 return unit_test_suite_runner(&cryptodev_testsuite); 14283 } 14284 14285 static int 14286 test_cryptodev_ccp(void) 14287 { 14288 gbl_driver_id = rte_cryptodev_driver_id_get( 14289 RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 14290 14291 if (gbl_driver_id == -1) { 14292 RTE_LOG(ERR, USER1, "CCP PMD must be loaded.\n"); 14293 return TEST_FAILED; 14294 } 14295 14296 return unit_test_suite_runner(&cryptodev_ccp_testsuite); 14297 } 14298 14299 static int 14300 test_cryptodev_octeontx(void) 14301 { 14302 gbl_driver_id = rte_cryptodev_driver_id_get( 14303 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)); 14304 if (gbl_driver_id == -1) { 14305 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded.\n"); 14306 return TEST_FAILED; 14307 } 14308 return unit_test_suite_runner(&cryptodev_testsuite); 14309 } 14310 14311 static int 14312 test_cryptodev_octeontx2(void) 14313 { 14314 gbl_driver_id = rte_cryptodev_driver_id_get( 14315 RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD)); 14316 if (gbl_driver_id == -1) { 14317 RTE_LOG(ERR, USER1, "OCTEON TX2 PMD must be loaded.\n"); 14318 return TEST_FAILED; 14319 } 14320 return unit_test_suite_runner(&cryptodev_testsuite); 14321 } 14322 14323 static int 14324 test_cryptodev_caam_jr(void /*argv __rte_unused, int argc __rte_unused*/) 14325 { 14326 gbl_driver_id = rte_cryptodev_driver_id_get( 14327 RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)); 14328 14329 if (gbl_driver_id == -1) { 14330 RTE_LOG(ERR, USER1, "CAAM_JR PMD must be loaded.\n"); 14331 return TEST_FAILED; 14332 } 14333 14334 return unit_test_suite_runner(&cryptodev_caam_jr_testsuite); 14335 } 14336 14337 static int 14338 test_cryptodev_nitrox(void) 14339 { 14340 gbl_driver_id = rte_cryptodev_driver_id_get( 14341 RTE_STR(CRYPTODEV_NAME_NITROX_PMD)); 14342 14343 if (gbl_driver_id == -1) { 14344 RTE_LOG(ERR, USER1, "NITROX PMD must be loaded.\n"); 14345 return TEST_FAILED; 14346 } 14347 14348 return unit_test_suite_runner(&cryptodev_testsuite); 14349 } 14350 14351 static int 14352 test_cryptodev_bcmfs(void) 14353 { 14354 gbl_driver_id = rte_cryptodev_driver_id_get( 14355 RTE_STR(CRYPTODEV_NAME_BCMFS_PMD)); 14356 14357 if (gbl_driver_id == -1) { 14358 RTE_LOG(ERR, USER1, "BCMFS PMD must be loaded.\n"); 14359 return TEST_FAILED; 14360 } 14361 14362 return unit_test_suite_runner(&cryptodev_testsuite); 14363 } 14364 14365 static int 14366 test_cryptodev_qat_raw_api(void /*argv __rte_unused, int argc __rte_unused*/) 14367 { 14368 int ret; 14369 14370 gbl_driver_id = rte_cryptodev_driver_id_get( 14371 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 14372 14373 if (gbl_driver_id == -1) { 14374 RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n"); 14375 return TEST_SKIPPED; 14376 } 14377 14378 global_api_test_type = CRYPTODEV_RAW_API_TEST; 14379 ret = unit_test_suite_runner(&cryptodev_testsuite); 14380 global_api_test_type = CRYPTODEV_API_TEST; 14381 14382 return ret; 14383 } 14384 14385 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest, 14386 test_cryptodev_qat_raw_api); 14387 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat); 14388 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 14389 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest, 14390 test_cryptodev_cpu_aesni_mb); 14391 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl); 14392 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 14393 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest, 14394 test_cryptodev_cpu_aesni_gcm); 14395 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null); 14396 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 14397 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 14398 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 14399 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8); 14400 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl); 14401 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec); 14402 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec); 14403 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp); 14404 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio); 14405 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx); 14406 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2); 14407 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr); 14408 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox); 14409 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs); 14410