1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2015-2020 Intel Corporation 3 * Copyright 2020 NXP 4 */ 5 6 #include <time.h> 7 8 #include <rte_common.h> 9 #include <rte_hexdump.h> 10 #include <rte_mbuf.h> 11 #include <rte_malloc.h> 12 #include <rte_memcpy.h> 13 #include <rte_pause.h> 14 #include <rte_bus_vdev.h> 15 #include <rte_ether.h> 16 17 #include <rte_crypto.h> 18 #include <rte_cryptodev.h> 19 #include <rte_cryptodev_pmd.h> 20 #include <rte_string_fns.h> 21 22 #ifdef RTE_CRYPTO_SCHEDULER 23 #include <rte_cryptodev_scheduler.h> 24 #include <rte_cryptodev_scheduler_operations.h> 25 #endif 26 27 #include <rte_lcore.h> 28 29 #include "test.h" 30 #include "test_cryptodev.h" 31 32 #include "test_cryptodev_blockcipher.h" 33 #include "test_cryptodev_aes_test_vectors.h" 34 #include "test_cryptodev_des_test_vectors.h" 35 #include "test_cryptodev_hash_test_vectors.h" 36 #include "test_cryptodev_kasumi_test_vectors.h" 37 #include "test_cryptodev_kasumi_hash_test_vectors.h" 38 #include "test_cryptodev_snow3g_test_vectors.h" 39 #include "test_cryptodev_snow3g_hash_test_vectors.h" 40 #include "test_cryptodev_zuc_test_vectors.h" 41 #include "test_cryptodev_aead_test_vectors.h" 42 #include "test_cryptodev_hmac_test_vectors.h" 43 #include "test_cryptodev_mixed_test_vectors.h" 44 #ifdef RTE_LIB_SECURITY 45 #include "test_cryptodev_security_pdcp_test_vectors.h" 46 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h" 47 #include "test_cryptodev_security_pdcp_test_func.h" 48 #include "test_cryptodev_security_docsis_test_vectors.h" 49 50 #define SDAP_DISABLED 0 51 #define SDAP_ENABLED 1 52 #endif 53 54 #define VDEV_ARGS_SIZE 100 55 #define MAX_NB_SESSIONS 4 56 57 #define MAX_DRV_SERVICE_CTX_SIZE 256 58 59 #define MAX_RAW_DEQUEUE_COUNT 65535 60 61 #define IN_PLACE 0 62 #define OUT_OF_PLACE 1 63 64 #ifndef ARRAY_SIZE 65 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 66 #endif 67 68 static int gbl_driver_id; 69 70 static enum rte_security_session_action_type gbl_action_type = 71 RTE_SECURITY_ACTION_TYPE_NONE; 72 73 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST; 74 75 struct crypto_testsuite_params { 76 struct rte_mempool *mbuf_pool; 77 struct rte_mempool *large_mbuf_pool; 78 struct rte_mempool *op_mpool; 79 struct rte_mempool *session_mpool; 80 struct rte_mempool *session_priv_mpool; 81 struct rte_cryptodev_config conf; 82 struct rte_cryptodev_qp_conf qp_conf; 83 84 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS]; 85 uint8_t valid_dev_count; 86 }; 87 88 struct crypto_unittest_params { 89 struct rte_crypto_sym_xform cipher_xform; 90 struct rte_crypto_sym_xform auth_xform; 91 struct rte_crypto_sym_xform aead_xform; 92 #ifdef RTE_LIB_SECURITY 93 struct rte_security_docsis_xform docsis_xform; 94 #endif 95 96 union { 97 struct rte_cryptodev_sym_session *sess; 98 #ifdef RTE_LIB_SECURITY 99 struct rte_security_session *sec_session; 100 #endif 101 }; 102 #ifdef RTE_LIB_SECURITY 103 enum rte_security_session_action_type type; 104 #endif 105 struct rte_crypto_op *op; 106 107 struct rte_mbuf *obuf, *ibuf; 108 109 uint8_t *digest; 110 }; 111 112 #define ALIGN_POW2_ROUNDUP(num, align) \ 113 (((num) + (align) - 1) & ~((align) - 1)) 114 115 /* 116 * Forward declarations. 117 */ 118 static int 119 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 120 struct crypto_unittest_params *ut_params, uint8_t *cipher_key, 121 uint8_t *hmac_key); 122 123 static int 124 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 125 struct crypto_unittest_params *ut_params, 126 struct crypto_testsuite_params *ts_param, 127 const uint8_t *cipher, 128 const uint8_t *digest, 129 const uint8_t *iv); 130 131 static struct rte_mbuf * 132 setup_test_string(struct rte_mempool *mpool, 133 const char *string, size_t len, uint8_t blocksize) 134 { 135 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool); 136 size_t t_len = len - (blocksize ? (len % blocksize) : 0); 137 138 memset(m->buf_addr, 0, m->buf_len); 139 if (m) { 140 char *dst = rte_pktmbuf_append(m, t_len); 141 142 if (!dst) { 143 rte_pktmbuf_free(m); 144 return NULL; 145 } 146 if (string != NULL) 147 rte_memcpy(dst, string, t_len); 148 else 149 memset(dst, 0, t_len); 150 } 151 152 return m; 153 } 154 155 /* Get number of bytes in X bits (rounding up) */ 156 static uint32_t 157 ceil_byte_length(uint32_t num_bits) 158 { 159 if (num_bits % 8) 160 return ((num_bits >> 3) + 1); 161 else 162 return (num_bits >> 3); 163 } 164 165 static uint32_t 166 get_raw_dp_dequeue_count(void *user_data __rte_unused) 167 { 168 return 1; 169 } 170 171 static void 172 post_process_raw_dp_op(void *user_data, uint32_t index __rte_unused, 173 uint8_t is_op_success) 174 { 175 struct rte_crypto_op *op = user_data; 176 op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS : 177 RTE_CRYPTO_OP_STATUS_ERROR; 178 } 179 180 void 181 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id, 182 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth, 183 uint8_t len_in_bits, uint8_t cipher_iv_len) 184 { 185 struct rte_crypto_sym_op *sop = op->sym; 186 struct rte_crypto_op *ret_op = NULL; 187 struct rte_crypto_vec data_vec[UINT8_MAX]; 188 struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv; 189 union rte_crypto_sym_ofs ofs; 190 struct rte_crypto_sym_vec vec; 191 struct rte_crypto_sgl sgl; 192 uint32_t max_len; 193 union rte_cryptodev_session_ctx sess; 194 uint32_t count = 0; 195 struct rte_crypto_raw_dp_ctx *ctx; 196 uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0, 197 auth_len = 0; 198 int32_t n; 199 uint32_t n_success; 200 int ctx_service_size; 201 int32_t status = 0; 202 int enqueue_status, dequeue_status; 203 204 ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id); 205 if (ctx_service_size < 0) { 206 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 207 return; 208 } 209 210 ctx = malloc(ctx_service_size); 211 if (!ctx) { 212 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 213 return; 214 } 215 216 /* Both are enums, setting crypto_sess will suit any session type */ 217 sess.crypto_sess = op->sym->session; 218 219 if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx, 220 op->sess_type, sess, 0) < 0) { 221 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 222 goto exit; 223 } 224 225 cipher_iv.iova = 0; 226 cipher_iv.va = NULL; 227 aad_auth_iv.iova = 0; 228 aad_auth_iv.va = NULL; 229 digest.iova = 0; 230 digest.va = NULL; 231 sgl.vec = data_vec; 232 vec.num = 1; 233 vec.sgl = &sgl; 234 vec.iv = &cipher_iv; 235 vec.digest = &digest; 236 vec.aad = &aad_auth_iv; 237 vec.status = &status; 238 239 ofs.raw = 0; 240 241 if (is_cipher && is_auth) { 242 cipher_offset = sop->cipher.data.offset; 243 cipher_len = sop->cipher.data.length; 244 auth_offset = sop->auth.data.offset; 245 auth_len = sop->auth.data.length; 246 max_len = RTE_MAX(cipher_offset + cipher_len, 247 auth_offset + auth_len); 248 if (len_in_bits) { 249 max_len = max_len >> 3; 250 cipher_offset = cipher_offset >> 3; 251 auth_offset = auth_offset >> 3; 252 cipher_len = cipher_len >> 3; 253 auth_len = auth_len >> 3; 254 } 255 ofs.ofs.cipher.head = cipher_offset; 256 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 257 ofs.ofs.auth.head = auth_offset; 258 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 259 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 260 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 261 aad_auth_iv.va = rte_crypto_op_ctod_offset( 262 op, void *, IV_OFFSET + cipher_iv_len); 263 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 264 cipher_iv_len); 265 digest.va = (void *)sop->auth.digest.data; 266 digest.iova = sop->auth.digest.phys_addr; 267 268 } else if (is_cipher) { 269 cipher_offset = sop->cipher.data.offset; 270 cipher_len = sop->cipher.data.length; 271 max_len = cipher_len + cipher_offset; 272 if (len_in_bits) { 273 max_len = max_len >> 3; 274 cipher_offset = cipher_offset >> 3; 275 cipher_len = cipher_len >> 3; 276 } 277 ofs.ofs.cipher.head = cipher_offset; 278 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 279 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 280 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 281 282 } else if (is_auth) { 283 auth_offset = sop->auth.data.offset; 284 auth_len = sop->auth.data.length; 285 max_len = auth_len + auth_offset; 286 if (len_in_bits) { 287 max_len = max_len >> 3; 288 auth_offset = auth_offset >> 3; 289 auth_len = auth_len >> 3; 290 } 291 ofs.ofs.auth.head = auth_offset; 292 ofs.ofs.auth.tail = max_len - auth_offset - auth_len; 293 aad_auth_iv.va = rte_crypto_op_ctod_offset( 294 op, void *, IV_OFFSET + cipher_iv_len); 295 aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET + 296 cipher_iv_len); 297 digest.va = (void *)sop->auth.digest.data; 298 digest.iova = sop->auth.digest.phys_addr; 299 300 } else { /* aead */ 301 cipher_offset = sop->aead.data.offset; 302 cipher_len = sop->aead.data.length; 303 max_len = cipher_len + cipher_offset; 304 if (len_in_bits) { 305 max_len = max_len >> 3; 306 cipher_offset = cipher_offset >> 3; 307 cipher_len = cipher_len >> 3; 308 } 309 ofs.ofs.cipher.head = cipher_offset; 310 ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len; 311 cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 312 cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET); 313 aad_auth_iv.va = (void *)sop->aead.aad.data; 314 aad_auth_iv.iova = sop->aead.aad.phys_addr; 315 digest.va = (void *)sop->aead.digest.data; 316 digest.iova = sop->aead.digest.phys_addr; 317 } 318 319 n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len, 320 data_vec, RTE_DIM(data_vec)); 321 if (n < 0 || n > sop->m_src->nb_segs) { 322 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 323 goto exit; 324 } 325 326 sgl.num = n; 327 328 if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op, 329 &enqueue_status) < 1) { 330 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 331 goto exit; 332 } 333 334 if (enqueue_status == 0) { 335 status = rte_cryptodev_raw_enqueue_done(ctx, 1); 336 if (status < 0) { 337 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 338 goto exit; 339 } 340 } else if (enqueue_status < 0) { 341 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 342 goto exit; 343 } 344 345 n = n_success = 0; 346 while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) { 347 n = rte_cryptodev_raw_dequeue_burst(ctx, 348 get_raw_dp_dequeue_count, post_process_raw_dp_op, 349 (void **)&ret_op, 0, &n_success, 350 &dequeue_status); 351 if (dequeue_status < 0) { 352 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 353 goto exit; 354 } 355 if (n == 0) 356 rte_pause(); 357 } 358 359 if (n == 1 && dequeue_status == 0) { 360 if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) { 361 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 362 goto exit; 363 } 364 } 365 366 op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op || 367 n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR : 368 RTE_CRYPTO_OP_STATUS_SUCCESS; 369 370 exit: 371 free(ctx); 372 } 373 374 static void 375 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op) 376 { 377 int32_t n, st; 378 struct rte_crypto_sym_op *sop; 379 union rte_crypto_sym_ofs ofs; 380 struct rte_crypto_sgl sgl; 381 struct rte_crypto_sym_vec symvec; 382 struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr; 383 struct rte_crypto_vec vec[UINT8_MAX]; 384 385 sop = op->sym; 386 387 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset, 388 sop->aead.data.length, vec, RTE_DIM(vec)); 389 390 if (n < 0 || n != sop->m_src->nb_segs) { 391 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 392 return; 393 } 394 395 sgl.vec = vec; 396 sgl.num = n; 397 symvec.sgl = &sgl; 398 symvec.iv = &iv_ptr; 399 symvec.digest = &digest_ptr; 400 symvec.aad = &aad_ptr; 401 symvec.status = &st; 402 symvec.num = 1; 403 404 /* for CPU crypto the IOVA address is not required */ 405 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 406 digest_ptr.va = (void *)sop->aead.digest.data; 407 aad_ptr.va = (void *)sop->aead.aad.data; 408 409 ofs.raw = 0; 410 411 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 412 &symvec); 413 414 if (n != 1) 415 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 416 else 417 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 418 } 419 420 static void 421 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op) 422 { 423 int32_t n, st; 424 struct rte_crypto_sym_op *sop; 425 union rte_crypto_sym_ofs ofs; 426 struct rte_crypto_sgl sgl; 427 struct rte_crypto_sym_vec symvec; 428 struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr; 429 struct rte_crypto_vec vec[UINT8_MAX]; 430 431 sop = op->sym; 432 433 n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset, 434 sop->auth.data.length, vec, RTE_DIM(vec)); 435 436 if (n < 0 || n != sop->m_src->nb_segs) { 437 op->status = RTE_CRYPTO_OP_STATUS_ERROR; 438 return; 439 } 440 441 sgl.vec = vec; 442 sgl.num = n; 443 symvec.sgl = &sgl; 444 symvec.iv = &iv_ptr; 445 symvec.digest = &digest_ptr; 446 symvec.status = &st; 447 symvec.num = 1; 448 449 iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET); 450 digest_ptr.va = (void *)sop->auth.digest.data; 451 452 ofs.raw = 0; 453 ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset; 454 ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) - 455 (sop->cipher.data.offset + sop->cipher.data.length); 456 457 n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs, 458 &symvec); 459 460 if (n != 1) 461 op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 462 else 463 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 464 } 465 466 static struct rte_crypto_op * 467 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op) 468 { 469 470 RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO); 471 472 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 473 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n"); 474 return NULL; 475 } 476 477 op = NULL; 478 479 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) 480 rte_pause(); 481 482 if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 483 RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status); 484 return NULL; 485 } 486 487 return op; 488 } 489 490 static struct crypto_testsuite_params testsuite_params = { NULL }; 491 static struct crypto_unittest_params unittest_params; 492 493 static int 494 testsuite_setup(void) 495 { 496 struct crypto_testsuite_params *ts_params = &testsuite_params; 497 struct rte_cryptodev_info info; 498 uint32_t i = 0, nb_devs, dev_id; 499 int ret; 500 uint16_t qp_id; 501 502 memset(ts_params, 0, sizeof(*ts_params)); 503 504 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL"); 505 if (ts_params->mbuf_pool == NULL) { 506 /* Not already created so create */ 507 ts_params->mbuf_pool = rte_pktmbuf_pool_create( 508 "CRYPTO_MBUFPOOL", 509 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE, 510 rte_socket_id()); 511 if (ts_params->mbuf_pool == NULL) { 512 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n"); 513 return TEST_FAILED; 514 } 515 } 516 517 ts_params->large_mbuf_pool = rte_mempool_lookup( 518 "CRYPTO_LARGE_MBUFPOOL"); 519 if (ts_params->large_mbuf_pool == NULL) { 520 /* Not already created so create */ 521 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create( 522 "CRYPTO_LARGE_MBUFPOOL", 523 1, 0, 0, UINT16_MAX, 524 rte_socket_id()); 525 if (ts_params->large_mbuf_pool == NULL) { 526 RTE_LOG(ERR, USER1, 527 "Can't create CRYPTO_LARGE_MBUFPOOL\n"); 528 return TEST_FAILED; 529 } 530 } 531 532 ts_params->op_mpool = rte_crypto_op_pool_create( 533 "MBUF_CRYPTO_SYM_OP_POOL", 534 RTE_CRYPTO_OP_TYPE_SYMMETRIC, 535 NUM_MBUFS, MBUF_CACHE_SIZE, 536 DEFAULT_NUM_XFORMS * 537 sizeof(struct rte_crypto_sym_xform) + 538 MAXIMUM_IV_LENGTH, 539 rte_socket_id()); 540 if (ts_params->op_mpool == NULL) { 541 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n"); 542 return TEST_FAILED; 543 } 544 545 /* Create an AESNI MB device if required */ 546 if (gbl_driver_id == rte_cryptodev_driver_id_get( 547 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) { 548 nb_devs = rte_cryptodev_device_count_by_driver( 549 rte_cryptodev_driver_id_get( 550 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))); 551 if (nb_devs < 1) { 552 ret = rte_vdev_init( 553 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL); 554 555 TEST_ASSERT(ret == 0, 556 "Failed to create instance of" 557 " pmd : %s", 558 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 559 } 560 } 561 562 /* Create an AESNI GCM device if required */ 563 if (gbl_driver_id == rte_cryptodev_driver_id_get( 564 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))) { 565 nb_devs = rte_cryptodev_device_count_by_driver( 566 rte_cryptodev_driver_id_get( 567 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))); 568 if (nb_devs < 1) { 569 TEST_ASSERT_SUCCESS(rte_vdev_init( 570 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL), 571 "Failed to create instance of" 572 " pmd : %s", 573 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 574 } 575 } 576 577 /* Create a SNOW 3G device if required */ 578 if (gbl_driver_id == rte_cryptodev_driver_id_get( 579 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD))) { 580 nb_devs = rte_cryptodev_device_count_by_driver( 581 rte_cryptodev_driver_id_get( 582 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD))); 583 if (nb_devs < 1) { 584 TEST_ASSERT_SUCCESS(rte_vdev_init( 585 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL), 586 "Failed to create instance of" 587 " pmd : %s", 588 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 589 } 590 } 591 592 /* Create a KASUMI device if required */ 593 if (gbl_driver_id == rte_cryptodev_driver_id_get( 594 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD))) { 595 nb_devs = rte_cryptodev_device_count_by_driver( 596 rte_cryptodev_driver_id_get( 597 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD))); 598 if (nb_devs < 1) { 599 TEST_ASSERT_SUCCESS(rte_vdev_init( 600 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL), 601 "Failed to create instance of" 602 " pmd : %s", 603 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 604 } 605 } 606 607 /* Create a ZUC device if required */ 608 if (gbl_driver_id == rte_cryptodev_driver_id_get( 609 RTE_STR(CRYPTODEV_NAME_ZUC_PMD))) { 610 nb_devs = rte_cryptodev_device_count_by_driver( 611 rte_cryptodev_driver_id_get( 612 RTE_STR(CRYPTODEV_NAME_ZUC_PMD))); 613 if (nb_devs < 1) { 614 TEST_ASSERT_SUCCESS(rte_vdev_init( 615 RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL), 616 "Failed to create instance of" 617 " pmd : %s", 618 RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 619 } 620 } 621 622 /* Create a NULL device if required */ 623 if (gbl_driver_id == rte_cryptodev_driver_id_get( 624 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) { 625 nb_devs = rte_cryptodev_device_count_by_driver( 626 rte_cryptodev_driver_id_get( 627 RTE_STR(CRYPTODEV_NAME_NULL_PMD))); 628 if (nb_devs < 1) { 629 ret = rte_vdev_init( 630 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL); 631 632 TEST_ASSERT(ret == 0, 633 "Failed to create instance of" 634 " pmd : %s", 635 RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 636 } 637 } 638 639 /* Create an OPENSSL device if required */ 640 if (gbl_driver_id == rte_cryptodev_driver_id_get( 641 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) { 642 nb_devs = rte_cryptodev_device_count_by_driver( 643 rte_cryptodev_driver_id_get( 644 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))); 645 if (nb_devs < 1) { 646 ret = rte_vdev_init( 647 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD), 648 NULL); 649 650 TEST_ASSERT(ret == 0, "Failed to create " 651 "instance of pmd : %s", 652 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 653 } 654 } 655 656 /* Create a ARMv8 device if required */ 657 if (gbl_driver_id == rte_cryptodev_driver_id_get( 658 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD))) { 659 nb_devs = rte_cryptodev_device_count_by_driver( 660 rte_cryptodev_driver_id_get( 661 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD))); 662 if (nb_devs < 1) { 663 ret = rte_vdev_init( 664 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD), 665 NULL); 666 667 TEST_ASSERT(ret == 0, "Failed to create " 668 "instance of pmd : %s", 669 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 670 } 671 } 672 673 /* Create a MVSAM device if required */ 674 if (gbl_driver_id == rte_cryptodev_driver_id_get( 675 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD))) { 676 nb_devs = rte_cryptodev_device_count_by_driver( 677 rte_cryptodev_driver_id_get( 678 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD))); 679 if (nb_devs < 1) { 680 ret = rte_vdev_init( 681 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD), 682 NULL); 683 684 TEST_ASSERT(ret == 0, "Failed to create " 685 "instance of pmd : %s", 686 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 687 } 688 } 689 690 /* Create an CCP device if required */ 691 if (gbl_driver_id == rte_cryptodev_driver_id_get( 692 RTE_STR(CRYPTODEV_NAME_CCP_PMD))) { 693 nb_devs = rte_cryptodev_device_count_by_driver( 694 rte_cryptodev_driver_id_get( 695 RTE_STR(CRYPTODEV_NAME_CCP_PMD))); 696 if (nb_devs < 1) { 697 ret = rte_vdev_init( 698 RTE_STR(CRYPTODEV_NAME_CCP_PMD), 699 NULL); 700 701 TEST_ASSERT(ret == 0, "Failed to create " 702 "instance of pmd : %s", 703 RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 704 } 705 } 706 707 #ifdef RTE_CRYPTO_SCHEDULER 708 char vdev_args[VDEV_ARGS_SIZE] = {""}; 709 char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core," 710 "ordering=enable,name=cryptodev_test_scheduler,corelist="}; 711 uint16_t worker_core_count = 0; 712 uint16_t socket_id = 0; 713 714 if (gbl_driver_id == rte_cryptodev_driver_id_get( 715 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) { 716 717 /* Identify the Worker Cores 718 * Use 2 worker cores for the device args 719 */ 720 RTE_LCORE_FOREACH_WORKER(i) { 721 if (worker_core_count > 1) 722 break; 723 snprintf(vdev_args, sizeof(vdev_args), 724 "%s%d", temp_str, i); 725 strcpy(temp_str, vdev_args); 726 strlcat(temp_str, ";", sizeof(temp_str)); 727 worker_core_count++; 728 socket_id = rte_lcore_to_socket_id(i); 729 } 730 if (worker_core_count != 2) { 731 RTE_LOG(ERR, USER1, 732 "Cryptodev scheduler test require at least " 733 "two worker cores to run. " 734 "Please use the correct coremask.\n"); 735 return TEST_FAILED; 736 } 737 strcpy(temp_str, vdev_args); 738 snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d", 739 temp_str, socket_id); 740 RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args); 741 nb_devs = rte_cryptodev_device_count_by_driver( 742 rte_cryptodev_driver_id_get( 743 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))); 744 if (nb_devs < 1) { 745 ret = rte_vdev_init( 746 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD), 747 vdev_args); 748 TEST_ASSERT(ret == 0, 749 "Failed to create instance %u of" 750 " pmd : %s", 751 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 752 } 753 } 754 #endif /* RTE_CRYPTO_SCHEDULER */ 755 756 nb_devs = rte_cryptodev_count(); 757 if (nb_devs < 1) { 758 RTE_LOG(WARNING, USER1, "No crypto devices found?\n"); 759 return TEST_SKIPPED; 760 } 761 762 /* Create list of valid crypto devs */ 763 for (i = 0; i < nb_devs; i++) { 764 rte_cryptodev_info_get(i, &info); 765 if (info.driver_id == gbl_driver_id) 766 ts_params->valid_devs[ts_params->valid_dev_count++] = i; 767 } 768 769 if (ts_params->valid_dev_count < 1) 770 return TEST_FAILED; 771 772 /* Set up all the qps on the first of the valid devices found */ 773 774 dev_id = ts_params->valid_devs[0]; 775 776 rte_cryptodev_info_get(dev_id, &info); 777 778 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; 779 ts_params->conf.socket_id = SOCKET_ID_ANY; 780 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY; 781 782 unsigned int session_size = 783 rte_cryptodev_sym_get_private_session_size(dev_id); 784 785 #ifdef RTE_LIB_SECURITY 786 unsigned int security_session_size = rte_security_session_get_size( 787 rte_cryptodev_get_sec_ctx(dev_id)); 788 789 if (session_size < security_session_size) 790 session_size = security_session_size; 791 #endif 792 /* 793 * Create mempool with maximum number of sessions. 794 */ 795 if (info.sym.max_nb_sessions != 0 && 796 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 797 RTE_LOG(ERR, USER1, "Device does not support " 798 "at least %u sessions\n", 799 MAX_NB_SESSIONS); 800 return TEST_FAILED; 801 } 802 803 ts_params->session_mpool = rte_cryptodev_sym_session_pool_create( 804 "test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0, 805 SOCKET_ID_ANY); 806 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 807 "session mempool allocation failed"); 808 809 ts_params->session_priv_mpool = rte_mempool_create( 810 "test_sess_mp_priv", 811 MAX_NB_SESSIONS, 812 session_size, 813 0, 0, NULL, NULL, NULL, 814 NULL, SOCKET_ID_ANY, 815 0); 816 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 817 "session mempool allocation failed"); 818 819 820 821 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, 822 &ts_params->conf), 823 "Failed to configure cryptodev %u with %u qps", 824 dev_id, ts_params->conf.nb_queue_pairs); 825 826 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 827 ts_params->qp_conf.mp_session = ts_params->session_mpool; 828 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 829 830 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 831 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 832 dev_id, qp_id, &ts_params->qp_conf, 833 rte_cryptodev_socket_id(dev_id)), 834 "Failed to setup queue pair %u on cryptodev %u", 835 qp_id, dev_id); 836 } 837 838 return TEST_SUCCESS; 839 } 840 841 static void 842 testsuite_teardown(void) 843 { 844 struct crypto_testsuite_params *ts_params = &testsuite_params; 845 int res; 846 847 if (ts_params->mbuf_pool != NULL) { 848 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 849 rte_mempool_avail_count(ts_params->mbuf_pool)); 850 } 851 852 if (ts_params->op_mpool != NULL) { 853 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", 854 rte_mempool_avail_count(ts_params->op_mpool)); 855 } 856 857 /* Free session mempools */ 858 if (ts_params->session_priv_mpool != NULL) { 859 rte_mempool_free(ts_params->session_priv_mpool); 860 ts_params->session_priv_mpool = NULL; 861 } 862 863 if (ts_params->session_mpool != NULL) { 864 rte_mempool_free(ts_params->session_mpool); 865 ts_params->session_mpool = NULL; 866 } 867 868 res = rte_cryptodev_close(ts_params->valid_devs[0]); 869 if (res) 870 RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res); 871 } 872 873 static int 874 dev_configure_and_start(uint64_t ff_disable) 875 { 876 struct crypto_testsuite_params *ts_params = &testsuite_params; 877 struct crypto_unittest_params *ut_params = &unittest_params; 878 879 uint16_t qp_id; 880 881 /* Clear unit test parameters before running test */ 882 memset(ut_params, 0, sizeof(*ut_params)); 883 884 /* Reconfigure device to default parameters */ 885 ts_params->conf.socket_id = SOCKET_ID_ANY; 886 ts_params->conf.ff_disable = ff_disable; 887 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 888 ts_params->qp_conf.mp_session = ts_params->session_mpool; 889 ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool; 890 891 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 892 &ts_params->conf), 893 "Failed to configure cryptodev %u", 894 ts_params->valid_devs[0]); 895 896 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { 897 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 898 ts_params->valid_devs[0], qp_id, 899 &ts_params->qp_conf, 900 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 901 "Failed to setup queue pair %u on cryptodev %u", 902 qp_id, ts_params->valid_devs[0]); 903 } 904 905 906 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 907 908 /* Start the device */ 909 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 910 "Failed to start cryptodev %u", 911 ts_params->valid_devs[0]); 912 913 return TEST_SUCCESS; 914 } 915 916 static int 917 ut_setup(void) 918 { 919 /* Configure and start the device with security feature disabled */ 920 return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY); 921 } 922 923 static int 924 ut_setup_security(void) 925 { 926 /* Configure and start the device with no features disabled */ 927 return dev_configure_and_start(0); 928 } 929 930 static void 931 ut_teardown(void) 932 { 933 struct crypto_testsuite_params *ts_params = &testsuite_params; 934 struct crypto_unittest_params *ut_params = &unittest_params; 935 struct rte_cryptodev_stats stats; 936 937 /* free crypto session structure */ 938 #ifdef RTE_LIB_SECURITY 939 if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) { 940 if (ut_params->sec_session) { 941 rte_security_session_destroy(rte_cryptodev_get_sec_ctx 942 (ts_params->valid_devs[0]), 943 ut_params->sec_session); 944 ut_params->sec_session = NULL; 945 } 946 } else 947 #endif 948 { 949 if (ut_params->sess) { 950 rte_cryptodev_sym_session_clear( 951 ts_params->valid_devs[0], 952 ut_params->sess); 953 rte_cryptodev_sym_session_free(ut_params->sess); 954 ut_params->sess = NULL; 955 } 956 } 957 958 /* free crypto operation structure */ 959 if (ut_params->op) 960 rte_crypto_op_free(ut_params->op); 961 962 /* 963 * free mbuf - both obuf and ibuf are usually the same, 964 * so check if they point at the same address is necessary, 965 * to avoid freeing the mbuf twice. 966 */ 967 if (ut_params->obuf) { 968 rte_pktmbuf_free(ut_params->obuf); 969 if (ut_params->ibuf == ut_params->obuf) 970 ut_params->ibuf = 0; 971 ut_params->obuf = 0; 972 } 973 if (ut_params->ibuf) { 974 rte_pktmbuf_free(ut_params->ibuf); 975 ut_params->ibuf = 0; 976 } 977 978 if (ts_params->mbuf_pool != NULL) 979 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n", 980 rte_mempool_avail_count(ts_params->mbuf_pool)); 981 982 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats); 983 984 /* Stop the device */ 985 rte_cryptodev_stop(ts_params->valid_devs[0]); 986 } 987 988 static int 989 test_device_configure_invalid_dev_id(void) 990 { 991 struct crypto_testsuite_params *ts_params = &testsuite_params; 992 uint16_t dev_id, num_devs = 0; 993 994 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1, 995 "Need at least %d devices for test", 1); 996 997 /* valid dev_id values */ 998 dev_id = ts_params->valid_devs[0]; 999 1000 /* Stop the device in case it's started so it can be configured */ 1001 rte_cryptodev_stop(dev_id); 1002 1003 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf), 1004 "Failed test for rte_cryptodev_configure: " 1005 "invalid dev_num %u", dev_id); 1006 1007 /* invalid dev_id values */ 1008 dev_id = num_devs; 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 dev_id = 0xff; 1015 1016 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf), 1017 "Failed test for rte_cryptodev_configure:" 1018 "invalid dev_num %u", dev_id); 1019 1020 return TEST_SUCCESS; 1021 } 1022 1023 static int 1024 test_device_configure_invalid_queue_pair_ids(void) 1025 { 1026 struct crypto_testsuite_params *ts_params = &testsuite_params; 1027 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs; 1028 1029 /* Stop the device in case it's started so it can be configured */ 1030 rte_cryptodev_stop(ts_params->valid_devs[0]); 1031 1032 /* valid - max value queue pairs */ 1033 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1034 1035 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1036 &ts_params->conf), 1037 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1038 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs); 1039 1040 /* valid - one queue pairs */ 1041 ts_params->conf.nb_queue_pairs = 1; 1042 1043 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1044 &ts_params->conf), 1045 "Failed to configure cryptodev: dev_id %u, qp_id %u", 1046 ts_params->valid_devs[0], 1047 ts_params->conf.nb_queue_pairs); 1048 1049 1050 /* invalid - zero queue pairs */ 1051 ts_params->conf.nb_queue_pairs = 0; 1052 1053 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1054 &ts_params->conf), 1055 "Failed test for rte_cryptodev_configure, dev_id %u," 1056 " invalid qps: %u", 1057 ts_params->valid_devs[0], 1058 ts_params->conf.nb_queue_pairs); 1059 1060 1061 /* invalid - max value supported by field queue pairs */ 1062 ts_params->conf.nb_queue_pairs = UINT16_MAX; 1063 1064 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1065 &ts_params->conf), 1066 "Failed test for rte_cryptodev_configure, dev_id %u," 1067 " invalid qps: %u", 1068 ts_params->valid_devs[0], 1069 ts_params->conf.nb_queue_pairs); 1070 1071 1072 /* invalid - max value + 1 queue pairs */ 1073 ts_params->conf.nb_queue_pairs = orig_nb_qps + 1; 1074 1075 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0], 1076 &ts_params->conf), 1077 "Failed test for rte_cryptodev_configure, dev_id %u," 1078 " invalid qps: %u", 1079 ts_params->valid_devs[0], 1080 ts_params->conf.nb_queue_pairs); 1081 1082 /* revert to original testsuite value */ 1083 ts_params->conf.nb_queue_pairs = orig_nb_qps; 1084 1085 return TEST_SUCCESS; 1086 } 1087 1088 static int 1089 test_queue_pair_descriptor_setup(void) 1090 { 1091 struct crypto_testsuite_params *ts_params = &testsuite_params; 1092 struct rte_cryptodev_qp_conf qp_conf = { 1093 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 1094 }; 1095 uint16_t qp_id; 1096 1097 /* Stop the device in case it's started so it can be configured */ 1098 rte_cryptodev_stop(ts_params->valid_devs[0]); 1099 1100 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 1101 &ts_params->conf), 1102 "Failed to configure cryptodev %u", 1103 ts_params->valid_devs[0]); 1104 1105 /* 1106 * Test various ring sizes on this device. memzones can't be 1107 * freed so are re-used if ring is released and re-created. 1108 */ 1109 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/ 1110 qp_conf.mp_session = ts_params->session_mpool; 1111 qp_conf.mp_session_private = ts_params->session_priv_mpool; 1112 1113 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1114 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1115 ts_params->valid_devs[0], qp_id, &qp_conf, 1116 rte_cryptodev_socket_id( 1117 ts_params->valid_devs[0])), 1118 "Failed test for " 1119 "rte_cryptodev_queue_pair_setup: num_inflights " 1120 "%u on qp %u on cryptodev %u", 1121 qp_conf.nb_descriptors, qp_id, 1122 ts_params->valid_devs[0]); 1123 } 1124 1125 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2); 1126 1127 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1128 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1129 ts_params->valid_devs[0], qp_id, &qp_conf, 1130 rte_cryptodev_socket_id( 1131 ts_params->valid_devs[0])), 1132 "Failed test for" 1133 " rte_cryptodev_queue_pair_setup: num_inflights" 1134 " %u on qp %u on cryptodev %u", 1135 qp_conf.nb_descriptors, qp_id, 1136 ts_params->valid_devs[0]); 1137 } 1138 1139 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */ 1140 1141 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1142 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1143 ts_params->valid_devs[0], qp_id, &qp_conf, 1144 rte_cryptodev_socket_id( 1145 ts_params->valid_devs[0])), 1146 "Failed test for " 1147 "rte_cryptodev_queue_pair_setup: num_inflights" 1148 " %u on qp %u on cryptodev %u", 1149 qp_conf.nb_descriptors, qp_id, 1150 ts_params->valid_devs[0]); 1151 } 1152 1153 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 1154 1155 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) { 1156 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 1157 ts_params->valid_devs[0], qp_id, &qp_conf, 1158 rte_cryptodev_socket_id( 1159 ts_params->valid_devs[0])), 1160 "Failed test for" 1161 " rte_cryptodev_queue_pair_setup:" 1162 "num_inflights %u on qp %u on cryptodev %u", 1163 qp_conf.nb_descriptors, qp_id, 1164 ts_params->valid_devs[0]); 1165 } 1166 1167 /* test invalid queue pair id */ 1168 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */ 1169 1170 qp_id = ts_params->conf.nb_queue_pairs; /*invalid */ 1171 1172 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1173 ts_params->valid_devs[0], 1174 qp_id, &qp_conf, 1175 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1176 "Failed test for rte_cryptodev_queue_pair_setup:" 1177 "invalid qp %u on cryptodev %u", 1178 qp_id, ts_params->valid_devs[0]); 1179 1180 qp_id = 0xffff; /*invalid*/ 1181 1182 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup( 1183 ts_params->valid_devs[0], 1184 qp_id, &qp_conf, 1185 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 1186 "Failed test for rte_cryptodev_queue_pair_setup:" 1187 "invalid qp %u on cryptodev %u", 1188 qp_id, ts_params->valid_devs[0]); 1189 1190 return TEST_SUCCESS; 1191 } 1192 1193 /* ***** Plaintext data for tests ***** */ 1194 1195 const char catch_22_quote_1[] = 1196 "There was only one catch and that was Catch-22, which " 1197 "specified that a concern for one's safety in the face of " 1198 "dangers that were real and immediate was the process of a " 1199 "rational mind. Orr was crazy and could be grounded. All he " 1200 "had to do was ask; and as soon as he did, he would no longer " 1201 "be crazy and would have to fly more missions. Orr would be " 1202 "crazy to fly more missions and sane if he didn't, but if he " 1203 "was sane he had to fly them. If he flew them he was crazy " 1204 "and didn't have to; but if he didn't want to he was sane and " 1205 "had to. Yossarian was moved very deeply by the absolute " 1206 "simplicity of this clause of Catch-22 and let out a " 1207 "respectful whistle. \"That's some catch, that Catch-22\", he " 1208 "observed. \"It's the best there is,\" Doc Daneeka agreed."; 1209 1210 const char catch_22_quote[] = 1211 "What a lousy earth! He wondered how many people were " 1212 "destitute that same night even in his own prosperous country, " 1213 "how many homes were shanties, how many husbands were drunk " 1214 "and wives socked, and how many children were bullied, abused, " 1215 "or abandoned. How many families hungered for food they could " 1216 "not afford to buy? How many hearts were broken? How many " 1217 "suicides would take place that same night, how many people " 1218 "would go insane? How many cockroaches and landlords would " 1219 "triumph? How many winners were losers, successes failures, " 1220 "and rich men poor men? How many wise guys were stupid? How " 1221 "many happy endings were unhappy endings? How many honest men " 1222 "were liars, brave men cowards, loyal men traitors, how many " 1223 "sainted men were corrupt, how many people in positions of " 1224 "trust had sold their souls to bodyguards, how many had never " 1225 "had souls? How many straight-and-narrow paths were crooked " 1226 "paths? How many best families were worst families and how " 1227 "many good people were bad people? When you added them all up " 1228 "and then subtracted, you might be left with only the children, " 1229 "and perhaps with Albert Einstein and an old violinist or " 1230 "sculptor somewhere."; 1231 1232 #define QUOTE_480_BYTES (480) 1233 #define QUOTE_512_BYTES (512) 1234 #define QUOTE_768_BYTES (768) 1235 #define QUOTE_1024_BYTES (1024) 1236 1237 1238 1239 /* ***** SHA1 Hash Tests ***** */ 1240 1241 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1) 1242 1243 static uint8_t hmac_sha1_key[] = { 1244 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 1245 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 1246 0xDE, 0xF4, 0xDE, 0xAD }; 1247 1248 /* ***** SHA224 Hash Tests ***** */ 1249 1250 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224) 1251 1252 1253 /* ***** AES-CBC Cipher Tests ***** */ 1254 1255 #define CIPHER_KEY_LENGTH_AES_CBC (16) 1256 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC) 1257 1258 static uint8_t aes_cbc_key[] = { 1259 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 1260 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A }; 1261 1262 static uint8_t aes_cbc_iv[] = { 1263 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 1264 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; 1265 1266 1267 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */ 1268 1269 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = { 1270 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31, 1271 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76, 1272 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E, 1273 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A, 1274 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E, 1275 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08, 1276 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0, 1277 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01, 1278 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57, 1279 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE, 1280 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9, 1281 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9, 1282 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D, 1283 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3, 1284 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46, 1285 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3, 1286 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80, 1287 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92, 1288 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5, 1289 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5, 1290 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2, 1291 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5, 1292 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1293 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76, 1294 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4, 1295 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62, 1296 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4, 1297 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4, 1298 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54, 1299 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61, 1300 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91, 1301 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A, 1302 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF, 1303 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F, 1304 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28, 1305 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E, 1306 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7, 1307 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76, 1308 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6, 1309 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03, 1310 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C, 1311 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2, 1312 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6, 1313 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96, 1314 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6, 1315 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA, 1316 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87, 1317 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55, 1318 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B, 1319 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98, 1320 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53, 1321 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A, 1322 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26, 1323 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36, 1324 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36, 1325 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D, 1326 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E, 1327 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E, 1328 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A, 1329 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6, 1330 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4, 1331 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7, 1332 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1, 1333 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C 1334 }; 1335 1336 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = { 1337 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60, 1338 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1339 0x18, 0x8c, 0x1d, 0x32 1340 }; 1341 1342 1343 /* Multisession Vector context Test */ 1344 /*Begin Session 0 */ 1345 static uint8_t ms_aes_cbc_key0[] = { 1346 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1347 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1348 }; 1349 1350 static uint8_t ms_aes_cbc_iv0[] = { 1351 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1352 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1353 }; 1354 1355 static const uint8_t ms_aes_cbc_cipher0[] = { 1356 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38, 1357 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC, 1358 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB, 1359 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9, 1360 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D, 1361 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4, 1362 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34, 1363 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F, 1364 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99, 1365 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED, 1366 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D, 1367 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24, 1368 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71, 1369 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72, 1370 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E, 1371 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD, 1372 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18, 1373 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6, 1374 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29, 1375 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C, 1376 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96, 1377 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26, 1378 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55, 1379 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46, 1380 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B, 1381 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4, 1382 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7, 1383 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5, 1384 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0, 1385 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E, 1386 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D, 1387 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44, 1388 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76, 1389 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3, 1390 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83, 1391 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85, 1392 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45, 1393 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25, 1394 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A, 1395 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1, 1396 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA, 1397 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3, 1398 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4, 1399 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60, 1400 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A, 1401 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A, 1402 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9, 1403 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55, 1404 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13, 1405 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B, 1406 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1, 1407 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0, 1408 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3, 1409 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23, 1410 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B, 1411 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07, 1412 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB, 1413 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1, 1414 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F, 1415 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F, 1416 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84, 1417 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B, 1418 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17, 1419 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF 1420 }; 1421 1422 1423 static uint8_t ms_hmac_key0[] = { 1424 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1425 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1426 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1427 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1428 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1429 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1430 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1431 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1432 }; 1433 1434 static const uint8_t ms_hmac_digest0[] = { 1435 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51, 1436 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F, 1437 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C, 1438 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4, 1439 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56, 1440 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4, 1441 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23, 1442 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90 1443 }; 1444 1445 /* End Session 0 */ 1446 /* Begin session 1 */ 1447 1448 static uint8_t ms_aes_cbc_key1[] = { 1449 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1450 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1451 }; 1452 1453 static uint8_t ms_aes_cbc_iv1[] = { 1454 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1455 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1456 }; 1457 1458 static const uint8_t ms_aes_cbc_cipher1[] = { 1459 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71, 1460 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23, 1461 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09, 1462 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A, 1463 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C, 1464 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F, 1465 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9, 1466 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66, 1467 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43, 1468 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB, 1469 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23, 1470 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29, 1471 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26, 1472 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F, 1473 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68, 1474 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77, 1475 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8, 1476 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97, 1477 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3, 1478 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90, 1479 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5, 1480 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E, 1481 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45, 1482 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B, 1483 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5, 1484 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D, 1485 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E, 1486 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD, 1487 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE, 1488 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1, 1489 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F, 1490 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25, 1491 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1, 1492 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3, 1493 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE, 1494 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6, 1495 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52, 1496 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA, 1497 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63, 1498 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E, 1499 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA, 1500 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB, 1501 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71, 1502 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF, 1503 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A, 1504 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95, 1505 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73, 1506 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49, 1507 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB, 1508 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B, 1509 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC, 1510 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED, 1511 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02, 1512 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4, 1513 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF, 1514 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82, 1515 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D, 1516 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6, 1517 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9, 1518 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35, 1519 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0, 1520 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53, 1521 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5, 1522 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3 1523 1524 }; 1525 1526 static uint8_t ms_hmac_key1[] = { 1527 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1528 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1529 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1530 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1531 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1532 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1533 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1534 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1535 }; 1536 1537 static const uint8_t ms_hmac_digest1[] = { 1538 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69, 1539 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50, 1540 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20, 1541 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD, 1542 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9, 1543 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4, 1544 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA, 1545 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F 1546 }; 1547 /* End Session 1 */ 1548 /* Begin Session 2 */ 1549 static uint8_t ms_aes_cbc_key2[] = { 1550 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1551 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1552 }; 1553 1554 static uint8_t ms_aes_cbc_iv2[] = { 1555 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 1556 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 1557 }; 1558 1559 static const uint8_t ms_aes_cbc_cipher2[] = { 1560 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91, 1561 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97, 1562 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8, 1563 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5, 1564 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98, 1565 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69, 1566 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09, 1567 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF, 1568 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44, 1569 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B, 1570 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9, 1571 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34, 1572 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99, 1573 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF, 1574 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC, 1575 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26, 1576 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3, 1577 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF, 1578 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3, 1579 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3, 1580 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA, 1581 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13, 1582 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38, 1583 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71, 1584 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC, 1585 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1, 1586 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E, 1587 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22, 1588 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62, 1589 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72, 1590 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6, 1591 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6, 1592 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44, 1593 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24, 1594 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5, 1595 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E, 1596 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17, 1597 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9, 1598 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D, 1599 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D, 1600 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22, 1601 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9, 1602 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49, 1603 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E, 1604 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B, 1605 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2, 1606 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95, 1607 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07, 1608 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3, 1609 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A, 1610 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57, 1611 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84, 1612 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61, 1613 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF, 1614 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17, 1615 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A, 1616 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1, 1617 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53, 1618 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7, 1619 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2, 1620 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A, 1621 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8, 1622 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70, 1623 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92 1624 }; 1625 1626 static uint8_t ms_hmac_key2[] = { 1627 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 1628 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1629 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1630 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60, 1631 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1, 1632 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1633 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76, 1634 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60 1635 }; 1636 1637 static const uint8_t ms_hmac_digest2[] = { 1638 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF, 1639 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6, 1640 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77, 1641 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27, 1642 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82, 1643 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24, 1644 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E, 1645 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59 1646 }; 1647 1648 /* End Session 2 */ 1649 1650 1651 static int 1652 test_AES_CBC_HMAC_SHA1_encrypt_digest(void) 1653 { 1654 struct crypto_testsuite_params *ts_params = &testsuite_params; 1655 struct crypto_unittest_params *ut_params = &unittest_params; 1656 1657 /* Verify the capabilities */ 1658 struct rte_cryptodev_sym_capability_idx cap_idx; 1659 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1660 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 1661 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 1662 &cap_idx) == NULL) 1663 return -ENOTSUP; 1664 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1665 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 1666 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 1667 &cap_idx) == NULL) 1668 return -ENOTSUP; 1669 1670 /* Generate test mbuf data and space for digest */ 1671 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 1672 catch_22_quote, QUOTE_512_BYTES, 0); 1673 1674 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 1675 DIGEST_BYTE_LENGTH_SHA1); 1676 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 1677 1678 /* Setup Cipher Parameters */ 1679 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1680 ut_params->cipher_xform.next = &ut_params->auth_xform; 1681 1682 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 1683 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 1684 ut_params->cipher_xform.cipher.key.data = aes_cbc_key; 1685 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 1686 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 1687 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 1688 1689 /* Setup HMAC Parameters */ 1690 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1691 1692 ut_params->auth_xform.next = NULL; 1693 1694 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 1695 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 1696 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; 1697 ut_params->auth_xform.auth.key.data = hmac_sha1_key; 1698 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; 1699 1700 ut_params->sess = rte_cryptodev_sym_session_create( 1701 ts_params->session_mpool); 1702 1703 /* Create crypto session*/ 1704 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 1705 ut_params->sess, &ut_params->cipher_xform, 1706 ts_params->session_priv_mpool); 1707 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 1708 1709 /* Generate crypto op data structure */ 1710 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1711 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1712 TEST_ASSERT_NOT_NULL(ut_params->op, 1713 "Failed to allocate symmetric crypto operation struct"); 1714 1715 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 1716 1717 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1718 1719 /* set crypto operation source mbuf */ 1720 sym_op->m_src = ut_params->ibuf; 1721 1722 /* Set crypto operation authentication parameters */ 1723 sym_op->auth.digest.data = ut_params->digest; 1724 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 1725 ut_params->ibuf, QUOTE_512_BYTES); 1726 1727 sym_op->auth.data.offset = 0; 1728 sym_op->auth.data.length = QUOTE_512_BYTES; 1729 1730 /* Copy IV at the end of the crypto operation */ 1731 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 1732 aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC); 1733 1734 /* Set crypto operation cipher parameters */ 1735 sym_op->cipher.data.offset = 0; 1736 sym_op->cipher.data.length = QUOTE_512_BYTES; 1737 1738 /* Process crypto operation */ 1739 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 1740 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 1741 ut_params->op); 1742 else 1743 TEST_ASSERT_NOT_NULL( 1744 process_crypto_request(ts_params->valid_devs[0], 1745 ut_params->op), 1746 "failed to process sym crypto op"); 1747 1748 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1749 "crypto op processing failed"); 1750 1751 /* Validate obuf */ 1752 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 1753 uint8_t *); 1754 1755 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, 1756 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 1757 QUOTE_512_BYTES, 1758 "ciphertext data not as expected"); 1759 1760 uint8_t *digest = ciphertext + QUOTE_512_BYTES; 1761 1762 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, 1763 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, 1764 gbl_driver_id == rte_cryptodev_driver_id_get( 1765 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ? 1766 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : 1767 DIGEST_BYTE_LENGTH_SHA1, 1768 "Generated digest data not as expected"); 1769 1770 return TEST_SUCCESS; 1771 } 1772 1773 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ 1774 1775 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) 1776 1777 static uint8_t hmac_sha512_key[] = { 1778 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1, 1779 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA, 1780 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76, 1781 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60, 1782 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1, 1783 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0, 1784 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76, 1785 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 }; 1786 1787 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = { 1788 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8, 1789 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48, 1790 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8, 1791 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70, 1792 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8, 1793 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E, 1794 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D, 1795 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A }; 1796 1797 1798 1799 static int 1800 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 1801 struct crypto_unittest_params *ut_params, 1802 uint8_t *cipher_key, 1803 uint8_t *hmac_key); 1804 1805 static int 1806 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 1807 struct crypto_unittest_params *ut_params, 1808 struct crypto_testsuite_params *ts_params, 1809 const uint8_t *cipher, 1810 const uint8_t *digest, 1811 const uint8_t *iv); 1812 1813 1814 static int 1815 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 1816 struct crypto_unittest_params *ut_params, 1817 uint8_t *cipher_key, 1818 uint8_t *hmac_key) 1819 { 1820 1821 /* Setup Cipher Parameters */ 1822 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1823 ut_params->cipher_xform.next = NULL; 1824 1825 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 1826 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 1827 ut_params->cipher_xform.cipher.key.data = cipher_key; 1828 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; 1829 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 1830 ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; 1831 1832 /* Setup HMAC Parameters */ 1833 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1834 ut_params->auth_xform.next = &ut_params->cipher_xform; 1835 1836 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 1837 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC; 1838 ut_params->auth_xform.auth.key.data = hmac_key; 1839 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512; 1840 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512; 1841 1842 return TEST_SUCCESS; 1843 } 1844 1845 1846 static int 1847 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess, 1848 struct crypto_unittest_params *ut_params, 1849 struct crypto_testsuite_params *ts_params, 1850 const uint8_t *cipher, 1851 const uint8_t *digest, 1852 const uint8_t *iv) 1853 { 1854 /* Generate test mbuf data and digest */ 1855 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool, 1856 (const char *) 1857 cipher, 1858 QUOTE_512_BYTES, 0); 1859 1860 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 1861 DIGEST_BYTE_LENGTH_SHA512); 1862 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); 1863 1864 rte_memcpy(ut_params->digest, 1865 digest, 1866 DIGEST_BYTE_LENGTH_SHA512); 1867 1868 /* Generate Crypto op data structure */ 1869 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 1870 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 1871 TEST_ASSERT_NOT_NULL(ut_params->op, 1872 "Failed to allocate symmetric crypto operation struct"); 1873 1874 rte_crypto_op_attach_sym_session(ut_params->op, sess); 1875 1876 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 1877 1878 /* set crypto operation source mbuf */ 1879 sym_op->m_src = ut_params->ibuf; 1880 1881 sym_op->auth.digest.data = ut_params->digest; 1882 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 1883 ut_params->ibuf, QUOTE_512_BYTES); 1884 1885 sym_op->auth.data.offset = 0; 1886 sym_op->auth.data.length = QUOTE_512_BYTES; 1887 1888 /* Copy IV at the end of the crypto operation */ 1889 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 1890 iv, CIPHER_IV_LENGTH_AES_CBC); 1891 1892 sym_op->cipher.data.offset = 0; 1893 sym_op->cipher.data.length = QUOTE_512_BYTES; 1894 1895 /* Process crypto operation */ 1896 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 1897 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 1898 ut_params->op); 1899 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 1900 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 1901 ut_params->op, 1, 1, 0, 0); 1902 else 1903 TEST_ASSERT_NOT_NULL( 1904 process_crypto_request(ts_params->valid_devs[0], 1905 ut_params->op), 1906 "failed to process sym crypto op"); 1907 1908 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1909 "crypto op processing failed"); 1910 1911 ut_params->obuf = ut_params->op->sym->m_src; 1912 1913 /* Validate obuf */ 1914 TEST_ASSERT_BUFFERS_ARE_EQUAL( 1915 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 1916 catch_22_quote, 1917 QUOTE_512_BYTES, 1918 "Plaintext data not as expected"); 1919 1920 /* Validate obuf */ 1921 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 1922 "Digest verification failed"); 1923 1924 return TEST_SUCCESS; 1925 } 1926 1927 static int 1928 test_blockcipher(enum blockcipher_test_type test_type) 1929 { 1930 struct crypto_testsuite_params *ts_params = &testsuite_params; 1931 int status; 1932 1933 status = test_blockcipher_all_tests(ts_params->mbuf_pool, 1934 ts_params->op_mpool, 1935 ts_params->session_mpool, ts_params->session_priv_mpool, 1936 ts_params->valid_devs[0], 1937 test_type); 1938 1939 if (status == -ENOTSUP) 1940 return status; 1941 1942 TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1943 1944 return TEST_SUCCESS; 1945 } 1946 1947 static int 1948 test_AES_cipheronly_all(void) 1949 { 1950 return test_blockcipher(BLKCIPHER_AES_CIPHERONLY_TYPE); 1951 } 1952 1953 static int 1954 test_AES_docsis_all(void) 1955 { 1956 /* Data-path service does not support DOCSIS yet */ 1957 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 1958 return -ENOTSUP; 1959 return test_blockcipher(BLKCIPHER_AES_DOCSIS_TYPE); 1960 } 1961 1962 static int 1963 test_DES_docsis_all(void) 1964 { 1965 /* Data-path service does not support DOCSIS yet */ 1966 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 1967 return -ENOTSUP; 1968 return test_blockcipher(BLKCIPHER_DES_DOCSIS_TYPE); 1969 } 1970 1971 static int 1972 test_DES_cipheronly_all(void) 1973 { 1974 return test_blockcipher(BLKCIPHER_DES_CIPHERONLY_TYPE); 1975 } 1976 1977 static int 1978 test_authonly_all(void) 1979 { 1980 return test_blockcipher(BLKCIPHER_AUTHONLY_TYPE); 1981 } 1982 1983 static int 1984 test_AES_chain_all(void) 1985 { 1986 return test_blockcipher(BLKCIPHER_AES_CHAIN_TYPE); 1987 } 1988 1989 static int 1990 test_3DES_chain_all(void) 1991 { 1992 return test_blockcipher(BLKCIPHER_3DES_CHAIN_TYPE); 1993 } 1994 1995 static int 1996 test_3DES_cipheronly_all(void) 1997 { 1998 return test_blockcipher(BLKCIPHER_3DES_CIPHERONLY_TYPE); 1999 } 2000 2001 /* ***** SNOW 3G Tests ***** */ 2002 static int 2003 create_wireless_algo_hash_session(uint8_t dev_id, 2004 const uint8_t *key, const uint8_t key_len, 2005 const uint8_t iv_len, const uint8_t auth_len, 2006 enum rte_crypto_auth_operation op, 2007 enum rte_crypto_auth_algorithm algo) 2008 { 2009 uint8_t hash_key[key_len]; 2010 int status; 2011 2012 struct crypto_testsuite_params *ts_params = &testsuite_params; 2013 struct crypto_unittest_params *ut_params = &unittest_params; 2014 2015 memcpy(hash_key, key, key_len); 2016 2017 debug_hexdump(stdout, "key:", key, key_len); 2018 2019 /* Setup Authentication Parameters */ 2020 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2021 ut_params->auth_xform.next = NULL; 2022 2023 ut_params->auth_xform.auth.op = op; 2024 ut_params->auth_xform.auth.algo = algo; 2025 ut_params->auth_xform.auth.key.length = key_len; 2026 ut_params->auth_xform.auth.key.data = hash_key; 2027 ut_params->auth_xform.auth.digest_length = auth_len; 2028 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 2029 ut_params->auth_xform.auth.iv.length = iv_len; 2030 ut_params->sess = rte_cryptodev_sym_session_create( 2031 ts_params->session_mpool); 2032 2033 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2034 &ut_params->auth_xform, 2035 ts_params->session_priv_mpool); 2036 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2037 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2038 return 0; 2039 } 2040 2041 static int 2042 create_wireless_algo_cipher_session(uint8_t dev_id, 2043 enum rte_crypto_cipher_operation op, 2044 enum rte_crypto_cipher_algorithm algo, 2045 const uint8_t *key, const uint8_t key_len, 2046 uint8_t iv_len) 2047 { 2048 uint8_t cipher_key[key_len]; 2049 int status; 2050 struct crypto_testsuite_params *ts_params = &testsuite_params; 2051 struct crypto_unittest_params *ut_params = &unittest_params; 2052 2053 memcpy(cipher_key, key, key_len); 2054 2055 /* Setup Cipher Parameters */ 2056 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2057 ut_params->cipher_xform.next = NULL; 2058 2059 ut_params->cipher_xform.cipher.algo = algo; 2060 ut_params->cipher_xform.cipher.op = op; 2061 ut_params->cipher_xform.cipher.key.data = cipher_key; 2062 ut_params->cipher_xform.cipher.key.length = key_len; 2063 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2064 ut_params->cipher_xform.cipher.iv.length = iv_len; 2065 2066 debug_hexdump(stdout, "key:", key, key_len); 2067 2068 /* Create Crypto session */ 2069 ut_params->sess = rte_cryptodev_sym_session_create( 2070 ts_params->session_mpool); 2071 2072 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2073 &ut_params->cipher_xform, 2074 ts_params->session_priv_mpool); 2075 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2076 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2077 return 0; 2078 } 2079 2080 static int 2081 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len, 2082 unsigned int cipher_len, 2083 unsigned int cipher_offset) 2084 { 2085 struct crypto_testsuite_params *ts_params = &testsuite_params; 2086 struct crypto_unittest_params *ut_params = &unittest_params; 2087 2088 /* Generate Crypto op data structure */ 2089 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2090 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2091 TEST_ASSERT_NOT_NULL(ut_params->op, 2092 "Failed to allocate pktmbuf offload"); 2093 2094 /* Set crypto operation data parameters */ 2095 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2096 2097 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2098 2099 /* set crypto operation source mbuf */ 2100 sym_op->m_src = ut_params->ibuf; 2101 2102 /* iv */ 2103 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2104 iv, iv_len); 2105 sym_op->cipher.data.length = cipher_len; 2106 sym_op->cipher.data.offset = cipher_offset; 2107 return 0; 2108 } 2109 2110 static int 2111 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len, 2112 unsigned int cipher_len, 2113 unsigned int cipher_offset) 2114 { 2115 struct crypto_testsuite_params *ts_params = &testsuite_params; 2116 struct crypto_unittest_params *ut_params = &unittest_params; 2117 2118 /* Generate Crypto op data structure */ 2119 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2120 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2121 TEST_ASSERT_NOT_NULL(ut_params->op, 2122 "Failed to allocate pktmbuf offload"); 2123 2124 /* Set crypto operation data parameters */ 2125 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2126 2127 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2128 2129 /* set crypto operation source mbuf */ 2130 sym_op->m_src = ut_params->ibuf; 2131 sym_op->m_dst = ut_params->obuf; 2132 2133 /* iv */ 2134 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2135 iv, iv_len); 2136 sym_op->cipher.data.length = cipher_len; 2137 sym_op->cipher.data.offset = cipher_offset; 2138 return 0; 2139 } 2140 2141 static int 2142 create_wireless_algo_cipher_auth_session(uint8_t dev_id, 2143 enum rte_crypto_cipher_operation cipher_op, 2144 enum rte_crypto_auth_operation auth_op, 2145 enum rte_crypto_auth_algorithm auth_algo, 2146 enum rte_crypto_cipher_algorithm cipher_algo, 2147 const uint8_t *key, uint8_t key_len, 2148 uint8_t auth_iv_len, uint8_t auth_len, 2149 uint8_t cipher_iv_len) 2150 2151 { 2152 uint8_t cipher_auth_key[key_len]; 2153 int status; 2154 2155 struct crypto_testsuite_params *ts_params = &testsuite_params; 2156 struct crypto_unittest_params *ut_params = &unittest_params; 2157 2158 memcpy(cipher_auth_key, key, key_len); 2159 2160 /* Setup Authentication Parameters */ 2161 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2162 ut_params->auth_xform.next = NULL; 2163 2164 ut_params->auth_xform.auth.op = auth_op; 2165 ut_params->auth_xform.auth.algo = auth_algo; 2166 ut_params->auth_xform.auth.key.length = key_len; 2167 /* Hash key = cipher key */ 2168 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2169 ut_params->auth_xform.auth.digest_length = auth_len; 2170 /* Auth IV will be after cipher IV */ 2171 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2172 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2173 2174 /* Setup Cipher Parameters */ 2175 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2176 ut_params->cipher_xform.next = &ut_params->auth_xform; 2177 2178 ut_params->cipher_xform.cipher.algo = cipher_algo; 2179 ut_params->cipher_xform.cipher.op = cipher_op; 2180 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2181 ut_params->cipher_xform.cipher.key.length = key_len; 2182 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2183 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2184 2185 debug_hexdump(stdout, "key:", key, key_len); 2186 2187 /* Create Crypto session*/ 2188 ut_params->sess = rte_cryptodev_sym_session_create( 2189 ts_params->session_mpool); 2190 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2191 2192 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2193 &ut_params->cipher_xform, 2194 ts_params->session_priv_mpool); 2195 if (status == -ENOTSUP) 2196 return status; 2197 2198 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2199 return 0; 2200 } 2201 2202 static int 2203 create_wireless_cipher_auth_session(uint8_t dev_id, 2204 enum rte_crypto_cipher_operation cipher_op, 2205 enum rte_crypto_auth_operation auth_op, 2206 enum rte_crypto_auth_algorithm auth_algo, 2207 enum rte_crypto_cipher_algorithm cipher_algo, 2208 const struct wireless_test_data *tdata) 2209 { 2210 const uint8_t key_len = tdata->key.len; 2211 uint8_t cipher_auth_key[key_len]; 2212 int status; 2213 2214 struct crypto_testsuite_params *ts_params = &testsuite_params; 2215 struct crypto_unittest_params *ut_params = &unittest_params; 2216 const uint8_t *key = tdata->key.data; 2217 const uint8_t auth_len = tdata->digest.len; 2218 uint8_t cipher_iv_len = tdata->cipher_iv.len; 2219 uint8_t auth_iv_len = tdata->auth_iv.len; 2220 2221 memcpy(cipher_auth_key, key, key_len); 2222 2223 /* Setup Authentication Parameters */ 2224 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2225 ut_params->auth_xform.next = NULL; 2226 2227 ut_params->auth_xform.auth.op = auth_op; 2228 ut_params->auth_xform.auth.algo = auth_algo; 2229 ut_params->auth_xform.auth.key.length = key_len; 2230 /* Hash key = cipher key */ 2231 ut_params->auth_xform.auth.key.data = cipher_auth_key; 2232 ut_params->auth_xform.auth.digest_length = auth_len; 2233 /* Auth IV will be after cipher IV */ 2234 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2235 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2236 2237 /* Setup Cipher Parameters */ 2238 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2239 ut_params->cipher_xform.next = &ut_params->auth_xform; 2240 2241 ut_params->cipher_xform.cipher.algo = cipher_algo; 2242 ut_params->cipher_xform.cipher.op = cipher_op; 2243 ut_params->cipher_xform.cipher.key.data = cipher_auth_key; 2244 ut_params->cipher_xform.cipher.key.length = key_len; 2245 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2246 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2247 2248 2249 debug_hexdump(stdout, "key:", key, key_len); 2250 2251 /* Create Crypto session*/ 2252 ut_params->sess = rte_cryptodev_sym_session_create( 2253 ts_params->session_mpool); 2254 2255 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2256 &ut_params->cipher_xform, 2257 ts_params->session_priv_mpool); 2258 if (status == -ENOTSUP) 2259 return status; 2260 2261 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2262 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2263 return 0; 2264 } 2265 2266 static int 2267 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id, 2268 const struct wireless_test_data *tdata) 2269 { 2270 return create_wireless_cipher_auth_session(dev_id, 2271 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 2272 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3, 2273 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata); 2274 } 2275 2276 static int 2277 create_wireless_algo_auth_cipher_session(uint8_t dev_id, 2278 enum rte_crypto_cipher_operation cipher_op, 2279 enum rte_crypto_auth_operation auth_op, 2280 enum rte_crypto_auth_algorithm auth_algo, 2281 enum rte_crypto_cipher_algorithm cipher_algo, 2282 const uint8_t *key, const uint8_t key_len, 2283 uint8_t auth_iv_len, uint8_t auth_len, 2284 uint8_t cipher_iv_len) 2285 { 2286 uint8_t auth_cipher_key[key_len]; 2287 int status; 2288 struct crypto_testsuite_params *ts_params = &testsuite_params; 2289 struct crypto_unittest_params *ut_params = &unittest_params; 2290 2291 memcpy(auth_cipher_key, key, key_len); 2292 2293 /* Setup Authentication Parameters */ 2294 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2295 ut_params->auth_xform.auth.op = auth_op; 2296 ut_params->auth_xform.next = &ut_params->cipher_xform; 2297 ut_params->auth_xform.auth.algo = auth_algo; 2298 ut_params->auth_xform.auth.key.length = key_len; 2299 ut_params->auth_xform.auth.key.data = auth_cipher_key; 2300 ut_params->auth_xform.auth.digest_length = auth_len; 2301 /* Auth IV will be after cipher IV */ 2302 ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len; 2303 ut_params->auth_xform.auth.iv.length = auth_iv_len; 2304 2305 /* Setup Cipher Parameters */ 2306 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 2307 ut_params->cipher_xform.next = NULL; 2308 ut_params->cipher_xform.cipher.algo = cipher_algo; 2309 ut_params->cipher_xform.cipher.op = cipher_op; 2310 ut_params->cipher_xform.cipher.key.data = auth_cipher_key; 2311 ut_params->cipher_xform.cipher.key.length = key_len; 2312 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 2313 ut_params->cipher_xform.cipher.iv.length = cipher_iv_len; 2314 2315 debug_hexdump(stdout, "key:", key, key_len); 2316 2317 /* Create Crypto session*/ 2318 ut_params->sess = rte_cryptodev_sym_session_create( 2319 ts_params->session_mpool); 2320 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 2321 2322 if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) { 2323 ut_params->auth_xform.next = NULL; 2324 ut_params->cipher_xform.next = &ut_params->auth_xform; 2325 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2326 &ut_params->cipher_xform, 2327 ts_params->session_priv_mpool); 2328 2329 } else 2330 status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 2331 &ut_params->auth_xform, 2332 ts_params->session_priv_mpool); 2333 2334 if (status == -ENOTSUP) 2335 return status; 2336 2337 TEST_ASSERT_EQUAL(status, 0, "session init failed"); 2338 2339 return 0; 2340 } 2341 2342 static int 2343 create_wireless_algo_hash_operation(const uint8_t *auth_tag, 2344 unsigned int auth_tag_len, 2345 const uint8_t *iv, unsigned int iv_len, 2346 unsigned int data_pad_len, 2347 enum rte_crypto_auth_operation op, 2348 unsigned int auth_len, unsigned int auth_offset) 2349 { 2350 struct crypto_testsuite_params *ts_params = &testsuite_params; 2351 2352 struct crypto_unittest_params *ut_params = &unittest_params; 2353 2354 /* Generate Crypto op data structure */ 2355 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2356 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2357 TEST_ASSERT_NOT_NULL(ut_params->op, 2358 "Failed to allocate pktmbuf offload"); 2359 2360 /* Set crypto operation data parameters */ 2361 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2362 2363 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2364 2365 /* set crypto operation source mbuf */ 2366 sym_op->m_src = ut_params->ibuf; 2367 2368 /* iv */ 2369 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 2370 iv, iv_len); 2371 /* digest */ 2372 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2373 ut_params->ibuf, auth_tag_len); 2374 2375 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2376 "no room to append auth tag"); 2377 ut_params->digest = sym_op->auth.digest.data; 2378 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2379 ut_params->ibuf, data_pad_len); 2380 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2381 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2382 else 2383 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2384 2385 debug_hexdump(stdout, "digest:", 2386 sym_op->auth.digest.data, 2387 auth_tag_len); 2388 2389 sym_op->auth.data.length = auth_len; 2390 sym_op->auth.data.offset = auth_offset; 2391 2392 return 0; 2393 } 2394 2395 static int 2396 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata, 2397 enum rte_crypto_auth_operation op) 2398 { 2399 struct crypto_testsuite_params *ts_params = &testsuite_params; 2400 struct crypto_unittest_params *ut_params = &unittest_params; 2401 2402 const uint8_t *auth_tag = tdata->digest.data; 2403 const unsigned int auth_tag_len = tdata->digest.len; 2404 unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len); 2405 unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2406 2407 const uint8_t *cipher_iv = tdata->cipher_iv.data; 2408 const uint8_t cipher_iv_len = tdata->cipher_iv.len; 2409 const uint8_t *auth_iv = tdata->auth_iv.data; 2410 const uint8_t auth_iv_len = tdata->auth_iv.len; 2411 const unsigned int cipher_len = tdata->validCipherLenInBits.len; 2412 const unsigned int auth_len = tdata->validAuthLenInBits.len; 2413 2414 /* Generate Crypto op data structure */ 2415 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2416 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2417 TEST_ASSERT_NOT_NULL(ut_params->op, 2418 "Failed to allocate pktmbuf offload"); 2419 /* Set crypto operation data parameters */ 2420 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2421 2422 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2423 2424 /* set crypto operation source mbuf */ 2425 sym_op->m_src = ut_params->ibuf; 2426 2427 /* digest */ 2428 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2429 ut_params->ibuf, auth_tag_len); 2430 2431 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2432 "no room to append auth tag"); 2433 ut_params->digest = sym_op->auth.digest.data; 2434 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2435 ut_params->ibuf, data_pad_len); 2436 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2437 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2438 else 2439 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2440 2441 debug_hexdump(stdout, "digest:", 2442 sym_op->auth.digest.data, 2443 auth_tag_len); 2444 2445 /* Copy cipher and auth IVs at the end of the crypto operation */ 2446 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2447 IV_OFFSET); 2448 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2449 iv_ptr += cipher_iv_len; 2450 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2451 2452 sym_op->cipher.data.length = cipher_len; 2453 sym_op->cipher.data.offset = 0; 2454 sym_op->auth.data.length = auth_len; 2455 sym_op->auth.data.offset = 0; 2456 2457 return 0; 2458 } 2459 2460 static int 2461 create_zuc_cipher_hash_generate_operation( 2462 const struct wireless_test_data *tdata) 2463 { 2464 return create_wireless_cipher_hash_operation(tdata, 2465 RTE_CRYPTO_AUTH_OP_GENERATE); 2466 } 2467 2468 static int 2469 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag, 2470 const unsigned auth_tag_len, 2471 const uint8_t *auth_iv, uint8_t auth_iv_len, 2472 unsigned data_pad_len, 2473 enum rte_crypto_auth_operation op, 2474 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2475 const unsigned cipher_len, const unsigned cipher_offset, 2476 const unsigned auth_len, const unsigned auth_offset) 2477 { 2478 struct crypto_testsuite_params *ts_params = &testsuite_params; 2479 struct crypto_unittest_params *ut_params = &unittest_params; 2480 2481 enum rte_crypto_cipher_algorithm cipher_algo = 2482 ut_params->cipher_xform.cipher.algo; 2483 enum rte_crypto_auth_algorithm auth_algo = 2484 ut_params->auth_xform.auth.algo; 2485 2486 /* Generate Crypto op data structure */ 2487 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2488 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2489 TEST_ASSERT_NOT_NULL(ut_params->op, 2490 "Failed to allocate pktmbuf offload"); 2491 /* Set crypto operation data parameters */ 2492 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2493 2494 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2495 2496 /* set crypto operation source mbuf */ 2497 sym_op->m_src = ut_params->ibuf; 2498 2499 /* digest */ 2500 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 2501 ut_params->ibuf, auth_tag_len); 2502 2503 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 2504 "no room to append auth tag"); 2505 ut_params->digest = sym_op->auth.digest.data; 2506 2507 if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) { 2508 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2509 ut_params->ibuf, data_pad_len); 2510 } else { 2511 struct rte_mbuf *m = ut_params->ibuf; 2512 unsigned int offset = data_pad_len; 2513 2514 while (offset > m->data_len && m->next != NULL) { 2515 offset -= m->data_len; 2516 m = m->next; 2517 } 2518 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2519 m, offset); 2520 } 2521 2522 if (op == RTE_CRYPTO_AUTH_OP_GENERATE) 2523 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2524 else 2525 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2526 2527 debug_hexdump(stdout, "digest:", 2528 sym_op->auth.digest.data, 2529 auth_tag_len); 2530 2531 /* Copy cipher and auth IVs at the end of the crypto operation */ 2532 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, 2533 IV_OFFSET); 2534 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2535 iv_ptr += cipher_iv_len; 2536 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2537 2538 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 2539 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 2540 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 2541 sym_op->cipher.data.length = cipher_len; 2542 sym_op->cipher.data.offset = cipher_offset; 2543 } else { 2544 sym_op->cipher.data.length = cipher_len >> 3; 2545 sym_op->cipher.data.offset = cipher_offset >> 3; 2546 } 2547 2548 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 2549 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 2550 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 2551 sym_op->auth.data.length = auth_len; 2552 sym_op->auth.data.offset = auth_offset; 2553 } else { 2554 sym_op->auth.data.length = auth_len >> 3; 2555 sym_op->auth.data.offset = auth_offset >> 3; 2556 } 2557 2558 return 0; 2559 } 2560 2561 static int 2562 create_wireless_algo_auth_cipher_operation( 2563 const uint8_t *auth_tag, unsigned int auth_tag_len, 2564 const uint8_t *cipher_iv, uint8_t cipher_iv_len, 2565 const uint8_t *auth_iv, uint8_t auth_iv_len, 2566 unsigned int data_pad_len, 2567 unsigned int cipher_len, unsigned int cipher_offset, 2568 unsigned int auth_len, unsigned int auth_offset, 2569 uint8_t op_mode, uint8_t do_sgl, uint8_t verify) 2570 { 2571 struct crypto_testsuite_params *ts_params = &testsuite_params; 2572 struct crypto_unittest_params *ut_params = &unittest_params; 2573 2574 enum rte_crypto_cipher_algorithm cipher_algo = 2575 ut_params->cipher_xform.cipher.algo; 2576 enum rte_crypto_auth_algorithm auth_algo = 2577 ut_params->auth_xform.auth.algo; 2578 2579 /* Generate Crypto op data structure */ 2580 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 2581 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 2582 TEST_ASSERT_NOT_NULL(ut_params->op, 2583 "Failed to allocate pktmbuf offload"); 2584 2585 /* Set crypto operation data parameters */ 2586 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 2587 2588 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 2589 2590 /* set crypto operation mbufs */ 2591 sym_op->m_src = ut_params->ibuf; 2592 if (op_mode == OUT_OF_PLACE) 2593 sym_op->m_dst = ut_params->obuf; 2594 2595 /* digest */ 2596 if (!do_sgl) { 2597 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset( 2598 (op_mode == IN_PLACE ? 2599 ut_params->ibuf : ut_params->obuf), 2600 uint8_t *, data_pad_len); 2601 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 2602 (op_mode == IN_PLACE ? 2603 ut_params->ibuf : ut_params->obuf), 2604 data_pad_len); 2605 memset(sym_op->auth.digest.data, 0, auth_tag_len); 2606 } else { 2607 uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3); 2608 struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ? 2609 sym_op->m_src : sym_op->m_dst); 2610 while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) { 2611 remaining_off -= rte_pktmbuf_data_len(sgl_buf); 2612 sgl_buf = sgl_buf->next; 2613 } 2614 sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf, 2615 uint8_t *, remaining_off); 2616 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf, 2617 remaining_off); 2618 memset(sym_op->auth.digest.data, 0, remaining_off); 2619 while (sgl_buf->next != NULL) { 2620 memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *), 2621 0, rte_pktmbuf_data_len(sgl_buf)); 2622 sgl_buf = sgl_buf->next; 2623 } 2624 } 2625 2626 /* Copy digest for the verification */ 2627 if (verify) 2628 memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len); 2629 2630 /* Copy cipher and auth IVs at the end of the crypto operation */ 2631 uint8_t *iv_ptr = rte_crypto_op_ctod_offset( 2632 ut_params->op, uint8_t *, IV_OFFSET); 2633 2634 rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); 2635 iv_ptr += cipher_iv_len; 2636 rte_memcpy(iv_ptr, auth_iv, auth_iv_len); 2637 2638 if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 2639 cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 2640 cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) { 2641 sym_op->cipher.data.length = cipher_len; 2642 sym_op->cipher.data.offset = cipher_offset; 2643 } else { 2644 sym_op->cipher.data.length = cipher_len >> 3; 2645 sym_op->cipher.data.offset = cipher_offset >> 3; 2646 } 2647 2648 if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 2649 auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 2650 auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) { 2651 sym_op->auth.data.length = auth_len; 2652 sym_op->auth.data.offset = auth_offset; 2653 } else { 2654 sym_op->auth.data.length = auth_len >> 3; 2655 sym_op->auth.data.offset = auth_offset >> 3; 2656 } 2657 2658 return 0; 2659 } 2660 2661 static int 2662 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata) 2663 { 2664 struct crypto_testsuite_params *ts_params = &testsuite_params; 2665 struct crypto_unittest_params *ut_params = &unittest_params; 2666 2667 int retval; 2668 unsigned plaintext_pad_len; 2669 unsigned plaintext_len; 2670 uint8_t *plaintext; 2671 struct rte_cryptodev_info dev_info; 2672 2673 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2674 uint64_t feat_flags = dev_info.feature_flags; 2675 2676 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 2677 ((tdata->validAuthLenInBits.len % 8) != 0)) { 2678 printf("Device doesn't support NON-Byte Aligned Data.\n"); 2679 return -ENOTSUP; 2680 } 2681 2682 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 2683 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 2684 printf("Device doesn't support RAW data-path APIs.\n"); 2685 return -ENOTSUP; 2686 } 2687 2688 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2689 return -ENOTSUP; 2690 2691 /* Verify the capabilities */ 2692 struct rte_cryptodev_sym_capability_idx cap_idx; 2693 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2694 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 2695 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2696 &cap_idx) == NULL) 2697 return -ENOTSUP; 2698 2699 /* Create SNOW 3G session */ 2700 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2701 tdata->key.data, tdata->key.len, 2702 tdata->auth_iv.len, tdata->digest.len, 2703 RTE_CRYPTO_AUTH_OP_GENERATE, 2704 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 2705 if (retval < 0) 2706 return retval; 2707 2708 /* alloc mbuf and set payload */ 2709 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2710 2711 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2712 rte_pktmbuf_tailroom(ut_params->ibuf)); 2713 2714 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2715 /* Append data which is padded to a multiple of */ 2716 /* the algorithms block size */ 2717 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2718 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2719 plaintext_pad_len); 2720 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2721 2722 /* Create SNOW 3G operation */ 2723 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 2724 tdata->auth_iv.data, tdata->auth_iv.len, 2725 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 2726 tdata->validAuthLenInBits.len, 2727 0); 2728 if (retval < 0) 2729 return retval; 2730 2731 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2732 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2733 ut_params->op, 0, 1, 1, 0); 2734 else 2735 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2736 ut_params->op); 2737 ut_params->obuf = ut_params->op->sym->m_src; 2738 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2739 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2740 + plaintext_pad_len; 2741 2742 /* Validate obuf */ 2743 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2744 ut_params->digest, 2745 tdata->digest.data, 2746 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 2747 "SNOW 3G Generated auth tag not as expected"); 2748 2749 return 0; 2750 } 2751 2752 static int 2753 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata) 2754 { 2755 struct crypto_testsuite_params *ts_params = &testsuite_params; 2756 struct crypto_unittest_params *ut_params = &unittest_params; 2757 2758 int retval; 2759 unsigned plaintext_pad_len; 2760 unsigned plaintext_len; 2761 uint8_t *plaintext; 2762 struct rte_cryptodev_info dev_info; 2763 2764 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2765 uint64_t feat_flags = dev_info.feature_flags; 2766 2767 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 2768 ((tdata->validAuthLenInBits.len % 8) != 0)) { 2769 printf("Device doesn't support NON-Byte Aligned Data.\n"); 2770 return -ENOTSUP; 2771 } 2772 2773 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 2774 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 2775 printf("Device doesn't support RAW data-path APIs.\n"); 2776 return -ENOTSUP; 2777 } 2778 2779 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2780 return -ENOTSUP; 2781 2782 /* Verify the capabilities */ 2783 struct rte_cryptodev_sym_capability_idx cap_idx; 2784 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2785 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 2786 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2787 &cap_idx) == NULL) 2788 return -ENOTSUP; 2789 2790 /* Create SNOW 3G session */ 2791 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2792 tdata->key.data, tdata->key.len, 2793 tdata->auth_iv.len, tdata->digest.len, 2794 RTE_CRYPTO_AUTH_OP_VERIFY, 2795 RTE_CRYPTO_AUTH_SNOW3G_UIA2); 2796 if (retval < 0) 2797 return retval; 2798 /* alloc mbuf and set payload */ 2799 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2800 2801 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2802 rte_pktmbuf_tailroom(ut_params->ibuf)); 2803 2804 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2805 /* Append data which is padded to a multiple of */ 2806 /* the algorithms block size */ 2807 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 2808 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2809 plaintext_pad_len); 2810 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2811 2812 /* Create SNOW 3G operation */ 2813 retval = create_wireless_algo_hash_operation(tdata->digest.data, 2814 tdata->digest.len, 2815 tdata->auth_iv.data, tdata->auth_iv.len, 2816 plaintext_pad_len, 2817 RTE_CRYPTO_AUTH_OP_VERIFY, 2818 tdata->validAuthLenInBits.len, 2819 0); 2820 if (retval < 0) 2821 return retval; 2822 2823 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2824 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2825 ut_params->op, 0, 1, 1, 0); 2826 else 2827 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2828 ut_params->op); 2829 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2830 ut_params->obuf = ut_params->op->sym->m_src; 2831 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2832 + plaintext_pad_len; 2833 2834 /* Validate obuf */ 2835 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 2836 return 0; 2837 else 2838 return -1; 2839 2840 return 0; 2841 } 2842 2843 static int 2844 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata) 2845 { 2846 struct crypto_testsuite_params *ts_params = &testsuite_params; 2847 struct crypto_unittest_params *ut_params = &unittest_params; 2848 2849 int retval; 2850 unsigned plaintext_pad_len; 2851 unsigned plaintext_len; 2852 uint8_t *plaintext; 2853 struct rte_cryptodev_info dev_info; 2854 2855 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2856 uint64_t feat_flags = dev_info.feature_flags; 2857 2858 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 2859 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 2860 printf("Device doesn't support RAW data-path APIs.\n"); 2861 return -ENOTSUP; 2862 } 2863 2864 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2865 return -ENOTSUP; 2866 2867 /* Verify the capabilities */ 2868 struct rte_cryptodev_sym_capability_idx cap_idx; 2869 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2870 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 2871 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2872 &cap_idx) == NULL) 2873 return -ENOTSUP; 2874 2875 /* Create KASUMI session */ 2876 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2877 tdata->key.data, tdata->key.len, 2878 0, tdata->digest.len, 2879 RTE_CRYPTO_AUTH_OP_GENERATE, 2880 RTE_CRYPTO_AUTH_KASUMI_F9); 2881 if (retval < 0) 2882 return retval; 2883 2884 /* alloc mbuf and set payload */ 2885 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2886 2887 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2888 rte_pktmbuf_tailroom(ut_params->ibuf)); 2889 2890 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2891 /* Append data which is padded to a multiple of */ 2892 /* the algorithms block size */ 2893 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2894 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2895 plaintext_pad_len); 2896 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2897 2898 /* Create KASUMI operation */ 2899 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 2900 NULL, 0, 2901 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 2902 tdata->plaintext.len, 2903 0); 2904 if (retval < 0) 2905 return retval; 2906 2907 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2908 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 2909 ut_params->op); 2910 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2911 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2912 ut_params->op, 0, 1, 1, 0); 2913 else 2914 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 2915 ut_params->op); 2916 2917 ut_params->obuf = ut_params->op->sym->m_src; 2918 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 2919 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 2920 + plaintext_pad_len; 2921 2922 /* Validate obuf */ 2923 TEST_ASSERT_BUFFERS_ARE_EQUAL( 2924 ut_params->digest, 2925 tdata->digest.data, 2926 DIGEST_BYTE_LENGTH_KASUMI_F9, 2927 "KASUMI Generated auth tag not as expected"); 2928 2929 return 0; 2930 } 2931 2932 static int 2933 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata) 2934 { 2935 struct crypto_testsuite_params *ts_params = &testsuite_params; 2936 struct crypto_unittest_params *ut_params = &unittest_params; 2937 2938 int retval; 2939 unsigned plaintext_pad_len; 2940 unsigned plaintext_len; 2941 uint8_t *plaintext; 2942 struct rte_cryptodev_info dev_info; 2943 2944 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 2945 uint64_t feat_flags = dev_info.feature_flags; 2946 2947 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 2948 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 2949 printf("Device doesn't support RAW data-path APIs.\n"); 2950 return -ENOTSUP; 2951 } 2952 2953 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 2954 return -ENOTSUP; 2955 2956 /* Verify the capabilities */ 2957 struct rte_cryptodev_sym_capability_idx cap_idx; 2958 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 2959 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 2960 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 2961 &cap_idx) == NULL) 2962 return -ENOTSUP; 2963 2964 /* Create KASUMI session */ 2965 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 2966 tdata->key.data, tdata->key.len, 2967 0, tdata->digest.len, 2968 RTE_CRYPTO_AUTH_OP_VERIFY, 2969 RTE_CRYPTO_AUTH_KASUMI_F9); 2970 if (retval < 0) 2971 return retval; 2972 /* alloc mbuf and set payload */ 2973 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 2974 2975 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 2976 rte_pktmbuf_tailroom(ut_params->ibuf)); 2977 2978 plaintext_len = ceil_byte_length(tdata->plaintext.len); 2979 /* Append data which is padded to a multiple */ 2980 /* of the algorithms block size */ 2981 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 2982 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 2983 plaintext_pad_len); 2984 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 2985 2986 /* Create KASUMI operation */ 2987 retval = create_wireless_algo_hash_operation(tdata->digest.data, 2988 tdata->digest.len, 2989 NULL, 0, 2990 plaintext_pad_len, 2991 RTE_CRYPTO_AUTH_OP_VERIFY, 2992 tdata->plaintext.len, 2993 0); 2994 if (retval < 0) 2995 return retval; 2996 2997 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 2998 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 2999 ut_params->op, 0, 1, 1, 0); 3000 else 3001 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3002 ut_params->op); 3003 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3004 ut_params->obuf = ut_params->op->sym->m_src; 3005 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 3006 + plaintext_pad_len; 3007 3008 /* Validate obuf */ 3009 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) 3010 return 0; 3011 else 3012 return -1; 3013 3014 return 0; 3015 } 3016 3017 static int 3018 test_snow3g_hash_generate_test_case_1(void) 3019 { 3020 return test_snow3g_authentication(&snow3g_hash_test_case_1); 3021 } 3022 3023 static int 3024 test_snow3g_hash_generate_test_case_2(void) 3025 { 3026 return test_snow3g_authentication(&snow3g_hash_test_case_2); 3027 } 3028 3029 static int 3030 test_snow3g_hash_generate_test_case_3(void) 3031 { 3032 return test_snow3g_authentication(&snow3g_hash_test_case_3); 3033 } 3034 3035 static int 3036 test_snow3g_hash_generate_test_case_4(void) 3037 { 3038 return test_snow3g_authentication(&snow3g_hash_test_case_4); 3039 } 3040 3041 static int 3042 test_snow3g_hash_generate_test_case_5(void) 3043 { 3044 return test_snow3g_authentication(&snow3g_hash_test_case_5); 3045 } 3046 3047 static int 3048 test_snow3g_hash_generate_test_case_6(void) 3049 { 3050 return test_snow3g_authentication(&snow3g_hash_test_case_6); 3051 } 3052 3053 static int 3054 test_snow3g_hash_verify_test_case_1(void) 3055 { 3056 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1); 3057 3058 } 3059 3060 static int 3061 test_snow3g_hash_verify_test_case_2(void) 3062 { 3063 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2); 3064 } 3065 3066 static int 3067 test_snow3g_hash_verify_test_case_3(void) 3068 { 3069 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3); 3070 } 3071 3072 static int 3073 test_snow3g_hash_verify_test_case_4(void) 3074 { 3075 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4); 3076 } 3077 3078 static int 3079 test_snow3g_hash_verify_test_case_5(void) 3080 { 3081 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5); 3082 } 3083 3084 static int 3085 test_snow3g_hash_verify_test_case_6(void) 3086 { 3087 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6); 3088 } 3089 3090 static int 3091 test_kasumi_hash_generate_test_case_1(void) 3092 { 3093 return test_kasumi_authentication(&kasumi_hash_test_case_1); 3094 } 3095 3096 static int 3097 test_kasumi_hash_generate_test_case_2(void) 3098 { 3099 return test_kasumi_authentication(&kasumi_hash_test_case_2); 3100 } 3101 3102 static int 3103 test_kasumi_hash_generate_test_case_3(void) 3104 { 3105 return test_kasumi_authentication(&kasumi_hash_test_case_3); 3106 } 3107 3108 static int 3109 test_kasumi_hash_generate_test_case_4(void) 3110 { 3111 return test_kasumi_authentication(&kasumi_hash_test_case_4); 3112 } 3113 3114 static int 3115 test_kasumi_hash_generate_test_case_5(void) 3116 { 3117 return test_kasumi_authentication(&kasumi_hash_test_case_5); 3118 } 3119 3120 static int 3121 test_kasumi_hash_generate_test_case_6(void) 3122 { 3123 return test_kasumi_authentication(&kasumi_hash_test_case_6); 3124 } 3125 3126 static int 3127 test_kasumi_hash_verify_test_case_1(void) 3128 { 3129 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1); 3130 } 3131 3132 static int 3133 test_kasumi_hash_verify_test_case_2(void) 3134 { 3135 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2); 3136 } 3137 3138 static int 3139 test_kasumi_hash_verify_test_case_3(void) 3140 { 3141 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3); 3142 } 3143 3144 static int 3145 test_kasumi_hash_verify_test_case_4(void) 3146 { 3147 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4); 3148 } 3149 3150 static int 3151 test_kasumi_hash_verify_test_case_5(void) 3152 { 3153 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5); 3154 } 3155 3156 static int 3157 test_kasumi_encryption(const struct kasumi_test_data *tdata) 3158 { 3159 struct crypto_testsuite_params *ts_params = &testsuite_params; 3160 struct crypto_unittest_params *ut_params = &unittest_params; 3161 3162 int retval; 3163 uint8_t *plaintext, *ciphertext; 3164 unsigned plaintext_pad_len; 3165 unsigned plaintext_len; 3166 struct rte_cryptodev_info dev_info; 3167 3168 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3169 uint64_t feat_flags = dev_info.feature_flags; 3170 3171 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3172 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3173 printf("Device doesn't support RAW data-path APIs.\n"); 3174 return -ENOTSUP; 3175 } 3176 3177 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3178 return -ENOTSUP; 3179 3180 /* Verify the capabilities */ 3181 struct rte_cryptodev_sym_capability_idx cap_idx; 3182 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3183 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3184 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3185 &cap_idx) == NULL) 3186 return -ENOTSUP; 3187 3188 /* Create KASUMI session */ 3189 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3190 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3191 RTE_CRYPTO_CIPHER_KASUMI_F8, 3192 tdata->key.data, tdata->key.len, 3193 tdata->cipher_iv.len); 3194 if (retval < 0) 3195 return retval; 3196 3197 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3198 3199 /* Clear mbuf payload */ 3200 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3201 rte_pktmbuf_tailroom(ut_params->ibuf)); 3202 3203 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3204 /* Append data which is padded to a multiple */ 3205 /* of the algorithms block size */ 3206 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3207 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3208 plaintext_pad_len); 3209 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3210 3211 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3212 3213 /* Create KASUMI operation */ 3214 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3215 tdata->cipher_iv.len, 3216 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3217 tdata->validCipherOffsetInBits.len); 3218 if (retval < 0) 3219 return retval; 3220 3221 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3222 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3223 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3224 else 3225 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3226 ut_params->op); 3227 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3228 3229 ut_params->obuf = ut_params->op->sym->m_dst; 3230 if (ut_params->obuf) 3231 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3232 else 3233 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3234 3235 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3236 3237 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3238 (tdata->validCipherOffsetInBits.len >> 3); 3239 /* Validate obuf */ 3240 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3241 ciphertext, 3242 reference_ciphertext, 3243 tdata->validCipherLenInBits.len, 3244 "KASUMI Ciphertext data not as expected"); 3245 return 0; 3246 } 3247 3248 static int 3249 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata) 3250 { 3251 struct crypto_testsuite_params *ts_params = &testsuite_params; 3252 struct crypto_unittest_params *ut_params = &unittest_params; 3253 3254 int retval; 3255 3256 unsigned int plaintext_pad_len; 3257 unsigned int plaintext_len; 3258 3259 uint8_t buffer[10000]; 3260 const uint8_t *ciphertext; 3261 3262 struct rte_cryptodev_info dev_info; 3263 3264 /* Verify the capabilities */ 3265 struct rte_cryptodev_sym_capability_idx cap_idx; 3266 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3267 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3268 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3269 &cap_idx) == NULL) 3270 return -ENOTSUP; 3271 3272 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3273 3274 uint64_t feat_flags = dev_info.feature_flags; 3275 3276 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 3277 printf("Device doesn't support in-place scatter-gather. " 3278 "Test Skipped.\n"); 3279 return -ENOTSUP; 3280 } 3281 3282 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3283 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3284 printf("Device doesn't support RAW data-path APIs.\n"); 3285 return -ENOTSUP; 3286 } 3287 3288 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3289 return -ENOTSUP; 3290 3291 /* Create KASUMI session */ 3292 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3293 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3294 RTE_CRYPTO_CIPHER_KASUMI_F8, 3295 tdata->key.data, tdata->key.len, 3296 tdata->cipher_iv.len); 3297 if (retval < 0) 3298 return retval; 3299 3300 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3301 3302 3303 /* Append data which is padded to a multiple */ 3304 /* of the algorithms block size */ 3305 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3306 3307 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3308 plaintext_pad_len, 10, 0); 3309 3310 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3311 3312 /* Create KASUMI operation */ 3313 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3314 tdata->cipher_iv.len, 3315 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3316 tdata->validCipherOffsetInBits.len); 3317 if (retval < 0) 3318 return retval; 3319 3320 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3321 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3322 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3323 else 3324 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3325 ut_params->op); 3326 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3327 3328 ut_params->obuf = ut_params->op->sym->m_dst; 3329 3330 if (ut_params->obuf) 3331 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3332 plaintext_len, buffer); 3333 else 3334 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3335 tdata->validCipherOffsetInBits.len >> 3, 3336 plaintext_len, buffer); 3337 3338 /* Validate obuf */ 3339 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3340 3341 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3342 (tdata->validCipherOffsetInBits.len >> 3); 3343 /* Validate obuf */ 3344 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3345 ciphertext, 3346 reference_ciphertext, 3347 tdata->validCipherLenInBits.len, 3348 "KASUMI Ciphertext data not as expected"); 3349 return 0; 3350 } 3351 3352 static int 3353 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata) 3354 { 3355 struct crypto_testsuite_params *ts_params = &testsuite_params; 3356 struct crypto_unittest_params *ut_params = &unittest_params; 3357 3358 int retval; 3359 uint8_t *plaintext, *ciphertext; 3360 unsigned plaintext_pad_len; 3361 unsigned plaintext_len; 3362 3363 /* Verify the capabilities */ 3364 struct rte_cryptodev_sym_capability_idx cap_idx; 3365 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3366 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3367 /* Data-path service does not support OOP */ 3368 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3369 &cap_idx) == NULL) 3370 return -ENOTSUP; 3371 3372 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3373 return -ENOTSUP; 3374 3375 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3376 return -ENOTSUP; 3377 3378 /* Create KASUMI session */ 3379 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3380 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3381 RTE_CRYPTO_CIPHER_KASUMI_F8, 3382 tdata->key.data, tdata->key.len, 3383 tdata->cipher_iv.len); 3384 if (retval < 0) 3385 return retval; 3386 3387 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3388 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3389 3390 /* Clear mbuf payload */ 3391 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3392 rte_pktmbuf_tailroom(ut_params->ibuf)); 3393 3394 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3395 /* Append data which is padded to a multiple */ 3396 /* of the algorithms block size */ 3397 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3398 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3399 plaintext_pad_len); 3400 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3401 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3402 3403 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3404 3405 /* Create KASUMI operation */ 3406 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3407 tdata->cipher_iv.len, 3408 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3409 tdata->validCipherOffsetInBits.len); 3410 if (retval < 0) 3411 return retval; 3412 3413 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3414 ut_params->op); 3415 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3416 3417 ut_params->obuf = ut_params->op->sym->m_dst; 3418 if (ut_params->obuf) 3419 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3420 else 3421 ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3); 3422 3423 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3424 3425 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3426 (tdata->validCipherOffsetInBits.len >> 3); 3427 /* Validate obuf */ 3428 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3429 ciphertext, 3430 reference_ciphertext, 3431 tdata->validCipherLenInBits.len, 3432 "KASUMI Ciphertext data not as expected"); 3433 return 0; 3434 } 3435 3436 static int 3437 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata) 3438 { 3439 struct crypto_testsuite_params *ts_params = &testsuite_params; 3440 struct crypto_unittest_params *ut_params = &unittest_params; 3441 3442 int retval; 3443 unsigned int plaintext_pad_len; 3444 unsigned int plaintext_len; 3445 3446 const uint8_t *ciphertext; 3447 uint8_t buffer[2048]; 3448 3449 struct rte_cryptodev_info dev_info; 3450 3451 /* Verify the capabilities */ 3452 struct rte_cryptodev_sym_capability_idx cap_idx; 3453 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3454 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3455 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3456 &cap_idx) == NULL) 3457 return -ENOTSUP; 3458 3459 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3460 return -ENOTSUP; 3461 3462 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3463 return -ENOTSUP; 3464 3465 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3466 3467 uint64_t feat_flags = dev_info.feature_flags; 3468 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 3469 printf("Device doesn't support out-of-place scatter-gather " 3470 "in both input and output mbufs. " 3471 "Test Skipped.\n"); 3472 return -ENOTSUP; 3473 } 3474 3475 /* Create KASUMI session */ 3476 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3477 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3478 RTE_CRYPTO_CIPHER_KASUMI_F8, 3479 tdata->key.data, tdata->key.len, 3480 tdata->cipher_iv.len); 3481 if (retval < 0) 3482 return retval; 3483 3484 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3485 /* Append data which is padded to a multiple */ 3486 /* of the algorithms block size */ 3487 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 3488 3489 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3490 plaintext_pad_len, 10, 0); 3491 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 3492 plaintext_pad_len, 3, 0); 3493 3494 /* Append data which is padded to a multiple */ 3495 /* of the algorithms block size */ 3496 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3497 3498 /* Create KASUMI operation */ 3499 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3500 tdata->cipher_iv.len, 3501 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3502 tdata->validCipherOffsetInBits.len); 3503 if (retval < 0) 3504 return retval; 3505 3506 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3507 ut_params->op); 3508 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3509 3510 ut_params->obuf = ut_params->op->sym->m_dst; 3511 if (ut_params->obuf) 3512 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3513 plaintext_pad_len, buffer); 3514 else 3515 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 3516 tdata->validCipherOffsetInBits.len >> 3, 3517 plaintext_pad_len, buffer); 3518 3519 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 3520 (tdata->validCipherOffsetInBits.len >> 3); 3521 /* Validate obuf */ 3522 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3523 ciphertext, 3524 reference_ciphertext, 3525 tdata->validCipherLenInBits.len, 3526 "KASUMI Ciphertext data not as expected"); 3527 return 0; 3528 } 3529 3530 3531 static int 3532 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata) 3533 { 3534 struct crypto_testsuite_params *ts_params = &testsuite_params; 3535 struct crypto_unittest_params *ut_params = &unittest_params; 3536 3537 int retval; 3538 uint8_t *ciphertext, *plaintext; 3539 unsigned ciphertext_pad_len; 3540 unsigned ciphertext_len; 3541 3542 /* Verify the capabilities */ 3543 struct rte_cryptodev_sym_capability_idx cap_idx; 3544 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3545 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3546 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3547 &cap_idx) == NULL) 3548 return -ENOTSUP; 3549 3550 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3551 return -ENOTSUP; 3552 3553 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3554 return -ENOTSUP; 3555 3556 /* Create KASUMI session */ 3557 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3558 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3559 RTE_CRYPTO_CIPHER_KASUMI_F8, 3560 tdata->key.data, tdata->key.len, 3561 tdata->cipher_iv.len); 3562 if (retval < 0) 3563 return retval; 3564 3565 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3566 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3567 3568 /* Clear mbuf payload */ 3569 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3570 rte_pktmbuf_tailroom(ut_params->ibuf)); 3571 3572 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 3573 /* Append data which is padded to a multiple */ 3574 /* of the algorithms block size */ 3575 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 3576 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3577 ciphertext_pad_len); 3578 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 3579 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 3580 3581 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 3582 3583 /* Create KASUMI operation */ 3584 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3585 tdata->cipher_iv.len, 3586 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 3587 tdata->validCipherOffsetInBits.len); 3588 if (retval < 0) 3589 return retval; 3590 3591 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3592 ut_params->op); 3593 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3594 3595 ut_params->obuf = ut_params->op->sym->m_dst; 3596 if (ut_params->obuf) 3597 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3598 else 3599 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 3600 3601 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 3602 3603 const uint8_t *reference_plaintext = tdata->plaintext.data + 3604 (tdata->validCipherOffsetInBits.len >> 3); 3605 /* Validate obuf */ 3606 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3607 plaintext, 3608 reference_plaintext, 3609 tdata->validCipherLenInBits.len, 3610 "KASUMI Plaintext data not as expected"); 3611 return 0; 3612 } 3613 3614 static int 3615 test_kasumi_decryption(const struct kasumi_test_data *tdata) 3616 { 3617 struct crypto_testsuite_params *ts_params = &testsuite_params; 3618 struct crypto_unittest_params *ut_params = &unittest_params; 3619 3620 int retval; 3621 uint8_t *ciphertext, *plaintext; 3622 unsigned ciphertext_pad_len; 3623 unsigned ciphertext_len; 3624 struct rte_cryptodev_info dev_info; 3625 3626 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3627 uint64_t feat_flags = dev_info.feature_flags; 3628 3629 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3630 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3631 printf("Device doesn't support RAW data-path APIs.\n"); 3632 return -ENOTSUP; 3633 } 3634 3635 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3636 return -ENOTSUP; 3637 3638 /* Verify the capabilities */ 3639 struct rte_cryptodev_sym_capability_idx cap_idx; 3640 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3641 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 3642 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3643 &cap_idx) == NULL) 3644 return -ENOTSUP; 3645 3646 /* Create KASUMI session */ 3647 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3648 RTE_CRYPTO_CIPHER_OP_DECRYPT, 3649 RTE_CRYPTO_CIPHER_KASUMI_F8, 3650 tdata->key.data, tdata->key.len, 3651 tdata->cipher_iv.len); 3652 if (retval < 0) 3653 return retval; 3654 3655 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3656 3657 /* Clear mbuf payload */ 3658 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3659 rte_pktmbuf_tailroom(ut_params->ibuf)); 3660 3661 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 3662 /* Append data which is padded to a multiple */ 3663 /* of the algorithms block size */ 3664 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8); 3665 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3666 ciphertext_pad_len); 3667 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 3668 3669 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 3670 3671 /* Create KASUMI operation */ 3672 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3673 tdata->cipher_iv.len, 3674 tdata->ciphertext.len, 3675 tdata->validCipherOffsetInBits.len); 3676 if (retval < 0) 3677 return retval; 3678 3679 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3680 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3681 ut_params->op, 1, 0, 1, 0); 3682 else 3683 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3684 ut_params->op); 3685 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3686 3687 ut_params->obuf = ut_params->op->sym->m_dst; 3688 if (ut_params->obuf) 3689 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3690 else 3691 plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3); 3692 3693 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 3694 3695 const uint8_t *reference_plaintext = tdata->plaintext.data + 3696 (tdata->validCipherOffsetInBits.len >> 3); 3697 /* Validate obuf */ 3698 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3699 plaintext, 3700 reference_plaintext, 3701 tdata->validCipherLenInBits.len, 3702 "KASUMI Plaintext data not as expected"); 3703 return 0; 3704 } 3705 3706 static int 3707 test_snow3g_encryption(const struct snow3g_test_data *tdata) 3708 { 3709 struct crypto_testsuite_params *ts_params = &testsuite_params; 3710 struct crypto_unittest_params *ut_params = &unittest_params; 3711 3712 int retval; 3713 uint8_t *plaintext, *ciphertext; 3714 unsigned plaintext_pad_len; 3715 unsigned plaintext_len; 3716 struct rte_cryptodev_info dev_info; 3717 3718 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3719 uint64_t feat_flags = dev_info.feature_flags; 3720 3721 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 3722 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 3723 printf("Device doesn't support RAW data-path APIs.\n"); 3724 return -ENOTSUP; 3725 } 3726 3727 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3728 return -ENOTSUP; 3729 3730 /* Verify the capabilities */ 3731 struct rte_cryptodev_sym_capability_idx cap_idx; 3732 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3733 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3734 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3735 &cap_idx) == NULL) 3736 return -ENOTSUP; 3737 3738 /* Create SNOW 3G session */ 3739 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3740 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3741 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3742 tdata->key.data, tdata->key.len, 3743 tdata->cipher_iv.len); 3744 if (retval < 0) 3745 return retval; 3746 3747 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3748 3749 /* Clear mbuf payload */ 3750 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3751 rte_pktmbuf_tailroom(ut_params->ibuf)); 3752 3753 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3754 /* Append data which is padded to a multiple of */ 3755 /* the algorithms block size */ 3756 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3757 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3758 plaintext_pad_len); 3759 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3760 3761 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3762 3763 /* Create SNOW 3G operation */ 3764 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 3765 tdata->cipher_iv.len, 3766 tdata->validCipherLenInBits.len, 3767 0); 3768 if (retval < 0) 3769 return retval; 3770 3771 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3772 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 3773 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 3774 else 3775 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3776 ut_params->op); 3777 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3778 3779 ut_params->obuf = ut_params->op->sym->m_dst; 3780 if (ut_params->obuf) 3781 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3782 else 3783 ciphertext = plaintext; 3784 3785 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3786 3787 /* Validate obuf */ 3788 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3789 ciphertext, 3790 tdata->ciphertext.data, 3791 tdata->validDataLenInBits.len, 3792 "SNOW 3G Ciphertext data not as expected"); 3793 return 0; 3794 } 3795 3796 3797 static int 3798 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) 3799 { 3800 struct crypto_testsuite_params *ts_params = &testsuite_params; 3801 struct crypto_unittest_params *ut_params = &unittest_params; 3802 uint8_t *plaintext, *ciphertext; 3803 3804 int retval; 3805 unsigned plaintext_pad_len; 3806 unsigned plaintext_len; 3807 3808 /* Verify the capabilities */ 3809 struct rte_cryptodev_sym_capability_idx cap_idx; 3810 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3811 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3812 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3813 &cap_idx) == NULL) 3814 return -ENOTSUP; 3815 3816 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3817 return -ENOTSUP; 3818 3819 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3820 return -ENOTSUP; 3821 3822 /* Create SNOW 3G session */ 3823 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3824 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3825 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3826 tdata->key.data, tdata->key.len, 3827 tdata->cipher_iv.len); 3828 if (retval < 0) 3829 return retval; 3830 3831 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3832 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 3833 3834 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 3835 "Failed to allocate input buffer in mempool"); 3836 TEST_ASSERT_NOT_NULL(ut_params->obuf, 3837 "Failed to allocate output buffer in mempool"); 3838 3839 /* Clear mbuf payload */ 3840 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 3841 rte_pktmbuf_tailroom(ut_params->ibuf)); 3842 3843 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3844 /* Append data which is padded to a multiple of */ 3845 /* the algorithms block size */ 3846 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3847 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 3848 plaintext_pad_len); 3849 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 3850 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 3851 3852 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 3853 3854 /* Create SNOW 3G operation */ 3855 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3856 tdata->cipher_iv.len, 3857 tdata->validCipherLenInBits.len, 3858 0); 3859 if (retval < 0) 3860 return retval; 3861 3862 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3863 ut_params->op); 3864 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3865 3866 ut_params->obuf = ut_params->op->sym->m_dst; 3867 if (ut_params->obuf) 3868 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 3869 else 3870 ciphertext = plaintext; 3871 3872 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3873 3874 /* Validate obuf */ 3875 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3876 ciphertext, 3877 tdata->ciphertext.data, 3878 tdata->validDataLenInBits.len, 3879 "SNOW 3G Ciphertext data not as expected"); 3880 return 0; 3881 } 3882 3883 static int 3884 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata) 3885 { 3886 struct crypto_testsuite_params *ts_params = &testsuite_params; 3887 struct crypto_unittest_params *ut_params = &unittest_params; 3888 3889 int retval; 3890 unsigned int plaintext_pad_len; 3891 unsigned int plaintext_len; 3892 uint8_t buffer[10000]; 3893 const uint8_t *ciphertext; 3894 3895 struct rte_cryptodev_info dev_info; 3896 3897 /* Verify the capabilities */ 3898 struct rte_cryptodev_sym_capability_idx cap_idx; 3899 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 3900 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 3901 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 3902 &cap_idx) == NULL) 3903 return -ENOTSUP; 3904 3905 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 3906 return -ENOTSUP; 3907 3908 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 3909 return -ENOTSUP; 3910 3911 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 3912 3913 uint64_t feat_flags = dev_info.feature_flags; 3914 3915 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 3916 printf("Device doesn't support out-of-place scatter-gather " 3917 "in both input and output mbufs. " 3918 "Test Skipped.\n"); 3919 return -ENOTSUP; 3920 } 3921 3922 /* Create SNOW 3G session */ 3923 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 3924 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 3925 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 3926 tdata->key.data, tdata->key.len, 3927 tdata->cipher_iv.len); 3928 if (retval < 0) 3929 return retval; 3930 3931 plaintext_len = ceil_byte_length(tdata->plaintext.len); 3932 /* Append data which is padded to a multiple of */ 3933 /* the algorithms block size */ 3934 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 3935 3936 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 3937 plaintext_pad_len, 10, 0); 3938 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 3939 plaintext_pad_len, 3, 0); 3940 3941 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 3942 "Failed to allocate input buffer in mempool"); 3943 TEST_ASSERT_NOT_NULL(ut_params->obuf, 3944 "Failed to allocate output buffer in mempool"); 3945 3946 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 3947 3948 /* Create SNOW 3G operation */ 3949 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 3950 tdata->cipher_iv.len, 3951 tdata->validCipherLenInBits.len, 3952 0); 3953 if (retval < 0) 3954 return retval; 3955 3956 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 3957 ut_params->op); 3958 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 3959 3960 ut_params->obuf = ut_params->op->sym->m_dst; 3961 if (ut_params->obuf) 3962 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 3963 plaintext_len, buffer); 3964 else 3965 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 3966 plaintext_len, buffer); 3967 3968 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 3969 3970 /* Validate obuf */ 3971 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 3972 ciphertext, 3973 tdata->ciphertext.data, 3974 tdata->validDataLenInBits.len, 3975 "SNOW 3G Ciphertext data not as expected"); 3976 3977 return 0; 3978 } 3979 3980 /* Shift right a buffer by "offset" bits, "offset" < 8 */ 3981 static void 3982 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) 3983 { 3984 uint8_t curr_byte, prev_byte; 3985 uint32_t length_in_bytes = ceil_byte_length(length + offset); 3986 uint8_t lower_byte_mask = (1 << offset) - 1; 3987 unsigned i; 3988 3989 prev_byte = buffer[0]; 3990 buffer[0] >>= offset; 3991 3992 for (i = 1; i < length_in_bytes; i++) { 3993 curr_byte = buffer[i]; 3994 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | 3995 (curr_byte >> offset); 3996 prev_byte = curr_byte; 3997 } 3998 } 3999 4000 static int 4001 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) 4002 { 4003 struct crypto_testsuite_params *ts_params = &testsuite_params; 4004 struct crypto_unittest_params *ut_params = &unittest_params; 4005 uint8_t *plaintext, *ciphertext; 4006 int retval; 4007 uint32_t plaintext_len; 4008 uint32_t plaintext_pad_len; 4009 uint8_t extra_offset = 4; 4010 uint8_t *expected_ciphertext_shifted; 4011 struct rte_cryptodev_info dev_info; 4012 4013 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4014 uint64_t feat_flags = dev_info.feature_flags; 4015 4016 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4017 ((tdata->validDataLenInBits.len % 8) != 0)) { 4018 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4019 return -ENOTSUP; 4020 } 4021 4022 /* Verify the capabilities */ 4023 struct rte_cryptodev_sym_capability_idx cap_idx; 4024 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4025 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4026 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4027 &cap_idx) == NULL) 4028 return -ENOTSUP; 4029 4030 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4031 return -ENOTSUP; 4032 4033 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4034 return -ENOTSUP; 4035 4036 /* Create SNOW 3G session */ 4037 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4038 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4039 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4040 tdata->key.data, tdata->key.len, 4041 tdata->cipher_iv.len); 4042 if (retval < 0) 4043 return retval; 4044 4045 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4046 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4047 4048 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4049 "Failed to allocate input buffer in mempool"); 4050 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4051 "Failed to allocate output buffer in mempool"); 4052 4053 /* Clear mbuf payload */ 4054 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4055 rte_pktmbuf_tailroom(ut_params->ibuf)); 4056 4057 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset); 4058 /* 4059 * Append data which is padded to a 4060 * multiple of the algorithms block size 4061 */ 4062 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4063 4064 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf, 4065 plaintext_pad_len); 4066 4067 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4068 4069 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3)); 4070 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); 4071 4072 #ifdef RTE_APP_TEST_DEBUG 4073 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); 4074 #endif 4075 /* Create SNOW 3G operation */ 4076 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4077 tdata->cipher_iv.len, 4078 tdata->validCipherLenInBits.len, 4079 extra_offset); 4080 if (retval < 0) 4081 return retval; 4082 4083 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4084 ut_params->op); 4085 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4086 4087 ut_params->obuf = ut_params->op->sym->m_dst; 4088 if (ut_params->obuf) 4089 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4090 else 4091 ciphertext = plaintext; 4092 4093 #ifdef RTE_APP_TEST_DEBUG 4094 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4095 #endif 4096 4097 expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8); 4098 4099 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, 4100 "failed to reserve memory for ciphertext shifted\n"); 4101 4102 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, 4103 ceil_byte_length(tdata->ciphertext.len)); 4104 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, 4105 extra_offset); 4106 /* Validate obuf */ 4107 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( 4108 ciphertext, 4109 expected_ciphertext_shifted, 4110 tdata->validDataLenInBits.len, 4111 extra_offset, 4112 "SNOW 3G Ciphertext data not as expected"); 4113 return 0; 4114 } 4115 4116 static int test_snow3g_decryption(const struct snow3g_test_data *tdata) 4117 { 4118 struct crypto_testsuite_params *ts_params = &testsuite_params; 4119 struct crypto_unittest_params *ut_params = &unittest_params; 4120 4121 int retval; 4122 4123 uint8_t *plaintext, *ciphertext; 4124 unsigned ciphertext_pad_len; 4125 unsigned ciphertext_len; 4126 struct rte_cryptodev_info dev_info; 4127 4128 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4129 uint64_t feat_flags = dev_info.feature_flags; 4130 4131 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4132 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4133 printf("Device doesn't support RAW data-path APIs.\n"); 4134 return -ENOTSUP; 4135 } 4136 4137 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4138 return -ENOTSUP; 4139 4140 /* Verify the capabilities */ 4141 struct rte_cryptodev_sym_capability_idx cap_idx; 4142 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4143 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4144 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4145 &cap_idx) == NULL) 4146 return -ENOTSUP; 4147 4148 /* Create SNOW 3G session */ 4149 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4150 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4151 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4152 tdata->key.data, tdata->key.len, 4153 tdata->cipher_iv.len); 4154 if (retval < 0) 4155 return retval; 4156 4157 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4158 4159 /* Clear mbuf payload */ 4160 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4161 rte_pktmbuf_tailroom(ut_params->ibuf)); 4162 4163 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4164 /* Append data which is padded to a multiple of */ 4165 /* the algorithms block size */ 4166 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4167 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4168 ciphertext_pad_len); 4169 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4170 4171 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4172 4173 /* Create SNOW 3G operation */ 4174 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 4175 tdata->cipher_iv.len, 4176 tdata->validCipherLenInBits.len, 4177 tdata->cipher.offset_bits); 4178 if (retval < 0) 4179 return retval; 4180 4181 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4182 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4183 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 4184 else 4185 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4186 ut_params->op); 4187 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4188 ut_params->obuf = ut_params->op->sym->m_dst; 4189 if (ut_params->obuf) 4190 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4191 else 4192 plaintext = ciphertext; 4193 4194 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4195 4196 /* Validate obuf */ 4197 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4198 tdata->plaintext.data, 4199 tdata->validDataLenInBits.len, 4200 "SNOW 3G Plaintext data not as expected"); 4201 return 0; 4202 } 4203 4204 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) 4205 { 4206 struct crypto_testsuite_params *ts_params = &testsuite_params; 4207 struct crypto_unittest_params *ut_params = &unittest_params; 4208 4209 int retval; 4210 4211 uint8_t *plaintext, *ciphertext; 4212 unsigned ciphertext_pad_len; 4213 unsigned ciphertext_len; 4214 4215 /* Verify the capabilities */ 4216 struct rte_cryptodev_sym_capability_idx cap_idx; 4217 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4218 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4219 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4220 &cap_idx) == NULL) 4221 return -ENOTSUP; 4222 4223 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4224 return -ENOTSUP; 4225 4226 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4227 return -ENOTSUP; 4228 4229 /* Create SNOW 3G session */ 4230 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 4231 RTE_CRYPTO_CIPHER_OP_DECRYPT, 4232 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4233 tdata->key.data, tdata->key.len, 4234 tdata->cipher_iv.len); 4235 if (retval < 0) 4236 return retval; 4237 4238 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4239 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4240 4241 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4242 "Failed to allocate input buffer"); 4243 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4244 "Failed to allocate output buffer"); 4245 4246 /* Clear mbuf payload */ 4247 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4248 rte_pktmbuf_tailroom(ut_params->ibuf)); 4249 4250 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4251 rte_pktmbuf_tailroom(ut_params->obuf)); 4252 4253 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4254 /* Append data which is padded to a multiple of */ 4255 /* the algorithms block size */ 4256 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4257 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4258 ciphertext_pad_len); 4259 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4260 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4261 4262 debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len); 4263 4264 /* Create SNOW 3G operation */ 4265 retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data, 4266 tdata->cipher_iv.len, 4267 tdata->validCipherLenInBits.len, 4268 0); 4269 if (retval < 0) 4270 return retval; 4271 4272 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4273 ut_params->op); 4274 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4275 ut_params->obuf = ut_params->op->sym->m_dst; 4276 if (ut_params->obuf) 4277 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4278 else 4279 plaintext = ciphertext; 4280 4281 debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); 4282 4283 /* Validate obuf */ 4284 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, 4285 tdata->plaintext.data, 4286 tdata->validDataLenInBits.len, 4287 "SNOW 3G Plaintext data not as expected"); 4288 return 0; 4289 } 4290 4291 static int 4292 test_zuc_cipher_auth(const struct wireless_test_data *tdata) 4293 { 4294 struct crypto_testsuite_params *ts_params = &testsuite_params; 4295 struct crypto_unittest_params *ut_params = &unittest_params; 4296 4297 int retval; 4298 4299 uint8_t *plaintext, *ciphertext; 4300 unsigned int plaintext_pad_len; 4301 unsigned int plaintext_len; 4302 4303 struct rte_cryptodev_info dev_info; 4304 struct rte_cryptodev_sym_capability_idx cap_idx; 4305 4306 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4307 uint64_t feat_flags = dev_info.feature_flags; 4308 4309 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 4310 ((tdata->validAuthLenInBits.len % 8 != 0) || 4311 (tdata->validDataLenInBits.len % 8 != 0))) { 4312 printf("Device doesn't support NON-Byte Aligned Data.\n"); 4313 return -ENOTSUP; 4314 } 4315 4316 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4317 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4318 printf("Device doesn't support RAW data-path APIs.\n"); 4319 return -ENOTSUP; 4320 } 4321 4322 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4323 return -ENOTSUP; 4324 4325 /* Check if device supports ZUC EEA3 */ 4326 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4327 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 4328 4329 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4330 &cap_idx) == NULL) 4331 return -ENOTSUP; 4332 4333 /* Check if device supports ZUC EIA3 */ 4334 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4335 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 4336 4337 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4338 &cap_idx) == NULL) 4339 return -ENOTSUP; 4340 4341 /* Create ZUC session */ 4342 retval = create_zuc_cipher_auth_encrypt_generate_session( 4343 ts_params->valid_devs[0], 4344 tdata); 4345 if (retval < 0) 4346 return retval; 4347 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4348 4349 /* clear mbuf payload */ 4350 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4351 rte_pktmbuf_tailroom(ut_params->ibuf)); 4352 4353 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4354 /* Append data which is padded to a multiple of */ 4355 /* the algorithms block size */ 4356 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4357 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4358 plaintext_pad_len); 4359 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4360 4361 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4362 4363 /* Create ZUC operation */ 4364 retval = create_zuc_cipher_hash_generate_operation(tdata); 4365 if (retval < 0) 4366 return retval; 4367 4368 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4369 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4370 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4371 else 4372 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4373 ut_params->op); 4374 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4375 ut_params->obuf = ut_params->op->sym->m_src; 4376 if (ut_params->obuf) 4377 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4378 else 4379 ciphertext = plaintext; 4380 4381 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4382 /* Validate obuf */ 4383 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4384 ciphertext, 4385 tdata->ciphertext.data, 4386 tdata->validDataLenInBits.len, 4387 "ZUC Ciphertext data not as expected"); 4388 4389 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4390 + plaintext_pad_len; 4391 4392 /* Validate obuf */ 4393 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4394 ut_params->digest, 4395 tdata->digest.data, 4396 4, 4397 "ZUC Generated auth tag not as expected"); 4398 return 0; 4399 } 4400 4401 static int 4402 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) 4403 { 4404 struct crypto_testsuite_params *ts_params = &testsuite_params; 4405 struct crypto_unittest_params *ut_params = &unittest_params; 4406 4407 int retval; 4408 4409 uint8_t *plaintext, *ciphertext; 4410 unsigned plaintext_pad_len; 4411 unsigned plaintext_len; 4412 struct rte_cryptodev_info dev_info; 4413 4414 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4415 uint64_t feat_flags = dev_info.feature_flags; 4416 4417 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4418 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4419 printf("Device doesn't support RAW data-path APIs.\n"); 4420 return -ENOTSUP; 4421 } 4422 4423 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4424 return -ENOTSUP; 4425 4426 /* Verify the capabilities */ 4427 struct rte_cryptodev_sym_capability_idx cap_idx; 4428 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4429 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4430 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4431 &cap_idx) == NULL) 4432 return -ENOTSUP; 4433 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4434 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4435 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4436 &cap_idx) == NULL) 4437 return -ENOTSUP; 4438 4439 /* Create SNOW 3G session */ 4440 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0], 4441 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 4442 RTE_CRYPTO_AUTH_OP_GENERATE, 4443 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4444 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4445 tdata->key.data, tdata->key.len, 4446 tdata->auth_iv.len, tdata->digest.len, 4447 tdata->cipher_iv.len); 4448 if (retval < 0) 4449 return retval; 4450 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4451 4452 /* clear mbuf payload */ 4453 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4454 rte_pktmbuf_tailroom(ut_params->ibuf)); 4455 4456 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4457 /* Append data which is padded to a multiple of */ 4458 /* the algorithms block size */ 4459 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4460 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4461 plaintext_pad_len); 4462 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4463 4464 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4465 4466 /* Create SNOW 3G operation */ 4467 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 4468 tdata->digest.len, tdata->auth_iv.data, 4469 tdata->auth_iv.len, 4470 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 4471 tdata->cipher_iv.data, tdata->cipher_iv.len, 4472 tdata->validCipherLenInBits.len, 4473 0, 4474 tdata->validAuthLenInBits.len, 4475 0 4476 ); 4477 if (retval < 0) 4478 return retval; 4479 4480 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4481 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4482 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4483 else 4484 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4485 ut_params->op); 4486 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4487 ut_params->obuf = ut_params->op->sym->m_src; 4488 if (ut_params->obuf) 4489 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 4490 else 4491 ciphertext = plaintext; 4492 4493 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 4494 /* Validate obuf */ 4495 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4496 ciphertext, 4497 tdata->ciphertext.data, 4498 tdata->validDataLenInBits.len, 4499 "SNOW 3G Ciphertext data not as expected"); 4500 4501 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4502 + plaintext_pad_len; 4503 4504 /* Validate obuf */ 4505 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4506 ut_params->digest, 4507 tdata->digest.data, 4508 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4509 "SNOW 3G Generated auth tag not as expected"); 4510 return 0; 4511 } 4512 4513 static int 4514 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata, 4515 uint8_t op_mode, uint8_t verify) 4516 { 4517 struct crypto_testsuite_params *ts_params = &testsuite_params; 4518 struct crypto_unittest_params *ut_params = &unittest_params; 4519 4520 int retval; 4521 4522 uint8_t *plaintext = NULL, *ciphertext = NULL; 4523 unsigned int plaintext_pad_len; 4524 unsigned int plaintext_len; 4525 unsigned int ciphertext_pad_len; 4526 unsigned int ciphertext_len; 4527 4528 struct rte_cryptodev_info dev_info; 4529 4530 /* Verify the capabilities */ 4531 struct rte_cryptodev_sym_capability_idx cap_idx; 4532 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4533 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4534 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4535 &cap_idx) == NULL) 4536 return -ENOTSUP; 4537 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4538 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4539 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4540 &cap_idx) == NULL) 4541 return -ENOTSUP; 4542 4543 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4544 return -ENOTSUP; 4545 4546 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4547 4548 uint64_t feat_flags = dev_info.feature_flags; 4549 4550 if (op_mode == OUT_OF_PLACE) { 4551 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 4552 printf("Device doesn't support digest encrypted.\n"); 4553 return -ENOTSUP; 4554 } 4555 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4556 return -ENOTSUP; 4557 } 4558 4559 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4560 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4561 printf("Device doesn't support RAW data-path APIs.\n"); 4562 return -ENOTSUP; 4563 } 4564 4565 /* Create SNOW 3G session */ 4566 retval = create_wireless_algo_auth_cipher_session( 4567 ts_params->valid_devs[0], 4568 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 4569 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 4570 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 4571 : RTE_CRYPTO_AUTH_OP_GENERATE), 4572 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4573 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4574 tdata->key.data, tdata->key.len, 4575 tdata->auth_iv.len, tdata->digest.len, 4576 tdata->cipher_iv.len); 4577 4578 if (retval < 0) 4579 return retval; 4580 4581 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4582 if (op_mode == OUT_OF_PLACE) 4583 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4584 4585 /* clear mbuf payload */ 4586 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4587 rte_pktmbuf_tailroom(ut_params->ibuf)); 4588 if (op_mode == OUT_OF_PLACE) 4589 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4590 rte_pktmbuf_tailroom(ut_params->obuf)); 4591 4592 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4593 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4594 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4595 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4596 4597 if (verify) { 4598 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4599 ciphertext_pad_len); 4600 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 4601 if (op_mode == OUT_OF_PLACE) 4602 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 4603 debug_hexdump(stdout, "ciphertext:", ciphertext, 4604 ciphertext_len); 4605 } else { 4606 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4607 plaintext_pad_len); 4608 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 4609 if (op_mode == OUT_OF_PLACE) 4610 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 4611 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 4612 } 4613 4614 /* Create SNOW 3G operation */ 4615 retval = create_wireless_algo_auth_cipher_operation( 4616 tdata->digest.data, tdata->digest.len, 4617 tdata->cipher_iv.data, tdata->cipher_iv.len, 4618 tdata->auth_iv.data, tdata->auth_iv.len, 4619 (tdata->digest.offset_bytes == 0 ? 4620 (verify ? ciphertext_pad_len : plaintext_pad_len) 4621 : tdata->digest.offset_bytes), 4622 tdata->validCipherLenInBits.len, 4623 tdata->cipher.offset_bits, 4624 tdata->validAuthLenInBits.len, 4625 tdata->auth.offset_bits, 4626 op_mode, 0, verify); 4627 4628 if (retval < 0) 4629 return retval; 4630 4631 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4632 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4633 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4634 else 4635 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4636 ut_params->op); 4637 4638 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4639 4640 ut_params->obuf = (op_mode == IN_PLACE ? 4641 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 4642 4643 if (verify) { 4644 if (ut_params->obuf) 4645 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 4646 uint8_t *); 4647 else 4648 plaintext = ciphertext + 4649 (tdata->cipher.offset_bits >> 3); 4650 4651 debug_hexdump(stdout, "plaintext:", plaintext, 4652 (tdata->plaintext.len >> 3) - tdata->digest.len); 4653 debug_hexdump(stdout, "plaintext expected:", 4654 tdata->plaintext.data, 4655 (tdata->plaintext.len >> 3) - tdata->digest.len); 4656 } else { 4657 if (ut_params->obuf) 4658 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 4659 uint8_t *); 4660 else 4661 ciphertext = plaintext; 4662 4663 debug_hexdump(stdout, "ciphertext:", ciphertext, 4664 ciphertext_len); 4665 debug_hexdump(stdout, "ciphertext expected:", 4666 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 4667 4668 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 4669 + (tdata->digest.offset_bytes == 0 ? 4670 plaintext_pad_len : tdata->digest.offset_bytes); 4671 4672 debug_hexdump(stdout, "digest:", ut_params->digest, 4673 tdata->digest.len); 4674 debug_hexdump(stdout, "digest expected:", tdata->digest.data, 4675 tdata->digest.len); 4676 } 4677 4678 /* Validate obuf */ 4679 if (verify) { 4680 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4681 plaintext, 4682 tdata->plaintext.data, 4683 tdata->plaintext.len >> 3, 4684 "SNOW 3G Plaintext data not as expected"); 4685 } else { 4686 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4687 ciphertext, 4688 tdata->ciphertext.data, 4689 tdata->validDataLenInBits.len, 4690 "SNOW 3G Ciphertext data not as expected"); 4691 4692 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4693 ut_params->digest, 4694 tdata->digest.data, 4695 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4696 "SNOW 3G Generated auth tag not as expected"); 4697 } 4698 return 0; 4699 } 4700 4701 static int 4702 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata, 4703 uint8_t op_mode, uint8_t verify) 4704 { 4705 struct crypto_testsuite_params *ts_params = &testsuite_params; 4706 struct crypto_unittest_params *ut_params = &unittest_params; 4707 4708 int retval; 4709 4710 const uint8_t *plaintext = NULL; 4711 const uint8_t *ciphertext = NULL; 4712 const uint8_t *digest = NULL; 4713 unsigned int plaintext_pad_len; 4714 unsigned int plaintext_len; 4715 unsigned int ciphertext_pad_len; 4716 unsigned int ciphertext_len; 4717 uint8_t buffer[10000]; 4718 uint8_t digest_buffer[10000]; 4719 4720 struct rte_cryptodev_info dev_info; 4721 4722 /* Verify the capabilities */ 4723 struct rte_cryptodev_sym_capability_idx cap_idx; 4724 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4725 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2; 4726 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4727 &cap_idx) == NULL) 4728 return -ENOTSUP; 4729 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4730 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2; 4731 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4732 &cap_idx) == NULL) 4733 return -ENOTSUP; 4734 4735 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4736 return -ENOTSUP; 4737 4738 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4739 4740 uint64_t feat_flags = dev_info.feature_flags; 4741 4742 if (op_mode == IN_PLACE) { 4743 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 4744 printf("Device doesn't support in-place scatter-gather " 4745 "in both input and output mbufs.\n"); 4746 return -ENOTSUP; 4747 } 4748 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4749 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4750 printf("Device doesn't support RAW data-path APIs.\n"); 4751 return -ENOTSUP; 4752 } 4753 } else { 4754 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4755 return -ENOTSUP; 4756 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 4757 printf("Device doesn't support out-of-place scatter-gather " 4758 "in both input and output mbufs.\n"); 4759 return -ENOTSUP; 4760 } 4761 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 4762 printf("Device doesn't support digest encrypted.\n"); 4763 return -ENOTSUP; 4764 } 4765 } 4766 4767 /* Create SNOW 3G session */ 4768 retval = create_wireless_algo_auth_cipher_session( 4769 ts_params->valid_devs[0], 4770 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 4771 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 4772 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 4773 : RTE_CRYPTO_AUTH_OP_GENERATE), 4774 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 4775 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 4776 tdata->key.data, tdata->key.len, 4777 tdata->auth_iv.len, tdata->digest.len, 4778 tdata->cipher_iv.len); 4779 4780 if (retval < 0) 4781 return retval; 4782 4783 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4784 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4785 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4786 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4787 4788 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 4789 plaintext_pad_len, 15, 0); 4790 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 4791 "Failed to allocate input buffer in mempool"); 4792 4793 if (op_mode == OUT_OF_PLACE) { 4794 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 4795 plaintext_pad_len, 15, 0); 4796 TEST_ASSERT_NOT_NULL(ut_params->obuf, 4797 "Failed to allocate output buffer in mempool"); 4798 } 4799 4800 if (verify) { 4801 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 4802 tdata->ciphertext.data); 4803 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4804 ciphertext_len, buffer); 4805 debug_hexdump(stdout, "ciphertext:", ciphertext, 4806 ciphertext_len); 4807 } else { 4808 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 4809 tdata->plaintext.data); 4810 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 4811 plaintext_len, buffer); 4812 debug_hexdump(stdout, "plaintext:", plaintext, 4813 plaintext_len); 4814 } 4815 memset(buffer, 0, sizeof(buffer)); 4816 4817 /* Create SNOW 3G operation */ 4818 retval = create_wireless_algo_auth_cipher_operation( 4819 tdata->digest.data, tdata->digest.len, 4820 tdata->cipher_iv.data, tdata->cipher_iv.len, 4821 tdata->auth_iv.data, tdata->auth_iv.len, 4822 (tdata->digest.offset_bytes == 0 ? 4823 (verify ? ciphertext_pad_len : plaintext_pad_len) 4824 : tdata->digest.offset_bytes), 4825 tdata->validCipherLenInBits.len, 4826 tdata->cipher.offset_bits, 4827 tdata->validAuthLenInBits.len, 4828 tdata->auth.offset_bits, 4829 op_mode, 1, verify); 4830 4831 if (retval < 0) 4832 return retval; 4833 4834 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4835 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 4836 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 4837 else 4838 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 4839 ut_params->op); 4840 4841 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 4842 4843 ut_params->obuf = (op_mode == IN_PLACE ? 4844 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 4845 4846 if (verify) { 4847 if (ut_params->obuf) 4848 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 4849 plaintext_len, buffer); 4850 else 4851 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 4852 plaintext_len, buffer); 4853 4854 debug_hexdump(stdout, "plaintext:", plaintext, 4855 (tdata->plaintext.len >> 3) - tdata->digest.len); 4856 debug_hexdump(stdout, "plaintext expected:", 4857 tdata->plaintext.data, 4858 (tdata->plaintext.len >> 3) - tdata->digest.len); 4859 } else { 4860 if (ut_params->obuf) 4861 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 4862 ciphertext_len, buffer); 4863 else 4864 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 4865 ciphertext_len, buffer); 4866 4867 debug_hexdump(stdout, "ciphertext:", ciphertext, 4868 ciphertext_len); 4869 debug_hexdump(stdout, "ciphertext expected:", 4870 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 4871 4872 if (ut_params->obuf) 4873 digest = rte_pktmbuf_read(ut_params->obuf, 4874 (tdata->digest.offset_bytes == 0 ? 4875 plaintext_pad_len : tdata->digest.offset_bytes), 4876 tdata->digest.len, digest_buffer); 4877 else 4878 digest = rte_pktmbuf_read(ut_params->ibuf, 4879 (tdata->digest.offset_bytes == 0 ? 4880 plaintext_pad_len : tdata->digest.offset_bytes), 4881 tdata->digest.len, digest_buffer); 4882 4883 debug_hexdump(stdout, "digest:", digest, 4884 tdata->digest.len); 4885 debug_hexdump(stdout, "digest expected:", 4886 tdata->digest.data, tdata->digest.len); 4887 } 4888 4889 /* Validate obuf */ 4890 if (verify) { 4891 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4892 plaintext, 4893 tdata->plaintext.data, 4894 tdata->plaintext.len >> 3, 4895 "SNOW 3G Plaintext data not as expected"); 4896 } else { 4897 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 4898 ciphertext, 4899 tdata->ciphertext.data, 4900 tdata->validDataLenInBits.len, 4901 "SNOW 3G Ciphertext data not as expected"); 4902 4903 TEST_ASSERT_BUFFERS_ARE_EQUAL( 4904 digest, 4905 tdata->digest.data, 4906 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 4907 "SNOW 3G Generated auth tag not as expected"); 4908 } 4909 return 0; 4910 } 4911 4912 static int 4913 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata, 4914 uint8_t op_mode, uint8_t verify) 4915 { 4916 struct crypto_testsuite_params *ts_params = &testsuite_params; 4917 struct crypto_unittest_params *ut_params = &unittest_params; 4918 4919 int retval; 4920 4921 uint8_t *plaintext = NULL, *ciphertext = NULL; 4922 unsigned int plaintext_pad_len; 4923 unsigned int plaintext_len; 4924 unsigned int ciphertext_pad_len; 4925 unsigned int ciphertext_len; 4926 4927 struct rte_cryptodev_info dev_info; 4928 4929 /* Verify the capabilities */ 4930 struct rte_cryptodev_sym_capability_idx cap_idx; 4931 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 4932 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 4933 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4934 &cap_idx) == NULL) 4935 return -ENOTSUP; 4936 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 4937 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 4938 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 4939 &cap_idx) == NULL) 4940 return -ENOTSUP; 4941 4942 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 4943 4944 uint64_t feat_flags = dev_info.feature_flags; 4945 4946 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 4947 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 4948 printf("Device doesn't support RAW data-path APIs.\n"); 4949 return -ENOTSUP; 4950 } 4951 4952 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 4953 return -ENOTSUP; 4954 4955 if (op_mode == OUT_OF_PLACE) { 4956 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 4957 return -ENOTSUP; 4958 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 4959 printf("Device doesn't support digest encrypted.\n"); 4960 return -ENOTSUP; 4961 } 4962 } 4963 4964 /* Create KASUMI session */ 4965 retval = create_wireless_algo_auth_cipher_session( 4966 ts_params->valid_devs[0], 4967 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 4968 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 4969 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 4970 : RTE_CRYPTO_AUTH_OP_GENERATE), 4971 RTE_CRYPTO_AUTH_KASUMI_F9, 4972 RTE_CRYPTO_CIPHER_KASUMI_F8, 4973 tdata->key.data, tdata->key.len, 4974 0, tdata->digest.len, 4975 tdata->cipher_iv.len); 4976 4977 if (retval < 0) 4978 return retval; 4979 4980 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4981 if (op_mode == OUT_OF_PLACE) 4982 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 4983 4984 /* clear mbuf payload */ 4985 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 4986 rte_pktmbuf_tailroom(ut_params->ibuf)); 4987 if (op_mode == OUT_OF_PLACE) 4988 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 4989 rte_pktmbuf_tailroom(ut_params->obuf)); 4990 4991 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 4992 plaintext_len = ceil_byte_length(tdata->plaintext.len); 4993 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 4994 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 4995 4996 if (verify) { 4997 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 4998 ciphertext_pad_len); 4999 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5000 if (op_mode == OUT_OF_PLACE) 5001 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5002 debug_hexdump(stdout, "ciphertext:", ciphertext, 5003 ciphertext_len); 5004 } else { 5005 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5006 plaintext_pad_len); 5007 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5008 if (op_mode == OUT_OF_PLACE) 5009 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5010 debug_hexdump(stdout, "plaintext:", plaintext, 5011 plaintext_len); 5012 } 5013 5014 /* Create KASUMI operation */ 5015 retval = create_wireless_algo_auth_cipher_operation( 5016 tdata->digest.data, tdata->digest.len, 5017 tdata->cipher_iv.data, tdata->cipher_iv.len, 5018 NULL, 0, 5019 (tdata->digest.offset_bytes == 0 ? 5020 (verify ? ciphertext_pad_len : plaintext_pad_len) 5021 : tdata->digest.offset_bytes), 5022 tdata->validCipherLenInBits.len, 5023 tdata->validCipherOffsetInBits.len, 5024 tdata->validAuthLenInBits.len, 5025 0, 5026 op_mode, 0, verify); 5027 5028 if (retval < 0) 5029 return retval; 5030 5031 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5032 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5033 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5034 else 5035 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5036 ut_params->op); 5037 5038 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5039 5040 ut_params->obuf = (op_mode == IN_PLACE ? 5041 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5042 5043 5044 if (verify) { 5045 if (ut_params->obuf) 5046 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5047 uint8_t *); 5048 else 5049 plaintext = ciphertext; 5050 5051 debug_hexdump(stdout, "plaintext:", plaintext, 5052 (tdata->plaintext.len >> 3) - tdata->digest.len); 5053 debug_hexdump(stdout, "plaintext expected:", 5054 tdata->plaintext.data, 5055 (tdata->plaintext.len >> 3) - tdata->digest.len); 5056 } else { 5057 if (ut_params->obuf) 5058 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5059 uint8_t *); 5060 else 5061 ciphertext = plaintext; 5062 5063 debug_hexdump(stdout, "ciphertext:", ciphertext, 5064 ciphertext_len); 5065 debug_hexdump(stdout, "ciphertext expected:", 5066 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5067 5068 ut_params->digest = rte_pktmbuf_mtod( 5069 ut_params->obuf, uint8_t *) + 5070 (tdata->digest.offset_bytes == 0 ? 5071 plaintext_pad_len : tdata->digest.offset_bytes); 5072 5073 debug_hexdump(stdout, "digest:", ut_params->digest, 5074 tdata->digest.len); 5075 debug_hexdump(stdout, "digest expected:", 5076 tdata->digest.data, tdata->digest.len); 5077 } 5078 5079 /* Validate obuf */ 5080 if (verify) { 5081 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5082 plaintext, 5083 tdata->plaintext.data, 5084 tdata->plaintext.len >> 3, 5085 "KASUMI Plaintext data not as expected"); 5086 } else { 5087 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5088 ciphertext, 5089 tdata->ciphertext.data, 5090 tdata->ciphertext.len >> 3, 5091 "KASUMI Ciphertext data not as expected"); 5092 5093 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5094 ut_params->digest, 5095 tdata->digest.data, 5096 DIGEST_BYTE_LENGTH_KASUMI_F9, 5097 "KASUMI Generated auth tag not as expected"); 5098 } 5099 return 0; 5100 } 5101 5102 static int 5103 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata, 5104 uint8_t op_mode, uint8_t verify) 5105 { 5106 struct crypto_testsuite_params *ts_params = &testsuite_params; 5107 struct crypto_unittest_params *ut_params = &unittest_params; 5108 5109 int retval; 5110 5111 const uint8_t *plaintext = NULL; 5112 const uint8_t *ciphertext = NULL; 5113 const uint8_t *digest = NULL; 5114 unsigned int plaintext_pad_len; 5115 unsigned int plaintext_len; 5116 unsigned int ciphertext_pad_len; 5117 unsigned int ciphertext_len; 5118 uint8_t buffer[10000]; 5119 uint8_t digest_buffer[10000]; 5120 5121 struct rte_cryptodev_info dev_info; 5122 5123 /* Verify the capabilities */ 5124 struct rte_cryptodev_sym_capability_idx cap_idx; 5125 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5126 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5127 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5128 &cap_idx) == NULL) 5129 return -ENOTSUP; 5130 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5131 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5132 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5133 &cap_idx) == NULL) 5134 return -ENOTSUP; 5135 5136 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5137 return -ENOTSUP; 5138 5139 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5140 5141 uint64_t feat_flags = dev_info.feature_flags; 5142 5143 if (op_mode == IN_PLACE) { 5144 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5145 printf("Device doesn't support in-place scatter-gather " 5146 "in both input and output mbufs.\n"); 5147 return -ENOTSUP; 5148 } 5149 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5150 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5151 printf("Device doesn't support RAW data-path APIs.\n"); 5152 return -ENOTSUP; 5153 } 5154 } else { 5155 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5156 return -ENOTSUP; 5157 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5158 printf("Device doesn't support out-of-place scatter-gather " 5159 "in both input and output mbufs.\n"); 5160 return -ENOTSUP; 5161 } 5162 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5163 printf("Device doesn't support digest encrypted.\n"); 5164 return -ENOTSUP; 5165 } 5166 } 5167 5168 /* Create KASUMI session */ 5169 retval = create_wireless_algo_auth_cipher_session( 5170 ts_params->valid_devs[0], 5171 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5172 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5173 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5174 : RTE_CRYPTO_AUTH_OP_GENERATE), 5175 RTE_CRYPTO_AUTH_KASUMI_F9, 5176 RTE_CRYPTO_CIPHER_KASUMI_F8, 5177 tdata->key.data, tdata->key.len, 5178 0, tdata->digest.len, 5179 tdata->cipher_iv.len); 5180 5181 if (retval < 0) 5182 return retval; 5183 5184 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5185 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5186 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5187 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5188 5189 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5190 plaintext_pad_len, 15, 0); 5191 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5192 "Failed to allocate input buffer in mempool"); 5193 5194 if (op_mode == OUT_OF_PLACE) { 5195 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 5196 plaintext_pad_len, 15, 0); 5197 TEST_ASSERT_NOT_NULL(ut_params->obuf, 5198 "Failed to allocate output buffer in mempool"); 5199 } 5200 5201 if (verify) { 5202 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 5203 tdata->ciphertext.data); 5204 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5205 ciphertext_len, buffer); 5206 debug_hexdump(stdout, "ciphertext:", ciphertext, 5207 ciphertext_len); 5208 } else { 5209 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5210 tdata->plaintext.data); 5211 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5212 plaintext_len, buffer); 5213 debug_hexdump(stdout, "plaintext:", plaintext, 5214 plaintext_len); 5215 } 5216 memset(buffer, 0, sizeof(buffer)); 5217 5218 /* Create KASUMI operation */ 5219 retval = create_wireless_algo_auth_cipher_operation( 5220 tdata->digest.data, tdata->digest.len, 5221 tdata->cipher_iv.data, tdata->cipher_iv.len, 5222 NULL, 0, 5223 (tdata->digest.offset_bytes == 0 ? 5224 (verify ? ciphertext_pad_len : plaintext_pad_len) 5225 : tdata->digest.offset_bytes), 5226 tdata->validCipherLenInBits.len, 5227 tdata->validCipherOffsetInBits.len, 5228 tdata->validAuthLenInBits.len, 5229 0, 5230 op_mode, 1, verify); 5231 5232 if (retval < 0) 5233 return retval; 5234 5235 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5236 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5237 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5238 else 5239 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5240 ut_params->op); 5241 5242 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5243 5244 ut_params->obuf = (op_mode == IN_PLACE ? 5245 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5246 5247 if (verify) { 5248 if (ut_params->obuf) 5249 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 5250 plaintext_len, buffer); 5251 else 5252 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 5253 plaintext_len, buffer); 5254 5255 debug_hexdump(stdout, "plaintext:", plaintext, 5256 (tdata->plaintext.len >> 3) - tdata->digest.len); 5257 debug_hexdump(stdout, "plaintext expected:", 5258 tdata->plaintext.data, 5259 (tdata->plaintext.len >> 3) - tdata->digest.len); 5260 } else { 5261 if (ut_params->obuf) 5262 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 5263 ciphertext_len, buffer); 5264 else 5265 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 5266 ciphertext_len, buffer); 5267 5268 debug_hexdump(stdout, "ciphertext:", ciphertext, 5269 ciphertext_len); 5270 debug_hexdump(stdout, "ciphertext expected:", 5271 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5272 5273 if (ut_params->obuf) 5274 digest = rte_pktmbuf_read(ut_params->obuf, 5275 (tdata->digest.offset_bytes == 0 ? 5276 plaintext_pad_len : tdata->digest.offset_bytes), 5277 tdata->digest.len, digest_buffer); 5278 else 5279 digest = rte_pktmbuf_read(ut_params->ibuf, 5280 (tdata->digest.offset_bytes == 0 ? 5281 plaintext_pad_len : tdata->digest.offset_bytes), 5282 tdata->digest.len, digest_buffer); 5283 5284 debug_hexdump(stdout, "digest:", digest, 5285 tdata->digest.len); 5286 debug_hexdump(stdout, "digest expected:", 5287 tdata->digest.data, tdata->digest.len); 5288 } 5289 5290 /* Validate obuf */ 5291 if (verify) { 5292 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5293 plaintext, 5294 tdata->plaintext.data, 5295 tdata->plaintext.len >> 3, 5296 "KASUMI Plaintext data not as expected"); 5297 } else { 5298 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5299 ciphertext, 5300 tdata->ciphertext.data, 5301 tdata->validDataLenInBits.len, 5302 "KASUMI Ciphertext data not as expected"); 5303 5304 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5305 digest, 5306 tdata->digest.data, 5307 DIGEST_BYTE_LENGTH_KASUMI_F9, 5308 "KASUMI Generated auth tag not as expected"); 5309 } 5310 return 0; 5311 } 5312 5313 static int 5314 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata) 5315 { 5316 struct crypto_testsuite_params *ts_params = &testsuite_params; 5317 struct crypto_unittest_params *ut_params = &unittest_params; 5318 5319 int retval; 5320 5321 uint8_t *plaintext, *ciphertext; 5322 unsigned plaintext_pad_len; 5323 unsigned plaintext_len; 5324 struct rte_cryptodev_info dev_info; 5325 5326 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5327 uint64_t feat_flags = dev_info.feature_flags; 5328 5329 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5330 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5331 printf("Device doesn't support RAW data-path APIs.\n"); 5332 return -ENOTSUP; 5333 } 5334 5335 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5336 return -ENOTSUP; 5337 5338 /* Verify the capabilities */ 5339 struct rte_cryptodev_sym_capability_idx cap_idx; 5340 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5341 cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9; 5342 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5343 &cap_idx) == NULL) 5344 return -ENOTSUP; 5345 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5346 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8; 5347 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5348 &cap_idx) == NULL) 5349 return -ENOTSUP; 5350 5351 /* Create KASUMI session */ 5352 retval = create_wireless_algo_cipher_auth_session( 5353 ts_params->valid_devs[0], 5354 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5355 RTE_CRYPTO_AUTH_OP_GENERATE, 5356 RTE_CRYPTO_AUTH_KASUMI_F9, 5357 RTE_CRYPTO_CIPHER_KASUMI_F8, 5358 tdata->key.data, tdata->key.len, 5359 0, tdata->digest.len, 5360 tdata->cipher_iv.len); 5361 if (retval < 0) 5362 return retval; 5363 5364 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5365 5366 /* clear mbuf payload */ 5367 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5368 rte_pktmbuf_tailroom(ut_params->ibuf)); 5369 5370 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5371 /* Append data which is padded to a multiple of */ 5372 /* the algorithms block size */ 5373 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5374 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5375 plaintext_pad_len); 5376 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5377 5378 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5379 5380 /* Create KASUMI operation */ 5381 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data, 5382 tdata->digest.len, NULL, 0, 5383 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5384 tdata->cipher_iv.data, tdata->cipher_iv.len, 5385 RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8), 5386 tdata->validCipherOffsetInBits.len, 5387 tdata->validAuthLenInBits.len, 5388 0 5389 ); 5390 if (retval < 0) 5391 return retval; 5392 5393 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5394 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5395 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5396 else 5397 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5398 ut_params->op); 5399 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5400 5401 if (ut_params->op->sym->m_dst) 5402 ut_params->obuf = ut_params->op->sym->m_dst; 5403 else 5404 ut_params->obuf = ut_params->op->sym->m_src; 5405 5406 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 5407 tdata->validCipherOffsetInBits.len >> 3); 5408 5409 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5410 + plaintext_pad_len; 5411 5412 const uint8_t *reference_ciphertext = tdata->ciphertext.data + 5413 (tdata->validCipherOffsetInBits.len >> 3); 5414 /* Validate obuf */ 5415 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5416 ciphertext, 5417 reference_ciphertext, 5418 tdata->validCipherLenInBits.len, 5419 "KASUMI Ciphertext data not as expected"); 5420 5421 /* Validate obuf */ 5422 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5423 ut_params->digest, 5424 tdata->digest.data, 5425 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 5426 "KASUMI Generated auth tag not as expected"); 5427 return 0; 5428 } 5429 5430 static int 5431 test_zuc_encryption(const struct wireless_test_data *tdata) 5432 { 5433 struct crypto_testsuite_params *ts_params = &testsuite_params; 5434 struct crypto_unittest_params *ut_params = &unittest_params; 5435 5436 int retval; 5437 uint8_t *plaintext, *ciphertext; 5438 unsigned plaintext_pad_len; 5439 unsigned plaintext_len; 5440 struct rte_cryptodev_info dev_info; 5441 5442 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5443 uint64_t feat_flags = dev_info.feature_flags; 5444 5445 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5446 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5447 printf("Device doesn't support RAW data-path APIs.\n"); 5448 return -ENOTSUP; 5449 } 5450 5451 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5452 return -ENOTSUP; 5453 5454 struct rte_cryptodev_sym_capability_idx cap_idx; 5455 5456 /* Check if device supports ZUC EEA3 */ 5457 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5458 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 5459 5460 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5461 &cap_idx) == NULL) 5462 return -ENOTSUP; 5463 5464 /* Create ZUC session */ 5465 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 5466 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5467 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5468 tdata->key.data, tdata->key.len, 5469 tdata->cipher_iv.len); 5470 if (retval < 0) 5471 return retval; 5472 5473 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5474 5475 /* Clear mbuf payload */ 5476 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5477 rte_pktmbuf_tailroom(ut_params->ibuf)); 5478 5479 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5480 /* Append data which is padded to a multiple */ 5481 /* of the algorithms block size */ 5482 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 5483 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5484 plaintext_pad_len); 5485 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5486 5487 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 5488 5489 /* Create ZUC operation */ 5490 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 5491 tdata->cipher_iv.len, 5492 tdata->plaintext.len, 5493 0); 5494 if (retval < 0) 5495 return retval; 5496 5497 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5498 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5499 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 5500 else 5501 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5502 ut_params->op); 5503 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5504 5505 ut_params->obuf = ut_params->op->sym->m_dst; 5506 if (ut_params->obuf) 5507 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); 5508 else 5509 ciphertext = plaintext; 5510 5511 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 5512 5513 /* Validate obuf */ 5514 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5515 ciphertext, 5516 tdata->ciphertext.data, 5517 tdata->validCipherLenInBits.len, 5518 "ZUC Ciphertext data not as expected"); 5519 return 0; 5520 } 5521 5522 static int 5523 test_zuc_encryption_sgl(const struct wireless_test_data *tdata) 5524 { 5525 struct crypto_testsuite_params *ts_params = &testsuite_params; 5526 struct crypto_unittest_params *ut_params = &unittest_params; 5527 5528 int retval; 5529 5530 unsigned int plaintext_pad_len; 5531 unsigned int plaintext_len; 5532 const uint8_t *ciphertext; 5533 uint8_t ciphertext_buffer[2048]; 5534 struct rte_cryptodev_info dev_info; 5535 5536 struct rte_cryptodev_sym_capability_idx cap_idx; 5537 5538 /* Check if device supports ZUC EEA3 */ 5539 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 5540 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3; 5541 5542 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5543 &cap_idx) == NULL) 5544 return -ENOTSUP; 5545 5546 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5547 return -ENOTSUP; 5548 5549 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5550 5551 uint64_t feat_flags = dev_info.feature_flags; 5552 5553 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5554 printf("Device doesn't support in-place scatter-gather. " 5555 "Test Skipped.\n"); 5556 return -ENOTSUP; 5557 } 5558 5559 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5560 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5561 printf("Device doesn't support RAW data-path APIs.\n"); 5562 return -ENOTSUP; 5563 } 5564 5565 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5566 5567 /* Append data which is padded to a multiple */ 5568 /* of the algorithms block size */ 5569 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 5570 5571 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5572 plaintext_pad_len, 10, 0); 5573 5574 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 5575 tdata->plaintext.data); 5576 5577 /* Create ZUC session */ 5578 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0], 5579 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 5580 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5581 tdata->key.data, tdata->key.len, 5582 tdata->cipher_iv.len); 5583 if (retval < 0) 5584 return retval; 5585 5586 /* Clear mbuf payload */ 5587 5588 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data); 5589 5590 /* Create ZUC operation */ 5591 retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data, 5592 tdata->cipher_iv.len, tdata->plaintext.len, 5593 0); 5594 if (retval < 0) 5595 return retval; 5596 5597 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5598 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5599 ut_params->op, 1, 0, 1, tdata->cipher_iv.len); 5600 else 5601 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5602 ut_params->op); 5603 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5604 5605 ut_params->obuf = ut_params->op->sym->m_dst; 5606 if (ut_params->obuf) 5607 ciphertext = rte_pktmbuf_read(ut_params->obuf, 5608 0, plaintext_len, ciphertext_buffer); 5609 else 5610 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 5611 0, plaintext_len, ciphertext_buffer); 5612 5613 /* Validate obuf */ 5614 debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); 5615 5616 /* Validate obuf */ 5617 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5618 ciphertext, 5619 tdata->ciphertext.data, 5620 tdata->validCipherLenInBits.len, 5621 "ZUC Ciphertext data not as expected"); 5622 5623 return 0; 5624 } 5625 5626 static int 5627 test_zuc_authentication(const struct wireless_test_data *tdata) 5628 { 5629 struct crypto_testsuite_params *ts_params = &testsuite_params; 5630 struct crypto_unittest_params *ut_params = &unittest_params; 5631 5632 int retval; 5633 unsigned plaintext_pad_len; 5634 unsigned plaintext_len; 5635 uint8_t *plaintext; 5636 5637 struct rte_cryptodev_sym_capability_idx cap_idx; 5638 struct rte_cryptodev_info dev_info; 5639 5640 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5641 uint64_t feat_flags = dev_info.feature_flags; 5642 5643 if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) && 5644 (tdata->validAuthLenInBits.len % 8 != 0)) { 5645 printf("Device doesn't support NON-Byte Aligned Data.\n"); 5646 return -ENOTSUP; 5647 } 5648 5649 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5650 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5651 printf("Device doesn't support RAW data-path APIs.\n"); 5652 return -ENOTSUP; 5653 } 5654 5655 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 5656 return -ENOTSUP; 5657 5658 /* Check if device supports ZUC EIA3 */ 5659 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5660 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 5661 5662 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5663 &cap_idx) == NULL) 5664 return -ENOTSUP; 5665 5666 /* Create ZUC session */ 5667 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], 5668 tdata->key.data, tdata->key.len, 5669 tdata->auth_iv.len, tdata->digest.len, 5670 RTE_CRYPTO_AUTH_OP_GENERATE, 5671 RTE_CRYPTO_AUTH_ZUC_EIA3); 5672 if (retval < 0) 5673 return retval; 5674 5675 /* alloc mbuf and set payload */ 5676 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5677 5678 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5679 rte_pktmbuf_tailroom(ut_params->ibuf)); 5680 5681 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5682 /* Append data which is padded to a multiple of */ 5683 /* the algorithms block size */ 5684 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8); 5685 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5686 plaintext_pad_len); 5687 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5688 5689 /* Create ZUC operation */ 5690 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len, 5691 tdata->auth_iv.data, tdata->auth_iv.len, 5692 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE, 5693 tdata->validAuthLenInBits.len, 5694 0); 5695 if (retval < 0) 5696 return retval; 5697 5698 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5699 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5700 ut_params->op, 0, 1, 1, 0); 5701 else 5702 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5703 ut_params->op); 5704 ut_params->obuf = ut_params->op->sym->m_src; 5705 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5706 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 5707 + plaintext_pad_len; 5708 5709 /* Validate obuf */ 5710 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5711 ut_params->digest, 5712 tdata->digest.data, 5713 tdata->digest.len, 5714 "ZUC Generated auth tag not as expected"); 5715 5716 return 0; 5717 } 5718 5719 static int 5720 test_zuc_auth_cipher(const struct wireless_test_data *tdata, 5721 uint8_t op_mode, uint8_t verify) 5722 { 5723 struct crypto_testsuite_params *ts_params = &testsuite_params; 5724 struct crypto_unittest_params *ut_params = &unittest_params; 5725 5726 int retval; 5727 5728 uint8_t *plaintext = NULL, *ciphertext = NULL; 5729 unsigned int plaintext_pad_len; 5730 unsigned int plaintext_len; 5731 unsigned int ciphertext_pad_len; 5732 unsigned int ciphertext_len; 5733 5734 struct rte_cryptodev_info dev_info; 5735 struct rte_cryptodev_sym_capability_idx cap_idx; 5736 5737 /* Check if device supports ZUC EIA3 */ 5738 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5739 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 5740 5741 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5742 &cap_idx) == NULL) 5743 return -ENOTSUP; 5744 5745 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5746 5747 uint64_t feat_flags = dev_info.feature_flags; 5748 5749 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5750 printf("Device doesn't support digest encrypted.\n"); 5751 return -ENOTSUP; 5752 } 5753 if (op_mode == IN_PLACE) { 5754 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5755 printf("Device doesn't support in-place scatter-gather " 5756 "in both input and output mbufs.\n"); 5757 return -ENOTSUP; 5758 } 5759 5760 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5761 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5762 printf("Device doesn't support RAW data-path APIs.\n"); 5763 return -ENOTSUP; 5764 } 5765 } else { 5766 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5767 return -ENOTSUP; 5768 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5769 printf("Device doesn't support out-of-place scatter-gather " 5770 "in both input and output mbufs.\n"); 5771 return -ENOTSUP; 5772 } 5773 } 5774 5775 /* Create ZUC session */ 5776 retval = create_wireless_algo_auth_cipher_session( 5777 ts_params->valid_devs[0], 5778 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5779 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5780 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5781 : RTE_CRYPTO_AUTH_OP_GENERATE), 5782 RTE_CRYPTO_AUTH_ZUC_EIA3, 5783 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5784 tdata->key.data, tdata->key.len, 5785 tdata->auth_iv.len, tdata->digest.len, 5786 tdata->cipher_iv.len); 5787 5788 if (retval < 0) 5789 return retval; 5790 5791 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5792 if (op_mode == OUT_OF_PLACE) 5793 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 5794 5795 /* clear mbuf payload */ 5796 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 5797 rte_pktmbuf_tailroom(ut_params->ibuf)); 5798 if (op_mode == OUT_OF_PLACE) 5799 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 5800 rte_pktmbuf_tailroom(ut_params->obuf)); 5801 5802 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5803 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5804 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5805 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5806 5807 if (verify) { 5808 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5809 ciphertext_pad_len); 5810 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 5811 if (op_mode == OUT_OF_PLACE) 5812 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 5813 debug_hexdump(stdout, "ciphertext:", ciphertext, 5814 ciphertext_len); 5815 } else { 5816 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 5817 plaintext_pad_len); 5818 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 5819 if (op_mode == OUT_OF_PLACE) 5820 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 5821 debug_hexdump(stdout, "plaintext:", plaintext, 5822 plaintext_len); 5823 } 5824 5825 /* Create ZUC operation */ 5826 retval = create_wireless_algo_auth_cipher_operation( 5827 tdata->digest.data, tdata->digest.len, 5828 tdata->cipher_iv.data, tdata->cipher_iv.len, 5829 tdata->auth_iv.data, tdata->auth_iv.len, 5830 (tdata->digest.offset_bytes == 0 ? 5831 (verify ? ciphertext_pad_len : plaintext_pad_len) 5832 : tdata->digest.offset_bytes), 5833 tdata->validCipherLenInBits.len, 5834 tdata->validCipherOffsetInBits.len, 5835 tdata->validAuthLenInBits.len, 5836 0, 5837 op_mode, 0, verify); 5838 5839 if (retval < 0) 5840 return retval; 5841 5842 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5843 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 5844 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 5845 else 5846 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 5847 ut_params->op); 5848 5849 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 5850 5851 ut_params->obuf = (op_mode == IN_PLACE ? 5852 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 5853 5854 5855 if (verify) { 5856 if (ut_params->obuf) 5857 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 5858 uint8_t *); 5859 else 5860 plaintext = ciphertext; 5861 5862 debug_hexdump(stdout, "plaintext:", plaintext, 5863 (tdata->plaintext.len >> 3) - tdata->digest.len); 5864 debug_hexdump(stdout, "plaintext expected:", 5865 tdata->plaintext.data, 5866 (tdata->plaintext.len >> 3) - tdata->digest.len); 5867 } else { 5868 if (ut_params->obuf) 5869 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 5870 uint8_t *); 5871 else 5872 ciphertext = plaintext; 5873 5874 debug_hexdump(stdout, "ciphertext:", ciphertext, 5875 ciphertext_len); 5876 debug_hexdump(stdout, "ciphertext expected:", 5877 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 5878 5879 ut_params->digest = rte_pktmbuf_mtod( 5880 ut_params->obuf, uint8_t *) + 5881 (tdata->digest.offset_bytes == 0 ? 5882 plaintext_pad_len : tdata->digest.offset_bytes); 5883 5884 debug_hexdump(stdout, "digest:", ut_params->digest, 5885 tdata->digest.len); 5886 debug_hexdump(stdout, "digest expected:", 5887 tdata->digest.data, tdata->digest.len); 5888 } 5889 5890 /* Validate obuf */ 5891 if (verify) { 5892 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5893 plaintext, 5894 tdata->plaintext.data, 5895 tdata->plaintext.len >> 3, 5896 "ZUC Plaintext data not as expected"); 5897 } else { 5898 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 5899 ciphertext, 5900 tdata->ciphertext.data, 5901 tdata->ciphertext.len >> 3, 5902 "ZUC Ciphertext data not as expected"); 5903 5904 TEST_ASSERT_BUFFERS_ARE_EQUAL( 5905 ut_params->digest, 5906 tdata->digest.data, 5907 DIGEST_BYTE_LENGTH_KASUMI_F9, 5908 "ZUC Generated auth tag not as expected"); 5909 } 5910 return 0; 5911 } 5912 5913 static int 5914 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata, 5915 uint8_t op_mode, uint8_t verify) 5916 { 5917 struct crypto_testsuite_params *ts_params = &testsuite_params; 5918 struct crypto_unittest_params *ut_params = &unittest_params; 5919 5920 int retval; 5921 5922 const uint8_t *plaintext = NULL; 5923 const uint8_t *ciphertext = NULL; 5924 const uint8_t *digest = NULL; 5925 unsigned int plaintext_pad_len; 5926 unsigned int plaintext_len; 5927 unsigned int ciphertext_pad_len; 5928 unsigned int ciphertext_len; 5929 uint8_t buffer[10000]; 5930 uint8_t digest_buffer[10000]; 5931 5932 struct rte_cryptodev_info dev_info; 5933 struct rte_cryptodev_sym_capability_idx cap_idx; 5934 5935 /* Check if device supports ZUC EIA3 */ 5936 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 5937 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3; 5938 5939 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 5940 &cap_idx) == NULL) 5941 return -ENOTSUP; 5942 5943 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 5944 5945 uint64_t feat_flags = dev_info.feature_flags; 5946 5947 if (op_mode == IN_PLACE) { 5948 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 5949 printf("Device doesn't support in-place scatter-gather " 5950 "in both input and output mbufs.\n"); 5951 return -ENOTSUP; 5952 } 5953 5954 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 5955 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 5956 printf("Device doesn't support RAW data-path APIs.\n"); 5957 return -ENOTSUP; 5958 } 5959 } else { 5960 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 5961 return -ENOTSUP; 5962 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 5963 printf("Device doesn't support out-of-place scatter-gather " 5964 "in both input and output mbufs.\n"); 5965 return -ENOTSUP; 5966 } 5967 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 5968 printf("Device doesn't support digest encrypted.\n"); 5969 return -ENOTSUP; 5970 } 5971 } 5972 5973 /* Create ZUC session */ 5974 retval = create_wireless_algo_auth_cipher_session( 5975 ts_params->valid_devs[0], 5976 (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT 5977 : RTE_CRYPTO_CIPHER_OP_ENCRYPT), 5978 (verify ? RTE_CRYPTO_AUTH_OP_VERIFY 5979 : RTE_CRYPTO_AUTH_OP_GENERATE), 5980 RTE_CRYPTO_AUTH_ZUC_EIA3, 5981 RTE_CRYPTO_CIPHER_ZUC_EEA3, 5982 tdata->key.data, tdata->key.len, 5983 tdata->auth_iv.len, tdata->digest.len, 5984 tdata->cipher_iv.len); 5985 5986 if (retval < 0) 5987 return retval; 5988 5989 ciphertext_len = ceil_byte_length(tdata->ciphertext.len); 5990 plaintext_len = ceil_byte_length(tdata->plaintext.len); 5991 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 5992 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 5993 5994 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 5995 plaintext_pad_len, 15, 0); 5996 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 5997 "Failed to allocate input buffer in mempool"); 5998 5999 if (op_mode == OUT_OF_PLACE) { 6000 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 6001 plaintext_pad_len, 15, 0); 6002 TEST_ASSERT_NOT_NULL(ut_params->obuf, 6003 "Failed to allocate output buffer in mempool"); 6004 } 6005 6006 if (verify) { 6007 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 6008 tdata->ciphertext.data); 6009 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6010 ciphertext_len, buffer); 6011 debug_hexdump(stdout, "ciphertext:", ciphertext, 6012 ciphertext_len); 6013 } else { 6014 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 6015 tdata->plaintext.data); 6016 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6017 plaintext_len, buffer); 6018 debug_hexdump(stdout, "plaintext:", plaintext, 6019 plaintext_len); 6020 } 6021 memset(buffer, 0, sizeof(buffer)); 6022 6023 /* Create ZUC operation */ 6024 retval = create_wireless_algo_auth_cipher_operation( 6025 tdata->digest.data, tdata->digest.len, 6026 tdata->cipher_iv.data, tdata->cipher_iv.len, 6027 NULL, 0, 6028 (tdata->digest.offset_bytes == 0 ? 6029 (verify ? ciphertext_pad_len : plaintext_pad_len) 6030 : tdata->digest.offset_bytes), 6031 tdata->validCipherLenInBits.len, 6032 tdata->validCipherOffsetInBits.len, 6033 tdata->validAuthLenInBits.len, 6034 0, 6035 op_mode, 1, verify); 6036 6037 if (retval < 0) 6038 return retval; 6039 6040 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6041 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 6042 ut_params->op, 1, 1, 1, tdata->cipher_iv.len); 6043 else 6044 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 6045 ut_params->op); 6046 6047 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6048 6049 ut_params->obuf = (op_mode == IN_PLACE ? 6050 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6051 6052 if (verify) { 6053 if (ut_params->obuf) 6054 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 6055 plaintext_len, buffer); 6056 else 6057 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 6058 plaintext_len, buffer); 6059 6060 debug_hexdump(stdout, "plaintext:", plaintext, 6061 (tdata->plaintext.len >> 3) - tdata->digest.len); 6062 debug_hexdump(stdout, "plaintext expected:", 6063 tdata->plaintext.data, 6064 (tdata->plaintext.len >> 3) - tdata->digest.len); 6065 } else { 6066 if (ut_params->obuf) 6067 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 6068 ciphertext_len, buffer); 6069 else 6070 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 6071 ciphertext_len, buffer); 6072 6073 debug_hexdump(stdout, "ciphertext:", ciphertext, 6074 ciphertext_len); 6075 debug_hexdump(stdout, "ciphertext expected:", 6076 tdata->ciphertext.data, tdata->ciphertext.len >> 3); 6077 6078 if (ut_params->obuf) 6079 digest = rte_pktmbuf_read(ut_params->obuf, 6080 (tdata->digest.offset_bytes == 0 ? 6081 plaintext_pad_len : tdata->digest.offset_bytes), 6082 tdata->digest.len, digest_buffer); 6083 else 6084 digest = rte_pktmbuf_read(ut_params->ibuf, 6085 (tdata->digest.offset_bytes == 0 ? 6086 plaintext_pad_len : tdata->digest.offset_bytes), 6087 tdata->digest.len, digest_buffer); 6088 6089 debug_hexdump(stdout, "digest:", digest, 6090 tdata->digest.len); 6091 debug_hexdump(stdout, "digest expected:", 6092 tdata->digest.data, tdata->digest.len); 6093 } 6094 6095 /* Validate obuf */ 6096 if (verify) { 6097 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6098 plaintext, 6099 tdata->plaintext.data, 6100 tdata->plaintext.len >> 3, 6101 "ZUC Plaintext data not as expected"); 6102 } else { 6103 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6104 ciphertext, 6105 tdata->ciphertext.data, 6106 tdata->validDataLenInBits.len, 6107 "ZUC Ciphertext data not as expected"); 6108 6109 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6110 digest, 6111 tdata->digest.data, 6112 DIGEST_BYTE_LENGTH_KASUMI_F9, 6113 "ZUC Generated auth tag not as expected"); 6114 } 6115 return 0; 6116 } 6117 6118 static int 6119 test_kasumi_encryption_test_case_1(void) 6120 { 6121 return test_kasumi_encryption(&kasumi_test_case_1); 6122 } 6123 6124 static int 6125 test_kasumi_encryption_test_case_1_sgl(void) 6126 { 6127 return test_kasumi_encryption_sgl(&kasumi_test_case_1); 6128 } 6129 6130 static int 6131 test_kasumi_encryption_test_case_1_oop(void) 6132 { 6133 return test_kasumi_encryption_oop(&kasumi_test_case_1); 6134 } 6135 6136 static int 6137 test_kasumi_encryption_test_case_1_oop_sgl(void) 6138 { 6139 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1); 6140 } 6141 6142 static int 6143 test_kasumi_encryption_test_case_2(void) 6144 { 6145 return test_kasumi_encryption(&kasumi_test_case_2); 6146 } 6147 6148 static int 6149 test_kasumi_encryption_test_case_3(void) 6150 { 6151 return test_kasumi_encryption(&kasumi_test_case_3); 6152 } 6153 6154 static int 6155 test_kasumi_encryption_test_case_4(void) 6156 { 6157 return test_kasumi_encryption(&kasumi_test_case_4); 6158 } 6159 6160 static int 6161 test_kasumi_encryption_test_case_5(void) 6162 { 6163 return test_kasumi_encryption(&kasumi_test_case_5); 6164 } 6165 6166 static int 6167 test_kasumi_decryption_test_case_1(void) 6168 { 6169 return test_kasumi_decryption(&kasumi_test_case_1); 6170 } 6171 6172 static int 6173 test_kasumi_decryption_test_case_1_oop(void) 6174 { 6175 return test_kasumi_decryption_oop(&kasumi_test_case_1); 6176 } 6177 6178 static int 6179 test_kasumi_decryption_test_case_2(void) 6180 { 6181 return test_kasumi_decryption(&kasumi_test_case_2); 6182 } 6183 6184 static int 6185 test_kasumi_decryption_test_case_3(void) 6186 { 6187 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6188 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6189 return -ENOTSUP; 6190 return test_kasumi_decryption(&kasumi_test_case_3); 6191 } 6192 6193 static int 6194 test_kasumi_decryption_test_case_4(void) 6195 { 6196 return test_kasumi_decryption(&kasumi_test_case_4); 6197 } 6198 6199 static int 6200 test_kasumi_decryption_test_case_5(void) 6201 { 6202 return test_kasumi_decryption(&kasumi_test_case_5); 6203 } 6204 static int 6205 test_snow3g_encryption_test_case_1(void) 6206 { 6207 return test_snow3g_encryption(&snow3g_test_case_1); 6208 } 6209 6210 static int 6211 test_snow3g_encryption_test_case_1_oop(void) 6212 { 6213 return test_snow3g_encryption_oop(&snow3g_test_case_1); 6214 } 6215 6216 static int 6217 test_snow3g_encryption_test_case_1_oop_sgl(void) 6218 { 6219 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1); 6220 } 6221 6222 6223 static int 6224 test_snow3g_encryption_test_case_1_offset_oop(void) 6225 { 6226 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); 6227 } 6228 6229 static int 6230 test_snow3g_encryption_test_case_2(void) 6231 { 6232 return test_snow3g_encryption(&snow3g_test_case_2); 6233 } 6234 6235 static int 6236 test_snow3g_encryption_test_case_3(void) 6237 { 6238 return test_snow3g_encryption(&snow3g_test_case_3); 6239 } 6240 6241 static int 6242 test_snow3g_encryption_test_case_4(void) 6243 { 6244 return test_snow3g_encryption(&snow3g_test_case_4); 6245 } 6246 6247 static int 6248 test_snow3g_encryption_test_case_5(void) 6249 { 6250 return test_snow3g_encryption(&snow3g_test_case_5); 6251 } 6252 6253 static int 6254 test_snow3g_decryption_test_case_1(void) 6255 { 6256 return test_snow3g_decryption(&snow3g_test_case_1); 6257 } 6258 6259 static int 6260 test_snow3g_decryption_test_case_1_oop(void) 6261 { 6262 return test_snow3g_decryption_oop(&snow3g_test_case_1); 6263 } 6264 6265 static int 6266 test_snow3g_decryption_test_case_2(void) 6267 { 6268 return test_snow3g_decryption(&snow3g_test_case_2); 6269 } 6270 6271 static int 6272 test_snow3g_decryption_test_case_3(void) 6273 { 6274 return test_snow3g_decryption(&snow3g_test_case_3); 6275 } 6276 6277 static int 6278 test_snow3g_decryption_test_case_4(void) 6279 { 6280 return test_snow3g_decryption(&snow3g_test_case_4); 6281 } 6282 6283 static int 6284 test_snow3g_decryption_test_case_5(void) 6285 { 6286 return test_snow3g_decryption(&snow3g_test_case_5); 6287 } 6288 6289 /* 6290 * Function prepares snow3g_hash_test_data from snow3g_test_data. 6291 * Pattern digest from snow3g_test_data must be allocated as 6292 * 4 last bytes in plaintext. 6293 */ 6294 static void 6295 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern, 6296 struct snow3g_hash_test_data *output) 6297 { 6298 if ((pattern != NULL) && (output != NULL)) { 6299 output->key.len = pattern->key.len; 6300 6301 memcpy(output->key.data, 6302 pattern->key.data, pattern->key.len); 6303 6304 output->auth_iv.len = pattern->auth_iv.len; 6305 6306 memcpy(output->auth_iv.data, 6307 pattern->auth_iv.data, pattern->auth_iv.len); 6308 6309 output->plaintext.len = pattern->plaintext.len; 6310 6311 memcpy(output->plaintext.data, 6312 pattern->plaintext.data, pattern->plaintext.len >> 3); 6313 6314 output->digest.len = pattern->digest.len; 6315 6316 memcpy(output->digest.data, 6317 &pattern->plaintext.data[pattern->digest.offset_bytes], 6318 pattern->digest.len); 6319 6320 output->validAuthLenInBits.len = 6321 pattern->validAuthLenInBits.len; 6322 } 6323 } 6324 6325 /* 6326 * Test case verify computed cipher and digest from snow3g_test_case_7 data. 6327 */ 6328 static int 6329 test_snow3g_decryption_with_digest_test_case_1(void) 6330 { 6331 struct snow3g_hash_test_data snow3g_hash_data; 6332 struct rte_cryptodev_info dev_info; 6333 struct crypto_testsuite_params *ts_params = &testsuite_params; 6334 6335 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6336 uint64_t feat_flags = dev_info.feature_flags; 6337 6338 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6339 printf("Device doesn't support encrypted digest operations.\n"); 6340 return -ENOTSUP; 6341 } 6342 6343 /* 6344 * Function prepare data for hash veryfication test case. 6345 * Digest is allocated in 4 last bytes in plaintext, pattern. 6346 */ 6347 snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data); 6348 6349 return test_snow3g_decryption(&snow3g_test_case_7) & 6350 test_snow3g_authentication_verify(&snow3g_hash_data); 6351 } 6352 6353 static int 6354 test_snow3g_cipher_auth_test_case_1(void) 6355 { 6356 return test_snow3g_cipher_auth(&snow3g_test_case_3); 6357 } 6358 6359 static int 6360 test_snow3g_auth_cipher_test_case_1(void) 6361 { 6362 return test_snow3g_auth_cipher( 6363 &snow3g_auth_cipher_test_case_1, IN_PLACE, 0); 6364 } 6365 6366 static int 6367 test_snow3g_auth_cipher_test_case_2(void) 6368 { 6369 return test_snow3g_auth_cipher( 6370 &snow3g_auth_cipher_test_case_2, IN_PLACE, 0); 6371 } 6372 6373 static int 6374 test_snow3g_auth_cipher_test_case_2_oop(void) 6375 { 6376 return test_snow3g_auth_cipher( 6377 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6378 } 6379 6380 static int 6381 test_snow3g_auth_cipher_part_digest_enc(void) 6382 { 6383 return test_snow3g_auth_cipher( 6384 &snow3g_auth_cipher_partial_digest_encryption, 6385 IN_PLACE, 0); 6386 } 6387 6388 static int 6389 test_snow3g_auth_cipher_part_digest_enc_oop(void) 6390 { 6391 return test_snow3g_auth_cipher( 6392 &snow3g_auth_cipher_partial_digest_encryption, 6393 OUT_OF_PLACE, 0); 6394 } 6395 6396 static int 6397 test_snow3g_auth_cipher_test_case_3_sgl(void) 6398 { 6399 /* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */ 6400 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6401 return -ENOTSUP; 6402 return test_snow3g_auth_cipher_sgl( 6403 &snow3g_auth_cipher_test_case_3, IN_PLACE, 0); 6404 } 6405 6406 static int 6407 test_snow3g_auth_cipher_test_case_3_oop_sgl(void) 6408 { 6409 return test_snow3g_auth_cipher_sgl( 6410 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0); 6411 } 6412 6413 static int 6414 test_snow3g_auth_cipher_part_digest_enc_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_partial_digest_encryption, 6421 IN_PLACE, 0); 6422 } 6423 6424 static int 6425 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void) 6426 { 6427 return test_snow3g_auth_cipher_sgl( 6428 &snow3g_auth_cipher_partial_digest_encryption, 6429 OUT_OF_PLACE, 0); 6430 } 6431 6432 static int 6433 test_snow3g_auth_cipher_verify_test_case_1(void) 6434 { 6435 return test_snow3g_auth_cipher( 6436 &snow3g_auth_cipher_test_case_1, IN_PLACE, 1); 6437 } 6438 6439 static int 6440 test_snow3g_auth_cipher_verify_test_case_2(void) 6441 { 6442 return test_snow3g_auth_cipher( 6443 &snow3g_auth_cipher_test_case_2, IN_PLACE, 1); 6444 } 6445 6446 static int 6447 test_snow3g_auth_cipher_verify_test_case_2_oop(void) 6448 { 6449 return test_snow3g_auth_cipher( 6450 &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 6451 } 6452 6453 static int 6454 test_snow3g_auth_cipher_verify_part_digest_enc(void) 6455 { 6456 return test_snow3g_auth_cipher( 6457 &snow3g_auth_cipher_partial_digest_encryption, 6458 IN_PLACE, 1); 6459 } 6460 6461 static int 6462 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void) 6463 { 6464 return test_snow3g_auth_cipher( 6465 &snow3g_auth_cipher_partial_digest_encryption, 6466 OUT_OF_PLACE, 1); 6467 } 6468 6469 static int 6470 test_snow3g_auth_cipher_verify_test_case_3_sgl(void) 6471 { 6472 return test_snow3g_auth_cipher_sgl( 6473 &snow3g_auth_cipher_test_case_3, IN_PLACE, 1); 6474 } 6475 6476 static int 6477 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void) 6478 { 6479 return test_snow3g_auth_cipher_sgl( 6480 &snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1); 6481 } 6482 6483 static int 6484 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void) 6485 { 6486 return test_snow3g_auth_cipher_sgl( 6487 &snow3g_auth_cipher_partial_digest_encryption, 6488 IN_PLACE, 1); 6489 } 6490 6491 static int 6492 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void) 6493 { 6494 return test_snow3g_auth_cipher_sgl( 6495 &snow3g_auth_cipher_partial_digest_encryption, 6496 OUT_OF_PLACE, 1); 6497 } 6498 6499 static int 6500 test_snow3g_auth_cipher_with_digest_test_case_1(void) 6501 { 6502 return test_snow3g_auth_cipher( 6503 &snow3g_test_case_7, IN_PLACE, 0); 6504 } 6505 6506 static int 6507 test_kasumi_auth_cipher_test_case_1(void) 6508 { 6509 return test_kasumi_auth_cipher( 6510 &kasumi_test_case_3, IN_PLACE, 0); 6511 } 6512 6513 static int 6514 test_kasumi_auth_cipher_test_case_2(void) 6515 { 6516 return test_kasumi_auth_cipher( 6517 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 6518 } 6519 6520 static int 6521 test_kasumi_auth_cipher_test_case_2_oop(void) 6522 { 6523 return test_kasumi_auth_cipher( 6524 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6525 } 6526 6527 static int 6528 test_kasumi_auth_cipher_test_case_2_sgl(void) 6529 { 6530 return test_kasumi_auth_cipher_sgl( 6531 &kasumi_auth_cipher_test_case_2, IN_PLACE, 0); 6532 } 6533 6534 static int 6535 test_kasumi_auth_cipher_test_case_2_oop_sgl(void) 6536 { 6537 return test_kasumi_auth_cipher_sgl( 6538 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0); 6539 } 6540 6541 static int 6542 test_kasumi_auth_cipher_verify_test_case_1(void) 6543 { 6544 return test_kasumi_auth_cipher( 6545 &kasumi_test_case_3, IN_PLACE, 1); 6546 } 6547 6548 static int 6549 test_kasumi_auth_cipher_verify_test_case_2(void) 6550 { 6551 return test_kasumi_auth_cipher( 6552 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 6553 } 6554 6555 static int 6556 test_kasumi_auth_cipher_verify_test_case_2_oop(void) 6557 { 6558 return test_kasumi_auth_cipher( 6559 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 6560 } 6561 6562 static int 6563 test_kasumi_auth_cipher_verify_test_case_2_sgl(void) 6564 { 6565 return test_kasumi_auth_cipher_sgl( 6566 &kasumi_auth_cipher_test_case_2, IN_PLACE, 1); 6567 } 6568 6569 static int 6570 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void) 6571 { 6572 return test_kasumi_auth_cipher_sgl( 6573 &kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1); 6574 } 6575 6576 static int 6577 test_kasumi_cipher_auth_test_case_1(void) 6578 { 6579 return test_kasumi_cipher_auth(&kasumi_test_case_6); 6580 } 6581 6582 static int 6583 test_zuc_encryption_test_case_1(void) 6584 { 6585 return test_zuc_encryption(&zuc_test_case_cipher_193b); 6586 } 6587 6588 static int 6589 test_zuc_encryption_test_case_2(void) 6590 { 6591 return test_zuc_encryption(&zuc_test_case_cipher_800b); 6592 } 6593 6594 static int 6595 test_zuc_encryption_test_case_3(void) 6596 { 6597 return test_zuc_encryption(&zuc_test_case_cipher_1570b); 6598 } 6599 6600 static int 6601 test_zuc_encryption_test_case_4(void) 6602 { 6603 return test_zuc_encryption(&zuc_test_case_cipher_2798b); 6604 } 6605 6606 static int 6607 test_zuc_encryption_test_case_5(void) 6608 { 6609 return test_zuc_encryption(&zuc_test_case_cipher_4019b); 6610 } 6611 6612 static int 6613 test_zuc_encryption_test_case_6_sgl(void) 6614 { 6615 return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b); 6616 } 6617 6618 static int 6619 test_zuc_hash_generate_test_case_1(void) 6620 { 6621 return test_zuc_authentication(&zuc_test_case_auth_1b); 6622 } 6623 6624 static int 6625 test_zuc_hash_generate_test_case_2(void) 6626 { 6627 return test_zuc_authentication(&zuc_test_case_auth_90b); 6628 } 6629 6630 static int 6631 test_zuc_hash_generate_test_case_3(void) 6632 { 6633 return test_zuc_authentication(&zuc_test_case_auth_577b); 6634 } 6635 6636 static int 6637 test_zuc_hash_generate_test_case_4(void) 6638 { 6639 return test_zuc_authentication(&zuc_test_case_auth_2079b); 6640 } 6641 6642 static int 6643 test_zuc_hash_generate_test_case_5(void) 6644 { 6645 return test_zuc_authentication(&zuc_test_auth_5670b); 6646 } 6647 6648 static int 6649 test_zuc_hash_generate_test_case_6(void) 6650 { 6651 return test_zuc_authentication(&zuc_test_case_auth_128b); 6652 } 6653 6654 static int 6655 test_zuc_hash_generate_test_case_7(void) 6656 { 6657 return test_zuc_authentication(&zuc_test_case_auth_2080b); 6658 } 6659 6660 static int 6661 test_zuc_hash_generate_test_case_8(void) 6662 { 6663 return test_zuc_authentication(&zuc_test_case_auth_584b); 6664 } 6665 6666 static int 6667 test_zuc_cipher_auth_test_case_1(void) 6668 { 6669 return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b); 6670 } 6671 6672 static int 6673 test_zuc_cipher_auth_test_case_2(void) 6674 { 6675 return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b); 6676 } 6677 6678 static int 6679 test_zuc_auth_cipher_test_case_1(void) 6680 { 6681 return test_zuc_auth_cipher( 6682 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 6683 } 6684 6685 static int 6686 test_zuc_auth_cipher_test_case_1_oop(void) 6687 { 6688 return test_zuc_auth_cipher( 6689 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 6690 } 6691 6692 static int 6693 test_zuc_auth_cipher_test_case_1_sgl(void) 6694 { 6695 return test_zuc_auth_cipher_sgl( 6696 &zuc_auth_cipher_test_case_1, IN_PLACE, 0); 6697 } 6698 6699 static int 6700 test_zuc_auth_cipher_test_case_1_oop_sgl(void) 6701 { 6702 return test_zuc_auth_cipher_sgl( 6703 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0); 6704 } 6705 6706 static int 6707 test_zuc_auth_cipher_verify_test_case_1(void) 6708 { 6709 return test_zuc_auth_cipher( 6710 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 6711 } 6712 6713 static int 6714 test_zuc_auth_cipher_verify_test_case_1_oop(void) 6715 { 6716 return test_zuc_auth_cipher( 6717 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 6718 } 6719 6720 static int 6721 test_zuc_auth_cipher_verify_test_case_1_sgl(void) 6722 { 6723 return test_zuc_auth_cipher_sgl( 6724 &zuc_auth_cipher_test_case_1, IN_PLACE, 1); 6725 } 6726 6727 static int 6728 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void) 6729 { 6730 return test_zuc_auth_cipher_sgl( 6731 &zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1); 6732 } 6733 6734 static int 6735 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata) 6736 { 6737 uint8_t dev_id = testsuite_params.valid_devs[0]; 6738 6739 struct rte_cryptodev_sym_capability_idx cap_idx; 6740 6741 /* Check if device supports particular cipher algorithm */ 6742 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 6743 cap_idx.algo.cipher = tdata->cipher_algo; 6744 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 6745 return -ENOTSUP; 6746 6747 /* Check if device supports particular hash algorithm */ 6748 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 6749 cap_idx.algo.auth = tdata->auth_algo; 6750 if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) 6751 return -ENOTSUP; 6752 6753 return 0; 6754 } 6755 6756 static int 6757 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata, 6758 uint8_t op_mode, uint8_t verify) 6759 { 6760 struct crypto_testsuite_params *ts_params = &testsuite_params; 6761 struct crypto_unittest_params *ut_params = &unittest_params; 6762 6763 int retval; 6764 6765 uint8_t *plaintext = NULL, *ciphertext = NULL; 6766 unsigned int plaintext_pad_len; 6767 unsigned int plaintext_len; 6768 unsigned int ciphertext_pad_len; 6769 unsigned int ciphertext_len; 6770 6771 struct rte_cryptodev_info dev_info; 6772 struct rte_crypto_op *op; 6773 6774 /* Check if device supports particular algorithms separately */ 6775 if (test_mixed_check_if_unsupported(tdata)) 6776 return -ENOTSUP; 6777 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6778 return -ENOTSUP; 6779 6780 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6781 6782 uint64_t feat_flags = dev_info.feature_flags; 6783 6784 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6785 printf("Device doesn't support digest encrypted.\n"); 6786 return -ENOTSUP; 6787 } 6788 6789 /* Create the session */ 6790 if (verify) 6791 retval = create_wireless_algo_cipher_auth_session( 6792 ts_params->valid_devs[0], 6793 RTE_CRYPTO_CIPHER_OP_DECRYPT, 6794 RTE_CRYPTO_AUTH_OP_VERIFY, 6795 tdata->auth_algo, 6796 tdata->cipher_algo, 6797 tdata->auth_key.data, tdata->auth_key.len, 6798 tdata->auth_iv.len, tdata->digest_enc.len, 6799 tdata->cipher_iv.len); 6800 else 6801 retval = create_wireless_algo_auth_cipher_session( 6802 ts_params->valid_devs[0], 6803 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 6804 RTE_CRYPTO_AUTH_OP_GENERATE, 6805 tdata->auth_algo, 6806 tdata->cipher_algo, 6807 tdata->auth_key.data, tdata->auth_key.len, 6808 tdata->auth_iv.len, tdata->digest_enc.len, 6809 tdata->cipher_iv.len); 6810 if (retval < 0) 6811 return retval; 6812 6813 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6814 if (op_mode == OUT_OF_PLACE) 6815 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 6816 6817 /* clear mbuf payload */ 6818 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 6819 rte_pktmbuf_tailroom(ut_params->ibuf)); 6820 if (op_mode == OUT_OF_PLACE) { 6821 6822 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 6823 rte_pktmbuf_tailroom(ut_params->obuf)); 6824 } 6825 6826 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 6827 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 6828 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 6829 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 6830 6831 if (verify) { 6832 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6833 ciphertext_pad_len); 6834 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); 6835 if (op_mode == OUT_OF_PLACE) 6836 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); 6837 debug_hexdump(stdout, "ciphertext:", ciphertext, 6838 ciphertext_len); 6839 } else { 6840 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 6841 plaintext_pad_len); 6842 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 6843 if (op_mode == OUT_OF_PLACE) 6844 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); 6845 debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); 6846 } 6847 6848 /* Create the operation */ 6849 retval = create_wireless_algo_auth_cipher_operation( 6850 tdata->digest_enc.data, tdata->digest_enc.len, 6851 tdata->cipher_iv.data, tdata->cipher_iv.len, 6852 tdata->auth_iv.data, tdata->auth_iv.len, 6853 (tdata->digest_enc.offset == 0 ? 6854 plaintext_pad_len 6855 : tdata->digest_enc.offset), 6856 tdata->validCipherLen.len_bits, 6857 tdata->cipher.offset_bits, 6858 tdata->validAuthLen.len_bits, 6859 tdata->auth.offset_bits, 6860 op_mode, 0, verify); 6861 6862 if (retval < 0) 6863 return retval; 6864 6865 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 6866 6867 /* Check if the op failed because the device doesn't */ 6868 /* support this particular combination of algorithms */ 6869 if (op == NULL && ut_params->op->status == 6870 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 6871 printf("Device doesn't support this mixed combination. " 6872 "Test Skipped.\n"); 6873 return -ENOTSUP; 6874 } 6875 ut_params->op = op; 6876 6877 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 6878 6879 ut_params->obuf = (op_mode == IN_PLACE ? 6880 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 6881 6882 if (verify) { 6883 if (ut_params->obuf) 6884 plaintext = rte_pktmbuf_mtod(ut_params->obuf, 6885 uint8_t *); 6886 else 6887 plaintext = ciphertext + 6888 (tdata->cipher.offset_bits >> 3); 6889 6890 debug_hexdump(stdout, "plaintext:", plaintext, 6891 tdata->plaintext.len_bits >> 3); 6892 debug_hexdump(stdout, "plaintext expected:", 6893 tdata->plaintext.data, 6894 tdata->plaintext.len_bits >> 3); 6895 } else { 6896 if (ut_params->obuf) 6897 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, 6898 uint8_t *); 6899 else 6900 ciphertext = plaintext; 6901 6902 debug_hexdump(stdout, "ciphertext:", ciphertext, 6903 ciphertext_len); 6904 debug_hexdump(stdout, "ciphertext expected:", 6905 tdata->ciphertext.data, 6906 tdata->ciphertext.len_bits >> 3); 6907 6908 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) 6909 + (tdata->digest_enc.offset == 0 ? 6910 plaintext_pad_len : tdata->digest_enc.offset); 6911 6912 debug_hexdump(stdout, "digest:", ut_params->digest, 6913 tdata->digest_enc.len); 6914 debug_hexdump(stdout, "digest expected:", 6915 tdata->digest_enc.data, 6916 tdata->digest_enc.len); 6917 } 6918 6919 /* Validate obuf */ 6920 if (verify) { 6921 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6922 plaintext, 6923 tdata->plaintext.data, 6924 tdata->plaintext.len_bits >> 3, 6925 "Plaintext data not as expected"); 6926 } else { 6927 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 6928 ciphertext, 6929 tdata->ciphertext.data, 6930 tdata->validDataLen.len_bits, 6931 "Ciphertext data not as expected"); 6932 6933 TEST_ASSERT_BUFFERS_ARE_EQUAL( 6934 ut_params->digest, 6935 tdata->digest_enc.data, 6936 DIGEST_BYTE_LENGTH_SNOW3G_UIA2, 6937 "Generated auth tag not as expected"); 6938 } 6939 6940 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 6941 "crypto op processing failed"); 6942 6943 return 0; 6944 } 6945 6946 static int 6947 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata, 6948 uint8_t op_mode, uint8_t verify) 6949 { 6950 struct crypto_testsuite_params *ts_params = &testsuite_params; 6951 struct crypto_unittest_params *ut_params = &unittest_params; 6952 6953 int retval; 6954 6955 const uint8_t *plaintext = NULL; 6956 const uint8_t *ciphertext = NULL; 6957 const uint8_t *digest = NULL; 6958 unsigned int plaintext_pad_len; 6959 unsigned int plaintext_len; 6960 unsigned int ciphertext_pad_len; 6961 unsigned int ciphertext_len; 6962 uint8_t buffer[10000]; 6963 uint8_t digest_buffer[10000]; 6964 6965 struct rte_cryptodev_info dev_info; 6966 struct rte_crypto_op *op; 6967 6968 /* Check if device supports particular algorithms */ 6969 if (test_mixed_check_if_unsupported(tdata)) 6970 return -ENOTSUP; 6971 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 6972 return -ENOTSUP; 6973 6974 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 6975 6976 uint64_t feat_flags = dev_info.feature_flags; 6977 6978 if (op_mode == IN_PLACE) { 6979 if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { 6980 printf("Device doesn't support in-place scatter-gather " 6981 "in both input and output mbufs.\n"); 6982 return -ENOTSUP; 6983 } 6984 } else { 6985 if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) { 6986 printf("Device doesn't support out-of-place scatter-gather " 6987 "in both input and output mbufs.\n"); 6988 return -ENOTSUP; 6989 } 6990 if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) { 6991 printf("Device doesn't support digest encrypted.\n"); 6992 return -ENOTSUP; 6993 } 6994 } 6995 6996 /* Create the session */ 6997 if (verify) 6998 retval = create_wireless_algo_cipher_auth_session( 6999 ts_params->valid_devs[0], 7000 RTE_CRYPTO_CIPHER_OP_DECRYPT, 7001 RTE_CRYPTO_AUTH_OP_VERIFY, 7002 tdata->auth_algo, 7003 tdata->cipher_algo, 7004 tdata->auth_key.data, tdata->auth_key.len, 7005 tdata->auth_iv.len, tdata->digest_enc.len, 7006 tdata->cipher_iv.len); 7007 else 7008 retval = create_wireless_algo_auth_cipher_session( 7009 ts_params->valid_devs[0], 7010 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 7011 RTE_CRYPTO_AUTH_OP_GENERATE, 7012 tdata->auth_algo, 7013 tdata->cipher_algo, 7014 tdata->auth_key.data, tdata->auth_key.len, 7015 tdata->auth_iv.len, tdata->digest_enc.len, 7016 tdata->cipher_iv.len); 7017 if (retval < 0) 7018 return retval; 7019 7020 ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits); 7021 plaintext_len = ceil_byte_length(tdata->plaintext.len_bits); 7022 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 7023 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16); 7024 7025 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, 7026 ciphertext_pad_len, 15, 0); 7027 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 7028 "Failed to allocate input buffer in mempool"); 7029 7030 if (op_mode == OUT_OF_PLACE) { 7031 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool, 7032 plaintext_pad_len, 15, 0); 7033 TEST_ASSERT_NOT_NULL(ut_params->obuf, 7034 "Failed to allocate output buffer in mempool"); 7035 } 7036 7037 if (verify) { 7038 pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, 7039 tdata->ciphertext.data); 7040 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7041 ciphertext_len, buffer); 7042 debug_hexdump(stdout, "ciphertext:", ciphertext, 7043 ciphertext_len); 7044 } else { 7045 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, 7046 tdata->plaintext.data); 7047 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7048 plaintext_len, buffer); 7049 debug_hexdump(stdout, "plaintext:", plaintext, 7050 plaintext_len); 7051 } 7052 memset(buffer, 0, sizeof(buffer)); 7053 7054 /* Create the operation */ 7055 retval = create_wireless_algo_auth_cipher_operation( 7056 tdata->digest_enc.data, tdata->digest_enc.len, 7057 tdata->cipher_iv.data, tdata->cipher_iv.len, 7058 tdata->auth_iv.data, tdata->auth_iv.len, 7059 (tdata->digest_enc.offset == 0 ? 7060 plaintext_pad_len 7061 : tdata->digest_enc.offset), 7062 tdata->validCipherLen.len_bits, 7063 tdata->cipher.offset_bits, 7064 tdata->validAuthLen.len_bits, 7065 tdata->auth.offset_bits, 7066 op_mode, 1, verify); 7067 7068 if (retval < 0) 7069 return retval; 7070 7071 op = process_crypto_request(ts_params->valid_devs[0], ut_params->op); 7072 7073 /* Check if the op failed because the device doesn't */ 7074 /* support this particular combination of algorithms */ 7075 if (op == NULL && ut_params->op->status == 7076 RTE_CRYPTO_OP_STATUS_INVALID_SESSION) { 7077 printf("Device doesn't support this mixed combination. " 7078 "Test Skipped.\n"); 7079 return -ENOTSUP; 7080 } 7081 ut_params->op = op; 7082 7083 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf"); 7084 7085 ut_params->obuf = (op_mode == IN_PLACE ? 7086 ut_params->op->sym->m_src : ut_params->op->sym->m_dst); 7087 7088 if (verify) { 7089 if (ut_params->obuf) 7090 plaintext = rte_pktmbuf_read(ut_params->obuf, 0, 7091 plaintext_len, buffer); 7092 else 7093 plaintext = rte_pktmbuf_read(ut_params->ibuf, 0, 7094 plaintext_len, buffer); 7095 7096 debug_hexdump(stdout, "plaintext:", plaintext, 7097 (tdata->plaintext.len_bits >> 3) - 7098 tdata->digest_enc.len); 7099 debug_hexdump(stdout, "plaintext expected:", 7100 tdata->plaintext.data, 7101 (tdata->plaintext.len_bits >> 3) - 7102 tdata->digest_enc.len); 7103 } else { 7104 if (ut_params->obuf) 7105 ciphertext = rte_pktmbuf_read(ut_params->obuf, 0, 7106 ciphertext_len, buffer); 7107 else 7108 ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0, 7109 ciphertext_len, buffer); 7110 7111 debug_hexdump(stdout, "ciphertext:", ciphertext, 7112 ciphertext_len); 7113 debug_hexdump(stdout, "ciphertext expected:", 7114 tdata->ciphertext.data, 7115 tdata->ciphertext.len_bits >> 3); 7116 7117 if (ut_params->obuf) 7118 digest = rte_pktmbuf_read(ut_params->obuf, 7119 (tdata->digest_enc.offset == 0 ? 7120 plaintext_pad_len : 7121 tdata->digest_enc.offset), 7122 tdata->digest_enc.len, digest_buffer); 7123 else 7124 digest = rte_pktmbuf_read(ut_params->ibuf, 7125 (tdata->digest_enc.offset == 0 ? 7126 plaintext_pad_len : 7127 tdata->digest_enc.offset), 7128 tdata->digest_enc.len, digest_buffer); 7129 7130 debug_hexdump(stdout, "digest:", digest, 7131 tdata->digest_enc.len); 7132 debug_hexdump(stdout, "digest expected:", 7133 tdata->digest_enc.data, tdata->digest_enc.len); 7134 } 7135 7136 /* Validate obuf */ 7137 if (verify) { 7138 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7139 plaintext, 7140 tdata->plaintext.data, 7141 tdata->plaintext.len_bits >> 3, 7142 "Plaintext data not as expected"); 7143 } else { 7144 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( 7145 ciphertext, 7146 tdata->ciphertext.data, 7147 tdata->validDataLen.len_bits, 7148 "Ciphertext data not as expected"); 7149 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7150 digest, 7151 tdata->digest_enc.data, 7152 tdata->digest_enc.len, 7153 "Generated auth tag not as expected"); 7154 } 7155 7156 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7157 "crypto op processing failed"); 7158 7159 return 0; 7160 } 7161 7162 /** AUTH AES CMAC + CIPHER AES CTR */ 7163 7164 static int 7165 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7166 { 7167 return test_mixed_auth_cipher( 7168 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7169 } 7170 7171 static int 7172 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7173 { 7174 return test_mixed_auth_cipher( 7175 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7176 } 7177 7178 static int 7179 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7180 { 7181 return test_mixed_auth_cipher_sgl( 7182 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0); 7183 } 7184 7185 static int 7186 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7187 { 7188 return test_mixed_auth_cipher_sgl( 7189 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7190 } 7191 7192 static int 7193 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void) 7194 { 7195 return test_mixed_auth_cipher( 7196 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7197 } 7198 7199 static int 7200 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void) 7201 { 7202 return test_mixed_auth_cipher( 7203 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7204 } 7205 7206 static int 7207 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void) 7208 { 7209 return test_mixed_auth_cipher_sgl( 7210 &auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1); 7211 } 7212 7213 static int 7214 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void) 7215 { 7216 return test_mixed_auth_cipher_sgl( 7217 &auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7218 } 7219 7220 /** MIXED AUTH + CIPHER */ 7221 7222 static int 7223 test_auth_zuc_cipher_snow_test_case_1(void) 7224 { 7225 return test_mixed_auth_cipher( 7226 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7227 } 7228 7229 static int 7230 test_verify_auth_zuc_cipher_snow_test_case_1(void) 7231 { 7232 return test_mixed_auth_cipher( 7233 &auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7234 } 7235 7236 static int 7237 test_auth_aes_cmac_cipher_snow_test_case_1(void) 7238 { 7239 return test_mixed_auth_cipher( 7240 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7241 } 7242 7243 static int 7244 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void) 7245 { 7246 return test_mixed_auth_cipher( 7247 &auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7248 } 7249 7250 static int 7251 test_auth_zuc_cipher_aes_ctr_test_case_1(void) 7252 { 7253 return test_mixed_auth_cipher( 7254 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7255 } 7256 7257 static int 7258 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void) 7259 { 7260 return test_mixed_auth_cipher( 7261 &auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7262 } 7263 7264 static int 7265 test_auth_snow_cipher_aes_ctr_test_case_1(void) 7266 { 7267 return test_mixed_auth_cipher( 7268 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7269 } 7270 7271 static int 7272 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void) 7273 { 7274 return test_mixed_auth_cipher( 7275 &auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7276 } 7277 7278 static int 7279 test_auth_snow_cipher_zuc_test_case_1(void) 7280 { 7281 return test_mixed_auth_cipher( 7282 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7283 } 7284 7285 static int 7286 test_verify_auth_snow_cipher_zuc_test_case_1(void) 7287 { 7288 return test_mixed_auth_cipher( 7289 &auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7290 } 7291 7292 static int 7293 test_auth_aes_cmac_cipher_zuc_test_case_1(void) 7294 { 7295 return test_mixed_auth_cipher( 7296 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7297 } 7298 7299 static int 7300 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void) 7301 { 7302 return test_mixed_auth_cipher( 7303 &auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7304 } 7305 7306 static int 7307 test_auth_null_cipher_snow_test_case_1(void) 7308 { 7309 return test_mixed_auth_cipher( 7310 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0); 7311 } 7312 7313 static int 7314 test_verify_auth_null_cipher_snow_test_case_1(void) 7315 { 7316 return test_mixed_auth_cipher( 7317 &auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1); 7318 } 7319 7320 static int 7321 test_auth_null_cipher_zuc_test_case_1(void) 7322 { 7323 return test_mixed_auth_cipher( 7324 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0); 7325 } 7326 7327 static int 7328 test_verify_auth_null_cipher_zuc_test_case_1(void) 7329 { 7330 return test_mixed_auth_cipher( 7331 &auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1); 7332 } 7333 7334 static int 7335 test_auth_snow_cipher_null_test_case_1(void) 7336 { 7337 return test_mixed_auth_cipher( 7338 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7339 } 7340 7341 static int 7342 test_verify_auth_snow_cipher_null_test_case_1(void) 7343 { 7344 return test_mixed_auth_cipher( 7345 &auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7346 } 7347 7348 static int 7349 test_auth_zuc_cipher_null_test_case_1(void) 7350 { 7351 return test_mixed_auth_cipher( 7352 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7353 } 7354 7355 static int 7356 test_verify_auth_zuc_cipher_null_test_case_1(void) 7357 { 7358 return test_mixed_auth_cipher( 7359 &auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7360 } 7361 7362 static int 7363 test_auth_null_cipher_aes_ctr_test_case_1(void) 7364 { 7365 return test_mixed_auth_cipher( 7366 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0); 7367 } 7368 7369 static int 7370 test_verify_auth_null_cipher_aes_ctr_test_case_1(void) 7371 { 7372 return test_mixed_auth_cipher( 7373 &auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1); 7374 } 7375 7376 static int 7377 test_auth_aes_cmac_cipher_null_test_case_1(void) 7378 { 7379 return test_mixed_auth_cipher( 7380 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0); 7381 } 7382 7383 static int 7384 test_verify_auth_aes_cmac_cipher_null_test_case_1(void) 7385 { 7386 return test_mixed_auth_cipher( 7387 &auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1); 7388 } 7389 7390 /* ***** AEAD algorithm Tests ***** */ 7391 7392 static int 7393 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo, 7394 enum rte_crypto_aead_operation op, 7395 const uint8_t *key, const uint8_t key_len, 7396 const uint16_t aad_len, const uint8_t auth_len, 7397 uint8_t iv_len) 7398 { 7399 uint8_t aead_key[key_len]; 7400 7401 struct crypto_testsuite_params *ts_params = &testsuite_params; 7402 struct crypto_unittest_params *ut_params = &unittest_params; 7403 7404 memcpy(aead_key, key, key_len); 7405 7406 /* Setup AEAD Parameters */ 7407 ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 7408 ut_params->aead_xform.next = NULL; 7409 ut_params->aead_xform.aead.algo = algo; 7410 ut_params->aead_xform.aead.op = op; 7411 ut_params->aead_xform.aead.key.data = aead_key; 7412 ut_params->aead_xform.aead.key.length = key_len; 7413 ut_params->aead_xform.aead.iv.offset = IV_OFFSET; 7414 ut_params->aead_xform.aead.iv.length = iv_len; 7415 ut_params->aead_xform.aead.digest_length = auth_len; 7416 ut_params->aead_xform.aead.aad_length = aad_len; 7417 7418 debug_hexdump(stdout, "key:", key, key_len); 7419 7420 /* Create Crypto session*/ 7421 ut_params->sess = rte_cryptodev_sym_session_create( 7422 ts_params->session_mpool); 7423 7424 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 7425 &ut_params->aead_xform, 7426 ts_params->session_priv_mpool); 7427 7428 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 7429 7430 return 0; 7431 } 7432 7433 static int 7434 create_aead_xform(struct rte_crypto_op *op, 7435 enum rte_crypto_aead_algorithm algo, 7436 enum rte_crypto_aead_operation aead_op, 7437 uint8_t *key, const uint8_t key_len, 7438 const uint8_t aad_len, const uint8_t auth_len, 7439 uint8_t iv_len) 7440 { 7441 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1), 7442 "failed to allocate space for crypto transform"); 7443 7444 struct rte_crypto_sym_op *sym_op = op->sym; 7445 7446 /* Setup AEAD Parameters */ 7447 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD; 7448 sym_op->xform->next = NULL; 7449 sym_op->xform->aead.algo = algo; 7450 sym_op->xform->aead.op = aead_op; 7451 sym_op->xform->aead.key.data = key; 7452 sym_op->xform->aead.key.length = key_len; 7453 sym_op->xform->aead.iv.offset = IV_OFFSET; 7454 sym_op->xform->aead.iv.length = iv_len; 7455 sym_op->xform->aead.digest_length = auth_len; 7456 sym_op->xform->aead.aad_length = aad_len; 7457 7458 debug_hexdump(stdout, "key:", key, key_len); 7459 7460 return 0; 7461 } 7462 7463 static int 7464 create_aead_operation(enum rte_crypto_aead_operation op, 7465 const struct aead_test_data *tdata) 7466 { 7467 struct crypto_testsuite_params *ts_params = &testsuite_params; 7468 struct crypto_unittest_params *ut_params = &unittest_params; 7469 7470 uint8_t *plaintext, *ciphertext; 7471 unsigned int aad_pad_len, plaintext_pad_len; 7472 7473 /* Generate Crypto op data structure */ 7474 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 7475 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 7476 TEST_ASSERT_NOT_NULL(ut_params->op, 7477 "Failed to allocate symmetric crypto operation struct"); 7478 7479 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 7480 7481 /* Append aad data */ 7482 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 7483 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16); 7484 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7485 aad_pad_len); 7486 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 7487 "no room to append aad"); 7488 7489 sym_op->aead.aad.phys_addr = 7490 rte_pktmbuf_iova(ut_params->ibuf); 7491 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 7492 memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len); 7493 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 7494 tdata->aad.len); 7495 7496 /* Append IV at the end of the crypto operation*/ 7497 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 7498 uint8_t *, IV_OFFSET); 7499 7500 /* Copy IV 1 byte after the IV pointer, according to the API */ 7501 rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len); 7502 debug_hexdump(stdout, "iv:", iv_ptr, 7503 tdata->iv.len); 7504 } else { 7505 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 7506 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7507 aad_pad_len); 7508 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 7509 "no room to append aad"); 7510 7511 sym_op->aead.aad.phys_addr = 7512 rte_pktmbuf_iova(ut_params->ibuf); 7513 memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len); 7514 debug_hexdump(stdout, "aad:", sym_op->aead.aad.data, 7515 tdata->aad.len); 7516 7517 /* Append IV at the end of the crypto operation*/ 7518 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 7519 uint8_t *, IV_OFFSET); 7520 7521 if (tdata->iv.len == 0) { 7522 rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH); 7523 debug_hexdump(stdout, "iv:", iv_ptr, 7524 AES_GCM_J0_LENGTH); 7525 } else { 7526 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 7527 debug_hexdump(stdout, "iv:", iv_ptr, 7528 tdata->iv.len); 7529 } 7530 } 7531 7532 /* Append plaintext/ciphertext */ 7533 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 7534 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 7535 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7536 plaintext_pad_len); 7537 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 7538 7539 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 7540 debug_hexdump(stdout, "plaintext:", plaintext, 7541 tdata->plaintext.len); 7542 7543 if (ut_params->obuf) { 7544 ciphertext = (uint8_t *)rte_pktmbuf_append( 7545 ut_params->obuf, 7546 plaintext_pad_len + aad_pad_len); 7547 TEST_ASSERT_NOT_NULL(ciphertext, 7548 "no room to append ciphertext"); 7549 7550 memset(ciphertext + aad_pad_len, 0, 7551 tdata->ciphertext.len); 7552 } 7553 } else { 7554 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16); 7555 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7556 plaintext_pad_len); 7557 TEST_ASSERT_NOT_NULL(ciphertext, 7558 "no room to append ciphertext"); 7559 7560 memcpy(ciphertext, tdata->ciphertext.data, 7561 tdata->ciphertext.len); 7562 debug_hexdump(stdout, "ciphertext:", ciphertext, 7563 tdata->ciphertext.len); 7564 7565 if (ut_params->obuf) { 7566 plaintext = (uint8_t *)rte_pktmbuf_append( 7567 ut_params->obuf, 7568 plaintext_pad_len + aad_pad_len); 7569 TEST_ASSERT_NOT_NULL(plaintext, 7570 "no room to append plaintext"); 7571 7572 memset(plaintext + aad_pad_len, 0, 7573 tdata->plaintext.len); 7574 } 7575 } 7576 7577 /* Append digest data */ 7578 if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) { 7579 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 7580 ut_params->obuf ? ut_params->obuf : 7581 ut_params->ibuf, 7582 tdata->auth_tag.len); 7583 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 7584 "no room to append digest"); 7585 memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len); 7586 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 7587 ut_params->obuf ? ut_params->obuf : 7588 ut_params->ibuf, 7589 plaintext_pad_len + 7590 aad_pad_len); 7591 } else { 7592 sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( 7593 ut_params->ibuf, tdata->auth_tag.len); 7594 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 7595 "no room to append digest"); 7596 sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset( 7597 ut_params->ibuf, 7598 plaintext_pad_len + aad_pad_len); 7599 7600 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 7601 tdata->auth_tag.len); 7602 debug_hexdump(stdout, "digest:", 7603 sym_op->aead.digest.data, 7604 tdata->auth_tag.len); 7605 } 7606 7607 sym_op->aead.data.length = tdata->plaintext.len; 7608 sym_op->aead.data.offset = aad_pad_len; 7609 7610 return 0; 7611 } 7612 7613 static int 7614 test_authenticated_encryption(const struct aead_test_data *tdata) 7615 { 7616 struct crypto_testsuite_params *ts_params = &testsuite_params; 7617 struct crypto_unittest_params *ut_params = &unittest_params; 7618 7619 int retval; 7620 uint8_t *ciphertext, *auth_tag; 7621 uint16_t plaintext_pad_len; 7622 uint32_t i; 7623 struct rte_cryptodev_info dev_info; 7624 7625 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 7626 uint64_t feat_flags = dev_info.feature_flags; 7627 7628 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 7629 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 7630 printf("Device doesn't support RAW data-path APIs.\n"); 7631 return -ENOTSUP; 7632 } 7633 7634 /* Verify the capabilities */ 7635 struct rte_cryptodev_sym_capability_idx cap_idx; 7636 const struct rte_cryptodev_symmetric_capability *capability; 7637 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 7638 cap_idx.algo.aead = tdata->algo; 7639 capability = rte_cryptodev_sym_capability_get( 7640 ts_params->valid_devs[0], &cap_idx); 7641 if (capability == NULL) 7642 return -ENOTSUP; 7643 if (rte_cryptodev_sym_capability_check_aead( 7644 capability, tdata->key.len, tdata->auth_tag.len, 7645 tdata->aad.len, tdata->iv.len)) 7646 return -ENOTSUP; 7647 7648 /* Create AEAD session */ 7649 retval = create_aead_session(ts_params->valid_devs[0], 7650 tdata->algo, 7651 RTE_CRYPTO_AEAD_OP_ENCRYPT, 7652 tdata->key.data, tdata->key.len, 7653 tdata->aad.len, tdata->auth_tag.len, 7654 tdata->iv.len); 7655 if (retval < 0) 7656 return retval; 7657 7658 if (tdata->aad.len > MBUF_SIZE) { 7659 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 7660 /* Populate full size of add data */ 7661 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 7662 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 7663 } else 7664 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7665 7666 /* clear mbuf payload */ 7667 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7668 rte_pktmbuf_tailroom(ut_params->ibuf)); 7669 7670 /* Create AEAD operation */ 7671 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 7672 if (retval < 0) 7673 return retval; 7674 7675 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 7676 7677 ut_params->op->sym->m_src = ut_params->ibuf; 7678 7679 /* Process crypto operation */ 7680 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 7681 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 7682 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 7683 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 7684 ut_params->op, 0, 0, 0, 0); 7685 else 7686 TEST_ASSERT_NOT_NULL( 7687 process_crypto_request(ts_params->valid_devs[0], 7688 ut_params->op), "failed to process sym crypto op"); 7689 7690 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 7691 "crypto op processing failed"); 7692 7693 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 7694 7695 if (ut_params->op->sym->m_dst) { 7696 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 7697 uint8_t *); 7698 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 7699 uint8_t *, plaintext_pad_len); 7700 } else { 7701 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 7702 uint8_t *, 7703 ut_params->op->sym->cipher.data.offset); 7704 auth_tag = ciphertext + plaintext_pad_len; 7705 } 7706 7707 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 7708 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 7709 7710 /* Validate obuf */ 7711 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7712 ciphertext, 7713 tdata->ciphertext.data, 7714 tdata->ciphertext.len, 7715 "Ciphertext data not as expected"); 7716 7717 TEST_ASSERT_BUFFERS_ARE_EQUAL( 7718 auth_tag, 7719 tdata->auth_tag.data, 7720 tdata->auth_tag.len, 7721 "Generated auth tag not as expected"); 7722 7723 return 0; 7724 7725 } 7726 7727 #ifdef RTE_LIB_SECURITY 7728 static int 7729 security_proto_supported(enum rte_security_session_action_type action, 7730 enum rte_security_session_protocol proto) 7731 { 7732 struct crypto_testsuite_params *ts_params = &testsuite_params; 7733 7734 const struct rte_security_capability *capabilities; 7735 const struct rte_security_capability *capability; 7736 uint16_t i = 0; 7737 7738 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 7739 rte_cryptodev_get_sec_ctx( 7740 ts_params->valid_devs[0]); 7741 7742 7743 capabilities = rte_security_capabilities_get(ctx); 7744 7745 if (capabilities == NULL) 7746 return -ENOTSUP; 7747 7748 while ((capability = &capabilities[i++])->action != 7749 RTE_SECURITY_ACTION_TYPE_NONE) { 7750 if (capability->action == action && 7751 capability->protocol == proto) 7752 return 0; 7753 } 7754 7755 return -ENOTSUP; 7756 } 7757 7758 /* Basic algorithm run function for async inplace mode. 7759 * Creates a session from input parameters and runs one operation 7760 * on input_vec. Checks the output of the crypto operation against 7761 * output_vec. 7762 */ 7763 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc, 7764 enum rte_crypto_auth_operation opa, 7765 const uint8_t *input_vec, unsigned int input_vec_len, 7766 const uint8_t *output_vec, 7767 unsigned int output_vec_len, 7768 enum rte_crypto_cipher_algorithm cipher_alg, 7769 const uint8_t *cipher_key, uint32_t cipher_key_len, 7770 enum rte_crypto_auth_algorithm auth_alg, 7771 const uint8_t *auth_key, uint32_t auth_key_len, 7772 uint8_t bearer, enum rte_security_pdcp_domain domain, 7773 uint8_t packet_direction, uint8_t sn_size, 7774 uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap) 7775 { 7776 struct crypto_testsuite_params *ts_params = &testsuite_params; 7777 struct crypto_unittest_params *ut_params = &unittest_params; 7778 uint8_t *plaintext; 7779 int ret = TEST_SUCCESS; 7780 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 7781 rte_cryptodev_get_sec_ctx( 7782 ts_params->valid_devs[0]); 7783 7784 /* Verify the capabilities */ 7785 struct rte_security_capability_idx sec_cap_idx; 7786 7787 sec_cap_idx.action = ut_params->type; 7788 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 7789 sec_cap_idx.pdcp.domain = domain; 7790 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 7791 return -ENOTSUP; 7792 7793 /* Generate test mbuf data */ 7794 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7795 7796 /* clear mbuf payload */ 7797 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 7798 rte_pktmbuf_tailroom(ut_params->ibuf)); 7799 7800 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 7801 input_vec_len); 7802 memcpy(plaintext, input_vec, input_vec_len); 7803 7804 /* Out of place support */ 7805 if (oop) { 7806 /* 7807 * For out-op-place we need to alloc another mbuf 7808 */ 7809 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 7810 rte_pktmbuf_append(ut_params->obuf, output_vec_len); 7811 } 7812 7813 /* Setup Cipher Parameters */ 7814 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 7815 ut_params->cipher_xform.cipher.algo = cipher_alg; 7816 ut_params->cipher_xform.cipher.op = opc; 7817 ut_params->cipher_xform.cipher.key.data = cipher_key; 7818 ut_params->cipher_xform.cipher.key.length = cipher_key_len; 7819 ut_params->cipher_xform.cipher.iv.length = 7820 packet_direction ? 4 : 0; 7821 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 7822 7823 /* Setup HMAC Parameters if ICV header is required */ 7824 if (auth_alg != 0) { 7825 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 7826 ut_params->auth_xform.next = NULL; 7827 ut_params->auth_xform.auth.algo = auth_alg; 7828 ut_params->auth_xform.auth.op = opa; 7829 ut_params->auth_xform.auth.key.data = auth_key; 7830 ut_params->auth_xform.auth.key.length = auth_key_len; 7831 7832 ut_params->cipher_xform.next = &ut_params->auth_xform; 7833 } else { 7834 ut_params->cipher_xform.next = NULL; 7835 } 7836 7837 struct rte_security_session_conf sess_conf = { 7838 .action_type = ut_params->type, 7839 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 7840 {.pdcp = { 7841 .bearer = bearer, 7842 .domain = domain, 7843 .pkt_dir = packet_direction, 7844 .sn_size = sn_size, 7845 .hfn = packet_direction ? 0 : hfn, 7846 /** 7847 * hfn can be set as pdcp_test_hfn[i] 7848 * if hfn_ovrd is not set. Here, PDCP 7849 * packet direction is just used to 7850 * run half of the cases with session 7851 * HFN and other half with per packet 7852 * HFN. 7853 */ 7854 .hfn_threshold = hfn_threshold, 7855 .hfn_ovrd = packet_direction ? 1 : 0, 7856 .sdap_enabled = sdap, 7857 } }, 7858 .crypto_xform = &ut_params->cipher_xform 7859 }; 7860 7861 /* Create security session */ 7862 ut_params->sec_session = rte_security_session_create(ctx, 7863 &sess_conf, ts_params->session_mpool, 7864 ts_params->session_priv_mpool); 7865 7866 if (!ut_params->sec_session) { 7867 printf("TestCase %s()-%d line %d failed %s: ", 7868 __func__, i, __LINE__, "Failed to allocate session"); 7869 ret = TEST_FAILED; 7870 goto on_err; 7871 } 7872 7873 /* Generate crypto op data structure */ 7874 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 7875 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 7876 if (!ut_params->op) { 7877 printf("TestCase %s()-%d line %d failed %s: ", 7878 __func__, i, __LINE__, 7879 "Failed to allocate symmetric crypto operation struct"); 7880 ret = TEST_FAILED; 7881 goto on_err; 7882 } 7883 7884 uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op, 7885 uint32_t *, IV_OFFSET); 7886 *per_pkt_hfn = packet_direction ? hfn : 0; 7887 7888 rte_security_attach_session(ut_params->op, ut_params->sec_session); 7889 7890 /* set crypto operation source mbuf */ 7891 ut_params->op->sym->m_src = ut_params->ibuf; 7892 if (oop) 7893 ut_params->op->sym->m_dst = ut_params->obuf; 7894 7895 /* Process crypto operation */ 7896 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) 7897 == NULL) { 7898 printf("TestCase %s()-%d line %d failed %s: ", 7899 __func__, i, __LINE__, 7900 "failed to process sym crypto op"); 7901 ret = TEST_FAILED; 7902 goto on_err; 7903 } 7904 7905 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 7906 printf("TestCase %s()-%d line %d failed %s: ", 7907 __func__, i, __LINE__, "crypto op processing failed"); 7908 ret = TEST_FAILED; 7909 goto on_err; 7910 } 7911 7912 /* Validate obuf */ 7913 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 7914 uint8_t *); 7915 if (oop) { 7916 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 7917 uint8_t *); 7918 } 7919 7920 if (memcmp(ciphertext, output_vec, output_vec_len)) { 7921 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 7922 rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len); 7923 rte_hexdump(stdout, "reference", output_vec, output_vec_len); 7924 ret = TEST_FAILED; 7925 goto on_err; 7926 } 7927 7928 on_err: 7929 rte_crypto_op_free(ut_params->op); 7930 ut_params->op = NULL; 7931 7932 if (ut_params->sec_session) 7933 rte_security_session_destroy(ctx, ut_params->sec_session); 7934 ut_params->sec_session = NULL; 7935 7936 rte_pktmbuf_free(ut_params->ibuf); 7937 ut_params->ibuf = NULL; 7938 if (oop) { 7939 rte_pktmbuf_free(ut_params->obuf); 7940 ut_params->obuf = NULL; 7941 } 7942 7943 return ret; 7944 } 7945 7946 static int 7947 test_pdcp_proto_SGL(int i, int oop, 7948 enum rte_crypto_cipher_operation opc, 7949 enum rte_crypto_auth_operation opa, 7950 uint8_t *input_vec, 7951 unsigned int input_vec_len, 7952 uint8_t *output_vec, 7953 unsigned int output_vec_len, 7954 uint32_t fragsz, 7955 uint32_t fragsz_oop) 7956 { 7957 struct crypto_testsuite_params *ts_params = &testsuite_params; 7958 struct crypto_unittest_params *ut_params = &unittest_params; 7959 uint8_t *plaintext; 7960 struct rte_mbuf *buf, *buf_oop = NULL; 7961 int ret = TEST_SUCCESS; 7962 int to_trn = 0; 7963 int to_trn_tbl[16]; 7964 int segs = 1; 7965 unsigned int trn_data = 0; 7966 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 7967 rte_cryptodev_get_sec_ctx( 7968 ts_params->valid_devs[0]); 7969 7970 /* Verify the capabilities */ 7971 struct rte_security_capability_idx sec_cap_idx; 7972 7973 sec_cap_idx.action = ut_params->type; 7974 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP; 7975 sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain; 7976 if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL) 7977 return -ENOTSUP; 7978 7979 if (fragsz > input_vec_len) 7980 fragsz = input_vec_len; 7981 7982 uint16_t plaintext_len = fragsz; 7983 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 7984 7985 if (fragsz_oop > output_vec_len) 7986 frag_size_oop = output_vec_len; 7987 7988 int ecx = 0; 7989 if (input_vec_len % fragsz != 0) { 7990 if (input_vec_len / fragsz + 1 > 16) 7991 return 1; 7992 } else if (input_vec_len / fragsz > 16) 7993 return 1; 7994 7995 /* Out of place support */ 7996 if (oop) { 7997 /* 7998 * For out-op-place we need to alloc another mbuf 7999 */ 8000 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8001 rte_pktmbuf_append(ut_params->obuf, frag_size_oop); 8002 buf_oop = ut_params->obuf; 8003 } 8004 8005 /* Generate test mbuf data */ 8006 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8007 8008 /* clear mbuf payload */ 8009 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8010 rte_pktmbuf_tailroom(ut_params->ibuf)); 8011 8012 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8013 plaintext_len); 8014 memcpy(plaintext, input_vec, plaintext_len); 8015 trn_data += plaintext_len; 8016 8017 buf = ut_params->ibuf; 8018 8019 /* 8020 * Loop until no more fragments 8021 */ 8022 8023 while (trn_data < input_vec_len) { 8024 ++segs; 8025 to_trn = (input_vec_len - trn_data < fragsz) ? 8026 (input_vec_len - trn_data) : fragsz; 8027 8028 to_trn_tbl[ecx++] = to_trn; 8029 8030 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8031 buf = buf->next; 8032 8033 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 8034 rte_pktmbuf_tailroom(buf)); 8035 8036 /* OOP */ 8037 if (oop && !fragsz_oop) { 8038 buf_oop->next = 8039 rte_pktmbuf_alloc(ts_params->mbuf_pool); 8040 buf_oop = buf_oop->next; 8041 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 8042 0, rte_pktmbuf_tailroom(buf_oop)); 8043 rte_pktmbuf_append(buf_oop, to_trn); 8044 } 8045 8046 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 8047 to_trn); 8048 8049 memcpy(plaintext, input_vec + trn_data, to_trn); 8050 trn_data += to_trn; 8051 } 8052 8053 ut_params->ibuf->nb_segs = segs; 8054 8055 segs = 1; 8056 if (fragsz_oop && oop) { 8057 to_trn = 0; 8058 ecx = 0; 8059 8060 trn_data = frag_size_oop; 8061 while (trn_data < output_vec_len) { 8062 ++segs; 8063 to_trn = 8064 (output_vec_len - trn_data < 8065 frag_size_oop) ? 8066 (output_vec_len - trn_data) : 8067 frag_size_oop; 8068 8069 to_trn_tbl[ecx++] = to_trn; 8070 8071 buf_oop->next = 8072 rte_pktmbuf_alloc(ts_params->mbuf_pool); 8073 buf_oop = buf_oop->next; 8074 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 8075 0, rte_pktmbuf_tailroom(buf_oop)); 8076 rte_pktmbuf_append(buf_oop, to_trn); 8077 8078 trn_data += to_trn; 8079 } 8080 ut_params->obuf->nb_segs = segs; 8081 } 8082 8083 /* Setup Cipher Parameters */ 8084 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8085 ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg; 8086 ut_params->cipher_xform.cipher.op = opc; 8087 ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i]; 8088 ut_params->cipher_xform.cipher.key.length = 8089 pdcp_test_params[i].cipher_key_len; 8090 ut_params->cipher_xform.cipher.iv.length = 0; 8091 8092 /* Setup HMAC Parameters if ICV header is required */ 8093 if (pdcp_test_params[i].auth_alg != 0) { 8094 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 8095 ut_params->auth_xform.next = NULL; 8096 ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg; 8097 ut_params->auth_xform.auth.op = opa; 8098 ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i]; 8099 ut_params->auth_xform.auth.key.length = 8100 pdcp_test_params[i].auth_key_len; 8101 8102 ut_params->cipher_xform.next = &ut_params->auth_xform; 8103 } else { 8104 ut_params->cipher_xform.next = NULL; 8105 } 8106 8107 struct rte_security_session_conf sess_conf = { 8108 .action_type = ut_params->type, 8109 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 8110 {.pdcp = { 8111 .bearer = pdcp_test_bearer[i], 8112 .domain = pdcp_test_params[i].domain, 8113 .pkt_dir = pdcp_test_packet_direction[i], 8114 .sn_size = pdcp_test_data_sn_size[i], 8115 .hfn = pdcp_test_hfn[i], 8116 .hfn_threshold = pdcp_test_hfn_threshold[i], 8117 .hfn_ovrd = 0, 8118 } }, 8119 .crypto_xform = &ut_params->cipher_xform 8120 }; 8121 8122 /* Create security session */ 8123 ut_params->sec_session = rte_security_session_create(ctx, 8124 &sess_conf, ts_params->session_mpool, 8125 ts_params->session_priv_mpool); 8126 8127 if (!ut_params->sec_session) { 8128 printf("TestCase %s()-%d line %d failed %s: ", 8129 __func__, i, __LINE__, "Failed to allocate session"); 8130 ret = TEST_FAILED; 8131 goto on_err; 8132 } 8133 8134 /* Generate crypto op data structure */ 8135 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8136 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8137 if (!ut_params->op) { 8138 printf("TestCase %s()-%d line %d failed %s: ", 8139 __func__, i, __LINE__, 8140 "Failed to allocate symmetric crypto operation struct"); 8141 ret = TEST_FAILED; 8142 goto on_err; 8143 } 8144 8145 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8146 8147 /* set crypto operation source mbuf */ 8148 ut_params->op->sym->m_src = ut_params->ibuf; 8149 if (oop) 8150 ut_params->op->sym->m_dst = ut_params->obuf; 8151 8152 /* Process crypto operation */ 8153 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) 8154 == NULL) { 8155 printf("TestCase %s()-%d line %d failed %s: ", 8156 __func__, i, __LINE__, 8157 "failed to process sym crypto op"); 8158 ret = TEST_FAILED; 8159 goto on_err; 8160 } 8161 8162 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8163 printf("TestCase %s()-%d line %d failed %s: ", 8164 __func__, i, __LINE__, "crypto op processing failed"); 8165 ret = TEST_FAILED; 8166 goto on_err; 8167 } 8168 8169 /* Validate obuf */ 8170 uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, 8171 uint8_t *); 8172 if (oop) { 8173 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 8174 uint8_t *); 8175 } 8176 if (fragsz_oop) 8177 fragsz = frag_size_oop; 8178 if (memcmp(ciphertext, output_vec, fragsz)) { 8179 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8180 rte_hexdump(stdout, "encrypted", ciphertext, fragsz); 8181 rte_hexdump(stdout, "reference", output_vec, fragsz); 8182 ret = TEST_FAILED; 8183 goto on_err; 8184 } 8185 8186 buf = ut_params->op->sym->m_src->next; 8187 if (oop) 8188 buf = ut_params->op->sym->m_dst->next; 8189 8190 unsigned int off = fragsz; 8191 8192 ecx = 0; 8193 while (buf) { 8194 ciphertext = rte_pktmbuf_mtod(buf, 8195 uint8_t *); 8196 if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) { 8197 printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); 8198 rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]); 8199 rte_hexdump(stdout, "reference", output_vec + off, 8200 to_trn_tbl[ecx]); 8201 ret = TEST_FAILED; 8202 goto on_err; 8203 } 8204 off += to_trn_tbl[ecx++]; 8205 buf = buf->next; 8206 } 8207 on_err: 8208 rte_crypto_op_free(ut_params->op); 8209 ut_params->op = NULL; 8210 8211 if (ut_params->sec_session) 8212 rte_security_session_destroy(ctx, ut_params->sec_session); 8213 ut_params->sec_session = NULL; 8214 8215 rte_pktmbuf_free(ut_params->ibuf); 8216 ut_params->ibuf = NULL; 8217 if (oop) { 8218 rte_pktmbuf_free(ut_params->obuf); 8219 ut_params->obuf = NULL; 8220 } 8221 8222 return ret; 8223 } 8224 8225 int 8226 test_pdcp_proto_cplane_encap(int i) 8227 { 8228 return test_pdcp_proto( 8229 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8230 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8231 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8232 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8233 pdcp_test_params[i].cipher_key_len, 8234 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8235 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8236 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8237 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8238 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8239 } 8240 8241 int 8242 test_pdcp_proto_uplane_encap(int i) 8243 { 8244 return test_pdcp_proto( 8245 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8246 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8247 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 8248 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8249 pdcp_test_params[i].cipher_key_len, 8250 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8251 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8252 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8253 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8254 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8255 } 8256 8257 int 8258 test_pdcp_proto_uplane_encap_with_int(int i) 8259 { 8260 return test_pdcp_proto( 8261 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE, 8262 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8263 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8264 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8265 pdcp_test_params[i].cipher_key_len, 8266 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8267 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8268 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8269 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8270 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8271 } 8272 8273 int 8274 test_pdcp_proto_cplane_decap(int i) 8275 { 8276 return test_pdcp_proto( 8277 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8278 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8279 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8280 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8281 pdcp_test_params[i].cipher_key_len, 8282 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8283 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8284 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8285 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8286 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8287 } 8288 8289 int 8290 test_pdcp_proto_uplane_decap(int i) 8291 { 8292 return test_pdcp_proto( 8293 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8294 pdcp_test_data_out[i], pdcp_test_data_in_len[i], 8295 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8296 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8297 pdcp_test_params[i].cipher_key_len, 8298 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8299 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8300 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8301 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8302 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8303 } 8304 8305 int 8306 test_pdcp_proto_uplane_decap_with_int(int i) 8307 { 8308 return test_pdcp_proto( 8309 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY, 8310 pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4, 8311 pdcp_test_data_in[i], pdcp_test_data_in_len[i], 8312 pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i], 8313 pdcp_test_params[i].cipher_key_len, 8314 pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i], 8315 pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i], 8316 pdcp_test_params[i].domain, pdcp_test_packet_direction[i], 8317 pdcp_test_data_sn_size[i], pdcp_test_hfn[i], 8318 pdcp_test_hfn_threshold[i], SDAP_DISABLED); 8319 } 8320 8321 static int 8322 test_PDCP_PROTO_SGL_in_place_32B(void) 8323 { 8324 /* i can be used for running any PDCP case 8325 * In this case it is uplane 12-bit AES-SNOW DL encap 8326 */ 8327 int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK; 8328 return test_pdcp_proto_SGL(i, IN_PLACE, 8329 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8330 RTE_CRYPTO_AUTH_OP_GENERATE, 8331 pdcp_test_data_in[i], 8332 pdcp_test_data_in_len[i], 8333 pdcp_test_data_out[i], 8334 pdcp_test_data_in_len[i]+4, 8335 32, 0); 8336 } 8337 static int 8338 test_PDCP_PROTO_SGL_oop_32B_128B(void) 8339 { 8340 /* i can be used for running any PDCP case 8341 * In this case it is uplane 18-bit NULL-NULL DL encap 8342 */ 8343 int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK; 8344 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8345 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8346 RTE_CRYPTO_AUTH_OP_GENERATE, 8347 pdcp_test_data_in[i], 8348 pdcp_test_data_in_len[i], 8349 pdcp_test_data_out[i], 8350 pdcp_test_data_in_len[i]+4, 8351 32, 128); 8352 } 8353 static int 8354 test_PDCP_PROTO_SGL_oop_32B_40B(void) 8355 { 8356 /* i can be used for running any PDCP case 8357 * In this case it is uplane 18-bit AES DL encap 8358 */ 8359 int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET 8360 + 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], 8368 32, 40); 8369 } 8370 static int 8371 test_PDCP_PROTO_SGL_oop_128B_32B(void) 8372 { 8373 /* i can be used for running any PDCP case 8374 * In this case it is cplane 12-bit AES-ZUC DL encap 8375 */ 8376 int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK; 8377 return test_pdcp_proto_SGL(i, OUT_OF_PLACE, 8378 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8379 RTE_CRYPTO_AUTH_OP_GENERATE, 8380 pdcp_test_data_in[i], 8381 pdcp_test_data_in_len[i], 8382 pdcp_test_data_out[i], 8383 pdcp_test_data_in_len[i]+4, 8384 128, 32); 8385 } 8386 8387 static int 8388 test_PDCP_SDAP_PROTO_encap_all(void) 8389 { 8390 int i = 0, size = 0; 8391 int err, all_err = TEST_SUCCESS; 8392 const struct pdcp_sdap_test *cur_test; 8393 8394 size = ARRAY_SIZE(list_pdcp_sdap_tests); 8395 8396 for (i = 0; i < size; i++) { 8397 cur_test = &list_pdcp_sdap_tests[i]; 8398 err = test_pdcp_proto( 8399 i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, 8400 RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in, 8401 cur_test->in_len, cur_test->data_out, 8402 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 8403 cur_test->param.cipher_alg, cur_test->cipher_key, 8404 cur_test->param.cipher_key_len, 8405 cur_test->param.auth_alg, 8406 cur_test->auth_key, cur_test->param.auth_key_len, 8407 cur_test->bearer, cur_test->param.domain, 8408 cur_test->packet_direction, cur_test->sn_size, 8409 cur_test->hfn, 8410 cur_test->hfn_threshold, SDAP_ENABLED); 8411 if (err) { 8412 printf("\t%d) %s: Encapsulation failed\n", 8413 cur_test->test_idx, 8414 cur_test->param.name); 8415 err = TEST_FAILED; 8416 } else { 8417 printf("\t%d) %s: Encap PASS\n", cur_test->test_idx, 8418 cur_test->param.name); 8419 err = TEST_SUCCESS; 8420 } 8421 all_err += err; 8422 } 8423 8424 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 8425 8426 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 8427 } 8428 8429 static int 8430 test_PDCP_SDAP_PROTO_decap_all(void) 8431 { 8432 int i = 0, size = 0; 8433 int err, all_err = TEST_SUCCESS; 8434 const struct pdcp_sdap_test *cur_test; 8435 8436 size = ARRAY_SIZE(list_pdcp_sdap_tests); 8437 8438 for (i = 0; i < size; i++) { 8439 cur_test = &list_pdcp_sdap_tests[i]; 8440 err = test_pdcp_proto( 8441 i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, 8442 RTE_CRYPTO_AUTH_OP_VERIFY, 8443 cur_test->data_out, 8444 cur_test->in_len + ((cur_test->auth_key) ? 4 : 0), 8445 cur_test->data_in, cur_test->in_len, 8446 cur_test->param.cipher_alg, 8447 cur_test->cipher_key, cur_test->param.cipher_key_len, 8448 cur_test->param.auth_alg, cur_test->auth_key, 8449 cur_test->param.auth_key_len, cur_test->bearer, 8450 cur_test->param.domain, cur_test->packet_direction, 8451 cur_test->sn_size, cur_test->hfn, 8452 cur_test->hfn_threshold, SDAP_ENABLED); 8453 if (err) { 8454 printf("\t%d) %s: Decapsulation failed\n", 8455 cur_test->test_idx, 8456 cur_test->param.name); 8457 err = TEST_FAILED; 8458 } else { 8459 printf("\t%d) %s: Decap PASS\n", cur_test->test_idx, 8460 cur_test->param.name); 8461 err = TEST_SUCCESS; 8462 } 8463 all_err += err; 8464 } 8465 8466 printf("Success: %d, Failure: %d\n", size + all_err, -all_err); 8467 8468 return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; 8469 } 8470 8471 static int 8472 test_PDCP_PROTO_all(void) 8473 { 8474 struct crypto_testsuite_params *ts_params = &testsuite_params; 8475 struct crypto_unittest_params *ut_params = &unittest_params; 8476 struct rte_cryptodev_info dev_info; 8477 int status; 8478 8479 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8480 uint64_t feat_flags = dev_info.feature_flags; 8481 8482 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 8483 return -ENOTSUP; 8484 8485 /* Set action type */ 8486 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 8487 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 8488 gbl_action_type; 8489 8490 if (security_proto_supported(ut_params->type, 8491 RTE_SECURITY_PROTOCOL_PDCP) < 0) 8492 return -ENOTSUP; 8493 8494 status = test_PDCP_PROTO_cplane_encap_all(); 8495 status += test_PDCP_PROTO_cplane_decap_all(); 8496 status += test_PDCP_PROTO_uplane_encap_all(); 8497 status += test_PDCP_PROTO_uplane_decap_all(); 8498 status += test_PDCP_PROTO_SGL_in_place_32B(); 8499 status += test_PDCP_PROTO_SGL_oop_32B_128B(); 8500 status += test_PDCP_PROTO_SGL_oop_32B_40B(); 8501 status += test_PDCP_PROTO_SGL_oop_128B_32B(); 8502 status += test_PDCP_SDAP_PROTO_encap_all(); 8503 status += test_PDCP_SDAP_PROTO_decap_all(); 8504 8505 if (status) 8506 return TEST_FAILED; 8507 else 8508 return TEST_SUCCESS; 8509 } 8510 8511 static int 8512 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td) 8513 { 8514 struct crypto_testsuite_params *ts_params = &testsuite_params; 8515 struct crypto_unittest_params *ut_params = &unittest_params; 8516 uint8_t *plaintext, *ciphertext; 8517 uint8_t *iv_ptr; 8518 int32_t cipher_len, crc_len; 8519 uint32_t crc_data_len; 8520 int ret = TEST_SUCCESS; 8521 8522 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8523 rte_cryptodev_get_sec_ctx( 8524 ts_params->valid_devs[0]); 8525 8526 /* Verify the capabilities */ 8527 struct rte_security_capability_idx sec_cap_idx; 8528 const struct rte_security_capability *sec_cap; 8529 const struct rte_cryptodev_capabilities *crypto_cap; 8530 const struct rte_cryptodev_symmetric_capability *sym_cap; 8531 int j = 0; 8532 8533 sec_cap_idx.action = ut_params->type; 8534 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 8535 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK; 8536 8537 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 8538 if (sec_cap == NULL) 8539 return -ENOTSUP; 8540 8541 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 8542 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 8543 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 8544 crypto_cap->sym.xform_type == 8545 RTE_CRYPTO_SYM_XFORM_CIPHER && 8546 crypto_cap->sym.cipher.algo == 8547 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 8548 sym_cap = &crypto_cap->sym; 8549 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 8550 d_td->key.len, 8551 d_td->iv.len) == 0) 8552 break; 8553 } 8554 } 8555 8556 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 8557 return -ENOTSUP; 8558 8559 /* Setup source mbuf payload */ 8560 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8561 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8562 rte_pktmbuf_tailroom(ut_params->ibuf)); 8563 8564 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8565 d_td->ciphertext.len); 8566 8567 memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len); 8568 8569 /* Setup cipher session parameters */ 8570 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8571 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 8572 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 8573 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 8574 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 8575 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 8576 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 8577 ut_params->cipher_xform.next = NULL; 8578 8579 /* Setup DOCSIS session parameters */ 8580 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK; 8581 8582 struct rte_security_session_conf sess_conf = { 8583 .action_type = ut_params->type, 8584 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 8585 .docsis = ut_params->docsis_xform, 8586 .crypto_xform = &ut_params->cipher_xform, 8587 }; 8588 8589 /* Create security session */ 8590 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 8591 ts_params->session_mpool, 8592 ts_params->session_priv_mpool); 8593 8594 if (!ut_params->sec_session) { 8595 printf("TestCase %s(%d) line %d: %s\n", 8596 __func__, i, __LINE__, "failed to allocate session"); 8597 ret = TEST_FAILED; 8598 goto on_err; 8599 } 8600 8601 /* Generate crypto op data structure */ 8602 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8603 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8604 if (!ut_params->op) { 8605 printf("TestCase %s(%d) line %d: %s\n", 8606 __func__, i, __LINE__, 8607 "failed to allocate symmetric crypto operation"); 8608 ret = TEST_FAILED; 8609 goto on_err; 8610 } 8611 8612 /* Setup CRC operation parameters */ 8613 crc_len = d_td->ciphertext.no_crc == false ? 8614 (d_td->ciphertext.len - 8615 d_td->ciphertext.crc_offset - 8616 RTE_ETHER_CRC_LEN) : 8617 0; 8618 crc_len = crc_len > 0 ? crc_len : 0; 8619 crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN; 8620 ut_params->op->sym->auth.data.length = crc_len; 8621 ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset; 8622 8623 /* Setup cipher operation parameters */ 8624 cipher_len = d_td->ciphertext.no_cipher == false ? 8625 (d_td->ciphertext.len - 8626 d_td->ciphertext.cipher_offset) : 8627 0; 8628 cipher_len = cipher_len > 0 ? cipher_len : 0; 8629 ut_params->op->sym->cipher.data.length = cipher_len; 8630 ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset; 8631 8632 /* Setup cipher IV */ 8633 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 8634 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 8635 8636 /* Attach session to operation */ 8637 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8638 8639 /* Set crypto operation mbufs */ 8640 ut_params->op->sym->m_src = ut_params->ibuf; 8641 ut_params->op->sym->m_dst = NULL; 8642 8643 /* Process crypto operation */ 8644 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 8645 NULL) { 8646 printf("TestCase %s(%d) line %d: %s\n", 8647 __func__, i, __LINE__, 8648 "failed to process security crypto op"); 8649 ret = TEST_FAILED; 8650 goto on_err; 8651 } 8652 8653 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8654 printf("TestCase %s(%d) line %d: %s\n", 8655 __func__, i, __LINE__, "crypto op processing failed"); 8656 ret = TEST_FAILED; 8657 goto on_err; 8658 } 8659 8660 /* Validate plaintext */ 8661 plaintext = ciphertext; 8662 8663 if (memcmp(plaintext, d_td->plaintext.data, 8664 d_td->plaintext.len - crc_data_len)) { 8665 printf("TestCase %s(%d) line %d: %s\n", 8666 __func__, i, __LINE__, "plaintext not as expected\n"); 8667 rte_hexdump(stdout, "expected", d_td->plaintext.data, 8668 d_td->plaintext.len); 8669 rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len); 8670 ret = TEST_FAILED; 8671 goto on_err; 8672 } 8673 8674 on_err: 8675 rte_crypto_op_free(ut_params->op); 8676 ut_params->op = NULL; 8677 8678 if (ut_params->sec_session) 8679 rte_security_session_destroy(ctx, ut_params->sec_session); 8680 ut_params->sec_session = NULL; 8681 8682 rte_pktmbuf_free(ut_params->ibuf); 8683 ut_params->ibuf = NULL; 8684 8685 return ret; 8686 } 8687 8688 static int 8689 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td) 8690 { 8691 struct crypto_testsuite_params *ts_params = &testsuite_params; 8692 struct crypto_unittest_params *ut_params = &unittest_params; 8693 uint8_t *plaintext, *ciphertext; 8694 uint8_t *iv_ptr; 8695 int32_t cipher_len, crc_len; 8696 int ret = TEST_SUCCESS; 8697 8698 struct rte_security_ctx *ctx = (struct rte_security_ctx *) 8699 rte_cryptodev_get_sec_ctx( 8700 ts_params->valid_devs[0]); 8701 8702 /* Verify the capabilities */ 8703 struct rte_security_capability_idx sec_cap_idx; 8704 const struct rte_security_capability *sec_cap; 8705 const struct rte_cryptodev_capabilities *crypto_cap; 8706 const struct rte_cryptodev_symmetric_capability *sym_cap; 8707 int j = 0; 8708 8709 sec_cap_idx.action = ut_params->type; 8710 sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS; 8711 sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 8712 8713 sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 8714 if (sec_cap == NULL) 8715 return -ENOTSUP; 8716 8717 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op != 8718 RTE_CRYPTO_OP_TYPE_UNDEFINED) { 8719 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC && 8720 crypto_cap->sym.xform_type == 8721 RTE_CRYPTO_SYM_XFORM_CIPHER && 8722 crypto_cap->sym.cipher.algo == 8723 RTE_CRYPTO_CIPHER_AES_DOCSISBPI) { 8724 sym_cap = &crypto_cap->sym; 8725 if (rte_cryptodev_sym_capability_check_cipher(sym_cap, 8726 d_td->key.len, 8727 d_td->iv.len) == 0) 8728 break; 8729 } 8730 } 8731 8732 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) 8733 return -ENOTSUP; 8734 8735 /* Setup source mbuf payload */ 8736 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 8737 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 8738 rte_pktmbuf_tailroom(ut_params->ibuf)); 8739 8740 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 8741 d_td->plaintext.len); 8742 8743 memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len); 8744 8745 /* Setup cipher session parameters */ 8746 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 8747 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI; 8748 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 8749 ut_params->cipher_xform.cipher.key.data = d_td->key.data; 8750 ut_params->cipher_xform.cipher.key.length = d_td->key.len; 8751 ut_params->cipher_xform.cipher.iv.length = d_td->iv.len; 8752 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 8753 ut_params->cipher_xform.next = NULL; 8754 8755 /* Setup DOCSIS session parameters */ 8756 ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK; 8757 8758 struct rte_security_session_conf sess_conf = { 8759 .action_type = ut_params->type, 8760 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 8761 .docsis = ut_params->docsis_xform, 8762 .crypto_xform = &ut_params->cipher_xform, 8763 }; 8764 8765 /* Create security session */ 8766 ut_params->sec_session = rte_security_session_create(ctx, &sess_conf, 8767 ts_params->session_mpool, 8768 ts_params->session_priv_mpool); 8769 8770 if (!ut_params->sec_session) { 8771 printf("TestCase %s(%d) line %d: %s\n", 8772 __func__, i, __LINE__, "failed to allocate session"); 8773 ret = TEST_FAILED; 8774 goto on_err; 8775 } 8776 8777 /* Generate crypto op data structure */ 8778 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 8779 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 8780 if (!ut_params->op) { 8781 printf("TestCase %s(%d) line %d: %s\n", 8782 __func__, i, __LINE__, 8783 "failed to allocate security crypto operation"); 8784 ret = TEST_FAILED; 8785 goto on_err; 8786 } 8787 8788 /* Setup CRC operation parameters */ 8789 crc_len = d_td->plaintext.no_crc == false ? 8790 (d_td->plaintext.len - 8791 d_td->plaintext.crc_offset - 8792 RTE_ETHER_CRC_LEN) : 8793 0; 8794 crc_len = crc_len > 0 ? crc_len : 0; 8795 ut_params->op->sym->auth.data.length = crc_len; 8796 ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset; 8797 8798 /* Setup cipher operation parameters */ 8799 cipher_len = d_td->plaintext.no_cipher == false ? 8800 (d_td->plaintext.len - 8801 d_td->plaintext.cipher_offset) : 8802 0; 8803 cipher_len = cipher_len > 0 ? cipher_len : 0; 8804 ut_params->op->sym->cipher.data.length = cipher_len; 8805 ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset; 8806 8807 /* Setup cipher IV */ 8808 iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET; 8809 rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len); 8810 8811 /* Attach session to operation */ 8812 rte_security_attach_session(ut_params->op, ut_params->sec_session); 8813 8814 /* Set crypto operation mbufs */ 8815 ut_params->op->sym->m_src = ut_params->ibuf; 8816 ut_params->op->sym->m_dst = NULL; 8817 8818 /* Process crypto operation */ 8819 if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) == 8820 NULL) { 8821 printf("TestCase %s(%d) line %d: %s\n", 8822 __func__, i, __LINE__, 8823 "failed to process security crypto op"); 8824 ret = TEST_FAILED; 8825 goto on_err; 8826 } 8827 8828 if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 8829 printf("TestCase %s(%d) line %d: %s\n", 8830 __func__, i, __LINE__, "crypto op processing failed"); 8831 ret = TEST_FAILED; 8832 goto on_err; 8833 } 8834 8835 /* Validate ciphertext */ 8836 ciphertext = plaintext; 8837 8838 if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) { 8839 printf("TestCase %s(%d) line %d: %s\n", 8840 __func__, i, __LINE__, "ciphertext not as expected\n"); 8841 rte_hexdump(stdout, "expected", d_td->ciphertext.data, 8842 d_td->ciphertext.len); 8843 rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len); 8844 ret = TEST_FAILED; 8845 goto on_err; 8846 } 8847 8848 on_err: 8849 rte_crypto_op_free(ut_params->op); 8850 ut_params->op = NULL; 8851 8852 if (ut_params->sec_session) 8853 rte_security_session_destroy(ctx, ut_params->sec_session); 8854 ut_params->sec_session = NULL; 8855 8856 rte_pktmbuf_free(ut_params->ibuf); 8857 ut_params->ibuf = NULL; 8858 8859 return ret; 8860 } 8861 8862 #define TEST_DOCSIS_COUNT(func) do { \ 8863 int ret = func; \ 8864 if (ret == TEST_SUCCESS) { \ 8865 printf("\t%2d)", n++); \ 8866 printf("+++++ PASSED:" #func"\n"); \ 8867 p++; \ 8868 } else if (ret == -ENOTSUP) { \ 8869 printf("\t%2d)", n++); \ 8870 printf("~~~~~ UNSUPP:" #func"\n"); \ 8871 u++; \ 8872 } else { \ 8873 printf("\t%2d)", n++); \ 8874 printf("----- FAILED:" #func"\n"); \ 8875 f++; \ 8876 } \ 8877 } while (0) 8878 8879 static int 8880 test_DOCSIS_PROTO_uplink_all(void) 8881 { 8882 int p = 0, u = 0, f = 0, n = 0; 8883 8884 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1)); 8885 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2)); 8886 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3)); 8887 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4)); 8888 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5)); 8889 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6)); 8890 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7)); 8891 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8)); 8892 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9)); 8893 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10)); 8894 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11)); 8895 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12)); 8896 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13)); 8897 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14)); 8898 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15)); 8899 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16)); 8900 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17)); 8901 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18)); 8902 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19)); 8903 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20)); 8904 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21)); 8905 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22)); 8906 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23)); 8907 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24)); 8908 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25)); 8909 TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26)); 8910 8911 if (f) 8912 printf("## %s: %d passed out of %d (%d unsupported)\n", 8913 __func__, p, n, u); 8914 8915 return f; 8916 }; 8917 8918 static int 8919 test_DOCSIS_PROTO_downlink_all(void) 8920 { 8921 int p = 0, u = 0, f = 0, n = 0; 8922 8923 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1)); 8924 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2)); 8925 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3)); 8926 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4)); 8927 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5)); 8928 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6)); 8929 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7)); 8930 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8)); 8931 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9)); 8932 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10)); 8933 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11)); 8934 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12)); 8935 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13)); 8936 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14)); 8937 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15)); 8938 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16)); 8939 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17)); 8940 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18)); 8941 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19)); 8942 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20)); 8943 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21)); 8944 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22)); 8945 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23)); 8946 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24)); 8947 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25)); 8948 TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26)); 8949 8950 if (f) 8951 printf("## %s: %d passed out of %d (%d unsupported)\n", 8952 __func__, p, n, u); 8953 8954 return f; 8955 }; 8956 8957 static int 8958 test_DOCSIS_PROTO_all(void) 8959 { 8960 struct crypto_testsuite_params *ts_params = &testsuite_params; 8961 struct crypto_unittest_params *ut_params = &unittest_params; 8962 struct rte_cryptodev_info dev_info; 8963 int status; 8964 8965 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 8966 uint64_t feat_flags = dev_info.feature_flags; 8967 8968 if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY)) 8969 return -ENOTSUP; 8970 8971 /* Set action type */ 8972 ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ? 8973 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL : 8974 gbl_action_type; 8975 8976 if (security_proto_supported(ut_params->type, 8977 RTE_SECURITY_PROTOCOL_DOCSIS) < 0) 8978 return -ENOTSUP; 8979 8980 status = test_DOCSIS_PROTO_uplink_all(); 8981 status += test_DOCSIS_PROTO_downlink_all(); 8982 8983 if (status) 8984 return TEST_FAILED; 8985 else 8986 return TEST_SUCCESS; 8987 } 8988 #endif 8989 8990 static int 8991 test_AES_GCM_authenticated_encryption_test_case_1(void) 8992 { 8993 return test_authenticated_encryption(&gcm_test_case_1); 8994 } 8995 8996 static int 8997 test_AES_GCM_authenticated_encryption_test_case_2(void) 8998 { 8999 return test_authenticated_encryption(&gcm_test_case_2); 9000 } 9001 9002 static int 9003 test_AES_GCM_authenticated_encryption_test_case_3(void) 9004 { 9005 return test_authenticated_encryption(&gcm_test_case_3); 9006 } 9007 9008 static int 9009 test_AES_GCM_authenticated_encryption_test_case_4(void) 9010 { 9011 return test_authenticated_encryption(&gcm_test_case_4); 9012 } 9013 9014 static int 9015 test_AES_GCM_authenticated_encryption_test_case_5(void) 9016 { 9017 return test_authenticated_encryption(&gcm_test_case_5); 9018 } 9019 9020 static int 9021 test_AES_GCM_authenticated_encryption_test_case_6(void) 9022 { 9023 return test_authenticated_encryption(&gcm_test_case_6); 9024 } 9025 9026 static int 9027 test_AES_GCM_authenticated_encryption_test_case_7(void) 9028 { 9029 return test_authenticated_encryption(&gcm_test_case_7); 9030 } 9031 9032 static int 9033 test_AES_GCM_authenticated_encryption_test_case_8(void) 9034 { 9035 return test_authenticated_encryption(&gcm_test_case_8); 9036 } 9037 9038 static int 9039 test_AES_GCM_J0_authenticated_encryption_test_case_1(void) 9040 { 9041 return test_authenticated_encryption(&gcm_J0_test_case_1); 9042 } 9043 9044 static int 9045 test_AES_GCM_auth_encryption_test_case_192_1(void) 9046 { 9047 return test_authenticated_encryption(&gcm_test_case_192_1); 9048 } 9049 9050 static int 9051 test_AES_GCM_auth_encryption_test_case_192_2(void) 9052 { 9053 return test_authenticated_encryption(&gcm_test_case_192_2); 9054 } 9055 9056 static int 9057 test_AES_GCM_auth_encryption_test_case_192_3(void) 9058 { 9059 return test_authenticated_encryption(&gcm_test_case_192_3); 9060 } 9061 9062 static int 9063 test_AES_GCM_auth_encryption_test_case_192_4(void) 9064 { 9065 return test_authenticated_encryption(&gcm_test_case_192_4); 9066 } 9067 9068 static int 9069 test_AES_GCM_auth_encryption_test_case_192_5(void) 9070 { 9071 return test_authenticated_encryption(&gcm_test_case_192_5); 9072 } 9073 9074 static int 9075 test_AES_GCM_auth_encryption_test_case_192_6(void) 9076 { 9077 return test_authenticated_encryption(&gcm_test_case_192_6); 9078 } 9079 9080 static int 9081 test_AES_GCM_auth_encryption_test_case_192_7(void) 9082 { 9083 return test_authenticated_encryption(&gcm_test_case_192_7); 9084 } 9085 9086 static int 9087 test_AES_GCM_auth_encryption_test_case_256_1(void) 9088 { 9089 return test_authenticated_encryption(&gcm_test_case_256_1); 9090 } 9091 9092 static int 9093 test_AES_GCM_auth_encryption_test_case_256_2(void) 9094 { 9095 return test_authenticated_encryption(&gcm_test_case_256_2); 9096 } 9097 9098 static int 9099 test_AES_GCM_auth_encryption_test_case_256_3(void) 9100 { 9101 return test_authenticated_encryption(&gcm_test_case_256_3); 9102 } 9103 9104 static int 9105 test_AES_GCM_auth_encryption_test_case_256_4(void) 9106 { 9107 return test_authenticated_encryption(&gcm_test_case_256_4); 9108 } 9109 9110 static int 9111 test_AES_GCM_auth_encryption_test_case_256_5(void) 9112 { 9113 return test_authenticated_encryption(&gcm_test_case_256_5); 9114 } 9115 9116 static int 9117 test_AES_GCM_auth_encryption_test_case_256_6(void) 9118 { 9119 return test_authenticated_encryption(&gcm_test_case_256_6); 9120 } 9121 9122 static int 9123 test_AES_GCM_auth_encryption_test_case_256_7(void) 9124 { 9125 return test_authenticated_encryption(&gcm_test_case_256_7); 9126 } 9127 9128 static int 9129 test_AES_GCM_auth_encryption_test_case_aad_1(void) 9130 { 9131 return test_authenticated_encryption(&gcm_test_case_aad_1); 9132 } 9133 9134 static int 9135 test_AES_GCM_auth_encryption_test_case_aad_2(void) 9136 { 9137 return test_authenticated_encryption(&gcm_test_case_aad_2); 9138 } 9139 9140 static int 9141 test_AES_GCM_auth_encryption_fail_iv_corrupt(void) 9142 { 9143 struct aead_test_data tdata; 9144 int res; 9145 9146 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9147 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9148 tdata.iv.data[0] += 1; 9149 res = test_authenticated_encryption(&tdata); 9150 if (res == -ENOTSUP) 9151 return res; 9152 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9153 return TEST_SUCCESS; 9154 } 9155 9156 static int 9157 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void) 9158 { 9159 struct aead_test_data tdata; 9160 int res; 9161 9162 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9163 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9164 tdata.plaintext.data[0] += 1; 9165 res = test_authenticated_encryption(&tdata); 9166 if (res == -ENOTSUP) 9167 return res; 9168 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9169 return TEST_SUCCESS; 9170 } 9171 9172 static int 9173 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void) 9174 { 9175 struct aead_test_data tdata; 9176 int res; 9177 9178 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9179 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9180 tdata.ciphertext.data[0] += 1; 9181 res = test_authenticated_encryption(&tdata); 9182 if (res == -ENOTSUP) 9183 return res; 9184 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9185 return TEST_SUCCESS; 9186 } 9187 9188 static int 9189 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void) 9190 { 9191 struct aead_test_data tdata; 9192 int res; 9193 9194 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9195 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9196 tdata.aad.len += 1; 9197 res = test_authenticated_encryption(&tdata); 9198 if (res == -ENOTSUP) 9199 return res; 9200 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9201 return TEST_SUCCESS; 9202 } 9203 9204 static int 9205 test_AES_GCM_auth_encryption_fail_aad_corrupt(void) 9206 { 9207 struct aead_test_data tdata; 9208 uint8_t aad[gcm_test_case_7.aad.len]; 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 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 9214 aad[0] += 1; 9215 tdata.aad.data = aad; 9216 res = test_authenticated_encryption(&tdata); 9217 if (res == -ENOTSUP) 9218 return res; 9219 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9220 return TEST_SUCCESS; 9221 } 9222 9223 static int 9224 test_AES_GCM_auth_encryption_fail_tag_corrupt(void) 9225 { 9226 struct aead_test_data tdata; 9227 int res; 9228 9229 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9230 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9231 tdata.auth_tag.data[0] += 1; 9232 res = test_authenticated_encryption(&tdata); 9233 if (res == -ENOTSUP) 9234 return res; 9235 TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed"); 9236 return TEST_SUCCESS; 9237 } 9238 9239 static int 9240 test_authenticated_decryption(const struct aead_test_data *tdata) 9241 { 9242 struct crypto_testsuite_params *ts_params = &testsuite_params; 9243 struct crypto_unittest_params *ut_params = &unittest_params; 9244 9245 int retval; 9246 uint8_t *plaintext; 9247 uint32_t i; 9248 struct rte_cryptodev_info dev_info; 9249 9250 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9251 uint64_t feat_flags = dev_info.feature_flags; 9252 9253 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9254 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9255 printf("Device doesn't support RAW data-path APIs.\n"); 9256 return -ENOTSUP; 9257 } 9258 9259 /* Verify the capabilities */ 9260 struct rte_cryptodev_sym_capability_idx cap_idx; 9261 const struct rte_cryptodev_symmetric_capability *capability; 9262 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9263 cap_idx.algo.aead = tdata->algo; 9264 capability = rte_cryptodev_sym_capability_get( 9265 ts_params->valid_devs[0], &cap_idx); 9266 if (capability == NULL) 9267 return -ENOTSUP; 9268 if (rte_cryptodev_sym_capability_check_aead( 9269 capability, tdata->key.len, tdata->auth_tag.len, 9270 tdata->aad.len, tdata->iv.len)) 9271 return -ENOTSUP; 9272 9273 /* Create AEAD session */ 9274 retval = create_aead_session(ts_params->valid_devs[0], 9275 tdata->algo, 9276 RTE_CRYPTO_AEAD_OP_DECRYPT, 9277 tdata->key.data, tdata->key.len, 9278 tdata->aad.len, tdata->auth_tag.len, 9279 tdata->iv.len); 9280 if (retval < 0) 9281 return retval; 9282 9283 /* alloc mbuf and set payload */ 9284 if (tdata->aad.len > MBUF_SIZE) { 9285 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 9286 /* Populate full size of add data */ 9287 for (i = 32; i < MAX_AAD_LENGTH; i += 32) 9288 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32); 9289 } else 9290 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9291 9292 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9293 rte_pktmbuf_tailroom(ut_params->ibuf)); 9294 9295 /* Create AEAD operation */ 9296 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 9297 if (retval < 0) 9298 return retval; 9299 9300 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9301 9302 ut_params->op->sym->m_src = ut_params->ibuf; 9303 9304 /* Process crypto operation */ 9305 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9306 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 9307 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 9308 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 9309 ut_params->op, 0, 0, 0, 0); 9310 else 9311 TEST_ASSERT_NOT_NULL( 9312 process_crypto_request(ts_params->valid_devs[0], 9313 ut_params->op), "failed to process sym crypto op"); 9314 9315 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9316 "crypto op processing failed"); 9317 9318 if (ut_params->op->sym->m_dst) 9319 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, 9320 uint8_t *); 9321 else 9322 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 9323 uint8_t *, 9324 ut_params->op->sym->cipher.data.offset); 9325 9326 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 9327 9328 /* Validate obuf */ 9329 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9330 plaintext, 9331 tdata->plaintext.data, 9332 tdata->plaintext.len, 9333 "Plaintext data not as expected"); 9334 9335 TEST_ASSERT_EQUAL(ut_params->op->status, 9336 RTE_CRYPTO_OP_STATUS_SUCCESS, 9337 "Authentication failed"); 9338 9339 return 0; 9340 } 9341 9342 static int 9343 test_AES_GCM_authenticated_decryption_test_case_1(void) 9344 { 9345 return test_authenticated_decryption(&gcm_test_case_1); 9346 } 9347 9348 static int 9349 test_AES_GCM_authenticated_decryption_test_case_2(void) 9350 { 9351 return test_authenticated_decryption(&gcm_test_case_2); 9352 } 9353 9354 static int 9355 test_AES_GCM_authenticated_decryption_test_case_3(void) 9356 { 9357 return test_authenticated_decryption(&gcm_test_case_3); 9358 } 9359 9360 static int 9361 test_AES_GCM_authenticated_decryption_test_case_4(void) 9362 { 9363 return test_authenticated_decryption(&gcm_test_case_4); 9364 } 9365 9366 static int 9367 test_AES_GCM_authenticated_decryption_test_case_5(void) 9368 { 9369 return test_authenticated_decryption(&gcm_test_case_5); 9370 } 9371 9372 static int 9373 test_AES_GCM_authenticated_decryption_test_case_6(void) 9374 { 9375 return test_authenticated_decryption(&gcm_test_case_6); 9376 } 9377 9378 static int 9379 test_AES_GCM_authenticated_decryption_test_case_7(void) 9380 { 9381 return test_authenticated_decryption(&gcm_test_case_7); 9382 } 9383 9384 static int 9385 test_AES_GCM_authenticated_decryption_test_case_8(void) 9386 { 9387 return test_authenticated_decryption(&gcm_test_case_8); 9388 } 9389 9390 static int 9391 test_AES_GCM_J0_authenticated_decryption_test_case_1(void) 9392 { 9393 return test_authenticated_decryption(&gcm_J0_test_case_1); 9394 } 9395 9396 static int 9397 test_AES_GCM_auth_decryption_test_case_192_1(void) 9398 { 9399 return test_authenticated_decryption(&gcm_test_case_192_1); 9400 } 9401 9402 static int 9403 test_AES_GCM_auth_decryption_test_case_192_2(void) 9404 { 9405 return test_authenticated_decryption(&gcm_test_case_192_2); 9406 } 9407 9408 static int 9409 test_AES_GCM_auth_decryption_test_case_192_3(void) 9410 { 9411 return test_authenticated_decryption(&gcm_test_case_192_3); 9412 } 9413 9414 static int 9415 test_AES_GCM_auth_decryption_test_case_192_4(void) 9416 { 9417 return test_authenticated_decryption(&gcm_test_case_192_4); 9418 } 9419 9420 static int 9421 test_AES_GCM_auth_decryption_test_case_192_5(void) 9422 { 9423 return test_authenticated_decryption(&gcm_test_case_192_5); 9424 } 9425 9426 static int 9427 test_AES_GCM_auth_decryption_test_case_192_6(void) 9428 { 9429 return test_authenticated_decryption(&gcm_test_case_192_6); 9430 } 9431 9432 static int 9433 test_AES_GCM_auth_decryption_test_case_192_7(void) 9434 { 9435 return test_authenticated_decryption(&gcm_test_case_192_7); 9436 } 9437 9438 static int 9439 test_AES_GCM_auth_decryption_test_case_256_1(void) 9440 { 9441 return test_authenticated_decryption(&gcm_test_case_256_1); 9442 } 9443 9444 static int 9445 test_AES_GCM_auth_decryption_test_case_256_2(void) 9446 { 9447 return test_authenticated_decryption(&gcm_test_case_256_2); 9448 } 9449 9450 static int 9451 test_AES_GCM_auth_decryption_test_case_256_3(void) 9452 { 9453 return test_authenticated_decryption(&gcm_test_case_256_3); 9454 } 9455 9456 static int 9457 test_AES_GCM_auth_decryption_test_case_256_4(void) 9458 { 9459 return test_authenticated_decryption(&gcm_test_case_256_4); 9460 } 9461 9462 static int 9463 test_AES_GCM_auth_decryption_test_case_256_5(void) 9464 { 9465 return test_authenticated_decryption(&gcm_test_case_256_5); 9466 } 9467 9468 static int 9469 test_AES_GCM_auth_decryption_test_case_256_6(void) 9470 { 9471 return test_authenticated_decryption(&gcm_test_case_256_6); 9472 } 9473 9474 static int 9475 test_AES_GCM_auth_decryption_test_case_256_7(void) 9476 { 9477 return test_authenticated_decryption(&gcm_test_case_256_7); 9478 } 9479 9480 static int 9481 test_AES_GCM_auth_decryption_test_case_aad_1(void) 9482 { 9483 return test_authenticated_decryption(&gcm_test_case_aad_1); 9484 } 9485 9486 static int 9487 test_AES_GCM_auth_decryption_test_case_aad_2(void) 9488 { 9489 return test_authenticated_decryption(&gcm_test_case_aad_2); 9490 } 9491 9492 static int 9493 test_AES_GCM_auth_decryption_fail_iv_corrupt(void) 9494 { 9495 struct aead_test_data tdata; 9496 int res; 9497 9498 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9499 tdata.iv.data[0] += 1; 9500 res = test_authenticated_decryption(&tdata); 9501 if (res == -ENOTSUP) 9502 return res; 9503 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9504 return TEST_SUCCESS; 9505 } 9506 9507 static int 9508 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void) 9509 { 9510 struct aead_test_data tdata; 9511 int res; 9512 9513 RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n"); 9514 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9515 tdata.plaintext.data[0] += 1; 9516 res = test_authenticated_decryption(&tdata); 9517 if (res == -ENOTSUP) 9518 return res; 9519 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9520 return TEST_SUCCESS; 9521 } 9522 9523 static int 9524 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void) 9525 { 9526 struct aead_test_data tdata; 9527 int res; 9528 9529 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9530 tdata.ciphertext.data[0] += 1; 9531 res = test_authenticated_decryption(&tdata); 9532 if (res == -ENOTSUP) 9533 return res; 9534 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9535 return TEST_SUCCESS; 9536 } 9537 9538 static int 9539 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void) 9540 { 9541 struct aead_test_data tdata; 9542 int res; 9543 9544 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9545 tdata.aad.len += 1; 9546 res = test_authenticated_decryption(&tdata); 9547 if (res == -ENOTSUP) 9548 return res; 9549 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9550 return TEST_SUCCESS; 9551 } 9552 9553 static int 9554 test_AES_GCM_auth_decryption_fail_aad_corrupt(void) 9555 { 9556 struct aead_test_data tdata; 9557 uint8_t aad[gcm_test_case_7.aad.len]; 9558 int res; 9559 9560 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9561 memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len); 9562 aad[0] += 1; 9563 tdata.aad.data = aad; 9564 res = test_authenticated_decryption(&tdata); 9565 if (res == -ENOTSUP) 9566 return res; 9567 TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed"); 9568 return TEST_SUCCESS; 9569 } 9570 9571 static int 9572 test_AES_GCM_auth_decryption_fail_tag_corrupt(void) 9573 { 9574 struct aead_test_data tdata; 9575 int res; 9576 9577 memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data)); 9578 tdata.auth_tag.data[0] += 1; 9579 res = test_authenticated_decryption(&tdata); 9580 if (res == -ENOTSUP) 9581 return res; 9582 TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed"); 9583 return TEST_SUCCESS; 9584 } 9585 9586 static int 9587 test_authenticated_encryption_oop(const struct aead_test_data *tdata) 9588 { 9589 struct crypto_testsuite_params *ts_params = &testsuite_params; 9590 struct crypto_unittest_params *ut_params = &unittest_params; 9591 9592 int retval; 9593 uint8_t *ciphertext, *auth_tag; 9594 uint16_t plaintext_pad_len; 9595 9596 /* Verify the capabilities */ 9597 struct rte_cryptodev_sym_capability_idx cap_idx; 9598 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9599 cap_idx.algo.aead = tdata->algo; 9600 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9601 &cap_idx) == NULL) 9602 return -ENOTSUP; 9603 9604 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 9605 return -ENOTSUP; 9606 9607 /* not supported with CPU crypto */ 9608 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9609 return -ENOTSUP; 9610 9611 /* Create AEAD session */ 9612 retval = create_aead_session(ts_params->valid_devs[0], 9613 tdata->algo, 9614 RTE_CRYPTO_AEAD_OP_ENCRYPT, 9615 tdata->key.data, tdata->key.len, 9616 tdata->aad.len, tdata->auth_tag.len, 9617 tdata->iv.len); 9618 if (retval < 0) 9619 return retval; 9620 9621 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9622 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9623 9624 /* clear mbuf payload */ 9625 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9626 rte_pktmbuf_tailroom(ut_params->ibuf)); 9627 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 9628 rte_pktmbuf_tailroom(ut_params->obuf)); 9629 9630 /* Create AEAD operation */ 9631 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 9632 if (retval < 0) 9633 return retval; 9634 9635 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9636 9637 ut_params->op->sym->m_src = ut_params->ibuf; 9638 ut_params->op->sym->m_dst = ut_params->obuf; 9639 9640 /* Process crypto operation */ 9641 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 9642 ut_params->op), "failed to process sym crypto op"); 9643 9644 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9645 "crypto op processing failed"); 9646 9647 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 9648 9649 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 9650 ut_params->op->sym->cipher.data.offset); 9651 auth_tag = ciphertext + plaintext_pad_len; 9652 9653 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 9654 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 9655 9656 /* Validate obuf */ 9657 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9658 ciphertext, 9659 tdata->ciphertext.data, 9660 tdata->ciphertext.len, 9661 "Ciphertext data not as expected"); 9662 9663 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9664 auth_tag, 9665 tdata->auth_tag.data, 9666 tdata->auth_tag.len, 9667 "Generated auth tag not as expected"); 9668 9669 return 0; 9670 9671 } 9672 9673 static int 9674 test_AES_GCM_authenticated_encryption_oop_test_case_1(void) 9675 { 9676 return test_authenticated_encryption_oop(&gcm_test_case_5); 9677 } 9678 9679 static int 9680 test_authenticated_decryption_oop(const struct aead_test_data *tdata) 9681 { 9682 struct crypto_testsuite_params *ts_params = &testsuite_params; 9683 struct crypto_unittest_params *ut_params = &unittest_params; 9684 9685 int retval; 9686 uint8_t *plaintext; 9687 9688 /* Verify the capabilities */ 9689 struct rte_cryptodev_sym_capability_idx cap_idx; 9690 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9691 cap_idx.algo.aead = tdata->algo; 9692 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9693 &cap_idx) == NULL) 9694 return -ENOTSUP; 9695 9696 /* not supported with CPU crypto and raw data-path APIs*/ 9697 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO || 9698 global_api_test_type == CRYPTODEV_RAW_API_TEST) 9699 return -ENOTSUP; 9700 9701 /* Create AEAD session */ 9702 retval = create_aead_session(ts_params->valid_devs[0], 9703 tdata->algo, 9704 RTE_CRYPTO_AEAD_OP_DECRYPT, 9705 tdata->key.data, tdata->key.len, 9706 tdata->aad.len, tdata->auth_tag.len, 9707 tdata->iv.len); 9708 if (retval < 0) 9709 return retval; 9710 9711 /* alloc mbuf and set payload */ 9712 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9713 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9714 9715 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9716 rte_pktmbuf_tailroom(ut_params->ibuf)); 9717 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, 9718 rte_pktmbuf_tailroom(ut_params->obuf)); 9719 9720 /* Create AEAD operation */ 9721 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 9722 if (retval < 0) 9723 return retval; 9724 9725 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 9726 9727 ut_params->op->sym->m_src = ut_params->ibuf; 9728 ut_params->op->sym->m_dst = ut_params->obuf; 9729 9730 /* Process crypto operation */ 9731 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 9732 ut_params->op), "failed to process sym crypto op"); 9733 9734 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9735 "crypto op processing failed"); 9736 9737 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *, 9738 ut_params->op->sym->cipher.data.offset); 9739 9740 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 9741 9742 /* Validate obuf */ 9743 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9744 plaintext, 9745 tdata->plaintext.data, 9746 tdata->plaintext.len, 9747 "Plaintext data not as expected"); 9748 9749 TEST_ASSERT_EQUAL(ut_params->op->status, 9750 RTE_CRYPTO_OP_STATUS_SUCCESS, 9751 "Authentication failed"); 9752 return 0; 9753 } 9754 9755 static int 9756 test_AES_GCM_authenticated_decryption_oop_test_case_1(void) 9757 { 9758 return test_authenticated_decryption_oop(&gcm_test_case_5); 9759 } 9760 9761 static int 9762 test_authenticated_encryption_sessionless( 9763 const struct aead_test_data *tdata) 9764 { 9765 struct crypto_testsuite_params *ts_params = &testsuite_params; 9766 struct crypto_unittest_params *ut_params = &unittest_params; 9767 9768 int retval; 9769 uint8_t *ciphertext, *auth_tag; 9770 uint16_t plaintext_pad_len; 9771 uint8_t key[tdata->key.len + 1]; 9772 struct rte_cryptodev_info dev_info; 9773 9774 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9775 uint64_t feat_flags = dev_info.feature_flags; 9776 9777 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 9778 printf("Device doesn't support Sessionless ops.\n"); 9779 return -ENOTSUP; 9780 } 9781 9782 /* not supported with CPU crypto */ 9783 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9784 return -ENOTSUP; 9785 9786 /* Verify the capabilities */ 9787 struct rte_cryptodev_sym_capability_idx cap_idx; 9788 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9789 cap_idx.algo.aead = tdata->algo; 9790 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9791 &cap_idx) == NULL) 9792 return -ENOTSUP; 9793 9794 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9795 9796 /* clear mbuf payload */ 9797 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9798 rte_pktmbuf_tailroom(ut_params->ibuf)); 9799 9800 /* Create AEAD operation */ 9801 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata); 9802 if (retval < 0) 9803 return retval; 9804 9805 /* Create GCM xform */ 9806 memcpy(key, tdata->key.data, tdata->key.len); 9807 retval = create_aead_xform(ut_params->op, 9808 tdata->algo, 9809 RTE_CRYPTO_AEAD_OP_ENCRYPT, 9810 key, tdata->key.len, 9811 tdata->aad.len, tdata->auth_tag.len, 9812 tdata->iv.len); 9813 if (retval < 0) 9814 return retval; 9815 9816 ut_params->op->sym->m_src = ut_params->ibuf; 9817 9818 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 9819 RTE_CRYPTO_OP_SESSIONLESS, 9820 "crypto op session type not sessionless"); 9821 9822 /* Process crypto operation */ 9823 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], 9824 ut_params->op), "failed to process sym crypto op"); 9825 9826 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 9827 9828 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9829 "crypto op status not success"); 9830 9831 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 9832 9833 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 9834 ut_params->op->sym->cipher.data.offset); 9835 auth_tag = ciphertext + plaintext_pad_len; 9836 9837 debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); 9838 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len); 9839 9840 /* Validate obuf */ 9841 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9842 ciphertext, 9843 tdata->ciphertext.data, 9844 tdata->ciphertext.len, 9845 "Ciphertext data not as expected"); 9846 9847 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9848 auth_tag, 9849 tdata->auth_tag.data, 9850 tdata->auth_tag.len, 9851 "Generated auth tag not as expected"); 9852 9853 return 0; 9854 9855 } 9856 9857 static int 9858 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void) 9859 { 9860 return test_authenticated_encryption_sessionless( 9861 &gcm_test_case_5); 9862 } 9863 9864 static int 9865 test_authenticated_decryption_sessionless( 9866 const struct aead_test_data *tdata) 9867 { 9868 struct crypto_testsuite_params *ts_params = &testsuite_params; 9869 struct crypto_unittest_params *ut_params = &unittest_params; 9870 9871 int retval; 9872 uint8_t *plaintext; 9873 uint8_t key[tdata->key.len + 1]; 9874 struct rte_cryptodev_info dev_info; 9875 9876 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 9877 uint64_t feat_flags = dev_info.feature_flags; 9878 9879 if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) { 9880 printf("Device doesn't support Sessionless ops.\n"); 9881 return -ENOTSUP; 9882 } 9883 9884 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 9885 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 9886 printf("Device doesn't support RAW data-path APIs.\n"); 9887 return -ENOTSUP; 9888 } 9889 9890 /* not supported with CPU crypto */ 9891 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 9892 return -ENOTSUP; 9893 9894 /* Verify the capabilities */ 9895 struct rte_cryptodev_sym_capability_idx cap_idx; 9896 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9897 cap_idx.algo.aead = tdata->algo; 9898 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 9899 &cap_idx) == NULL) 9900 return -ENOTSUP; 9901 9902 /* alloc mbuf and set payload */ 9903 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 9904 9905 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 9906 rte_pktmbuf_tailroom(ut_params->ibuf)); 9907 9908 /* Create AEAD operation */ 9909 retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata); 9910 if (retval < 0) 9911 return retval; 9912 9913 /* Create AEAD xform */ 9914 memcpy(key, tdata->key.data, tdata->key.len); 9915 retval = create_aead_xform(ut_params->op, 9916 tdata->algo, 9917 RTE_CRYPTO_AEAD_OP_DECRYPT, 9918 key, tdata->key.len, 9919 tdata->aad.len, tdata->auth_tag.len, 9920 tdata->iv.len); 9921 if (retval < 0) 9922 return retval; 9923 9924 ut_params->op->sym->m_src = ut_params->ibuf; 9925 9926 TEST_ASSERT_EQUAL(ut_params->op->sess_type, 9927 RTE_CRYPTO_OP_SESSIONLESS, 9928 "crypto op session type not sessionless"); 9929 9930 /* Process crypto operation */ 9931 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 9932 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 9933 ut_params->op, 0, 0, 0, 0); 9934 else 9935 TEST_ASSERT_NOT_NULL(process_crypto_request( 9936 ts_params->valid_devs[0], ut_params->op), 9937 "failed to process sym crypto op"); 9938 9939 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 9940 9941 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 9942 "crypto op status not success"); 9943 9944 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 9945 ut_params->op->sym->cipher.data.offset); 9946 9947 debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len); 9948 9949 /* Validate obuf */ 9950 TEST_ASSERT_BUFFERS_ARE_EQUAL( 9951 plaintext, 9952 tdata->plaintext.data, 9953 tdata->plaintext.len, 9954 "Plaintext data not as expected"); 9955 9956 TEST_ASSERT_EQUAL(ut_params->op->status, 9957 RTE_CRYPTO_OP_STATUS_SUCCESS, 9958 "Authentication failed"); 9959 return 0; 9960 } 9961 9962 static int 9963 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void) 9964 { 9965 return test_authenticated_decryption_sessionless( 9966 &gcm_test_case_5); 9967 } 9968 9969 static int 9970 test_AES_CCM_authenticated_encryption_test_case_128_1(void) 9971 { 9972 return test_authenticated_encryption(&ccm_test_case_128_1); 9973 } 9974 9975 static int 9976 test_AES_CCM_authenticated_encryption_test_case_128_2(void) 9977 { 9978 return test_authenticated_encryption(&ccm_test_case_128_2); 9979 } 9980 9981 static int 9982 test_AES_CCM_authenticated_encryption_test_case_128_3(void) 9983 { 9984 return test_authenticated_encryption(&ccm_test_case_128_3); 9985 } 9986 9987 static int 9988 test_AES_CCM_authenticated_decryption_test_case_128_1(void) 9989 { 9990 return test_authenticated_decryption(&ccm_test_case_128_1); 9991 } 9992 9993 static int 9994 test_AES_CCM_authenticated_decryption_test_case_128_2(void) 9995 { 9996 return test_authenticated_decryption(&ccm_test_case_128_2); 9997 } 9998 9999 static int 10000 test_AES_CCM_authenticated_decryption_test_case_128_3(void) 10001 { 10002 return test_authenticated_decryption(&ccm_test_case_128_3); 10003 } 10004 10005 static int 10006 test_AES_CCM_authenticated_encryption_test_case_192_1(void) 10007 { 10008 return test_authenticated_encryption(&ccm_test_case_192_1); 10009 } 10010 10011 static int 10012 test_AES_CCM_authenticated_encryption_test_case_192_2(void) 10013 { 10014 return test_authenticated_encryption(&ccm_test_case_192_2); 10015 } 10016 10017 static int 10018 test_AES_CCM_authenticated_encryption_test_case_192_3(void) 10019 { 10020 return test_authenticated_encryption(&ccm_test_case_192_3); 10021 } 10022 10023 static int 10024 test_AES_CCM_authenticated_decryption_test_case_192_1(void) 10025 { 10026 return test_authenticated_decryption(&ccm_test_case_192_1); 10027 } 10028 10029 static int 10030 test_AES_CCM_authenticated_decryption_test_case_192_2(void) 10031 { 10032 return test_authenticated_decryption(&ccm_test_case_192_2); 10033 } 10034 10035 static int 10036 test_AES_CCM_authenticated_decryption_test_case_192_3(void) 10037 { 10038 return test_authenticated_decryption(&ccm_test_case_192_3); 10039 } 10040 10041 static int 10042 test_AES_CCM_authenticated_encryption_test_case_256_1(void) 10043 { 10044 return test_authenticated_encryption(&ccm_test_case_256_1); 10045 } 10046 10047 static int 10048 test_AES_CCM_authenticated_encryption_test_case_256_2(void) 10049 { 10050 return test_authenticated_encryption(&ccm_test_case_256_2); 10051 } 10052 10053 static int 10054 test_AES_CCM_authenticated_encryption_test_case_256_3(void) 10055 { 10056 return test_authenticated_encryption(&ccm_test_case_256_3); 10057 } 10058 10059 static int 10060 test_AES_CCM_authenticated_decryption_test_case_256_1(void) 10061 { 10062 return test_authenticated_decryption(&ccm_test_case_256_1); 10063 } 10064 10065 static int 10066 test_AES_CCM_authenticated_decryption_test_case_256_2(void) 10067 { 10068 return test_authenticated_decryption(&ccm_test_case_256_2); 10069 } 10070 10071 static int 10072 test_AES_CCM_authenticated_decryption_test_case_256_3(void) 10073 { 10074 return test_authenticated_decryption(&ccm_test_case_256_3); 10075 } 10076 10077 static int 10078 test_stats(void) 10079 { 10080 struct crypto_testsuite_params *ts_params = &testsuite_params; 10081 struct rte_cryptodev_stats stats; 10082 10083 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10084 return -ENOTSUP; 10085 10086 /* Verify the capabilities */ 10087 struct rte_cryptodev_sym_capability_idx cap_idx; 10088 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10089 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; 10090 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10091 &cap_idx) == NULL) 10092 return -ENOTSUP; 10093 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10094 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 10095 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10096 &cap_idx) == NULL) 10097 return -ENOTSUP; 10098 10099 if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats) 10100 == -ENOTSUP) 10101 return -ENOTSUP; 10102 10103 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 10104 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600, 10105 &stats) == -ENODEV), 10106 "rte_cryptodev_stats_get invalid dev failed"); 10107 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0), 10108 "rte_cryptodev_stats_get invalid Param failed"); 10109 10110 /* Test expected values */ 10111 test_AES_CBC_HMAC_SHA1_encrypt_digest(); 10112 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 10113 &stats), 10114 "rte_cryptodev_stats_get failed"); 10115 TEST_ASSERT((stats.enqueued_count == 1), 10116 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10117 TEST_ASSERT((stats.dequeued_count == 1), 10118 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10119 TEST_ASSERT((stats.enqueue_err_count == 0), 10120 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10121 TEST_ASSERT((stats.dequeue_err_count == 0), 10122 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10123 10124 /* invalid device but should ignore and not reset device stats*/ 10125 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300); 10126 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 10127 &stats), 10128 "rte_cryptodev_stats_get failed"); 10129 TEST_ASSERT((stats.enqueued_count == 1), 10130 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10131 10132 /* check that a valid reset clears stats */ 10133 rte_cryptodev_stats_reset(ts_params->valid_devs[0]); 10134 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0], 10135 &stats), 10136 "rte_cryptodev_stats_get failed"); 10137 TEST_ASSERT((stats.enqueued_count == 0), 10138 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10139 TEST_ASSERT((stats.dequeued_count == 0), 10140 "rte_cryptodev_stats_get returned unexpected enqueued stat"); 10141 10142 return TEST_SUCCESS; 10143 } 10144 10145 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params, 10146 struct crypto_unittest_params *ut_params, 10147 enum rte_crypto_auth_operation op, 10148 const struct HMAC_MD5_vector *test_case) 10149 { 10150 uint8_t key[64]; 10151 10152 memcpy(key, test_case->key.data, test_case->key.len); 10153 10154 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10155 ut_params->auth_xform.next = NULL; 10156 ut_params->auth_xform.auth.op = op; 10157 10158 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC; 10159 10160 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN; 10161 ut_params->auth_xform.auth.key.length = test_case->key.len; 10162 ut_params->auth_xform.auth.key.data = key; 10163 10164 ut_params->sess = rte_cryptodev_sym_session_create( 10165 ts_params->session_mpool); 10166 10167 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10168 ut_params->sess, &ut_params->auth_xform, 10169 ts_params->session_priv_mpool); 10170 10171 if (ut_params->sess == NULL) 10172 return TEST_FAILED; 10173 10174 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10175 10176 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 10177 rte_pktmbuf_tailroom(ut_params->ibuf)); 10178 10179 return 0; 10180 } 10181 10182 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params, 10183 const struct HMAC_MD5_vector *test_case, 10184 uint8_t **plaintext) 10185 { 10186 uint16_t plaintext_pad_len; 10187 10188 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 10189 10190 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 10191 16); 10192 10193 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 10194 plaintext_pad_len); 10195 memcpy(*plaintext, test_case->plaintext.data, 10196 test_case->plaintext.len); 10197 10198 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 10199 ut_params->ibuf, MD5_DIGEST_LEN); 10200 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 10201 "no room to append digest"); 10202 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 10203 ut_params->ibuf, plaintext_pad_len); 10204 10205 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) { 10206 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data, 10207 test_case->auth_tag.len); 10208 } 10209 10210 sym_op->auth.data.offset = 0; 10211 sym_op->auth.data.length = test_case->plaintext.len; 10212 10213 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 10214 ut_params->op->sym->m_src = ut_params->ibuf; 10215 10216 return 0; 10217 } 10218 10219 static int 10220 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case) 10221 { 10222 uint16_t plaintext_pad_len; 10223 uint8_t *plaintext, *auth_tag; 10224 10225 struct crypto_testsuite_params *ts_params = &testsuite_params; 10226 struct crypto_unittest_params *ut_params = &unittest_params; 10227 struct rte_cryptodev_info dev_info; 10228 10229 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10230 uint64_t feat_flags = dev_info.feature_flags; 10231 10232 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10233 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10234 printf("Device doesn't support RAW data-path APIs.\n"); 10235 return -ENOTSUP; 10236 } 10237 10238 /* Verify the capabilities */ 10239 struct rte_cryptodev_sym_capability_idx cap_idx; 10240 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10241 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 10242 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10243 &cap_idx) == NULL) 10244 return -ENOTSUP; 10245 10246 if (MD5_HMAC_create_session(ts_params, ut_params, 10247 RTE_CRYPTO_AUTH_OP_GENERATE, test_case)) 10248 return TEST_FAILED; 10249 10250 /* Generate Crypto op data structure */ 10251 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10252 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10253 TEST_ASSERT_NOT_NULL(ut_params->op, 10254 "Failed to allocate symmetric crypto operation struct"); 10255 10256 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len, 10257 16); 10258 10259 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 10260 return TEST_FAILED; 10261 10262 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10263 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 10264 ut_params->op); 10265 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10266 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10267 ut_params->op, 0, 1, 0, 0); 10268 else 10269 TEST_ASSERT_NOT_NULL( 10270 process_crypto_request(ts_params->valid_devs[0], 10271 ut_params->op), 10272 "failed to process sym crypto op"); 10273 10274 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10275 "crypto op processing failed"); 10276 10277 if (ut_params->op->sym->m_dst) { 10278 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 10279 uint8_t *, plaintext_pad_len); 10280 } else { 10281 auth_tag = plaintext + plaintext_pad_len; 10282 } 10283 10284 TEST_ASSERT_BUFFERS_ARE_EQUAL( 10285 auth_tag, 10286 test_case->auth_tag.data, 10287 test_case->auth_tag.len, 10288 "HMAC_MD5 generated tag not as expected"); 10289 10290 return TEST_SUCCESS; 10291 } 10292 10293 static int 10294 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case) 10295 { 10296 uint8_t *plaintext; 10297 10298 struct crypto_testsuite_params *ts_params = &testsuite_params; 10299 struct crypto_unittest_params *ut_params = &unittest_params; 10300 struct rte_cryptodev_info dev_info; 10301 10302 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10303 uint64_t feat_flags = dev_info.feature_flags; 10304 10305 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 10306 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 10307 printf("Device doesn't support RAW data-path APIs.\n"); 10308 return -ENOTSUP; 10309 } 10310 10311 /* Verify the capabilities */ 10312 struct rte_cryptodev_sym_capability_idx cap_idx; 10313 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10314 cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC; 10315 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10316 &cap_idx) == NULL) 10317 return -ENOTSUP; 10318 10319 if (MD5_HMAC_create_session(ts_params, ut_params, 10320 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) { 10321 return TEST_FAILED; 10322 } 10323 10324 /* Generate Crypto op data structure */ 10325 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 10326 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 10327 TEST_ASSERT_NOT_NULL(ut_params->op, 10328 "Failed to allocate symmetric crypto operation struct"); 10329 10330 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext)) 10331 return TEST_FAILED; 10332 10333 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 10334 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 10335 ut_params->op); 10336 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 10337 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 10338 ut_params->op, 0, 1, 0, 0); 10339 else 10340 TEST_ASSERT_NOT_NULL( 10341 process_crypto_request(ts_params->valid_devs[0], 10342 ut_params->op), 10343 "failed to process sym crypto op"); 10344 10345 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 10346 "HMAC_MD5 crypto op processing failed"); 10347 10348 return TEST_SUCCESS; 10349 } 10350 10351 static int 10352 test_MD5_HMAC_generate_case_1(void) 10353 { 10354 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1); 10355 } 10356 10357 static int 10358 test_MD5_HMAC_verify_case_1(void) 10359 { 10360 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1); 10361 } 10362 10363 static int 10364 test_MD5_HMAC_generate_case_2(void) 10365 { 10366 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2); 10367 } 10368 10369 static int 10370 test_MD5_HMAC_verify_case_2(void) 10371 { 10372 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2); 10373 } 10374 10375 static int 10376 test_multi_session(void) 10377 { 10378 struct crypto_testsuite_params *ts_params = &testsuite_params; 10379 struct crypto_unittest_params *ut_params = &unittest_params; 10380 10381 struct rte_cryptodev_info dev_info; 10382 struct rte_cryptodev_sym_session **sessions; 10383 10384 uint16_t i; 10385 10386 /* Verify the capabilities */ 10387 struct rte_cryptodev_sym_capability_idx cap_idx; 10388 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10389 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 10390 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10391 &cap_idx) == NULL) 10392 return -ENOTSUP; 10393 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10394 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 10395 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10396 &cap_idx) == NULL) 10397 return -ENOTSUP; 10398 10399 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params, 10400 aes_cbc_key, hmac_sha512_key); 10401 10402 10403 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10404 10405 sessions = rte_malloc(NULL, 10406 (sizeof(struct rte_cryptodev_sym_session *) * 10407 MAX_NB_SESSIONS) + 1, 0); 10408 10409 /* Create multiple crypto sessions*/ 10410 for (i = 0; i < MAX_NB_SESSIONS; i++) { 10411 10412 sessions[i] = rte_cryptodev_sym_session_create( 10413 ts_params->session_mpool); 10414 10415 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10416 sessions[i], &ut_params->auth_xform, 10417 ts_params->session_priv_mpool); 10418 TEST_ASSERT_NOT_NULL(sessions[i], 10419 "Session creation failed at session number %u", 10420 i); 10421 10422 /* Attempt to send a request on each session */ 10423 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform( 10424 sessions[i], 10425 ut_params, 10426 ts_params, 10427 catch_22_quote_2_512_bytes_AES_CBC_ciphertext, 10428 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, 10429 aes_cbc_iv), 10430 "Failed to perform decrypt on request number %u.", i); 10431 /* free crypto operation structure */ 10432 if (ut_params->op) 10433 rte_crypto_op_free(ut_params->op); 10434 10435 /* 10436 * free mbuf - both obuf and ibuf are usually the same, 10437 * so check if they point at the same address is necessary, 10438 * to avoid freeing the mbuf twice. 10439 */ 10440 if (ut_params->obuf) { 10441 rte_pktmbuf_free(ut_params->obuf); 10442 if (ut_params->ibuf == ut_params->obuf) 10443 ut_params->ibuf = 0; 10444 ut_params->obuf = 0; 10445 } 10446 if (ut_params->ibuf) { 10447 rte_pktmbuf_free(ut_params->ibuf); 10448 ut_params->ibuf = 0; 10449 } 10450 } 10451 10452 /* Next session create should fail */ 10453 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10454 sessions[i], &ut_params->auth_xform, 10455 ts_params->session_priv_mpool); 10456 TEST_ASSERT_NULL(sessions[i], 10457 "Session creation succeeded unexpectedly!"); 10458 10459 for (i = 0; i < MAX_NB_SESSIONS; i++) { 10460 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 10461 sessions[i]); 10462 rte_cryptodev_sym_session_free(sessions[i]); 10463 } 10464 10465 rte_free(sessions); 10466 10467 return TEST_SUCCESS; 10468 } 10469 10470 struct multi_session_params { 10471 struct crypto_unittest_params ut_params; 10472 uint8_t *cipher_key; 10473 uint8_t *hmac_key; 10474 const uint8_t *cipher; 10475 const uint8_t *digest; 10476 uint8_t *iv; 10477 }; 10478 10479 #define MB_SESSION_NUMBER 3 10480 10481 static int 10482 test_multi_session_random_usage(void) 10483 { 10484 struct crypto_testsuite_params *ts_params = &testsuite_params; 10485 struct rte_cryptodev_info dev_info; 10486 struct rte_cryptodev_sym_session **sessions; 10487 uint32_t i, j; 10488 struct multi_session_params ut_paramz[] = { 10489 10490 { 10491 .cipher_key = ms_aes_cbc_key0, 10492 .hmac_key = ms_hmac_key0, 10493 .cipher = ms_aes_cbc_cipher0, 10494 .digest = ms_hmac_digest0, 10495 .iv = ms_aes_cbc_iv0 10496 }, 10497 { 10498 .cipher_key = ms_aes_cbc_key1, 10499 .hmac_key = ms_hmac_key1, 10500 .cipher = ms_aes_cbc_cipher1, 10501 .digest = ms_hmac_digest1, 10502 .iv = ms_aes_cbc_iv1 10503 }, 10504 { 10505 .cipher_key = ms_aes_cbc_key2, 10506 .hmac_key = ms_hmac_key2, 10507 .cipher = ms_aes_cbc_cipher2, 10508 .digest = ms_hmac_digest2, 10509 .iv = ms_aes_cbc_iv2 10510 }, 10511 10512 }; 10513 10514 /* Verify the capabilities */ 10515 struct rte_cryptodev_sym_capability_idx cap_idx; 10516 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10517 cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC; 10518 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10519 &cap_idx) == NULL) 10520 return -ENOTSUP; 10521 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10522 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; 10523 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 10524 &cap_idx) == NULL) 10525 return -ENOTSUP; 10526 10527 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10528 10529 sessions = rte_malloc(NULL, 10530 (sizeof(struct rte_cryptodev_sym_session *) 10531 * MAX_NB_SESSIONS) + 1, 0); 10532 10533 for (i = 0; i < MB_SESSION_NUMBER; i++) { 10534 sessions[i] = rte_cryptodev_sym_session_create( 10535 ts_params->session_mpool); 10536 10537 rte_memcpy(&ut_paramz[i].ut_params, &unittest_params, 10538 sizeof(struct crypto_unittest_params)); 10539 10540 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( 10541 &ut_paramz[i].ut_params, 10542 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key); 10543 10544 /* Create multiple crypto sessions*/ 10545 rte_cryptodev_sym_session_init( 10546 ts_params->valid_devs[0], 10547 sessions[i], 10548 &ut_paramz[i].ut_params.auth_xform, 10549 ts_params->session_priv_mpool); 10550 10551 TEST_ASSERT_NOT_NULL(sessions[i], 10552 "Session creation failed at session number %u", 10553 i); 10554 10555 } 10556 10557 srand(time(NULL)); 10558 for (i = 0; i < 40000; i++) { 10559 10560 j = rand() % MB_SESSION_NUMBER; 10561 10562 TEST_ASSERT_SUCCESS( 10563 test_AES_CBC_HMAC_SHA512_decrypt_perform( 10564 sessions[j], 10565 &ut_paramz[j].ut_params, 10566 ts_params, ut_paramz[j].cipher, 10567 ut_paramz[j].digest, 10568 ut_paramz[j].iv), 10569 "Failed to perform decrypt on request number %u.", i); 10570 10571 if (ut_paramz[j].ut_params.op) 10572 rte_crypto_op_free(ut_paramz[j].ut_params.op); 10573 10574 /* 10575 * free mbuf - both obuf and ibuf are usually the same, 10576 * so check if they point at the same address is necessary, 10577 * to avoid freeing the mbuf twice. 10578 */ 10579 if (ut_paramz[j].ut_params.obuf) { 10580 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf); 10581 if (ut_paramz[j].ut_params.ibuf 10582 == ut_paramz[j].ut_params.obuf) 10583 ut_paramz[j].ut_params.ibuf = 0; 10584 ut_paramz[j].ut_params.obuf = 0; 10585 } 10586 if (ut_paramz[j].ut_params.ibuf) { 10587 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); 10588 ut_paramz[j].ut_params.ibuf = 0; 10589 } 10590 } 10591 10592 for (i = 0; i < MB_SESSION_NUMBER; i++) { 10593 rte_cryptodev_sym_session_clear(ts_params->valid_devs[0], 10594 sessions[i]); 10595 rte_cryptodev_sym_session_free(sessions[i]); 10596 } 10597 10598 rte_free(sessions); 10599 10600 return TEST_SUCCESS; 10601 } 10602 10603 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab, 10604 0xab, 0xab, 0xab, 0xab, 10605 0xab, 0xab, 0xab, 0xab, 10606 0xab, 0xab, 0xab, 0xab}; 10607 10608 static int 10609 test_null_invalid_operation(void) 10610 { 10611 struct crypto_testsuite_params *ts_params = &testsuite_params; 10612 struct crypto_unittest_params *ut_params = &unittest_params; 10613 int ret; 10614 10615 /* This test is for NULL PMD only */ 10616 if (gbl_driver_id != rte_cryptodev_driver_id_get( 10617 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 10618 return -ENOTSUP; 10619 10620 /* Setup Cipher Parameters */ 10621 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10622 ut_params->cipher_xform.next = NULL; 10623 10624 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; 10625 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 10626 10627 ut_params->sess = rte_cryptodev_sym_session_create( 10628 ts_params->session_mpool); 10629 10630 /* Create Crypto session*/ 10631 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10632 ut_params->sess, &ut_params->cipher_xform, 10633 ts_params->session_priv_mpool); 10634 TEST_ASSERT(ret < 0, 10635 "Session creation succeeded unexpectedly"); 10636 10637 10638 /* Setup HMAC Parameters */ 10639 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10640 ut_params->auth_xform.next = NULL; 10641 10642 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; 10643 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 10644 10645 ut_params->sess = rte_cryptodev_sym_session_create( 10646 ts_params->session_mpool); 10647 10648 /* Create Crypto session*/ 10649 ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10650 ut_params->sess, &ut_params->auth_xform, 10651 ts_params->session_priv_mpool); 10652 TEST_ASSERT(ret < 0, 10653 "Session creation succeeded unexpectedly"); 10654 10655 return TEST_SUCCESS; 10656 } 10657 10658 10659 #define NULL_BURST_LENGTH (32) 10660 10661 static int 10662 test_null_burst_operation(void) 10663 { 10664 struct crypto_testsuite_params *ts_params = &testsuite_params; 10665 struct crypto_unittest_params *ut_params = &unittest_params; 10666 10667 unsigned i, burst_len = NULL_BURST_LENGTH; 10668 10669 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL }; 10670 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL }; 10671 10672 /* This test is for NULL PMD only */ 10673 if (gbl_driver_id != rte_cryptodev_driver_id_get( 10674 RTE_STR(CRYPTODEV_NAME_NULL_PMD))) 10675 return -ENOTSUP; 10676 10677 /* Setup Cipher Parameters */ 10678 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 10679 ut_params->cipher_xform.next = &ut_params->auth_xform; 10680 10681 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL; 10682 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 10683 10684 /* Setup HMAC Parameters */ 10685 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 10686 ut_params->auth_xform.next = NULL; 10687 10688 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL; 10689 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 10690 10691 ut_params->sess = rte_cryptodev_sym_session_create( 10692 ts_params->session_mpool); 10693 10694 /* Create Crypto session*/ 10695 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 10696 ut_params->sess, &ut_params->cipher_xform, 10697 ts_params->session_priv_mpool); 10698 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 10699 10700 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool, 10701 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len), 10702 burst_len, "failed to generate burst of crypto ops"); 10703 10704 /* Generate an operation for each mbuf in burst */ 10705 for (i = 0; i < burst_len; i++) { 10706 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool); 10707 10708 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf"); 10709 10710 unsigned *data = (unsigned *)rte_pktmbuf_append(m, 10711 sizeof(unsigned)); 10712 *data = i; 10713 10714 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess); 10715 10716 burst[i]->sym->m_src = m; 10717 } 10718 10719 /* Process crypto operation */ 10720 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 10721 0, burst, burst_len), 10722 burst_len, 10723 "Error enqueuing burst"); 10724 10725 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 10726 0, burst_dequeued, burst_len), 10727 burst_len, 10728 "Error dequeuing burst"); 10729 10730 10731 for (i = 0; i < burst_len; i++) { 10732 TEST_ASSERT_EQUAL( 10733 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *), 10734 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src, 10735 uint32_t *), 10736 "data not as expected"); 10737 10738 rte_pktmbuf_free(burst[i]->sym->m_src); 10739 rte_crypto_op_free(burst[i]); 10740 } 10741 10742 return TEST_SUCCESS; 10743 } 10744 10745 static uint16_t 10746 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 10747 uint16_t nb_ops, void *user_param) 10748 { 10749 RTE_SET_USED(dev_id); 10750 RTE_SET_USED(qp_id); 10751 RTE_SET_USED(ops); 10752 RTE_SET_USED(user_param); 10753 10754 printf("crypto enqueue callback called\n"); 10755 return nb_ops; 10756 } 10757 10758 static uint16_t 10759 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, 10760 uint16_t nb_ops, void *user_param) 10761 { 10762 RTE_SET_USED(dev_id); 10763 RTE_SET_USED(qp_id); 10764 RTE_SET_USED(ops); 10765 RTE_SET_USED(user_param); 10766 10767 printf("crypto dequeue callback called\n"); 10768 return nb_ops; 10769 } 10770 10771 /* 10772 * Thread using enqueue/dequeue callback with RCU. 10773 */ 10774 static int 10775 test_enqdeq_callback_thread(void *arg) 10776 { 10777 RTE_SET_USED(arg); 10778 /* DP thread calls rte_cryptodev_enqueue_burst()/ 10779 * rte_cryptodev_dequeue_burst() and invokes callback. 10780 */ 10781 test_null_burst_operation(); 10782 return 0; 10783 } 10784 10785 static int 10786 test_enq_callback_setup(void) 10787 { 10788 struct crypto_testsuite_params *ts_params = &testsuite_params; 10789 struct rte_cryptodev_info dev_info; 10790 struct rte_cryptodev_qp_conf qp_conf = { 10791 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 10792 }; 10793 10794 struct rte_cryptodev_cb *cb; 10795 uint16_t qp_id = 0; 10796 10797 /* Stop the device in case it's started so it can be configured */ 10798 rte_cryptodev_stop(ts_params->valid_devs[0]); 10799 10800 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10801 10802 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 10803 &ts_params->conf), 10804 "Failed to configure cryptodev %u", 10805 ts_params->valid_devs[0]); 10806 10807 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 10808 qp_conf.mp_session = ts_params->session_mpool; 10809 qp_conf.mp_session_private = ts_params->session_priv_mpool; 10810 10811 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 10812 ts_params->valid_devs[0], qp_id, &qp_conf, 10813 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 10814 "Failed test for " 10815 "rte_cryptodev_queue_pair_setup: num_inflights " 10816 "%u on qp %u on cryptodev %u", 10817 qp_conf.nb_descriptors, qp_id, 10818 ts_params->valid_devs[0]); 10819 10820 /* Test with invalid crypto device */ 10821 cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS, 10822 qp_id, test_enq_callback, NULL); 10823 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 10824 "cryptodev %u did not fail", 10825 qp_id, RTE_CRYPTO_MAX_DEVS); 10826 10827 /* Test with invalid queue pair */ 10828 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 10829 dev_info.max_nb_queue_pairs + 1, 10830 test_enq_callback, NULL); 10831 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 10832 "cryptodev %u did not fail", 10833 dev_info.max_nb_queue_pairs + 1, 10834 ts_params->valid_devs[0]); 10835 10836 /* Test with NULL callback */ 10837 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 10838 qp_id, NULL, NULL); 10839 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 10840 "cryptodev %u did not fail", 10841 qp_id, ts_params->valid_devs[0]); 10842 10843 /* Test with valid configuration */ 10844 cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0], 10845 qp_id, test_enq_callback, NULL); 10846 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 10847 "qp %u on cryptodev %u", 10848 qp_id, ts_params->valid_devs[0]); 10849 10850 rte_cryptodev_start(ts_params->valid_devs[0]); 10851 10852 /* Launch a thread */ 10853 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 10854 rte_get_next_lcore(-1, 1, 0)); 10855 10856 /* Wait until reader exited. */ 10857 rte_eal_mp_wait_lcore(); 10858 10859 /* Test with invalid crypto device */ 10860 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 10861 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 10862 "Expected call to fail as crypto device is invalid"); 10863 10864 /* Test with invalid queue pair */ 10865 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 10866 ts_params->valid_devs[0], 10867 dev_info.max_nb_queue_pairs + 1, cb), 10868 "Expected call to fail as queue pair is invalid"); 10869 10870 /* Test with NULL callback */ 10871 TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback( 10872 ts_params->valid_devs[0], qp_id, NULL), 10873 "Expected call to fail as callback is NULL"); 10874 10875 /* Test with valid configuration */ 10876 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback( 10877 ts_params->valid_devs[0], qp_id, cb), 10878 "Failed test to remove callback on " 10879 "qp %u on cryptodev %u", 10880 qp_id, ts_params->valid_devs[0]); 10881 10882 return TEST_SUCCESS; 10883 } 10884 10885 static int 10886 test_deq_callback_setup(void) 10887 { 10888 struct crypto_testsuite_params *ts_params = &testsuite_params; 10889 struct rte_cryptodev_info dev_info; 10890 struct rte_cryptodev_qp_conf qp_conf = { 10891 .nb_descriptors = MAX_NUM_OPS_INFLIGHT 10892 }; 10893 10894 struct rte_cryptodev_cb *cb; 10895 uint16_t qp_id = 0; 10896 10897 /* Stop the device in case it's started so it can be configured */ 10898 rte_cryptodev_stop(ts_params->valid_devs[0]); 10899 10900 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 10901 10902 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 10903 &ts_params->conf), 10904 "Failed to configure cryptodev %u", 10905 ts_params->valid_devs[0]); 10906 10907 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; 10908 qp_conf.mp_session = ts_params->session_mpool; 10909 qp_conf.mp_session_private = ts_params->session_priv_mpool; 10910 10911 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 10912 ts_params->valid_devs[0], qp_id, &qp_conf, 10913 rte_cryptodev_socket_id(ts_params->valid_devs[0])), 10914 "Failed test for " 10915 "rte_cryptodev_queue_pair_setup: num_inflights " 10916 "%u on qp %u on cryptodev %u", 10917 qp_conf.nb_descriptors, qp_id, 10918 ts_params->valid_devs[0]); 10919 10920 /* Test with invalid crypto device */ 10921 cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS, 10922 qp_id, test_deq_callback, NULL); 10923 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 10924 "cryptodev %u did not fail", 10925 qp_id, RTE_CRYPTO_MAX_DEVS); 10926 10927 /* Test with invalid queue pair */ 10928 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 10929 dev_info.max_nb_queue_pairs + 1, 10930 test_deq_callback, NULL); 10931 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 10932 "cryptodev %u did not fail", 10933 dev_info.max_nb_queue_pairs + 1, 10934 ts_params->valid_devs[0]); 10935 10936 /* Test with NULL callback */ 10937 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 10938 qp_id, NULL, NULL); 10939 TEST_ASSERT_NULL(cb, "Add callback on qp %u on " 10940 "cryptodev %u did not fail", 10941 qp_id, ts_params->valid_devs[0]); 10942 10943 /* Test with valid configuration */ 10944 cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0], 10945 qp_id, test_deq_callback, NULL); 10946 TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on " 10947 "qp %u on cryptodev %u", 10948 qp_id, ts_params->valid_devs[0]); 10949 10950 rte_cryptodev_start(ts_params->valid_devs[0]); 10951 10952 /* Launch a thread */ 10953 rte_eal_remote_launch(test_enqdeq_callback_thread, NULL, 10954 rte_get_next_lcore(-1, 1, 0)); 10955 10956 /* Wait until reader exited. */ 10957 rte_eal_mp_wait_lcore(); 10958 10959 /* Test with invalid crypto device */ 10960 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 10961 RTE_CRYPTO_MAX_DEVS, qp_id, cb), 10962 "Expected call to fail as crypto device is invalid"); 10963 10964 /* Test with invalid queue pair */ 10965 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 10966 ts_params->valid_devs[0], 10967 dev_info.max_nb_queue_pairs + 1, cb), 10968 "Expected call to fail as queue pair is invalid"); 10969 10970 /* Test with NULL callback */ 10971 TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback( 10972 ts_params->valid_devs[0], qp_id, NULL), 10973 "Expected call to fail as callback is NULL"); 10974 10975 /* Test with valid configuration */ 10976 TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback( 10977 ts_params->valid_devs[0], qp_id, cb), 10978 "Failed test to remove callback on " 10979 "qp %u on cryptodev %u", 10980 qp_id, ts_params->valid_devs[0]); 10981 10982 return TEST_SUCCESS; 10983 } 10984 10985 static void 10986 generate_gmac_large_plaintext(uint8_t *data) 10987 { 10988 uint16_t i; 10989 10990 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32) 10991 memcpy(&data[i], &data[0], 32); 10992 } 10993 10994 static int 10995 create_gmac_operation(enum rte_crypto_auth_operation op, 10996 const struct gmac_test_data *tdata) 10997 { 10998 struct crypto_testsuite_params *ts_params = &testsuite_params; 10999 struct crypto_unittest_params *ut_params = &unittest_params; 11000 struct rte_crypto_sym_op *sym_op; 11001 11002 uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 11003 11004 /* Generate Crypto op data structure */ 11005 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11006 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11007 TEST_ASSERT_NOT_NULL(ut_params->op, 11008 "Failed to allocate symmetric crypto operation struct"); 11009 11010 sym_op = ut_params->op->sym; 11011 11012 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11013 ut_params->ibuf, tdata->gmac_tag.len); 11014 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11015 "no room to append digest"); 11016 11017 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11018 ut_params->ibuf, plaintext_pad_len); 11019 11020 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 11021 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 11022 tdata->gmac_tag.len); 11023 debug_hexdump(stdout, "digest:", 11024 sym_op->auth.digest.data, 11025 tdata->gmac_tag.len); 11026 } 11027 11028 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 11029 uint8_t *, IV_OFFSET); 11030 11031 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 11032 11033 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 11034 11035 sym_op->cipher.data.length = 0; 11036 sym_op->cipher.data.offset = 0; 11037 11038 sym_op->auth.data.offset = 0; 11039 sym_op->auth.data.length = tdata->plaintext.len; 11040 11041 return 0; 11042 } 11043 11044 static int 11045 create_gmac_operation_sgl(enum rte_crypto_auth_operation op, 11046 const struct gmac_test_data *tdata, 11047 void *digest_mem, uint64_t digest_phys) 11048 { 11049 struct crypto_testsuite_params *ts_params = &testsuite_params; 11050 struct crypto_unittest_params *ut_params = &unittest_params; 11051 struct rte_crypto_sym_op *sym_op; 11052 11053 /* Generate Crypto op data structure */ 11054 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11055 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11056 TEST_ASSERT_NOT_NULL(ut_params->op, 11057 "Failed to allocate symmetric crypto operation struct"); 11058 11059 sym_op = ut_params->op->sym; 11060 11061 sym_op->auth.digest.data = digest_mem; 11062 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11063 "no room to append digest"); 11064 11065 sym_op->auth.digest.phys_addr = digest_phys; 11066 11067 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) { 11068 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data, 11069 tdata->gmac_tag.len); 11070 debug_hexdump(stdout, "digest:", 11071 sym_op->auth.digest.data, 11072 tdata->gmac_tag.len); 11073 } 11074 11075 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 11076 uint8_t *, IV_OFFSET); 11077 11078 rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len); 11079 11080 debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len); 11081 11082 sym_op->cipher.data.length = 0; 11083 sym_op->cipher.data.offset = 0; 11084 11085 sym_op->auth.data.offset = 0; 11086 sym_op->auth.data.length = tdata->plaintext.len; 11087 11088 return 0; 11089 } 11090 11091 static int create_gmac_session(uint8_t dev_id, 11092 const struct gmac_test_data *tdata, 11093 enum rte_crypto_auth_operation auth_op) 11094 { 11095 uint8_t auth_key[tdata->key.len]; 11096 11097 struct crypto_testsuite_params *ts_params = &testsuite_params; 11098 struct crypto_unittest_params *ut_params = &unittest_params; 11099 11100 memcpy(auth_key, tdata->key.data, tdata->key.len); 11101 11102 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11103 ut_params->auth_xform.next = NULL; 11104 11105 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC; 11106 ut_params->auth_xform.auth.op = auth_op; 11107 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len; 11108 ut_params->auth_xform.auth.key.length = tdata->key.len; 11109 ut_params->auth_xform.auth.key.data = auth_key; 11110 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 11111 ut_params->auth_xform.auth.iv.length = tdata->iv.len; 11112 11113 11114 ut_params->sess = rte_cryptodev_sym_session_create( 11115 ts_params->session_mpool); 11116 11117 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 11118 &ut_params->auth_xform, 11119 ts_params->session_priv_mpool); 11120 11121 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11122 11123 return 0; 11124 } 11125 11126 static int 11127 test_AES_GMAC_authentication(const struct gmac_test_data *tdata) 11128 { 11129 struct crypto_testsuite_params *ts_params = &testsuite_params; 11130 struct crypto_unittest_params *ut_params = &unittest_params; 11131 struct rte_cryptodev_info dev_info; 11132 11133 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11134 uint64_t feat_flags = dev_info.feature_flags; 11135 11136 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11137 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11138 printf("Device doesn't support RAW data-path APIs.\n"); 11139 return -ENOTSUP; 11140 } 11141 11142 int retval; 11143 11144 uint8_t *auth_tag, *plaintext; 11145 uint16_t plaintext_pad_len; 11146 11147 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 11148 "No GMAC length in the source data"); 11149 11150 /* Verify the capabilities */ 11151 struct rte_cryptodev_sym_capability_idx cap_idx; 11152 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11153 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 11154 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11155 &cap_idx) == NULL) 11156 return -ENOTSUP; 11157 11158 retval = create_gmac_session(ts_params->valid_devs[0], 11159 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 11160 11161 if (retval < 0) 11162 return retval; 11163 11164 if (tdata->plaintext.len > MBUF_SIZE) 11165 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 11166 else 11167 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11168 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 11169 "Failed to allocate input buffer in mempool"); 11170 11171 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11172 rte_pktmbuf_tailroom(ut_params->ibuf)); 11173 11174 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 11175 /* 11176 * Runtime generate the large plain text instead of use hard code 11177 * plain text vector. It is done to avoid create huge source file 11178 * with the test vector. 11179 */ 11180 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 11181 generate_gmac_large_plaintext(tdata->plaintext.data); 11182 11183 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11184 plaintext_pad_len); 11185 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 11186 11187 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 11188 debug_hexdump(stdout, "plaintext:", plaintext, 11189 tdata->plaintext.len); 11190 11191 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE, 11192 tdata); 11193 11194 if (retval < 0) 11195 return retval; 11196 11197 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11198 11199 ut_params->op->sym->m_src = ut_params->ibuf; 11200 11201 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11202 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11203 ut_params->op); 11204 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11205 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11206 ut_params->op, 0, 1, 0, 0); 11207 else 11208 TEST_ASSERT_NOT_NULL( 11209 process_crypto_request(ts_params->valid_devs[0], 11210 ut_params->op), "failed to process sym crypto op"); 11211 11212 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11213 "crypto op processing failed"); 11214 11215 if (ut_params->op->sym->m_dst) { 11216 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 11217 uint8_t *, plaintext_pad_len); 11218 } else { 11219 auth_tag = plaintext + plaintext_pad_len; 11220 } 11221 11222 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 11223 11224 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11225 auth_tag, 11226 tdata->gmac_tag.data, 11227 tdata->gmac_tag.len, 11228 "GMAC Generated auth tag not as expected"); 11229 11230 return 0; 11231 } 11232 11233 static int 11234 test_AES_GMAC_authentication_test_case_1(void) 11235 { 11236 return test_AES_GMAC_authentication(&gmac_test_case_1); 11237 } 11238 11239 static int 11240 test_AES_GMAC_authentication_test_case_2(void) 11241 { 11242 return test_AES_GMAC_authentication(&gmac_test_case_2); 11243 } 11244 11245 static int 11246 test_AES_GMAC_authentication_test_case_3(void) 11247 { 11248 return test_AES_GMAC_authentication(&gmac_test_case_3); 11249 } 11250 11251 static int 11252 test_AES_GMAC_authentication_test_case_4(void) 11253 { 11254 return test_AES_GMAC_authentication(&gmac_test_case_4); 11255 } 11256 11257 static int 11258 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata) 11259 { 11260 struct crypto_testsuite_params *ts_params = &testsuite_params; 11261 struct crypto_unittest_params *ut_params = &unittest_params; 11262 int retval; 11263 uint32_t plaintext_pad_len; 11264 uint8_t *plaintext; 11265 struct rte_cryptodev_info dev_info; 11266 11267 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11268 uint64_t feat_flags = dev_info.feature_flags; 11269 11270 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 11271 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 11272 printf("Device doesn't support RAW data-path APIs.\n"); 11273 return -ENOTSUP; 11274 } 11275 11276 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 11277 "No GMAC length in the source data"); 11278 11279 /* Verify the capabilities */ 11280 struct rte_cryptodev_sym_capability_idx cap_idx; 11281 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11282 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 11283 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11284 &cap_idx) == NULL) 11285 return -ENOTSUP; 11286 11287 retval = create_gmac_session(ts_params->valid_devs[0], 11288 tdata, RTE_CRYPTO_AUTH_OP_VERIFY); 11289 11290 if (retval < 0) 11291 return retval; 11292 11293 if (tdata->plaintext.len > MBUF_SIZE) 11294 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool); 11295 else 11296 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11297 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 11298 "Failed to allocate input buffer in mempool"); 11299 11300 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11301 rte_pktmbuf_tailroom(ut_params->ibuf)); 11302 11303 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16); 11304 11305 /* 11306 * Runtime generate the large plain text instead of use hard code 11307 * plain text vector. It is done to avoid create huge source file 11308 * with the test vector. 11309 */ 11310 if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH) 11311 generate_gmac_large_plaintext(tdata->plaintext.data); 11312 11313 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11314 plaintext_pad_len); 11315 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 11316 11317 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len); 11318 debug_hexdump(stdout, "plaintext:", plaintext, 11319 tdata->plaintext.len); 11320 11321 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY, 11322 tdata); 11323 11324 if (retval < 0) 11325 return retval; 11326 11327 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11328 11329 ut_params->op->sym->m_src = ut_params->ibuf; 11330 11331 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11332 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 11333 ut_params->op); 11334 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 11335 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 11336 ut_params->op, 0, 1, 0, 0); 11337 else 11338 TEST_ASSERT_NOT_NULL( 11339 process_crypto_request(ts_params->valid_devs[0], 11340 ut_params->op), "failed to process sym crypto op"); 11341 11342 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11343 "crypto op processing failed"); 11344 11345 return 0; 11346 11347 } 11348 11349 static int 11350 test_AES_GMAC_authentication_verify_test_case_1(void) 11351 { 11352 return test_AES_GMAC_authentication_verify(&gmac_test_case_1); 11353 } 11354 11355 static int 11356 test_AES_GMAC_authentication_verify_test_case_2(void) 11357 { 11358 return test_AES_GMAC_authentication_verify(&gmac_test_case_2); 11359 } 11360 11361 static int 11362 test_AES_GMAC_authentication_verify_test_case_3(void) 11363 { 11364 return test_AES_GMAC_authentication_verify(&gmac_test_case_3); 11365 } 11366 11367 static int 11368 test_AES_GMAC_authentication_verify_test_case_4(void) 11369 { 11370 return test_AES_GMAC_authentication_verify(&gmac_test_case_4); 11371 } 11372 11373 static int 11374 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata, 11375 uint32_t fragsz) 11376 { 11377 struct crypto_testsuite_params *ts_params = &testsuite_params; 11378 struct crypto_unittest_params *ut_params = &unittest_params; 11379 struct rte_cryptodev_info dev_info; 11380 uint64_t feature_flags; 11381 unsigned int trn_data = 0; 11382 void *digest_mem = NULL; 11383 uint32_t segs = 1; 11384 unsigned int to_trn = 0; 11385 struct rte_mbuf *buf = NULL; 11386 uint8_t *auth_tag, *plaintext; 11387 int retval; 11388 11389 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0, 11390 "No GMAC length in the source data"); 11391 11392 /* Verify the capabilities */ 11393 struct rte_cryptodev_sym_capability_idx cap_idx; 11394 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11395 cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC; 11396 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 11397 &cap_idx) == NULL) 11398 return -ENOTSUP; 11399 11400 /* Check for any input SGL support */ 11401 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 11402 feature_flags = dev_info.feature_flags; 11403 11404 if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) || 11405 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) || 11406 (!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))) 11407 return -ENOTSUP; 11408 11409 if (fragsz > tdata->plaintext.len) 11410 fragsz = tdata->plaintext.len; 11411 11412 uint16_t plaintext_len = fragsz; 11413 11414 retval = create_gmac_session(ts_params->valid_devs[0], 11415 tdata, RTE_CRYPTO_AUTH_OP_GENERATE); 11416 11417 if (retval < 0) 11418 return retval; 11419 11420 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11421 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 11422 "Failed to allocate input buffer in mempool"); 11423 11424 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 11425 rte_pktmbuf_tailroom(ut_params->ibuf)); 11426 11427 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11428 plaintext_len); 11429 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 11430 11431 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 11432 11433 trn_data += plaintext_len; 11434 11435 buf = ut_params->ibuf; 11436 11437 /* 11438 * Loop until no more fragments 11439 */ 11440 11441 while (trn_data < tdata->plaintext.len) { 11442 ++segs; 11443 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 11444 (tdata->plaintext.len - trn_data) : fragsz; 11445 11446 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 11447 buf = buf->next; 11448 11449 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 11450 rte_pktmbuf_tailroom(buf)); 11451 11452 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 11453 to_trn); 11454 11455 memcpy(plaintext, tdata->plaintext.data + trn_data, 11456 to_trn); 11457 trn_data += to_trn; 11458 if (trn_data == tdata->plaintext.len) 11459 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 11460 tdata->gmac_tag.len); 11461 } 11462 ut_params->ibuf->nb_segs = segs; 11463 11464 /* 11465 * Place digest at the end of the last buffer 11466 */ 11467 uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn; 11468 11469 if (!digest_mem) { 11470 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 11471 + tdata->gmac_tag.len); 11472 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 11473 tdata->plaintext.len); 11474 } 11475 11476 retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE, 11477 tdata, digest_mem, digest_phys); 11478 11479 if (retval < 0) 11480 return retval; 11481 11482 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11483 11484 ut_params->op->sym->m_src = ut_params->ibuf; 11485 11486 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 11487 return -ENOTSUP; 11488 11489 TEST_ASSERT_NOT_NULL( 11490 process_crypto_request(ts_params->valid_devs[0], 11491 ut_params->op), "failed to process sym crypto op"); 11492 11493 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 11494 "crypto op processing failed"); 11495 11496 auth_tag = digest_mem; 11497 debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len); 11498 TEST_ASSERT_BUFFERS_ARE_EQUAL( 11499 auth_tag, 11500 tdata->gmac_tag.data, 11501 tdata->gmac_tag.len, 11502 "GMAC Generated auth tag not as expected"); 11503 11504 return 0; 11505 } 11506 11507 /* Segment size not multiple of block size (16B) */ 11508 static int 11509 test_AES_GMAC_authentication_SGL_40B(void) 11510 { 11511 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40); 11512 } 11513 11514 static int 11515 test_AES_GMAC_authentication_SGL_80B(void) 11516 { 11517 return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80); 11518 } 11519 11520 static int 11521 test_AES_GMAC_authentication_SGL_2048B(void) 11522 { 11523 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048); 11524 } 11525 11526 /* Segment size not multiple of block size (16B) */ 11527 static int 11528 test_AES_GMAC_authentication_SGL_2047B(void) 11529 { 11530 return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047); 11531 } 11532 11533 struct test_crypto_vector { 11534 enum rte_crypto_cipher_algorithm crypto_algo; 11535 unsigned int cipher_offset; 11536 unsigned int cipher_len; 11537 11538 struct { 11539 uint8_t data[64]; 11540 unsigned int len; 11541 } cipher_key; 11542 11543 struct { 11544 uint8_t data[64]; 11545 unsigned int len; 11546 } iv; 11547 11548 struct { 11549 const uint8_t *data; 11550 unsigned int len; 11551 } plaintext; 11552 11553 struct { 11554 const uint8_t *data; 11555 unsigned int len; 11556 } ciphertext; 11557 11558 enum rte_crypto_auth_algorithm auth_algo; 11559 unsigned int auth_offset; 11560 11561 struct { 11562 uint8_t data[128]; 11563 unsigned int len; 11564 } auth_key; 11565 11566 struct { 11567 const uint8_t *data; 11568 unsigned int len; 11569 } aad; 11570 11571 struct { 11572 uint8_t data[128]; 11573 unsigned int len; 11574 } digest; 11575 }; 11576 11577 static const struct test_crypto_vector 11578 hmac_sha1_test_crypto_vector = { 11579 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 11580 .plaintext = { 11581 .data = plaintext_hash, 11582 .len = 512 11583 }, 11584 .auth_key = { 11585 .data = { 11586 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 11587 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 11588 0xDE, 0xF4, 0xDE, 0xAD 11589 }, 11590 .len = 20 11591 }, 11592 .digest = { 11593 .data = { 11594 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77, 11595 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17, 11596 0x3F, 0x91, 0x64, 0x59 11597 }, 11598 .len = 20 11599 } 11600 }; 11601 11602 static const struct test_crypto_vector 11603 aes128_gmac_test_vector = { 11604 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC, 11605 .plaintext = { 11606 .data = plaintext_hash, 11607 .len = 512 11608 }, 11609 .iv = { 11610 .data = { 11611 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 11612 0x08, 0x09, 0x0A, 0x0B 11613 }, 11614 .len = 12 11615 }, 11616 .auth_key = { 11617 .data = { 11618 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 11619 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA 11620 }, 11621 .len = 16 11622 }, 11623 .digest = { 11624 .data = { 11625 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56, 11626 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A 11627 }, 11628 .len = 16 11629 } 11630 }; 11631 11632 static const struct test_crypto_vector 11633 aes128cbc_hmac_sha1_test_vector = { 11634 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 11635 .cipher_offset = 0, 11636 .cipher_len = 512, 11637 .cipher_key = { 11638 .data = { 11639 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 11640 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 11641 }, 11642 .len = 16 11643 }, 11644 .iv = { 11645 .data = { 11646 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 11647 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 11648 }, 11649 .len = 16 11650 }, 11651 .plaintext = { 11652 .data = plaintext_hash, 11653 .len = 512 11654 }, 11655 .ciphertext = { 11656 .data = ciphertext512_aes128cbc, 11657 .len = 512 11658 }, 11659 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 11660 .auth_offset = 0, 11661 .auth_key = { 11662 .data = { 11663 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 11664 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 11665 0xDE, 0xF4, 0xDE, 0xAD 11666 }, 11667 .len = 20 11668 }, 11669 .digest = { 11670 .data = { 11671 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60, 11672 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1, 11673 0x18, 0x8C, 0x1D, 0x32 11674 }, 11675 .len = 20 11676 } 11677 }; 11678 11679 static const struct test_crypto_vector 11680 aes128cbc_hmac_sha1_aad_test_vector = { 11681 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC, 11682 .cipher_offset = 8, 11683 .cipher_len = 496, 11684 .cipher_key = { 11685 .data = { 11686 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, 11687 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A 11688 }, 11689 .len = 16 11690 }, 11691 .iv = { 11692 .data = { 11693 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 11694 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 11695 }, 11696 .len = 16 11697 }, 11698 .plaintext = { 11699 .data = plaintext_hash, 11700 .len = 512 11701 }, 11702 .ciphertext = { 11703 .data = ciphertext512_aes128cbc_aad, 11704 .len = 512 11705 }, 11706 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 11707 .auth_offset = 0, 11708 .auth_key = { 11709 .data = { 11710 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, 11711 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, 11712 0xDE, 0xF4, 0xDE, 0xAD 11713 }, 11714 .len = 20 11715 }, 11716 .digest = { 11717 .data = { 11718 0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F, 11719 0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B, 11720 0x62, 0x0F, 0xFB, 0x10 11721 }, 11722 .len = 20 11723 } 11724 }; 11725 11726 static void 11727 data_corruption(uint8_t *data) 11728 { 11729 data[0] += 1; 11730 } 11731 11732 static void 11733 tag_corruption(uint8_t *data, unsigned int tag_offset) 11734 { 11735 data[tag_offset] += 1; 11736 } 11737 11738 static int 11739 create_auth_session(struct crypto_unittest_params *ut_params, 11740 uint8_t dev_id, 11741 const struct test_crypto_vector *reference, 11742 enum rte_crypto_auth_operation auth_op) 11743 { 11744 struct crypto_testsuite_params *ts_params = &testsuite_params; 11745 uint8_t auth_key[reference->auth_key.len + 1]; 11746 11747 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 11748 11749 /* Setup Authentication Parameters */ 11750 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11751 ut_params->auth_xform.auth.op = auth_op; 11752 ut_params->auth_xform.next = NULL; 11753 ut_params->auth_xform.auth.algo = reference->auth_algo; 11754 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 11755 ut_params->auth_xform.auth.key.data = auth_key; 11756 ut_params->auth_xform.auth.digest_length = reference->digest.len; 11757 11758 /* Create Crypto session*/ 11759 ut_params->sess = rte_cryptodev_sym_session_create( 11760 ts_params->session_mpool); 11761 11762 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 11763 &ut_params->auth_xform, 11764 ts_params->session_priv_mpool); 11765 11766 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11767 11768 return 0; 11769 } 11770 11771 static int 11772 create_auth_cipher_session(struct crypto_unittest_params *ut_params, 11773 uint8_t dev_id, 11774 const struct test_crypto_vector *reference, 11775 enum rte_crypto_auth_operation auth_op, 11776 enum rte_crypto_cipher_operation cipher_op) 11777 { 11778 struct crypto_testsuite_params *ts_params = &testsuite_params; 11779 uint8_t cipher_key[reference->cipher_key.len + 1]; 11780 uint8_t auth_key[reference->auth_key.len + 1]; 11781 11782 memcpy(cipher_key, reference->cipher_key.data, 11783 reference->cipher_key.len); 11784 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 11785 11786 /* Setup Authentication Parameters */ 11787 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11788 ut_params->auth_xform.auth.op = auth_op; 11789 ut_params->auth_xform.auth.algo = reference->auth_algo; 11790 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 11791 ut_params->auth_xform.auth.key.data = auth_key; 11792 ut_params->auth_xform.auth.digest_length = reference->digest.len; 11793 11794 if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) { 11795 ut_params->auth_xform.auth.iv.offset = IV_OFFSET; 11796 ut_params->auth_xform.auth.iv.length = reference->iv.len; 11797 } else { 11798 ut_params->auth_xform.next = &ut_params->cipher_xform; 11799 11800 /* Setup Cipher Parameters */ 11801 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11802 ut_params->cipher_xform.next = NULL; 11803 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 11804 ut_params->cipher_xform.cipher.op = cipher_op; 11805 ut_params->cipher_xform.cipher.key.data = cipher_key; 11806 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 11807 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 11808 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 11809 } 11810 11811 /* Create Crypto session*/ 11812 ut_params->sess = rte_cryptodev_sym_session_create( 11813 ts_params->session_mpool); 11814 11815 rte_cryptodev_sym_session_init(dev_id, ut_params->sess, 11816 &ut_params->auth_xform, 11817 ts_params->session_priv_mpool); 11818 11819 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 11820 11821 return 0; 11822 } 11823 11824 static int 11825 create_auth_operation(struct crypto_testsuite_params *ts_params, 11826 struct crypto_unittest_params *ut_params, 11827 const struct test_crypto_vector *reference, 11828 unsigned int auth_generate) 11829 { 11830 /* Generate Crypto op data structure */ 11831 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11832 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11833 TEST_ASSERT_NOT_NULL(ut_params->op, 11834 "Failed to allocate pktmbuf offload"); 11835 11836 /* Set crypto operation data parameters */ 11837 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11838 11839 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 11840 11841 /* set crypto operation source mbuf */ 11842 sym_op->m_src = ut_params->ibuf; 11843 11844 /* digest */ 11845 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11846 ut_params->ibuf, reference->digest.len); 11847 11848 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11849 "no room to append auth tag"); 11850 11851 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11852 ut_params->ibuf, reference->plaintext.len); 11853 11854 if (auth_generate) 11855 memset(sym_op->auth.digest.data, 0, reference->digest.len); 11856 else 11857 memcpy(sym_op->auth.digest.data, 11858 reference->digest.data, 11859 reference->digest.len); 11860 11861 debug_hexdump(stdout, "digest:", 11862 sym_op->auth.digest.data, 11863 reference->digest.len); 11864 11865 sym_op->auth.data.length = reference->plaintext.len; 11866 sym_op->auth.data.offset = 0; 11867 11868 return 0; 11869 } 11870 11871 static int 11872 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params, 11873 struct crypto_unittest_params *ut_params, 11874 const struct test_crypto_vector *reference, 11875 unsigned int auth_generate) 11876 { 11877 /* Generate Crypto op data structure */ 11878 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11879 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11880 TEST_ASSERT_NOT_NULL(ut_params->op, 11881 "Failed to allocate pktmbuf offload"); 11882 11883 /* Set crypto operation data parameters */ 11884 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11885 11886 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 11887 11888 /* set crypto operation source mbuf */ 11889 sym_op->m_src = ut_params->ibuf; 11890 11891 /* digest */ 11892 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11893 ut_params->ibuf, reference->digest.len); 11894 11895 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11896 "no room to append auth tag"); 11897 11898 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11899 ut_params->ibuf, reference->ciphertext.len); 11900 11901 if (auth_generate) 11902 memset(sym_op->auth.digest.data, 0, reference->digest.len); 11903 else 11904 memcpy(sym_op->auth.digest.data, 11905 reference->digest.data, 11906 reference->digest.len); 11907 11908 debug_hexdump(stdout, "digest:", 11909 sym_op->auth.digest.data, 11910 reference->digest.len); 11911 11912 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 11913 reference->iv.data, reference->iv.len); 11914 11915 sym_op->cipher.data.length = 0; 11916 sym_op->cipher.data.offset = 0; 11917 11918 sym_op->auth.data.length = reference->plaintext.len; 11919 sym_op->auth.data.offset = 0; 11920 11921 return 0; 11922 } 11923 11924 static int 11925 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params, 11926 struct crypto_unittest_params *ut_params, 11927 const struct test_crypto_vector *reference, 11928 unsigned int auth_generate) 11929 { 11930 /* Generate Crypto op data structure */ 11931 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 11932 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 11933 TEST_ASSERT_NOT_NULL(ut_params->op, 11934 "Failed to allocate pktmbuf offload"); 11935 11936 /* Set crypto operation data parameters */ 11937 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 11938 11939 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 11940 11941 /* set crypto operation source mbuf */ 11942 sym_op->m_src = ut_params->ibuf; 11943 11944 /* digest */ 11945 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append( 11946 ut_params->ibuf, reference->digest.len); 11947 11948 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, 11949 "no room to append auth tag"); 11950 11951 sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( 11952 ut_params->ibuf, reference->ciphertext.len); 11953 11954 if (auth_generate) 11955 memset(sym_op->auth.digest.data, 0, reference->digest.len); 11956 else 11957 memcpy(sym_op->auth.digest.data, 11958 reference->digest.data, 11959 reference->digest.len); 11960 11961 debug_hexdump(stdout, "digest:", 11962 sym_op->auth.digest.data, 11963 reference->digest.len); 11964 11965 rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), 11966 reference->iv.data, reference->iv.len); 11967 11968 sym_op->cipher.data.length = reference->cipher_len; 11969 sym_op->cipher.data.offset = reference->cipher_offset; 11970 11971 sym_op->auth.data.length = reference->plaintext.len; 11972 sym_op->auth.data.offset = reference->auth_offset; 11973 11974 return 0; 11975 } 11976 11977 static int 11978 create_auth_verify_operation(struct crypto_testsuite_params *ts_params, 11979 struct crypto_unittest_params *ut_params, 11980 const struct test_crypto_vector *reference) 11981 { 11982 return create_auth_operation(ts_params, ut_params, reference, 0); 11983 } 11984 11985 static int 11986 create_auth_verify_GMAC_operation( 11987 struct crypto_testsuite_params *ts_params, 11988 struct crypto_unittest_params *ut_params, 11989 const struct test_crypto_vector *reference) 11990 { 11991 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0); 11992 } 11993 11994 static int 11995 create_cipher_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_cipher_auth_operation(ts_params, ut_params, reference, 0); 12000 } 12001 12002 static int 12003 test_authentication_verify_fail_when_data_corruption( 12004 struct crypto_testsuite_params *ts_params, 12005 struct crypto_unittest_params *ut_params, 12006 const struct test_crypto_vector *reference, 12007 unsigned int data_corrupted) 12008 { 12009 int retval; 12010 12011 uint8_t *plaintext; 12012 struct rte_cryptodev_info dev_info; 12013 12014 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12015 uint64_t feat_flags = dev_info.feature_flags; 12016 12017 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12018 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12019 printf("Device doesn't support RAW data-path APIs.\n"); 12020 return -ENOTSUP; 12021 } 12022 12023 /* Verify the capabilities */ 12024 struct rte_cryptodev_sym_capability_idx cap_idx; 12025 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12026 cap_idx.algo.auth = reference->auth_algo; 12027 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12028 &cap_idx) == NULL) 12029 return -ENOTSUP; 12030 12031 12032 /* Create session */ 12033 retval = create_auth_session(ut_params, 12034 ts_params->valid_devs[0], 12035 reference, 12036 RTE_CRYPTO_AUTH_OP_VERIFY); 12037 if (retval < 0) 12038 return retval; 12039 12040 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12041 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12042 "Failed to allocate input buffer in mempool"); 12043 12044 /* clear mbuf payload */ 12045 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12046 rte_pktmbuf_tailroom(ut_params->ibuf)); 12047 12048 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12049 reference->plaintext.len); 12050 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12051 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 12052 12053 debug_hexdump(stdout, "plaintext:", plaintext, 12054 reference->plaintext.len); 12055 12056 /* Create operation */ 12057 retval = create_auth_verify_operation(ts_params, ut_params, reference); 12058 12059 if (retval < 0) 12060 return retval; 12061 12062 if (data_corrupted) 12063 data_corruption(plaintext); 12064 else 12065 tag_corruption(plaintext, reference->plaintext.len); 12066 12067 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 12068 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12069 ut_params->op); 12070 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 12071 RTE_CRYPTO_OP_STATUS_SUCCESS, 12072 "authentication not failed"); 12073 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12074 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12075 ut_params->op, 0, 1, 0, 0); 12076 else { 12077 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 12078 ut_params->op); 12079 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 12080 } 12081 12082 return 0; 12083 } 12084 12085 static int 12086 test_authentication_verify_GMAC_fail_when_corruption( 12087 struct crypto_testsuite_params *ts_params, 12088 struct crypto_unittest_params *ut_params, 12089 const struct test_crypto_vector *reference, 12090 unsigned int data_corrupted) 12091 { 12092 int retval; 12093 uint8_t *plaintext; 12094 struct rte_cryptodev_info dev_info; 12095 12096 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12097 uint64_t feat_flags = dev_info.feature_flags; 12098 12099 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12100 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12101 printf("Device doesn't support RAW data-path APIs.\n"); 12102 return -ENOTSUP; 12103 } 12104 12105 /* Verify the capabilities */ 12106 struct rte_cryptodev_sym_capability_idx cap_idx; 12107 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12108 cap_idx.algo.auth = reference->auth_algo; 12109 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12110 &cap_idx) == NULL) 12111 return -ENOTSUP; 12112 12113 /* Create session */ 12114 retval = create_auth_cipher_session(ut_params, 12115 ts_params->valid_devs[0], 12116 reference, 12117 RTE_CRYPTO_AUTH_OP_VERIFY, 12118 RTE_CRYPTO_CIPHER_OP_DECRYPT); 12119 if (retval < 0) 12120 return retval; 12121 12122 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12123 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12124 "Failed to allocate input buffer in mempool"); 12125 12126 /* clear mbuf payload */ 12127 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12128 rte_pktmbuf_tailroom(ut_params->ibuf)); 12129 12130 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12131 reference->plaintext.len); 12132 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12133 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 12134 12135 debug_hexdump(stdout, "plaintext:", plaintext, 12136 reference->plaintext.len); 12137 12138 /* Create operation */ 12139 retval = create_auth_verify_GMAC_operation(ts_params, 12140 ut_params, 12141 reference); 12142 12143 if (retval < 0) 12144 return retval; 12145 12146 if (data_corrupted) 12147 data_corruption(plaintext); 12148 else 12149 tag_corruption(plaintext, reference->aad.len); 12150 12151 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 12152 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12153 ut_params->op); 12154 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 12155 RTE_CRYPTO_OP_STATUS_SUCCESS, 12156 "authentication not failed"); 12157 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12158 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12159 ut_params->op, 0, 1, 0, 0); 12160 else { 12161 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 12162 ut_params->op); 12163 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 12164 } 12165 12166 return 0; 12167 } 12168 12169 static int 12170 test_authenticated_decryption_fail_when_corruption( 12171 struct crypto_testsuite_params *ts_params, 12172 struct crypto_unittest_params *ut_params, 12173 const struct test_crypto_vector *reference, 12174 unsigned int data_corrupted) 12175 { 12176 int retval; 12177 12178 uint8_t *ciphertext; 12179 struct rte_cryptodev_info dev_info; 12180 12181 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12182 uint64_t feat_flags = dev_info.feature_flags; 12183 12184 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12185 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12186 printf("Device doesn't support RAW data-path APIs.\n"); 12187 return -ENOTSUP; 12188 } 12189 12190 /* Verify the capabilities */ 12191 struct rte_cryptodev_sym_capability_idx cap_idx; 12192 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12193 cap_idx.algo.auth = reference->auth_algo; 12194 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12195 &cap_idx) == NULL) 12196 return -ENOTSUP; 12197 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12198 cap_idx.algo.cipher = reference->crypto_algo; 12199 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12200 &cap_idx) == NULL) 12201 return -ENOTSUP; 12202 12203 /* Create session */ 12204 retval = create_auth_cipher_session(ut_params, 12205 ts_params->valid_devs[0], 12206 reference, 12207 RTE_CRYPTO_AUTH_OP_VERIFY, 12208 RTE_CRYPTO_CIPHER_OP_DECRYPT); 12209 if (retval < 0) 12210 return retval; 12211 12212 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12213 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12214 "Failed to allocate input buffer in mempool"); 12215 12216 /* clear mbuf payload */ 12217 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12218 rte_pktmbuf_tailroom(ut_params->ibuf)); 12219 12220 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12221 reference->ciphertext.len); 12222 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 12223 memcpy(ciphertext, reference->ciphertext.data, 12224 reference->ciphertext.len); 12225 12226 /* Create operation */ 12227 retval = create_cipher_auth_verify_operation(ts_params, 12228 ut_params, 12229 reference); 12230 12231 if (retval < 0) 12232 return retval; 12233 12234 if (data_corrupted) 12235 data_corruption(ciphertext); 12236 else 12237 tag_corruption(ciphertext, reference->ciphertext.len); 12238 12239 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) { 12240 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12241 ut_params->op); 12242 TEST_ASSERT_NOT_EQUAL(ut_params->op->status, 12243 RTE_CRYPTO_OP_STATUS_SUCCESS, 12244 "authentication not failed"); 12245 } else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12246 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12247 ut_params->op, 1, 1, 0, 0); 12248 else { 12249 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 12250 ut_params->op); 12251 TEST_ASSERT_NULL(ut_params->op, "authentication not failed"); 12252 } 12253 12254 return 0; 12255 } 12256 12257 static int 12258 test_authenticated_encryt_with_esn( 12259 struct crypto_testsuite_params *ts_params, 12260 struct crypto_unittest_params *ut_params, 12261 const struct test_crypto_vector *reference) 12262 { 12263 int retval; 12264 12265 uint8_t *authciphertext, *plaintext, *auth_tag; 12266 uint16_t plaintext_pad_len; 12267 uint8_t cipher_key[reference->cipher_key.len + 1]; 12268 uint8_t auth_key[reference->auth_key.len + 1]; 12269 struct rte_cryptodev_info dev_info; 12270 12271 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12272 uint64_t feat_flags = dev_info.feature_flags; 12273 12274 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12275 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12276 printf("Device doesn't support RAW data-path APIs.\n"); 12277 return -ENOTSUP; 12278 } 12279 12280 /* Verify the capabilities */ 12281 struct rte_cryptodev_sym_capability_idx cap_idx; 12282 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12283 cap_idx.algo.auth = reference->auth_algo; 12284 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12285 &cap_idx) == NULL) 12286 return -ENOTSUP; 12287 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12288 cap_idx.algo.cipher = reference->crypto_algo; 12289 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12290 &cap_idx) == NULL) 12291 return -ENOTSUP; 12292 12293 /* Create session */ 12294 memcpy(cipher_key, reference->cipher_key.data, 12295 reference->cipher_key.len); 12296 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 12297 12298 /* Setup Cipher Parameters */ 12299 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12300 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 12301 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; 12302 ut_params->cipher_xform.cipher.key.data = cipher_key; 12303 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 12304 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 12305 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 12306 12307 ut_params->cipher_xform.next = &ut_params->auth_xform; 12308 12309 /* Setup Authentication Parameters */ 12310 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12311 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; 12312 ut_params->auth_xform.auth.algo = reference->auth_algo; 12313 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 12314 ut_params->auth_xform.auth.key.data = auth_key; 12315 ut_params->auth_xform.auth.digest_length = reference->digest.len; 12316 ut_params->auth_xform.next = NULL; 12317 12318 /* Create Crypto session*/ 12319 ut_params->sess = rte_cryptodev_sym_session_create( 12320 ts_params->session_mpool); 12321 12322 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12323 ut_params->sess, 12324 &ut_params->cipher_xform, 12325 ts_params->session_priv_mpool); 12326 12327 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12328 12329 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12330 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12331 "Failed to allocate input buffer in mempool"); 12332 12333 /* clear mbuf payload */ 12334 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12335 rte_pktmbuf_tailroom(ut_params->ibuf)); 12336 12337 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12338 reference->plaintext.len); 12339 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext"); 12340 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len); 12341 12342 /* Create operation */ 12343 retval = create_cipher_auth_operation(ts_params, 12344 ut_params, 12345 reference, 0); 12346 12347 if (retval < 0) 12348 return retval; 12349 12350 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12351 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12352 ut_params->op); 12353 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12354 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12355 ut_params->op, 1, 1, 0, 0); 12356 else 12357 ut_params->op = process_crypto_request( 12358 ts_params->valid_devs[0], ut_params->op); 12359 12360 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned"); 12361 12362 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12363 "crypto op processing failed"); 12364 12365 plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16); 12366 12367 authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *, 12368 ut_params->op->sym->auth.data.offset); 12369 auth_tag = authciphertext + plaintext_pad_len; 12370 debug_hexdump(stdout, "ciphertext:", authciphertext, 12371 reference->ciphertext.len); 12372 debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len); 12373 12374 /* Validate obuf */ 12375 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12376 authciphertext, 12377 reference->ciphertext.data, 12378 reference->ciphertext.len, 12379 "Ciphertext data not as expected"); 12380 12381 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12382 auth_tag, 12383 reference->digest.data, 12384 reference->digest.len, 12385 "Generated digest not as expected"); 12386 12387 return TEST_SUCCESS; 12388 12389 } 12390 12391 static int 12392 test_authenticated_decrypt_with_esn( 12393 struct crypto_testsuite_params *ts_params, 12394 struct crypto_unittest_params *ut_params, 12395 const struct test_crypto_vector *reference) 12396 { 12397 int retval; 12398 12399 uint8_t *ciphertext; 12400 uint8_t cipher_key[reference->cipher_key.len + 1]; 12401 uint8_t auth_key[reference->auth_key.len + 1]; 12402 struct rte_cryptodev_info dev_info; 12403 12404 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12405 uint64_t feat_flags = dev_info.feature_flags; 12406 12407 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12408 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12409 printf("Device doesn't support RAW data-path APIs.\n"); 12410 return -ENOTSUP; 12411 } 12412 12413 /* Verify the capabilities */ 12414 struct rte_cryptodev_sym_capability_idx cap_idx; 12415 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12416 cap_idx.algo.auth = reference->auth_algo; 12417 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12418 &cap_idx) == NULL) 12419 return -ENOTSUP; 12420 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12421 cap_idx.algo.cipher = reference->crypto_algo; 12422 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12423 &cap_idx) == NULL) 12424 return -ENOTSUP; 12425 12426 /* Create session */ 12427 memcpy(cipher_key, reference->cipher_key.data, 12428 reference->cipher_key.len); 12429 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len); 12430 12431 /* Setup Authentication Parameters */ 12432 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 12433 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; 12434 ut_params->auth_xform.auth.algo = reference->auth_algo; 12435 ut_params->auth_xform.auth.key.length = reference->auth_key.len; 12436 ut_params->auth_xform.auth.key.data = auth_key; 12437 ut_params->auth_xform.auth.digest_length = reference->digest.len; 12438 ut_params->auth_xform.next = &ut_params->cipher_xform; 12439 12440 /* Setup Cipher Parameters */ 12441 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 12442 ut_params->cipher_xform.next = NULL; 12443 ut_params->cipher_xform.cipher.algo = reference->crypto_algo; 12444 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; 12445 ut_params->cipher_xform.cipher.key.data = cipher_key; 12446 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len; 12447 ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; 12448 ut_params->cipher_xform.cipher.iv.length = reference->iv.len; 12449 12450 /* Create Crypto session*/ 12451 ut_params->sess = rte_cryptodev_sym_session_create( 12452 ts_params->session_mpool); 12453 12454 rte_cryptodev_sym_session_init(ts_params->valid_devs[0], 12455 ut_params->sess, 12456 &ut_params->auth_xform, 12457 ts_params->session_priv_mpool); 12458 12459 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); 12460 12461 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12462 TEST_ASSERT_NOT_NULL(ut_params->ibuf, 12463 "Failed to allocate input buffer in mempool"); 12464 12465 /* clear mbuf payload */ 12466 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12467 rte_pktmbuf_tailroom(ut_params->ibuf)); 12468 12469 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12470 reference->ciphertext.len); 12471 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext"); 12472 memcpy(ciphertext, reference->ciphertext.data, 12473 reference->ciphertext.len); 12474 12475 /* Create operation */ 12476 retval = create_cipher_auth_verify_operation(ts_params, 12477 ut_params, 12478 reference); 12479 12480 if (retval < 0) 12481 return retval; 12482 12483 if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12484 process_cpu_crypt_auth_op(ts_params->valid_devs[0], 12485 ut_params->op); 12486 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12487 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12488 ut_params->op, 1, 1, 0, 0); 12489 else 12490 ut_params->op = process_crypto_request(ts_params->valid_devs[0], 12491 ut_params->op); 12492 12493 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process"); 12494 TEST_ASSERT_EQUAL(ut_params->op->status, 12495 RTE_CRYPTO_OP_STATUS_SUCCESS, 12496 "crypto op processing passed"); 12497 12498 ut_params->obuf = ut_params->op->sym->m_src; 12499 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf"); 12500 12501 return 0; 12502 } 12503 12504 static int 12505 create_aead_operation_SGL(enum rte_crypto_aead_operation op, 12506 const struct aead_test_data *tdata, 12507 void *digest_mem, uint64_t digest_phys) 12508 { 12509 struct crypto_testsuite_params *ts_params = &testsuite_params; 12510 struct crypto_unittest_params *ut_params = &unittest_params; 12511 12512 const unsigned int auth_tag_len = tdata->auth_tag.len; 12513 const unsigned int iv_len = tdata->iv.len; 12514 unsigned int aad_len = tdata->aad.len; 12515 unsigned int aad_len_pad = 0; 12516 12517 /* Generate Crypto op data structure */ 12518 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, 12519 RTE_CRYPTO_OP_TYPE_SYMMETRIC); 12520 TEST_ASSERT_NOT_NULL(ut_params->op, 12521 "Failed to allocate symmetric crypto operation struct"); 12522 12523 struct rte_crypto_sym_op *sym_op = ut_params->op->sym; 12524 12525 sym_op->aead.digest.data = digest_mem; 12526 12527 TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data, 12528 "no room to append digest"); 12529 12530 sym_op->aead.digest.phys_addr = digest_phys; 12531 12532 if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) { 12533 rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data, 12534 auth_tag_len); 12535 debug_hexdump(stdout, "digest:", 12536 sym_op->aead.digest.data, 12537 auth_tag_len); 12538 } 12539 12540 /* Append aad data */ 12541 if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) { 12542 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12543 uint8_t *, IV_OFFSET); 12544 12545 /* Copy IV 1 byte after the IV pointer, according to the API */ 12546 rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len); 12547 12548 aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16); 12549 12550 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 12551 ut_params->ibuf, aad_len); 12552 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 12553 "no room to prepend aad"); 12554 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 12555 ut_params->ibuf); 12556 12557 memset(sym_op->aead.aad.data, 0, aad_len); 12558 /* Copy AAD 18 bytes after the AAD pointer, according to the API */ 12559 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 12560 12561 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 12562 debug_hexdump(stdout, "aad:", 12563 sym_op->aead.aad.data, aad_len); 12564 } else { 12565 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, 12566 uint8_t *, IV_OFFSET); 12567 12568 rte_memcpy(iv_ptr, tdata->iv.data, iv_len); 12569 12570 aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16); 12571 12572 sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend( 12573 ut_params->ibuf, aad_len_pad); 12574 TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data, 12575 "no room to prepend aad"); 12576 sym_op->aead.aad.phys_addr = rte_pktmbuf_iova( 12577 ut_params->ibuf); 12578 12579 memset(sym_op->aead.aad.data, 0, aad_len); 12580 rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len); 12581 12582 debug_hexdump(stdout, "iv:", iv_ptr, iv_len); 12583 debug_hexdump(stdout, "aad:", 12584 sym_op->aead.aad.data, aad_len); 12585 } 12586 12587 sym_op->aead.data.length = tdata->plaintext.len; 12588 sym_op->aead.data.offset = aad_len_pad; 12589 12590 return 0; 12591 } 12592 12593 #define SGL_MAX_NO 16 12594 12595 static int 12596 test_authenticated_encryption_SGL(const struct aead_test_data *tdata, 12597 const int oop, uint32_t fragsz, uint32_t fragsz_oop) 12598 { 12599 struct crypto_testsuite_params *ts_params = &testsuite_params; 12600 struct crypto_unittest_params *ut_params = &unittest_params; 12601 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL; 12602 int retval; 12603 int to_trn = 0; 12604 int to_trn_tbl[SGL_MAX_NO]; 12605 int segs = 1; 12606 unsigned int trn_data = 0; 12607 uint8_t *plaintext, *ciphertext, *auth_tag; 12608 struct rte_cryptodev_info dev_info; 12609 12610 /* Verify the capabilities */ 12611 struct rte_cryptodev_sym_capability_idx cap_idx; 12612 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD; 12613 cap_idx.algo.aead = tdata->algo; 12614 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], 12615 &cap_idx) == NULL) 12616 return -ENOTSUP; 12617 12618 /* OOP not supported with CPU crypto */ 12619 if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12620 return -ENOTSUP; 12621 12622 /* Detailed check for the particular SGL support flag */ 12623 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); 12624 if (!oop) { 12625 unsigned int sgl_in = fragsz < tdata->plaintext.len; 12626 if (sgl_in && (!(dev_info.feature_flags & 12627 RTE_CRYPTODEV_FF_IN_PLACE_SGL))) 12628 return -ENOTSUP; 12629 12630 uint64_t feat_flags = dev_info.feature_flags; 12631 12632 if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) && 12633 (!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { 12634 printf("Device doesn't support RAW data-path APIs.\n"); 12635 return -ENOTSUP; 12636 } 12637 } else { 12638 unsigned int sgl_in = fragsz < tdata->plaintext.len; 12639 unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) < 12640 tdata->plaintext.len; 12641 /* Raw data path API does not support OOP */ 12642 if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12643 return -ENOTSUP; 12644 if (sgl_in && !sgl_out) { 12645 if (!(dev_info.feature_flags & 12646 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) 12647 return -ENOTSUP; 12648 } else if (!sgl_in && sgl_out) { 12649 if (!(dev_info.feature_flags & 12650 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT)) 12651 return -ENOTSUP; 12652 } else if (sgl_in && sgl_out) { 12653 if (!(dev_info.feature_flags & 12654 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) 12655 return -ENOTSUP; 12656 } 12657 } 12658 12659 if (fragsz > tdata->plaintext.len) 12660 fragsz = tdata->plaintext.len; 12661 12662 uint16_t plaintext_len = fragsz; 12663 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; 12664 12665 if (fragsz_oop > tdata->plaintext.len) 12666 frag_size_oop = tdata->plaintext.len; 12667 12668 int ecx = 0; 12669 void *digest_mem = NULL; 12670 12671 uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16); 12672 12673 if (tdata->plaintext.len % fragsz != 0) { 12674 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO) 12675 return 1; 12676 } else { 12677 if (tdata->plaintext.len / fragsz > SGL_MAX_NO) 12678 return 1; 12679 } 12680 12681 /* 12682 * For out-op-place we need to alloc another mbuf 12683 */ 12684 if (oop) { 12685 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12686 rte_pktmbuf_append(ut_params->obuf, 12687 frag_size_oop + prepend_len); 12688 buf_oop = ut_params->obuf; 12689 } 12690 12691 /* Create AEAD session */ 12692 retval = create_aead_session(ts_params->valid_devs[0], 12693 tdata->algo, 12694 RTE_CRYPTO_AEAD_OP_ENCRYPT, 12695 tdata->key.data, tdata->key.len, 12696 tdata->aad.len, tdata->auth_tag.len, 12697 tdata->iv.len); 12698 if (retval < 0) 12699 return retval; 12700 12701 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12702 12703 /* clear mbuf payload */ 12704 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, 12705 rte_pktmbuf_tailroom(ut_params->ibuf)); 12706 12707 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12708 plaintext_len); 12709 12710 memcpy(plaintext, tdata->plaintext.data, plaintext_len); 12711 12712 trn_data += plaintext_len; 12713 12714 buf = ut_params->ibuf; 12715 12716 /* 12717 * Loop until no more fragments 12718 */ 12719 12720 while (trn_data < tdata->plaintext.len) { 12721 ++segs; 12722 to_trn = (tdata->plaintext.len - trn_data < fragsz) ? 12723 (tdata->plaintext.len - trn_data) : fragsz; 12724 12725 to_trn_tbl[ecx++] = to_trn; 12726 12727 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); 12728 buf = buf->next; 12729 12730 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, 12731 rte_pktmbuf_tailroom(buf)); 12732 12733 /* OOP */ 12734 if (oop && !fragsz_oop) { 12735 buf_last_oop = buf_oop->next = 12736 rte_pktmbuf_alloc(ts_params->mbuf_pool); 12737 buf_oop = buf_oop->next; 12738 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 12739 0, rte_pktmbuf_tailroom(buf_oop)); 12740 rte_pktmbuf_append(buf_oop, to_trn); 12741 } 12742 12743 plaintext = (uint8_t *)rte_pktmbuf_append(buf, 12744 to_trn); 12745 12746 memcpy(plaintext, tdata->plaintext.data + trn_data, 12747 to_trn); 12748 trn_data += to_trn; 12749 if (trn_data == tdata->plaintext.len) { 12750 if (oop) { 12751 if (!fragsz_oop) 12752 digest_mem = rte_pktmbuf_append(buf_oop, 12753 tdata->auth_tag.len); 12754 } else 12755 digest_mem = (uint8_t *)rte_pktmbuf_append(buf, 12756 tdata->auth_tag.len); 12757 } 12758 } 12759 12760 uint64_t digest_phys = 0; 12761 12762 ut_params->ibuf->nb_segs = segs; 12763 12764 segs = 1; 12765 if (fragsz_oop && oop) { 12766 to_trn = 0; 12767 ecx = 0; 12768 12769 if (frag_size_oop == tdata->plaintext.len) { 12770 digest_mem = rte_pktmbuf_append(ut_params->obuf, 12771 tdata->auth_tag.len); 12772 12773 digest_phys = rte_pktmbuf_iova_offset( 12774 ut_params->obuf, 12775 tdata->plaintext.len + prepend_len); 12776 } 12777 12778 trn_data = frag_size_oop; 12779 while (trn_data < tdata->plaintext.len) { 12780 ++segs; 12781 to_trn = 12782 (tdata->plaintext.len - trn_data < 12783 frag_size_oop) ? 12784 (tdata->plaintext.len - trn_data) : 12785 frag_size_oop; 12786 12787 to_trn_tbl[ecx++] = to_trn; 12788 12789 buf_last_oop = buf_oop->next = 12790 rte_pktmbuf_alloc(ts_params->mbuf_pool); 12791 buf_oop = buf_oop->next; 12792 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), 12793 0, rte_pktmbuf_tailroom(buf_oop)); 12794 rte_pktmbuf_append(buf_oop, to_trn); 12795 12796 trn_data += to_trn; 12797 12798 if (trn_data == tdata->plaintext.len) { 12799 digest_mem = rte_pktmbuf_append(buf_oop, 12800 tdata->auth_tag.len); 12801 } 12802 } 12803 12804 ut_params->obuf->nb_segs = segs; 12805 } 12806 12807 /* 12808 * Place digest at the end of the last buffer 12809 */ 12810 if (!digest_phys) 12811 digest_phys = rte_pktmbuf_iova(buf) + to_trn; 12812 if (oop && buf_last_oop) 12813 digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn; 12814 12815 if (!digest_mem && !oop) { 12816 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, 12817 + tdata->auth_tag.len); 12818 digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf, 12819 tdata->plaintext.len); 12820 } 12821 12822 /* Create AEAD operation */ 12823 retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT, 12824 tdata, digest_mem, digest_phys); 12825 12826 if (retval < 0) 12827 return retval; 12828 12829 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); 12830 12831 ut_params->op->sym->m_src = ut_params->ibuf; 12832 if (oop) 12833 ut_params->op->sym->m_dst = ut_params->obuf; 12834 12835 /* Process crypto operation */ 12836 if (oop == IN_PLACE && 12837 gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) 12838 process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op); 12839 else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) 12840 process_sym_raw_dp_op(ts_params->valid_devs[0], 0, 12841 ut_params->op, 0, 0, 0, 0); 12842 else 12843 TEST_ASSERT_NOT_NULL( 12844 process_crypto_request(ts_params->valid_devs[0], 12845 ut_params->op), "failed to process sym crypto op"); 12846 12847 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, 12848 "crypto op processing failed"); 12849 12850 12851 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src, 12852 uint8_t *, prepend_len); 12853 if (oop) { 12854 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst, 12855 uint8_t *, prepend_len); 12856 } 12857 12858 if (fragsz_oop) 12859 fragsz = fragsz_oop; 12860 12861 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12862 ciphertext, 12863 tdata->ciphertext.data, 12864 fragsz, 12865 "Ciphertext data not as expected"); 12866 12867 buf = ut_params->op->sym->m_src->next; 12868 if (oop) 12869 buf = ut_params->op->sym->m_dst->next; 12870 12871 unsigned int off = fragsz; 12872 12873 ecx = 0; 12874 while (buf) { 12875 ciphertext = rte_pktmbuf_mtod(buf, 12876 uint8_t *); 12877 12878 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12879 ciphertext, 12880 tdata->ciphertext.data + off, 12881 to_trn_tbl[ecx], 12882 "Ciphertext data not as expected"); 12883 12884 off += to_trn_tbl[ecx++]; 12885 buf = buf->next; 12886 } 12887 12888 auth_tag = digest_mem; 12889 TEST_ASSERT_BUFFERS_ARE_EQUAL( 12890 auth_tag, 12891 tdata->auth_tag.data, 12892 tdata->auth_tag.len, 12893 "Generated auth tag not as expected"); 12894 12895 return 0; 12896 } 12897 12898 static int 12899 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) 12900 { 12901 return test_authenticated_encryption_SGL( 12902 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400); 12903 } 12904 12905 static int 12906 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void) 12907 { 12908 return test_authenticated_encryption_SGL( 12909 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000); 12910 } 12911 12912 static int 12913 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void) 12914 { 12915 return test_authenticated_encryption_SGL( 12916 &gcm_test_case_8, OUT_OF_PLACE, 400, 12917 gcm_test_case_8.plaintext.len); 12918 } 12919 12920 static int 12921 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void) 12922 { 12923 /* This test is not for OPENSSL PMD */ 12924 if (gbl_driver_id == rte_cryptodev_driver_id_get( 12925 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) 12926 return -ENOTSUP; 12927 12928 return test_authenticated_encryption_SGL( 12929 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0); 12930 } 12931 12932 static int 12933 test_authentication_verify_fail_when_data_corrupted( 12934 struct crypto_testsuite_params *ts_params, 12935 struct crypto_unittest_params *ut_params, 12936 const struct test_crypto_vector *reference) 12937 { 12938 return test_authentication_verify_fail_when_data_corruption( 12939 ts_params, ut_params, reference, 1); 12940 } 12941 12942 static int 12943 test_authentication_verify_fail_when_tag_corrupted( 12944 struct crypto_testsuite_params *ts_params, 12945 struct crypto_unittest_params *ut_params, 12946 const struct test_crypto_vector *reference) 12947 { 12948 return test_authentication_verify_fail_when_data_corruption( 12949 ts_params, ut_params, reference, 0); 12950 } 12951 12952 static int 12953 test_authentication_verify_GMAC_fail_when_data_corrupted( 12954 struct crypto_testsuite_params *ts_params, 12955 struct crypto_unittest_params *ut_params, 12956 const struct test_crypto_vector *reference) 12957 { 12958 return test_authentication_verify_GMAC_fail_when_corruption( 12959 ts_params, ut_params, reference, 1); 12960 } 12961 12962 static int 12963 test_authentication_verify_GMAC_fail_when_tag_corrupted( 12964 struct crypto_testsuite_params *ts_params, 12965 struct crypto_unittest_params *ut_params, 12966 const struct test_crypto_vector *reference) 12967 { 12968 return test_authentication_verify_GMAC_fail_when_corruption( 12969 ts_params, ut_params, reference, 0); 12970 } 12971 12972 static int 12973 test_authenticated_decryption_fail_when_data_corrupted( 12974 struct crypto_testsuite_params *ts_params, 12975 struct crypto_unittest_params *ut_params, 12976 const struct test_crypto_vector *reference) 12977 { 12978 return test_authenticated_decryption_fail_when_corruption( 12979 ts_params, ut_params, reference, 1); 12980 } 12981 12982 static int 12983 test_authenticated_decryption_fail_when_tag_corrupted( 12984 struct crypto_testsuite_params *ts_params, 12985 struct crypto_unittest_params *ut_params, 12986 const struct test_crypto_vector *reference) 12987 { 12988 return test_authenticated_decryption_fail_when_corruption( 12989 ts_params, ut_params, reference, 0); 12990 } 12991 12992 static int 12993 authentication_verify_HMAC_SHA1_fail_data_corrupt(void) 12994 { 12995 return test_authentication_verify_fail_when_data_corrupted( 12996 &testsuite_params, &unittest_params, 12997 &hmac_sha1_test_crypto_vector); 12998 } 12999 13000 static int 13001 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void) 13002 { 13003 return test_authentication_verify_fail_when_tag_corrupted( 13004 &testsuite_params, &unittest_params, 13005 &hmac_sha1_test_crypto_vector); 13006 } 13007 13008 static int 13009 authentication_verify_AES128_GMAC_fail_data_corrupt(void) 13010 { 13011 return test_authentication_verify_GMAC_fail_when_data_corrupted( 13012 &testsuite_params, &unittest_params, 13013 &aes128_gmac_test_vector); 13014 } 13015 13016 static int 13017 authentication_verify_AES128_GMAC_fail_tag_corrupt(void) 13018 { 13019 return test_authentication_verify_GMAC_fail_when_tag_corrupted( 13020 &testsuite_params, &unittest_params, 13021 &aes128_gmac_test_vector); 13022 } 13023 13024 static int 13025 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void) 13026 { 13027 return test_authenticated_decryption_fail_when_data_corrupted( 13028 &testsuite_params, 13029 &unittest_params, 13030 &aes128cbc_hmac_sha1_test_vector); 13031 } 13032 13033 static int 13034 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void) 13035 { 13036 return test_authenticated_decryption_fail_when_tag_corrupted( 13037 &testsuite_params, 13038 &unittest_params, 13039 &aes128cbc_hmac_sha1_test_vector); 13040 } 13041 13042 static int 13043 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void) 13044 { 13045 return test_authenticated_encryt_with_esn( 13046 &testsuite_params, 13047 &unittest_params, 13048 &aes128cbc_hmac_sha1_aad_test_vector); 13049 } 13050 13051 static int 13052 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void) 13053 { 13054 return test_authenticated_decrypt_with_esn( 13055 &testsuite_params, 13056 &unittest_params, 13057 &aes128cbc_hmac_sha1_aad_test_vector); 13058 } 13059 13060 static int 13061 test_chacha20_poly1305_encrypt_test_case_rfc8439(void) 13062 { 13063 return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439); 13064 } 13065 13066 static int 13067 test_chacha20_poly1305_decrypt_test_case_rfc8439(void) 13068 { 13069 return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439); 13070 } 13071 13072 #ifdef RTE_CRYPTO_SCHEDULER 13073 13074 /* global AESNI worker IDs for the scheduler test */ 13075 uint8_t aesni_ids[2]; 13076 13077 static int 13078 test_scheduler_attach_slave_op(void) 13079 { 13080 struct crypto_testsuite_params *ts_params = &testsuite_params; 13081 uint8_t sched_id = ts_params->valid_devs[0]; 13082 uint32_t nb_devs, i, nb_devs_attached = 0; 13083 int ret; 13084 char vdev_name[32]; 13085 13086 /* create 2 AESNI_MB if necessary */ 13087 nb_devs = rte_cryptodev_device_count_by_driver( 13088 rte_cryptodev_driver_id_get( 13089 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))); 13090 if (nb_devs < 2) { 13091 for (i = nb_devs; i < 2; i++) { 13092 snprintf(vdev_name, sizeof(vdev_name), "%s_%u", 13093 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), 13094 i); 13095 ret = rte_vdev_init(vdev_name, NULL); 13096 13097 TEST_ASSERT(ret == 0, 13098 "Failed to create instance %u of" 13099 " pmd : %s", 13100 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 13101 } 13102 } 13103 13104 /* attach 2 AESNI_MB cdevs */ 13105 for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2; 13106 i++) { 13107 struct rte_cryptodev_info info; 13108 unsigned int session_size; 13109 13110 rte_cryptodev_info_get(i, &info); 13111 if (info.driver_id != rte_cryptodev_driver_id_get( 13112 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) 13113 continue; 13114 13115 session_size = rte_cryptodev_sym_get_private_session_size(i); 13116 /* 13117 * Create the session mempool again, since now there are new devices 13118 * to use the mempool. 13119 */ 13120 if (ts_params->session_mpool) { 13121 rte_mempool_free(ts_params->session_mpool); 13122 ts_params->session_mpool = NULL; 13123 } 13124 if (ts_params->session_priv_mpool) { 13125 rte_mempool_free(ts_params->session_priv_mpool); 13126 ts_params->session_priv_mpool = NULL; 13127 } 13128 13129 if (info.sym.max_nb_sessions != 0 && 13130 info.sym.max_nb_sessions < MAX_NB_SESSIONS) { 13131 RTE_LOG(ERR, USER1, 13132 "Device does not support " 13133 "at least %u sessions\n", 13134 MAX_NB_SESSIONS); 13135 return TEST_FAILED; 13136 } 13137 /* 13138 * Create mempool with maximum number of sessions, 13139 * to include the session headers 13140 */ 13141 if (ts_params->session_mpool == NULL) { 13142 ts_params->session_mpool = 13143 rte_cryptodev_sym_session_pool_create( 13144 "test_sess_mp", 13145 MAX_NB_SESSIONS, 0, 0, 0, 13146 SOCKET_ID_ANY); 13147 TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 13148 "session mempool allocation failed"); 13149 } 13150 13151 /* 13152 * Create mempool with maximum number of sessions, 13153 * to include device specific session private data 13154 */ 13155 if (ts_params->session_priv_mpool == NULL) { 13156 ts_params->session_priv_mpool = rte_mempool_create( 13157 "test_sess_mp_priv", 13158 MAX_NB_SESSIONS, 13159 session_size, 13160 0, 0, NULL, NULL, NULL, 13161 NULL, SOCKET_ID_ANY, 13162 0); 13163 13164 TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool, 13165 "session mempool allocation failed"); 13166 } 13167 13168 ts_params->qp_conf.mp_session = ts_params->session_mpool; 13169 ts_params->qp_conf.mp_session_private = 13170 ts_params->session_priv_mpool; 13171 13172 ret = rte_cryptodev_scheduler_worker_attach(sched_id, 13173 (uint8_t)i); 13174 13175 TEST_ASSERT(ret == 0, 13176 "Failed to attach device %u of pmd : %s", i, 13177 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 13178 13179 aesni_ids[nb_devs_attached] = (uint8_t)i; 13180 13181 nb_devs_attached++; 13182 } 13183 13184 return 0; 13185 } 13186 13187 static int 13188 test_scheduler_detach_slave_op(void) 13189 { 13190 struct crypto_testsuite_params *ts_params = &testsuite_params; 13191 uint8_t sched_id = ts_params->valid_devs[0]; 13192 uint32_t i; 13193 int ret; 13194 13195 for (i = 0; i < 2; i++) { 13196 ret = rte_cryptodev_scheduler_worker_detach(sched_id, 13197 aesni_ids[i]); 13198 TEST_ASSERT(ret == 0, 13199 "Failed to detach device %u", aesni_ids[i]); 13200 } 13201 13202 return 0; 13203 } 13204 13205 static int 13206 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode) 13207 { 13208 struct crypto_testsuite_params *ts_params = &testsuite_params; 13209 uint8_t sched_id = ts_params->valid_devs[0]; 13210 /* set mode */ 13211 return rte_cryptodev_scheduler_mode_set(sched_id, 13212 scheduler_mode); 13213 } 13214 13215 static int 13216 test_scheduler_mode_roundrobin_op(void) 13217 { 13218 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) == 13219 0, "Failed to set roundrobin mode"); 13220 return 0; 13221 13222 } 13223 13224 static int 13225 test_scheduler_mode_multicore_op(void) 13226 { 13227 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) == 13228 0, "Failed to set multicore mode"); 13229 13230 return 0; 13231 } 13232 13233 static int 13234 test_scheduler_mode_failover_op(void) 13235 { 13236 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) == 13237 0, "Failed to set failover mode"); 13238 13239 return 0; 13240 } 13241 13242 static int 13243 test_scheduler_mode_pkt_size_distr_op(void) 13244 { 13245 TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) == 13246 0, "Failed to set pktsize mode"); 13247 13248 return 0; 13249 } 13250 13251 static struct unit_test_suite cryptodev_scheduler_testsuite = { 13252 .suite_name = "Crypto Device Scheduler Unit Test Suite", 13253 .setup = testsuite_setup, 13254 .teardown = testsuite_teardown, 13255 .unit_test_cases = { 13256 /* Multi Core */ 13257 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 13258 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_multicore_op), 13259 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13260 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13261 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13262 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 13263 13264 /* Round Robin */ 13265 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 13266 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_roundrobin_op), 13267 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13268 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13269 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13270 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 13271 13272 /* Fail over */ 13273 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 13274 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_failover_op), 13275 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13276 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13277 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13278 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 13279 13280 /* PKT SIZE */ 13281 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op), 13282 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_pkt_size_distr_op), 13283 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13284 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13285 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13286 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op), 13287 13288 TEST_CASES_END() /**< NULL terminate unit test array */ 13289 } 13290 }; 13291 13292 #endif /* RTE_CRYPTO_SCHEDULER */ 13293 13294 static struct unit_test_suite cryptodev_testsuite = { 13295 .suite_name = "Crypto Unit Test Suite", 13296 .setup = testsuite_setup, 13297 .teardown = testsuite_teardown, 13298 .unit_test_cases = { 13299 TEST_CASE_ST(ut_setup, ut_teardown, 13300 test_device_configure_invalid_dev_id), 13301 TEST_CASE_ST(ut_setup, ut_teardown, 13302 test_queue_pair_descriptor_setup), 13303 TEST_CASE_ST(ut_setup, ut_teardown, 13304 test_device_configure_invalid_queue_pair_ids), 13305 TEST_CASE_ST(ut_setup, ut_teardown, 13306 test_multi_session), 13307 TEST_CASE_ST(ut_setup, ut_teardown, 13308 test_multi_session_random_usage), 13309 13310 TEST_CASE_ST(ut_setup, ut_teardown, 13311 test_null_invalid_operation), 13312 TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation), 13313 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13314 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13315 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 13316 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 13317 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_cipheronly_all), 13318 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_all), 13319 TEST_CASE_ST(ut_setup, ut_teardown, test_DES_docsis_all), 13320 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13321 TEST_CASE_ST(ut_setup, ut_teardown, test_stats), 13322 13323 /** AES CCM Authenticated Encryption 128 bits key */ 13324 TEST_CASE_ST(ut_setup, ut_teardown, 13325 test_AES_CCM_authenticated_encryption_test_case_128_1), 13326 TEST_CASE_ST(ut_setup, ut_teardown, 13327 test_AES_CCM_authenticated_encryption_test_case_128_2), 13328 TEST_CASE_ST(ut_setup, ut_teardown, 13329 test_AES_CCM_authenticated_encryption_test_case_128_3), 13330 13331 /** AES CCM Authenticated Decryption 128 bits key*/ 13332 TEST_CASE_ST(ut_setup, ut_teardown, 13333 test_AES_CCM_authenticated_decryption_test_case_128_1), 13334 TEST_CASE_ST(ut_setup, ut_teardown, 13335 test_AES_CCM_authenticated_decryption_test_case_128_2), 13336 TEST_CASE_ST(ut_setup, ut_teardown, 13337 test_AES_CCM_authenticated_decryption_test_case_128_3), 13338 13339 /** AES CCM Authenticated Encryption 192 bits key */ 13340 TEST_CASE_ST(ut_setup, ut_teardown, 13341 test_AES_CCM_authenticated_encryption_test_case_192_1), 13342 TEST_CASE_ST(ut_setup, ut_teardown, 13343 test_AES_CCM_authenticated_encryption_test_case_192_2), 13344 TEST_CASE_ST(ut_setup, ut_teardown, 13345 test_AES_CCM_authenticated_encryption_test_case_192_3), 13346 13347 /** AES CCM Authenticated Decryption 192 bits key*/ 13348 TEST_CASE_ST(ut_setup, ut_teardown, 13349 test_AES_CCM_authenticated_decryption_test_case_192_1), 13350 TEST_CASE_ST(ut_setup, ut_teardown, 13351 test_AES_CCM_authenticated_decryption_test_case_192_2), 13352 TEST_CASE_ST(ut_setup, ut_teardown, 13353 test_AES_CCM_authenticated_decryption_test_case_192_3), 13354 13355 /** AES CCM Authenticated Encryption 256 bits key */ 13356 TEST_CASE_ST(ut_setup, ut_teardown, 13357 test_AES_CCM_authenticated_encryption_test_case_256_1), 13358 TEST_CASE_ST(ut_setup, ut_teardown, 13359 test_AES_CCM_authenticated_encryption_test_case_256_2), 13360 TEST_CASE_ST(ut_setup, ut_teardown, 13361 test_AES_CCM_authenticated_encryption_test_case_256_3), 13362 13363 /** AES CCM Authenticated Decryption 256 bits key*/ 13364 TEST_CASE_ST(ut_setup, ut_teardown, 13365 test_AES_CCM_authenticated_decryption_test_case_256_1), 13366 TEST_CASE_ST(ut_setup, ut_teardown, 13367 test_AES_CCM_authenticated_decryption_test_case_256_2), 13368 TEST_CASE_ST(ut_setup, ut_teardown, 13369 test_AES_CCM_authenticated_decryption_test_case_256_3), 13370 13371 /** AES GCM Authenticated Encryption */ 13372 TEST_CASE_ST(ut_setup, ut_teardown, 13373 test_AES_GCM_auth_encrypt_SGL_in_place_1500B), 13374 TEST_CASE_ST(ut_setup, ut_teardown, 13375 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B), 13376 TEST_CASE_ST(ut_setup, ut_teardown, 13377 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B), 13378 TEST_CASE_ST(ut_setup, ut_teardown, 13379 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg), 13380 TEST_CASE_ST(ut_setup, ut_teardown, 13381 test_AES_GCM_authenticated_encryption_test_case_1), 13382 TEST_CASE_ST(ut_setup, ut_teardown, 13383 test_AES_GCM_authenticated_encryption_test_case_2), 13384 TEST_CASE_ST(ut_setup, ut_teardown, 13385 test_AES_GCM_authenticated_encryption_test_case_3), 13386 TEST_CASE_ST(ut_setup, ut_teardown, 13387 test_AES_GCM_authenticated_encryption_test_case_4), 13388 TEST_CASE_ST(ut_setup, ut_teardown, 13389 test_AES_GCM_authenticated_encryption_test_case_5), 13390 TEST_CASE_ST(ut_setup, ut_teardown, 13391 test_AES_GCM_authenticated_encryption_test_case_6), 13392 TEST_CASE_ST(ut_setup, ut_teardown, 13393 test_AES_GCM_authenticated_encryption_test_case_7), 13394 TEST_CASE_ST(ut_setup, ut_teardown, 13395 test_AES_GCM_authenticated_encryption_test_case_8), 13396 TEST_CASE_ST(ut_setup, ut_teardown, 13397 test_AES_GCM_J0_authenticated_encryption_test_case_1), 13398 13399 /** AES GCM Authenticated Decryption */ 13400 TEST_CASE_ST(ut_setup, ut_teardown, 13401 test_AES_GCM_authenticated_decryption_test_case_1), 13402 TEST_CASE_ST(ut_setup, ut_teardown, 13403 test_AES_GCM_authenticated_decryption_test_case_2), 13404 TEST_CASE_ST(ut_setup, ut_teardown, 13405 test_AES_GCM_authenticated_decryption_test_case_3), 13406 TEST_CASE_ST(ut_setup, ut_teardown, 13407 test_AES_GCM_authenticated_decryption_test_case_4), 13408 TEST_CASE_ST(ut_setup, ut_teardown, 13409 test_AES_GCM_authenticated_decryption_test_case_5), 13410 TEST_CASE_ST(ut_setup, ut_teardown, 13411 test_AES_GCM_authenticated_decryption_test_case_6), 13412 TEST_CASE_ST(ut_setup, ut_teardown, 13413 test_AES_GCM_authenticated_decryption_test_case_7), 13414 TEST_CASE_ST(ut_setup, ut_teardown, 13415 test_AES_GCM_authenticated_decryption_test_case_8), 13416 TEST_CASE_ST(ut_setup, ut_teardown, 13417 test_AES_GCM_J0_authenticated_decryption_test_case_1), 13418 13419 /** AES GCM Authenticated Encryption 192 bits key */ 13420 TEST_CASE_ST(ut_setup, ut_teardown, 13421 test_AES_GCM_auth_encryption_test_case_192_1), 13422 TEST_CASE_ST(ut_setup, ut_teardown, 13423 test_AES_GCM_auth_encryption_test_case_192_2), 13424 TEST_CASE_ST(ut_setup, ut_teardown, 13425 test_AES_GCM_auth_encryption_test_case_192_3), 13426 TEST_CASE_ST(ut_setup, ut_teardown, 13427 test_AES_GCM_auth_encryption_test_case_192_4), 13428 TEST_CASE_ST(ut_setup, ut_teardown, 13429 test_AES_GCM_auth_encryption_test_case_192_5), 13430 TEST_CASE_ST(ut_setup, ut_teardown, 13431 test_AES_GCM_auth_encryption_test_case_192_6), 13432 TEST_CASE_ST(ut_setup, ut_teardown, 13433 test_AES_GCM_auth_encryption_test_case_192_7), 13434 13435 /** AES GCM Authenticated Decryption 192 bits key */ 13436 TEST_CASE_ST(ut_setup, ut_teardown, 13437 test_AES_GCM_auth_decryption_test_case_192_1), 13438 TEST_CASE_ST(ut_setup, ut_teardown, 13439 test_AES_GCM_auth_decryption_test_case_192_2), 13440 TEST_CASE_ST(ut_setup, ut_teardown, 13441 test_AES_GCM_auth_decryption_test_case_192_3), 13442 TEST_CASE_ST(ut_setup, ut_teardown, 13443 test_AES_GCM_auth_decryption_test_case_192_4), 13444 TEST_CASE_ST(ut_setup, ut_teardown, 13445 test_AES_GCM_auth_decryption_test_case_192_5), 13446 TEST_CASE_ST(ut_setup, ut_teardown, 13447 test_AES_GCM_auth_decryption_test_case_192_6), 13448 TEST_CASE_ST(ut_setup, ut_teardown, 13449 test_AES_GCM_auth_decryption_test_case_192_7), 13450 13451 /** AES GCM Authenticated Encryption 256 bits key */ 13452 TEST_CASE_ST(ut_setup, ut_teardown, 13453 test_AES_GCM_auth_encryption_test_case_256_1), 13454 TEST_CASE_ST(ut_setup, ut_teardown, 13455 test_AES_GCM_auth_encryption_test_case_256_2), 13456 TEST_CASE_ST(ut_setup, ut_teardown, 13457 test_AES_GCM_auth_encryption_test_case_256_3), 13458 TEST_CASE_ST(ut_setup, ut_teardown, 13459 test_AES_GCM_auth_encryption_test_case_256_4), 13460 TEST_CASE_ST(ut_setup, ut_teardown, 13461 test_AES_GCM_auth_encryption_test_case_256_5), 13462 TEST_CASE_ST(ut_setup, ut_teardown, 13463 test_AES_GCM_auth_encryption_test_case_256_6), 13464 TEST_CASE_ST(ut_setup, ut_teardown, 13465 test_AES_GCM_auth_encryption_test_case_256_7), 13466 13467 /** AES GCM Authenticated Decryption 256 bits key */ 13468 TEST_CASE_ST(ut_setup, ut_teardown, 13469 test_AES_GCM_auth_decryption_test_case_256_1), 13470 TEST_CASE_ST(ut_setup, ut_teardown, 13471 test_AES_GCM_auth_decryption_test_case_256_2), 13472 TEST_CASE_ST(ut_setup, ut_teardown, 13473 test_AES_GCM_auth_decryption_test_case_256_3), 13474 TEST_CASE_ST(ut_setup, ut_teardown, 13475 test_AES_GCM_auth_decryption_test_case_256_4), 13476 TEST_CASE_ST(ut_setup, ut_teardown, 13477 test_AES_GCM_auth_decryption_test_case_256_5), 13478 TEST_CASE_ST(ut_setup, ut_teardown, 13479 test_AES_GCM_auth_decryption_test_case_256_6), 13480 TEST_CASE_ST(ut_setup, ut_teardown, 13481 test_AES_GCM_auth_decryption_test_case_256_7), 13482 13483 /** AES GCM Authenticated Encryption big aad size */ 13484 TEST_CASE_ST(ut_setup, ut_teardown, 13485 test_AES_GCM_auth_encryption_test_case_aad_1), 13486 TEST_CASE_ST(ut_setup, ut_teardown, 13487 test_AES_GCM_auth_encryption_test_case_aad_2), 13488 13489 /** AES GCM Authenticated Decryption big aad size */ 13490 TEST_CASE_ST(ut_setup, ut_teardown, 13491 test_AES_GCM_auth_decryption_test_case_aad_1), 13492 TEST_CASE_ST(ut_setup, ut_teardown, 13493 test_AES_GCM_auth_decryption_test_case_aad_2), 13494 13495 /** Out of place tests */ 13496 TEST_CASE_ST(ut_setup, ut_teardown, 13497 test_AES_GCM_authenticated_encryption_oop_test_case_1), 13498 TEST_CASE_ST(ut_setup, ut_teardown, 13499 test_AES_GCM_authenticated_decryption_oop_test_case_1), 13500 13501 /** Session-less tests */ 13502 TEST_CASE_ST(ut_setup, ut_teardown, 13503 test_AES_GCM_authenticated_encryption_sessionless_test_case_1), 13504 TEST_CASE_ST(ut_setup, ut_teardown, 13505 test_AES_GCM_authenticated_decryption_sessionless_test_case_1), 13506 13507 /** AES GMAC Authentication */ 13508 TEST_CASE_ST(ut_setup, ut_teardown, 13509 test_AES_GMAC_authentication_test_case_1), 13510 TEST_CASE_ST(ut_setup, ut_teardown, 13511 test_AES_GMAC_authentication_verify_test_case_1), 13512 TEST_CASE_ST(ut_setup, ut_teardown, 13513 test_AES_GMAC_authentication_test_case_2), 13514 TEST_CASE_ST(ut_setup, ut_teardown, 13515 test_AES_GMAC_authentication_verify_test_case_2), 13516 TEST_CASE_ST(ut_setup, ut_teardown, 13517 test_AES_GMAC_authentication_test_case_3), 13518 TEST_CASE_ST(ut_setup, ut_teardown, 13519 test_AES_GMAC_authentication_verify_test_case_3), 13520 TEST_CASE_ST(ut_setup, ut_teardown, 13521 test_AES_GMAC_authentication_test_case_4), 13522 TEST_CASE_ST(ut_setup, ut_teardown, 13523 test_AES_GMAC_authentication_verify_test_case_4), 13524 TEST_CASE_ST(ut_setup, ut_teardown, 13525 test_AES_GMAC_authentication_SGL_40B), 13526 TEST_CASE_ST(ut_setup, ut_teardown, 13527 test_AES_GMAC_authentication_SGL_80B), 13528 TEST_CASE_ST(ut_setup, ut_teardown, 13529 test_AES_GMAC_authentication_SGL_2048B), 13530 TEST_CASE_ST(ut_setup, ut_teardown, 13531 test_AES_GMAC_authentication_SGL_2047B), 13532 13533 /** Chacha20-Poly1305 */ 13534 TEST_CASE_ST(ut_setup, ut_teardown, 13535 test_chacha20_poly1305_encrypt_test_case_rfc8439), 13536 TEST_CASE_ST(ut_setup, ut_teardown, 13537 test_chacha20_poly1305_decrypt_test_case_rfc8439), 13538 /** SNOW 3G encrypt only (UEA2) */ 13539 TEST_CASE_ST(ut_setup, ut_teardown, 13540 test_snow3g_encryption_test_case_1), 13541 TEST_CASE_ST(ut_setup, ut_teardown, 13542 test_snow3g_encryption_test_case_2), 13543 TEST_CASE_ST(ut_setup, ut_teardown, 13544 test_snow3g_encryption_test_case_3), 13545 TEST_CASE_ST(ut_setup, ut_teardown, 13546 test_snow3g_encryption_test_case_4), 13547 TEST_CASE_ST(ut_setup, ut_teardown, 13548 test_snow3g_encryption_test_case_5), 13549 13550 TEST_CASE_ST(ut_setup, ut_teardown, 13551 test_snow3g_encryption_test_case_1_oop), 13552 TEST_CASE_ST(ut_setup, ut_teardown, 13553 test_snow3g_encryption_test_case_1_oop_sgl), 13554 TEST_CASE_ST(ut_setup, ut_teardown, 13555 test_snow3g_encryption_test_case_1_offset_oop), 13556 TEST_CASE_ST(ut_setup, ut_teardown, 13557 test_snow3g_decryption_test_case_1_oop), 13558 13559 /** SNOW 3G generate auth, then encrypt (UEA2) */ 13560 TEST_CASE_ST(ut_setup, ut_teardown, 13561 test_snow3g_auth_cipher_test_case_1), 13562 TEST_CASE_ST(ut_setup, ut_teardown, 13563 test_snow3g_auth_cipher_test_case_2), 13564 TEST_CASE_ST(ut_setup, ut_teardown, 13565 test_snow3g_auth_cipher_test_case_2_oop), 13566 TEST_CASE_ST(ut_setup, ut_teardown, 13567 test_snow3g_auth_cipher_part_digest_enc), 13568 TEST_CASE_ST(ut_setup, ut_teardown, 13569 test_snow3g_auth_cipher_part_digest_enc_oop), 13570 TEST_CASE_ST(ut_setup, ut_teardown, 13571 test_snow3g_auth_cipher_test_case_3_sgl), 13572 TEST_CASE_ST(ut_setup, ut_teardown, 13573 test_snow3g_auth_cipher_test_case_3_oop_sgl), 13574 TEST_CASE_ST(ut_setup, ut_teardown, 13575 test_snow3g_auth_cipher_part_digest_enc_sgl), 13576 TEST_CASE_ST(ut_setup, ut_teardown, 13577 test_snow3g_auth_cipher_part_digest_enc_oop_sgl), 13578 13579 /** SNOW 3G decrypt (UEA2), then verify auth */ 13580 TEST_CASE_ST(ut_setup, ut_teardown, 13581 test_snow3g_auth_cipher_verify_test_case_1), 13582 TEST_CASE_ST(ut_setup, ut_teardown, 13583 test_snow3g_auth_cipher_verify_test_case_2), 13584 TEST_CASE_ST(ut_setup, ut_teardown, 13585 test_snow3g_auth_cipher_verify_test_case_2_oop), 13586 TEST_CASE_ST(ut_setup, ut_teardown, 13587 test_snow3g_auth_cipher_verify_part_digest_enc), 13588 TEST_CASE_ST(ut_setup, ut_teardown, 13589 test_snow3g_auth_cipher_verify_part_digest_enc_oop), 13590 TEST_CASE_ST(ut_setup, ut_teardown, 13591 test_snow3g_auth_cipher_verify_test_case_3_sgl), 13592 TEST_CASE_ST(ut_setup, ut_teardown, 13593 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl), 13594 TEST_CASE_ST(ut_setup, ut_teardown, 13595 test_snow3g_auth_cipher_verify_part_digest_enc_sgl), 13596 TEST_CASE_ST(ut_setup, ut_teardown, 13597 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl), 13598 13599 /** SNOW 3G decrypt only (UEA2) */ 13600 TEST_CASE_ST(ut_setup, ut_teardown, 13601 test_snow3g_decryption_test_case_1), 13602 TEST_CASE_ST(ut_setup, ut_teardown, 13603 test_snow3g_decryption_test_case_2), 13604 TEST_CASE_ST(ut_setup, ut_teardown, 13605 test_snow3g_decryption_test_case_3), 13606 TEST_CASE_ST(ut_setup, ut_teardown, 13607 test_snow3g_decryption_test_case_4), 13608 TEST_CASE_ST(ut_setup, ut_teardown, 13609 test_snow3g_decryption_test_case_5), 13610 TEST_CASE_ST(ut_setup, ut_teardown, 13611 test_snow3g_decryption_with_digest_test_case_1), 13612 TEST_CASE_ST(ut_setup, ut_teardown, 13613 test_snow3g_hash_generate_test_case_1), 13614 TEST_CASE_ST(ut_setup, ut_teardown, 13615 test_snow3g_hash_generate_test_case_2), 13616 TEST_CASE_ST(ut_setup, ut_teardown, 13617 test_snow3g_hash_generate_test_case_3), 13618 /* Tests with buffers which length is not byte-aligned */ 13619 TEST_CASE_ST(ut_setup, ut_teardown, 13620 test_snow3g_hash_generate_test_case_4), 13621 TEST_CASE_ST(ut_setup, ut_teardown, 13622 test_snow3g_hash_generate_test_case_5), 13623 TEST_CASE_ST(ut_setup, ut_teardown, 13624 test_snow3g_hash_generate_test_case_6), 13625 TEST_CASE_ST(ut_setup, ut_teardown, 13626 test_snow3g_hash_verify_test_case_1), 13627 TEST_CASE_ST(ut_setup, ut_teardown, 13628 test_snow3g_hash_verify_test_case_2), 13629 TEST_CASE_ST(ut_setup, ut_teardown, 13630 test_snow3g_hash_verify_test_case_3), 13631 /* Tests with buffers which length is not byte-aligned */ 13632 TEST_CASE_ST(ut_setup, ut_teardown, 13633 test_snow3g_hash_verify_test_case_4), 13634 TEST_CASE_ST(ut_setup, ut_teardown, 13635 test_snow3g_hash_verify_test_case_5), 13636 TEST_CASE_ST(ut_setup, ut_teardown, 13637 test_snow3g_hash_verify_test_case_6), 13638 TEST_CASE_ST(ut_setup, ut_teardown, 13639 test_snow3g_cipher_auth_test_case_1), 13640 TEST_CASE_ST(ut_setup, ut_teardown, 13641 test_snow3g_auth_cipher_with_digest_test_case_1), 13642 13643 /** ZUC encrypt only (EEA3) */ 13644 TEST_CASE_ST(ut_setup, ut_teardown, 13645 test_zuc_encryption_test_case_1), 13646 TEST_CASE_ST(ut_setup, ut_teardown, 13647 test_zuc_encryption_test_case_2), 13648 TEST_CASE_ST(ut_setup, ut_teardown, 13649 test_zuc_encryption_test_case_3), 13650 TEST_CASE_ST(ut_setup, ut_teardown, 13651 test_zuc_encryption_test_case_4), 13652 TEST_CASE_ST(ut_setup, ut_teardown, 13653 test_zuc_encryption_test_case_5), 13654 TEST_CASE_ST(ut_setup, ut_teardown, 13655 test_zuc_encryption_test_case_6_sgl), 13656 13657 /** ZUC authenticate (EIA3) */ 13658 TEST_CASE_ST(ut_setup, ut_teardown, 13659 test_zuc_hash_generate_test_case_1), 13660 TEST_CASE_ST(ut_setup, ut_teardown, 13661 test_zuc_hash_generate_test_case_2), 13662 TEST_CASE_ST(ut_setup, ut_teardown, 13663 test_zuc_hash_generate_test_case_3), 13664 TEST_CASE_ST(ut_setup, ut_teardown, 13665 test_zuc_hash_generate_test_case_4), 13666 TEST_CASE_ST(ut_setup, ut_teardown, 13667 test_zuc_hash_generate_test_case_5), 13668 TEST_CASE_ST(ut_setup, ut_teardown, 13669 test_zuc_hash_generate_test_case_6), 13670 TEST_CASE_ST(ut_setup, ut_teardown, 13671 test_zuc_hash_generate_test_case_7), 13672 TEST_CASE_ST(ut_setup, ut_teardown, 13673 test_zuc_hash_generate_test_case_8), 13674 13675 /** ZUC alg-chain (EEA3/EIA3) */ 13676 TEST_CASE_ST(ut_setup, ut_teardown, 13677 test_zuc_cipher_auth_test_case_1), 13678 TEST_CASE_ST(ut_setup, ut_teardown, 13679 test_zuc_cipher_auth_test_case_2), 13680 13681 /** ZUC generate auth, then encrypt (EEA3) */ 13682 TEST_CASE_ST(ut_setup, ut_teardown, 13683 test_zuc_auth_cipher_test_case_1), 13684 TEST_CASE_ST(ut_setup, ut_teardown, 13685 test_zuc_auth_cipher_test_case_1_oop), 13686 TEST_CASE_ST(ut_setup, ut_teardown, 13687 test_zuc_auth_cipher_test_case_1_sgl), 13688 TEST_CASE_ST(ut_setup, ut_teardown, 13689 test_zuc_auth_cipher_test_case_1_oop_sgl), 13690 13691 /** ZUC decrypt (EEA3), then verify auth */ 13692 TEST_CASE_ST(ut_setup, ut_teardown, 13693 test_zuc_auth_cipher_verify_test_case_1), 13694 TEST_CASE_ST(ut_setup, ut_teardown, 13695 test_zuc_auth_cipher_verify_test_case_1_oop), 13696 TEST_CASE_ST(ut_setup, ut_teardown, 13697 test_zuc_auth_cipher_verify_test_case_1_sgl), 13698 TEST_CASE_ST(ut_setup, ut_teardown, 13699 test_zuc_auth_cipher_verify_test_case_1_oop_sgl), 13700 13701 /** HMAC_MD5 Authentication */ 13702 TEST_CASE_ST(ut_setup, ut_teardown, 13703 test_MD5_HMAC_generate_case_1), 13704 TEST_CASE_ST(ut_setup, ut_teardown, 13705 test_MD5_HMAC_verify_case_1), 13706 TEST_CASE_ST(ut_setup, ut_teardown, 13707 test_MD5_HMAC_generate_case_2), 13708 TEST_CASE_ST(ut_setup, ut_teardown, 13709 test_MD5_HMAC_verify_case_2), 13710 13711 /** KASUMI hash only (UIA1) */ 13712 TEST_CASE_ST(ut_setup, ut_teardown, 13713 test_kasumi_hash_generate_test_case_1), 13714 TEST_CASE_ST(ut_setup, ut_teardown, 13715 test_kasumi_hash_generate_test_case_2), 13716 TEST_CASE_ST(ut_setup, ut_teardown, 13717 test_kasumi_hash_generate_test_case_3), 13718 TEST_CASE_ST(ut_setup, ut_teardown, 13719 test_kasumi_hash_generate_test_case_4), 13720 TEST_CASE_ST(ut_setup, ut_teardown, 13721 test_kasumi_hash_generate_test_case_5), 13722 TEST_CASE_ST(ut_setup, ut_teardown, 13723 test_kasumi_hash_generate_test_case_6), 13724 13725 TEST_CASE_ST(ut_setup, ut_teardown, 13726 test_kasumi_hash_verify_test_case_1), 13727 TEST_CASE_ST(ut_setup, ut_teardown, 13728 test_kasumi_hash_verify_test_case_2), 13729 TEST_CASE_ST(ut_setup, ut_teardown, 13730 test_kasumi_hash_verify_test_case_3), 13731 TEST_CASE_ST(ut_setup, ut_teardown, 13732 test_kasumi_hash_verify_test_case_4), 13733 TEST_CASE_ST(ut_setup, ut_teardown, 13734 test_kasumi_hash_verify_test_case_5), 13735 13736 /** KASUMI encrypt only (UEA1) */ 13737 TEST_CASE_ST(ut_setup, ut_teardown, 13738 test_kasumi_encryption_test_case_1), 13739 TEST_CASE_ST(ut_setup, ut_teardown, 13740 test_kasumi_encryption_test_case_1_sgl), 13741 TEST_CASE_ST(ut_setup, ut_teardown, 13742 test_kasumi_encryption_test_case_1_oop), 13743 TEST_CASE_ST(ut_setup, ut_teardown, 13744 test_kasumi_encryption_test_case_1_oop_sgl), 13745 TEST_CASE_ST(ut_setup, ut_teardown, 13746 test_kasumi_encryption_test_case_2), 13747 TEST_CASE_ST(ut_setup, ut_teardown, 13748 test_kasumi_encryption_test_case_3), 13749 TEST_CASE_ST(ut_setup, ut_teardown, 13750 test_kasumi_encryption_test_case_4), 13751 TEST_CASE_ST(ut_setup, ut_teardown, 13752 test_kasumi_encryption_test_case_5), 13753 13754 /** KASUMI decrypt only (UEA1) */ 13755 TEST_CASE_ST(ut_setup, ut_teardown, 13756 test_kasumi_decryption_test_case_1), 13757 TEST_CASE_ST(ut_setup, ut_teardown, 13758 test_kasumi_decryption_test_case_2), 13759 TEST_CASE_ST(ut_setup, ut_teardown, 13760 test_kasumi_decryption_test_case_3), 13761 TEST_CASE_ST(ut_setup, ut_teardown, 13762 test_kasumi_decryption_test_case_4), 13763 TEST_CASE_ST(ut_setup, ut_teardown, 13764 test_kasumi_decryption_test_case_5), 13765 TEST_CASE_ST(ut_setup, ut_teardown, 13766 test_kasumi_decryption_test_case_1_oop), 13767 13768 TEST_CASE_ST(ut_setup, ut_teardown, 13769 test_kasumi_cipher_auth_test_case_1), 13770 13771 /** KASUMI generate auth, then encrypt (F8) */ 13772 TEST_CASE_ST(ut_setup, ut_teardown, 13773 test_kasumi_auth_cipher_test_case_1), 13774 TEST_CASE_ST(ut_setup, ut_teardown, 13775 test_kasumi_auth_cipher_test_case_2), 13776 TEST_CASE_ST(ut_setup, ut_teardown, 13777 test_kasumi_auth_cipher_test_case_2_oop), 13778 TEST_CASE_ST(ut_setup, ut_teardown, 13779 test_kasumi_auth_cipher_test_case_2_sgl), 13780 TEST_CASE_ST(ut_setup, ut_teardown, 13781 test_kasumi_auth_cipher_test_case_2_oop_sgl), 13782 13783 /** KASUMI decrypt (F8), then verify auth */ 13784 TEST_CASE_ST(ut_setup, ut_teardown, 13785 test_kasumi_auth_cipher_verify_test_case_1), 13786 TEST_CASE_ST(ut_setup, ut_teardown, 13787 test_kasumi_auth_cipher_verify_test_case_2), 13788 TEST_CASE_ST(ut_setup, ut_teardown, 13789 test_kasumi_auth_cipher_verify_test_case_2_oop), 13790 TEST_CASE_ST(ut_setup, ut_teardown, 13791 test_kasumi_auth_cipher_verify_test_case_2_sgl), 13792 TEST_CASE_ST(ut_setup, ut_teardown, 13793 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl), 13794 13795 /** ESN Testcase */ 13796 TEST_CASE_ST(ut_setup, ut_teardown, 13797 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check), 13798 TEST_CASE_ST(ut_setup, ut_teardown, 13799 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check), 13800 13801 /** Negative tests */ 13802 TEST_CASE_ST(ut_setup, ut_teardown, 13803 authentication_verify_HMAC_SHA1_fail_data_corrupt), 13804 TEST_CASE_ST(ut_setup, ut_teardown, 13805 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 13806 TEST_CASE_ST(ut_setup, ut_teardown, 13807 test_AES_GCM_auth_encryption_fail_iv_corrupt), 13808 TEST_CASE_ST(ut_setup, ut_teardown, 13809 test_AES_GCM_auth_encryption_fail_in_data_corrupt), 13810 TEST_CASE_ST(ut_setup, ut_teardown, 13811 test_AES_GCM_auth_encryption_fail_out_data_corrupt), 13812 TEST_CASE_ST(ut_setup, ut_teardown, 13813 test_AES_GCM_auth_encryption_fail_aad_len_corrupt), 13814 TEST_CASE_ST(ut_setup, ut_teardown, 13815 test_AES_GCM_auth_encryption_fail_aad_corrupt), 13816 TEST_CASE_ST(ut_setup, ut_teardown, 13817 test_AES_GCM_auth_encryption_fail_tag_corrupt), 13818 TEST_CASE_ST(ut_setup, ut_teardown, 13819 test_AES_GCM_auth_decryption_fail_iv_corrupt), 13820 TEST_CASE_ST(ut_setup, ut_teardown, 13821 test_AES_GCM_auth_decryption_fail_in_data_corrupt), 13822 TEST_CASE_ST(ut_setup, ut_teardown, 13823 test_AES_GCM_auth_decryption_fail_out_data_corrupt), 13824 TEST_CASE_ST(ut_setup, ut_teardown, 13825 test_AES_GCM_auth_decryption_fail_aad_len_corrupt), 13826 TEST_CASE_ST(ut_setup, ut_teardown, 13827 test_AES_GCM_auth_decryption_fail_aad_corrupt), 13828 TEST_CASE_ST(ut_setup, ut_teardown, 13829 test_AES_GCM_auth_decryption_fail_tag_corrupt), 13830 TEST_CASE_ST(ut_setup, ut_teardown, 13831 authentication_verify_AES128_GMAC_fail_data_corrupt), 13832 TEST_CASE_ST(ut_setup, ut_teardown, 13833 authentication_verify_AES128_GMAC_fail_tag_corrupt), 13834 TEST_CASE_ST(ut_setup, ut_teardown, 13835 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 13836 TEST_CASE_ST(ut_setup, ut_teardown, 13837 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 13838 13839 /** Mixed CIPHER + HASH algorithms */ 13840 /** AUTH AES CMAC + CIPHER AES CTR */ 13841 TEST_CASE_ST(ut_setup, ut_teardown, 13842 test_aes_cmac_aes_ctr_digest_enc_test_case_1), 13843 TEST_CASE_ST(ut_setup, ut_teardown, 13844 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 13845 TEST_CASE_ST(ut_setup, ut_teardown, 13846 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 13847 TEST_CASE_ST(ut_setup, ut_teardown, 13848 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 13849 TEST_CASE_ST(ut_setup, ut_teardown, 13850 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1), 13851 TEST_CASE_ST(ut_setup, ut_teardown, 13852 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop), 13853 TEST_CASE_ST(ut_setup, ut_teardown, 13854 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl), 13855 TEST_CASE_ST(ut_setup, ut_teardown, 13856 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl), 13857 13858 /** AUTH ZUC + CIPHER SNOW3G */ 13859 TEST_CASE_ST(ut_setup, ut_teardown, 13860 test_auth_zuc_cipher_snow_test_case_1), 13861 TEST_CASE_ST(ut_setup, ut_teardown, 13862 test_verify_auth_zuc_cipher_snow_test_case_1), 13863 /** AUTH AES CMAC + CIPHER SNOW3G */ 13864 TEST_CASE_ST(ut_setup, ut_teardown, 13865 test_auth_aes_cmac_cipher_snow_test_case_1), 13866 TEST_CASE_ST(ut_setup, ut_teardown, 13867 test_verify_auth_aes_cmac_cipher_snow_test_case_1), 13868 /** AUTH ZUC + CIPHER AES CTR */ 13869 TEST_CASE_ST(ut_setup, ut_teardown, 13870 test_auth_zuc_cipher_aes_ctr_test_case_1), 13871 TEST_CASE_ST(ut_setup, ut_teardown, 13872 test_verify_auth_zuc_cipher_aes_ctr_test_case_1), 13873 /** AUTH SNOW3G + CIPHER AES CTR */ 13874 TEST_CASE_ST(ut_setup, ut_teardown, 13875 test_auth_snow_cipher_aes_ctr_test_case_1), 13876 TEST_CASE_ST(ut_setup, ut_teardown, 13877 test_verify_auth_snow_cipher_aes_ctr_test_case_1), 13878 /** AUTH SNOW3G + CIPHER ZUC */ 13879 TEST_CASE_ST(ut_setup, ut_teardown, 13880 test_auth_snow_cipher_zuc_test_case_1), 13881 TEST_CASE_ST(ut_setup, ut_teardown, 13882 test_verify_auth_snow_cipher_zuc_test_case_1), 13883 /** AUTH AES CMAC + CIPHER ZUC */ 13884 TEST_CASE_ST(ut_setup, ut_teardown, 13885 test_auth_aes_cmac_cipher_zuc_test_case_1), 13886 TEST_CASE_ST(ut_setup, ut_teardown, 13887 test_verify_auth_aes_cmac_cipher_zuc_test_case_1), 13888 13889 /** AUTH NULL + CIPHER SNOW3G */ 13890 TEST_CASE_ST(ut_setup, ut_teardown, 13891 test_auth_null_cipher_snow_test_case_1), 13892 TEST_CASE_ST(ut_setup, ut_teardown, 13893 test_verify_auth_null_cipher_snow_test_case_1), 13894 /** AUTH NULL + CIPHER ZUC */ 13895 TEST_CASE_ST(ut_setup, ut_teardown, 13896 test_auth_null_cipher_zuc_test_case_1), 13897 TEST_CASE_ST(ut_setup, ut_teardown, 13898 test_verify_auth_null_cipher_zuc_test_case_1), 13899 /** AUTH SNOW3G + CIPHER NULL */ 13900 TEST_CASE_ST(ut_setup, ut_teardown, 13901 test_auth_snow_cipher_null_test_case_1), 13902 TEST_CASE_ST(ut_setup, ut_teardown, 13903 test_verify_auth_snow_cipher_null_test_case_1), 13904 /** AUTH ZUC + CIPHER NULL */ 13905 TEST_CASE_ST(ut_setup, ut_teardown, 13906 test_auth_zuc_cipher_null_test_case_1), 13907 TEST_CASE_ST(ut_setup, ut_teardown, 13908 test_verify_auth_zuc_cipher_null_test_case_1), 13909 /** AUTH NULL + CIPHER AES CTR */ 13910 TEST_CASE_ST(ut_setup, ut_teardown, 13911 test_auth_null_cipher_aes_ctr_test_case_1), 13912 TEST_CASE_ST(ut_setup, ut_teardown, 13913 test_verify_auth_null_cipher_aes_ctr_test_case_1), 13914 /** AUTH AES CMAC + CIPHER NULL */ 13915 TEST_CASE_ST(ut_setup, ut_teardown, 13916 test_auth_aes_cmac_cipher_null_test_case_1), 13917 TEST_CASE_ST(ut_setup, ut_teardown, 13918 test_verify_auth_aes_cmac_cipher_null_test_case_1), 13919 13920 #ifdef RTE_LIB_SECURITY 13921 TEST_CASE_ST(ut_setup_security, ut_teardown, 13922 test_PDCP_PROTO_all), 13923 TEST_CASE_ST(ut_setup_security, ut_teardown, 13924 test_DOCSIS_PROTO_all), 13925 #endif 13926 TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup), 13927 TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup), 13928 TEST_CASES_END() /**< NULL terminate unit test array */ 13929 } 13930 }; 13931 13932 static struct unit_test_suite cryptodev_virtio_testsuite = { 13933 .suite_name = "Crypto VIRTIO Unit Test Suite", 13934 .setup = testsuite_setup, 13935 .teardown = testsuite_teardown, 13936 .unit_test_cases = { 13937 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13938 13939 TEST_CASES_END() /**< NULL terminate unit test array */ 13940 } 13941 }; 13942 13943 static struct unit_test_suite cryptodev_caam_jr_testsuite = { 13944 .suite_name = "Crypto CAAM JR Unit Test Suite", 13945 .setup = testsuite_setup, 13946 .teardown = testsuite_teardown, 13947 .unit_test_cases = { 13948 TEST_CASE_ST(ut_setup, ut_teardown, 13949 test_device_configure_invalid_dev_id), 13950 TEST_CASE_ST(ut_setup, ut_teardown, 13951 test_multi_session), 13952 13953 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13954 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 13955 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13956 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 13957 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13958 13959 TEST_CASES_END() /**< NULL terminate unit test array */ 13960 } 13961 }; 13962 13963 static struct unit_test_suite cryptodev_mrvl_testsuite = { 13964 .suite_name = "Crypto Device Marvell Component Test Suite", 13965 .setup = testsuite_setup, 13966 .teardown = testsuite_teardown, 13967 .unit_test_cases = { 13968 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 13969 TEST_CASE_ST(ut_setup, ut_teardown, 13970 test_multi_session_random_usage), 13971 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 13972 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 13973 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 13974 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 13975 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 13976 13977 /** Negative tests */ 13978 TEST_CASE_ST(ut_setup, ut_teardown, 13979 authentication_verify_HMAC_SHA1_fail_data_corrupt), 13980 TEST_CASE_ST(ut_setup, ut_teardown, 13981 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 13982 TEST_CASE_ST(ut_setup, ut_teardown, 13983 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 13984 TEST_CASE_ST(ut_setup, ut_teardown, 13985 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 13986 13987 TEST_CASES_END() /**< NULL terminate unit test array */ 13988 } 13989 }; 13990 13991 static struct unit_test_suite cryptodev_ccp_testsuite = { 13992 .suite_name = "Crypto Device CCP Unit Test Suite", 13993 .setup = testsuite_setup, 13994 .teardown = testsuite_teardown, 13995 .unit_test_cases = { 13996 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session), 13997 TEST_CASE_ST(ut_setup, ut_teardown, 13998 test_multi_session_random_usage), 13999 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all), 14000 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all), 14001 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all), 14002 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all), 14003 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all), 14004 14005 /** Negative tests */ 14006 TEST_CASE_ST(ut_setup, ut_teardown, 14007 authentication_verify_HMAC_SHA1_fail_data_corrupt), 14008 TEST_CASE_ST(ut_setup, ut_teardown, 14009 authentication_verify_HMAC_SHA1_fail_tag_corrupt), 14010 TEST_CASE_ST(ut_setup, ut_teardown, 14011 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt), 14012 TEST_CASE_ST(ut_setup, ut_teardown, 14013 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt), 14014 14015 TEST_CASES_END() /**< NULL terminate unit test array */ 14016 } 14017 }; 14018 14019 static int 14020 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/) 14021 { 14022 gbl_driver_id = rte_cryptodev_driver_id_get( 14023 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 14024 14025 if (gbl_driver_id == -1) { 14026 RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n"); 14027 return TEST_SKIPPED; 14028 } 14029 14030 return unit_test_suite_runner(&cryptodev_testsuite); 14031 } 14032 14033 static int 14034 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/) 14035 { 14036 gbl_driver_id = rte_cryptodev_driver_id_get( 14037 RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD)); 14038 14039 if (gbl_driver_id == -1) { 14040 RTE_LOG(ERR, USER1, "VIRTIO PMD must be loaded.\n"); 14041 return TEST_FAILED; 14042 } 14043 14044 return unit_test_suite_runner(&cryptodev_virtio_testsuite); 14045 } 14046 14047 static int 14048 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/) 14049 { 14050 gbl_driver_id = rte_cryptodev_driver_id_get( 14051 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)); 14052 14053 if (gbl_driver_id == -1) { 14054 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 14055 return TEST_SKIPPED; 14056 } 14057 14058 return unit_test_suite_runner(&cryptodev_testsuite); 14059 } 14060 14061 static int 14062 test_cryptodev_cpu_aesni_mb(void) 14063 { 14064 int32_t rc; 14065 enum rte_security_session_action_type at; 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 at = gbl_action_type; 14076 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 14077 rc = unit_test_suite_runner(&cryptodev_testsuite); 14078 gbl_action_type = at; 14079 return rc; 14080 } 14081 14082 static int 14083 test_cryptodev_openssl(void) 14084 { 14085 gbl_driver_id = rte_cryptodev_driver_id_get( 14086 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 14087 14088 if (gbl_driver_id == -1) { 14089 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded.\n"); 14090 return TEST_SKIPPED; 14091 } 14092 14093 return unit_test_suite_runner(&cryptodev_testsuite); 14094 } 14095 14096 static int 14097 test_cryptodev_aesni_gcm(void) 14098 { 14099 gbl_driver_id = rte_cryptodev_driver_id_get( 14100 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)); 14101 14102 if (gbl_driver_id == -1) { 14103 RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded.\n"); 14104 return TEST_SKIPPED; 14105 } 14106 14107 return unit_test_suite_runner(&cryptodev_testsuite); 14108 } 14109 14110 static int 14111 test_cryptodev_cpu_aesni_gcm(void) 14112 { 14113 int32_t rc; 14114 enum rte_security_session_action_type at; 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 at = gbl_action_type; 14125 gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO; 14126 rc = unit_test_suite_runner(&cryptodev_testsuite); 14127 gbl_action_type = at; 14128 return rc; 14129 } 14130 14131 static int 14132 test_cryptodev_null(void) 14133 { 14134 gbl_driver_id = rte_cryptodev_driver_id_get( 14135 RTE_STR(CRYPTODEV_NAME_NULL_PMD)); 14136 14137 if (gbl_driver_id == -1) { 14138 RTE_LOG(ERR, USER1, "NULL PMD must be loaded.\n"); 14139 return TEST_SKIPPED; 14140 } 14141 14142 return unit_test_suite_runner(&cryptodev_testsuite); 14143 } 14144 14145 static int 14146 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/) 14147 { 14148 gbl_driver_id = rte_cryptodev_driver_id_get( 14149 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)); 14150 14151 if (gbl_driver_id == -1) { 14152 RTE_LOG(ERR, USER1, "SNOW3G PMD must be loaded.\n"); 14153 return TEST_SKIPPED; 14154 } 14155 14156 return unit_test_suite_runner(&cryptodev_testsuite); 14157 } 14158 14159 static int 14160 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/) 14161 { 14162 gbl_driver_id = rte_cryptodev_driver_id_get( 14163 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)); 14164 14165 if (gbl_driver_id == -1) { 14166 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded.\n"); 14167 return TEST_SKIPPED; 14168 } 14169 14170 return unit_test_suite_runner(&cryptodev_testsuite); 14171 } 14172 14173 static int 14174 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/) 14175 { 14176 gbl_driver_id = rte_cryptodev_driver_id_get( 14177 RTE_STR(CRYPTODEV_NAME_ZUC_PMD)); 14178 14179 if (gbl_driver_id == -1) { 14180 RTE_LOG(ERR, USER1, "ZUC PMD must be loaded.\n"); 14181 return TEST_SKIPPED; 14182 } 14183 14184 return unit_test_suite_runner(&cryptodev_testsuite); 14185 } 14186 14187 static int 14188 test_cryptodev_armv8(void) 14189 { 14190 gbl_driver_id = rte_cryptodev_driver_id_get( 14191 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)); 14192 14193 if (gbl_driver_id == -1) { 14194 RTE_LOG(ERR, USER1, "ARMV8 PMD must be loaded.\n"); 14195 return TEST_SKIPPED; 14196 } 14197 14198 return unit_test_suite_runner(&cryptodev_testsuite); 14199 } 14200 14201 static int 14202 test_cryptodev_mrvl(void) 14203 { 14204 gbl_driver_id = rte_cryptodev_driver_id_get( 14205 RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)); 14206 14207 if (gbl_driver_id == -1) { 14208 RTE_LOG(ERR, USER1, "MVSAM PMD must be loaded.\n"); 14209 return TEST_SKIPPED; 14210 } 14211 14212 return unit_test_suite_runner(&cryptodev_mrvl_testsuite); 14213 } 14214 14215 #ifdef RTE_CRYPTO_SCHEDULER 14216 14217 static int 14218 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/) 14219 { 14220 gbl_driver_id = rte_cryptodev_driver_id_get( 14221 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)); 14222 14223 if (gbl_driver_id == -1) { 14224 RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n"); 14225 return TEST_SKIPPED; 14226 } 14227 14228 if (rte_cryptodev_driver_id_get( 14229 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) { 14230 RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n"); 14231 return TEST_SKIPPED; 14232 } 14233 return unit_test_suite_runner(&cryptodev_scheduler_testsuite); 14234 } 14235 14236 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler); 14237 14238 #endif 14239 14240 static int 14241 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/) 14242 { 14243 gbl_driver_id = rte_cryptodev_driver_id_get( 14244 RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD)); 14245 14246 if (gbl_driver_id == -1) { 14247 RTE_LOG(ERR, USER1, "DPAA2 SEC PMD must be loaded.\n"); 14248 return TEST_SKIPPED; 14249 } 14250 14251 return unit_test_suite_runner(&cryptodev_testsuite); 14252 } 14253 14254 static int 14255 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/) 14256 { 14257 gbl_driver_id = rte_cryptodev_driver_id_get( 14258 RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD)); 14259 14260 if (gbl_driver_id == -1) { 14261 RTE_LOG(ERR, USER1, "DPAA SEC PMD must be loaded.\n"); 14262 return TEST_SKIPPED; 14263 } 14264 14265 return unit_test_suite_runner(&cryptodev_testsuite); 14266 } 14267 14268 static int 14269 test_cryptodev_ccp(void) 14270 { 14271 gbl_driver_id = rte_cryptodev_driver_id_get( 14272 RTE_STR(CRYPTODEV_NAME_CCP_PMD)); 14273 14274 if (gbl_driver_id == -1) { 14275 RTE_LOG(ERR, USER1, "CCP PMD must be loaded.\n"); 14276 return TEST_FAILED; 14277 } 14278 14279 return unit_test_suite_runner(&cryptodev_ccp_testsuite); 14280 } 14281 14282 static int 14283 test_cryptodev_octeontx(void) 14284 { 14285 gbl_driver_id = rte_cryptodev_driver_id_get( 14286 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)); 14287 if (gbl_driver_id == -1) { 14288 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded.\n"); 14289 return TEST_FAILED; 14290 } 14291 return unit_test_suite_runner(&cryptodev_testsuite); 14292 } 14293 14294 static int 14295 test_cryptodev_octeontx2(void) 14296 { 14297 gbl_driver_id = rte_cryptodev_driver_id_get( 14298 RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD)); 14299 if (gbl_driver_id == -1) { 14300 RTE_LOG(ERR, USER1, "OCTEON TX2 PMD must be loaded.\n"); 14301 return TEST_FAILED; 14302 } 14303 return unit_test_suite_runner(&cryptodev_testsuite); 14304 } 14305 14306 static int 14307 test_cryptodev_caam_jr(void /*argv __rte_unused, int argc __rte_unused*/) 14308 { 14309 gbl_driver_id = rte_cryptodev_driver_id_get( 14310 RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD)); 14311 14312 if (gbl_driver_id == -1) { 14313 RTE_LOG(ERR, USER1, "CAAM_JR PMD must be loaded.\n"); 14314 return TEST_FAILED; 14315 } 14316 14317 return unit_test_suite_runner(&cryptodev_caam_jr_testsuite); 14318 } 14319 14320 static int 14321 test_cryptodev_nitrox(void) 14322 { 14323 gbl_driver_id = rte_cryptodev_driver_id_get( 14324 RTE_STR(CRYPTODEV_NAME_NITROX_PMD)); 14325 14326 if (gbl_driver_id == -1) { 14327 RTE_LOG(ERR, USER1, "NITROX PMD must be loaded.\n"); 14328 return TEST_FAILED; 14329 } 14330 14331 return unit_test_suite_runner(&cryptodev_testsuite); 14332 } 14333 14334 static int 14335 test_cryptodev_bcmfs(void) 14336 { 14337 gbl_driver_id = rte_cryptodev_driver_id_get( 14338 RTE_STR(CRYPTODEV_NAME_BCMFS_PMD)); 14339 14340 if (gbl_driver_id == -1) { 14341 RTE_LOG(ERR, USER1, "BCMFS PMD must be loaded.\n"); 14342 return TEST_FAILED; 14343 } 14344 14345 return unit_test_suite_runner(&cryptodev_testsuite); 14346 } 14347 14348 static int 14349 test_cryptodev_qat_raw_api(void /*argv __rte_unused, int argc __rte_unused*/) 14350 { 14351 int ret; 14352 14353 gbl_driver_id = rte_cryptodev_driver_id_get( 14354 RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD)); 14355 14356 if (gbl_driver_id == -1) { 14357 RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n"); 14358 return TEST_SKIPPED; 14359 } 14360 14361 global_api_test_type = CRYPTODEV_RAW_API_TEST; 14362 ret = unit_test_suite_runner(&cryptodev_testsuite); 14363 global_api_test_type = CRYPTODEV_API_TEST; 14364 14365 return ret; 14366 } 14367 14368 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest, 14369 test_cryptodev_qat_raw_api); 14370 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat); 14371 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb); 14372 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest, 14373 test_cryptodev_cpu_aesni_mb); 14374 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl); 14375 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm); 14376 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest, 14377 test_cryptodev_cpu_aesni_gcm); 14378 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null); 14379 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g); 14380 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi); 14381 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc); 14382 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8); 14383 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl); 14384 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec); 14385 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec); 14386 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp); 14387 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio); 14388 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx); 14389 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2); 14390 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr); 14391 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox); 14392 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs); 14393